Refactors the System Navigation settings page

Bug: 130915285
Bug: 128855215
Bug: 127718810
Bug: 129115299
Test: make RunSettingsRoboTests ROBOTEST_FILTER=SystemNavigationGestureSettingsTest
Test: make RunSettingsRoboTests ROBOTEST_FILTER=SystemNavigationPreferenceControllerTest

Change-Id: If11e1fe4bf150d2dd9578f731e71abf6b74f5d90
This commit is contained in:
Mehdi Alizadeh
2019-05-08 18:09:24 -07:00
parent 815ed755c3
commit 36f32a46ca
17 changed files with 351 additions and 769 deletions

View File

@@ -1,199 +0,0 @@
/*
* Copyright (C) 2019 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 android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
import static com.android.settings.gestures.SystemNavigationEdgeToEdgePreferenceController.PREF_KEY_EDGE_TO_EDGE;
import static com.android.settings.gestures.SystemNavigationLegacyPreferenceController.PREF_KEY_LEGACY;
import static com.android.settings.gestures.SystemNavigationSwipeUpPreferenceController.PREF_KEY_SWIPE_UP;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.om.IOverlayManager;
import android.content.pm.ApplicationInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import androidx.preference.PreferenceScreen;
import com.android.internal.R;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settings.widget.RadioButtonPreference;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowPackageManager;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = SettingsShadowResources.class)
public class SystemNavigationEdgeToEdgePreferenceControllerTest {
private Context mContext;
private ShadowPackageManager mPackageManager;
@Mock
private IOverlayManager mOverlayManager;
private SystemNavigationEdgeToEdgePreferenceController mController;
private static final String ACTION_QUICKSTEP = "android.intent.action.QUICKSTEP_SERVICE";
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
SettingsShadowResources.overrideResource(R.bool.config_swipe_up_gesture_setting_available,
true);
mContext = RuntimeEnvironment.application;
mPackageManager = Shadows.shadowOf(mContext.getPackageManager());
mController = new SystemNavigationEdgeToEdgePreferenceController(mContext, mOverlayManager,
PREF_KEY_EDGE_TO_EDGE);
}
@After
public void tearDown() {
SettingsShadowResources.reset();
}
@Test
public void testIsGestureAvailable_matchingServiceExists_shouldReturnTrue() {
final ComponentName recentsComponentName = ComponentName.unflattenFromString(
mContext.getString(com.android.internal.R.string.config_recentsComponentName));
final Intent quickStepIntent = new Intent(ACTION_QUICKSTEP)
.setPackage(recentsComponentName.getPackageName());
final ResolveInfo info = new ResolveInfo();
info.serviceInfo = new ServiceInfo();
info.resolvePackageName = recentsComponentName.getPackageName();
info.serviceInfo.packageName = info.resolvePackageName;
info.serviceInfo.name = recentsComponentName.getClassName();
info.serviceInfo.applicationInfo = new ApplicationInfo();
info.serviceInfo.applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
mPackageManager.addResolveInfoForIntent(quickStepIntent, info);
assertThat(SystemNavigationEdgeToEdgePreferenceController.isGestureAvailable(mContext))
.isTrue();
}
@Test
public void testIsGestureAvailable_overlayDisabled_matchingServiceExists_shouldReturnFalse() {
SettingsShadowResources.overrideResource(R.bool.config_swipe_up_gesture_setting_available,
false);
final ComponentName recentsComponentName = ComponentName.unflattenFromString(
mContext.getString(com.android.internal.R.string.config_recentsComponentName));
final Intent quickStepIntent = new Intent(ACTION_QUICKSTEP)
.setPackage(recentsComponentName.getPackageName());
mPackageManager.addResolveInfoForIntent(quickStepIntent, new ResolveInfo());
assertThat(SystemNavigationEdgeToEdgePreferenceController.isGestureAvailable(mContext))
.isFalse();
}
@Test
public void testIsGestureAvailable_noMatchingServiceExists_shouldReturnFalse() {
assertThat(SystemNavigationEdgeToEdgePreferenceController.isGestureAvailable(mContext))
.isFalse();
}
@Test
public void testIsGestureAvailable_noOverlayPackage_shouldReturnFalse() {
assertThat(SystemNavigationEdgeToEdgePreferenceController.isGestureAvailable(mContext,
"com.package.fake")).isFalse();
}
@Test
public void testIsChecked_defaultIsEdgeToEdge_shouldReturnTrue() {
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
NAV_BAR_MODE_GESTURAL);
assertThat(mController.isChecked()).isTrue();
}
@Test
public void testIsChecked_defaultIsLegacy_shouldReturnFalse() {
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
NAV_BAR_MODE_3BUTTON);
assertThat(mController.isChecked()).isFalse();
}
@Test
public void testIsChecked_defaultIsSwipeUp_shouldReturnFalse() {
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
NAV_BAR_MODE_2BUTTON);
assertThat(mController.isChecked()).isFalse();
}
@Test
public void testIsChecked_radioButtonClicked_shouldReturnTrue() {
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
NAV_BAR_MODE_GESTURAL);
// Set the setting to be enabled.
mController.onRadioButtonClicked(null);
assertThat(mController.isChecked()).isTrue();
}
@Test
public void testOnRadioButtonClicked_setsCorrectRadioButtonChecked() {
RadioButtonPreference radioLegacy = mock(RadioButtonPreference.class);
RadioButtonPreference radioSwipeUp = mock(RadioButtonPreference.class);
RadioButtonPreference radioEdgeToEdge = mock(RadioButtonPreference.class);
PreferenceScreen screen = mock(PreferenceScreen.class);
when(screen.findPreference(PREF_KEY_LEGACY)).thenReturn(radioLegacy);
when(screen.findPreference(PREF_KEY_SWIPE_UP)).thenReturn(radioSwipeUp);
when(screen.findPreference(PREF_KEY_EDGE_TO_EDGE)).thenReturn(radioEdgeToEdge);
mController.displayPreference(screen);
mController.onRadioButtonClicked(radioEdgeToEdge);
verify(radioLegacy, times(1)).setChecked(false);
verify(radioSwipeUp, times(1)).setChecked(false);
verify(radioEdgeToEdge, times(1)).setChecked(true);
}
@Test
public void isSliceable_returnsFalse() {
assertThat(mController.isSliceable()).isFalse();
}
@Test
public void isSliceableIncorrectKey_returnsFalse() {
final SystemNavigationEdgeToEdgePreferenceController controller =
new SystemNavigationEdgeToEdgePreferenceController(mContext, "bad_key");
assertThat(controller.isSliceable()).isFalse();
}
}

View File

@@ -0,0 +1,115 @@
/*
* Copyright (C) 2019 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 android.os.UserHandle.USER_CURRENT;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON_OVERLAY;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON_OVERLAY;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL_OVERLAY;
import static com.android.settings.gestures.SystemNavigationGestureSettings.KEY_SYSTEM_NAV_2BUTTONS;
import static com.android.settings.gestures.SystemNavigationGestureSettings.KEY_SYSTEM_NAV_3BUTTONS;
import static com.android.settings.gestures.SystemNavigationGestureSettings.KEY_SYSTEM_NAV_GESTURAL;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import android.content.Context;
import android.content.om.IOverlayManager;
import android.os.ServiceManager;
import android.provider.SearchIndexableResource;
import android.text.TextUtils;
import com.android.internal.R;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import org.junit.Before;
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;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = SettingsShadowResources.class)
public class SystemNavigationGestureSettingsTest {
private Context mContext;
private IOverlayManager mOverlayManager;
private SystemNavigationGestureSettings mSettings;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mOverlayManager = mock(IOverlayManager.class);
mSettings = new SystemNavigationGestureSettings();
}
@Test
public void testSearchIndexProvider_shouldIndexResource() {
final List<SearchIndexableResource> indexRes =
SystemNavigationGestureSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
RuntimeEnvironment.application, true /* enabled */);
assertThat(indexRes).isNotNull();
assertThat(indexRes.get(0).xmlResId).isEqualTo(mSettings.getPreferenceScreenResId());
}
@Test
public void testGetCurrentSystemNavigationMode() {
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
NAV_BAR_MODE_GESTURAL);
assertThat(TextUtils.equals(mSettings.getCurrentSystemNavigationMode(mContext),
KEY_SYSTEM_NAV_GESTURAL)).isTrue();
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
NAV_BAR_MODE_3BUTTON);
assertThat(TextUtils.equals(mSettings.getCurrentSystemNavigationMode(mContext),
KEY_SYSTEM_NAV_3BUTTONS)).isTrue();
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
NAV_BAR_MODE_2BUTTON);
assertThat(TextUtils.equals(mSettings.getCurrentSystemNavigationMode(mContext),
KEY_SYSTEM_NAV_2BUTTONS)).isTrue();
}
@Test
public void testSetCurrentSystemNavigationMode() throws Exception {
mSettings.setCurrentSystemNavigationMode(mOverlayManager, KEY_SYSTEM_NAV_GESTURAL);
verify(mOverlayManager, times(1)).setEnabledExclusiveInCategory(
NAV_BAR_MODE_GESTURAL_OVERLAY, USER_CURRENT);
mSettings.setCurrentSystemNavigationMode(mOverlayManager, KEY_SYSTEM_NAV_2BUTTONS);
verify(mOverlayManager, times(1)).setEnabledExclusiveInCategory(
NAV_BAR_MODE_2BUTTON_OVERLAY, USER_CURRENT);
mSettings.setCurrentSystemNavigationMode(mOverlayManager, KEY_SYSTEM_NAV_3BUTTONS);
verify(mOverlayManager, times(1)).setEnabledExclusiveInCategory(
NAV_BAR_MODE_3BUTTON_OVERLAY, USER_CURRENT);
}
}

View File

@@ -1,201 +0,0 @@
/*
* Copyright (C) 2019 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 android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
import static com.android.settings.gestures.SystemNavigationEdgeToEdgePreferenceController.PREF_KEY_EDGE_TO_EDGE;
import static com.android.settings.gestures.SystemNavigationLegacyPreferenceController.PREF_KEY_LEGACY;
import static com.android.settings.gestures.SystemNavigationSwipeUpPreferenceController.PREF_KEY_SWIPE_UP;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.om.IOverlayManager;
import android.content.pm.ApplicationInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import androidx.preference.PreferenceScreen;
import com.android.internal.R;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settings.widget.RadioButtonPreference;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowPackageManager;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = SettingsShadowResources.class)
public class SystemNavigationLegacyPreferenceControllerTest {
private Context mContext;
private ShadowPackageManager mPackageManager;
@Mock
private IOverlayManager mOverlayManager;
private SystemNavigationLegacyPreferenceController mController;
private static final String ACTION_QUICKSTEP = "android.intent.action.QUICKSTEP_SERVICE";
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
SettingsShadowResources.overrideResource(R.bool.config_swipe_up_gesture_setting_available,
true);
mContext = RuntimeEnvironment.application;
mPackageManager = Shadows.shadowOf(mContext.getPackageManager());
mController = new SystemNavigationLegacyPreferenceController(mContext, mOverlayManager,
PREF_KEY_LEGACY);
}
@After
public void tearDown() {
SettingsShadowResources.reset();
}
@Test
public void testIsGestureAvailable_matchingServiceExists_shouldReturnTrue() {
final ComponentName recentsComponentName = ComponentName.unflattenFromString(
mContext.getString(com.android.internal.R.string.config_recentsComponentName));
final Intent quickStepIntent = new Intent(ACTION_QUICKSTEP)
.setPackage(recentsComponentName.getPackageName());
final ResolveInfo info = new ResolveInfo();
info.serviceInfo = new ServiceInfo();
info.resolvePackageName = recentsComponentName.getPackageName();
info.serviceInfo.packageName = info.resolvePackageName;
info.serviceInfo.name = recentsComponentName.getClassName();
info.serviceInfo.applicationInfo = new ApplicationInfo();
info.serviceInfo.applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
mPackageManager.addResolveInfoForIntent(quickStepIntent, info);
assertThat(SystemNavigationLegacyPreferenceController.isGestureAvailable(mContext))
.isTrue();
}
@Test
public void testIsGestureAvailable_overlayDisabled_matchingServiceExists_shouldReturnFalse() {
SettingsShadowResources.overrideResource(R.bool.config_swipe_up_gesture_setting_available,
false);
final ComponentName recentsComponentName = ComponentName.unflattenFromString(
mContext.getString(com.android.internal.R.string.config_recentsComponentName));
final Intent quickStepIntent = new Intent(ACTION_QUICKSTEP)
.setPackage(recentsComponentName.getPackageName());
mPackageManager.addResolveInfoForIntent(quickStepIntent, new ResolveInfo());
assertThat(
SystemNavigationLegacyPreferenceController.isGestureAvailable(mContext)).isFalse();
}
@Test
public void testIsGestureAvailable_noMatchingServiceExists_shouldReturnFalse() {
assertThat(
SystemNavigationLegacyPreferenceController.isGestureAvailable(mContext)).isFalse();
}
@Test
public void testIsGestureAvailable_noOverlayPackage_shouldReturnFalse() {
assertThat(SystemNavigationLegacyPreferenceController.isGestureAvailable(mContext,
"com.package.fake")).isFalse();
}
@Test
public void testIsChecked_defaultIsLegacy_shouldReturnTrue() {
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
NAV_BAR_MODE_3BUTTON);
assertThat(mController.isChecked()).isTrue();
}
@Test
public void testIsChecked_defaultIsSwipeUp_shouldReturnFalse() {
// Turn on the Swipe Up mode (2-buttons)
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
NAV_BAR_MODE_2BUTTON);
assertThat(mController.isChecked()).isFalse();
}
@Test
public void testIsChecked_defaultIsEdgeToEdge_shouldReturnFalse() {
// Turn on the Edge to Edge
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
NAV_BAR_MODE_GESTURAL);
assertThat(mController.isChecked()).isFalse();
}
@Test
public void testIsChecked_radioButtonClicked_shouldReturnTrue() {
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
NAV_BAR_MODE_3BUTTON);
// Set the setting to be enabled.
mController.onRadioButtonClicked(null);
assertThat(mController.isChecked()).isTrue();
}
@Test
public void testOnRadioButtonClicked_setsCorrectRadioButtonChecked() {
RadioButtonPreference radioLegacy = mock(RadioButtonPreference.class);
RadioButtonPreference radioSwipeUp = mock(RadioButtonPreference.class);
RadioButtonPreference radioEdgeToEdge = mock(RadioButtonPreference.class);
PreferenceScreen screen = mock(PreferenceScreen.class);
when(screen.findPreference(PREF_KEY_LEGACY)).thenReturn(radioLegacy);
when(screen.findPreference(PREF_KEY_SWIPE_UP)).thenReturn(radioSwipeUp);
when(screen.findPreference(PREF_KEY_EDGE_TO_EDGE)).thenReturn(radioEdgeToEdge);
mController.displayPreference(screen);
mController.onRadioButtonClicked(radioLegacy);
verify(radioLegacy, times(1)).setChecked(true);
verify(radioSwipeUp, times(1)).setChecked(false);
verify(radioEdgeToEdge, times(1)).setChecked(false);
}
@Test
public void isSliceable_returnsFalse() {
assertThat(mController.isSliceable()).isFalse();
}
@Test
public void isSliceableIncorrectKey_returnsFalse() {
final SystemNavigationLegacyPreferenceController controller =
new SystemNavigationLegacyPreferenceController(mContext, "bad_key");
assertThat(controller.isSliceable()).isFalse();
}
}

View File

@@ -11,7 +11,7 @@
* 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.
* limitations under the License
*/
package com.android.settings.gestures;
@@ -20,36 +20,25 @@ import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
import static com.android.settings.gestures.SystemNavigationEdgeToEdgePreferenceController.PREF_KEY_EDGE_TO_EDGE;
import static com.android.settings.gestures.SystemNavigationLegacyPreferenceController.PREF_KEY_LEGACY;
import static com.android.settings.gestures.SystemNavigationSwipeUpPreferenceController.PREF_KEY_SWIPE_UP;
import static com.android.settings.gestures.SystemNavigationPreferenceController.PREF_KEY_SYSTEM_NAVIGATION;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.om.IOverlayManager;
import android.content.pm.ApplicationInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import androidx.preference.PreferenceScreen;
import android.text.TextUtils;
import com.android.internal.R;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settings.widget.RadioButtonPreference;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@@ -59,15 +48,12 @@ import org.robolectric.shadows.ShadowPackageManager;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = SettingsShadowResources.class)
public class SystemNavigationSwipeUpPreferenceControllerTest {
public class SystemNavigationPreferenceControllerTest {
private Context mContext;
private ShadowPackageManager mPackageManager;
@Mock
private IOverlayManager mOverlayManager;
private SystemNavigationSwipeUpPreferenceController mController;
private SystemNavigationPreferenceController mController;
private static final String ACTION_QUICKSTEP = "android.intent.action.QUICKSTEP_SERVICE";
@@ -81,8 +67,8 @@ public class SystemNavigationSwipeUpPreferenceControllerTest {
mContext = RuntimeEnvironment.application;
mPackageManager = Shadows.shadowOf(mContext.getPackageManager());
mController = new SystemNavigationSwipeUpPreferenceController(mContext, mOverlayManager,
PREF_KEY_SWIPE_UP);
mController = new SystemNavigationPreferenceController(mContext,
PREF_KEY_SYSTEM_NAVIGATION);
}
@After
@@ -105,8 +91,7 @@ public class SystemNavigationSwipeUpPreferenceControllerTest {
info.serviceInfo.applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
mPackageManager.addResolveInfoForIntent(quickStepIntent, info);
assertThat(SystemNavigationSwipeUpPreferenceController.isGestureAvailable(mContext))
.isTrue();
assertThat(SystemNavigationPreferenceController.isGestureAvailable(mContext)).isTrue();
}
@Test
@@ -120,80 +105,65 @@ public class SystemNavigationSwipeUpPreferenceControllerTest {
.setPackage(recentsComponentName.getPackageName());
mPackageManager.addResolveInfoForIntent(quickStepIntent, new ResolveInfo());
assertThat(SystemNavigationSwipeUpPreferenceController.isGestureAvailable(mContext))
.isFalse();
assertThat(SystemNavigationPreferenceController.isGestureAvailable(mContext)).isFalse();
}
@Test
public void testIsGestureAvailable_noMatchingServiceExists_shouldReturnFalse() {
assertThat(SystemNavigationSwipeUpPreferenceController.isGestureAvailable(mContext))
.isFalse();
assertThat(SystemNavigationPreferenceController.isGestureAvailable(mContext)).isFalse();
}
@Test
public void testIsGestureAvailable_noOverlayPackage_shouldReturnFalse() {
assertThat(SystemNavigationSwipeUpPreferenceController.isGestureAvailable(mContext,
public void testIsOverlayPackageAvailable_noOverlayPackage_shouldReturnFalse() {
assertThat(SystemNavigationPreferenceController.isOverlayPackageAvailable(mContext,
"com.package.fake")).isFalse();
}
@Test
public void testIsChecked_defaultIsSwipeUp_shouldReturnTrue() {
public void testIsSwipeUpEnabled() {
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
NAV_BAR_MODE_2BUTTON);
assertThat(mController.isChecked()).isTrue();
}
assertThat(SystemNavigationPreferenceController.isSwipeUpEnabled(mContext)).isTrue();
@Test
public void testIsChecked_defaultIsLegacy_shouldReturnFalse() {
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
NAV_BAR_MODE_3BUTTON);
assertThat(mController.isChecked()).isFalse();
}
assertThat(SystemNavigationPreferenceController.isSwipeUpEnabled(mContext)).isFalse();
@Test
public void testIsChecked_defaultIsEdgeToEdge_shouldReturnFalse() {
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
NAV_BAR_MODE_GESTURAL);
assertThat(mController.isChecked()).isFalse();
assertThat(SystemNavigationPreferenceController.isSwipeUpEnabled(mContext)).isFalse();
}
@Test
public void testIsChecked_radioButtonClicked_shouldReturnTrue() {
public void testIsEdgeToEdgeEnabled() {
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
NAV_BAR_MODE_GESTURAL);
assertThat(SystemNavigationPreferenceController.isEdgeToEdgeEnabled(mContext)).isTrue();
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
NAV_BAR_MODE_3BUTTON);
assertThat(SystemNavigationPreferenceController.isEdgeToEdgeEnabled(mContext)).isFalse();
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
NAV_BAR_MODE_2BUTTON);
// Set the setting to be enabled.
mController.onRadioButtonClicked(null);
assertThat(mController.isChecked()).isTrue();
assertThat(SystemNavigationPreferenceController.isEdgeToEdgeEnabled(mContext)).isFalse();
}
@Test
public void testOnRadioButtonClicked_setsCorrectRadioButtonChecked() {
RadioButtonPreference radioLegacy = mock(RadioButtonPreference.class);
RadioButtonPreference radioSwipeUp = mock(RadioButtonPreference.class);
RadioButtonPreference radioEdgeToEdge = mock(RadioButtonPreference.class);
PreferenceScreen screen = mock(PreferenceScreen.class);
public void testGetSummary() {
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
NAV_BAR_MODE_GESTURAL);
assertThat(TextUtils.equals(mController.getSummary(), mContext.getText(
com.android.settings.R.string.edge_to_edge_navigation_title))).isTrue();
when(screen.findPreference(PREF_KEY_LEGACY)).thenReturn(radioLegacy);
when(screen.findPreference(PREF_KEY_SWIPE_UP)).thenReturn(radioSwipeUp);
when(screen.findPreference(PREF_KEY_EDGE_TO_EDGE)).thenReturn(radioEdgeToEdge);
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
NAV_BAR_MODE_3BUTTON);
assertThat(TextUtils.equals(mController.getSummary(),
mContext.getText(com.android.settings.R.string.legacy_navigation_title))).isTrue();
mController.displayPreference(screen);
mController.onRadioButtonClicked(radioSwipeUp);
verify(radioLegacy, times(1)).setChecked(false);
verify(radioSwipeUp, times(1)).setChecked(true);
verify(radioEdgeToEdge, times(1)).setChecked(false);
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
NAV_BAR_MODE_2BUTTON);
assertThat(TextUtils.equals(mController.getSummary(), mContext.getText(
com.android.settings.R.string.swipe_up_to_switch_apps_title))).isTrue();
}
@Test
public void isSliceable_returnsFalse() {
assertThat(mController.isSliceable()).isFalse();
}
@Test
public void isSliceableIncorrectKey_returnsFalse() {
final SystemNavigationSwipeUpPreferenceController controller =
new SystemNavigationSwipeUpPreferenceController(mContext, "bad_key");
assertThat(controller.isSliceable()).isFalse();
}
}
}