blob: e01bc8810fa955a6c1ab72c4ac3f1770eac3bd8e [file] [log] [blame]
Doris Ling204ca742017-07-18 15:43:26 -07001/*
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
17package com.android.settings.gestures;
18
19import android.content.ContentResolver;
20import android.content.Context;
Issei Suzukifd85a9f2019-02-26 16:16:47 +010021import android.hardware.display.AmbientDisplayConfiguration;
Doris Ling204ca742017-07-18 15:43:26 -070022import android.provider.Settings;
Edgar Wangcef10202020-05-25 11:46:56 +080023import android.text.TextUtils;
Edgar Wangbd0dd5d2021-01-29 03:01:28 +080024import android.util.FeatureFlagUtils;
Doris Ling204ca742017-07-18 15:43:26 -070025
Fan Zhang31b21002019-01-16 13:49:47 -080026import androidx.annotation.NonNull;
27
Doris Ling204ca742017-07-18 15:43:26 -070028import com.android.settings.R;
Edgar Wangcef10202020-05-25 11:46:56 +080029import com.android.settings.aware.AwareFeatureProvider;
Matthew Fritze7d2b4f52017-12-11 09:57:54 -080030import com.android.settings.core.BasePreferenceController;
Edgar Wangbd0dd5d2021-01-29 03:01:28 +080031import com.android.settings.core.FeatureFlags;
Doris Ling204ca742017-07-18 15:43:26 -070032import com.android.settings.overlay.FeatureFactory;
33import com.android.settingslib.core.AbstractPreferenceController;
34
Julia Reynolds584aba12018-04-10 11:04:23 -040035import java.util.ArrayList;
Doris Ling204ca742017-07-18 15:43:26 -070036import java.util.List;
37
Matthew Fritze7d2b4f52017-12-11 09:57:54 -080038public class GesturesSettingPreferenceController extends BasePreferenceController {
Doris Ling204ca742017-07-18 15:43:26 -070039 private final AssistGestureFeatureProvider mFeatureProvider;
Edgar Wangcef10202020-05-25 11:46:56 +080040 private final AwareFeatureProvider mAwareFeatureProvider;
Doris Ling204ca742017-07-18 15:43:26 -070041 private List<AbstractPreferenceController> mGestureControllers;
42
Matthew Fritze7d2b4f52017-12-11 09:57:54 -080043 private static final String KEY_GESTURES_SETTINGS = "gesture_settings";
HJ ChangLiao3c4c3fc2018-04-02 17:06:55 +080044 private static final String FAKE_PREF_KEY = "fake_key_only_for_get_available";
Matthew Fritze7d2b4f52017-12-11 09:57:54 -080045
Doris Ling204ca742017-07-18 15:43:26 -070046 public GesturesSettingPreferenceController(Context context) {
Matthew Fritze7d2b4f52017-12-11 09:57:54 -080047 super(context, KEY_GESTURES_SETTINGS);
Doris Ling204ca742017-07-18 15:43:26 -070048 mFeatureProvider = FeatureFactory.getFactory(context).getAssistGestureFeatureProvider();
Edgar Wangcef10202020-05-25 11:46:56 +080049 mAwareFeatureProvider = FeatureFactory.getFactory(context).getAwareFeatureProvider();
Doris Ling204ca742017-07-18 15:43:26 -070050 }
51
52 @Override
Matthew Fritze7d2b4f52017-12-11 09:57:54 -080053 public int getAvailabilityStatus() {
Doris Ling204ca742017-07-18 15:43:26 -070054 if (mGestureControllers == null) {
HJ ChangLiao3c4c3fc2018-04-02 17:06:55 +080055 mGestureControllers = buildAllPreferenceControllers(mContext);
Doris Ling204ca742017-07-18 15:43:26 -070056 }
57 boolean isAvailable = false;
58 for (AbstractPreferenceController controller : mGestureControllers) {
59 isAvailable = isAvailable || controller.isAvailable();
60 }
Stanley Wang9c4e2d62018-11-30 16:52:46 +080061 return isAvailable ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
HJ ChangLiao3c4c3fc2018-04-02 17:06:55 +080062 }
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 Reynolds584aba12018-04-10 11:04:23 -040074 final List<AbstractPreferenceController> controllers = new ArrayList<>();
HJ ChangLiao3c4c3fc2018-04-02 17:06:55 +080075
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));
Beverlyc1fd6dc2018-11-01 18:08:26 -040085 controllers.add(new PreventRingingParentPreferenceController(context, FAKE_PREF_KEY));
HJ ChangLiao3c4c3fc2018-04-02 17:06:55 +080086 return controllers;
Doris Ling204ca742017-07-18 15:43:26 -070087 }
88
89 @Override
Fan Zhang906572b2018-02-27 10:30:11 -080090 public CharSequence getSummary() {
Edgar Wangbd0dd5d2021-01-29 03:01:28 +080091 if (FeatureFlagUtils.isEnabled(mContext, FeatureFlags.SILKY_HOME)) {
92 return null;
93 }
94
Doris Ling204ca742017-07-18 15:43:26 -070095 if (!mFeatureProvider.isSensorAvailable(mContext)) {
Matthew Fritzec69f73f2018-01-02 16:39:39 -080096 return "";
Doris Ling204ca742017-07-18 15:43:26 -070097 }
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 Wangcef10202020-05-25 11:46:56 +0800103 final boolean sensorSupported = mFeatureProvider.isSupported(mContext);
Matthew Fritzec69f73f2018-01-02 16:39:39 -0800104
Edgar Wangcef10202020-05-25 11:46:56 +0800105 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 Zhang906572b2018-02-27 10:30:11 -0800112 return mContext.getText(
Doris Ling204ca742017-07-18 15:43:26 -0700113 R.string.language_input_gesture_summary_on_with_assist);
Doris Ling204ca742017-07-18 15:43:26 -0700114 }
Matthew Fritzec69f73f2018-01-02 16:39:39 -0800115 if (assistGestureSilenceEnabled) {
Fan Zhang906572b2018-02-27 10:30:11 -0800116 return mContext.getText(
Matthew Fritzec69f73f2018-01-02 16:39:39 -0800117 R.string.language_input_gesture_summary_on_non_assist);
118 }
Fan Zhang906572b2018-02-27 10:30:11 -0800119 return mContext.getText(R.string.language_input_gesture_summary_off);
Doris Ling204ca742017-07-18 15:43:26 -0700120 }
Stanley Wang9c4e2d62018-11-30 16:52:46 +0800121}