1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.car.developeroptions.gestures; 18 19 import static android.provider.Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED; 20 21 import android.content.Context; 22 import android.content.SharedPreferences; 23 import android.provider.Settings; 24 import android.text.TextUtils; 25 26 import com.android.car.developeroptions.Utils; 27 28 public class SwipeToNotificationPreferenceController extends GesturePreferenceController { 29 30 private static final int ON = 1; 31 private static final int OFF = 0; 32 33 private static final String PREF_KEY_VIDEO = "gesture_swipe_down_fingerprint_video"; 34 35 private static final String SECURE_KEY = SYSTEM_NAVIGATION_KEYS_ENABLED; 36 SwipeToNotificationPreferenceController(Context context, String key)37 public SwipeToNotificationPreferenceController(Context context, String key) { 38 super(context, key); 39 } 40 isSuggestionComplete(Context context, SharedPreferences prefs)41 public static boolean isSuggestionComplete(Context context, SharedPreferences prefs) { 42 return !isGestureAvailable(context) 43 || prefs.getBoolean(SwipeToNotificationSettings.PREF_KEY_SUGGESTION_COMPLETE, 44 false); 45 } 46 isGestureAvailable(Context context)47 private static boolean isGestureAvailable(Context context) { 48 return Utils.hasFingerprintHardware(context) 49 && context.getResources() 50 .getBoolean(com.android.internal.R.bool.config_supportSystemNavigationKeys); 51 } 52 53 @Override getVideoPrefKey()54 protected String getVideoPrefKey() { 55 return PREF_KEY_VIDEO; 56 } 57 58 @Override getAvailabilityStatus()59 public int getAvailabilityStatus() { 60 return isAvailable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE; 61 } 62 63 @Override isSliceable()64 public boolean isSliceable() { 65 return TextUtils.equals(getPreferenceKey(), "gesture_swipe_down_fingerprint"); 66 } 67 68 @Override setChecked(boolean isChecked)69 public boolean setChecked(boolean isChecked) { 70 setSwipeToNotification(mContext, isChecked); 71 return true; 72 } 73 74 @Override isChecked()75 public boolean isChecked() { 76 return isSwipeToNotificationOn(mContext); 77 } 78 isSwipeToNotificationOn(Context context)79 public static boolean isSwipeToNotificationOn(Context context) { 80 return Settings.Secure.getInt(context.getContentResolver(), SECURE_KEY, OFF) == ON; 81 } 82 setSwipeToNotification(Context context, boolean isEnabled)83 public static boolean setSwipeToNotification(Context context, boolean isEnabled) { 84 return Settings.Secure.putInt( 85 context.getContentResolver(), SECURE_KEY, isEnabled ? ON : OFF); 86 } 87 isAvailable(Context context)88 public static boolean isAvailable(Context context) { 89 return isGestureAvailable(context); 90 } 91 } 92