From: Arian Date: Wed, 14 Oct 2020 21:06:47 +0000 (+0200) Subject: samsung: doze: Allow to wake the screen on gestures instead of pulsing X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f0653e76558c069251c696ddc5bb09a1e6c1e0ac;p=GitHub%2FLineageOS%2Fandroid_hardware_samsung.git 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 --- diff --git a/doze/res/xml/gesture_panel.xml b/doze/res/xml/gesture_panel.xml index 5680fda..e59de9c 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 101f670..418197b 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 7ee7cab..aaddb0c 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 b8b5df9..9478c89 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); + } }