• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 static android.app.contextualsearch.ContextualSearchManager.FEATURE_CONTEXTUAL_SEARCH;
20 import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON_OVERLAY;
21 import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON_OVERLAY;
22 
23 import android.content.Context;
24 import android.provider.Settings;
25 
26 import com.android.settings.R;
27 import com.android.settings.core.TogglePreferenceController;
28 
29 /**
30  * Configures behaviour of long press home button to invoke assistant app gesture.
31  */
32 public class ButtonNavigationSettingsAssistController extends TogglePreferenceController {
33 
ButtonNavigationSettingsAssistController(Context context, String key)34     public ButtonNavigationSettingsAssistController(Context context, String key) {
35         super(context, key);
36     }
37 
38     @Override
isChecked()39     public boolean isChecked() {
40         boolean onByDefault = mContext.getResources().getBoolean(
41                 com.android.internal.R.bool.config_assistLongPressHomeEnabledDefault);
42         return Settings.Secure.getInt(mContext.getContentResolver(),
43                 Settings.Secure.ASSIST_LONG_PRESS_HOME_ENABLED, onByDefault ? 1 : 0) == 1;
44     }
45 
46     @Override
setChecked(boolean isChecked)47     public boolean setChecked(boolean isChecked) {
48         return Settings.Secure.putInt(mContext.getContentResolver(),
49                 Settings.Secure.ASSIST_LONG_PRESS_HOME_ENABLED, isChecked ? 1 : 0);
50     }
51 
52     @Override
getAvailabilityStatus()53     public int getAvailabilityStatus() {
54         // Hide the existing assistant UI elements when contextual search is available.
55         if (mContext.getPackageManager().hasSystemFeature(FEATURE_CONTEXTUAL_SEARCH)) {
56             return UNSUPPORTED_ON_DEVICE;
57         }
58 
59         if (SystemNavigationPreferenceController.isOverlayPackageAvailable(mContext,
60                 NAV_BAR_MODE_2BUTTON_OVERLAY)
61                 || SystemNavigationPreferenceController.isOverlayPackageAvailable(mContext,
62                 NAV_BAR_MODE_3BUTTON_OVERLAY)) {
63             return AVAILABLE;
64         }
65 
66         return UNSUPPORTED_ON_DEVICE;
67     }
68 
69     @Override
getSliceHighlightMenuRes()70     public int getSliceHighlightMenuRes() {
71         return R.string.menu_key_system;
72     }
73 }
74