(2/n) Stop user from enabling OHM setting if user is using 3-button
mode Return One-Handed mode getAvailabilityStatus to UNSUPPORTED_ON_DEVICE when SystemNavigationMode is 3-button. Bug: 184903678 Test: manual Test: manual verified on Settings > System > Gesture page Test: make RunSettingsRoboTests ROBOTEST_FILTER= "com.android.settings.gestures .OneHandedEnablePreferenceControllerTest" Test: make RunSettingsRoboTests ROBOTEST_FILTER= "com.android.settings.gestures .SwipeBottomToNotificationPreferenceControllerTest" Change-Id: I454dabb5cc267d544732fa5079f3146154d0568c
This commit is contained in:
@@ -19,7 +19,6 @@ package com.android.settings.gestures;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.widget.SettingsMainSwitchPreferenceController;
|
||||
|
||||
/**
|
||||
@@ -33,9 +32,8 @@ public class OneHandedEnablePreferenceController extends SettingsMainSwitchPrefe
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return OneHandedSettingsUtils.isSupportOneHandedMode()
|
||||
? BasePreferenceController.AVAILABLE
|
||||
: BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||
return OneHandedSettingsUtils.isFeatureAvailable(mContext)
|
||||
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -176,6 +176,28 @@ public class OneHandedSettingsUtils {
|
||||
sCurrentUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get NavigationBar mode flag from Settings provider.
|
||||
* @param context App context
|
||||
* @return Navigation bar mode:
|
||||
* 0 = 3 button
|
||||
* 1 = 2 button
|
||||
* 2 = fully gestural
|
||||
*/
|
||||
public static int getNavigationBarMode(Context context) {
|
||||
return Settings.Secure.getIntForUser(context.getContentResolver(),
|
||||
Settings.Secure.NAVIGATION_MODE, 2 /* fully gestural */, sCurrentUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context App context
|
||||
* @return Support One-Handed mode feature or not.
|
||||
*/
|
||||
public static boolean isFeatureAvailable(Context context) {
|
||||
return isSupportOneHandedMode() && getNavigationBarMode(context) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers callback for observing Settings.Secure.ONE_HANDED_MODE_ENABLED state.
|
||||
* @param callback for state changes
|
||||
|
@@ -33,7 +33,8 @@ public class SwipeBottomToNotificationPreferenceController extends TogglePrefere
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return OneHandedSettingsUtils.isSupportOneHandedMode() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
return OneHandedSettingsUtils.isFeatureAvailable(mContext)
|
||||
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import android.content.Context;
|
||||
import android.os.SystemProperties;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
@@ -60,6 +61,7 @@ public class OneHandedEnablePreferenceControllerTest {
|
||||
@Test
|
||||
public void getAvailabilityStatus_setSupportOneHandedModeProperty_shouldAvailable() {
|
||||
SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true");
|
||||
setNavigationBarMode(mContext, "2" /* fully gestural */);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||
@@ -68,6 +70,16 @@ public class OneHandedEnablePreferenceControllerTest {
|
||||
@Test
|
||||
public void getAvailabilityStatus_unsetSupportOneHandedModeProperty_shouldUnsupported() {
|
||||
SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "false");
|
||||
setNavigationBarMode(mContext, "2" /* fully gestural */);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_set3ButtonModeProperty_shouldUnsupported() {
|
||||
SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true");
|
||||
setNavigationBarMode(mContext, "0" /* 3-button */);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
@@ -88,4 +100,18 @@ public class OneHandedEnablePreferenceControllerTest {
|
||||
assertThat(mController.getSummary())
|
||||
.isEqualTo(mContext.getText(R.string.switch_off_text));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set NavigationBar mode flag to Settings provider.
|
||||
* @param context App context
|
||||
* @param value Navigation bar mode:
|
||||
* 0 = 3 button
|
||||
* 1 = 2 button
|
||||
* 2 = fully gestural
|
||||
* @return true if the value was set, false on database errors.
|
||||
*/
|
||||
private boolean setNavigationBarMode(Context context, String value) {
|
||||
return Settings.Secure.putStringForUser(context.getContentResolver(),
|
||||
Settings.Secure.NAVIGATION_MODE, value, UserHandle.myUserId());
|
||||
}
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.SystemProperties;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -69,6 +70,7 @@ public class SwipeBottomToNotificationPreferenceControllerTest {
|
||||
@Test
|
||||
public void getAvailabilityStatus_oneHandedUnsupported_returnsUnsupport() {
|
||||
SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "false");
|
||||
setNavigationBarMode(mContext, "2" /* fully gestural */);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
@@ -77,10 +79,20 @@ public class SwipeBottomToNotificationPreferenceControllerTest {
|
||||
@Test
|
||||
public void getAvailabilityStatus_oneHandedSupported_returnsAvailable() {
|
||||
SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true");
|
||||
setNavigationBarMode(mContext, "2" /* fully gestural */);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_set3ButtonModeProperty_returnsUnsupport() {
|
||||
SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true");
|
||||
setNavigationBarMode(mContext, "0" /* 3-button */);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_gestureEnabled_returnsOnSummary() {
|
||||
mController.setChecked(true);
|
||||
@@ -105,4 +117,18 @@ public class SwipeBottomToNotificationPreferenceControllerTest {
|
||||
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set NavigationBar mode flag to Settings provider.
|
||||
* @param context App context
|
||||
* @param value Navigation bar mode:
|
||||
* 0 = 3 button
|
||||
* 1 = 2 button
|
||||
* 2 = fully gestural
|
||||
* @return true if the value was set, false on database errors.
|
||||
*/
|
||||
private boolean setNavigationBarMode(Context context, String value) {
|
||||
return Settings.Secure.putStringForUser(context.getContentResolver(),
|
||||
Settings.Secure.NAVIGATION_MODE, value, UserHandle.myUserId());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user