samsung: doze: Allow to wake the screen on gestures instead of pulsing

Co-authored-by: Nauval Rizky <enuma.alrizky@gmail.com>
Co-authored-by: Fabian Leutenegger <fabian.leutenegger@bluewin.ch>
Change-Id: I1e74f8eafa51843e77d2d8c514c646a4494327cd
tirimbino
Arian 4 years ago committed by Bruno Martins
parent 67e48ea301
commit c143344242
  1. 6
      doze/res/xml/gesture_panel.xml
  2. 16
      doze/src/org/lineageos/settings/doze/SamsungDozeService.java
  3. 7
      doze/src/org/lineageos/settings/doze/SamsungDozeSettings.java
  4. 6
      doze/src/org/lineageos/settings/doze/Utils.java

@ -24,6 +24,12 @@
android:summary="@string/ambient_display_always_on_summary" android:summary="@string/ambient_display_always_on_summary"
android:persistent="false" /> 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 <PreferenceCategory
android:key="proximity_sensor" android:key="proximity_sensor"
android:title="@string/proximity_sensor_title"> android:title="@string/proximity_sensor_title">

@ -27,6 +27,7 @@ import android.hardware.SensorEventListener;
import android.hardware.SensorManager; import android.hardware.SensorManager;
import android.os.IBinder; import android.os.IBinder;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.SystemClock;
import android.os.UserHandle; import android.os.UserHandle;
import android.util.Log; import android.util.Log;
@ -72,7 +73,7 @@ public class SamsungDozeService extends Service {
boolean isNear = event.values[0] < mSensor.getMaximumRange(); boolean isNear = event.values[0] < mSensor.getMaximumRange();
if (mSawNear && !isNear) { if (mSawNear && !isNear) {
if (shouldPulse(event.timestamp)) { if (shouldPulse(event.timestamp)) {
launchDozePulse(); wakeOrLaunchDozePulse();
} }
} else { } else {
mInPocketTime = event.timestamp; mInPocketTime = event.timestamp;
@ -140,9 +141,16 @@ public class SamsungDozeService extends Service {
return null; return null;
} }
private void launchDozePulse() { private void wakeOrLaunchDozePulse() {
mContext.sendBroadcastAsUser(new Intent(DOZE_INTENT), if (Utils.isWakeOnGestureEnabled(mContext)) {
new UserHandle(UserHandle.USER_CURRENT)); 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() { private boolean isInteractive() {

@ -43,6 +43,7 @@ public class SamsungDozeSettings extends PreferenceFragment
private SwitchPreference mAlwaysOnDisplayPreference; private SwitchPreference mAlwaysOnDisplayPreference;
private SwitchPreference mHandwavePreference; private SwitchPreference mHandwavePreference;
private SwitchPreference mPocketPreference; private SwitchPreference mPocketPreference;
private SwitchPreference mWakeOnGesturePreference;
private Handler mHandler = new Handler(); private Handler mHandler = new Handler();
@ -67,12 +68,17 @@ public class SamsungDozeSettings extends PreferenceFragment
mPocketPreference.setEnabled(dozeEnabled); mPocketPreference.setEnabled(dozeEnabled);
mPocketPreference.setOnPreferenceChangeListener(this); 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 // Hide AOD if not supported and set all its dependents otherwise
if (!Utils.alwaysOnDisplayAvailable(getActivity())) { if (!Utils.alwaysOnDisplayAvailable(getActivity())) {
getPreferenceScreen().removePreference(mAlwaysOnDisplayPreference); getPreferenceScreen().removePreference(mAlwaysOnDisplayPreference);
} else { } else {
mHandwavePreference.setDependency(Utils.ALWAYS_ON_DISPLAY); mHandwavePreference.setDependency(Utils.ALWAYS_ON_DISPLAY);
mPocketPreference.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); mHandwavePreference.setEnabled(isChecked);
mPocketPreference.setEnabled(isChecked); mPocketPreference.setEnabled(isChecked);
mWakeOnGesturePreference.setEnabled(isChecked);
} }
@Override @Override

@ -38,6 +38,7 @@ public final class Utils {
protected static final String GESTURE_HAND_WAVE_KEY = "gesture_hand_wave"; protected static final String GESTURE_HAND_WAVE_KEY = "gesture_hand_wave";
protected static final String GESTURE_POCKET_KEY = "gesture_pocket"; 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) { protected static void startService(Context context) {
if (DEBUG) Log.d(TAG, "Starting service"); if (DEBUG) Log.d(TAG, "Starting service");
@ -101,4 +102,9 @@ public final class Utils {
return PreferenceManager.getDefaultSharedPreferences(context) return PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(GESTURE_POCKET_KEY, false); .getBoolean(GESTURE_POCKET_KEY, false);
} }
protected static boolean isWakeOnGestureEnabled(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(WAKE_ON_GESTURE_KEY, false);
}
} }

Loading…
Cancel
Save