Support wallet launch in Double Tap Power Gesture Settings

Modify Double Tap Power Gesture Settings screen to be able to set the
gesture to launch the wallet.

If the feature flag is disabled, the
Double Tap Power Gesture Settings screen defaults to the current
screen ("Quickly open camera"), which only provides the option to open the camera upon detecting the
gesture.

If the feature flag is enabled, the Double Tap Power Gesture Settings
screen defaults to the new "Double Tap Power Button" screen, which
provides the option to open the camera, the wallet, or neither upon
detecting the gesture.

Android Settings Feature Request: b/380287172

Bug: 378131008
Test: manual tested screen alternates based on feature flag
Test: atest DoubleTapPowerSettingsTest
Test: atest DoubleTapPowerPreferenceControllerTest
Test: atest DoubleTapPowerToOpenCameraPreferenceControllerTest
FLAG: android.service.quickaccesswallet.launch_wallet_option_on_power_double_tap

Change-Id: I1fc05ab3cfee2e86a80a1756655c368aae16747c
This commit is contained in:
Lorenzo Lucena Maguire
2024-11-18 07:11:26 +00:00
parent 406a01dfab
commit d3af193384
7 changed files with 306 additions and 28 deletions

View File

@@ -11158,6 +11158,23 @@
<!-- Summary text for double tap power for camera [CHAR LIMIT=160]--> <!-- Summary text for double tap power for camera [CHAR LIMIT=160]-->
<string name="double_tap_power_for_camera_summary">To quickly open camera, press the power button twice. Works from any screen.</string> <string name="double_tap_power_for_camera_summary">To quickly open camera, press the power button twice. Works from any screen.</string>
<!-- Title text for double tap power gesture [CHAR LIMIT=80]-->
<string name="double_tap_power_title">Double tap power button</string>
<!-- Summary for double tap power settings [DO NOT TRANSLATE] -->
<string name="double_tap_power_summary" translatable="false"><xliff:g id="double_tap_power_on_off" example="On">%1$s</xliff:g> / <xliff:g id="double_tap_power_actions" example="Access Wallet">%2$s</xliff:g></string>
<!-- Switch label to enable/disable double tap power button gesture [CHAR LIMIT=60] -->
<string name="double_tap_power_enabled">Use double tap</string>
<!-- Category title for double tap power gesture [CHAR_LIMIT=80] -->
<string name="double_tap_power_target_action_category">Double Tap Power Button</string>
<!-- Double Tap Power Gesture camera launch action title [CHAR_LIMIT=60] -->
<string name="double_tap_power_camera_action_title">Open Camera</string>
<!-- Setting summary to describe double tap power button will open camera. [CHAR LIMIT=NONE] -->
<string name="double_tap_power_camera_action_summary">Access Camera</string>
<!-- Double Tap Power Gesture wallet launch action title [CHAR_LIMIT=60] -->
<string name="double_tap_power_wallet_action_title">Open Wallet</string>
<!-- Setting summary to describe double tap power button will open wallet. [CHAR LIMIT=NONE] -->
<string name="double_tap_power_wallet_action_summary">Access Wallet</string>
<!-- Title text for double twist for camera mode [CHAR LIMIT=60]--> <!-- Title text for double twist for camera mode [CHAR LIMIT=60]-->
<string name="double_twist_for_camera_mode_title">Flip camera for selfie</string> <string name="double_twist_for_camera_mode_title">Flip camera for selfie</string>

View File

@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2024 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.
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/double_tap_power_title">
<com.android.settingslib.widget.IllustrationPreference
android:key="gesture_double_tap_power_video"
settings:searchable="false"
settings:lottie_rawRes="@drawable/quickly_open_camera"/>
<com.android.settingslib.widget.MainSwitchPreference
android:key="gesture_double_tap_power_enabled_main_switch"
android:title="@string/double_tap_power_enabled"
settings:keywords="@string/keywords_gesture"
settings:controller="com.android.settings.gestures.DoubleTapPowerMainSwitchPreferenceController"/>
<PreferenceCategory
android:key="gesture_double_tap_power_actions"
android:title="@string/double_tap_power_target_action_category">
<com.android.settingslib.widget.SelectorWithWidgetPreference
android:key="gesture_double_power_tap_camera"
android:title="@string/double_tap_power_camera_action_title"
settings:controller="com.android.settings.gestures.DoubleTapPowerForCameraPreferenceController"/>
<com.android.settingslib.widget.SelectorWithWidgetPreference
android:key="gesture_double_power_tap_wallet"
android:title="@string/double_tap_power_wallet_action_title"
settings:controller="com.android.settings.gestures.DoubleTapPowerForWalletPreferenceController"/>
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -29,7 +29,7 @@
<Preference <Preference
android:key="gesture_double_tap_power_input_summary" android:key="gesture_double_tap_power_input_summary"
android:title="@string/double_tap_power_for_camera_title" android:title="@string/double_tap_power_title"
android:fragment="com.android.settings.gestures.DoubleTapPowerSettings" android:fragment="com.android.settings.gestures.DoubleTapPowerSettings"
settings:searchable="false" settings:searchable="false"
settings:controller="com.android.settings.gestures.DoubleTapPowerPreferenceController" /> settings:controller="com.android.settings.gestures.DoubleTapPowerPreferenceController" />

View File

@@ -23,6 +23,8 @@ import android.content.SharedPreferences;
import android.provider.Settings; import android.provider.Settings;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.core.BasePreferenceController; import com.android.settings.core.BasePreferenceController;
@@ -39,8 +41,12 @@ public class DoubleTapPowerPreferenceController extends BasePreferenceController
} }
private static boolean isGestureAvailable(@NonNull Context context) { private static boolean isGestureAvailable(@NonNull Context context) {
if (!android.service.quickaccesswallet.Flags.launchWalletOptionOnPowerDoubleTap()) {
return context.getResources() return context.getResources()
.getBoolean(com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled); .getBoolean(
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled);
}
return DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureAvailable(context);
} }
@Override @Override
@@ -48,9 +54,21 @@ public class DoubleTapPowerPreferenceController extends BasePreferenceController
return isGestureAvailable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE; return isGestureAvailable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
} }
@Override
public void displayPreference(@NonNull PreferenceScreen screen) {
if (!android.service.quickaccesswallet.Flags.launchWalletOptionOnPowerDoubleTap()) {
final Preference preference = screen.findPreference(getPreferenceKey());
if (preference != null) {
preference.setTitle(R.string.double_tap_power_for_camera_title);
}
}
super.displayPreference(screen);
}
@Override @Override
@NonNull @NonNull
public CharSequence getSummary() { public CharSequence getSummary() {
if (!android.service.quickaccesswallet.Flags.launchWalletOptionOnPowerDoubleTap()) {
final boolean isCameraDoubleTapPowerGestureEnabled = final boolean isCameraDoubleTapPowerGestureEnabled =
Settings.Secure.getInt( Settings.Secure.getInt(
mContext.getContentResolver(), mContext.getContentResolver(),
@@ -62,4 +80,16 @@ public class DoubleTapPowerPreferenceController extends BasePreferenceController
? R.string.gesture_setting_on ? R.string.gesture_setting_on
: R.string.gesture_setting_off); : R.string.gesture_setting_off);
} }
if (DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(mContext)) {
final CharSequence onString =
mContext.getText(com.android.settings.R.string.gesture_setting_on);
final CharSequence actionString =
DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(
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);
}
return mContext.getText(com.android.settings.R.string.gesture_setting_off);
}
} }

View File

@@ -19,6 +19,9 @@ package com.android.settings.gestures;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.provider.SearchIndexableResource;
import androidx.annotation.NonNull;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment; import com.android.settings.dashboard.DashboardFragment;
@@ -27,6 +30,8 @@ import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable; import com.android.settingslib.search.SearchIndexable;
import java.util.List;
@SearchIndexable @SearchIndexable
public class DoubleTapPowerSettings extends DashboardFragment { public class DoubleTapPowerSettings extends DashboardFragment {
@@ -56,9 +61,24 @@ public class DoubleTapPowerSettings extends DashboardFragment {
@Override @Override
protected int getPreferenceScreenResId() { protected int getPreferenceScreenResId() {
return R.xml.double_tap_power_to_open_camera_settings; return android.service.quickaccesswallet.Flags.launchWalletOptionOnPowerDoubleTap()
? R.xml.double_tap_power_settings
: R.xml.double_tap_power_to_open_camera_settings;
} }
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.double_tap_power_to_open_camera_settings); new BaseSearchIndexProvider() {
@Override
@NonNull
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;
return List.of(sir);
}
};
} }

View File

@@ -17,6 +17,7 @@
package com.android.settings.gestures; 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 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.DoubleTapPowerToOpenCameraPreferenceController.OFF; import static com.android.settings.gestures.DoubleTapPowerToOpenCameraPreferenceController.OFF;
@@ -24,18 +25,29 @@ import static com.android.settings.gestures.DoubleTapPowerToOpenCameraPreference
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.when;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings; import android.provider.Settings;
import android.service.quickaccesswallet.Flags;
import android.text.TextUtils; import android.text.TextUtils;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProviderImpl; import com.android.settings.dashboard.suggestions.SuggestionFeatureProviderImpl;
import com.android.settings.testutils.shadow.SettingsShadowResources; import com.android.settings.testutils.shadow.SettingsShadowResources;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
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;
@@ -46,16 +58,22 @@ 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();
private Context mContext; private Context mContext;
private ContentResolver mContentResolver; private ContentResolver mContentResolver;
private DoubleTapPowerPreferenceController mController; private DoubleTapPowerPreferenceController mController;
private Preference mPreference;
private PreferenceScreen mScreen;
private static final String KEY_DOUBLE_TAP_POWER = "gesture_double_tap_power"; private static final String KEY_DOUBLE_TAP_POWER = "gesture_double_tap_power";
@Before @Before
public void setUp() { public void setUp() {
mContext = RuntimeEnvironment.application; mContext = RuntimeEnvironment.getApplication();
mContentResolver = mContext.getContentResolver(); mContentResolver = mContext.getContentResolver();
mController = new DoubleTapPowerPreferenceController(mContext, KEY_DOUBLE_TAP_POWER); mController = new DoubleTapPowerPreferenceController(mContext, KEY_DOUBLE_TAP_POWER);
mPreference = new Preference(mContext);
mScreen = mock(PreferenceScreen.class);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
} }
@After @After
@@ -64,7 +82,26 @@ public class DoubleTapPowerPreferenceControllerTest {
} }
@Test @Test
public void isAvailable_configIsTrue_shouldReturnTrue() { @EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isAvailable_flagEnabled_configIsTrue_returnsTrue() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_doubleTapPowerGestureEnabled, Boolean.TRUE);
assertThat(mController.isAvailable()).isTrue();
}
@Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isAvailable_flagEnabled_configIsFalse_returnsFalse() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_doubleTapPowerGestureEnabled, Boolean.FALSE);
assertThat(mController.isAvailable()).isFalse();
}
@Test
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isAvailable_flagDisabled_configIsTrue_returnsTrue() {
SettingsShadowResources.overrideResource( SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled, com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled,
Boolean.TRUE); Boolean.TRUE);
@@ -73,7 +110,8 @@ public class DoubleTapPowerPreferenceControllerTest {
} }
@Test @Test
public void isAvailable_configIsFalse_shouldReturnFalse() { @DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isAvailable_flagDisabled_configIsFalse_returnsFalse() {
SettingsShadowResources.overrideResource( SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled, com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled,
Boolean.FALSE); Boolean.FALSE);
@@ -82,7 +120,42 @@ public class DoubleTapPowerPreferenceControllerTest {
} }
@Test @Test
public void isSuggestionCompleted_doubleTapPower_trueWhenNotAvailable() { @EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isSuggestionCompleted_enableFlag_doubleTapPower_trueWhenNotAvailable() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_doubleTapPowerGestureEnabled, false);
assertThat(isSuggestionComplete(mContext, null /* prefs */)).isTrue();
}
@Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isSuggestionCompleted_enableFlag_doubleTapPower_falseWhenNotVisited() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_doubleTapPowerGestureEnabled, true);
// No stored value in shared preferences if not visited yet.
final SharedPreferences prefs =
new SuggestionFeatureProviderImpl().getSharedPrefs(mContext);
assertThat(isSuggestionComplete(mContext, prefs)).isFalse();
}
@Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isSuggestionCompleted_enableFlag_doubleTapPower_trueWhenVisited() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_doubleTapPowerGestureEnabled, true);
// No stored value in shared preferences if not visited yet.
final SharedPreferences prefs =
new SuggestionFeatureProviderImpl().getSharedPrefs(mContext);
prefs.edit().putBoolean(DoubleTapPowerSettings.PREF_KEY_SUGGESTION_COMPLETE, true).commit();
assertThat(isSuggestionComplete(mContext, prefs)).isTrue();
}
@Test
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isSuggestionCompleted_disableFlag_doubleTapPower_trueWhenNotAvailable() {
SettingsShadowResources.overrideResource( SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled, false); com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled, false);
@@ -90,7 +163,8 @@ public class DoubleTapPowerPreferenceControllerTest {
} }
@Test @Test
public void isSuggestionCompleted_doubleTapPower_falseWhenNotVisited() { @DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isSuggestionCompleted_disableFlag_doubleTapPower_falseWhenNotVisited() {
SettingsShadowResources.overrideResource( SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled, true); com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled, true);
// No stored value in shared preferences if not visited yet. // No stored value in shared preferences if not visited yet.
@@ -101,7 +175,8 @@ public class DoubleTapPowerPreferenceControllerTest {
} }
@Test @Test
public void isSuggestionCompleted_doubleTapPower_trueWhenVisited() { @DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isSuggestionCompleted_disableFlag_doubleTapPower_trueWhenVisited() {
SettingsShadowResources.overrideResource( SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled, true); com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled, true);
// No stored value in shared preferences if not visited yet. // No stored value in shared preferences if not visited yet.
@@ -113,7 +188,20 @@ public class DoubleTapPowerPreferenceControllerTest {
} }
@Test @Test
public void getSummary_doubleTapPowerEnabled_returnsOn() { @DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void displayPreference_flagDisabled_doubleTapPowerLegacyTitleIsDisplayed() {
mController.displayPreference(mScreen);
assertThat(
TextUtils.equals(
mPreference.getTitle(),
mContext.getText(R.string.double_tap_power_for_camera_title)))
.isTrue();
}
@Test
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void getSummary_flagDisabled_doubleTapPowerEnabled_returnsOn() {
// Set the setting to be enabled. // Set the setting to be enabled.
Settings.Secure.putInt(mContentResolver, CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, ON); Settings.Secure.putInt(mContentResolver, CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, ON);
@@ -125,14 +213,67 @@ public class DoubleTapPowerPreferenceControllerTest {
} }
@Test @Test
public void getSummary_doubleTapPowerDisabled_returnsOff() { @DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void getSummary_flagDisabled_doubleTapPowerDisabled_returnsOff() {
// Set the setting to be disabled. // Set the setting to be disabled.
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_on))) mContext.getText(R.string.gesture_setting_off)))
.isTrue();
}
@Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void getSummary_flagEnabled_doubleTapPowerDisabled_returnsOff() {
// Set the setting to be disabled.
Settings.Secure.putInt(
mContentResolver, DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED, 0 /* OFF */);
assertThat(
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_cameraTargetAction_returnsSummary() {
// Set the setting to be enabled.
Settings.Secure.putInt(
mContentResolver, DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED, 1 /* ON */);
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))))
.isTrue();
}
@Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void getSummary_flagEnabled_doubleTapPowerEnabled_walletTargetAction_returnsSummary() {
// Set the setting to be enabled.
Settings.Secure.putInt(
mContentResolver, DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED, 1 /* ON */);
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))))
.isTrue(); .isTrue();
} }
} }

View File

@@ -18,11 +18,16 @@ package com.android.settings.gestures;
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.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.SearchIndexableResource; import android.provider.SearchIndexableResource;
import android.service.quickaccesswallet.Flags;
import com.android.settings.R; import com.android.settings.R;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
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;
@@ -33,6 +38,7 @@ import java.util.List;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
public class DoubleTapPowerSettingsTest { public class DoubleTapPowerSettingsTest {
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
private DoubleTapPowerSettings mSettings; private DoubleTapPowerSettings mSettings;
@Before @Before
@@ -41,18 +47,38 @@ public class DoubleTapPowerSettingsTest {
} }
@Test @Test
public void getPreferenceResId_returnsResId() { @EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void getPreferenceScreenResId_flagEnabled_returnsFlagEnabledResId() {
assertThat(mSettings.getPreferenceScreenResId()).isEqualTo(R.xml.double_tap_power_settings);
}
@Test
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void getPreferenceScreenResId_flagDisabled_returnsFlagDisabledResId() {
assertThat(mSettings.getPreferenceScreenResId()) assertThat(mSettings.getPreferenceScreenResId())
.isEqualTo(R.xml.double_tap_power_to_open_camera_settings); .isEqualTo(R.xml.double_tap_power_to_open_camera_settings);
} }
@Test @Test
public void testSearchIndexProvider_shouldIndexResource() { @EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void testSearchIndexProvider_flagEnabled_shouldIndexFlagEnabledResource() {
final List<SearchIndexableResource> indexRes = final List<SearchIndexableResource> indexRes =
DoubleTapPowerSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex( DoubleTapPowerSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
RuntimeEnvironment.application, true /* enabled */); RuntimeEnvironment.getApplication(), true /* enabled */);
assertThat(indexRes).isNotNull(); assertThat(indexRes).isNotNull();
assertThat(indexRes.get(0).xmlResId).isEqualTo(mSettings.getPreferenceScreenResId()); assertThat(indexRes.get(0).xmlResId).isEqualTo(R.xml.double_tap_power_settings);
}
@Test
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void testSearchIndexProvider_flagDisabled_shouldIndexFlagDisabledResource() {
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);
} }
} }