summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Adrian Roos <roosa@google.com> 2017-06-28 15:38:52 +0000
committer android-build-merger <android-build-merger@google.com> 2017-06-28 15:38:52 +0000
commitcbbb27bce21844157e57cdb40d665e28f1eb63e0 (patch)
treed9d600df5b015378cbcafc4a95815de5517faeea
parent5896454353ddef68a7c64de84d6c2820063103aa (diff)
parent56fb90cf3e14b874d3702c6087e76a1bda922da1 (diff)
Merge "AOD: Proximity check doze triggers" into oc-dr1-dev am: 939171ee8b
am: 56fb90cf3e Change-Id: I03e74dab4e096ac8a9b5fc01dfd90ca745eabf09
-rw-r--r--packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java72
1 files changed, 41 insertions, 31 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java b/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java
index 1ece5fc0063f..8d1d6e0ce460 100644
--- a/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java
+++ b/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java
@@ -39,6 +39,7 @@ import com.android.systemui.util.Assert;
import com.android.systemui.util.wakelock.WakeLock;
import java.io.PrintWriter;
+import java.util.function.IntConsumer;
/**
* Handles triggers for ambient state changes.
@@ -98,18 +99,44 @@ public class DozeTriggers implements DozeMachine.Part {
requestPulse(DozeLog.PULSE_REASON_NOTIFICATION, false /* performedProxCheck */);
}
+ private void proximityCheckThenCall(IntConsumer callback,
+ boolean alreadyPerformedProxCheck,
+ int pulseReason) {
+ if (alreadyPerformedProxCheck) {
+ callback.accept(ProximityCheck.RESULT_NOT_CHECKED);
+ } else {
+ final long start = SystemClock.uptimeMillis();
+ new ProximityCheck() {
+ @Override
+ public void onProximityResult(int result) {
+ final long end = SystemClock.uptimeMillis();
+ DozeLog.traceProximityResult(mContext, result == RESULT_NEAR,
+ end - start, pulseReason);
+ callback.accept(result);
+ }
+ }.check();
+ }
+ }
+
private void onSensor(int pulseReason, boolean sensorPerformedProxCheck,
float screenX, float screenY) {
boolean isDoubleTap = pulseReason == DozeLog.PULSE_REASON_SENSOR_DOUBLE_TAP;
boolean isPickup = pulseReason == DozeLog.PULSE_REASON_SENSOR_PICKUP;
if (mConfig.alwaysOnEnabled(UserHandle.USER_CURRENT)) {
- if (isDoubleTap) {
- mDozeHost.onDoubleTap(screenX, screenY);
- mMachine.wakeUp();
- } else {
- mDozeHost.extendPulse();
- }
+ proximityCheckThenCall((result) -> {
+ if (result == ProximityCheck.RESULT_NEAR) {
+ // In pocket, drop event.
+ return;
+ }
+ if (isDoubleTap) {
+ mDozeHost.onDoubleTap(screenX, screenY);
+ mMachine.wakeUp();
+ } else {
+ mDozeHost.extendPulse();
+ }
+ }, sensorPerformedProxCheck, pulseReason);
+ return;
} else {
requestPulse(pulseReason, sensorPerformedProxCheck);
}
@@ -202,33 +229,15 @@ public class DozeTriggers implements DozeMachine.Part {
}
mPulsePending = true;
- if (!mDozeParameters.getProxCheckBeforePulse() || performedProxCheck) {
- // skip proximity check
- continuePulseRequest(reason);
- return;
- }
-
- final long start = SystemClock.uptimeMillis();
- new ProximityCheck() {
- @Override
- public void onProximityResult(int result) {
- final long end = SystemClock.uptimeMillis();
- DozeLog.traceProximityResult(mContext, result == RESULT_NEAR,
- end - start, reason);
- if (performedProxCheck) {
- // we already continued
- return;
- }
- // avoid pulsing in pockets
- if (result == RESULT_NEAR) {
- mPulsePending = false;
- return;
- }
-
- // not in-pocket, continue pulsing
+ proximityCheckThenCall((result) -> {
+ if (result == ProximityCheck.RESULT_NEAR) {
+ // in pocket, abort pulse
+ mPulsePending = false;
+ } else {
+ // not in pocket, continue pulsing
continuePulseRequest(reason);
}
- }.check();
+ }, !mDozeParameters.getProxCheckBeforePulse() || performedProxCheck, reason);
}
private boolean canPulse() {
@@ -262,6 +271,7 @@ public class DozeTriggers implements DozeMachine.Part {
protected static final int RESULT_UNKNOWN = 0;
protected static final int RESULT_NEAR = 1;
protected static final int RESULT_FAR = 2;
+ protected static final int RESULT_NOT_CHECKED = 3;
private boolean mRegistered;
private boolean mFinished;