sm8150-common: doze: Introduce raise to wake gesture
* Highly inspired by iOS raise to wake - Adapted to OnePlus sm8150 doze sm8150-common: doze: Add min interval for raise2wake * avoid having early wakeup * also fix typo in acquire timeout sm8150-common: doze: Enable pickup when raise to wake is toggled - This is needed in order for raise to wake to function properly. sm8150-common: doze: Fix pickup status for raise to wake Co-authored-by: AnierinB <anierinb@evolution-x.org> Co-authored-by: AshutoshSundresh <ashutoshsundresh@gmail.com> Co-authored-by: LuK1337 <priv.luk@gmail.com> Signed-off-by: AnierinB <anierinb@evolution-x.org> Signed-off-by: Omkar Chandorkar <gotenksIN@aosip.dev> Signed-off-by: LuK1337 <priv.luk@gmail.com> Change-Id: I5df0c4f11f1b24ab813abc393960c5f03f5fab1f
This commit is contained in:
parent
5d947faf83
commit
776063454f
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2021 The LineageOS Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<resources>
|
||||
<!-- Pickup gesture -->
|
||||
<string-array name="pick_up_gesture_entries" translatable="false">
|
||||
<item>@string/disabled</item>
|
||||
<item>@string/pick_up_gesture_summary</item>
|
||||
<item>@string/pick_up_wake_gesture_summary</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pick_up_gesture_values" translatable="false">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
</string-array>
|
||||
</resources>
|
|
@ -28,12 +28,14 @@
|
|||
android:key="pickup_sensor"
|
||||
android:title="@string/pickup_sensor_title">
|
||||
|
||||
<SwitchPreference
|
||||
android:key="gesture_pick_up"
|
||||
android:defaultValue="false"
|
||||
<ListPreference
|
||||
android:key="gesture_pick_up_type"
|
||||
android:defaultValue="0"
|
||||
android:icon="@drawable/ic_pickup"
|
||||
android:title="@string/pick_up_gesture_title"
|
||||
android:summary="@string/pick_up_gesture_summary" />
|
||||
android:summary="%s"
|
||||
android:entries="@array/pick_up_gesture_entries"
|
||||
android:entryValues="@array/pick_up_gesture_values" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ import android.view.ViewGroup;
|
|||
import android.widget.CompoundButton;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
|
@ -48,7 +49,7 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
|
|||
|
||||
private SwitchPreference mAlwaysOnDisplayPreference;
|
||||
|
||||
private SwitchPreference mPickUpPreference;
|
||||
private ListPreference mPickUpPreference;
|
||||
|
||||
private Handler mHandler = new Handler();
|
||||
|
||||
|
@ -74,7 +75,7 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
|
|||
PreferenceCategory pickupSensorCategory = (PreferenceCategory) getPreferenceScreen().
|
||||
findPreference(Utils.CATEG_PICKUP_SENSOR);
|
||||
|
||||
mPickUpPreference = (SwitchPreference) findPreference(Utils.GESTURE_PICK_UP_KEY);
|
||||
mPickUpPreference = (ListPreference) findPreference(Utils.GESTURE_PICK_UP_KEY);
|
||||
mPickUpPreference.setEnabled(dozeEnabled);
|
||||
mPickUpPreference.setOnPreferenceChangeListener(this);
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@ import android.hardware.Sensor;
|
|||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.os.PowerManager;
|
||||
import android.os.PowerManager.WakeLock;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
|
||||
|
@ -35,9 +37,13 @@ public class PickupSensor implements SensorEventListener {
|
|||
private static final String TAG = "PickupSensor";
|
||||
|
||||
private static final int MIN_PULSE_INTERVAL_MS = 2500;
|
||||
private static final int MIN_WAKEUP_INTERVAL_MS = 1000;
|
||||
private static final int WAKELOCK_TIMEOUT_MS = 300;
|
||||
|
||||
private PowerManager mPowerManager;
|
||||
private SensorManager mSensorManager;
|
||||
private Sensor mSensor;
|
||||
private WakeLock mWakeLock;
|
||||
private Context mContext;
|
||||
private ExecutorService mExecutorService;
|
||||
|
||||
|
@ -45,8 +51,10 @@ public class PickupSensor implements SensorEventListener {
|
|||
|
||||
public PickupSensor(Context context) {
|
||||
mContext = context;
|
||||
mPowerManager = mContext.getSystemService(PowerManager.class);
|
||||
mSensorManager = mContext.getSystemService(SensorManager.class);
|
||||
mSensor = Utils.getSensor(mSensorManager, "oneplus.sensor.op_motion_detect");
|
||||
mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
|
||||
mExecutorService = Executors.newSingleThreadExecutor();
|
||||
}
|
||||
|
||||
|
@ -66,7 +74,13 @@ public class PickupSensor implements SensorEventListener {
|
|||
mEntryTimestamp = SystemClock.elapsedRealtime();
|
||||
|
||||
if (event.values[0] == 1) {
|
||||
Utils.launchDozePulse(mContext);
|
||||
if (Utils.isPickUpSetToWake(mContext)) {
|
||||
mWakeLock.acquire(WAKELOCK_TIMEOUT_MS);
|
||||
mPowerManager.wakeUp(SystemClock.uptimeMillis(),
|
||||
PowerManager.WAKE_REASON_GESTURE, TAG);
|
||||
} else {
|
||||
Utils.launchDozePulse(mContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ public final class Utils {
|
|||
|
||||
protected static final String CATEG_PICKUP_SENSOR = "pickup_sensor";
|
||||
|
||||
protected static final String GESTURE_PICK_UP_KEY = "gesture_pick_up";
|
||||
protected static final String GESTURE_PICK_UP_KEY = "gesture_pick_up_type";
|
||||
|
||||
protected static void startService(Context context) {
|
||||
if (DEBUG) Log.d(TAG, "Starting service");
|
||||
|
@ -93,13 +93,14 @@ public final class Utils {
|
|||
return new AmbientDisplayConfiguration(context).alwaysOnAvailable();
|
||||
}
|
||||
|
||||
protected static boolean isGestureEnabled(Context context, String gesture) {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getBoolean(gesture, false);
|
||||
protected static boolean isPickUpEnabled(Context context) {
|
||||
return !PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getString(GESTURE_PICK_UP_KEY, "0").equals("0");
|
||||
}
|
||||
|
||||
protected static boolean isPickUpEnabled(Context context) {
|
||||
return isGestureEnabled(context, GESTURE_PICK_UP_KEY);
|
||||
protected static boolean isPickUpSetToWake(Context context) {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getString(GESTURE_PICK_UP_KEY, "0").equals("2");
|
||||
}
|
||||
|
||||
public static boolean areGesturesEnabled(Context context) {
|
||||
|
|
Loading…
Reference in New Issue