Loading services/core/java/com/android/server/AnyMotionDetector.java +48 −39 Original line number Diff line number Diff line Loading @@ -108,6 +108,7 @@ public class AnyMotionDetector { public AnyMotionDetector(PowerManager pm, Handler handler, SensorManager sm, DeviceIdleCallback callback, float thresholdAngle) { if (DEBUG) Slog.d(TAG, "AnyMotionDetector instantiated."); synchronized (mLock) { mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); mWakeLock.setReferenceCounted(false); mHandler = handler; Loading @@ -122,23 +123,32 @@ public class AnyMotionDetector { ((double)ORIENTATION_MEASUREMENT_DURATION_MILLIS / SAMPLING_INTERVAL_MILLIS)); if (DEBUG) Slog.d(TAG, "mNumSufficientSamples = " + mNumSufficientSamples); } } /* * Acquire accel data until we determine AnyMotion status. */ public void checkForAnyMotion() { if (DEBUG) Slog.d(TAG, "checkForAnyMotion(). mState = " + mState); if (DEBUG) { Slog.d(TAG, "checkForAnyMotion(). mState = " + mState); } if (mState != STATE_ACTIVE) { synchronized (mLock) { mState = STATE_ACTIVE; if (DEBUG) Slog.d(TAG, "Moved from STATE_INACTIVE to STATE_ACTIVE."); if (DEBUG) { Slog.d(TAG, "Moved from STATE_INACTIVE to STATE_ACTIVE."); } mCurrentGravityVector = null; mPreviousGravityVector = null; startOrientationMeasurement(); mWakeLock.acquire(); startOrientationMeasurementLocked(); } } } public void stop() { if (mState == STATE_ACTIVE) { synchronized (mLock) { mState = STATE_INACTIVE; if (DEBUG) Slog.d(TAG, "Moved from STATE_ACTIVE to STATE_INACTIVE."); if (mMeasurementInProgress) { Loading @@ -147,24 +157,22 @@ public class AnyMotionDetector { } mHandler.removeCallbacks(mMeasurementTimeout); mHandler.removeCallbacks(mSensorRestart); mWakeLock.release(); mCurrentGravityVector = null; mPreviousGravityVector = null; mWakeLock.release(); } } } private void startOrientationMeasurement() { if (DEBUG) Slog.d(TAG, "startOrientationMeasurement: mMeasurementInProgress=" + private void startOrientationMeasurementLocked() { if (DEBUG) Slog.d(TAG, "startOrientationMeasurementLocked: mMeasurementInProgress=" + mMeasurementInProgress + ", (mAccelSensor != null)=" + (mAccelSensor != null)); if (!mMeasurementInProgress && mAccelSensor != null) { if (mSensorManager.registerListener(mListener, mAccelSensor, SAMPLING_INTERVAL_MILLIS * 1000)) { mWakeLock.acquire(); mMeasurementInProgress = true; mRunningStats.reset(); } Message msg = Message.obtain(mHandler, mMeasurementTimeout); msg.setAsynchronous(true); mHandler.sendMessageDelayed(msg, ACCELEROMETER_DATA_TIMEOUT_MILLIS); Loading @@ -178,7 +186,6 @@ public class AnyMotionDetector { if (mMeasurementInProgress) { mSensorManager.unregisterListener(mListener); mHandler.removeCallbacks(mMeasurementTimeout); mWakeLock.release(); long detectionEndTime = SystemClock.elapsedRealtime(); mMeasurementInProgress = false; mPreviousGravityVector = mCurrentGravityVector; Loading @@ -196,8 +203,10 @@ public class AnyMotionDetector { status = getStationaryStatus(); if (DEBUG) Slog.d(TAG, "getStationaryStatus() returned " + status); if (status != RESULT_UNKNOWN) { if (DEBUG) Slog.d(TAG, "Moved from STATE_ACTIVE to STATE_INACTIVE. status = " + status); mWakeLock.release(); if (DEBUG) { Slog.d(TAG, "Moved from STATE_ACTIVE to STATE_INACTIVE. status = " + status); } mState = STATE_INACTIVE; } else { /* Loading Loading @@ -275,7 +284,7 @@ public class AnyMotionDetector { @Override public void run() { synchronized (mLock) { startOrientationMeasurement(); startOrientationMeasurementLocked(); } } }; Loading Loading
services/core/java/com/android/server/AnyMotionDetector.java +48 −39 Original line number Diff line number Diff line Loading @@ -108,6 +108,7 @@ public class AnyMotionDetector { public AnyMotionDetector(PowerManager pm, Handler handler, SensorManager sm, DeviceIdleCallback callback, float thresholdAngle) { if (DEBUG) Slog.d(TAG, "AnyMotionDetector instantiated."); synchronized (mLock) { mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); mWakeLock.setReferenceCounted(false); mHandler = handler; Loading @@ -122,23 +123,32 @@ public class AnyMotionDetector { ((double)ORIENTATION_MEASUREMENT_DURATION_MILLIS / SAMPLING_INTERVAL_MILLIS)); if (DEBUG) Slog.d(TAG, "mNumSufficientSamples = " + mNumSufficientSamples); } } /* * Acquire accel data until we determine AnyMotion status. */ public void checkForAnyMotion() { if (DEBUG) Slog.d(TAG, "checkForAnyMotion(). mState = " + mState); if (DEBUG) { Slog.d(TAG, "checkForAnyMotion(). mState = " + mState); } if (mState != STATE_ACTIVE) { synchronized (mLock) { mState = STATE_ACTIVE; if (DEBUG) Slog.d(TAG, "Moved from STATE_INACTIVE to STATE_ACTIVE."); if (DEBUG) { Slog.d(TAG, "Moved from STATE_INACTIVE to STATE_ACTIVE."); } mCurrentGravityVector = null; mPreviousGravityVector = null; startOrientationMeasurement(); mWakeLock.acquire(); startOrientationMeasurementLocked(); } } } public void stop() { if (mState == STATE_ACTIVE) { synchronized (mLock) { mState = STATE_INACTIVE; if (DEBUG) Slog.d(TAG, "Moved from STATE_ACTIVE to STATE_INACTIVE."); if (mMeasurementInProgress) { Loading @@ -147,24 +157,22 @@ public class AnyMotionDetector { } mHandler.removeCallbacks(mMeasurementTimeout); mHandler.removeCallbacks(mSensorRestart); mWakeLock.release(); mCurrentGravityVector = null; mPreviousGravityVector = null; mWakeLock.release(); } } } private void startOrientationMeasurement() { if (DEBUG) Slog.d(TAG, "startOrientationMeasurement: mMeasurementInProgress=" + private void startOrientationMeasurementLocked() { if (DEBUG) Slog.d(TAG, "startOrientationMeasurementLocked: mMeasurementInProgress=" + mMeasurementInProgress + ", (mAccelSensor != null)=" + (mAccelSensor != null)); if (!mMeasurementInProgress && mAccelSensor != null) { if (mSensorManager.registerListener(mListener, mAccelSensor, SAMPLING_INTERVAL_MILLIS * 1000)) { mWakeLock.acquire(); mMeasurementInProgress = true; mRunningStats.reset(); } Message msg = Message.obtain(mHandler, mMeasurementTimeout); msg.setAsynchronous(true); mHandler.sendMessageDelayed(msg, ACCELEROMETER_DATA_TIMEOUT_MILLIS); Loading @@ -178,7 +186,6 @@ public class AnyMotionDetector { if (mMeasurementInProgress) { mSensorManager.unregisterListener(mListener); mHandler.removeCallbacks(mMeasurementTimeout); mWakeLock.release(); long detectionEndTime = SystemClock.elapsedRealtime(); mMeasurementInProgress = false; mPreviousGravityVector = mCurrentGravityVector; Loading @@ -196,8 +203,10 @@ public class AnyMotionDetector { status = getStationaryStatus(); if (DEBUG) Slog.d(TAG, "getStationaryStatus() returned " + status); if (status != RESULT_UNKNOWN) { if (DEBUG) Slog.d(TAG, "Moved from STATE_ACTIVE to STATE_INACTIVE. status = " + status); mWakeLock.release(); if (DEBUG) { Slog.d(TAG, "Moved from STATE_ACTIVE to STATE_INACTIVE. status = " + status); } mState = STATE_INACTIVE; } else { /* Loading Loading @@ -275,7 +284,7 @@ public class AnyMotionDetector { @Override public void run() { synchronized (mLock) { startOrientationMeasurement(); startOrientationMeasurementLocked(); } } }; Loading