samsung: doze: Allow to wake the screen on gestures instead of pulsing
authorArian <arian.kulmer@web.de>
Wed, 14 Oct 2020 21:06:47 +0000 (23:06 +0200)
committerFrancescodario Cuzzocrea <bosconovic@gmail.com>
Wed, 13 Jan 2021 14:29:13 +0000 (15:29 +0100)
Co-authored-by: Nauval Rizky <enuma.alrizky@gmail.com>
Co-authored-by: Fabian Leutenegger <fabian.leutenegger@bluewin.ch>
Change-Id: I1e74f8eafa51843e77d2d8c514c646a4494327cd

doze/res/xml/gesture_panel.xml
doze/src/org/lineageos/settings/doze/SamsungDozeService.java
doze/src/org/lineageos/settings/doze/SamsungDozeSettings.java
doze/src/org/lineageos/settings/doze/Utils.java

index 5680fda6a62bc18a49d4aad6d948bbea5d741ac1..e59de9c326c7bfe12f6f7f8c6d2cadb78c67e8af 100644 (file)
         android:summary="@string/ambient_display_always_on_summary"
         android:persistent="false" />
 
+    <SwitchPreference
+        android:key="wake_on_gesture"
+        android:defaultValue="false"
+        android:title="@string/wake_on_gesture_title"
+        android:summary="@string/wake_on_gesture_summary" />
+
     <PreferenceCategory
         android:key="proximity_sensor"
         android:title="@string/proximity_sensor_title">
index 101f670b017feca260483883668864b85059d7a8..418197bcb645361243dbe36d4d95082bf6da172e 100644 (file)
@@ -27,6 +27,7 @@ import android.hardware.SensorEventListener;
 import android.hardware.SensorManager;
 import android.os.IBinder;
 import android.os.PowerManager;
+import android.os.SystemClock;
 import android.os.UserHandle;
 import android.util.Log;
 
@@ -72,7 +73,7 @@ public class SamsungDozeService extends Service {
             boolean isNear = event.values[0] < mSensor.getMaximumRange();
             if (mSawNear && !isNear) {
                 if (shouldPulse(event.timestamp)) {
-                    launchDozePulse();
+                    wakeOrLaunchDozePulse();
                 }
             } else {
                 mInPocketTime = event.timestamp;
@@ -140,9 +141,16 @@ public class SamsungDozeService extends Service {
         return null;
     }
 
-    private void launchDozePulse() {
-        mContext.sendBroadcastAsUser(new Intent(DOZE_INTENT),
-                new UserHandle(UserHandle.USER_CURRENT));
+    private void wakeOrLaunchDozePulse() {
+        if (Utils.isWakeOnGestureEnabled(mContext)) {
+            if (DEBUG) Log.d(TAG, "Wake up display");
+            PowerManager powerManager = mContext.getSystemService(PowerManager.class);
+            powerManager.wakeUp(SystemClock.uptimeMillis(), PowerManager.WAKE_REASON_GESTURE, TAG);
+        } else {
+            if (DEBUG) Log.d(TAG, "Launch doze pulse");
+            mContext.sendBroadcastAsUser(
+                    new Intent(DOZE_INTENT), new UserHandle(UserHandle.USER_CURRENT));
+        }
     }
 
     private boolean isInteractive() {
index 7ee7cab692acac1a178db97f258855bd57623fc3..aaddb0caee5c966ee76e0ae723af5b18ddb3af9f 100644 (file)
@@ -43,6 +43,7 @@ public class SamsungDozeSettings extends PreferenceFragment
     private SwitchPreference mAlwaysOnDisplayPreference;
     private SwitchPreference mHandwavePreference;
     private SwitchPreference mPocketPreference;
+    private SwitchPreference mWakeOnGesturePreference;
 
     private Handler mHandler = new Handler();
 
@@ -67,12 +68,17 @@ public class SamsungDozeSettings extends PreferenceFragment
         mPocketPreference.setEnabled(dozeEnabled);
         mPocketPreference.setOnPreferenceChangeListener(this);
 
+        mWakeOnGesturePreference = (SwitchPreference) findPreference(Utils.WAKE_ON_GESTURE_KEY);
+        mWakeOnGesturePreference.setEnabled(dozeEnabled);
+        mWakeOnGesturePreference.setOnPreferenceChangeListener(this);
+
         // Hide AOD if not supported and set all its dependents otherwise
         if (!Utils.alwaysOnDisplayAvailable(getActivity())) {
             getPreferenceScreen().removePreference(mAlwaysOnDisplayPreference);
         } else {
             mHandwavePreference.setDependency(Utils.ALWAYS_ON_DISPLAY);
             mPocketPreference.setDependency(Utils.ALWAYS_ON_DISPLAY);
+            mWakeOnGesturePreference.setDependency(Utils.ALWAYS_ON_DISPLAY);
         }
     }
 
@@ -143,6 +149,7 @@ public class SamsungDozeSettings extends PreferenceFragment
 
         mHandwavePreference.setEnabled(isChecked);
         mPocketPreference.setEnabled(isChecked);
+        mWakeOnGesturePreference.setEnabled(isChecked);
     }
 
     @Override
index b8b5df954395010515f9307e4a3767a5be47eae2..9478c89bd9d75b944d50c2816ed3b7f10257c180 100644 (file)
@@ -38,6 +38,7 @@ public final class Utils {
 
     protected static final String GESTURE_HAND_WAVE_KEY = "gesture_hand_wave";
     protected static final String GESTURE_POCKET_KEY = "gesture_pocket";
+    protected static final String WAKE_ON_GESTURE_KEY = "wake_on_gesture";
 
     protected static void startService(Context context) {
         if (DEBUG) Log.d(TAG, "Starting service");
@@ -101,4 +102,9 @@ public final class Utils {
         return PreferenceManager.getDefaultSharedPreferences(context)
                 .getBoolean(GESTURE_POCKET_KEY, false);
     }
+
+    protected static boolean isWakeOnGestureEnabled(Context context) {
+        return PreferenceManager.getDefaultSharedPreferences(context)
+                .getBoolean(WAKE_ON_GESTURE_KEY, false);
+    }
 }