Loading quickstep/src/com/android/quickstep/util/ActiveGestureLog.java +44 −20 Original line number Diff line number Diff line Loading @@ -67,15 +67,15 @@ public class ActiveGestureLog { /** * Adds a log to be printed at log-dump-time. */ public void addLog(String event) { public void addLog(@NonNull String event) { addLog(event, null); } public void addLog(String event, int extras) { public void addLog(@NonNull String event, int extras) { addLog(event, extras, null); } public void addLog(String event, boolean extras) { public void addLog(@NonNull String event, boolean extras) { addLog(event, extras, null); } Loading @@ -85,30 +85,30 @@ public class ActiveGestureLog { * @param gestureEvent GestureEvent representing the event being logged. */ public void addLog( String event, @Nullable ActiveGestureErrorDetector.GestureEvent gestureEvent) { @NonNull String event, @Nullable ActiveGestureErrorDetector.GestureEvent gestureEvent) { addLog(new CompoundString(event), gestureEvent); } public void addLog( String event, @NonNull String event, int extras, @Nullable ActiveGestureErrorDetector.GestureEvent gestureEvent) { addLog(new CompoundString(event).append(": ").append(extras), gestureEvent); } public void addLog( String event, @NonNull String event, boolean extras, @Nullable ActiveGestureErrorDetector.GestureEvent gestureEvent) { addLog(new CompoundString(event).append(": ").append(extras), gestureEvent); } public void addLog(CompoundString compoundString) { public void addLog(@NonNull CompoundString compoundString) { addLog(compoundString, null); } public void addLog( CompoundString compoundString, @NonNull CompoundString compoundString, @Nullable ActiveGestureErrorDetector.GestureEvent gestureEvent) { EventLog lastEventLog = logs[(nextIndex + logs.length - 1) % logs.length]; if (lastEventLog == null || mCurrentLogId != lastEventLog.logId) { Loading Loading @@ -259,21 +259,20 @@ public class ActiveGestureLog { public CompoundString(String substring) { mIsNoOp = substring == null; if (mIsNoOp) { mSubstrings = null; mArgs = null; return; } mSubstrings = new ArrayList<>(); mSubstrings = mIsNoOp ? null : new ArrayList<>(); mArgs = mIsNoOp ? null : new ArrayList<>(); if (!mIsNoOp) { mSubstrings.add(substring); mArgs = new ArrayList<>(); } } public CompoundString append(CompoundString substring) { if (mIsNoOp) { if (mIsNoOp || substring.mIsNoOp) { return this; } mSubstrings.addAll(substring.mSubstrings); mArgs.addAll(substring.mArgs); return this; } Loading @@ -288,30 +287,53 @@ public class ActiveGestureLog { } public CompoundString append(int num) { if (mIsNoOp) { return this; } mArgs.add(num); return append("%d"); } public CompoundString append(long num) { if (mIsNoOp) { return this; } mArgs.add(num); return append("%d"); } public CompoundString append(float num) { if (mIsNoOp) { return this; } mArgs.add(num); return append("%.2f"); } public CompoundString append(double num) { if (mIsNoOp) { return this; } mArgs.add(num); return append("%.2f"); } public CompoundString append(boolean bool) { if (mIsNoOp) { return this; } mArgs.add(bool); return append("%b"); } public Object[] getArgs() { private Object[] getArgs() { Preconditions.assertTrue(!mIsNoOp); return mArgs.toArray(); } Loading @@ -320,7 +342,7 @@ public class ActiveGestureLog { return String.format(toUnformattedString(), getArgs()); } public String toUnformattedString() { private String toUnformattedString() { Preconditions.assertTrue(!mIsNoOp); StringBuilder sb = new StringBuilder(); Loading @@ -333,7 +355,7 @@ public class ActiveGestureLog { @Override public int hashCode() { return Objects.hash(mIsNoOp, mSubstrings); return Objects.hash(mIsNoOp, mSubstrings, mArgs); } @Override Loading @@ -342,7 +364,9 @@ public class ActiveGestureLog { return false; } CompoundString other = (CompoundString) obj; return (mIsNoOp == other.mIsNoOp) && Objects.equals(mSubstrings, other.mSubstrings); return (mIsNoOp == other.mIsNoOp) && Objects.equals(mSubstrings, other.mSubstrings) && Objects.equals(mArgs, other.mArgs); } } } quickstep/src/com/android/quickstep/util/MotionPauseDetector.java +49 −19 Original line number Diff line number Diff line Loading @@ -96,8 +96,14 @@ public class MotionPauseDetector { mSpeedSomewhatFast = res.getDimension(R.dimen.motion_pause_detector_speed_somewhat_fast); mSpeedFast = res.getDimension(R.dimen.motion_pause_detector_speed_fast); mForcePauseTimeout = new Alarm(); mForcePauseTimeout.setOnAlarmListener(alarm -> updatePaused(true /* isPaused */, "Force pause timeout after " + alarm.getLastSetTimeout() + "ms" /* reason */)); mForcePauseTimeout.setOnAlarmListener(alarm -> { ActiveGestureLog.CompoundString log = new ActiveGestureLog.CompoundString("Force pause timeout after ") .append(alarm.getLastSetTimeout()) .append("ms"); addLogs(log); updatePaused(true /* isPaused */, log); }); mMakePauseHarderToTrigger = makePauseHarderToTrigger; mVelocityProvider = new SystemVelocityProvider(axis); } Loading @@ -113,8 +119,14 @@ public class MotionPauseDetector { * @param disallowPause If true, we will not detect any pauses until this is set to false again. */ public void setDisallowPause(boolean disallowPause) { ActiveGestureLog.CompoundString log = new ActiveGestureLog.CompoundString("Set disallowPause=") .append(disallowPause); if (mDisallowPause != disallowPause) { addLogs(log); } mDisallowPause = disallowPause; updatePaused(mIsPaused, "Set disallowPause=" + disallowPause); updatePaused(mIsPaused, log); } /** Loading Loading @@ -148,27 +160,30 @@ public class MotionPauseDetector { float speed = Math.abs(velocity); float previousSpeed = Math.abs(prevVelocity); boolean isPaused; String isPausedReason = ""; ActiveGestureLog.CompoundString isPausedReason; if (mIsPaused) { // Continue to be paused until moving at a fast speed. isPaused = speed < mSpeedFast || previousSpeed < mSpeedFast; isPausedReason = "Was paused, but started moving at a fast speed"; isPausedReason = new ActiveGestureLog.CompoundString( "Was paused, but started moving at a fast speed"); } else { if (velocity < 0 != prevVelocity < 0) { // We're just changing directions, not necessarily stopping. isPaused = false; isPausedReason = "Velocity changed directions"; isPausedReason = new ActiveGestureLog.CompoundString("Velocity changed directions"); } else { isPaused = speed < mSpeedVerySlow && previousSpeed < mSpeedVerySlow; isPausedReason = "Pause requires back to back slow speeds"; isPausedReason = new ActiveGestureLog.CompoundString( "Pause requires back to back slow speeds"); if (!isPaused && !mHasEverBeenPaused) { // We want to be more aggressive about detecting the first pause to ensure it // feels as responsive as possible; getting two very slow speeds back to back // takes too long, so also check for a rapid deceleration. boolean isRapidDeceleration = speed < previousSpeed * RAPID_DECELERATION_FACTOR; isPaused = isRapidDeceleration && speed < mSpeedSomewhatFast; isPausedReason = "Didn't have back to back slow speeds, checking for rapid" + " deceleration on first pause only"; isPausedReason = new ActiveGestureLog.CompoundString( "Didn't have back to back slow speeds, checking for rapid ") .append(" deceleration on first pause only"); } if (mMakePauseHarderToTrigger) { if (speed < mSpeedSlow) { Loading @@ -176,12 +191,14 @@ public class MotionPauseDetector { mSlowStartTime = time; } isPaused = time - mSlowStartTime >= HARDER_TRIGGER_TIMEOUT; isPausedReason = "Maintained slow speed for sufficient duration when making" + " pause harder to trigger"; isPausedReason = new ActiveGestureLog.CompoundString( "Maintained slow speed for sufficient duration when making") .append(" pause harder to trigger"); } else { mSlowStartTime = 0; isPaused = false; isPausedReason = "Intentionally making pause harder to trigger"; isPausedReason = new ActiveGestureLog.CompoundString( "Intentionally making pause harder to trigger"); } } } Loading @@ -189,18 +206,21 @@ public class MotionPauseDetector { updatePaused(isPaused, isPausedReason); } private void updatePaused(boolean isPaused, String reason) { private void updatePaused(boolean isPaused, ActiveGestureLog.CompoundString reason) { if (mDisallowPause) { reason = "Disallow pause; otherwise, would have been " + isPaused + " due to " + reason; reason = new ActiveGestureLog.CompoundString( "Disallow pause; otherwise, would have been ") .append(isPaused) .append(" due to reason:") .append(reason); isPaused = false; } if (mIsPaused != isPaused) { mIsPaused = isPaused; String logString = "onMotionPauseChanged, paused=" + mIsPaused + " reason=" + reason; if (Utilities.isRunningInTestHarness()) { Log.d(TAG, logString); } ActiveGestureLog.INSTANCE.addLog(logString); addLogs(new ActiveGestureLog.CompoundString("onMotionPauseChanged triggered; paused=") .append(mIsPaused) .append(", reason=") .append(reason)); boolean isFirstDetectedPause = !mHasEverBeenPaused && mIsPaused; if (mIsPaused) { AccessibilityManagerCompat.sendTestProtocolEventToTest(mContext, Loading @@ -219,6 +239,16 @@ public class MotionPauseDetector { } } private void addLogs(ActiveGestureLog.CompoundString compoundString) { ActiveGestureLog.CompoundString logString = new ActiveGestureLog.CompoundString("MotionPauseDetector: ") .append(compoundString); if (Utilities.isRunningInTestHarness()) { Log.d(TAG, logString.toString()); } ActiveGestureLog.INSTANCE.addLog(logString); } public void clear() { mVelocityProvider.clear(); mPreviousVelocity = null; Loading Loading
quickstep/src/com/android/quickstep/util/ActiveGestureLog.java +44 −20 Original line number Diff line number Diff line Loading @@ -67,15 +67,15 @@ public class ActiveGestureLog { /** * Adds a log to be printed at log-dump-time. */ public void addLog(String event) { public void addLog(@NonNull String event) { addLog(event, null); } public void addLog(String event, int extras) { public void addLog(@NonNull String event, int extras) { addLog(event, extras, null); } public void addLog(String event, boolean extras) { public void addLog(@NonNull String event, boolean extras) { addLog(event, extras, null); } Loading @@ -85,30 +85,30 @@ public class ActiveGestureLog { * @param gestureEvent GestureEvent representing the event being logged. */ public void addLog( String event, @Nullable ActiveGestureErrorDetector.GestureEvent gestureEvent) { @NonNull String event, @Nullable ActiveGestureErrorDetector.GestureEvent gestureEvent) { addLog(new CompoundString(event), gestureEvent); } public void addLog( String event, @NonNull String event, int extras, @Nullable ActiveGestureErrorDetector.GestureEvent gestureEvent) { addLog(new CompoundString(event).append(": ").append(extras), gestureEvent); } public void addLog( String event, @NonNull String event, boolean extras, @Nullable ActiveGestureErrorDetector.GestureEvent gestureEvent) { addLog(new CompoundString(event).append(": ").append(extras), gestureEvent); } public void addLog(CompoundString compoundString) { public void addLog(@NonNull CompoundString compoundString) { addLog(compoundString, null); } public void addLog( CompoundString compoundString, @NonNull CompoundString compoundString, @Nullable ActiveGestureErrorDetector.GestureEvent gestureEvent) { EventLog lastEventLog = logs[(nextIndex + logs.length - 1) % logs.length]; if (lastEventLog == null || mCurrentLogId != lastEventLog.logId) { Loading Loading @@ -259,21 +259,20 @@ public class ActiveGestureLog { public CompoundString(String substring) { mIsNoOp = substring == null; if (mIsNoOp) { mSubstrings = null; mArgs = null; return; } mSubstrings = new ArrayList<>(); mSubstrings = mIsNoOp ? null : new ArrayList<>(); mArgs = mIsNoOp ? null : new ArrayList<>(); if (!mIsNoOp) { mSubstrings.add(substring); mArgs = new ArrayList<>(); } } public CompoundString append(CompoundString substring) { if (mIsNoOp) { if (mIsNoOp || substring.mIsNoOp) { return this; } mSubstrings.addAll(substring.mSubstrings); mArgs.addAll(substring.mArgs); return this; } Loading @@ -288,30 +287,53 @@ public class ActiveGestureLog { } public CompoundString append(int num) { if (mIsNoOp) { return this; } mArgs.add(num); return append("%d"); } public CompoundString append(long num) { if (mIsNoOp) { return this; } mArgs.add(num); return append("%d"); } public CompoundString append(float num) { if (mIsNoOp) { return this; } mArgs.add(num); return append("%.2f"); } public CompoundString append(double num) { if (mIsNoOp) { return this; } mArgs.add(num); return append("%.2f"); } public CompoundString append(boolean bool) { if (mIsNoOp) { return this; } mArgs.add(bool); return append("%b"); } public Object[] getArgs() { private Object[] getArgs() { Preconditions.assertTrue(!mIsNoOp); return mArgs.toArray(); } Loading @@ -320,7 +342,7 @@ public class ActiveGestureLog { return String.format(toUnformattedString(), getArgs()); } public String toUnformattedString() { private String toUnformattedString() { Preconditions.assertTrue(!mIsNoOp); StringBuilder sb = new StringBuilder(); Loading @@ -333,7 +355,7 @@ public class ActiveGestureLog { @Override public int hashCode() { return Objects.hash(mIsNoOp, mSubstrings); return Objects.hash(mIsNoOp, mSubstrings, mArgs); } @Override Loading @@ -342,7 +364,9 @@ public class ActiveGestureLog { return false; } CompoundString other = (CompoundString) obj; return (mIsNoOp == other.mIsNoOp) && Objects.equals(mSubstrings, other.mSubstrings); return (mIsNoOp == other.mIsNoOp) && Objects.equals(mSubstrings, other.mSubstrings) && Objects.equals(mArgs, other.mArgs); } } }
quickstep/src/com/android/quickstep/util/MotionPauseDetector.java +49 −19 Original line number Diff line number Diff line Loading @@ -96,8 +96,14 @@ public class MotionPauseDetector { mSpeedSomewhatFast = res.getDimension(R.dimen.motion_pause_detector_speed_somewhat_fast); mSpeedFast = res.getDimension(R.dimen.motion_pause_detector_speed_fast); mForcePauseTimeout = new Alarm(); mForcePauseTimeout.setOnAlarmListener(alarm -> updatePaused(true /* isPaused */, "Force pause timeout after " + alarm.getLastSetTimeout() + "ms" /* reason */)); mForcePauseTimeout.setOnAlarmListener(alarm -> { ActiveGestureLog.CompoundString log = new ActiveGestureLog.CompoundString("Force pause timeout after ") .append(alarm.getLastSetTimeout()) .append("ms"); addLogs(log); updatePaused(true /* isPaused */, log); }); mMakePauseHarderToTrigger = makePauseHarderToTrigger; mVelocityProvider = new SystemVelocityProvider(axis); } Loading @@ -113,8 +119,14 @@ public class MotionPauseDetector { * @param disallowPause If true, we will not detect any pauses until this is set to false again. */ public void setDisallowPause(boolean disallowPause) { ActiveGestureLog.CompoundString log = new ActiveGestureLog.CompoundString("Set disallowPause=") .append(disallowPause); if (mDisallowPause != disallowPause) { addLogs(log); } mDisallowPause = disallowPause; updatePaused(mIsPaused, "Set disallowPause=" + disallowPause); updatePaused(mIsPaused, log); } /** Loading Loading @@ -148,27 +160,30 @@ public class MotionPauseDetector { float speed = Math.abs(velocity); float previousSpeed = Math.abs(prevVelocity); boolean isPaused; String isPausedReason = ""; ActiveGestureLog.CompoundString isPausedReason; if (mIsPaused) { // Continue to be paused until moving at a fast speed. isPaused = speed < mSpeedFast || previousSpeed < mSpeedFast; isPausedReason = "Was paused, but started moving at a fast speed"; isPausedReason = new ActiveGestureLog.CompoundString( "Was paused, but started moving at a fast speed"); } else { if (velocity < 0 != prevVelocity < 0) { // We're just changing directions, not necessarily stopping. isPaused = false; isPausedReason = "Velocity changed directions"; isPausedReason = new ActiveGestureLog.CompoundString("Velocity changed directions"); } else { isPaused = speed < mSpeedVerySlow && previousSpeed < mSpeedVerySlow; isPausedReason = "Pause requires back to back slow speeds"; isPausedReason = new ActiveGestureLog.CompoundString( "Pause requires back to back slow speeds"); if (!isPaused && !mHasEverBeenPaused) { // We want to be more aggressive about detecting the first pause to ensure it // feels as responsive as possible; getting two very slow speeds back to back // takes too long, so also check for a rapid deceleration. boolean isRapidDeceleration = speed < previousSpeed * RAPID_DECELERATION_FACTOR; isPaused = isRapidDeceleration && speed < mSpeedSomewhatFast; isPausedReason = "Didn't have back to back slow speeds, checking for rapid" + " deceleration on first pause only"; isPausedReason = new ActiveGestureLog.CompoundString( "Didn't have back to back slow speeds, checking for rapid ") .append(" deceleration on first pause only"); } if (mMakePauseHarderToTrigger) { if (speed < mSpeedSlow) { Loading @@ -176,12 +191,14 @@ public class MotionPauseDetector { mSlowStartTime = time; } isPaused = time - mSlowStartTime >= HARDER_TRIGGER_TIMEOUT; isPausedReason = "Maintained slow speed for sufficient duration when making" + " pause harder to trigger"; isPausedReason = new ActiveGestureLog.CompoundString( "Maintained slow speed for sufficient duration when making") .append(" pause harder to trigger"); } else { mSlowStartTime = 0; isPaused = false; isPausedReason = "Intentionally making pause harder to trigger"; isPausedReason = new ActiveGestureLog.CompoundString( "Intentionally making pause harder to trigger"); } } } Loading @@ -189,18 +206,21 @@ public class MotionPauseDetector { updatePaused(isPaused, isPausedReason); } private void updatePaused(boolean isPaused, String reason) { private void updatePaused(boolean isPaused, ActiveGestureLog.CompoundString reason) { if (mDisallowPause) { reason = "Disallow pause; otherwise, would have been " + isPaused + " due to " + reason; reason = new ActiveGestureLog.CompoundString( "Disallow pause; otherwise, would have been ") .append(isPaused) .append(" due to reason:") .append(reason); isPaused = false; } if (mIsPaused != isPaused) { mIsPaused = isPaused; String logString = "onMotionPauseChanged, paused=" + mIsPaused + " reason=" + reason; if (Utilities.isRunningInTestHarness()) { Log.d(TAG, logString); } ActiveGestureLog.INSTANCE.addLog(logString); addLogs(new ActiveGestureLog.CompoundString("onMotionPauseChanged triggered; paused=") .append(mIsPaused) .append(", reason=") .append(reason)); boolean isFirstDetectedPause = !mHasEverBeenPaused && mIsPaused; if (mIsPaused) { AccessibilityManagerCompat.sendTestProtocolEventToTest(mContext, Loading @@ -219,6 +239,16 @@ public class MotionPauseDetector { } } private void addLogs(ActiveGestureLog.CompoundString compoundString) { ActiveGestureLog.CompoundString logString = new ActiveGestureLog.CompoundString("MotionPauseDetector: ") .append(compoundString); if (Utilities.isRunningInTestHarness()) { Log.d(TAG, logString.toString()); } ActiveGestureLog.INSTANCE.addLog(logString); } public void clear() { mVelocityProvider.clear(); mPreviousVelocity = null; Loading