samsung: doze: add standard pickup sensor support

fcuzzocrea:

  * adapt original change to be suitable for SamsungDoze

Change-Id: Ie2572fec6d4307ce0b555f6ee4dbf92c9cf7bd87
tirimbino
Michael Bestas 4 years ago committed by Tim Zimmermann
parent f4fa0359d4
commit 79fae21736
No known key found for this signature in database
GPG Key ID: 6DC21A63F819C5EF
  1. 10
      doze/res/xml/gesture_panel.xml
  2. 66
      doze/src/org/lineageos/settings/doze/SamsungDozeService.java
  3. 7
      doze/src/org/lineageos/settings/doze/SamsungDozeSettings.java
  4. 9
      doze/src/org/lineageos/settings/doze/Utils.java

@ -58,4 +58,14 @@
android:summary="@string/pocket_gesture_summary" />
</PreferenceCategory>
<PreferenceCategory
android:key="pickup_sensor"
android:title="@string/pickup_sensor_title">
<SwitchPreference
android:key="gesture_pick_up"
android:defaultValue="false"
android:title="@string/pick_up_gesture_title"
android:summary="@string/pick_up_gesture_summary" />
</PreferenceCategory>
</PreferenceScreen>

@ -25,6 +25,8 @@ import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.hardware.TriggerEvent;
import android.hardware.TriggerEventListener;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.SystemClock;
@ -45,12 +47,52 @@ public class SamsungDozeService extends Service {
private Context mContext;
private ExecutorService mExecutorService;
private SamsungProximitySensor mSensor;
private SamsungProximitySensor mProximitySensor;
private SamsungPickUpSensor mPickUpSensor;
private PowerManager mPowerManager;
private boolean mHandwaveGestureEnabled = false;
private boolean mPickUpGestureEnabled = false;
private boolean mPocketGestureEnabled = false;
class SamsungPickUpSensor {
private SensorManager mSensorManager;
private Sensor mSensor;
private long mEntryTimestamp;
public SamsungPickUpSensor(Context context) {
mSensorManager = mContext.getSystemService(SensorManager.class);
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PICK_UP_GESTURE);
mExecutorService = Executors.newSingleThreadExecutor();
}
private Future<?> submit(Runnable runnable) {
return mExecutorService.submit(runnable);
}
protected void enable() {
submit(() -> {
mSensorManager.requestTriggerSensor(mPickupListener, mSensor);
});
}
protected void disable() {
submit(() -> {
mSensorManager.cancelTriggerSensor(mPickupListener, mSensor);
});
}
private TriggerEventListener mPickupListener = new TriggerEventListener() {
@Override
public void onTrigger(TriggerEvent event) {
if (DEBUG) Log.d(TAG, "Triggered");
wakeOrLaunchDozePulse();
enable();
}
};
}
class SamsungProximitySensor implements SensorEventListener {
private SensorManager mSensorManager;
private Sensor mSensor;
@ -121,9 +163,11 @@ public class SamsungDozeService extends Service {
if (DEBUG) Log.d(TAG, "SamsungDozeService Started");
mContext = this;
mPowerManager = getSystemService(PowerManager.class);
mSensor = new SamsungProximitySensor(mContext);
mProximitySensor = new SamsungProximitySensor(mContext);
mPickUpSensor = new SamsungPickUpSensor(mContext);
if (!isInteractive()) {
mSensor.enable();
mProximitySensor.enable();
mPickUpSensor.enable();
}
}
@ -159,12 +203,24 @@ public class SamsungDozeService extends Service {
private void onDisplayOn() {
if (DEBUG) Log.d(TAG, "Display on");
mSensor.disable();
if (Utils.isPickUpGestureEnabled(this)) {
mPickUpSensor.disable();
}
if (Utils.isHandwaveGestureEnabled(this) ||
Utils.isPocketGestureEnabled(this)) {
mProximitySensor.disable();
}
}
private void onDisplayOff() {
if (DEBUG) Log.d(TAG, "Display off");
mSensor.enable();
if (Utils.isPickUpGestureEnabled(this)) {
mPickUpSensor.enable();
}
if (Utils.isHandwaveGestureEnabled(this) ||
Utils.isPocketGestureEnabled(this)) {
mProximitySensor.enable();
}
}
private BroadcastReceiver mScreenStateReceiver = new BroadcastReceiver() {

@ -38,6 +38,7 @@ public class SamsungDozeSettings extends PreferenceFragment
private SwitchPreference mAlwaysOnDisplayPreference;
private SwitchPreference mHandwavePreference;
private SwitchPreference mPickUpPreference;
private SwitchPreference mPocketPreference;
private SwitchPreference mWakeOnGesturePreference;
@ -62,6 +63,10 @@ public class SamsungDozeSettings extends PreferenceFragment
mHandwavePreference.setEnabled(dozeEnabled);
mHandwavePreference.setOnPreferenceChangeListener(this);
mPickUpPreference = findPreference(Utils.GESTURE_PICK_UP_KEY);
mPickUpPreference.setEnabled(dozeEnabled);
mPickUpPreference.setOnPreferenceChangeListener(this);
mPocketPreference = findPreference(Utils.GESTURE_POCKET_KEY);
mPocketPreference.setEnabled(dozeEnabled);
mPocketPreference.setOnPreferenceChangeListener(this);
@ -75,6 +80,7 @@ public class SamsungDozeSettings extends PreferenceFragment
getPreferenceScreen().removePreference(mAlwaysOnDisplayPreference);
} else {
mHandwavePreference.setDependency(Utils.ALWAYS_ON_DISPLAY);
mPickUpPreference.setDependency(Utils.ALWAYS_ON_DISPLAY);
mPocketPreference.setDependency(Utils.ALWAYS_ON_DISPLAY);
mWakeOnGesturePreference.setDependency(Utils.ALWAYS_ON_DISPLAY);
}
@ -115,6 +121,7 @@ public class SamsungDozeSettings extends PreferenceFragment
mAlwaysOnDisplayPreference.setEnabled(isChecked);
mHandwavePreference.setEnabled(isChecked);
mPickUpPreference.setEnabled(isChecked);
mPocketPreference.setEnabled(isChecked);
mWakeOnGesturePreference.setEnabled(isChecked);
}

@ -37,6 +37,7 @@ public final class Utils {
protected static final String ALWAYS_ON_DISPLAY = "always_on_display";
protected static final String DOZE_ENABLE = "doze_enable";
protected static final String GESTURE_HAND_WAVE_KEY = "gesture_hand_wave";
protected static final String GESTURE_PICK_UP_KEY = "gesture_pick_up";
protected static final String GESTURE_POCKET_KEY = "gesture_pocket";
protected static final String WAKE_ON_GESTURE_KEY = "wake_on_gesture";
@ -90,7 +91,8 @@ public final class Utils {
}
protected static boolean isAnyGestureEnabled(Context context) {
return isHandwaveGestureEnabled(context) || isPocketGestureEnabled(context);
return isHandwaveGestureEnabled(context) || isPickUpGestureEnabled(context) ||
isPocketGestureEnabled(context);
}
protected static boolean isHandwaveGestureEnabled(Context context) {
@ -98,6 +100,11 @@ public final class Utils {
.getBoolean(GESTURE_HAND_WAVE_KEY, false);
}
protected static boolean isPickUpGestureEnabled(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(GESTURE_PICK_UP_KEY, false);
}
protected static boolean isPocketGestureEnabled(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(GESTURE_POCKET_KEY, false);

Loading…
Cancel
Save