Merge "Adds Edge to Edge option in gesture settings page"

This commit is contained in:
Mehdi Alizadeh
2019-03-08 04:49:41 +00:00
committed by Android (Google) Code Review
13 changed files with 788 additions and 135 deletions

View File

@@ -0,0 +1,174 @@
/*
* 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 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.when;
import static org.mockito.Mockito.verify;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.provider.Settings;
import androidx.preference.Preference;
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.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;
private SystemNavigationEdgeToEdgePreferenceController mController;
private static final String ACTION_QUICKSTEP = "android.intent.action.QUICKSTEP_SERVICE";
@Before
public void setUp() {
SettingsShadowResources.overrideResource(R.bool.config_swipe_up_gesture_setting_available,
true);
SettingsShadowResources.overrideResource(R.bool.config_swipe_up_gesture_default, true);
mContext = RuntimeEnvironment.application;
Settings.Global.putInt(mContext.getContentResolver(), "prototype_enabled", 1);
mPackageManager = Shadows.shadowOf(mContext.getPackageManager());
mController = new SystemNavigationEdgeToEdgePreferenceController(mContext,
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 testIsChecked_defaultIsTrue_shouldReturnTrue() {
assertThat(mController.isChecked()).isTrue();
}
@Test
public void testIsChecked_defaultIsFalse_shouldReturnFalse() {
Settings.Global.putInt(mContext.getContentResolver(), "prototype_enabled", 0);
assertThat(mController.isChecked()).isFalse();
}
@Test
public void testIsChecked_radioButtonClicked_shouldReturnTrue() {
// 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 isSliceableCorrectKey_returnsTrue() {
assertThat(mController.isSliceable()).isTrue();
}
@Test
public void isSliceableIncorrectKey_returnsFalse() {
final SystemNavigationEdgeToEdgePreferenceController controller =
new SystemNavigationEdgeToEdgePreferenceController(mContext, "bad_key");
assertThat(controller.isSliceable()).isFalse();
}
}

View File

@@ -0,0 +1,171 @@
/*
* 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 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.when;
import static org.mockito.Mockito.verify;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import androidx.preference.Preference;
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.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;
private SystemNavigationLegacyPreferenceController mController;
private static final String ACTION_QUICKSTEP = "android.intent.action.QUICKSTEP_SERVICE";
@Before
public void setUp() {
SettingsShadowResources.overrideResource(R.bool.config_swipe_up_gesture_setting_available,
true);
SettingsShadowResources.overrideResource(R.bool.config_swipe_up_gesture_default, false);
mContext = RuntimeEnvironment.application;
mPackageManager = Shadows.shadowOf(mContext.getPackageManager());
mController = new SystemNavigationLegacyPreferenceController(mContext, 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 testIsChecked_defaultIsTrue_shouldReturnTrue() {
assertThat(mController.isChecked()).isTrue();
}
@Test
public void testIsChecked_defaultIsFalse_shouldReturnFalse() {
// Turn on the Swipe Up mode (2-buttons)
SettingsShadowResources.overrideResource(R.bool.config_swipe_up_gesture_default, true);
assertThat(mController.isChecked()).isFalse();
}
@Test
public void testIsChecked_radioButtonClicked_shouldReturnTrue() {
// 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 isSliceableCorrectKey_returnsTrue() {
assertThat(mController.isSliceable()).isTrue();
}
@Test
public void isSliceableIncorrectKey_returnsFalse() {
final SystemNavigationLegacyPreferenceController controller =
new SystemNavigationLegacyPreferenceController(mContext, "bad_key");
assertThat(controller.isSliceable()).isFalse();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 The Android Open Source Project
* 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.
@@ -16,8 +16,17 @@
package com.android.settings.gestures;
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.when;
import static org.mockito.Mockito.verify;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -25,8 +34,12 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import androidx.preference.Preference;
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;
@@ -40,14 +53,14 @@ import org.robolectric.shadows.ShadowPackageManager;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = SettingsShadowResources.class)
public class SwipeUpPreferenceControllerTest {
public class SystemNavigationSwipeUpPreferenceControllerTest {
private Context mContext;
private ShadowPackageManager mPackageManager;
private SwipeUpPreferenceController mController;
private SystemNavigationSwipeUpPreferenceController mController;
private static final String ACTION_QUICKSTEP = "android.intent.action.QUICKSTEP_SERVICE";
private static final String KEY_SWIPE_UP = "gesture_swipe_up";
@Before
public void setUp() {
@@ -57,7 +70,8 @@ public class SwipeUpPreferenceControllerTest {
mContext = RuntimeEnvironment.application;
mPackageManager = Shadows.shadowOf(mContext.getPackageManager());
mController = new SwipeUpPreferenceController(mContext, KEY_SWIPE_UP);
mController = new SystemNavigationSwipeUpPreferenceController(mContext, PREF_KEY_SWIPE_UP);
}
@After
@@ -80,7 +94,8 @@ public class SwipeUpPreferenceControllerTest {
info.serviceInfo.applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
mPackageManager.addResolveInfoForIntent(quickStepIntent, info);
assertThat(SwipeUpPreferenceController.isGestureAvailable(mContext)).isTrue();
assertThat(SystemNavigationSwipeUpPreferenceController.isGestureAvailable(mContext))
.isTrue();
}
@Test
@@ -94,12 +109,14 @@ public class SwipeUpPreferenceControllerTest {
.setPackage(recentsComponentName.getPackageName());
mPackageManager.addResolveInfoForIntent(quickStepIntent, new ResolveInfo());
assertThat(SwipeUpPreferenceController.isGestureAvailable(mContext)).isFalse();
assertThat(SystemNavigationSwipeUpPreferenceController.isGestureAvailable(mContext))
.isFalse();
}
@Test
public void testIsGestureAvailable_noMatchingServiceExists_shouldReturnFalse() {
assertThat(SwipeUpPreferenceController.isGestureAvailable(mContext)).isFalse();
assertThat(SystemNavigationSwipeUpPreferenceController.isGestureAvailable(mContext))
.isFalse();
}
@Test
@@ -114,30 +131,40 @@ public class SwipeUpPreferenceControllerTest {
}
@Test
public void testIsChecked_setCheckedTrue_shouldReturnTrue() {
public void testIsChecked_radioButtonClicked_shouldReturnTrue() {
// Set the setting to be enabled.
mController.setChecked(true);
mController.onRadioButtonClicked(null);
assertThat(mController.isChecked()).isTrue();
}
@Test
public void testIsChecked_setCheckedFalse_shouldReturnFalse() {
// Set the setting to be disabled.
mController.setChecked(false);
assertThat(mController.isChecked()).isFalse();
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(radioSwipeUp);
verify(radioLegacy, times(1)).setChecked(false);
verify(radioSwipeUp, times(1)).setChecked(true);
verify(radioEdgeToEdge, times(1)).setChecked(false);
}
@Test
public void isSliceableCorrectKey_returnsTrue() {
final SwipeUpPreferenceController controller =
new SwipeUpPreferenceController(mContext, "gesture_swipe_up");
assertThat(controller.isSliceable()).isTrue();
assertThat(mController.isSliceable()).isTrue();
}
@Test
public void isSliceableIncorrectKey_returnsFalse() {
final SwipeUpPreferenceController controller =
new SwipeUpPreferenceController(mContext, "bad_key");
final SystemNavigationSwipeUpPreferenceController controller =
new SystemNavigationSwipeUpPreferenceController(mContext, "bad_key");
assertThat(controller.isSliceable()).isFalse();
}
}