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;
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;
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();
}
}
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() {
private SwitchPreference mAlwaysOnDisplayPreference;
private SwitchPreference mHandwavePreference;
+ private SwitchPreference mPickUpPreference;
private SwitchPreference mPocketPreference;
private SwitchPreference mWakeOnGesturePreference;
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);
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);
}
mAlwaysOnDisplayPreference.setEnabled(isChecked);
mHandwavePreference.setEnabled(isChecked);
+ mPickUpPreference.setEnabled(isChecked);
mPocketPreference.setEnabled(isChecked);
mWakeOnGesturePreference.setEnabled(isChecked);
}
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";
}
protected static boolean isAnyGestureEnabled(Context context) {
- return isHandwaveGestureEnabled(context) || isPocketGestureEnabled(context);
+ return isHandwaveGestureEnabled(context) || isPickUpGestureEnabled(context) ||
+ isPocketGestureEnabled(context);
}
protected static boolean isHandwaveGestureEnabled(Context context) {
.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);