summaryrefslogtreecommitdiff
path: root/doze
diff options
context:
space:
mode:
authorArian <arian.kulmer@web.de>2020-10-14 23:06:47 +0200
committerMichael Bestas <mkbestas@lineageos.org>2020-12-20 18:55:01 +0200
commit318d4dceb3181605b26db297af4379c42369a040 (patch)
treef0e14b85cdefc15b17400e73f7bf324cd434effc /doze
parentb3b442059acc0a14269c72ab4d485de8fa7e95c4 (diff)
sdm660-common: 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
Diffstat (limited to 'doze')
-rw-r--r--doze/res/xml/doze_settings.xml6
-rw-r--r--doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java6
-rw-r--r--doze/src/org/lineageos/settings/doze/ProximitySensor.java2
-rw-r--r--doze/src/org/lineageos/settings/doze/TiltSensor.java2
-rw-r--r--doze/src/org/lineageos/settings/doze/Utils.java21
5 files changed, 31 insertions, 6 deletions
diff --git a/doze/res/xml/doze_settings.xml b/doze/res/xml/doze_settings.xml
index dd6e19b..5708c65 100644
--- a/doze/res/xml/doze_settings.xml
+++ b/doze/res/xml/doze_settings.xml
@@ -16,6 +16,12 @@
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+ <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="tilt_sensor"
android:title="@string/tilt_sensor_title">
diff --git a/doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java b/doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java
index 52458d1..7769edd 100644
--- a/doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java
+++ b/doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java
@@ -46,6 +46,7 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
private TextView mTextView;
private View mSwitchBar;
+ private SwitchPreference mWakeOnGesturePreference;
private SwitchPreference mPickUpPreference;
private SwitchPreference mHandwavePreference;
private SwitchPreference mPocketPreference;
@@ -66,6 +67,10 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
boolean dozeEnabled = Utils.isDozeEnabled(getActivity());
+ mWakeOnGesturePreference = (SwitchPreference) findPreference(Utils.WAKE_ON_GESTURE_KEY);
+ mWakeOnGesturePreference.setEnabled(dozeEnabled);
+ mWakeOnGesturePreference.setOnPreferenceChangeListener(this);
+
PreferenceCategory proximitySensorCategory =
(PreferenceCategory) getPreferenceScreen().findPreference(Utils.CATEG_PROX_SENSOR);
@@ -130,6 +135,7 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
mTextView.setText(getString(isChecked ? R.string.switch_bar_on : R.string.switch_bar_off));
mSwitchBar.setActivated(isChecked);
+ mWakeOnGesturePreference.setEnabled(isChecked);
mPickUpPreference.setEnabled(isChecked);
mHandwavePreference.setEnabled(isChecked);
mPocketPreference.setEnabled(isChecked);
diff --git a/doze/src/org/lineageos/settings/doze/ProximitySensor.java b/doze/src/org/lineageos/settings/doze/ProximitySensor.java
index 71594ff..7d0bc39 100644
--- a/doze/src/org/lineageos/settings/doze/ProximitySensor.java
+++ b/doze/src/org/lineageos/settings/doze/ProximitySensor.java
@@ -63,7 +63,7 @@ public class ProximitySensor implements SensorEventListener {
boolean isNear = event.values[0] < mSensor.getMaximumRange();
if (mSawNear && !isNear) {
if (shouldPulse(event.timestamp)) {
- Utils.launchDozePulse(mContext);
+ Utils.wakeOrLaunchDozePulse(mContext);
}
} else {
mInPocketTime = event.timestamp;
diff --git a/doze/src/org/lineageos/settings/doze/TiltSensor.java b/doze/src/org/lineageos/settings/doze/TiltSensor.java
index 6598127..cdaec9b 100644
--- a/doze/src/org/lineageos/settings/doze/TiltSensor.java
+++ b/doze/src/org/lineageos/settings/doze/TiltSensor.java
@@ -67,7 +67,7 @@ public class TiltSensor implements SensorEventListener {
}
if (event.values[0] == 1) {
- Utils.launchDozePulse(mContext);
+ Utils.wakeOrLaunchDozePulse(mContext);
}
}
diff --git a/doze/src/org/lineageos/settings/doze/Utils.java b/doze/src/org/lineageos/settings/doze/Utils.java
index 490095e..e6658f6 100644
--- a/doze/src/org/lineageos/settings/doze/Utils.java
+++ b/doze/src/org/lineageos/settings/doze/Utils.java
@@ -20,6 +20,8 @@ package org.lineageos.settings.doze;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
+import android.os.PowerManager;
+import android.os.SystemClock;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.Log;
@@ -30,6 +32,7 @@ import static android.provider.Settings.Secure.DOZE_ENABLED;
public final class Utils {
+ protected static final String WAKE_ON_GESTURE_KEY = "wake_on_gesture";
protected static final String CATEG_PROX_SENSOR = "proximity_sensor";
protected static final String GESTURE_PICK_UP_KEY = "gesture_pick_up";
protected static final String GESTURE_HAND_WAVE_KEY = "gesture_hand_wave";
@@ -79,10 +82,16 @@ public final class Utils {
DOZE_ENABLED, enable ? 1 : 0);
}
- protected static void launchDozePulse(Context context) {
- if (DEBUG) Log.d(TAG, "Launch doze pulse");
- context.sendBroadcastAsUser(new Intent(DOZE_INTENT),
- new UserHandle(UserHandle.USER_CURRENT));
+ protected static void wakeOrLaunchDozePulse(Context context) {
+ if (isWakeOnGestureEnabled(context)) {
+ if (DEBUG) Log.d(TAG, "Wake up display");
+ PowerManager powerManager = context.getSystemService(PowerManager.class);
+ powerManager.wakeUp(SystemClock.uptimeMillis(), PowerManager.WAKE_REASON_GESTURE, TAG);
+ } else {
+ if (DEBUG) Log.d(TAG, "Launch doze pulse");
+ context.sendBroadcastAsUser(
+ new Intent(DOZE_INTENT), new UserHandle(UserHandle.USER_CURRENT));
+ }
}
protected static boolean isGestureEnabled(Context context, String gesture) {
@@ -90,6 +99,10 @@ public final class Utils {
.getBoolean(gesture, false);
}
+ protected static boolean isWakeOnGestureEnabled(Context context) {
+ return isGestureEnabled(context, WAKE_ON_GESTURE_KEY);
+ }
+
protected static boolean isPickUpEnabled(Context context) {
return isGestureEnabled(context, GESTURE_PICK_UP_KEY);
}