Files
app_Settings/tests/robotests/src/com/android/settings/gestures/DoubleTapPowerSettingsTest.java
Lorenzo Lucena Maguire 0e64487bc3 Support Double Tap Power to open camera via config resource
"Quickly open camera" screen was previously replaced by the "Double
Tap Power Button" screen and accessible only if the
feature flag
android.service.quickaccesswallet.launch_wallet_option_on_power_double_tap
was disabled.

This CL introduces the possibility to set, via a config resource, "Quickly open camera" as the double tap power
gesture screen.

Test: atest DoubleTapPowerSettingsTest
Test: atest DoubleTapPowerPreferenceControllerTest
Test: atest DoubleTapPowerSettingsUtilsTest
Test: manually modified config and verified screen and gesture behavior
change
Flag: android.service.quickaccesswallet.launch_wallet_option_on_power_double_tap
Bug: 384794943
Change-Id: I5ab4422da09fa90848c66a41829327494080b5a2

Change-Id: I8e04cac3999a7ed99a611ef084c54bc07a5505dc
2025-01-07 03:59:59 +00:00

133 lines
5.3 KiB
Java

/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.gestures;
import static com.android.settings.gestures.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;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
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;
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();
private DoubleTapPowerSettings mSettings;
@Before
public void setUp() {
mSettings = new DoubleTapPowerSettings();
}
@Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
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() {
assertThat(mSettings.getPreferenceScreenResId())
.isEqualTo(R.xml.double_tap_power_to_open_camera_settings);
}
@Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
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 */);
assertThat(indexRes).isNotNull();
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_indexFlagDisabledResource() {
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);
}
}