Merge changes from topic "swipe-up-gesture-overlay" into pi-dev
am: 3167f72961
Change-Id: Iac284f04b0ba862064ea5d2822819eaf31dcb4c0
This commit is contained in:
@@ -131,4 +131,7 @@
|
|||||||
<!-- List of a11y components on the device allowed to be enabled by Settings Slices -->
|
<!-- List of a11y components on the device allowed to be enabled by Settings Slices -->
|
||||||
<string-array name="config_settings_slices_accessibility_components" translatable="false"/>
|
<string-array name="config_settings_slices_accessibility_components" translatable="false"/>
|
||||||
|
|
||||||
|
<!-- Whether or not swipe up gesture's opt-in setting is available on this device -->
|
||||||
|
<bool name="config_swipe_up_gesture_setting_available">false</bool>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -24,6 +24,8 @@ import android.os.UserManager;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
public class SwipeUpPreferenceController extends GesturePreferenceController {
|
public class SwipeUpPreferenceController extends GesturePreferenceController {
|
||||||
|
|
||||||
private final int ON = 1;
|
private final int ON = 1;
|
||||||
@@ -39,6 +41,10 @@ public class SwipeUpPreferenceController extends GesturePreferenceController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static boolean isGestureAvailable(Context context) {
|
static boolean isGestureAvailable(Context context) {
|
||||||
|
if (!context.getResources().getBoolean(R.bool.config_swipe_up_gesture_setting_available)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
final ComponentName recentsComponentName = ComponentName.unflattenFromString(
|
final ComponentName recentsComponentName = ComponentName.unflattenFromString(
|
||||||
context.getString(com.android.internal.R.string.config_recentsComponentName));
|
context.getString(com.android.internal.R.string.config_recentsComponentName));
|
||||||
final Intent quickStepIntent = new Intent(ACTION_QUICKSTEP)
|
final Intent quickStepIntent = new Intent(ACTION_QUICKSTEP)
|
||||||
@@ -74,8 +80,10 @@ public class SwipeUpPreferenceController extends GesturePreferenceController {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isChecked() {
|
public boolean isChecked() {
|
||||||
|
final int defaultValue = mContext.getResources()
|
||||||
|
.getBoolean(com.android.internal.R.bool.config_swipe_up_gesture_default) ? ON : OFF;
|
||||||
final int swipeUpEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
|
final int swipeUpEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
Settings.Secure.SWIPE_UP_TO_SWITCH_APPS_ENABLED, OFF);
|
Settings.Secure.SWIPE_UP_TO_SWITCH_APPS_ENABLED, defaultValue);
|
||||||
return swipeUpEnabled != OFF;
|
return swipeUpEnabled != OFF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,35 +18,32 @@ package com.android.settings.gestures;
|
|||||||
|
|
||||||
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;
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.hardware.Sensor;
|
|
||||||
import android.hardware.SensorManager;
|
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Answers;
|
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.Shadows;
|
import org.robolectric.Shadows;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
import org.robolectric.shadows.ShadowPackageManager;
|
import org.robolectric.shadows.ShadowPackageManager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(shadows = SettingsShadowResources.class)
|
||||||
public class SwipeUpPreferenceControllerTest {
|
public class SwipeUpPreferenceControllerTest {
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
@@ -58,11 +55,21 @@ public class SwipeUpPreferenceControllerTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
SettingsShadowResources.overrideResource(R.bool.config_swipe_up_gesture_setting_available,
|
||||||
|
true);
|
||||||
|
SettingsShadowResources.overrideResource(
|
||||||
|
com.android.internal.R.bool.config_swipe_up_gesture_default, true);
|
||||||
|
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
mPackageManager = Shadows.shadowOf(mContext.getPackageManager());
|
mPackageManager = Shadows.shadowOf(mContext.getPackageManager());
|
||||||
mController = new SwipeUpPreferenceController(mContext, KEY_SWIPE_UP);
|
mController = new SwipeUpPreferenceController(mContext, KEY_SWIPE_UP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
SettingsShadowResources.reset();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsGestureAvailable_matchingServiceExists_shouldReturnTrue() {
|
public void testIsGestureAvailable_matchingServiceExists_shouldReturnTrue() {
|
||||||
final ComponentName recentsComponentName = ComponentName.unflattenFromString(
|
final ComponentName recentsComponentName = ComponentName.unflattenFromString(
|
||||||
@@ -74,20 +81,46 @@ public class SwipeUpPreferenceControllerTest {
|
|||||||
assertThat(SwipeUpPreferenceController.isGestureAvailable(mContext)).isTrue();
|
assertThat(SwipeUpPreferenceController.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(SwipeUpPreferenceController.isGestureAvailable(mContext)).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsGestureAvailable_noMatchingServiceExists_shouldReturnFalse() {
|
public void testIsGestureAvailable_noMatchingServiceExists_shouldReturnFalse() {
|
||||||
assertThat(SwipeUpPreferenceController.isGestureAvailable(mContext)).isFalse();
|
assertThat(SwipeUpPreferenceController.isGestureAvailable(mContext)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsChecked_configIsSet_shouldReturnTrue() {
|
public void testIsChecked_defaultIsTrue_shouldReturnTrue() {
|
||||||
|
assertThat(mController.isChecked()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsChecked_defaultIsFalse_shouldReturnFalse() {
|
||||||
|
SettingsShadowResources.overrideResource(
|
||||||
|
com.android.internal.R.bool.config_swipe_up_gesture_default, false);
|
||||||
|
assertThat(mController.isChecked()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsChecked_setCheckedTrue_shouldReturnTrue() {
|
||||||
// Set the setting to be enabled.
|
// Set the setting to be enabled.
|
||||||
mController.setChecked(true);
|
mController.setChecked(true);
|
||||||
assertThat(mController.isChecked()).isTrue();
|
assertThat(mController.isChecked()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsChecked_configIsNotSet_shouldReturnFalse() {
|
public void testIsChecked_setCheckedFalse_shouldReturnFalse() {
|
||||||
// Set the setting to be disabled.
|
// Set the setting to be disabled.
|
||||||
mController.setChecked(false);
|
mController.setChecked(false);
|
||||||
assertThat(mController.isChecked()).isFalse();
|
assertThat(mController.isChecked()).isFalse();
|
||||||
|
Reference in New Issue
Block a user