RESTRICT AUTOMERGE Use Alternative Prox Sensor for Falsing
This allows new phones to use a sensor with a different theshold when attempting to determine the devices proximity to surfaces. Bug: 149420648 Test: manual Change-Id: Iee8568f7d9f58359dc1e72fd195a42abeaf2ddf3
This commit is contained in:
@@ -201,6 +201,14 @@
|
||||
always-on display) -->
|
||||
<string name="doze_brightness_sensor_type" translatable="false"></string>
|
||||
|
||||
<!-- Override value to use for proximity sensor. -->
|
||||
<string name="proximity_sensor_type" translatable="false">@string/doze_brightness_sensor_type</string>
|
||||
|
||||
<!-- If using proximity_sensor_type, specifies a threshold value to distinguish near and
|
||||
far break points. A sensor value less than or equal to this is considered "near". -->
|
||||
<item name="proximity_sensor_threshold" translatable="false" format="float" type="dimen">
|
||||
0</item>
|
||||
|
||||
<!-- Doze: pulse parameter - how long does it take to fade in? -->
|
||||
<integer name="doze_pulse_duration_in">130</integer>
|
||||
|
||||
|
||||
@@ -43,11 +43,11 @@ import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.plugins.SensorManagerPlugin;
|
||||
import com.android.systemui.statusbar.phone.DozeParameters;
|
||||
import com.android.systemui.util.AlarmTimeout;
|
||||
import com.android.systemui.util.AsyncSensorManager;
|
||||
import com.android.systemui.util.ProximitySensor;
|
||||
import com.android.systemui.util.wakelock.WakeLock;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
@@ -288,6 +288,7 @@ public class DozeSensors {
|
||||
final AlarmTimeout mCooldownTimer;
|
||||
final AlwaysOnDisplayPolicy mPolicy;
|
||||
final Sensor mSensor;
|
||||
private final float mSensorThreshold;
|
||||
final boolean mUsingBrightnessSensor;
|
||||
|
||||
public ProxSensor(AlwaysOnDisplayPolicy policy) {
|
||||
@@ -297,11 +298,14 @@ public class DozeSensors {
|
||||
|
||||
// The default prox sensor can be noisy, so let's use a prox gated brightness sensor
|
||||
// if available.
|
||||
Sensor sensor = DozeSensors.findSensorWithType(mSensorManager,
|
||||
mContext.getString(R.string.doze_brightness_sensor_type));
|
||||
Sensor sensor = ProximitySensor.findCustomProxSensor(mContext, mSensorManager);
|
||||
mUsingBrightnessSensor = sensor != null;
|
||||
if (sensor == null) {
|
||||
if (mUsingBrightnessSensor) {
|
||||
mSensorThreshold = ProximitySensor.getBrightnessSensorThreshold(
|
||||
mContext.getResources());
|
||||
} else {
|
||||
sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
|
||||
mSensorThreshold = sensor.getMaximumRange();
|
||||
}
|
||||
mSensor = sensor;
|
||||
}
|
||||
@@ -343,11 +347,9 @@ public class DozeSensors {
|
||||
if (DEBUG) Log.d(TAG, "onSensorChanged " + event);
|
||||
|
||||
if (mUsingBrightnessSensor) {
|
||||
// The custom brightness sensor is gated by the proximity sensor and will return 0
|
||||
// whenever prox is covered.
|
||||
mCurrentlyFar = event.values[0] > 0;
|
||||
mCurrentlyFar = event.values[0] > mSensorThreshold;
|
||||
} else {
|
||||
mCurrentlyFar = event.values[0] >= event.sensor.getMaximumRange();
|
||||
mCurrentlyFar = event.values[0] >= mSensorThreshold;
|
||||
}
|
||||
mProxCallback.accept(mCurrentlyFar);
|
||||
|
||||
|
||||
@@ -41,10 +41,10 @@ import com.android.internal.logging.MetricsLogger;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.internal.util.Preconditions;
|
||||
import com.android.systemui.Dependency;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.dock.DockManager;
|
||||
import com.android.systemui.statusbar.phone.DozeParameters;
|
||||
import com.android.systemui.util.Assert;
|
||||
import com.android.systemui.util.ProximitySensor;
|
||||
import com.android.systemui.util.wakelock.WakeLock;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
@@ -431,15 +431,18 @@ public class DozeTriggers implements DozeMachine.Part {
|
||||
private boolean mFinished;
|
||||
private float mMaxRange;
|
||||
private boolean mUsingBrightnessSensor;
|
||||
private float mSensorThreshold;
|
||||
|
||||
protected abstract void onProximityResult(int result);
|
||||
|
||||
public void check() {
|
||||
Preconditions.checkState(!mFinished && !mRegistered);
|
||||
Sensor sensor = DozeSensors.findSensorWithType(mSensorManager,
|
||||
mContext.getString(R.string.doze_brightness_sensor_type));
|
||||
Sensor sensor = ProximitySensor.findCustomProxSensor(mContext, mSensorManager);
|
||||
mUsingBrightnessSensor = sensor != null;
|
||||
if (sensor == null) {
|
||||
if (mUsingBrightnessSensor) {
|
||||
mSensorThreshold = ProximitySensor.getBrightnessSensorThreshold(
|
||||
mContext.getResources());
|
||||
} else {
|
||||
sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
|
||||
}
|
||||
if (sensor == null) {
|
||||
@@ -473,7 +476,7 @@ public class DozeTriggers implements DozeMachine.Part {
|
||||
if (mUsingBrightnessSensor) {
|
||||
// The custom brightness sensor is gated by the proximity sensor and will
|
||||
// return 0 whenever prox is covered.
|
||||
isNear = event.values[0] == 0;
|
||||
isNear = event.values[0] <= mSensorThreshold;
|
||||
} else {
|
||||
isNear = event.values[0] < mMaxRange;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.android.systemui.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
@@ -40,7 +41,7 @@ public class ProximitySensor {
|
||||
private final Sensor mSensor;
|
||||
private final AsyncSensorManager mSensorManager;
|
||||
private final boolean mUsingBrightnessSensor;
|
||||
private final float mMaxRange;
|
||||
private final float mThreshold;
|
||||
|
||||
private SensorEventListener mSensorEventListener = new SensorEventListener() {
|
||||
@Override
|
||||
@@ -59,7 +60,7 @@ public class ProximitySensor {
|
||||
@Inject
|
||||
public ProximitySensor(Context context, AsyncSensorManager sensorManager) {
|
||||
mSensorManager = sensorManager;
|
||||
Sensor sensor = findBrightnessSensor(context, sensorManager);
|
||||
Sensor sensor = findCustomProxSensor(context, sensorManager);
|
||||
|
||||
if (sensor == null) {
|
||||
mUsingBrightnessSensor = false;
|
||||
@@ -69,9 +70,13 @@ public class ProximitySensor {
|
||||
}
|
||||
mSensor = sensor;
|
||||
if (mSensor != null) {
|
||||
mMaxRange = mSensor.getMaximumRange();
|
||||
if (mUsingBrightnessSensor) {
|
||||
mThreshold = getBrightnessSensorThreshold(context.getResources());
|
||||
} else {
|
||||
mThreshold = mSensor.getMaximumRange();
|
||||
}
|
||||
} else {
|
||||
mMaxRange = 0;
|
||||
mThreshold = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,8 +84,18 @@ public class ProximitySensor {
|
||||
mTag = tag;
|
||||
}
|
||||
|
||||
private Sensor findBrightnessSensor(Context context, SensorManager sensorManager) {
|
||||
String sensorType = context.getString(R.string.doze_brightness_sensor_type);
|
||||
/**
|
||||
* Returns a brightness sensor that can be used for proximity purposes.
|
||||
*
|
||||
* @deprecated This method exists for legacy purposes. Use the containing class directly.
|
||||
*/
|
||||
@Deprecated
|
||||
public static Sensor findCustomProxSensor(Context context, SensorManager sensorManager) {
|
||||
String sensorType = context.getString(R.string.proximity_sensor_type);
|
||||
if (sensorType.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Sensor> sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL);
|
||||
Sensor sensor = null;
|
||||
for (Sensor s : sensorList) {
|
||||
@@ -93,6 +108,16 @@ public class ProximitySensor {
|
||||
return sensor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a threshold value that can be used along with {@link #findCustomProxSensor}
|
||||
*
|
||||
* @deprecated This method exists for legacy purposes. Use the containing class directly.
|
||||
*/
|
||||
@Deprecated
|
||||
public static float getBrightnessSensorThreshold(Resources resources) {
|
||||
return resources.getFloat(R.dimen.proximity_sensor_threshold);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code false} if a Proximity sensor is not available.
|
||||
*/
|
||||
@@ -141,11 +166,11 @@ public class ProximitySensor {
|
||||
}
|
||||
|
||||
private void onSensorEvent(SensorEvent event) {
|
||||
boolean near = event.values[0] < mMaxRange;
|
||||
if (mUsingBrightnessSensor) {
|
||||
near = event.values[0] == 0;
|
||||
mNear = event.values[0] <= mThreshold;
|
||||
} else {
|
||||
mNear = event.values[0] < mThreshold;
|
||||
}
|
||||
mNear = near;
|
||||
mListeners.forEach(proximitySensorListener ->
|
||||
proximitySensorListener.onProximitySensorEvent(
|
||||
new ProximityEvent(mNear, event.timestamp)));
|
||||
|
||||
Reference in New Issue
Block a user