davinci: parts: Allow to wake the screen instead of pulsing

Co-authored-by: Nauval Rizky <enuma.alrizky@gmail.com>
Co-authored-by: Fabian Leutenegger <fabian.leutenegger@bluewin.ch>
Change-Id: I1e74f8eafa51843e77d2d8c514c646a4494327cd
This commit is contained in:
Arian 2020-10-14 23:06:47 +02:00
parent fed308cae8
commit 1db9129db8
No known key found for this signature in database
GPG Key ID: 48029380598CE3B9
6 changed files with 42 additions and 10 deletions

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:tint="?android:attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M7,1A2,2 0 0,0 5,3V21A2,2 0 0,0 7,23H17A2,2 0 0,0 19,21V3A2,2 0 0,0 17,1H7M7,4H17V20H7V4M9,6V10H10.5V7.5H13V6H9M13.5,14V16.5H11V18H15V14H13.5Z" />
</vector>

View File

@ -25,6 +25,13 @@
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:icon="@drawable/ic_doze_wake"
android:title="@string/wake_on_gesture_title"
android:summary="@string/wake_on_gesture_summary" />
<PreferenceCategory <PreferenceCategory
android:key="pickup_sensor" android:key="pickup_sensor"
android:title="@string/pickup_sensor_title"> android:title="@string/pickup_sensor_title">

View File

@ -48,7 +48,7 @@ public class DozeSettingsFragment extends PreferenceFragment
private View mSwitchBar; private View mSwitchBar;
private SwitchPreference mAlwaysOnDisplayPreference; private SwitchPreference mAlwaysOnDisplayPreference;
private SwitchPreference mWakeOnGesturePreference;
private SwitchPreference mPickUpPreference; private SwitchPreference mPickUpPreference;
private SwitchPreference mHandwavePreference; private SwitchPreference mHandwavePreference;
private SwitchPreference mPocketPreference; private SwitchPreference mPocketPreference;
@ -74,6 +74,10 @@ public class DozeSettingsFragment extends PreferenceFragment
mAlwaysOnDisplayPreference.setChecked(DozeUtils.isAlwaysOnEnabled(getActivity())); mAlwaysOnDisplayPreference.setChecked(DozeUtils.isAlwaysOnEnabled(getActivity()));
mAlwaysOnDisplayPreference.setOnPreferenceChangeListener(this); mAlwaysOnDisplayPreference.setOnPreferenceChangeListener(this);
mWakeOnGesturePreference = (SwitchPreference) findPreference(DozeUtils.WAKE_ON_GESTURE_KEY);
mWakeOnGesturePreference.setEnabled(dozeEnabled);
mWakeOnGesturePreference.setOnPreferenceChangeListener(this);
PreferenceCategory pickupSensorCategory = PreferenceCategory pickupSensorCategory =
(PreferenceCategory) getPreferenceScreen().findPreference( (PreferenceCategory) getPreferenceScreen().findPreference(
DozeUtils.CATEG_PICKUP_SENSOR); DozeUtils.CATEG_PICKUP_SENSOR);
@ -102,6 +106,7 @@ public class DozeSettingsFragment extends PreferenceFragment
if (!DozeUtils.alwaysOnDisplayAvailable(getActivity())) { if (!DozeUtils.alwaysOnDisplayAvailable(getActivity())) {
getPreferenceScreen().removePreference(mAlwaysOnDisplayPreference); getPreferenceScreen().removePreference(mAlwaysOnDisplayPreference);
} else { } else {
mWakeOnGesturePreference.setDependency(DozeUtils.ALWAYS_ON_DISPLAY);
pickupSensorCategory.setDependency(DozeUtils.ALWAYS_ON_DISPLAY); pickupSensorCategory.setDependency(DozeUtils.ALWAYS_ON_DISPLAY);
proximitySensorCategory.setDependency(DozeUtils.ALWAYS_ON_DISPLAY); proximitySensorCategory.setDependency(DozeUtils.ALWAYS_ON_DISPLAY);
} }
@ -161,7 +166,7 @@ public class DozeSettingsFragment extends PreferenceFragment
mAlwaysOnDisplayPreference.setChecked(false); mAlwaysOnDisplayPreference.setChecked(false);
} }
mAlwaysOnDisplayPreference.setEnabled(isChecked); mAlwaysOnDisplayPreference.setEnabled(isChecked);
mWakeOnGesturePreference.setEnabled(isChecked);
mPickUpPreference.setEnabled(isChecked); mPickUpPreference.setEnabled(isChecked);
mHandwavePreference.setEnabled(isChecked); mHandwavePreference.setEnabled(isChecked);
mPocketPreference.setEnabled(isChecked); mPocketPreference.setEnabled(isChecked);

View File

@ -23,6 +23,8 @@ import android.content.pm.PackageManager;
import android.hardware.display.AmbientDisplayConfiguration; import android.hardware.display.AmbientDisplayConfiguration;
import android.hardware.Sensor; import android.hardware.Sensor;
import android.hardware.SensorManager; import android.hardware.SensorManager;
import android.os.PowerManager;
import android.os.SystemClock;
import android.os.UserHandle; import android.os.UserHandle;
import android.provider.Settings; import android.provider.Settings;
import android.util.Log; import android.util.Log;
@ -38,7 +40,7 @@ public final class DozeUtils {
private static final String DOZE_INTENT = "com.android.systemui.doze.pulse"; private static final String DOZE_INTENT = "com.android.systemui.doze.pulse";
protected static final String ALWAYS_ON_DISPLAY = "always_on_display"; protected static final String ALWAYS_ON_DISPLAY = "always_on_display";
protected static final String WAKE_ON_GESTURE_KEY = "wake_on_gesture";
protected static final String CATEG_PICKUP_SENSOR = "pickup_sensor"; protected static final String CATEG_PICKUP_SENSOR = "pickup_sensor";
protected static final String CATEG_PROX_SENSOR = "proximity_sensor"; protected static final String CATEG_PROX_SENSOR = "proximity_sensor";
@ -85,11 +87,16 @@ public final class DozeUtils {
return Settings.Secure.getInt(context.getContentResolver(), DOZE_ENABLED, 1) != 0; return Settings.Secure.getInt(context.getContentResolver(), DOZE_ENABLED, 1) != 0;
} }
protected static void launchDozePulse(Context context) { protected static void wakeOrLaunchDozePulse(Context context) {
if (DEBUG) if (isWakeOnGestureEnabled(context)) {
Log.d(TAG, "Launch doze pulse"); if (DEBUG) Log.d(TAG, "Wake up display");
context.sendBroadcastAsUser( PowerManager powerManager = context.getSystemService(PowerManager.class);
new Intent(DOZE_INTENT), new UserHandle(UserHandle.USER_CURRENT)); 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 enableAlwaysOn(Context context, boolean enable) { protected static boolean enableAlwaysOn(Context context, boolean enable) {
@ -115,6 +122,10 @@ public final class DozeUtils {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(gesture, false); return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(gesture, false);
} }
protected static boolean isWakeOnGestureEnabled(Context context) {
return isGestureEnabled(context, WAKE_ON_GESTURE_KEY);
}
protected static boolean isPickUpEnabled(Context context) { protected static boolean isPickUpEnabled(Context context) {
return isGestureEnabled(context, GESTURE_PICK_UP_KEY); return isGestureEnabled(context, GESTURE_PICK_UP_KEY);
} }

View File

@ -64,7 +64,7 @@ public class PickupSensor implements SensorEventListener {
mEntryTimestamp = SystemClock.elapsedRealtime(); mEntryTimestamp = SystemClock.elapsedRealtime();
if (event.values[0] == 1) { if (event.values[0] == 1) {
DozeUtils.launchDozePulse(mContext); DozeUtils.wakeOrLaunchDozePulse(mContext);
} }
} }

View File

@ -60,7 +60,7 @@ public class ProximitySensor implements SensorEventListener {
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)) {
DozeUtils.launchDozePulse(mContext); DozeUtils.wakeOrLaunchDozePulse(mContext);
} }
} else { } else {
mInPocketTime = event.timestamp; mInPocketTime = event.timestamp;