Merge "Support Double Tap Power to open camera via config resource" into main

This commit is contained in:
Lorenzo Lucena Maguire
2025-01-07 12:06:03 -08:00
committed by Android (Google) Code Review
12 changed files with 285 additions and 112 deletions

View File

@@ -65,7 +65,8 @@ public class DoubleTapPowerForCameraPreferenceController extends BasePreferenceC
@Override
public int getAvailabilityStatus() {
if (!DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureAvailable(mContext)) {
if (!DoubleTapPowerSettingsUtils
.isMultiTargetDoubleTapPowerButtonGestureAvailable(mContext)) {
return UNSUPPORTED_ON_DEVICE;
}
return DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(mContext)

View File

@@ -65,7 +65,8 @@ public class DoubleTapPowerForWalletPreferenceController extends BasePreferenceC
@Override
public int getAvailabilityStatus() {
if (!DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureAvailable(mContext)) {
if (!DoubleTapPowerSettingsUtils
.isMultiTargetDoubleTapPowerButtonGestureAvailable(mContext)) {
return UNSUPPORTED_ON_DEVICE;
}
return DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(mContext)

View File

@@ -57,7 +57,8 @@ public class DoubleTapPowerMainSwitchPreferenceController
@Override
public int getAvailabilityStatus() {
return DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureAvailable(mContext)
return DoubleTapPowerSettingsUtils
.isMultiTargetDoubleTapPowerButtonGestureAvailable(mContext)
? AVAILABLE
: UNSUPPORTED_ON_DEVICE;
}

View File

@@ -18,6 +18,8 @@ package com.android.settings.gestures;
import static android.provider.Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED;
import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.DOUBLE_TAP_POWER_DISABLED_MODE;
import android.content.Context;
import android.content.SharedPreferences;
import android.provider.Settings;
@@ -37,7 +39,8 @@ public class DoubleTapPowerPreferenceController extends BasePreferenceController
public static boolean isSuggestionComplete(Context context, SharedPreferences prefs) {
return !isGestureAvailable(context)
|| prefs.getBoolean(DoubleTapPowerSettings.PREF_KEY_SUGGESTION_COMPLETE, false);
|| prefs.getBoolean(DoubleTapPowerSettings.PREF_KEY_SUGGESTION_COMPLETE,
false);
}
private static boolean isGestureAvailable(@NonNull Context context) {
@@ -46,7 +49,10 @@ public class DoubleTapPowerPreferenceController extends BasePreferenceController
.getBoolean(
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled);
}
return DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureAvailable(context);
return context.getResources()
.getInteger(
com.android.internal.R.integer.config_doubleTapPowerGestureMode)
!= DOUBLE_TAP_POWER_DISABLED_MODE;
}
@Override
@@ -56,7 +62,9 @@ public class DoubleTapPowerPreferenceController extends BasePreferenceController
@Override
public void displayPreference(@NonNull PreferenceScreen screen) {
if (!android.service.quickaccesswallet.Flags.launchWalletOptionOnPowerDoubleTap()) {
if (!android.service.quickaccesswallet.Flags.launchWalletOptionOnPowerDoubleTap()
|| !DoubleTapPowerSettingsUtils
.isMultiTargetDoubleTapPowerButtonGestureAvailable(mContext)) {
final Preference preference = screen.findPreference(getPreferenceKey());
if (preference != null) {
preference.setTitle(R.string.double_tap_power_for_camera_title);
@@ -68,12 +76,14 @@ public class DoubleTapPowerPreferenceController extends BasePreferenceController
@Override
@NonNull
public CharSequence getSummary() {
if (!android.service.quickaccesswallet.Flags.launchWalletOptionOnPowerDoubleTap()) {
if (!android.service.quickaccesswallet.Flags.launchWalletOptionOnPowerDoubleTap()
|| !DoubleTapPowerSettingsUtils
.isMultiTargetDoubleTapPowerButtonGestureAvailable(mContext)) {
final boolean isCameraDoubleTapPowerGestureEnabled =
Settings.Secure.getInt(
mContext.getContentResolver(),
CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED,
DoubleTapPowerToOpenCameraPreferenceController.ON)
mContext.getContentResolver(),
CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED,
DoubleTapPowerToOpenCameraPreferenceController.ON)
== DoubleTapPowerToOpenCameraPreferenceController.ON;
return mContext.getText(
isCameraDoubleTapPowerGestureEnabled
@@ -85,7 +95,7 @@ public class DoubleTapPowerPreferenceController extends BasePreferenceController
mContext.getText(com.android.settings.R.string.gesture_setting_on);
final CharSequence actionString =
DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(
mContext)
mContext)
? mContext.getText(R.string.double_tap_power_camera_action_summary)
: mContext.getText(R.string.double_tap_power_wallet_action_summary);
return mContext.getString(R.string.double_tap_power_summary, onString, actionString);

View File

@@ -39,9 +39,11 @@ public class DoubleTapPowerSettings extends DashboardFragment {
public static final String PREF_KEY_SUGGESTION_COMPLETE =
"pref_double_tap_power_suggestion_complete";
private Context mContext;
@Override
public void onAttach(Context context) {
mContext = context;
super.onAttach(context);
SuggestionFeatureProvider suggestionFeatureProvider =
FeatureFactory.getFeatureFactory().getSuggestionFeatureProvider();
@@ -61,7 +63,15 @@ public class DoubleTapPowerSettings extends DashboardFragment {
@Override
protected int getPreferenceScreenResId() {
return android.service.quickaccesswallet.Flags.launchWalletOptionOnPowerDoubleTap()
return getDoubleTapPowerSettingsResId(mContext);
}
private static int getDoubleTapPowerSettingsResId(Context context) {
if (!android.service.quickaccesswallet.Flags.launchWalletOptionOnPowerDoubleTap()) {
return R.xml.double_tap_power_to_open_camera_settings;
}
return DoubleTapPowerSettingsUtils
.isMultiTargetDoubleTapPowerButtonGestureAvailable(context)
? R.xml.double_tap_power_settings
: R.xml.double_tap_power_to_open_camera_settings;
}
@@ -73,11 +83,7 @@ public class DoubleTapPowerSettings extends DashboardFragment {
public List<SearchIndexableResource> getXmlResourcesToIndex(
@NonNull Context context, boolean enabled) {
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId =
android.service.quickaccesswallet.Flags
.launchWalletOptionOnPowerDoubleTap()
? R.xml.double_tap_power_settings
: R.xml.double_tap_power_to_open_camera_settings;
sir.xmlResId = getDoubleTapPowerSettingsResId(context);
return List.of(sir);
}
};

View File

@@ -29,6 +29,16 @@ import com.android.internal.R;
/** Common code for double tap power settings shared between controllers. */
final class DoubleTapPowerSettingsUtils {
/** Configuration value indicating double tap power button gesture is disabled. */
static final int DOUBLE_TAP_POWER_DISABLED_MODE = 0;
/** Configuration value indicating double tap power button gesture should launch camera. */
static final int DOUBLE_TAP_POWER_LAUNCH_CAMERA_MODE = 1;
/**
* Configuration value indicating double tap power button gesture should launch one of many
* target actions.
*/
static final int DOUBLE_TAP_POWER_MULTI_TARGET_MODE = 2;
/** Setting storing whether the double tap power button gesture is enabled. */
private static final String DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED =
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED;
@@ -52,19 +62,23 @@ final class DoubleTapPowerSettingsUtils {
/**
* @return true if double tap power button gesture is available.
*/
public static boolean isDoubleTapPowerButtonGestureAvailable(@NonNull Context context) {
return context.getResources().getBoolean(R.bool.config_doubleTapPowerGestureEnabled);
public static boolean isMultiTargetDoubleTapPowerButtonGestureAvailable(
@NonNull Context context) {
return context.getResources()
.getInteger(
R.integer.config_doubleTapPowerGestureMode)
== DOUBLE_TAP_POWER_MULTI_TARGET_MODE;
}
/**
* Gets double tap power button gesture enable or disable flag from Settings provider.
*
* @return true if double tap on the power button gesture is currently enabled.
* @param context App context
* @return true if double tap on the power button gesture is currently enabled.
*/
public static boolean isDoubleTapPowerButtonGestureEnabled(@NonNull Context context) {
return Settings.Secure.getInt(
context.getContentResolver(), DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED, ON)
context.getContentResolver(), DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED, ON)
== ON;
}
@@ -72,7 +86,7 @@ final class DoubleTapPowerSettingsUtils {
* Sets double tap power button gesture enable or disable flag to Settings provider.
*
* @param context App context
* @param enable enable or disable double tap power button gesture.
* @param enable enable or disable double tap power button gesture.
* @return {@code true} if the setting is updated.
*/
public static boolean setDoubleTapPowerButtonGestureEnabled(
@@ -84,19 +98,19 @@ final class DoubleTapPowerSettingsUtils {
}
/**
* @return true if double tap on the power button gesture for camera launch is currently
* enabled.
* @param context App context
* @return true if double tap on the power button gesture for camera launch is currently
* enabled.
*/
public static boolean isDoubleTapPowerButtonGestureForCameraLaunchEnabled(
@NonNull Context context) {
return Settings.Secure.getInt(
context.getContentResolver(),
DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION,
context.getResources()
.getInteger(
com.android.internal.R.integer
.config_defaultDoubleTapPowerGestureAction))
context.getContentResolver(),
DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION,
context.getResources()
.getInteger(
com.android.internal.R.integer
.config_doubleTapPowerGestureMultiTargetDefaultAction))
== DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE;
}

View File

@@ -16,6 +16,9 @@
package com.android.settings.gestures;
import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.DOUBLE_TAP_POWER_DISABLED_MODE;
import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.DOUBLE_TAP_POWER_MULTI_TARGET_MODE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
@@ -72,7 +75,8 @@ public class DoubleTapPowerForCameraPreferenceControllerTest {
@Test
public void getAvailabilityStatus_setDoubleTapPowerGestureNotAvailable_preferenceUnsupported() {
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(false);
when(mResources.getInteger(R.integer.config_doubleTapPowerGestureMode)).thenReturn(
DOUBLE_TAP_POWER_DISABLED_MODE);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
@@ -80,7 +84,8 @@ public class DoubleTapPowerForCameraPreferenceControllerTest {
@Test
public void getAvailabilityStatus_setDoubleTapPowerButtonDisabled_preferenceDisabled() {
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(true);
when(mResources.getInteger(R.integer.config_doubleTapPowerGestureMode)).thenReturn(
DOUBLE_TAP_POWER_MULTI_TARGET_MODE);
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, false);
assertThat(mController.getAvailabilityStatus())
@@ -89,7 +94,8 @@ public class DoubleTapPowerForCameraPreferenceControllerTest {
@Test
public void getAvailabilityStatus_setDoubleTapPowerCameraLaunchEnabled_preferenceEnabled() {
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(true);
when(mResources.getInteger(R.integer.config_doubleTapPowerGestureMode)).thenReturn(
DOUBLE_TAP_POWER_MULTI_TARGET_MODE);
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, true);
assertThat(mController.getAvailabilityStatus())

View File

@@ -16,6 +16,9 @@
package com.android.settings.gestures;
import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.DOUBLE_TAP_POWER_DISABLED_MODE;
import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.DOUBLE_TAP_POWER_MULTI_TARGET_MODE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
@@ -74,7 +77,8 @@ public class DoubleTapPowerForWalletPreferenceControllerTest {
@Test
public void getAvailabilityStatus_setDoubleTapPowerGestureNotAvailable_preferenceUnsupported() {
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(false);
when(mResources.getInteger(R.integer.config_doubleTapPowerGestureMode)).thenReturn(
DOUBLE_TAP_POWER_DISABLED_MODE);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
@@ -82,7 +86,8 @@ public class DoubleTapPowerForWalletPreferenceControllerTest {
@Test
public void getAvailabilityStatus_setDoubleTapPowerButtonDisabled_preferenceDisabled() {
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(true);
when(mResources.getInteger(R.integer.config_doubleTapPowerGestureMode)).thenReturn(
DOUBLE_TAP_POWER_MULTI_TARGET_MODE);
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, false);
assertThat(mController.getAvailabilityStatus())
@@ -91,7 +96,8 @@ public class DoubleTapPowerForWalletPreferenceControllerTest {
@Test
public void getAvailabilityStatus_setDoubleTapPowerWalletLaunchEnabled_preferenceEnabled() {
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(true);
when(mResources.getInteger(R.integer.config_doubleTapPowerGestureMode)).thenReturn(
DOUBLE_TAP_POWER_MULTI_TARGET_MODE);
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, true);
assertThat(mController.getAvailabilityStatus())

View File

@@ -16,6 +16,9 @@
package com.android.settings.gestures;
import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.DOUBLE_TAP_POWER_DISABLED_MODE;
import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.DOUBLE_TAP_POWER_MULTI_TARGET_MODE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
@@ -54,7 +57,8 @@ public class DoubleTapPowerMainSwitchPreferenceControllerTest {
@Test
public void getAvailabilityStatus_setDoubleTapPowerGestureAvailable_preferenceEnabled() {
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(true);
when(mResources.getInteger(R.integer.config_doubleTapPowerGestureMode)).thenReturn(
DOUBLE_TAP_POWER_MULTI_TARGET_MODE);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
@@ -62,7 +66,8 @@ public class DoubleTapPowerMainSwitchPreferenceControllerTest {
@Test
public void getAvailabilityStatus_setDoubleTapPowerGestureUnavailable_preferenceUnsupported() {
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(false);
when(mResources.getInteger(R.integer.config_doubleTapPowerGestureMode)).thenReturn(
DOUBLE_TAP_POWER_DISABLED_MODE);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);

View File

@@ -20,6 +20,9 @@ import static android.provider.Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_D
import static android.provider.Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED;
import static com.android.settings.gestures.DoubleTapPowerPreferenceController.isSuggestionComplete;
import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.DOUBLE_TAP_POWER_DISABLED_MODE;
import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.DOUBLE_TAP_POWER_LAUNCH_CAMERA_MODE;
import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.DOUBLE_TAP_POWER_MULTI_TARGET_MODE;
import static com.android.settings.gestures.DoubleTapPowerToOpenCameraPreferenceController.OFF;
import static com.android.settings.gestures.DoubleTapPowerToOpenCameraPreferenceController.ON;
@@ -58,7 +61,8 @@ import org.robolectric.annotation.Config;
@Config(shadows = SettingsShadowResources.class)
public class DoubleTapPowerPreferenceControllerTest {
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
@Rule
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
private Context mContext;
private ContentResolver mContentResolver;
private DoubleTapPowerPreferenceController mController;
@@ -83,18 +87,30 @@ public class DoubleTapPowerPreferenceControllerTest {
@Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isAvailable_flagEnabled_configIsTrue_returnsTrue() {
public void isAvailable_flagEnabled_configIsMultiTargetMode_returnsTrue() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_doubleTapPowerGestureEnabled, Boolean.TRUE);
com.android.internal.R.integer.config_doubleTapPowerGestureMode,
DOUBLE_TAP_POWER_MULTI_TARGET_MODE);
assertThat(mController.isAvailable()).isTrue();
}
@Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isAvailable_flagEnabled_configIsFalse_returnsFalse() {
public void isAvailable_flagEnabled_configIsCameraLaunchMode_returnsTrue() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_doubleTapPowerGestureEnabled, Boolean.FALSE);
com.android.internal.R.integer.config_doubleTapPowerGestureMode,
DOUBLE_TAP_POWER_LAUNCH_CAMERA_MODE);
assertThat(mController.isAvailable()).isTrue();
}
@Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isAvailable_flagEnabled_configIsDisabledMode_returnsFalse() {
SettingsShadowResources.overrideResource(
com.android.internal.R.integer.config_doubleTapPowerGestureMode,
DOUBLE_TAP_POWER_DISABLED_MODE);
assertThat(mController.isAvailable()).isFalse();
}
@@ -121,18 +137,20 @@ public class DoubleTapPowerPreferenceControllerTest {
@Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isSuggestionCompleted_enableFlag_doubleTapPower_trueWhenNotAvailable() {
public void isSuggestionCompleted_flagEnabled_configIsMultiTargetMode_trueWhenNotAvailable() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_doubleTapPowerGestureEnabled, false);
com.android.internal.R.integer.config_doubleTapPowerGestureMode,
DOUBLE_TAP_POWER_DISABLED_MODE);
assertThat(isSuggestionComplete(mContext, null /* prefs */)).isTrue();
}
@Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isSuggestionCompleted_enableFlag_doubleTapPower_falseWhenNotVisited() {
public void isSuggestionCompleted_enableFlag_configIsMultiTargetMode_falseWhenNotVisited() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_doubleTapPowerGestureEnabled, true);
com.android.internal.R.integer.config_doubleTapPowerGestureMode,
DOUBLE_TAP_POWER_MULTI_TARGET_MODE);
// No stored value in shared preferences if not visited yet.
final SharedPreferences prefs =
new SuggestionFeatureProviderImpl().getSharedPrefs(mContext);
@@ -142,9 +160,10 @@ public class DoubleTapPowerPreferenceControllerTest {
@Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isSuggestionCompleted_enableFlag_doubleTapPower_trueWhenVisited() {
public void isSuggestionCompleted_enableFlag_configIsMultiTargetMode_trueWhenVisited() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_doubleTapPowerGestureEnabled, true);
com.android.internal.R.integer.config_doubleTapPowerGestureMode,
DOUBLE_TAP_POWER_MULTI_TARGET_MODE);
// No stored value in shared preferences if not visited yet.
final SharedPreferences prefs =
new SuggestionFeatureProviderImpl().getSharedPrefs(mContext);
@@ -189,13 +208,30 @@ public class DoubleTapPowerPreferenceControllerTest {
@Test
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void displayPreference_flagDisabled_doubleTapPowerLegacyTitleIsDisplayed() {
public void displayPreference_flagDisabled_cameraLaunchTitleIsDisplayed() {
mController.displayPreference(mScreen);
assertThat(
TextUtils.equals(
mPreference.getTitle(),
mContext.getText(R.string.double_tap_power_for_camera_title)))
TextUtils.equals(
mPreference.getTitle(),
mContext.getText(R.string.double_tap_power_for_camera_title)))
.isTrue();
}
@Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void
displayPreference_flagEnabled_configIsCameraLaunchMode_cameraLaunchTitleIsDisplayed() {
SettingsShadowResources.overrideResource(
com.android.internal.R.integer.config_doubleTapPowerGestureMode,
DOUBLE_TAP_POWER_LAUNCH_CAMERA_MODE);
mController.displayPreference(mScreen);
assertThat(
TextUtils.equals(
mPreference.getTitle(),
mContext.getText(R.string.double_tap_power_for_camera_title)))
.isTrue();
}
@@ -206,9 +242,9 @@ public class DoubleTapPowerPreferenceControllerTest {
Settings.Secure.putInt(mContentResolver, CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, ON);
assertThat(
TextUtils.equals(
mController.getSummary(),
mContext.getText(R.string.gesture_setting_on)))
TextUtils.equals(
mController.getSummary(),
mContext.getText(R.string.gesture_setting_on)))
.isTrue();
}
@@ -219,9 +255,42 @@ public class DoubleTapPowerPreferenceControllerTest {
Settings.Secure.putInt(mContentResolver, CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, OFF);
assertThat(
TextUtils.equals(
mController.getSummary(),
mContext.getText(R.string.gesture_setting_off)))
TextUtils.equals(
mController.getSummary(),
mContext.getText(R.string.gesture_setting_off)))
.isTrue();
}
@Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void getSummary_flagEnabled_doubleTapPowerEnabled_configIsCameraLaunchMode_returnsOn() {
// Set the setting to be enabled.
Settings.Secure.putInt(mContentResolver, CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, ON);
SettingsShadowResources.overrideResource(
com.android.internal.R.integer.config_doubleTapPowerGestureMode,
DOUBLE_TAP_POWER_LAUNCH_CAMERA_MODE);
assertThat(
TextUtils.equals(
mController.getSummary(),
mContext.getText(R.string.gesture_setting_on)))
.isTrue();
}
@Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void
getSummary_flagEnabled_doubleTapPowerDisabled_configIsCameraLaunchMode_returnsOff() {
// Set the setting to be disabled.
Settings.Secure.putInt(mContentResolver, CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, OFF);
SettingsShadowResources.overrideResource(
com.android.internal.R.integer.config_doubleTapPowerGestureMode,
DOUBLE_TAP_POWER_LAUNCH_CAMERA_MODE);
assertThat(
TextUtils.equals(
mController.getSummary(),
mContext.getText(R.string.gesture_setting_off)))
.isTrue();
}
@@ -233,9 +302,9 @@ public class DoubleTapPowerPreferenceControllerTest {
mContentResolver, DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED, 0 /* OFF */);
assertThat(
TextUtils.equals(
mController.getSummary(),
mContext.getText(R.string.gesture_setting_off)))
TextUtils.equals(
mController.getSummary(),
mContext.getText(R.string.gesture_setting_off)))
.isTrue();
}
@@ -248,13 +317,13 @@ public class DoubleTapPowerPreferenceControllerTest {
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForCameraLaunch(mContext);
assertThat(
TextUtils.equals(
mController.getSummary(),
mContext.getString(
R.string.double_tap_power_summary,
mContext.getText(R.string.gesture_setting_on),
mContext.getText(
R.string.double_tap_power_camera_action_summary))))
TextUtils.equals(
mController.getSummary(),
mContext.getString(
R.string.double_tap_power_summary,
mContext.getText(R.string.gesture_setting_on),
mContext.getText(
R.string.double_tap_power_camera_action_summary))))
.isTrue();
}
@@ -267,13 +336,13 @@ public class DoubleTapPowerPreferenceControllerTest {
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForWalletLaunch(mContext);
assertThat(
TextUtils.equals(
mController.getSummary(),
mContext.getString(
R.string.double_tap_power_summary,
mContext.getText(R.string.gesture_setting_on),
mContext.getText(
R.string.double_tap_power_wallet_action_summary))))
TextUtils.equals(
mController.getSummary(),
mContext.getString(
R.string.double_tap_power_summary,
mContext.getText(R.string.gesture_setting_on),
mContext.getText(
R.string.double_tap_power_wallet_action_summary))))
.isTrue();
}
}

View File

@@ -16,6 +16,9 @@
package com.android.settings.gestures;
import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.DOUBLE_TAP_POWER_LAUNCH_CAMERA_MODE;
import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.DOUBLE_TAP_POWER_MULTI_TARGET_MODE;
import static com.google.common.truth.Truth.assertThat;
import android.platform.test.annotations.DisableFlags;
@@ -25,6 +28,7 @@ import android.provider.SearchIndexableResource;
import android.service.quickaccesswallet.Flags;
import com.android.settings.R;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import org.junit.Before;
import org.junit.Rule;
@@ -32,13 +36,16 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.List;
@Config(shadows = SettingsShadowResources.class)
@RunWith(RobolectricTestRunner.class)
public class DoubleTapPowerSettingsTest {
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
@Rule
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
private DoubleTapPowerSettings mSettings;
@Before
@@ -48,10 +55,29 @@ public class DoubleTapPowerSettingsTest {
@Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void getPreferenceScreenResId_flagEnabled_returnsFlagEnabledResId() {
public void
getPreferenceScreenResId_flagEnabled_configIsMultiTargetMode_returnsMultiTargetResId() {
SettingsShadowResources.overrideResource(
com.android.internal.R.integer.config_doubleTapPowerGestureMode,
DOUBLE_TAP_POWER_MULTI_TARGET_MODE);
mSettings.onAttach(RuntimeEnvironment.getApplication());
assertThat(mSettings.getPreferenceScreenResId()).isEqualTo(R.xml.double_tap_power_settings);
}
@Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void
getPreferenceScreenResId_flagEnabled_configIsCameraMode_returnsCameraLaunchResId() {
SettingsShadowResources.overrideResource(
com.android.internal.R.integer.config_doubleTapPowerGestureMode,
DOUBLE_TAP_POWER_LAUNCH_CAMERA_MODE);
mSettings.onAttach(RuntimeEnvironment.getApplication());
assertThat(mSettings.getPreferenceScreenResId()).isEqualTo(
R.xml.double_tap_power_to_open_camera_settings);
}
@Test
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void getPreferenceScreenResId_flagDisabled_returnsFlagDisabledResId() {
@@ -61,7 +87,12 @@ public class DoubleTapPowerSettingsTest {
@Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void testSearchIndexProvider_flagEnabled_shouldIndexFlagEnabledResource() {
public void
testSearchIndexProvider_flagEnabled_configIsMultiTargetMode_indexMultiTargetResId() {
SettingsShadowResources.overrideResource(
com.android.internal.R.integer.config_doubleTapPowerGestureMode,
DOUBLE_TAP_POWER_MULTI_TARGET_MODE);
final List<SearchIndexableResource> indexRes =
DoubleTapPowerSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
RuntimeEnvironment.getApplication(), true /* enabled */);
@@ -70,9 +101,26 @@ public class DoubleTapPowerSettingsTest {
assertThat(indexRes.get(0).xmlResId).isEqualTo(R.xml.double_tap_power_settings);
}
@Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void
testSearchIndexProvider_flagEnabled_configIsCameraLaunchMode_indexCameraLaunchResId() {
SettingsShadowResources.overrideResource(
com.android.internal.R.integer.config_doubleTapPowerGestureMode,
DOUBLE_TAP_POWER_LAUNCH_CAMERA_MODE);
final List<SearchIndexableResource> indexRes =
DoubleTapPowerSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
RuntimeEnvironment.getApplication(), true /* enabled */);
assertThat(indexRes).isNotNull();
assertThat(indexRes.get(0).xmlResId).isEqualTo(
R.xml.double_tap_power_to_open_camera_settings);
}
@Test
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void testSearchIndexProvider_flagDisabled_shouldIndexFlagDisabledResource() {
public void testSearchIndexProvider_flagDisabled_indexFlagDisabledResource() {
final List<SearchIndexableResource> indexRes =
DoubleTapPowerSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
RuntimeEnvironment.getApplication(), true /* enabled */);

View File

@@ -16,6 +16,8 @@
package com.android.settings.gestures;
import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.DOUBLE_TAP_POWER_DISABLED_MODE;
import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.DOUBLE_TAP_POWER_MULTI_TARGET_MODE;
import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.OFF;
import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.ON;
@@ -55,18 +57,22 @@ public class DoubleTapPowerSettingsUtilsTest {
}
@Test
public void isDoubleTapPowerButtonGestureAvailable_setAvailable_returnsTrue() {
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(true);
public void isMultiTargetDoubleTapPowerButtonGestureAvailable_setAvailable_returnsTrue() {
when(mResources.getInteger(R.integer.config_doubleTapPowerGestureMode)).thenReturn(
DOUBLE_TAP_POWER_MULTI_TARGET_MODE);
assertThat(DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureAvailable(mContext))
assertThat(DoubleTapPowerSettingsUtils.isMultiTargetDoubleTapPowerButtonGestureAvailable(
mContext))
.isTrue();
}
@Test
public void isDoubleTapPowerButtonGestureAvailable_setUnavailable_returnsFalse() {
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(false);
public void isMultiTargetDoubleTapPowerButtonGestureAvailable_setUnavailable_returnsFalse() {
when(mResources.getInteger(R.integer.config_doubleTapPowerGestureMode)).thenReturn(
DOUBLE_TAP_POWER_DISABLED_MODE);
assertThat(DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureAvailable(mContext))
assertThat(DoubleTapPowerSettingsUtils.isMultiTargetDoubleTapPowerButtonGestureAvailable(
mContext))
.isFalse();
}
@@ -103,10 +109,10 @@ public class DoubleTapPowerSettingsUtilsTest {
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, true);
assertThat(
Settings.Secure.getInt(
mContext.getContentResolver(),
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED,
OFF))
Settings.Secure.getInt(
mContext.getContentResolver(),
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED,
OFF))
.isEqualTo(ON);
}
@@ -115,10 +121,10 @@ public class DoubleTapPowerSettingsUtilsTest {
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, false);
assertThat(
Settings.Secure.getInt(
mContext.getContentResolver(),
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED,
ON))
Settings.Secure.getInt(
mContext.getContentResolver(),
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED,
ON))
.isEqualTo(OFF);
}
@@ -130,8 +136,8 @@ public class DoubleTapPowerSettingsUtilsTest {
DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE);
assertThat(
DoubleTapPowerSettingsUtils
.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(mContext))
DoubleTapPowerSettingsUtils
.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(mContext))
.isTrue();
}
@@ -144,32 +150,32 @@ public class DoubleTapPowerSettingsUtilsTest {
DOUBLE_TAP_POWER_BUTTON_WALLET_LAUNCH_VALUE);
assertThat(
DoubleTapPowerSettingsUtils
.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(mContext))
DoubleTapPowerSettingsUtils
.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(mContext))
.isFalse();
}
@Test
public void
isDoubleTapPowerButtonGestureForCameraLaunchEnabled_defaultSetToCamera_returnsTrue() {
when(mResources.getInteger(R.integer.config_defaultDoubleTapPowerGestureAction))
when(mResources.getInteger(R.integer.config_doubleTapPowerGestureMultiTargetDefaultAction))
.thenReturn(DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE);
assertThat(
DoubleTapPowerSettingsUtils
.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(mContext))
DoubleTapPowerSettingsUtils
.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(mContext))
.isTrue();
}
@Test
public void
isDoubleTapPowerButtonGestureForCameraLaunchEnabled_defaultNotCamera_returnsFalse() {
when(mResources.getInteger(R.integer.config_defaultDoubleTapPowerGestureAction))
when(mResources.getInteger(R.integer.config_doubleTapPowerGestureMultiTargetDefaultAction))
.thenReturn(DOUBLE_TAP_POWER_BUTTON_WALLET_LAUNCH_VALUE);
assertThat(
DoubleTapPowerSettingsUtils
.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(mContext))
DoubleTapPowerSettingsUtils
.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(mContext))
.isFalse();
}
@@ -180,10 +186,10 @@ public class DoubleTapPowerSettingsUtilsTest {
assertThat(result).isTrue();
assertThat(
Settings.Secure.getInt(
mContext.getContentResolver(),
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE,
DOUBLE_TAP_POWER_BUTTON_WALLET_LAUNCH_VALUE))
Settings.Secure.getInt(
mContext.getContentResolver(),
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE,
DOUBLE_TAP_POWER_BUTTON_WALLET_LAUNCH_VALUE))
.isEqualTo(DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE);
}
@@ -194,10 +200,10 @@ public class DoubleTapPowerSettingsUtilsTest {
assertThat(result).isTrue();
assertThat(
Settings.Secure.getInt(
mContext.getContentResolver(),
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE,
DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE))
Settings.Secure.getInt(
mContext.getContentResolver(),
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE,
DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE))
.isEqualTo(DOUBLE_TAP_POWER_BUTTON_WALLET_LAUNCH_VALUE);
}
}