android:summary="@string/ambient_display_always_on_summary"
android:persistent="false" />
+ <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="proximity_sensor"
android:title="@string/proximity_sensor_title">
import android.hardware.SensorManager;
import android.os.IBinder;
import android.os.PowerManager;
+import android.os.SystemClock;
import android.os.UserHandle;
import android.util.Log;
boolean isNear = event.values[0] < mSensor.getMaximumRange();
if (mSawNear && !isNear) {
if (shouldPulse(event.timestamp)) {
- launchDozePulse();
+ wakeOrLaunchDozePulse();
}
} else {
mInPocketTime = event.timestamp;
return null;
}
- private void launchDozePulse() {
- mContext.sendBroadcastAsUser(new Intent(DOZE_INTENT),
- new UserHandle(UserHandle.USER_CURRENT));
+ private void wakeOrLaunchDozePulse() {
+ if (Utils.isWakeOnGestureEnabled(mContext)) {
+ if (DEBUG) Log.d(TAG, "Wake up display");
+ PowerManager powerManager = mContext.getSystemService(PowerManager.class);
+ powerManager.wakeUp(SystemClock.uptimeMillis(), PowerManager.WAKE_REASON_GESTURE, TAG);
+ } else {
+ if (DEBUG) Log.d(TAG, "Launch doze pulse");
+ mContext.sendBroadcastAsUser(
+ new Intent(DOZE_INTENT), new UserHandle(UserHandle.USER_CURRENT));
+ }
}
private boolean isInteractive() {
private SwitchPreference mAlwaysOnDisplayPreference;
private SwitchPreference mHandwavePreference;
private SwitchPreference mPocketPreference;
+ private SwitchPreference mWakeOnGesturePreference;
private Handler mHandler = new Handler();
mPocketPreference.setEnabled(dozeEnabled);
mPocketPreference.setOnPreferenceChangeListener(this);
+ mWakeOnGesturePreference = (SwitchPreference) findPreference(Utils.WAKE_ON_GESTURE_KEY);
+ mWakeOnGesturePreference.setEnabled(dozeEnabled);
+ mWakeOnGesturePreference.setOnPreferenceChangeListener(this);
+
// Hide AOD if not supported and set all its dependents otherwise
if (!Utils.alwaysOnDisplayAvailable(getActivity())) {
getPreferenceScreen().removePreference(mAlwaysOnDisplayPreference);
} else {
mHandwavePreference.setDependency(Utils.ALWAYS_ON_DISPLAY);
mPocketPreference.setDependency(Utils.ALWAYS_ON_DISPLAY);
+ mWakeOnGesturePreference.setDependency(Utils.ALWAYS_ON_DISPLAY);
}
}
mHandwavePreference.setEnabled(isChecked);
mPocketPreference.setEnabled(isChecked);
+ mWakeOnGesturePreference.setEnabled(isChecked);
}
@Override
protected static final String GESTURE_HAND_WAVE_KEY = "gesture_hand_wave";
protected static final String GESTURE_POCKET_KEY = "gesture_pocket";
+ protected static final String WAKE_ON_GESTURE_KEY = "wake_on_gesture";
protected static void startService(Context context) {
if (DEBUG) Log.d(TAG, "Starting service");
return PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(GESTURE_POCKET_KEY, false);
}
+
+ protected static boolean isWakeOnGestureEnabled(Context context) {
+ return PreferenceManager.getDefaultSharedPreferences(context)
+ .getBoolean(WAKE_ON_GESTURE_KEY, false);
+ }
}