Merge "Improve the UI of Press & hold power button settings" into tm-qpr-dev am: 1cc741a745
am: 179c4dd48a
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/19291450 Change-Id: I970ace8e8cee5aa3e23693d2a3985999f8f10b8c Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
1
res/raw/lottie_long_press_power_for_power_menu.json
Normal file
1
res/raw/lottie_long_press_power_for_power_menu.json
Normal file
File diff suppressed because one or more lines are too long
@@ -12671,7 +12671,7 @@
|
|||||||
<!-- Summary for prevent ringing setting -->
|
<!-- Summary for prevent ringing setting -->
|
||||||
<string name="prevent_ringing_option_mute_summary">Mute</string>
|
<string name="prevent_ringing_option_mute_summary">Mute</string>
|
||||||
<!-- Summary for prevent ringing setting when the option itself is unavailable. [CHAR LIMIT=NONE] -->
|
<!-- Summary for prevent ringing setting when the option itself is unavailable. [CHAR LIMIT=NONE] -->
|
||||||
<string name="prevent_ringing_option_unavailable_lpp_summary">To enable, first change \"Press and hold power button\" to the power menu.</string>
|
<string name="prevent_ringing_option_unavailable_lpp_summary">To enable, first change \"Press & hold power button\" to the power menu.</string>
|
||||||
|
|
||||||
<!-- Title for detail page of wifi network [CHAR LIMIT=30] -->
|
<!-- Title for detail page of wifi network [CHAR LIMIT=30] -->
|
||||||
<string name="pref_title_network_details">Network details</string>
|
<string name="pref_title_network_details">Network details</string>
|
||||||
@@ -13430,29 +13430,28 @@
|
|||||||
<!-- Cards and passes name lower case [CHAR LIMIT=40] -->
|
<!-- Cards and passes name lower case [CHAR LIMIT=40] -->
|
||||||
<string name="cards_passes_lower">cards & passes</string>
|
<string name="cards_passes_lower">cards & passes</string>
|
||||||
|
|
||||||
<!-- Power menu setting name [CHAR LIMIT=NONE] -->
|
<!-- Power menu setting name [CHAR LIMIT=60] -->
|
||||||
<string name="power_menu_setting_name">Press and hold power button</string>
|
<string name="power_menu_setting_name">Press & hold power button</string>
|
||||||
|
|
||||||
<!-- Power menu setting summary to describe press and hold power button for Assistant is enabled. [CHAR LIMIT=NONE] -->
|
<!-- Power menu setting section title for selecting the press and hold power button behavior. [CHAR LIMIT=60] -->
|
||||||
<string name="power_menu_summary_long_press_for_assist_enabled">Press and hold for the Assistant</string>
|
<string name="power_menu_long_press_category_title">Press & hold power button to access</string>
|
||||||
<!-- Power menu setting summary to describe press and hold power button for Assistant is disabled and power menu will appear. [CHAR LIMIT=NONE] -->
|
<!-- Power menu setting option to make press and hold power button to open Power Menu. [CHAR LIMIT=60] -->
|
||||||
<string name="power_menu_summary_long_press_for_assist_disabled_with_power_menu">Press and hold for the power menu</string>
|
<string name="power_menu_long_press_for_power_menu_title">Power menu</string>
|
||||||
<!-- Power menu setting summary to describe press and hold power button for Assistant is disabled and nothing will happen. [CHAR LIMIT=NONE] -->
|
<!-- Power menu setting option to make press and hold power button to open Assistant. [CHAR LIMIT=60] -->
|
||||||
<string name="power_menu_summary_long_press_for_assist_disabled_no_action">Press and hold disabled</string>
|
<string name="power_menu_long_press_for_assistant_title">Digital assistant</string>
|
||||||
|
|
||||||
|
<!-- Power menu setting summary to describe press and hold power button will open Assistant. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="power_menu_summary_long_press_for_assistant">Access digital assistant</string>
|
||||||
|
<!-- Power menu setting summary to describe press and hold power button will open Power Menu. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="power_menu_summary_long_press_for_power_menu">Access power menu</string>
|
||||||
|
|
||||||
<!-- Power menu setting privacy no secure screen lock set [CHAR_LIMIT=NONE] -->
|
<!-- Power menu setting privacy no secure screen lock set [CHAR_LIMIT=NONE] -->
|
||||||
<string name="lockscreen_privacy_not_secure">To use, first set a screen lock</string>
|
<string name="lockscreen_privacy_not_secure">To use, first set a screen lock</string>
|
||||||
|
|
||||||
<!-- Power menu setting use long press power to invoke assistant. [CHAR LIMIT=NONE] -->
|
<!-- Power menu explanation to press power and volume up to show power menu. [CHAR LIMIT=NONE] -->
|
||||||
<string name="power_menu_long_press_for_assist">Hold for Assistant</string>
|
<string name="power_menu_power_volume_up_hint">Power menu:\nPress the power button and the volume up button at the same time</string>
|
||||||
|
|
||||||
<!-- Power menu setting use log press power to invoke assistant summary. [CHAR LIMIT=NONE] -->
|
|
||||||
<string name="power_menu_long_press_for_assist_summary">Trigger the Assistant by holding the power button</string>
|
|
||||||
|
|
||||||
<!-- Power menu explanation to press power and volume up to show power and emergency menu. [CHAR LIMIT=NONE] -->
|
|
||||||
<string name="power_menu_power_volume_up_hint">Power & Emergency Menu:\nPress Power and Volume up at the same time.</string>
|
|
||||||
<!-- Power menu explanation where to find prevent ringing option. [CHAR LIMIT=NONE] -->
|
<!-- Power menu explanation where to find prevent ringing option. [CHAR LIMIT=NONE] -->
|
||||||
<string name="power_menu_power_prevent_ringing_hint">Prevent ringing:\nShortcut available in the volume menu.</string>
|
<string name="power_menu_power_prevent_ringing_hint">Prevent ringing:\nPress a volume button for the shortcut</string>
|
||||||
|
|
||||||
<!-- Power menu title of the seekbar setting controlling duration of how long the power button must be held to invoke assistant. [CHAR LIMIT=NONE]-->
|
<!-- Power menu title of the seekbar setting controlling duration of how long the power button must be held to invoke assistant. [CHAR LIMIT=NONE]-->
|
||||||
<string name="power_menu_long_press_for_assist_sensitivity_title">Press & hold duration</string>
|
<string name="power_menu_long_press_for_assist_sensitivity_title">Press & hold duration</string>
|
||||||
|
@@ -23,19 +23,28 @@
|
|||||||
android:key="gesture_power_menu_video"
|
android:key="gesture_power_menu_video"
|
||||||
settings:searchable="false"
|
settings:searchable="false"
|
||||||
settings:lottie_imageAssetsFolder="power_menu"
|
settings:lottie_imageAssetsFolder="power_menu"
|
||||||
settings:lottie_rawRes="@raw/lottie_power_menu"/>
|
settings:lottie_rawRes="@raw/lottie_long_press_power_for_power_menu"
|
||||||
|
settings:controller="com.android.settings.gestures.LongPressPowerIllustrationPreferenceController"/>
|
||||||
|
|
||||||
<SwitchPreference
|
<PreferenceCategory
|
||||||
android:key="gesture_power_menu_long_press_for_assist"
|
android:key="gesture_power_menu_long_press_category"
|
||||||
android:title="@string/power_menu_long_press_for_assist"
|
android:title="@string/power_menu_long_press_category_title">
|
||||||
android:summary="@string/power_menu_long_press_for_assist_summary"
|
<com.android.settingslib.widget.SelectorWithWidgetPreference
|
||||||
settings:controller="com.android.settings.gestures.LongPressPowerButtonPreferenceController"
|
android:key="gesture_power_menu_long_press_for_power_menu"
|
||||||
/>
|
android:title="@string/power_menu_long_press_for_power_menu_title"
|
||||||
|
settings:controller="com.android.settings.gestures.LongPressPowerForPowerMenuPreferenceController"/>
|
||||||
|
|
||||||
|
<com.android.settingslib.widget.SelectorWithWidgetPreference
|
||||||
|
android:key="gesture_power_menu_long_press_for_assistant"
|
||||||
|
android:title="@string/power_menu_long_press_for_assistant_title"
|
||||||
|
settings:controller="com.android.settings.gestures.LongPressPowerForAssistantPreferenceController"/>
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
<com.android.settings.widget.LabeledSeekBarPreference
|
<com.android.settings.widget.LabeledSeekBarPreference
|
||||||
android:key="gesture_power_menu_long_press_for_assist_sensitivity"
|
android:key="gesture_power_menu_long_press_for_assist_sensitivity"
|
||||||
android:title="@string/power_menu_long_press_for_assist_sensitivity_title"
|
android:title="@string/power_menu_long_press_for_assist_sensitivity_title"
|
||||||
android:summary="@string/power_menu_long_press_for_assist_sensitivity_summary"
|
android:summary="@string/power_menu_long_press_for_assist_sensitivity_summary"
|
||||||
|
settings:allowDividerAbove="true"
|
||||||
settings:textStart="@string/power_menu_long_press_for_assist_sensitivity_low_label"
|
settings:textStart="@string/power_menu_long_press_for_assist_sensitivity_low_label"
|
||||||
settings:textEnd="@string/power_menu_long_press_for_assist_sensitivity_high_label"
|
settings:textEnd="@string/power_menu_long_press_for_assist_sensitivity_high_label"
|
||||||
settings:controller="com.android.settings.gestures.LongPressPowerSensitivityPreferenceController"
|
settings:controller="com.android.settings.gestures.LongPressPowerSensitivityPreferenceController"
|
||||||
@@ -45,5 +54,6 @@
|
|||||||
android:key="power_menu_power_volume_up_hint"
|
android:key="power_menu_power_volume_up_hint"
|
||||||
android:title="@string/power_menu_power_volume_up_hint"
|
android:title="@string/power_menu_power_volume_up_hint"
|
||||||
android:selectable="false"
|
android:selectable="false"
|
||||||
settings:searchable="false"/>
|
settings:searchable="false"
|
||||||
|
settings:controller="com.android.settings.gestures.LongPressPowerFooterPreferenceController"/>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@@ -1,196 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2021 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.gestures;
|
|
||||||
|
|
||||||
import static com.android.settings.gestures.PowerMenuSettingsUtils.LONG_PRESS_POWER_ASSISTANT_VALUE;
|
|
||||||
import static com.android.settings.gestures.PowerMenuSettingsUtils.LONG_PRESS_POWER_GLOBAL_ACTIONS;
|
|
||||||
import static com.android.settings.gestures.PowerMenuSettingsUtils.POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE;
|
|
||||||
import static com.android.settings.gestures.PowerMenuSettingsUtils.POWER_BUTTON_LONG_PRESS_SETTING;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
|
||||||
|
|
||||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configures the behaviour of long press power button action.
|
|
||||||
*/
|
|
||||||
public class LongPressPowerButtonPreferenceController extends TogglePreferenceController {
|
|
||||||
|
|
||||||
private static final String KEY_CHORD_POWER_VOLUME_UP_SETTING =
|
|
||||||
Settings.Global.KEY_CHORD_POWER_VOLUME_UP;
|
|
||||||
|
|
||||||
private static final String FOOTER_HINT_KEY = "power_menu_power_volume_up_hint";
|
|
||||||
private static final String ASSIST_SWITCH_KEY = "gesture_power_menu_long_press_for_assist";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Values used for volume key chord behaviour when Assist setting is enabled.
|
|
||||||
*
|
|
||||||
* Values based on config_keyChordPowerVolumeUp in
|
|
||||||
* frameworks/base/core/res/res/values/config.xml
|
|
||||||
*/
|
|
||||||
@VisibleForTesting
|
|
||||||
static final int KEY_CHORD_POWER_VOLUME_UP_NO_ACTION = 0;
|
|
||||||
@VisibleForTesting
|
|
||||||
static final int KEY_CHORD_POWER_VOLUME_UP_MUTE_TOGGLE = 1;
|
|
||||||
@VisibleForTesting
|
|
||||||
static final int KEY_CHORD_POWER_VOLUME_UP_GLOBAL_ACTIONS = 2;
|
|
||||||
|
|
||||||
private static final int KEY_CHORD_POWER_VOLUME_UP_DEFAULT_VALUE_RESOURCE =
|
|
||||||
com.android.internal.R.integer.config_keyChordPowerVolumeUp;
|
|
||||||
|
|
||||||
@MonotonicNonNull
|
|
||||||
@VisibleForTesting
|
|
||||||
Preference mFooterHint;
|
|
||||||
|
|
||||||
@MonotonicNonNull
|
|
||||||
@VisibleForTesting
|
|
||||||
Preference mAssistSwitch;
|
|
||||||
|
|
||||||
public LongPressPowerButtonPreferenceController(Context context, String key) {
|
|
||||||
super(context, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void displayPreference(PreferenceScreen screen) {
|
|
||||||
super.displayPreference(screen);
|
|
||||||
mFooterHint = screen.findPreference(FOOTER_HINT_KEY);
|
|
||||||
mAssistSwitch = screen.findPreference(ASSIST_SWITCH_KEY);
|
|
||||||
refreshStateDisplay();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CharSequence getSummary() {
|
|
||||||
final int powerButtonValue = PowerMenuSettingsUtils.getPowerButtonSettingValue(mContext);
|
|
||||||
if (powerButtonValue == LONG_PRESS_POWER_ASSISTANT_VALUE) {
|
|
||||||
return mContext.getString(R.string.power_menu_summary_long_press_for_assist_enabled);
|
|
||||||
} else if (powerButtonValue == LONG_PRESS_POWER_GLOBAL_ACTIONS) {
|
|
||||||
return mContext.getString(
|
|
||||||
R.string.power_menu_summary_long_press_for_assist_disabled_with_power_menu);
|
|
||||||
} else {
|
|
||||||
return mContext.getString(
|
|
||||||
R.string.power_menu_summary_long_press_for_assist_disabled_no_action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getAvailabilityStatus() {
|
|
||||||
final boolean enabled = mContext.getResources().getBoolean(
|
|
||||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable);
|
|
||||||
return enabled ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isChecked() {
|
|
||||||
return PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean setChecked(boolean isChecked) {
|
|
||||||
if (setPowerLongPressValue(isChecked)) {
|
|
||||||
// The key chord value is dependant on the long press setting and it always
|
|
||||||
// toggled in tandem. POWER_BUTTON_LONG_PRESS_SETTING is always the source
|
|
||||||
// of truth for both.
|
|
||||||
setPowerVolumeChordValue(isChecked);
|
|
||||||
refreshStateDisplay();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSliceHighlightMenuRes() {
|
|
||||||
return R.string.menu_key_system;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void refreshStateDisplay() {
|
|
||||||
if (mAssistSwitch != null) {
|
|
||||||
mAssistSwitch.setSummary(getSummary());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mFooterHint != null) {
|
|
||||||
String footerHintText = mContext.getString(R.string.power_menu_power_volume_up_hint);
|
|
||||||
// If the device supports hush gesture, we need to notify the user where to find
|
|
||||||
// the setting.
|
|
||||||
if (mContext.getResources().getBoolean(
|
|
||||||
com.android.internal.R.bool.config_volumeHushGestureEnabled)) {
|
|
||||||
footerHintText = footerHintText + "\n\n" + mContext.getString(
|
|
||||||
R.string.power_menu_power_prevent_ringing_hint);
|
|
||||||
}
|
|
||||||
|
|
||||||
mFooterHint.setSummary(footerHintText);
|
|
||||||
mFooterHint.setVisible(isPowerMenuKeyChordEnabled(mContext));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isPowerMenuKeyChordEnabled(Context context) {
|
|
||||||
return Settings.Global.getInt(context.getContentResolver(),
|
|
||||||
KEY_CHORD_POWER_VOLUME_UP_SETTING,
|
|
||||||
context.getResources().getInteger(
|
|
||||||
com.android.internal.R.integer.config_keyChordPowerVolumeUp))
|
|
||||||
== KEY_CHORD_POWER_VOLUME_UP_GLOBAL_ACTIONS;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean setPowerLongPressValue(boolean isChecked) {
|
|
||||||
if (isChecked) {
|
|
||||||
return Settings.Global.putInt(mContext.getContentResolver(),
|
|
||||||
POWER_BUTTON_LONG_PRESS_SETTING, LONG_PRESS_POWER_ASSISTANT_VALUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// We need to determine the right disabled value based on the device default
|
|
||||||
// for long-press power.
|
|
||||||
|
|
||||||
// If the default is to start the assistant, then the fallback is GlobalActions.
|
|
||||||
final int defaultPowerButtonValue = mContext.getResources().getInteger(
|
|
||||||
POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE);
|
|
||||||
if (defaultPowerButtonValue == LONG_PRESS_POWER_ASSISTANT_VALUE) {
|
|
||||||
return Settings.Global.putInt(mContext.getContentResolver(),
|
|
||||||
POWER_BUTTON_LONG_PRESS_SETTING, LONG_PRESS_POWER_GLOBAL_ACTIONS);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the default is something different than Assist, we use that default.
|
|
||||||
return Settings.Global.putInt(mContext.getContentResolver(),
|
|
||||||
POWER_BUTTON_LONG_PRESS_SETTING, defaultPowerButtonValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates {@link Settings.Global.KEY_CHORD_POWER_VOLUME_UP} based on the changed value of
|
|
||||||
* {@link #POWER_BUTTON_LONG_PRESS_SETTING}. If power button is used for Assist, key chord
|
|
||||||
* should show the power menu.
|
|
||||||
*/
|
|
||||||
private boolean setPowerVolumeChordValue(boolean isPowerButtonLongPressChecked) {
|
|
||||||
if (isPowerButtonLongPressChecked) {
|
|
||||||
return Settings.Global.putInt(mContext.getContentResolver(),
|
|
||||||
KEY_CHORD_POWER_VOLUME_UP_SETTING, KEY_CHORD_POWER_VOLUME_UP_GLOBAL_ACTIONS);
|
|
||||||
}
|
|
||||||
|
|
||||||
// We restore key chord to the default value.
|
|
||||||
int keyChordDefaultValue = mContext.getResources().getInteger(
|
|
||||||
KEY_CHORD_POWER_VOLUME_UP_DEFAULT_VALUE_RESOURCE);
|
|
||||||
return Settings.Global.putInt(mContext.getContentResolver(),
|
|
||||||
KEY_CHORD_POWER_VOLUME_UP_SETTING, keyChordDefaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.gestures;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.lifecycle.LifecycleObserver;
|
||||||
|
import androidx.lifecycle.OnLifecycleEvent;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
|
||||||
|
/** Configures the behaviour of long press power footer. */
|
||||||
|
public class LongPressPowerFooterPreferenceController extends BasePreferenceController
|
||||||
|
implements PowerMenuSettingsUtils.SettingsStateCallback, LifecycleObserver {
|
||||||
|
|
||||||
|
private Preference mPreference;
|
||||||
|
private final PowerMenuSettingsUtils mUtils;
|
||||||
|
|
||||||
|
public LongPressPowerFooterPreferenceController(Context context, String key) {
|
||||||
|
super(context, key);
|
||||||
|
mUtils = new PowerMenuSettingsUtils(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
mPreference = screen.findPreference(getPreferenceKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateState(Preference preference) {
|
||||||
|
super.updateState(preference);
|
||||||
|
|
||||||
|
CharSequence footerHintText = mContext.getString(R.string.power_menu_power_volume_up_hint);
|
||||||
|
// If the device supports hush gesture, we need to tell the user where to find the setting.
|
||||||
|
if (mContext.getResources()
|
||||||
|
.getBoolean(com.android.internal.R.bool.config_volumeHushGestureEnabled)) {
|
||||||
|
footerHintText =
|
||||||
|
TextUtils.concat(
|
||||||
|
footerHintText,
|
||||||
|
"\n\n",
|
||||||
|
mContext.getString(R.string.power_menu_power_prevent_ringing_hint));
|
||||||
|
}
|
||||||
|
|
||||||
|
preference.setSummary(footerHintText);
|
||||||
|
preference.setVisible(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChange(Uri uri) {
|
||||||
|
if (mPreference != null) {
|
||||||
|
updateState(mPreference);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @OnLifecycleEvent(Lifecycle.Event.ON_START) */
|
||||||
|
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
||||||
|
public void onStart() {
|
||||||
|
mUtils.registerObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @OnLifecycleEvent(Lifecycle.Event.ON_STOP) */
|
||||||
|
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
|
||||||
|
public void onStop() {
|
||||||
|
mUtils.unregisterObserver();
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.gestures;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.Uri;
|
||||||
|
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.lifecycle.LifecycleObserver;
|
||||||
|
import androidx.lifecycle.OnLifecycleEvent;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settingslib.widget.SelectorWithWidgetPreference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures the behaviour of the radio selector to configure long press power button to Assistant.
|
||||||
|
*/
|
||||||
|
public class LongPressPowerForAssistantPreferenceController extends BasePreferenceController
|
||||||
|
implements PowerMenuSettingsUtils.SettingsStateCallback,
|
||||||
|
SelectorWithWidgetPreference.OnClickListener,
|
||||||
|
LifecycleObserver {
|
||||||
|
|
||||||
|
private SelectorWithWidgetPreference mPreference;
|
||||||
|
private final PowerMenuSettingsUtils mUtils;
|
||||||
|
|
||||||
|
public LongPressPowerForAssistantPreferenceController(Context context, String key) {
|
||||||
|
super(context, key);
|
||||||
|
mUtils = new PowerMenuSettingsUtils(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return PowerMenuSettingsUtils.isLongPressPowerSettingAvailable(mContext)
|
||||||
|
? AVAILABLE
|
||||||
|
: UNSUPPORTED_ON_DEVICE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
mPreference = screen.findPreference(getPreferenceKey());
|
||||||
|
if (mPreference != null) {
|
||||||
|
mPreference.setOnClickListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateState(Preference preference) {
|
||||||
|
super.updateState(preference);
|
||||||
|
if (preference instanceof SelectorWithWidgetPreference) {
|
||||||
|
((SelectorWithWidgetPreference) preference)
|
||||||
|
.setChecked(
|
||||||
|
PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRadioButtonClicked(SelectorWithWidgetPreference preference) {
|
||||||
|
PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
|
||||||
|
if (mPreference != null) {
|
||||||
|
updateState(mPreference);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChange(Uri uri) {
|
||||||
|
if (mPreference != null) {
|
||||||
|
updateState(mPreference);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @OnLifecycleEvent(Lifecycle.Event.ON_START) */
|
||||||
|
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
||||||
|
public void onStart() {
|
||||||
|
mUtils.registerObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @OnLifecycleEvent(Lifecycle.Event.ON_STOP) */
|
||||||
|
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
|
||||||
|
public void onStop() {
|
||||||
|
mUtils.unregisterObserver();
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.gestures;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.Uri;
|
||||||
|
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.lifecycle.LifecycleObserver;
|
||||||
|
import androidx.lifecycle.OnLifecycleEvent;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settingslib.widget.SelectorWithWidgetPreference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures the behaviour of the radio selector to configure long press power button to Power
|
||||||
|
* Menu.
|
||||||
|
*/
|
||||||
|
public class LongPressPowerForPowerMenuPreferenceController extends BasePreferenceController
|
||||||
|
implements PowerMenuSettingsUtils.SettingsStateCallback,
|
||||||
|
SelectorWithWidgetPreference.OnClickListener,
|
||||||
|
LifecycleObserver {
|
||||||
|
|
||||||
|
private SelectorWithWidgetPreference mPreference;
|
||||||
|
private final PowerMenuSettingsUtils mUtils;
|
||||||
|
|
||||||
|
public LongPressPowerForPowerMenuPreferenceController(Context context, String key) {
|
||||||
|
super(context, key);
|
||||||
|
mUtils = new PowerMenuSettingsUtils(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return PowerMenuSettingsUtils.isLongPressPowerSettingAvailable(mContext)
|
||||||
|
? AVAILABLE
|
||||||
|
: UNSUPPORTED_ON_DEVICE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
mPreference = screen.findPreference(getPreferenceKey());
|
||||||
|
if (mPreference != null) {
|
||||||
|
mPreference.setOnClickListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateState(Preference preference) {
|
||||||
|
super.updateState(preference);
|
||||||
|
if (preference instanceof SelectorWithWidgetPreference) {
|
||||||
|
((SelectorWithWidgetPreference) preference)
|
||||||
|
.setChecked(
|
||||||
|
!PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRadioButtonClicked(SelectorWithWidgetPreference preference) {
|
||||||
|
PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
|
||||||
|
if (mPreference != null) {
|
||||||
|
updateState(mPreference);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChange(Uri uri) {
|
||||||
|
if (mPreference != null) {
|
||||||
|
updateState(mPreference);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @OnLifecycleEvent(Lifecycle.Event.ON_START) */
|
||||||
|
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
||||||
|
public void onStart() {
|
||||||
|
mUtils.registerObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @OnLifecycleEvent(Lifecycle.Event.ON_STOP) */
|
||||||
|
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
|
||||||
|
public void onStop() {
|
||||||
|
mUtils.unregisterObserver();
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.gestures;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.Uri;
|
||||||
|
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.lifecycle.LifecycleObserver;
|
||||||
|
import androidx.lifecycle.OnLifecycleEvent;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settingslib.widget.IllustrationPreference;
|
||||||
|
|
||||||
|
/** Configures the behaviour of long press power illustration. */
|
||||||
|
public class LongPressPowerIllustrationPreferenceController extends BasePreferenceController
|
||||||
|
implements PowerMenuSettingsUtils.SettingsStateCallback, LifecycleObserver {
|
||||||
|
|
||||||
|
private IllustrationPreference mIllustrationPreference;
|
||||||
|
private final PowerMenuSettingsUtils mUtils;
|
||||||
|
|
||||||
|
public LongPressPowerIllustrationPreferenceController(Context context, String key) {
|
||||||
|
super(context, key);
|
||||||
|
mUtils = new PowerMenuSettingsUtils(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
mIllustrationPreference = screen.findPreference(getPreferenceKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateState(Preference preference) {
|
||||||
|
super.updateState(preference);
|
||||||
|
|
||||||
|
((IllustrationPreference) preference)
|
||||||
|
.setLottieAnimationResId(
|
||||||
|
PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)
|
||||||
|
? R.raw.lottie_long_press_power_for_assistant
|
||||||
|
: R.raw.lottie_long_press_power_for_power_menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChange(Uri uri) {
|
||||||
|
if (mIllustrationPreference != null) {
|
||||||
|
updateState(mIllustrationPreference);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @OnLifecycleEvent(Lifecycle.Event.ON_START) */
|
||||||
|
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
||||||
|
public void onStart() {
|
||||||
|
mUtils.registerObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @OnLifecycleEvent(Lifecycle.Event.ON_STOP) */
|
||||||
|
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
|
||||||
|
public void onStop() {
|
||||||
|
mUtils.unregisterObserver();
|
||||||
|
}
|
||||||
|
}
|
@@ -17,37 +17,28 @@
|
|||||||
package com.android.settings.gestures;
|
package com.android.settings.gestures;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.ContentObserver;
|
import android.net.Uri;
|
||||||
import android.os.Handler;
|
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.lifecycle.LifecycleObserver;
|
||||||
|
import androidx.lifecycle.OnLifecycleEvent;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.core.SliderPreferenceController;
|
import com.android.settings.core.SliderPreferenceController;
|
||||||
import com.android.settings.widget.LabeledSeekBarPreference;
|
import com.android.settings.widget.LabeledSeekBarPreference;
|
||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
|
||||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
|
||||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
|
||||||
|
|
||||||
/** Handles changes to the long press power button sensitivity slider. */
|
/** Handles changes to the long press power button sensitivity slider. */
|
||||||
public class LongPressPowerSensitivityPreferenceController extends
|
public class LongPressPowerSensitivityPreferenceController extends SliderPreferenceController
|
||||||
SliderPreferenceController implements
|
implements PowerMenuSettingsUtils.SettingsStateCallback, LifecycleObserver {
|
||||||
LifecycleObserver, OnStart, OnStop {
|
|
||||||
|
|
||||||
private final ContentObserver mPowerButtonObserver = new ContentObserver(Handler.getMain()) {
|
|
||||||
@Override
|
|
||||||
public void onChange(boolean selfChange) {
|
|
||||||
if (mPreference != null) {
|
|
||||||
updateState(mPreference);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private final int[] mSensitivityValues;
|
private final int[] mSensitivityValues;
|
||||||
|
|
||||||
|
private final PowerMenuSettingsUtils mUtils;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private LabeledSeekBarPreference mPreference;
|
private LabeledSeekBarPreference mPreference;
|
||||||
|
|
||||||
@@ -55,18 +46,19 @@ public class LongPressPowerSensitivityPreferenceController extends
|
|||||||
super(context, preferenceKey);
|
super(context, preferenceKey);
|
||||||
mSensitivityValues = context.getResources().getIntArray(
|
mSensitivityValues = context.getResources().getIntArray(
|
||||||
com.android.internal.R.array.config_longPressOnPowerDurationSettings);
|
com.android.internal.R.array.config_longPressOnPowerDurationSettings);
|
||||||
|
mUtils = new PowerMenuSettingsUtils(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/** @OnLifecycleEvent(Lifecycle.Event.ON_START) */
|
||||||
|
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
mContext.getContentResolver().registerContentObserver(
|
mUtils.registerObserver(this);
|
||||||
Settings.Global.getUriFor(PowerMenuSettingsUtils.POWER_BUTTON_LONG_PRESS_SETTING),
|
|
||||||
false, mPowerButtonObserver);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/** @OnLifecycleEvent(Lifecycle.Event.ON_STOP) */
|
||||||
|
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
mContext.getContentResolver().unregisterContentObserver(mPowerButtonObserver);
|
mUtils.unregisterObserver();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -86,21 +78,19 @@ public class LongPressPowerSensitivityPreferenceController extends
|
|||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
super.updateState(preference);
|
super.updateState(preference);
|
||||||
final LabeledSeekBarPreference pref = (LabeledSeekBarPreference) preference;
|
final LabeledSeekBarPreference pref = (LabeledSeekBarPreference) preference;
|
||||||
pref.setEnabled(
|
pref.setVisible(
|
||||||
isAvailable() && PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext));
|
PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)
|
||||||
|
&& getAvailabilityStatus() == AVAILABLE);
|
||||||
pref.setProgress(getSliderPosition());
|
pref.setProgress(getSliderPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public int getAvailabilityStatus() {
|
||||||
if (mSensitivityValues == null || mSensitivityValues.length < 2) {
|
if (mSensitivityValues == null
|
||||||
|
|| mSensitivityValues.length < 2
|
||||||
|
|| !PowerMenuSettingsUtils.isLongPressPowerSettingAvailable(mContext)) {
|
||||||
return UNSUPPORTED_ON_DEVICE;
|
return UNSUPPORTED_ON_DEVICE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext)) {
|
|
||||||
return DISABLED_DEPENDENT_SETTING;
|
|
||||||
}
|
|
||||||
|
|
||||||
return AVAILABLE;
|
return AVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,6 +110,13 @@ public class LongPressPowerSensitivityPreferenceController extends
|
|||||||
mSensitivityValues[position]);
|
mSensitivityValues[position]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChange(Uri uri) {
|
||||||
|
if (mPreference != null) {
|
||||||
|
updateState(mPreference);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMax() {
|
public int getMax() {
|
||||||
if (mSensitivityValues == null || mSensitivityValues.length == 0) {
|
if (mSensitivityValues == null || mSensitivityValues.length == 0) {
|
||||||
|
@@ -16,9 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.gestures;
|
package com.android.settings.gestures;
|
||||||
|
|
||||||
import static com.android.settings.gestures.PowerMenuSettingsUtils.LONG_PRESS_POWER_ASSISTANT_VALUE;
|
|
||||||
import static com.android.settings.gestures.PowerMenuSettingsUtils.LONG_PRESS_POWER_GLOBAL_ACTIONS;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -32,25 +29,17 @@ public class PowerMenuPreferenceController extends BasePreferenceController {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getSummary() {
|
public CharSequence getSummary() {
|
||||||
final int powerButtonValue = PowerMenuSettingsUtils.getPowerButtonSettingValue(mContext);
|
if (PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)) {
|
||||||
if (powerButtonValue == LONG_PRESS_POWER_ASSISTANT_VALUE) {
|
return mContext.getText(R.string.power_menu_summary_long_press_for_assistant);
|
||||||
return mContext.getText(R.string.power_menu_summary_long_press_for_assist_enabled);
|
|
||||||
} else if (powerButtonValue == LONG_PRESS_POWER_GLOBAL_ACTIONS) {
|
|
||||||
return mContext.getText(
|
|
||||||
R.string.power_menu_summary_long_press_for_assist_disabled_with_power_menu);
|
|
||||||
} else {
|
} else {
|
||||||
return mContext.getText(
|
return mContext.getText(R.string.power_menu_summary_long_press_for_power_menu);
|
||||||
R.string.power_menu_summary_long_press_for_assist_disabled_no_action);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public int getAvailabilityStatus() {
|
||||||
return isAssistInvocationAvailable() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
return PowerMenuSettingsUtils.isLongPressPowerSettingAvailable(mContext)
|
||||||
}
|
? AVAILABLE
|
||||||
|
: UNSUPPORTED_ON_DEVICE;
|
||||||
private boolean isAssistInvocationAvailable() {
|
|
||||||
return mContext.getResources().getBoolean(
|
|
||||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,53 +16,163 @@
|
|||||||
|
|
||||||
package com.android.settings.gestures;
|
package com.android.settings.gestures;
|
||||||
|
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.database.ContentObserver;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
/** Common code for long press power settings shared between controllers. */
|
/** Common code for long press power settings shared between controllers. */
|
||||||
final class PowerMenuSettingsUtils {
|
final class PowerMenuSettingsUtils {
|
||||||
|
|
||||||
/**
|
/** Setting storing the current behaviour of long press power. */
|
||||||
* Setting storing the current behaviour of long press power.
|
private static final String POWER_BUTTON_LONG_PRESS_SETTING =
|
||||||
*/
|
|
||||||
public static final String POWER_BUTTON_LONG_PRESS_SETTING =
|
|
||||||
Settings.Global.POWER_BUTTON_LONG_PRESS;
|
Settings.Global.POWER_BUTTON_LONG_PRESS;
|
||||||
|
|
||||||
|
/** Setting storing the current behaviour of key chord power + volume up. */
|
||||||
|
private static final String KEY_CHORD_POWER_VOLUME_UP_SETTING =
|
||||||
|
Settings.Global.KEY_CHORD_POWER_VOLUME_UP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Value used for long press power button behaviour when the Assist setting is disabled.
|
* Value used for long press power button behaviour when long press power for Assistant is
|
||||||
|
* disabled.
|
||||||
*
|
*
|
||||||
* If this value matches Assist setting, then it falls back to Global Actions panel or
|
* <p>If this value matches long press power for Assistant, then it falls back to Global Actions
|
||||||
* power menu, depending on their respective settings.
|
* panel (i.e., the Power Menu), depending on their respective settings.
|
||||||
*/
|
*/
|
||||||
public static final int POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE =
|
private static final int POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE =
|
||||||
com.android.internal.R.integer.config_longPressOnPowerBehavior;
|
com.android.internal.R.integer.config_longPressOnPowerBehavior;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Values used for long press power button behaviour when Assist setting is enabled.
|
* Value used for key chord power + volume up behaviour when long press power for Assistant is
|
||||||
*
|
* disabled.
|
||||||
* {@link com.android.server.policy.PhoneWindowManager#LONG_PRESS_POWER_GLOBAL_ACTIONS} for
|
|
||||||
* source of the value.
|
|
||||||
*/
|
*/
|
||||||
static final int LONG_PRESS_POWER_NO_ACTION = 0;
|
private static final int KEY_CHORD_POWER_VOLUME_UP_DEFAULT_VALUE_RESOURCE =
|
||||||
static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
|
com.android.internal.R.integer.config_keyChordPowerVolumeUp;
|
||||||
static final int LONG_PRESS_POWER_ASSISTANT_VALUE = 5; // Settings.Secure.ASSISTANT
|
|
||||||
|
private static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; // a.k.a., Power Menu
|
||||||
|
private static final int LONG_PRESS_POWER_ASSISTANT_VALUE = 5; // Settings.Secure.ASSISTANT
|
||||||
|
|
||||||
|
private static final int KEY_CHORD_POWER_VOLUME_UP_GLOBAL_ACTIONS = 2;
|
||||||
|
|
||||||
|
private static final Uri POWER_BUTTON_LONG_PRESS_URI =
|
||||||
|
Settings.Global.getUriFor(POWER_BUTTON_LONG_PRESS_SETTING);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return current value of power button behaviour.
|
* @return true if long press power for assistant is currently enabled.
|
||||||
*/
|
*/
|
||||||
public static int getPowerButtonSettingValue(Context context) {
|
public static boolean isLongPressPowerForAssistantEnabled(Context context) {
|
||||||
return Settings.Global.getInt(context.getContentResolver(),
|
int longPressPowerSettingValue = Settings.Global.getInt(
|
||||||
|
context.getContentResolver(),
|
||||||
POWER_BUTTON_LONG_PRESS_SETTING,
|
POWER_BUTTON_LONG_PRESS_SETTING,
|
||||||
context.getResources().getInteger(POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE));
|
context.getResources().getInteger(POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE));
|
||||||
|
return longPressPowerSettingValue == LONG_PRESS_POWER_ASSISTANT_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if long press power for assist is currently enabled.
|
* @return true if long press power for assistant setting is available on the device.
|
||||||
*/
|
*/
|
||||||
public static boolean isLongPressPowerForAssistEnabled(Context context) {
|
public static boolean isLongPressPowerSettingAvailable(Context context) {
|
||||||
return getPowerButtonSettingValue(context) == LONG_PRESS_POWER_ASSISTANT_VALUE;
|
if (!context.getResources().getBoolean(
|
||||||
|
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable)) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PowerMenuSettingsUtils() {
|
int defaultLongPressPowerSettingValue =
|
||||||
|
context.getResources().getInteger(POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE);
|
||||||
|
switch (defaultLongPressPowerSettingValue) {
|
||||||
|
case LONG_PRESS_POWER_GLOBAL_ACTIONS:
|
||||||
|
case LONG_PRESS_POWER_ASSISTANT_VALUE:
|
||||||
|
// We support switching between Power Menu and Digital Assistant.
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
// All other combinations are not supported.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean setLongPressPowerForAssistant(Context context) {
|
||||||
|
if (Settings.Global.putInt(
|
||||||
|
context.getContentResolver(),
|
||||||
|
POWER_BUTTON_LONG_PRESS_SETTING,
|
||||||
|
LONG_PRESS_POWER_ASSISTANT_VALUE)) {
|
||||||
|
// Make power + volume up buttons to open the power menu
|
||||||
|
Settings.Global.putInt(
|
||||||
|
context.getContentResolver(),
|
||||||
|
KEY_CHORD_POWER_VOLUME_UP_SETTING,
|
||||||
|
KEY_CHORD_POWER_VOLUME_UP_GLOBAL_ACTIONS);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean setLongPressPowerForPowerMenu(Context context) {
|
||||||
|
if (Settings.Global.putInt(
|
||||||
|
context.getContentResolver(),
|
||||||
|
POWER_BUTTON_LONG_PRESS_SETTING,
|
||||||
|
LONG_PRESS_POWER_GLOBAL_ACTIONS)) {
|
||||||
|
// We restore power + volume up buttons to the default action.
|
||||||
|
int keyChordDefaultValue =
|
||||||
|
context.getResources()
|
||||||
|
.getInteger(KEY_CHORD_POWER_VOLUME_UP_DEFAULT_VALUE_RESOURCE);
|
||||||
|
Settings.Global.putInt(
|
||||||
|
context.getContentResolver(),
|
||||||
|
KEY_CHORD_POWER_VOLUME_UP_SETTING,
|
||||||
|
keyChordDefaultValue);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Context mContext;
|
||||||
|
private final SettingsObserver mSettingsObserver;
|
||||||
|
|
||||||
|
PowerMenuSettingsUtils(Context context) {
|
||||||
|
mContext = context;
|
||||||
|
mSettingsObserver = new SettingsObserver(new Handler(Looper.getMainLooper()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers callback for observing SettingsProvider state.
|
||||||
|
*
|
||||||
|
* @param callback for state changes
|
||||||
|
*/
|
||||||
|
public void registerObserver(SettingsStateCallback callback) {
|
||||||
|
mSettingsObserver.setCallback(callback);
|
||||||
|
final ContentResolver resolver = mContext.getContentResolver();
|
||||||
|
resolver.registerContentObserver(POWER_BUTTON_LONG_PRESS_URI, true, mSettingsObserver);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Unregisters callback for observing SettingsProvider state. */
|
||||||
|
public void unregisterObserver() {
|
||||||
|
final ContentResolver resolver = mContext.getContentResolver();
|
||||||
|
resolver.unregisterContentObserver(mSettingsObserver);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** An interface for when SettingsProvider key state changes. */
|
||||||
|
public interface SettingsStateCallback {
|
||||||
|
/** Callback method for SettingsProvider key state changes. */
|
||||||
|
void onChange(Uri uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class SettingsObserver extends ContentObserver {
|
||||||
|
private SettingsStateCallback mCallback;
|
||||||
|
|
||||||
|
SettingsObserver(Handler handler) {
|
||||||
|
super(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setCallback(SettingsStateCallback callback) {
|
||||||
|
mCallback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChange(boolean selfChange, Uri uri) {
|
||||||
|
if (mCallback != null) {
|
||||||
|
mCallback.onChange(uri);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,220 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2021 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.gestures;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import androidx.annotation.StringRes;
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.mockito.stubbing.Answer;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
public class LongPressPowerButtonPreferenceControllerTest {
|
|
||||||
|
|
||||||
private static final String KEY_LONG_PRESS_POWER_BUTTON =
|
|
||||||
"gesture_power_menu_long_press_for_assist";
|
|
||||||
|
|
||||||
private Application mContext;
|
|
||||||
private Resources mResources;
|
|
||||||
private LongPressPowerButtonPreferenceController mController;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
|
||||||
mResources = mock(Resources.class);
|
|
||||||
when(mContext.getResources()).thenReturn(mResources);
|
|
||||||
when(mResources.getString(anyInt())).thenAnswer((Answer<String>) invocation -> {
|
|
||||||
int id = invocation.getArgument(0);
|
|
||||||
return getString(id);
|
|
||||||
});
|
|
||||||
when(mResources.getBoolean(
|
|
||||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
|
||||||
.thenReturn(true);
|
|
||||||
mController = new LongPressPowerButtonPreferenceController(mContext,
|
|
||||||
KEY_LONG_PRESS_POWER_BUTTON);
|
|
||||||
mController.mAssistSwitch = mock(Preference.class);
|
|
||||||
mController.mFooterHint = mock(Preference.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isAvailable_configIsTrue_shouldReturnTrue() {
|
|
||||||
when(mResources.getBoolean(
|
|
||||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
|
||||||
.thenReturn(true);
|
|
||||||
|
|
||||||
assertThat(mController.isAvailable()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isAvailable_configIsFalse_shouldReturnFalse() {
|
|
||||||
when(mResources.getBoolean(
|
|
||||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
|
||||||
.thenReturn(false);
|
|
||||||
|
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void preferenceChecked_powerMenuHintTextShown() {
|
|
||||||
mController.onPreferenceChange(null, true);
|
|
||||||
|
|
||||||
verify(mController.mFooterHint).setSummary(
|
|
||||||
getString(
|
|
||||||
R.string.power_menu_power_volume_up_hint));
|
|
||||||
verify(mController.mFooterHint).setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void preferenceUnchecked_keyChordEnabled_powerMenuHintTextShown() {
|
|
||||||
when(mResources.getInteger(
|
|
||||||
com.android.internal.R.integer.config_keyChordPowerVolumeUp))
|
|
||||||
.thenReturn(
|
|
||||||
LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_GLOBAL_ACTIONS);
|
|
||||||
|
|
||||||
mController.onPreferenceChange(null, false);
|
|
||||||
|
|
||||||
verify(mController.mFooterHint).setSummary(
|
|
||||||
getString(
|
|
||||||
R.string.power_menu_power_volume_up_hint));
|
|
||||||
verify(mController.mFooterHint).setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void preferenceChecked_hushGestureEnabled_powerMenuHintTextIncludesHushHint() {
|
|
||||||
when(mResources.getBoolean(
|
|
||||||
com.android.internal.R.bool.config_volumeHushGestureEnabled))
|
|
||||||
.thenReturn(true);
|
|
||||||
|
|
||||||
mController.onPreferenceChange(null, true);
|
|
||||||
|
|
||||||
verify(mController.mFooterHint).setSummary(
|
|
||||||
getString(
|
|
||||||
R.string.power_menu_power_volume_up_hint) + "\n\n"
|
|
||||||
+ getString(
|
|
||||||
R.string.power_menu_power_prevent_ringing_hint));
|
|
||||||
verify(mController.mFooterHint).setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void preferenceUnchecked_keyChordDisabled_powerMenuHintTextHidden() {
|
|
||||||
mController.onPreferenceChange(null, false);
|
|
||||||
when(mResources.getInteger(
|
|
||||||
com.android.internal.R.integer.config_keyChordPowerVolumeUp))
|
|
||||||
.thenReturn(
|
|
||||||
LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_NO_ACTION);
|
|
||||||
|
|
||||||
verify(mController.mFooterHint).setVisible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void preferenceChecked_longPressPowerSettingSetToAssistant() {
|
|
||||||
mController.onPreferenceChange(null, true);
|
|
||||||
|
|
||||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
|
||||||
Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo(
|
|
||||||
PowerMenuSettingsUtils.LONG_PRESS_POWER_ASSISTANT_VALUE);
|
|
||||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
|
||||||
Settings.Global.KEY_CHORD_POWER_VOLUME_UP, -1)).isEqualTo(
|
|
||||||
LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_GLOBAL_ACTIONS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void preferenceUnchecked_longPressPowerSettingSetToDefaultValue() {
|
|
||||||
when(mResources.getInteger(
|
|
||||||
com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
|
||||||
.thenReturn(
|
|
||||||
PowerMenuSettingsUtils.LONG_PRESS_POWER_GLOBAL_ACTIONS);
|
|
||||||
|
|
||||||
mController.onPreferenceChange(null, false);
|
|
||||||
|
|
||||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
|
||||||
Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo(
|
|
||||||
PowerMenuSettingsUtils.LONG_PRESS_POWER_GLOBAL_ACTIONS);
|
|
||||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
|
||||||
Settings.Global.KEY_CHORD_POWER_VOLUME_UP, -1)).isEqualTo(
|
|
||||||
LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_NO_ACTION);
|
|
||||||
verify(mController.mAssistSwitch).setSummary(
|
|
||||||
getString(
|
|
||||||
R.string.power_menu_summary_long_press_for_assist_disabled_with_power_menu));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void preferenceUnchecked_muteChordDefault_longPressPowerSettingSetToDefaultValue() {
|
|
||||||
// Value out of range chosen deliberately.
|
|
||||||
when(mResources.getInteger(
|
|
||||||
com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
|
||||||
.thenReturn(8);
|
|
||||||
when(mResources.getInteger(
|
|
||||||
com.android.internal.R.integer.config_keyChordPowerVolumeUp))
|
|
||||||
.thenReturn(
|
|
||||||
LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_MUTE_TOGGLE);
|
|
||||||
|
|
||||||
mController.onPreferenceChange(null, false);
|
|
||||||
|
|
||||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
|
||||||
Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo(8);
|
|
||||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
|
||||||
Settings.Global.KEY_CHORD_POWER_VOLUME_UP, -1)).isEqualTo(
|
|
||||||
LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_MUTE_TOGGLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void preferenceUnchecked_assistDefault_setNoAction() {
|
|
||||||
// Ensure that the Assistant is the default behavior for LPP.
|
|
||||||
when(mResources.getInteger(
|
|
||||||
com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
|
||||||
.thenReturn(
|
|
||||||
PowerMenuSettingsUtils.LONG_PRESS_POWER_ASSISTANT_VALUE);
|
|
||||||
|
|
||||||
mController.onPreferenceChange(null, false);
|
|
||||||
|
|
||||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
|
||||||
Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo(
|
|
||||||
PowerMenuSettingsUtils.LONG_PRESS_POWER_GLOBAL_ACTIONS);
|
|
||||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
|
||||||
Settings.Global.KEY_CHORD_POWER_VOLUME_UP, -1)).isEqualTo(
|
|
||||||
LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_NO_ACTION);
|
|
||||||
verify(mController.mAssistSwitch).setSummary(getString(
|
|
||||||
R.string.power_menu_summary_long_press_for_assist_disabled_with_power_menu));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getString(@StringRes int id) {
|
|
||||||
return ApplicationProvider.getApplicationContext().getString(id);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,115 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.gestures;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settingslib.widget.FooterPreference;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
public class LongPressPowerFooterPreferenceControllerTest {
|
||||||
|
|
||||||
|
private Application mContext;
|
||||||
|
private Resources mResources;
|
||||||
|
private Preference mPreference;
|
||||||
|
private LongPressPowerFooterPreferenceController mController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
|
mResources = spy(mContext.getResources());
|
||||||
|
when(mContext.getResources()).thenReturn(mResources);
|
||||||
|
mPreference = new FooterPreference(mContext);
|
||||||
|
mController = new LongPressPowerFooterPreferenceController(mContext, "test_key");
|
||||||
|
|
||||||
|
PreferenceScreen mScreen = mock(PreferenceScreen.class);
|
||||||
|
when(mScreen.findPreference("test_key")).thenReturn(mPreference);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_longPressPowerForPowerMenu_hidesPreference() {
|
||||||
|
PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
|
||||||
|
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
|
assertThat(mPreference.isVisible()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_longPressPowerForAssistant_showsPreference() {
|
||||||
|
PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
|
||||||
|
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
|
assertThat(mPreference.isVisible()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_notEligible_showsPreference() {
|
||||||
|
PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
|
||||||
|
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
|
assertThat(mPreference.isVisible()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_hushGestureEnabled_includesPreventRingingHint() {
|
||||||
|
when(mResources.getBoolean(com.android.internal.R.bool.config_volumeHushGestureEnabled))
|
||||||
|
.thenReturn(true);
|
||||||
|
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
|
assertThat(mPreference.getSummary().toString())
|
||||||
|
.isEqualTo(
|
||||||
|
TextUtils.concat(
|
||||||
|
mContext.getString(R.string.power_menu_power_volume_up_hint),
|
||||||
|
"\n\n",
|
||||||
|
mContext.getString(
|
||||||
|
R.string.power_menu_power_prevent_ringing_hint)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_hushGestureDisabled_doesNotIncludePreventRingingHint() {
|
||||||
|
when(mResources.getBoolean(com.android.internal.R.bool.config_volumeHushGestureEnabled))
|
||||||
|
.thenReturn(false);
|
||||||
|
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
|
assertThat(mPreference.getSummary().toString())
|
||||||
|
.isEqualTo(mContext.getString(R.string.power_menu_power_volume_up_hint));
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,116 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.gestures;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settingslib.widget.SelectorWithWidgetPreference;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
public class LongPressPowerForAssistantPreferenceControllerTest {
|
||||||
|
|
||||||
|
private Application mContext;
|
||||||
|
private Resources mResources;
|
||||||
|
private SelectorWithWidgetPreference mPreference;
|
||||||
|
private LongPressPowerForAssistantPreferenceController mController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
|
mResources = spy(mContext.getResources());
|
||||||
|
mPreference = new SelectorWithWidgetPreference(mContext);
|
||||||
|
mController = new LongPressPowerForAssistantPreferenceController(mContext, "test_key");
|
||||||
|
|
||||||
|
when(mContext.getResources()).thenReturn(mResources);
|
||||||
|
when(mResources.getBoolean(
|
||||||
|
com.android.internal.R.bool
|
||||||
|
.config_longPressOnPowerForAssistantSettingAvailable))
|
||||||
|
.thenReturn(true);
|
||||||
|
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||||
|
.thenReturn(5); // Default to Assistant
|
||||||
|
|
||||||
|
PreferenceScreen mScreen = mock(PreferenceScreen.class);
|
||||||
|
when(mScreen.findPreference("test_key")).thenReturn(mPreference);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
mController.onStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void initialState_longPressPowerForPowerMenu_preferenceNotChecked() {
|
||||||
|
PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
|
||||||
|
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
|
assertThat(mPreference.isChecked()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void initialState_longPressPowerForAssistant_preferenceChecked() {
|
||||||
|
PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
|
||||||
|
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
|
assertThat(mPreference.isChecked()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_longPressPowerSettingAvailable_returnsAvailable() {
|
||||||
|
assertThat(mController.getAvailabilityStatus())
|
||||||
|
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_longPressPowerSettingNotAvailable_returnsNotAvailable() {
|
||||||
|
when(mResources.getBoolean(
|
||||||
|
com.android.internal.R.bool
|
||||||
|
.config_longPressOnPowerForAssistantSettingAvailable))
|
||||||
|
.thenReturn(false);
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus())
|
||||||
|
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onClick_updatesSettingsValue_checksPreference() {
|
||||||
|
// Initial state: preference not checked
|
||||||
|
PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)).isFalse();
|
||||||
|
assertThat(mPreference.isChecked()).isFalse();
|
||||||
|
|
||||||
|
mPreference.performClick();
|
||||||
|
|
||||||
|
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)).isTrue();
|
||||||
|
assertThat(mPreference.isChecked()).isTrue();
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,116 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.gestures;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settingslib.widget.SelectorWithWidgetPreference;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
public class LongPressPowerForPowerMenuPreferenceControllerTest {
|
||||||
|
|
||||||
|
private Application mContext;
|
||||||
|
private Resources mResources;
|
||||||
|
private SelectorWithWidgetPreference mPreference;
|
||||||
|
private LongPressPowerForPowerMenuPreferenceController mController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
|
mResources = spy(mContext.getResources());
|
||||||
|
mPreference = new SelectorWithWidgetPreference(mContext);
|
||||||
|
mController = new LongPressPowerForPowerMenuPreferenceController(mContext, "test_key");
|
||||||
|
|
||||||
|
when(mContext.getResources()).thenReturn(mResources);
|
||||||
|
when(mResources.getBoolean(
|
||||||
|
com.android.internal.R.bool
|
||||||
|
.config_longPressOnPowerForAssistantSettingAvailable))
|
||||||
|
.thenReturn(true);
|
||||||
|
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||||
|
.thenReturn(5); // Default to Assistant
|
||||||
|
|
||||||
|
PreferenceScreen mScreen = mock(PreferenceScreen.class);
|
||||||
|
when(mScreen.findPreference("test_key")).thenReturn(mPreference);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
mController.onStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void initialState_longPressPowerForPowerMenu_preferenceChecked() {
|
||||||
|
PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
|
||||||
|
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
|
assertThat(mPreference.isChecked()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void initialState_longPressPowerForAssistant_preferenceNotChecked() {
|
||||||
|
PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
|
||||||
|
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
|
assertThat(mPreference.isChecked()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_longPressPowerSettingAvailable_returnsAvailable() {
|
||||||
|
assertThat(mController.getAvailabilityStatus())
|
||||||
|
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_longPressPowerSettingNotAvailable_returnsNotAvailable() {
|
||||||
|
when(mResources.getBoolean(
|
||||||
|
com.android.internal.R.bool
|
||||||
|
.config_longPressOnPowerForAssistantSettingAvailable))
|
||||||
|
.thenReturn(false);
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus())
|
||||||
|
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onClick_updatesSettingsValue_checksPreference() {
|
||||||
|
// Initial state: preference not checked
|
||||||
|
PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)).isTrue();
|
||||||
|
assertThat(mPreference.isChecked()).isFalse();
|
||||||
|
|
||||||
|
mPreference.performClick();
|
||||||
|
|
||||||
|
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)).isFalse();
|
||||||
|
assertThat(mPreference.isChecked()).isTrue();
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.gestures;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settingslib.widget.IllustrationPreference;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
public class LongPressPowerIllustrationPreferenceControllerTest {
|
||||||
|
|
||||||
|
private Application mContext;
|
||||||
|
private IllustrationPreference mPreference;
|
||||||
|
private LongPressPowerIllustrationPreferenceController mController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mContext = ApplicationProvider.getApplicationContext();
|
||||||
|
mPreference = new IllustrationPreference(mContext);
|
||||||
|
mController = new LongPressPowerIllustrationPreferenceController(mContext, "test_key");
|
||||||
|
|
||||||
|
PreferenceScreen mScreen = mock(PreferenceScreen.class);
|
||||||
|
when(mScreen.findPreference("test_key")).thenReturn(mPreference);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_longPressPowerForPowerMenu_showsPowerMenuAnimation() {
|
||||||
|
PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
|
||||||
|
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
|
assertThat(mPreference.getLottieAnimationResId())
|
||||||
|
.isEqualTo(R.raw.lottie_long_press_power_for_power_menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_longPressPowerForAssistant_showsAssistantAnimation() {
|
||||||
|
PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
|
||||||
|
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
|
assertThat(mPreference.getLottieAnimationResId())
|
||||||
|
.isEqualTo(R.raw.lottie_long_press_power_for_assistant);
|
||||||
|
}
|
||||||
|
}
|
@@ -26,14 +26,20 @@ import android.app.Application;
|
|||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
|
import com.android.settings.widget.LabeledSeekBarPreference;
|
||||||
|
import com.android.settingslib.testutils.shadow.ShadowInteractionJankMonitor;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(shadows = {ShadowInteractionJankMonitor.class})
|
||||||
public class LongPressPowerSensitivityPreferenceControllerTest {
|
public class LongPressPowerSensitivityPreferenceControllerTest {
|
||||||
|
|
||||||
private static final String KEY_LONG_PRESS_SENSITIVITY =
|
private static final String KEY_LONG_PRESS_SENSITIVITY =
|
||||||
@@ -43,7 +49,9 @@ public class LongPressPowerSensitivityPreferenceControllerTest {
|
|||||||
|
|
||||||
private Application mContext;
|
private Application mContext;
|
||||||
private Resources mResources;
|
private Resources mResources;
|
||||||
|
private LabeledSeekBarPreference mPreference;
|
||||||
private LongPressPowerSensitivityPreferenceController mController;
|
private LongPressPowerSensitivityPreferenceController mController;
|
||||||
|
private PreferenceScreen mScreen;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -54,9 +62,20 @@ public class LongPressPowerSensitivityPreferenceControllerTest {
|
|||||||
when(mResources.getIntArray(
|
when(mResources.getIntArray(
|
||||||
com.android.internal.R.array.config_longPressOnPowerDurationSettings))
|
com.android.internal.R.array.config_longPressOnPowerDurationSettings))
|
||||||
.thenReturn(SENSITIVITY_VALUES);
|
.thenReturn(SENSITIVITY_VALUES);
|
||||||
|
when(mResources.getBoolean(
|
||||||
|
com.android.internal.R.bool
|
||||||
|
.config_longPressOnPowerForAssistantSettingAvailable))
|
||||||
|
.thenReturn(true);
|
||||||
|
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||||
|
.thenReturn(5); // Default to Assistant
|
||||||
|
|
||||||
|
mPreference = new LabeledSeekBarPreference(mContext, null);
|
||||||
mController = new LongPressPowerSensitivityPreferenceController(mContext,
|
mController = new LongPressPowerSensitivityPreferenceController(mContext,
|
||||||
KEY_LONG_PRESS_SENSITIVITY);
|
KEY_LONG_PRESS_SENSITIVITY);
|
||||||
|
|
||||||
|
mScreen = mock(PreferenceScreen.class);
|
||||||
|
when(mScreen.findPreference(KEY_LONG_PRESS_SENSITIVITY)).thenReturn(mPreference);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -98,46 +117,64 @@ public class LongPressPowerSensitivityPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void longPressForAssistEnabled_isAvailable() {
|
public void longPressForAssistant_isVisible() {
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
|
||||||
Settings.Global.POWER_BUTTON_LONG_PRESS,
|
|
||||||
PowerMenuSettingsUtils.LONG_PRESS_POWER_ASSISTANT_VALUE);
|
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
mController.updateState(mPreference);
|
||||||
LongPressPowerSensitivityPreferenceController.AVAILABLE);
|
|
||||||
|
assertThat(mPreference.isVisible()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void longPressForAssistDisabled_isNotAvailableDueToDependentSetting() {
|
public void longPressForPowerMenu_isHidden() {
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
|
||||||
Settings.Global.POWER_BUTTON_LONG_PRESS,
|
|
||||||
PowerMenuSettingsUtils.LONG_PRESS_POWER_NO_ACTION);
|
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
mController.updateState(mPreference);
|
||||||
LongPressPowerSensitivityPreferenceController.DISABLED_DEPENDENT_SETTING);
|
|
||||||
|
assertThat(mPreference.isVisible()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sensitivityValuesAreNull_notAvailable() {
|
public void longPressPowerSettingNotAvailable_notAvailable_isHidden() {
|
||||||
|
when(mResources.getBoolean(
|
||||||
|
com.android.internal.R.bool
|
||||||
|
.config_longPressOnPowerForAssistantSettingAvailable))
|
||||||
|
.thenReturn(false);
|
||||||
|
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus())
|
||||||
|
.isEqualTo(LongPressPowerSensitivityPreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||||
|
assertThat(mPreference.isVisible()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void sensitivityValuesAreNull_notAvailable_isHidden() {
|
||||||
when(mResources.getIntArray(
|
when(mResources.getIntArray(
|
||||||
com.android.internal.R.array.config_longPressOnPowerDurationSettings))
|
com.android.internal.R.array.config_longPressOnPowerDurationSettings))
|
||||||
.thenReturn(null);
|
.thenReturn(null);
|
||||||
mController = new LongPressPowerSensitivityPreferenceController(mContext,
|
mController = new LongPressPowerSensitivityPreferenceController(mContext,
|
||||||
KEY_LONG_PRESS_SENSITIVITY);
|
KEY_LONG_PRESS_SENSITIVITY);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||||
LongPressPowerSensitivityPreferenceController.UNSUPPORTED_ON_DEVICE);
|
LongPressPowerSensitivityPreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||||
|
assertThat(mPreference.isVisible()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sensitivityValuesArrayTooShort_notAvailable() {
|
public void sensitivityValuesArrayTooShort_notAvailable_isHidden() {
|
||||||
when(mResources.getIntArray(
|
when(mResources.getIntArray(
|
||||||
com.android.internal.R.array.config_longPressOnPowerDurationSettings))
|
com.android.internal.R.array.config_longPressOnPowerDurationSettings))
|
||||||
.thenReturn(new int[]{200});
|
.thenReturn(new int[]{200});
|
||||||
mController = new LongPressPowerSensitivityPreferenceController(mContext,
|
mController = new LongPressPowerSensitivityPreferenceController(mContext,
|
||||||
KEY_LONG_PRESS_SENSITIVITY);
|
KEY_LONG_PRESS_SENSITIVITY);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||||
LongPressPowerSensitivityPreferenceController.UNSUPPORTED_ON_DEVICE);
|
LongPressPowerSensitivityPreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||||
|
assertThat(mPreference.isVisible()).isFalse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,20 +18,21 @@ package com.android.settings.gestures;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class PowerMenuPreferenceControllerTest {
|
public class PowerMenuPreferenceControllerTest {
|
||||||
@@ -41,35 +42,75 @@ public class PowerMenuPreferenceControllerTest {
|
|||||||
|
|
||||||
private static final String KEY_GESTURE_POWER_MENU = "gesture_power_menu";
|
private static final String KEY_GESTURE_POWER_MENU = "gesture_power_menu";
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mContext = spy(RuntimeEnvironment.application);
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
mResources = mock(Resources.class);
|
mResources = spy(mContext.getResources());
|
||||||
when(mResources.getBoolean(
|
|
||||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
|
||||||
.thenReturn(true);
|
|
||||||
when(mContext.getResources()).thenReturn(mResources);
|
|
||||||
mController = new PowerMenuPreferenceController(mContext, KEY_GESTURE_POWER_MENU);
|
mController = new PowerMenuPreferenceController(mContext, KEY_GESTURE_POWER_MENU);
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
when(mContext.getResources()).thenReturn(mResources);
|
||||||
public void getAvailabilityStatus_assistAvailable_available() {
|
|
||||||
when(mResources.getBoolean(
|
when(mResources.getBoolean(
|
||||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
com.android.internal.R.bool
|
||||||
|
.config_longPressOnPowerForAssistantSettingAvailable))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
|
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
.thenReturn(1); // Default to power menu
|
||||||
BasePreferenceController.AVAILABLE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_assistUnavailable_unavailable() {
|
public void getAvailabilityStatus_settingsAvailable_returnsAvailable() {
|
||||||
when(mResources.getBoolean(
|
when(mResources.getBoolean(
|
||||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
com.android.internal.R.bool
|
||||||
.thenReturn(false);
|
.config_longPressOnPowerForAssistantSettingAvailable))
|
||||||
|
.thenReturn(true);
|
||||||
|
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||||
|
.thenReturn(1); // Default to power menu
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
assertThat(mController.getAvailabilityStatus())
|
||||||
BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_settingsNotAvailable_returnsNotAvailable() {
|
||||||
|
when(mResources.getBoolean(
|
||||||
|
com.android.internal.R.bool
|
||||||
|
.config_longPressOnPowerForAssistantSettingAvailable))
|
||||||
|
.thenReturn(false);
|
||||||
|
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||||
|
.thenReturn(1); // Default to power menu
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus())
|
||||||
|
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_longPressPowerSettingNotAvailable_returnsNotAvailable() {
|
||||||
|
when(mResources.getBoolean(
|
||||||
|
com.android.internal.R.bool
|
||||||
|
.config_longPressOnPowerForAssistantSettingAvailable))
|
||||||
|
.thenReturn(true);
|
||||||
|
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||||
|
.thenReturn(3); // Default to power off (unsupported setup)
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus())
|
||||||
|
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSummary_longPressPowerToAssistant_returnsNotAvailable() {
|
||||||
|
PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
|
||||||
|
|
||||||
|
assertThat(mController.getSummary().toString())
|
||||||
|
.isEqualTo(
|
||||||
|
mContext.getString(R.string.power_menu_summary_long_press_for_assistant));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSummary_longPressPowerToPowerMenu_returnsNotAvailable() {
|
||||||
|
PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
|
||||||
|
|
||||||
|
assertThat(mController.getSummary().toString())
|
||||||
|
.isEqualTo(
|
||||||
|
mContext.getString(R.string.power_menu_summary_long_press_for_power_menu));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -44,48 +44,123 @@ public class PowerMenuSettingsUtilsTest {
|
|||||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
mResources = mock(Resources.class);
|
mResources = mock(Resources.class);
|
||||||
when(mContext.getResources()).thenReturn(mResources);
|
when(mContext.getResources()).thenReturn(mResources);
|
||||||
|
|
||||||
|
when(mResources.getBoolean(
|
||||||
|
com.android.internal.R.bool
|
||||||
|
.config_longPressOnPowerForAssistantSettingAvailable))
|
||||||
|
.thenReturn(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void longPressBehaviourValuePresent_returnsValue() {
|
public void isLongPressPowerForAssistantEnabled_valueSetToAssistant_returnsTrue() {
|
||||||
when(mResources.getInteger(
|
Settings.Global.putInt(
|
||||||
com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
mContext.getContentResolver(), Settings.Global.POWER_BUTTON_LONG_PRESS, 5);
|
||||||
.thenReturn(0);
|
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)).isTrue();
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
|
||||||
Settings.Global.POWER_BUTTON_LONG_PRESS, 1);
|
|
||||||
|
|
||||||
assertThat(PowerMenuSettingsUtils.getPowerButtonSettingValue(mContext)).isEqualTo(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void longPressBehaviourValueNotPresent_returnsDefault() {
|
public void isLongPressPowerForAssistantEnabled_valueNotSetToAssistant_returnsFalse() {
|
||||||
when(mResources.getInteger(
|
Settings.Global.putInt(
|
||||||
com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
mContext.getContentResolver(), Settings.Global.POWER_BUTTON_LONG_PRESS, 3);
|
||||||
.thenReturn(2);
|
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)).isFalse();
|
||||||
|
|
||||||
assertThat(PowerMenuSettingsUtils.getPowerButtonSettingValue(mContext)).isEqualTo(2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void longPressBehaviourValueSetToAssistant_isAssistEnabledReturnsTrue() {
|
public void isLongPressPowerForAssistantEnabled_valueNotSet_defaultToAssistant_returnsTrue() {
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||||
Settings.Global.POWER_BUTTON_LONG_PRESS, 5);
|
.thenReturn(5);
|
||||||
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext)).isTrue();
|
|
||||||
|
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void longPressBehaviourValueNotSetToAssistant_isAssistEnabledReturnsFalse() {
|
public void isLongPressPowerForAssistantEnabled_valueNotSet_defaultToPowerMenu_returnsFalse() {
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||||
Settings.Global.POWER_BUTTON_LONG_PRESS, 3);
|
.thenReturn(1);
|
||||||
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext)).isFalse();
|
|
||||||
|
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void longPressBehaviourDefaultSetToAssistant_isAssistEnabledReturnsFalse() {
|
public void isLongPressPowerSettingAvailable_defaultToAssistant_returnsTrue() {
|
||||||
when(mResources.getInteger(
|
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||||
com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
.thenReturn(5);
|
||||||
|
assertThat(PowerMenuSettingsUtils.isLongPressPowerSettingAvailable(mContext)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isLongPressPowerSettingAvailable_defaultToPowerMenu_returnsTrue() {
|
||||||
|
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||||
|
.thenReturn(1);
|
||||||
|
assertThat(PowerMenuSettingsUtils.isLongPressPowerSettingAvailable(mContext)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isLongPressPowerSettingAvailable_defaultToPowerOff_returnsFalse() {
|
||||||
|
// Power off is the unsupported option in long press power settings
|
||||||
|
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||||
.thenReturn(3);
|
.thenReturn(3);
|
||||||
|
assertThat(PowerMenuSettingsUtils.isLongPressPowerSettingAvailable(mContext)).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext)).isFalse();
|
@Test
|
||||||
|
public void isLongPressPowerSettingAvailable_settingDisabled_returnsFalse() {
|
||||||
|
// Disable the setting
|
||||||
|
when(mResources.getBoolean(
|
||||||
|
com.android.internal.R.bool
|
||||||
|
.config_longPressOnPowerForAssistantSettingAvailable))
|
||||||
|
.thenReturn(false);
|
||||||
|
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||||
|
.thenReturn(1);
|
||||||
|
|
||||||
|
assertThat(PowerMenuSettingsUtils.isLongPressPowerSettingAvailable(mContext)).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setLongPressPowerForAssistant_updatesValue() throws Exception {
|
||||||
|
boolean result = PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
|
||||||
|
|
||||||
|
assertThat(result).isTrue();
|
||||||
|
assertThat(
|
||||||
|
Settings.Global.getInt(
|
||||||
|
mContext.getContentResolver(),
|
||||||
|
Settings.Global.POWER_BUTTON_LONG_PRESS))
|
||||||
|
.isEqualTo(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setLongPressPowerForAssistant_updatesKeyChordValueToPowerMenu() throws Exception {
|
||||||
|
PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
|
||||||
|
assertThat(
|
||||||
|
Settings.Global.getInt(
|
||||||
|
mContext.getContentResolver(),
|
||||||
|
Settings.Global.KEY_CHORD_POWER_VOLUME_UP))
|
||||||
|
.isEqualTo(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setLongPressPowerForPowerMenu_updatesValue() throws Exception {
|
||||||
|
boolean result = PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
|
||||||
|
|
||||||
|
assertThat(result).isTrue();
|
||||||
|
assertThat(
|
||||||
|
Settings.Global.getInt(
|
||||||
|
mContext.getContentResolver(),
|
||||||
|
Settings.Global.POWER_BUTTON_LONG_PRESS))
|
||||||
|
.isEqualTo(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setLongPressPowerForPowerMenu_updatesKeyChordValueToDefault() throws Exception {
|
||||||
|
when(mResources.getInteger(com.android.internal.R.integer.config_keyChordPowerVolumeUp))
|
||||||
|
.thenReturn(1);
|
||||||
|
|
||||||
|
PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
|
||||||
|
|
||||||
|
assertThat(
|
||||||
|
Settings.Global.getInt(
|
||||||
|
mContext.getContentResolver(),
|
||||||
|
Settings.Global.KEY_CHORD_POWER_VOLUME_UP))
|
||||||
|
.isEqualTo(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user