aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriele M <moto.falcon.git@gmail.com>2016-02-29 13:23:40 +0100
committerGabriele M <moto.falcon.git@gmail.com>2016-04-01 13:03:58 -0700
commit7e6bea9ac4b736176723b8e1c57b58fb24382989 (patch)
tree699541551b9d9879065e6ce4786e64f8d7eca70a
parent963e53e19a0da216da8b8b825ce39e095c8cc403 (diff)
msm8226-common: CMActions: Hold a wakelock when the screen is on
Sometimes the device is suspended before ACTION_SCREEN_OFF is received. When this happens, the proximity sensor doesn't get enabled, breaking the wake gesture. Hold a wakelock when the screen is on and release it only once the sensor has been enabled. Change-Id: I320d4bbc4aea2f2f7e3ba9bdf854af08a97631fd
-rw-r--r--CMActions/src/com/cmactions/CMActionsService.java15
1 files changed, 15 insertions, 0 deletions
diff --git a/CMActions/src/com/cmactions/CMActionsService.java b/CMActions/src/com/cmactions/CMActionsService.java
index 2c3f84c..9eb1efa 100644
--- a/CMActions/src/com/cmactions/CMActionsService.java
+++ b/CMActions/src/com/cmactions/CMActionsService.java
@@ -50,6 +50,7 @@ public class CMActionsService extends Service {
private Context mContext;
private MotoProximitySensor mSensor;
private PowerManager mPowerManager;
+ private PowerManager.WakeLock mWakeLock;
private boolean mHandwaveGestureEnabled = false;
private boolean mPocketGestureEnabled = false;
@@ -112,6 +113,7 @@ public class CMActionsService extends Service {
mContext = this;
mPowerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
mSensor = new MotoProximitySensor(mContext);
+ mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "CMActionsWakeLock");
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
loadPreferences(sharedPrefs);
sharedPrefs.registerOnSharedPreferenceChangeListener(mPrefListener);
@@ -151,6 +153,10 @@ public class CMActionsService extends Service {
private void onDisplayOn() {
if (DEBUG) Log.d(TAG, "Display on");
mSensor.disable();
+ if (areGesturesEnabled() && !mWakeLock.isHeld()) {
+ if (DEBUG) Log.d(TAG, "Acquiring wakelock");
+ mWakeLock.acquire();
+ }
}
private void onDisplayOff() {
@@ -158,6 +164,10 @@ public class CMActionsService extends Service {
if (areGesturesEnabled()) {
mSensor.enable();
}
+ if (mWakeLock.isHeld()) {
+ if (DEBUG) Log.d(TAG, "Releasing wakelock");
+ mWakeLock.release();
+ }
}
private void loadPreferences(SharedPreferences sharedPreferences) {
@@ -185,6 +195,11 @@ public class CMActionsService extends Service {
} else if (GESTURE_POCKET_KEY.equals(key)) {
mPocketGestureEnabled = sharedPreferences.getBoolean(GESTURE_POCKET_KEY, false);
}
+
+ if (areGesturesEnabled() && !mWakeLock.isHeld()) {
+ if (DEBUG) Log.d(TAG, "Acquiring wakelock");
+ mWakeLock.acquire();
+ }
}
};
}