Merge "SysUi ThresholdSensorImpl registers for wakeup variant" into sc-dev
This commit is contained in:
@@ -36,12 +36,13 @@ public class SensorModule {
|
|||||||
try {
|
try {
|
||||||
return thresholdSensorBuilder
|
return thresholdSensorBuilder
|
||||||
.setSensorDelay(SensorManager.SENSOR_DELAY_NORMAL)
|
.setSensorDelay(SensorManager.SENSOR_DELAY_NORMAL)
|
||||||
.setSensorResourceId(R.string.proximity_sensor_type)
|
.setSensorResourceId(R.string.proximity_sensor_type, true)
|
||||||
.setThresholdResourceId(R.dimen.proximity_sensor_threshold)
|
.setThresholdResourceId(R.dimen.proximity_sensor_threshold)
|
||||||
.setThresholdLatchResourceId(R.dimen.proximity_sensor_threshold_latch)
|
.setThresholdLatchResourceId(R.dimen.proximity_sensor_threshold_latch)
|
||||||
.build();
|
.build();
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
Sensor defaultSensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
|
Sensor defaultSensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY,
|
||||||
|
true);
|
||||||
return thresholdSensorBuilder
|
return thresholdSensorBuilder
|
||||||
.setSensor(defaultSensor)
|
.setSensor(defaultSensor)
|
||||||
.setThresholdValue(defaultSensor != null ? defaultSensor.getMaximumRange() : 0)
|
.setThresholdValue(defaultSensor != null ? defaultSensor.getMaximumRange() : 0)
|
||||||
@@ -55,7 +56,7 @@ public class SensorModule {
|
|||||||
ThresholdSensorImpl.Builder thresholdSensorBuilder) {
|
ThresholdSensorImpl.Builder thresholdSensorBuilder) {
|
||||||
try {
|
try {
|
||||||
return thresholdSensorBuilder
|
return thresholdSensorBuilder
|
||||||
.setSensorResourceId(R.string.proximity_sensor_secondary_type)
|
.setSensorResourceId(R.string.proximity_sensor_secondary_type, true)
|
||||||
.setThresholdResourceId(R.dimen.proximity_sensor_secondary_threshold)
|
.setThresholdResourceId(R.dimen.proximity_sensor_secondary_threshold)
|
||||||
.setThresholdLatchResourceId(R.dimen.proximity_sensor_secondary_threshold_latch)
|
.setThresholdLatchResourceId(R.dimen.proximity_sensor_secondary_threshold_latch)
|
||||||
.build();
|
.build();
|
||||||
|
|||||||
@@ -230,14 +230,16 @@ class ThresholdSensorImpl implements ThresholdSensor {
|
|||||||
mExecution = execution;
|
mExecution = execution;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Builder setSensorDelay(int sensorDelay) {
|
Builder setSensorDelay(int sensorDelay) {
|
||||||
mSensorDelay = sensorDelay;
|
mSensorDelay = sensorDelay;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
Builder setSensorResourceId(int sensorResourceId) {
|
* If requiresWakeUp is false, the first sensor with sensorType (regardless of whether the
|
||||||
setSensorType(mResources.getString(sensorResourceId));
|
* sensor is a wakeup sensor or not) will be set.
|
||||||
|
*/
|
||||||
|
Builder setSensorResourceId(int sensorResourceId, boolean requireWakeUp) {
|
||||||
|
setSensorType(mResources.getString(sensorResourceId), requireWakeUp);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,8 +261,12 @@ class ThresholdSensorImpl implements ThresholdSensor {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Builder setSensorType(String sensorType) {
|
/**
|
||||||
Sensor sensor = findSensorByType(sensorType);
|
* If requiresWakeUp is false, the first sensor with sensorType (regardless of whether the
|
||||||
|
* sensor is a wakeup sensor or not) will be set.
|
||||||
|
*/
|
||||||
|
Builder setSensorType(String sensorType, boolean requireWakeUp) {
|
||||||
|
Sensor sensor = findSensorByType(sensorType, requireWakeUp);
|
||||||
if (sensor != null) {
|
if (sensor != null) {
|
||||||
setSensor(sensor);
|
setSensor(sensor);
|
||||||
}
|
}
|
||||||
@@ -310,7 +316,8 @@ class ThresholdSensorImpl implements ThresholdSensor {
|
|||||||
mThresholdValue, mThresholdLatchValue, mSensorDelay);
|
mThresholdValue, mThresholdLatchValue, mSensorDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Sensor findSensorByType(String sensorType) {
|
@VisibleForTesting
|
||||||
|
Sensor findSensorByType(String sensorType, boolean requireWakeUp) {
|
||||||
if (sensorType.isEmpty()) {
|
if (sensorType.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -320,9 +327,11 @@ class ThresholdSensorImpl implements ThresholdSensor {
|
|||||||
for (Sensor s : sensorList) {
|
for (Sensor s : sensorList) {
|
||||||
if (sensorType.equals(s.getStringType())) {
|
if (sensorType.equals(s.getStringType())) {
|
||||||
sensor = s;
|
sensor = s;
|
||||||
|
if (!requireWakeUp || sensor.isWakeUpSensor()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return sensor;
|
return sensor;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public class FakeSensorManager extends SensorManager {
|
|||||||
|
|
||||||
public FakeSensorManager(Context context) throws Exception {
|
public FakeSensorManager(Context context) throws Exception {
|
||||||
Sensor proxSensor = context.getSystemService(SensorManager.class)
|
Sensor proxSensor = context.getSystemService(SensorManager.class)
|
||||||
.getDefaultSensor(Sensor.TYPE_PROXIMITY);
|
.getDefaultSensor(Sensor.TYPE_PROXIMITY, true);
|
||||||
if (proxSensor == null) {
|
if (proxSensor == null) {
|
||||||
// No prox? Let's create a fake one!
|
// No prox? Let's create a fake one!
|
||||||
proxSensor =
|
proxSensor =
|
||||||
|
|||||||
@@ -16,10 +16,15 @@
|
|||||||
|
|
||||||
package com.android.systemui.util.sensors;
|
package com.android.systemui.util.sensors;
|
||||||
|
|
||||||
|
import static android.hardware.Sensor.TYPE_ALL;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.hardware.Sensor;
|
||||||
import android.test.suitebuilder.annotation.SmallTest;
|
import android.test.suitebuilder.annotation.SmallTest;
|
||||||
import android.testing.AndroidTestingRunner;
|
import android.testing.AndroidTestingRunner;
|
||||||
|
|
||||||
@@ -33,6 +38,8 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
@RunWith(AndroidTestingRunner.class)
|
@RunWith(AndroidTestingRunner.class)
|
||||||
public class ThresholdSensorImplTest extends SysuiTestCase {
|
public class ThresholdSensorImplTest extends SysuiTestCase {
|
||||||
@@ -59,6 +66,79 @@ public class ThresholdSensorImplTest extends SysuiTestCase {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRegistersWakeUpProxSensor_givenWakeUpExistsAfterNonWakeup() {
|
||||||
|
// GIVEN sensor manager with two prox sensors (one non-wakeup, one wakeup)
|
||||||
|
final String sensorTypeProx = "prox";
|
||||||
|
AsyncSensorManager mockSensorManager = mock(AsyncSensorManager.class);
|
||||||
|
|
||||||
|
Sensor mockNonWakeupProx = mock(Sensor.class);
|
||||||
|
when(mockNonWakeupProx.isWakeUpSensor()).thenReturn(false);
|
||||||
|
when(mockNonWakeupProx.getStringType()).thenReturn(sensorTypeProx);
|
||||||
|
|
||||||
|
Sensor mockWakeupProx = mock(Sensor.class);
|
||||||
|
when(mockWakeupProx.isWakeUpSensor()).thenReturn(true);
|
||||||
|
when(mockWakeupProx.getStringType()).thenReturn(sensorTypeProx);
|
||||||
|
|
||||||
|
when(mockSensorManager.getSensorList(TYPE_ALL)).thenReturn(
|
||||||
|
List.of(mockNonWakeupProx, mockWakeupProx));
|
||||||
|
|
||||||
|
// WHEN we build a threshold sensor by type
|
||||||
|
ThresholdSensorImpl.Builder thresholdSensorBuilder = new ThresholdSensorImpl.Builder(
|
||||||
|
null, mockSensorManager, new FakeExecution());
|
||||||
|
Sensor proxSensor = thresholdSensorBuilder.findSensorByType(sensorTypeProx, true);
|
||||||
|
|
||||||
|
// THEN the prox sensor used is the wakeup sensor
|
||||||
|
assertEquals(mockWakeupProx, proxSensor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRegistersWakeUpProxSensor_givenNonWakeUpExistsAfterWakeup() {
|
||||||
|
// GIVEN sensor manager with two prox sensors (one wakeup, one non-wakeup)
|
||||||
|
final String sensorTypeProx = "prox";
|
||||||
|
AsyncSensorManager mockSensorManager = mock(AsyncSensorManager.class);
|
||||||
|
|
||||||
|
Sensor mockNonWakeupProx = mock(Sensor.class);
|
||||||
|
when(mockNonWakeupProx.isWakeUpSensor()).thenReturn(false);
|
||||||
|
when(mockNonWakeupProx.getStringType()).thenReturn(sensorTypeProx);
|
||||||
|
|
||||||
|
Sensor mockWakeupProx = mock(Sensor.class);
|
||||||
|
when(mockWakeupProx.isWakeUpSensor()).thenReturn(true);
|
||||||
|
when(mockWakeupProx.getStringType()).thenReturn(sensorTypeProx);
|
||||||
|
|
||||||
|
when(mockSensorManager.getSensorList(TYPE_ALL)).thenReturn(
|
||||||
|
List.of(mockWakeupProx, mockNonWakeupProx));
|
||||||
|
|
||||||
|
// WHEN we build a threshold sensor by type
|
||||||
|
ThresholdSensorImpl.Builder thresholdSensorBuilder = new ThresholdSensorImpl.Builder(
|
||||||
|
null, mockSensorManager, new FakeExecution());
|
||||||
|
Sensor proxSensor = thresholdSensorBuilder.findSensorByType(sensorTypeProx, true);
|
||||||
|
|
||||||
|
// THEN the prox sensor used is the wakeup sensor
|
||||||
|
assertEquals(mockWakeupProx, proxSensor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRegistersNonWakeUpProxSensor_givenNonWakeUpOnly() {
|
||||||
|
// GIVEN sensor manager with one non-wakeup prox sensor
|
||||||
|
final String sensorTypeProx = "prox";
|
||||||
|
AsyncSensorManager mockSensorManager = mock(AsyncSensorManager.class);
|
||||||
|
|
||||||
|
Sensor mockNonWakeupProx = mock(Sensor.class);
|
||||||
|
when(mockNonWakeupProx.isWakeUpSensor()).thenReturn(false);
|
||||||
|
when(mockNonWakeupProx.getStringType()).thenReturn(sensorTypeProx);
|
||||||
|
|
||||||
|
when(mockSensorManager.getSensorList(TYPE_ALL)).thenReturn(List.of(mockNonWakeupProx));
|
||||||
|
|
||||||
|
// WHEN we build a threshold sensor by type
|
||||||
|
ThresholdSensorImpl.Builder thresholdSensorBuilder = new ThresholdSensorImpl.Builder(
|
||||||
|
null, mockSensorManager, new FakeExecution());
|
||||||
|
Sensor proxSensor = thresholdSensorBuilder.findSensorByType(sensorTypeProx, true);
|
||||||
|
|
||||||
|
// THEN the prox sensor used is the one available (non-wakeup)
|
||||||
|
assertEquals(mockNonWakeupProx, proxSensor);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSingleListener() {
|
public void testSingleListener() {
|
||||||
TestableListener listener = new TestableListener();
|
TestableListener listener = new TestableListener();
|
||||||
|
|||||||
Reference in New Issue
Block a user