Doris Ling | 204ca74 | 2017-07-18 15:43:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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.settings.gestures; |
| 18 | |
| 19 | import android.content.ContentResolver; |
| 20 | import android.content.Context; |
Issei Suzuki | fd85a9f | 2019-02-26 16:16:47 +0100 | [diff] [blame] | 21 | import android.hardware.display.AmbientDisplayConfiguration; |
Doris Ling | 204ca74 | 2017-07-18 15:43:26 -0700 | [diff] [blame] | 22 | import android.provider.Settings; |
Edgar Wang | cef1020 | 2020-05-25 11:46:56 +0800 | [diff] [blame] | 23 | import android.text.TextUtils; |
Edgar Wang | bd0dd5d | 2021-01-29 03:01:28 +0800 | [diff] [blame] | 24 | import android.util.FeatureFlagUtils; |
Doris Ling | 204ca74 | 2017-07-18 15:43:26 -0700 | [diff] [blame] | 25 | |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 26 | import androidx.annotation.NonNull; |
| 27 | |
Doris Ling | 204ca74 | 2017-07-18 15:43:26 -0700 | [diff] [blame] | 28 | import com.android.settings.R; |
Edgar Wang | cef1020 | 2020-05-25 11:46:56 +0800 | [diff] [blame] | 29 | import com.android.settings.aware.AwareFeatureProvider; |
Matthew Fritze | 7d2b4f5 | 2017-12-11 09:57:54 -0800 | [diff] [blame] | 30 | import com.android.settings.core.BasePreferenceController; |
Edgar Wang | bd0dd5d | 2021-01-29 03:01:28 +0800 | [diff] [blame] | 31 | import com.android.settings.core.FeatureFlags; |
Doris Ling | 204ca74 | 2017-07-18 15:43:26 -0700 | [diff] [blame] | 32 | import com.android.settings.overlay.FeatureFactory; |
| 33 | import com.android.settingslib.core.AbstractPreferenceController; |
| 34 | |
Julia Reynolds | 584aba1 | 2018-04-10 11:04:23 -0400 | [diff] [blame] | 35 | import java.util.ArrayList; |
Doris Ling | 204ca74 | 2017-07-18 15:43:26 -0700 | [diff] [blame] | 36 | import java.util.List; |
| 37 | |
Matthew Fritze | 7d2b4f5 | 2017-12-11 09:57:54 -0800 | [diff] [blame] | 38 | public class GesturesSettingPreferenceController extends BasePreferenceController { |
Doris Ling | 204ca74 | 2017-07-18 15:43:26 -0700 | [diff] [blame] | 39 | private final AssistGestureFeatureProvider mFeatureProvider; |
Edgar Wang | cef1020 | 2020-05-25 11:46:56 +0800 | [diff] [blame] | 40 | private final AwareFeatureProvider mAwareFeatureProvider; |
Doris Ling | 204ca74 | 2017-07-18 15:43:26 -0700 | [diff] [blame] | 41 | private List<AbstractPreferenceController> mGestureControllers; |
| 42 | |
Matthew Fritze | 7d2b4f5 | 2017-12-11 09:57:54 -0800 | [diff] [blame] | 43 | private static final String KEY_GESTURES_SETTINGS = "gesture_settings"; |
HJ ChangLiao | 3c4c3fc | 2018-04-02 17:06:55 +0800 | [diff] [blame] | 44 | private static final String FAKE_PREF_KEY = "fake_key_only_for_get_available"; |
Matthew Fritze | 7d2b4f5 | 2017-12-11 09:57:54 -0800 | [diff] [blame] | 45 | |
Doris Ling | 204ca74 | 2017-07-18 15:43:26 -0700 | [diff] [blame] | 46 | public GesturesSettingPreferenceController(Context context) { |
Matthew Fritze | 7d2b4f5 | 2017-12-11 09:57:54 -0800 | [diff] [blame] | 47 | super(context, KEY_GESTURES_SETTINGS); |
Doris Ling | 204ca74 | 2017-07-18 15:43:26 -0700 | [diff] [blame] | 48 | mFeatureProvider = FeatureFactory.getFactory(context).getAssistGestureFeatureProvider(); |
Edgar Wang | cef1020 | 2020-05-25 11:46:56 +0800 | [diff] [blame] | 49 | mAwareFeatureProvider = FeatureFactory.getFactory(context).getAwareFeatureProvider(); |
Doris Ling | 204ca74 | 2017-07-18 15:43:26 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | @Override |
Matthew Fritze | 7d2b4f5 | 2017-12-11 09:57:54 -0800 | [diff] [blame] | 53 | public int getAvailabilityStatus() { |
Doris Ling | 204ca74 | 2017-07-18 15:43:26 -0700 | [diff] [blame] | 54 | if (mGestureControllers == null) { |
HJ ChangLiao | 3c4c3fc | 2018-04-02 17:06:55 +0800 | [diff] [blame] | 55 | mGestureControllers = buildAllPreferenceControllers(mContext); |
Doris Ling | 204ca74 | 2017-07-18 15:43:26 -0700 | [diff] [blame] | 56 | } |
| 57 | boolean isAvailable = false; |
| 58 | for (AbstractPreferenceController controller : mGestureControllers) { |
| 59 | isAvailable = isAvailable || controller.isAvailable(); |
| 60 | } |
Stanley Wang | 9c4e2d6 | 2018-11-30 16:52:46 +0800 | [diff] [blame] | 61 | return isAvailable ? AVAILABLE : UNSUPPORTED_ON_DEVICE; |
HJ ChangLiao | 3c4c3fc | 2018-04-02 17:06:55 +0800 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Get all controllers for their availability status when doing getAvailabilityStatus. |
| 66 | * Do not use this method to add controllers into fragment, most of below controllers already |
| 67 | * convert to TogglePreferenceController, please register them in xml. |
| 68 | * The key is fake because those controllers won't be use to control preference. |
| 69 | */ |
| 70 | private static List<AbstractPreferenceController> buildAllPreferenceControllers( |
| 71 | @NonNull Context context) { |
| 72 | final AmbientDisplayConfiguration ambientDisplayConfiguration = |
| 73 | new AmbientDisplayConfiguration(context); |
Julia Reynolds | 584aba1 | 2018-04-10 11:04:23 -0400 | [diff] [blame] | 74 | final List<AbstractPreferenceController> controllers = new ArrayList<>(); |
HJ ChangLiao | 3c4c3fc | 2018-04-02 17:06:55 +0800 | [diff] [blame] | 75 | |
| 76 | controllers.add(new AssistGestureSettingsPreferenceController(context, FAKE_PREF_KEY) |
| 77 | .setAssistOnly(false)); |
| 78 | controllers.add(new SwipeToNotificationPreferenceController(context, FAKE_PREF_KEY)); |
| 79 | controllers.add(new DoubleTwistPreferenceController(context, FAKE_PREF_KEY)); |
| 80 | controllers.add(new DoubleTapPowerPreferenceController(context, FAKE_PREF_KEY)); |
| 81 | controllers.add(new PickupGesturePreferenceController(context, FAKE_PREF_KEY) |
| 82 | .setConfig(ambientDisplayConfiguration)); |
| 83 | controllers.add(new DoubleTapScreenPreferenceController(context, FAKE_PREF_KEY) |
| 84 | .setConfig(ambientDisplayConfiguration)); |
Beverly | c1fd6dc | 2018-11-01 18:08:26 -0400 | [diff] [blame] | 85 | controllers.add(new PreventRingingParentPreferenceController(context, FAKE_PREF_KEY)); |
HJ ChangLiao | 3c4c3fc | 2018-04-02 17:06:55 +0800 | [diff] [blame] | 86 | return controllers; |
Doris Ling | 204ca74 | 2017-07-18 15:43:26 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | @Override |
Fan Zhang | 906572b | 2018-02-27 10:30:11 -0800 | [diff] [blame] | 90 | public CharSequence getSummary() { |
Edgar Wang | bd0dd5d | 2021-01-29 03:01:28 +0800 | [diff] [blame] | 91 | if (FeatureFlagUtils.isEnabled(mContext, FeatureFlags.SILKY_HOME)) { |
| 92 | return null; |
| 93 | } |
| 94 | |
Doris Ling | 204ca74 | 2017-07-18 15:43:26 -0700 | [diff] [blame] | 95 | if (!mFeatureProvider.isSensorAvailable(mContext)) { |
Matthew Fritze | c69f73f | 2018-01-02 16:39:39 -0800 | [diff] [blame] | 96 | return ""; |
Doris Ling | 204ca74 | 2017-07-18 15:43:26 -0700 | [diff] [blame] | 97 | } |
| 98 | final ContentResolver contentResolver = mContext.getContentResolver(); |
| 99 | final boolean assistGestureEnabled = Settings.Secure.getInt( |
| 100 | contentResolver, Settings.Secure.ASSIST_GESTURE_ENABLED, 1) != 0; |
| 101 | final boolean assistGestureSilenceEnabled = Settings.Secure.getInt( |
| 102 | contentResolver, Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, 1) != 0; |
Edgar Wang | cef1020 | 2020-05-25 11:46:56 +0800 | [diff] [blame] | 103 | final boolean sensorSupported = mFeatureProvider.isSupported(mContext); |
Matthew Fritze | c69f73f | 2018-01-02 16:39:39 -0800 | [diff] [blame] | 104 | |
Edgar Wang | cef1020 | 2020-05-25 11:46:56 +0800 | [diff] [blame] | 105 | final CharSequence awareSummary = mAwareFeatureProvider.getGestureSummary(mContext, |
| 106 | sensorSupported, assistGestureEnabled, assistGestureSilenceEnabled); |
| 107 | if (!TextUtils.isEmpty(awareSummary)) { |
| 108 | return awareSummary; |
| 109 | } |
| 110 | |
| 111 | if (sensorSupported && assistGestureEnabled) { |
Fan Zhang | 906572b | 2018-02-27 10:30:11 -0800 | [diff] [blame] | 112 | return mContext.getText( |
Doris Ling | 204ca74 | 2017-07-18 15:43:26 -0700 | [diff] [blame] | 113 | R.string.language_input_gesture_summary_on_with_assist); |
Doris Ling | 204ca74 | 2017-07-18 15:43:26 -0700 | [diff] [blame] | 114 | } |
Matthew Fritze | c69f73f | 2018-01-02 16:39:39 -0800 | [diff] [blame] | 115 | if (assistGestureSilenceEnabled) { |
Fan Zhang | 906572b | 2018-02-27 10:30:11 -0800 | [diff] [blame] | 116 | return mContext.getText( |
Matthew Fritze | c69f73f | 2018-01-02 16:39:39 -0800 | [diff] [blame] | 117 | R.string.language_input_gesture_summary_on_non_assist); |
| 118 | } |
Fan Zhang | 906572b | 2018-02-27 10:30:11 -0800 | [diff] [blame] | 119 | return mContext.getText(R.string.language_input_gesture_summary_off); |
Doris Ling | 204ca74 | 2017-07-18 15:43:26 -0700 | [diff] [blame] | 120 | } |
Stanley Wang | 9c4e2d6 | 2018-11-30 16:52:46 +0800 | [diff] [blame] | 121 | } |