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 @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
if (!DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureAvailable(mContext)) { if (!DoubleTapPowerSettingsUtils
.isMultiTargetDoubleTapPowerButtonGestureAvailable(mContext)) {
return UNSUPPORTED_ON_DEVICE; return UNSUPPORTED_ON_DEVICE;
} }
return DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(mContext) return DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(mContext)

View File

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

View File

@@ -57,7 +57,8 @@ public class DoubleTapPowerMainSwitchPreferenceController
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
return DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureAvailable(mContext) return DoubleTapPowerSettingsUtils
.isMultiTargetDoubleTapPowerButtonGestureAvailable(mContext)
? AVAILABLE ? AVAILABLE
: UNSUPPORTED_ON_DEVICE; : 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 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.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.provider.Settings; import android.provider.Settings;
@@ -37,7 +39,8 @@ public class DoubleTapPowerPreferenceController extends BasePreferenceController
public static boolean isSuggestionComplete(Context context, SharedPreferences prefs) { public static boolean isSuggestionComplete(Context context, SharedPreferences prefs) {
return !isGestureAvailable(context) 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) { private static boolean isGestureAvailable(@NonNull Context context) {
@@ -46,7 +49,10 @@ public class DoubleTapPowerPreferenceController extends BasePreferenceController
.getBoolean( .getBoolean(
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled); 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 @Override
@@ -56,7 +62,9 @@ public class DoubleTapPowerPreferenceController extends BasePreferenceController
@Override @Override
public void displayPreference(@NonNull PreferenceScreen screen) { 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()); final Preference preference = screen.findPreference(getPreferenceKey());
if (preference != null) { if (preference != null) {
preference.setTitle(R.string.double_tap_power_for_camera_title); preference.setTitle(R.string.double_tap_power_for_camera_title);
@@ -68,12 +76,14 @@ public class DoubleTapPowerPreferenceController extends BasePreferenceController
@Override @Override
@NonNull @NonNull
public CharSequence getSummary() { public CharSequence getSummary() {
if (!android.service.quickaccesswallet.Flags.launchWalletOptionOnPowerDoubleTap()) { if (!android.service.quickaccesswallet.Flags.launchWalletOptionOnPowerDoubleTap()
|| !DoubleTapPowerSettingsUtils
.isMultiTargetDoubleTapPowerButtonGestureAvailable(mContext)) {
final boolean isCameraDoubleTapPowerGestureEnabled = final boolean isCameraDoubleTapPowerGestureEnabled =
Settings.Secure.getInt( Settings.Secure.getInt(
mContext.getContentResolver(), mContext.getContentResolver(),
CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED,
DoubleTapPowerToOpenCameraPreferenceController.ON) DoubleTapPowerToOpenCameraPreferenceController.ON)
== DoubleTapPowerToOpenCameraPreferenceController.ON; == DoubleTapPowerToOpenCameraPreferenceController.ON;
return mContext.getText( return mContext.getText(
isCameraDoubleTapPowerGestureEnabled isCameraDoubleTapPowerGestureEnabled
@@ -85,7 +95,7 @@ public class DoubleTapPowerPreferenceController extends BasePreferenceController
mContext.getText(com.android.settings.R.string.gesture_setting_on); mContext.getText(com.android.settings.R.string.gesture_setting_on);
final CharSequence actionString = final CharSequence actionString =
DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureForCameraLaunchEnabled( DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(
mContext) mContext)
? mContext.getText(R.string.double_tap_power_camera_action_summary) ? mContext.getText(R.string.double_tap_power_camera_action_summary)
: mContext.getText(R.string.double_tap_power_wallet_action_summary); : mContext.getText(R.string.double_tap_power_wallet_action_summary);
return mContext.getString(R.string.double_tap_power_summary, onString, actionString); 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 = public static final String PREF_KEY_SUGGESTION_COMPLETE =
"pref_double_tap_power_suggestion_complete"; "pref_double_tap_power_suggestion_complete";
private Context mContext;
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
mContext = context;
super.onAttach(context); super.onAttach(context);
SuggestionFeatureProvider suggestionFeatureProvider = SuggestionFeatureProvider suggestionFeatureProvider =
FeatureFactory.getFeatureFactory().getSuggestionFeatureProvider(); FeatureFactory.getFeatureFactory().getSuggestionFeatureProvider();
@@ -61,7 +63,15 @@ public class DoubleTapPowerSettings extends DashboardFragment {
@Override @Override
protected int getPreferenceScreenResId() { 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_settings
: R.xml.double_tap_power_to_open_camera_settings; : R.xml.double_tap_power_to_open_camera_settings;
} }
@@ -73,11 +83,7 @@ public class DoubleTapPowerSettings extends DashboardFragment {
public List<SearchIndexableResource> getXmlResourcesToIndex( public List<SearchIndexableResource> getXmlResourcesToIndex(
@NonNull Context context, boolean enabled) { @NonNull Context context, boolean enabled) {
final SearchIndexableResource sir = new SearchIndexableResource(context); final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = sir.xmlResId = getDoubleTapPowerSettingsResId(context);
android.service.quickaccesswallet.Flags
.launchWalletOptionOnPowerDoubleTap()
? R.xml.double_tap_power_settings
: R.xml.double_tap_power_to_open_camera_settings;
return List.of(sir); 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. */ /** Common code for double tap power settings shared between controllers. */
final class DoubleTapPowerSettingsUtils { 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. */ /** Setting storing whether the double tap power button gesture is enabled. */
private static final String DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED = private static final String DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED =
Settings.Secure.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. * @return true if double tap power button gesture is available.
*/ */
public static boolean isDoubleTapPowerButtonGestureAvailable(@NonNull Context context) { public static boolean isMultiTargetDoubleTapPowerButtonGestureAvailable(
return context.getResources().getBoolean(R.bool.config_doubleTapPowerGestureEnabled); @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. * 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 * @param context App context
* @return true if double tap on the power button gesture is currently enabled.
*/ */
public static boolean isDoubleTapPowerButtonGestureEnabled(@NonNull Context context) { public static boolean isDoubleTapPowerButtonGestureEnabled(@NonNull Context context) {
return Settings.Secure.getInt( return Settings.Secure.getInt(
context.getContentResolver(), DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED, ON) context.getContentResolver(), DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED, ON)
== ON; == ON;
} }
@@ -72,7 +86,7 @@ final class DoubleTapPowerSettingsUtils {
* Sets double tap power button gesture enable or disable flag to Settings provider. * Sets double tap power button gesture enable or disable flag to Settings provider.
* *
* @param context App context * @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. * @return {@code true} if the setting is updated.
*/ */
public static boolean setDoubleTapPowerButtonGestureEnabled( 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 * @param context App context
* @return true if double tap on the power button gesture for camera launch is currently
* enabled.
*/ */
public static boolean isDoubleTapPowerButtonGestureForCameraLaunchEnabled( public static boolean isDoubleTapPowerButtonGestureForCameraLaunchEnabled(
@NonNull Context context) { @NonNull Context context) {
return Settings.Secure.getInt( return Settings.Secure.getInt(
context.getContentResolver(), context.getContentResolver(),
DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION, DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION,
context.getResources() context.getResources()
.getInteger( .getInteger(
com.android.internal.R.integer com.android.internal.R.integer
.config_defaultDoubleTapPowerGestureAction)) .config_doubleTapPowerGestureMultiTargetDefaultAction))
== DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE; == DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE;
} }

View File

@@ -16,6 +16,9 @@
package com.android.settings.gestures; 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 com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@@ -72,7 +75,8 @@ public class DoubleTapPowerForCameraPreferenceControllerTest {
@Test @Test
public void getAvailabilityStatus_setDoubleTapPowerGestureNotAvailable_preferenceUnsupported() { 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()) assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE); .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
@@ -80,7 +84,8 @@ public class DoubleTapPowerForCameraPreferenceControllerTest {
@Test @Test
public void getAvailabilityStatus_setDoubleTapPowerButtonDisabled_preferenceDisabled() { 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); DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, false);
assertThat(mController.getAvailabilityStatus()) assertThat(mController.getAvailabilityStatus())
@@ -89,7 +94,8 @@ public class DoubleTapPowerForCameraPreferenceControllerTest {
@Test @Test
public void getAvailabilityStatus_setDoubleTapPowerCameraLaunchEnabled_preferenceEnabled() { 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); DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, true);
assertThat(mController.getAvailabilityStatus()) assertThat(mController.getAvailabilityStatus())

View File

@@ -16,6 +16,9 @@
package com.android.settings.gestures; 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 com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@@ -74,7 +77,8 @@ public class DoubleTapPowerForWalletPreferenceControllerTest {
@Test @Test
public void getAvailabilityStatus_setDoubleTapPowerGestureNotAvailable_preferenceUnsupported() { 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()) assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE); .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
@@ -82,7 +86,8 @@ public class DoubleTapPowerForWalletPreferenceControllerTest {
@Test @Test
public void getAvailabilityStatus_setDoubleTapPowerButtonDisabled_preferenceDisabled() { 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); DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, false);
assertThat(mController.getAvailabilityStatus()) assertThat(mController.getAvailabilityStatus())
@@ -91,7 +96,8 @@ public class DoubleTapPowerForWalletPreferenceControllerTest {
@Test @Test
public void getAvailabilityStatus_setDoubleTapPowerWalletLaunchEnabled_preferenceEnabled() { 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); DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, true);
assertThat(mController.getAvailabilityStatus()) assertThat(mController.getAvailabilityStatus())

View File

@@ -16,6 +16,9 @@
package com.android.settings.gestures; 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 com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@@ -54,7 +57,8 @@ public class DoubleTapPowerMainSwitchPreferenceControllerTest {
@Test @Test
public void getAvailabilityStatus_setDoubleTapPowerGestureAvailable_preferenceEnabled() { 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()) assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE); .isEqualTo(BasePreferenceController.AVAILABLE);
@@ -62,7 +66,8 @@ public class DoubleTapPowerMainSwitchPreferenceControllerTest {
@Test @Test
public void getAvailabilityStatus_setDoubleTapPowerGestureUnavailable_preferenceUnsupported() { 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()) assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE); .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 android.provider.Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED;
import static com.android.settings.gestures.DoubleTapPowerPreferenceController.isSuggestionComplete; 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.OFF;
import static com.android.settings.gestures.DoubleTapPowerToOpenCameraPreferenceController.ON; import static com.android.settings.gestures.DoubleTapPowerToOpenCameraPreferenceController.ON;
@@ -58,7 +61,8 @@ import org.robolectric.annotation.Config;
@Config(shadows = SettingsShadowResources.class) @Config(shadows = SettingsShadowResources.class)
public class DoubleTapPowerPreferenceControllerTest { public class DoubleTapPowerPreferenceControllerTest {
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); @Rule
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
private Context mContext; private Context mContext;
private ContentResolver mContentResolver; private ContentResolver mContentResolver;
private DoubleTapPowerPreferenceController mController; private DoubleTapPowerPreferenceController mController;
@@ -83,18 +87,30 @@ public class DoubleTapPowerPreferenceControllerTest {
@Test @Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP) @EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isAvailable_flagEnabled_configIsTrue_returnsTrue() { public void isAvailable_flagEnabled_configIsMultiTargetMode_returnsTrue() {
SettingsShadowResources.overrideResource( 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(); assertThat(mController.isAvailable()).isTrue();
} }
@Test @Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP) @EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isAvailable_flagEnabled_configIsFalse_returnsFalse() { public void isAvailable_flagEnabled_configIsCameraLaunchMode_returnsTrue() {
SettingsShadowResources.overrideResource( 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(); assertThat(mController.isAvailable()).isFalse();
} }
@@ -121,18 +137,20 @@ public class DoubleTapPowerPreferenceControllerTest {
@Test @Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP) @EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isSuggestionCompleted_enableFlag_doubleTapPower_trueWhenNotAvailable() { public void isSuggestionCompleted_flagEnabled_configIsMultiTargetMode_trueWhenNotAvailable() {
SettingsShadowResources.overrideResource( 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(); assertThat(isSuggestionComplete(mContext, null /* prefs */)).isTrue();
} }
@Test @Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP) @EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isSuggestionCompleted_enableFlag_doubleTapPower_falseWhenNotVisited() { public void isSuggestionCompleted_enableFlag_configIsMultiTargetMode_falseWhenNotVisited() {
SettingsShadowResources.overrideResource( 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. // No stored value in shared preferences if not visited yet.
final SharedPreferences prefs = final SharedPreferences prefs =
new SuggestionFeatureProviderImpl().getSharedPrefs(mContext); new SuggestionFeatureProviderImpl().getSharedPrefs(mContext);
@@ -142,9 +160,10 @@ public class DoubleTapPowerPreferenceControllerTest {
@Test @Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP) @EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isSuggestionCompleted_enableFlag_doubleTapPower_trueWhenVisited() { public void isSuggestionCompleted_enableFlag_configIsMultiTargetMode_trueWhenVisited() {
SettingsShadowResources.overrideResource( 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. // No stored value in shared preferences if not visited yet.
final SharedPreferences prefs = final SharedPreferences prefs =
new SuggestionFeatureProviderImpl().getSharedPrefs(mContext); new SuggestionFeatureProviderImpl().getSharedPrefs(mContext);
@@ -189,13 +208,30 @@ public class DoubleTapPowerPreferenceControllerTest {
@Test @Test
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP) @DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void displayPreference_flagDisabled_doubleTapPowerLegacyTitleIsDisplayed() { public void displayPreference_flagDisabled_cameraLaunchTitleIsDisplayed() {
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
assertThat( assertThat(
TextUtils.equals( TextUtils.equals(
mPreference.getTitle(), mPreference.getTitle(),
mContext.getText(R.string.double_tap_power_for_camera_title))) 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(); .isTrue();
} }
@@ -206,9 +242,9 @@ public class DoubleTapPowerPreferenceControllerTest {
Settings.Secure.putInt(mContentResolver, CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, ON); Settings.Secure.putInt(mContentResolver, CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, ON);
assertThat( assertThat(
TextUtils.equals( TextUtils.equals(
mController.getSummary(), mController.getSummary(),
mContext.getText(R.string.gesture_setting_on))) mContext.getText(R.string.gesture_setting_on)))
.isTrue(); .isTrue();
} }
@@ -219,9 +255,42 @@ public class DoubleTapPowerPreferenceControllerTest {
Settings.Secure.putInt(mContentResolver, CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, OFF); Settings.Secure.putInt(mContentResolver, CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, OFF);
assertThat( assertThat(
TextUtils.equals( TextUtils.equals(
mController.getSummary(), mController.getSummary(),
mContext.getText(R.string.gesture_setting_off))) 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(); .isTrue();
} }
@@ -233,9 +302,9 @@ public class DoubleTapPowerPreferenceControllerTest {
mContentResolver, DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED, 0 /* OFF */); mContentResolver, DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED, 0 /* OFF */);
assertThat( assertThat(
TextUtils.equals( TextUtils.equals(
mController.getSummary(), mController.getSummary(),
mContext.getText(R.string.gesture_setting_off))) mContext.getText(R.string.gesture_setting_off)))
.isTrue(); .isTrue();
} }
@@ -248,13 +317,13 @@ public class DoubleTapPowerPreferenceControllerTest {
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForCameraLaunch(mContext); DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForCameraLaunch(mContext);
assertThat( assertThat(
TextUtils.equals( TextUtils.equals(
mController.getSummary(), mController.getSummary(),
mContext.getString( mContext.getString(
R.string.double_tap_power_summary, R.string.double_tap_power_summary,
mContext.getText(R.string.gesture_setting_on), mContext.getText(R.string.gesture_setting_on),
mContext.getText( mContext.getText(
R.string.double_tap_power_camera_action_summary)))) R.string.double_tap_power_camera_action_summary))))
.isTrue(); .isTrue();
} }
@@ -267,13 +336,13 @@ public class DoubleTapPowerPreferenceControllerTest {
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForWalletLaunch(mContext); DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForWalletLaunch(mContext);
assertThat( assertThat(
TextUtils.equals( TextUtils.equals(
mController.getSummary(), mController.getSummary(),
mContext.getString( mContext.getString(
R.string.double_tap_power_summary, R.string.double_tap_power_summary,
mContext.getText(R.string.gesture_setting_on), mContext.getText(R.string.gesture_setting_on),
mContext.getText( mContext.getText(
R.string.double_tap_power_wallet_action_summary)))) R.string.double_tap_power_wallet_action_summary))))
.isTrue(); .isTrue();
} }
} }

View File

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

View File

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