From c14334424235d33a9a52c67f819e638f526c562e Mon Sep 17 00:00:00 2001 From: Arian Date: Wed, 14 Oct 2020 23:06:47 +0200 Subject: [PATCH] samsung: doze: Allow to wake the screen on gestures instead of pulsing Co-authored-by: Nauval Rizky Co-authored-by: Fabian Leutenegger Change-Id: I1e74f8eafa51843e77d2d8c514c646a4494327cd --- doze/res/xml/gesture_panel.xml | 6 ++++++ .../settings/doze/SamsungDozeService.java | 16 ++++++++++++---- .../settings/doze/SamsungDozeSettings.java | 7 +++++++ doze/src/org/lineageos/settings/doze/Utils.java | 6 ++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/doze/res/xml/gesture_panel.xml b/doze/res/xml/gesture_panel.xml index 5680fda6..e59de9c3 100644 --- a/doze/res/xml/gesture_panel.xml +++ b/doze/res/xml/gesture_panel.xml @@ -24,6 +24,12 @@ android:summary="@string/ambient_display_always_on_summary" android:persistent="false" /> + + diff --git a/doze/src/org/lineageos/settings/doze/SamsungDozeService.java b/doze/src/org/lineageos/settings/doze/SamsungDozeService.java index 101f670b..418197bc 100644 --- a/doze/src/org/lineageos/settings/doze/SamsungDozeService.java +++ b/doze/src/org/lineageos/settings/doze/SamsungDozeService.java @@ -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() { diff --git a/doze/src/org/lineageos/settings/doze/SamsungDozeSettings.java b/doze/src/org/lineageos/settings/doze/SamsungDozeSettings.java index 7ee7cab6..aaddb0ca 100644 --- a/doze/src/org/lineageos/settings/doze/SamsungDozeSettings.java +++ b/doze/src/org/lineageos/settings/doze/SamsungDozeSettings.java @@ -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 diff --git a/doze/src/org/lineageos/settings/doze/Utils.java b/doze/src/org/lineageos/settings/doze/Utils.java index b8b5df95..9478c89b 100644 --- a/doze/src/org/lineageos/settings/doze/Utils.java +++ b/doze/src/org/lineageos/settings/doze/Utils.java @@ -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); + } }