samsung: doze: add proximity wake
authorDave Daynard <nardholio@gmail.com>
Mon, 25 May 2015 16:54:00 +0000 (12:54 -0400)
committerJan Altensen <info@stricted.net>
Fri, 20 Mar 2020 13:56:31 +0000 (14:56 +0100)
Change-Id: Ib02f4611e7b8bc09d540ca5c49aab68ef27f188b

doze/AndroidManifest.xml
doze/res/values/strings.xml
doze/res/xml/gesture_panel.xml
doze/src/com/cyanogenmod/settings/device/SamsungDozeService.java
doze/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java

index 804b80db32512df4435d48f0d4a59ddb9d4d244f..0bcc51f9f6aee7252492686e6e3e16ac498eacb7 100644 (file)
@@ -5,6 +5,7 @@
     android:versionName="1.0"
     android:sharedUserId="android.uid.system">
 
+    <uses-permission android:name="android.permission.DEVICE_POWER" />
     <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
     <uses-permission android:name="android.permission.VIBRATE"/>
     <uses-permission android:name="android.permission.WAKE_LOCK" />
index 273a2116a1458ba62197d1ba8424538773c7f90e..6c2d264477a5ff18966524d34ff5743637a59bb2 100644 (file)
@@ -28,4 +28,9 @@
     <string name="pocket_gesture_title">Pocket</string>
     <string name="pocket_gesture_summary">Pulse notifications on removal from pocket</string>
 
+    <string name="proximity_wake_title">Proximity wake</string>
+
+    <string name="proximity_wake_enable_title">Proximity wake</string>
+    <string name="proximity_wake_enable_summary">Wake device on hand wave</string>
+
 </resources>
index ba48f9d4a20c77f5efc420bb2986098c086aee5e..40a017ce967d92e77bcc228885ca8e602979c684 100644 (file)
             android:summary="@string/pocket_gesture_summary" />
     </PreferenceCategory>
 
+    <PreferenceCategory
+        android:key="proximity_wake_key"
+        android:title="@string/proximity_wake_title" >
+
+        <SwitchPreference
+            android:key="proximity_wake_enable"
+            android:defaultValue="false"
+            android:title="@string/proximity_wake_enable_title"
+            android:summary="@string/proximity_wake_enable_summary" />
+    </PreferenceCategory>
+
 </PreferenceScreen>
\ No newline at end of file
index f559544391de1b52188722737a37ab55e63050b9..6d40cf1459696bf64fa74b5763f1c48625d6bc57 100644 (file)
@@ -33,6 +33,7 @@ import android.provider.Settings;
 import android.util.Log;
 
 import java.util.ArrayList;
+import java.util.concurrent.TimeUnit;
 import java.util.List;
 
 public class SamsungDozeService extends Service {
@@ -43,6 +44,7 @@ public class SamsungDozeService extends Service {
 
     private static final String GESTURE_HAND_WAVE_KEY = "gesture_hand_wave";
     private static final String GESTURE_POCKET_KEY = "gesture_pocket";
+    private static final String PROXIMITY_WAKE_KEY = "proximity_wake_enable";
 
     private static final int POCKET_DELTA_NS = 1000 * 1000 * 1000;
 
@@ -52,6 +54,7 @@ public class SamsungDozeService extends Service {
 
     private boolean mHandwaveGestureEnabled = false;
     private boolean mPocketGestureEnabled = false;
+    private boolean mProximityWakeEnabled = false;
 
     class SamsungProximitySensor implements SensorEventListener {
         private SensorManager mSensorManager;
@@ -88,6 +91,9 @@ public class SamsungDozeService extends Service {
 
             if (mHandwaveGestureEnabled && mPocketGestureEnabled) {
                 return true;
+            } else if (mProximityWakeEnabled && (delta < POCKET_DELTA_NS)) {
+                mPowerManager.wakeUp(TimeUnit.NANOSECONDS.toMillis(timestamp));
+                return false;
             } else if (mHandwaveGestureEnabled && !mPocketGestureEnabled) {
                 return delta < POCKET_DELTA_NS;
             } else if (!mHandwaveGestureEnabled && mPocketGestureEnabled) {
@@ -96,8 +102,9 @@ public class SamsungDozeService extends Service {
             return false;
         }
 
-        public void enable() {
-            if (mHandwaveGestureEnabled || mPocketGestureEnabled) {
+        public void testAndEnable() {
+            if ((isDozeEnabled() && (mHandwaveGestureEnabled || mPocketGestureEnabled)) ||
+                    mProximityWakeEnabled) {
                 mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
             }
         }
@@ -116,8 +123,8 @@ public class SamsungDozeService extends Service {
         SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
         loadPreferences(sharedPrefs);
         sharedPrefs.registerOnSharedPreferenceChangeListener(mPrefListener);
-        if (!isInteractive() && isDozeEnabled()) {
-            mSensor.enable();
+        if (!isInteractive()) {
+            mSensor.testAndEnable();
         }
     }
 
@@ -155,9 +162,7 @@ public class SamsungDozeService extends Service {
 
     private void onDisplayOff() {
         if (DEBUG) Log.d(TAG, "Display off");
-        if (isDozeEnabled()) {
-            mSensor.enable();
-        }
+        mSensor.testAndEnable();
     }
 
     private void loadPreferences(SharedPreferences sharedPreferences) {
@@ -184,6 +189,8 @@ public class SamsungDozeService extends Service {
                 mHandwaveGestureEnabled = sharedPreferences.getBoolean(GESTURE_HAND_WAVE_KEY, false);
             } else if (GESTURE_POCKET_KEY.equals(key)) {
                 mPocketGestureEnabled = sharedPreferences.getBoolean(GESTURE_POCKET_KEY, false);
+            } else if (PROXIMITY_WAKE_KEY.equals(key)) {
+                mProximityWakeEnabled = sharedPreferences.getBoolean(PROXIMITY_WAKE_KEY, false);
             }
         }
     };
index dc184225a6702407ae3110d3c604b795888c198e..5b69988f169c747a4bb3c30a1fd4d66d7c4617ad 100644 (file)
@@ -32,10 +32,12 @@ public class TouchscreenGestureSettings extends PreferenceActivity {
     private static final String KEY_AMBIENT_DISPLAY_ENABLE = "ambient_display_enable";
     private static final String KEY_HAND_WAVE = "gesture_hand_wave";
     private static final String KEY_GESTURE_POCKET = "gesture_pocket";
+    private static final String KEY_PROXIMITY_WAKE = "proximity_wake_enable";
 
     private SwitchPreference mAmbientDisplayPreference;
     private SwitchPreference mHandwavePreference;
     private SwitchPreference mPocketPreference;
+    private SwitchPreference mProximityWakePreference;
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
@@ -50,9 +52,13 @@ public class TouchscreenGestureSettings extends PreferenceActivity {
         mHandwavePreference =
             (SwitchPreference) findPreference(KEY_HAND_WAVE);
         mHandwavePreference.setEnabled(dozeEnabled);
+        mHandwavePreference.setOnPreferenceChangeListener(mProximityListener);
         mPocketPreference =
             (SwitchPreference) findPreference(KEY_GESTURE_POCKET);
         mPocketPreference.setEnabled(dozeEnabled);
+        mProximityWakePreference =
+            (SwitchPreference) findPreference(KEY_PROXIMITY_WAKE);
+        mProximityWakePreference.setOnPreferenceChangeListener(mProximityListener);
 
         final ActionBar actionBar = getActionBar();
         actionBar.setDisplayHomeAsUpEnabled(true);
@@ -100,4 +106,19 @@ public class TouchscreenGestureSettings extends PreferenceActivity {
             return ret;
         }
     };
+
+    private Preference.OnPreferenceChangeListener mProximityListener =
+        new Preference.OnPreferenceChangeListener() {
+        @Override
+        public boolean onPreferenceChange(Preference preference, Object newValue) {
+            if ((boolean) newValue) {
+                if (preference.getKey().equals(KEY_HAND_WAVE)) {
+                    mProximityWakePreference.setChecked(false);
+                } else if (preference.getKey().equals(KEY_PROXIMITY_WAKE)) {
+                    mHandwavePreference.setChecked(false);
+                }
+            }
+            return true;
+        }
+    };
 }