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 android.content.Context; 20 import android.provider.Settings; 21 22 /** Common code for long press power settings shared between controllers. */ 23 final class PowerMenuSettingsUtils { 24 25 /** 26 * Setting storing the current behaviour of long press power. 27 */ 28 public static final String POWER_BUTTON_LONG_PRESS_SETTING = 29 Settings.Global.POWER_BUTTON_LONG_PRESS; 30 31 /** 32 * Value used for long press power button behaviour when the Assist setting is disabled. 33 * 34 * If this value matches Assist setting, then it falls back to Global Actions panel or 35 * power menu, depending on their respective settings. 36 */ 37 public static final int POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE = 38 com.android.internal.R.integer.config_longPressOnPowerBehavior; 39 40 /** 41 * Values used for long press power button behaviour when Assist setting is enabled. 42 * 43 * {@link com.android.server.policy.PhoneWindowManager#LONG_PRESS_POWER_GLOBAL_ACTIONS} for 44 * source of the value. 45 */ 46 static final int LONG_PRESS_POWER_NO_ACTION = 0; 47 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; 48 static final int LONG_PRESS_POWER_ASSISTANT_VALUE = 5; // Settings.Secure.ASSISTANT 49 50 /** 51 * @return current value of power button behaviour. 52 */ getPowerButtonSettingValue(Context context)53 public static int getPowerButtonSettingValue(Context context) { 54 return Settings.Global.getInt(context.getContentResolver(), 55 POWER_BUTTON_LONG_PRESS_SETTING, 56 context.getResources().getInteger(POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE)); 57 } 58 59 /** 60 * @return true if long press power for assist is currently enabled. 61 */ isLongPressPowerForAssistEnabled(Context context)62 public static boolean isLongPressPowerForAssistEnabled(Context context) { 63 return getPowerButtonSettingValue(context) == LONG_PRESS_POWER_ASSISTANT_VALUE; 64 } 65 PowerMenuSettingsUtils()66 private PowerMenuSettingsUtils() { 67 } 68 } 69