Merge "Find the double twist sensor using the type instead of the name" into sc-dev am: 6e972e81ef
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/15270335 Change-Id: Ibbc0b965e9b0676cefc78570f5ec46c6bbc30330
This commit is contained in:
@@ -58,8 +58,8 @@
|
|||||||
<!-- Manufacturer backup settings label -->
|
<!-- Manufacturer backup settings label -->
|
||||||
<string name="config_backup_settings_label" translatable="true"></string>
|
<string name="config_backup_settings_label" translatable="true"></string>
|
||||||
|
|
||||||
<!-- Double twist sensor name and vendor used by gesture setting -->
|
<!-- Double twist sensor type and vendor used by gesture setting -->
|
||||||
<string name="gesture_double_twist_sensor_name" translatable="false"></string>
|
<string name="gesture_double_twist_sensor_type" translatable="false"></string>
|
||||||
<string name="gesture_double_twist_sensor_vendor" translatable="false"></string>
|
<string name="gesture_double_twist_sensor_vendor" translatable="false"></string>
|
||||||
|
|
||||||
<!-- When true enable gesture setting. -->
|
<!-- When true enable gesture setting. -->
|
||||||
|
@@ -53,13 +53,13 @@ public class DoubleTwistPreferenceController extends GesturePreferenceController
|
|||||||
|
|
||||||
public static boolean isGestureAvailable(Context context) {
|
public static boolean isGestureAvailable(Context context) {
|
||||||
final Resources resources = context.getResources();
|
final Resources resources = context.getResources();
|
||||||
final String name = resources.getString(R.string.gesture_double_twist_sensor_name);
|
final String type = resources.getString(R.string.gesture_double_twist_sensor_type);
|
||||||
final String vendor = resources.getString(R.string.gesture_double_twist_sensor_vendor);
|
final String vendor = resources.getString(R.string.gesture_double_twist_sensor_vendor);
|
||||||
if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(vendor)) {
|
if (!TextUtils.isEmpty(type) && !TextUtils.isEmpty(vendor)) {
|
||||||
final SensorManager sensorManager =
|
final SensorManager sensorManager =
|
||||||
(SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
(SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
||||||
for (Sensor s : sensorManager.getSensorList(Sensor.TYPE_ALL)) {
|
for (Sensor s : sensorManager.getSensorList(Sensor.TYPE_ALL)) {
|
||||||
if (name.equals(s.getName()) && vendor.equals(s.getVendor())) {
|
if (type.equals(s.getStringType()) && vendor.equals(s.getVendor())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -78,7 +78,7 @@ public class DoubleTwistPreferenceControllerTest {
|
|||||||
when(mContext.getResources().getString(anyInt())).thenReturn("test");
|
when(mContext.getResources().getString(anyInt())).thenReturn("test");
|
||||||
when(mContext.getSystemService(Context.SENSOR_SERVICE)).thenReturn(mSensorManager);
|
when(mContext.getSystemService(Context.SENSOR_SERVICE)).thenReturn(mSensorManager);
|
||||||
when(mSensorManager.getSensorList(anyInt())).thenReturn(sensorList);
|
when(mSensorManager.getSensorList(anyInt())).thenReturn(sensorList);
|
||||||
when(sensorList.get(0).getName()).thenReturn("test");
|
when(sensorList.get(0).getStringType()).thenReturn("test");
|
||||||
when(sensorList.get(0).getVendor()).thenReturn("test");
|
when(sensorList.get(0).getVendor()).thenReturn("test");
|
||||||
|
|
||||||
assertThat(mController.isAvailable()).isTrue();
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
@@ -97,7 +97,7 @@ public class DoubleTwistPreferenceControllerTest {
|
|||||||
when(mContext.getResources().getString(anyInt())).thenReturn("test");
|
when(mContext.getResources().getString(anyInt())).thenReturn("test");
|
||||||
when(mContext.getSystemService(Context.SENSOR_SERVICE)).thenReturn(mSensorManager);
|
when(mContext.getSystemService(Context.SENSOR_SERVICE)).thenReturn(mSensorManager);
|
||||||
when(mSensorManager.getSensorList(anyInt())).thenReturn(sensorList);
|
when(mSensorManager.getSensorList(anyInt())).thenReturn(sensorList);
|
||||||
when(sensorList.get(0).getName()).thenReturn("not_test");
|
when(sensorList.get(0).getStringType()).thenReturn("not_test");
|
||||||
|
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
}
|
}
|
||||||
@@ -105,9 +105,9 @@ public class DoubleTwistPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void isSuggestionCompleted_doubleTwist_trueWhenNotAvailable() {
|
public void isSuggestionCompleted_doubleTwist_trueWhenNotAvailable() {
|
||||||
SettingsShadowResources.overrideResource(
|
SettingsShadowResources.overrideResource(
|
||||||
R.string.gesture_double_twist_sensor_name, "nonexistant name");
|
R.string.gesture_double_twist_sensor_type, "nonexistent type");
|
||||||
SettingsShadowResources.overrideResource(
|
SettingsShadowResources.overrideResource(
|
||||||
R.string.gesture_double_twist_sensor_vendor, "nonexistant vendor");
|
R.string.gesture_double_twist_sensor_vendor, "nonexistent vendor");
|
||||||
|
|
||||||
assertThat(DoubleTwistPreferenceController.isSuggestionComplete(
|
assertThat(DoubleTwistPreferenceController.isSuggestionComplete(
|
||||||
RuntimeEnvironment.application, null /* prefs */))
|
RuntimeEnvironment.application, null /* prefs */))
|
||||||
|
Reference in New Issue
Block a user