Loading services/core/java/com/android/server/AnyMotionDetector.java +50 −28 Original line number Diff line number Diff line Loading @@ -70,6 +70,9 @@ public class AnyMotionDetector { /** The interval between accelerometer orientation measurements. */ private static final long ORIENTATION_MEASUREMENT_INTERVAL_MILLIS = 5000; /** The maximum duration we will hold a wakelock to determine stationary status. */ private static final long WAKELOCK_TIMEOUT_MILLIS = 30000; /** * The duration in milliseconds after which an orientation measurement is considered * too stale to be used. Loading Loading @@ -141,16 +144,19 @@ public class AnyMotionDetector { mCurrentGravityVector = null; mPreviousGravityVector = null; mWakeLock.acquire(); Message wakelockTimeoutMsg = Message.obtain(mHandler, mWakelockTimeout); mHandler.sendMessageDelayed(wakelockTimeoutMsg, WAKELOCK_TIMEOUT_MILLIS); startOrientationMeasurementLocked(); } } } public void stop() { if (mState == STATE_ACTIVE) { synchronized (mLock) { if (mState == STATE_ACTIVE) { mState = STATE_INACTIVE; if (DEBUG) Slog.d(TAG, "Moved from STATE_ACTIVE to STATE_INACTIVE."); } if (mMeasurementInProgress) { mMeasurementInProgress = false; mSensorManager.unregisterListener(mListener); Loading @@ -159,7 +165,9 @@ public class AnyMotionDetector { mHandler.removeCallbacks(mSensorRestart); mCurrentGravityVector = null; mPreviousGravityVector = null; if (mWakeLock.isHeld()) { mWakeLock.release(); mHandler.removeCallbacks(mWakelockTimeout); } } } Loading @@ -173,9 +181,8 @@ public class AnyMotionDetector { mMeasurementInProgress = true; mRunningStats.reset(); } Message msg = Message.obtain(mHandler, mMeasurementTimeout); msg.setAsynchronous(true); mHandler.sendMessageDelayed(msg, ACCELEROMETER_DATA_TIMEOUT_MILLIS); Message measurementTimeoutMsg = Message.obtain(mHandler, mMeasurementTimeout); mHandler.sendMessageDelayed(measurementTimeoutMsg, ACCELEROMETER_DATA_TIMEOUT_MILLIS); } } Loading @@ -186,10 +193,12 @@ public class AnyMotionDetector { if (mMeasurementInProgress) { mSensorManager.unregisterListener(mListener); mHandler.removeCallbacks(mMeasurementTimeout); long detectionEndTime = SystemClock.elapsedRealtime(); mMeasurementInProgress = false; mPreviousGravityVector = mCurrentGravityVector; mCurrentGravityVector = mRunningStats.getRunningAverage(); if (mRunningStats.getSampleCount() == 0) { Slog.w(TAG, "No accelerometer data acquired for orientation measurement."); } if (DEBUG) { Slog.d(TAG, "mRunningStats = " + mRunningStats.toString()); String currentGravityVectorString = (mCurrentGravityVector == null) ? Loading @@ -203,7 +212,10 @@ public class AnyMotionDetector { status = getStationaryStatus(); if (DEBUG) Slog.d(TAG, "getStationaryStatus() returned " + status); if (status != RESULT_UNKNOWN) { if (mWakeLock.isHeld()) { mWakeLock.release(); mHandler.removeCallbacks(mWakelockTimeout); } if (DEBUG) { Slog.d(TAG, "Moved from STATE_ACTIVE to STATE_INACTIVE. status = " + status); } Loading @@ -217,7 +229,6 @@ public class AnyMotionDetector { " scheduled in " + ORIENTATION_MEASUREMENT_INTERVAL_MILLIS + " milliseconds."); Message msg = Message.obtain(mHandler, mSensorRestart); msg.setAsynchronous(true); mHandler.sendMessageDelayed(msg, ORIENTATION_MEASUREMENT_INTERVAL_MILLIS); } } Loading Loading @@ -271,6 +282,7 @@ public class AnyMotionDetector { } } if (status != RESULT_UNKNOWN) { mHandler.removeCallbacks(mWakelockTimeout); mCallback.onAnyMotionResult(status); } } Loading Loading @@ -300,11 +312,21 @@ public class AnyMotionDetector { status = stopOrientationMeasurementLocked(); } if (status != RESULT_UNKNOWN) { mHandler.removeCallbacks(mWakelockTimeout); mCallback.onAnyMotionResult(status); } } }; private final Runnable mWakelockTimeout = new Runnable() { @Override public void run() { synchronized (mLock) { stop(); } } }; /** * A timestamped three dimensional vector and some vector operations. */ Loading services/core/java/com/android/server/DeviceIdleController.java +3 −4 Original line number Diff line number Diff line Loading @@ -973,13 +973,12 @@ public class DeviceIdleController extends SystemService cancelSensingTimeoutAlarmLocked(); } } if (result == AnyMotionDetector.RESULT_MOVED) { if (DEBUG) Slog.d(TAG, "RESULT_MOVED received."); if ((result == AnyMotionDetector.RESULT_MOVED) || (result == AnyMotionDetector.RESULT_UNKNOWN)) { synchronized (this) { handleMotionDetectedLocked(mConstants.INACTIVE_TIMEOUT, "sense_motion"); handleMotionDetectedLocked(mConstants.INACTIVE_TIMEOUT, "non_stationary"); } } else if (result == AnyMotionDetector.RESULT_STATIONARY) { if (DEBUG) Slog.d(TAG, "RESULT_STATIONARY received."); if (mState == STATE_SENSING) { // If we are currently sensing, it is time to move to locating. synchronized (this) { Loading Loading
services/core/java/com/android/server/AnyMotionDetector.java +50 −28 Original line number Diff line number Diff line Loading @@ -70,6 +70,9 @@ public class AnyMotionDetector { /** The interval between accelerometer orientation measurements. */ private static final long ORIENTATION_MEASUREMENT_INTERVAL_MILLIS = 5000; /** The maximum duration we will hold a wakelock to determine stationary status. */ private static final long WAKELOCK_TIMEOUT_MILLIS = 30000; /** * The duration in milliseconds after which an orientation measurement is considered * too stale to be used. Loading Loading @@ -141,16 +144,19 @@ public class AnyMotionDetector { mCurrentGravityVector = null; mPreviousGravityVector = null; mWakeLock.acquire(); Message wakelockTimeoutMsg = Message.obtain(mHandler, mWakelockTimeout); mHandler.sendMessageDelayed(wakelockTimeoutMsg, WAKELOCK_TIMEOUT_MILLIS); startOrientationMeasurementLocked(); } } } public void stop() { if (mState == STATE_ACTIVE) { synchronized (mLock) { if (mState == STATE_ACTIVE) { mState = STATE_INACTIVE; if (DEBUG) Slog.d(TAG, "Moved from STATE_ACTIVE to STATE_INACTIVE."); } if (mMeasurementInProgress) { mMeasurementInProgress = false; mSensorManager.unregisterListener(mListener); Loading @@ -159,7 +165,9 @@ public class AnyMotionDetector { mHandler.removeCallbacks(mSensorRestart); mCurrentGravityVector = null; mPreviousGravityVector = null; if (mWakeLock.isHeld()) { mWakeLock.release(); mHandler.removeCallbacks(mWakelockTimeout); } } } Loading @@ -173,9 +181,8 @@ public class AnyMotionDetector { mMeasurementInProgress = true; mRunningStats.reset(); } Message msg = Message.obtain(mHandler, mMeasurementTimeout); msg.setAsynchronous(true); mHandler.sendMessageDelayed(msg, ACCELEROMETER_DATA_TIMEOUT_MILLIS); Message measurementTimeoutMsg = Message.obtain(mHandler, mMeasurementTimeout); mHandler.sendMessageDelayed(measurementTimeoutMsg, ACCELEROMETER_DATA_TIMEOUT_MILLIS); } } Loading @@ -186,10 +193,12 @@ public class AnyMotionDetector { if (mMeasurementInProgress) { mSensorManager.unregisterListener(mListener); mHandler.removeCallbacks(mMeasurementTimeout); long detectionEndTime = SystemClock.elapsedRealtime(); mMeasurementInProgress = false; mPreviousGravityVector = mCurrentGravityVector; mCurrentGravityVector = mRunningStats.getRunningAverage(); if (mRunningStats.getSampleCount() == 0) { Slog.w(TAG, "No accelerometer data acquired for orientation measurement."); } if (DEBUG) { Slog.d(TAG, "mRunningStats = " + mRunningStats.toString()); String currentGravityVectorString = (mCurrentGravityVector == null) ? Loading @@ -203,7 +212,10 @@ public class AnyMotionDetector { status = getStationaryStatus(); if (DEBUG) Slog.d(TAG, "getStationaryStatus() returned " + status); if (status != RESULT_UNKNOWN) { if (mWakeLock.isHeld()) { mWakeLock.release(); mHandler.removeCallbacks(mWakelockTimeout); } if (DEBUG) { Slog.d(TAG, "Moved from STATE_ACTIVE to STATE_INACTIVE. status = " + status); } Loading @@ -217,7 +229,6 @@ public class AnyMotionDetector { " scheduled in " + ORIENTATION_MEASUREMENT_INTERVAL_MILLIS + " milliseconds."); Message msg = Message.obtain(mHandler, mSensorRestart); msg.setAsynchronous(true); mHandler.sendMessageDelayed(msg, ORIENTATION_MEASUREMENT_INTERVAL_MILLIS); } } Loading Loading @@ -271,6 +282,7 @@ public class AnyMotionDetector { } } if (status != RESULT_UNKNOWN) { mHandler.removeCallbacks(mWakelockTimeout); mCallback.onAnyMotionResult(status); } } Loading Loading @@ -300,11 +312,21 @@ public class AnyMotionDetector { status = stopOrientationMeasurementLocked(); } if (status != RESULT_UNKNOWN) { mHandler.removeCallbacks(mWakelockTimeout); mCallback.onAnyMotionResult(status); } } }; private final Runnable mWakelockTimeout = new Runnable() { @Override public void run() { synchronized (mLock) { stop(); } } }; /** * A timestamped three dimensional vector and some vector operations. */ Loading
services/core/java/com/android/server/DeviceIdleController.java +3 −4 Original line number Diff line number Diff line Loading @@ -973,13 +973,12 @@ public class DeviceIdleController extends SystemService cancelSensingTimeoutAlarmLocked(); } } if (result == AnyMotionDetector.RESULT_MOVED) { if (DEBUG) Slog.d(TAG, "RESULT_MOVED received."); if ((result == AnyMotionDetector.RESULT_MOVED) || (result == AnyMotionDetector.RESULT_UNKNOWN)) { synchronized (this) { handleMotionDetectedLocked(mConstants.INACTIVE_TIMEOUT, "sense_motion"); handleMotionDetectedLocked(mConstants.INACTIVE_TIMEOUT, "non_stationary"); } } else if (result == AnyMotionDetector.RESULT_STATIONARY) { if (DEBUG) Slog.d(TAG, "RESULT_STATIONARY received."); if (mState == STATE_SENSING) { // If we are currently sensing, it is time to move to locating. synchronized (this) { Loading