samsung: doze: Rebrand from cyanogenmod to lineageos
authorArne Coucheron <arco68@gmail.com>
Sat, 14 Oct 2017 06:21:29 +0000 (08:21 +0200)
committerJan Altensen <info@stricted.net>
Fri, 20 Mar 2020 13:56:41 +0000 (14:56 +0100)
Change-Id: I619080f46a69a80fe3923cb3df6a676242f36eac

12 files changed:
doze/Android.mk
doze/AndroidManifest.xml
doze/proguard.flags
doze/res/xml/gesture_panel.xml
doze/src/com/cyanogenmod/settings/device/BootCompletedReceiver.java [deleted file]
doze/src/com/cyanogenmod/settings/device/SamsungDozeActivity.java [deleted file]
doze/src/com/cyanogenmod/settings/device/SamsungDozeService.java [deleted file]
doze/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java [deleted file]
doze/src/org/lineageos/settings/device/BootCompletedReceiver.java [new file with mode: 0644]
doze/src/org/lineageos/settings/device/SamsungDozeActivity.java [new file with mode: 0644]
doze/src/org/lineageos/settings/device/SamsungDozeService.java [new file with mode: 0644]
doze/src/org/lineageos/settings/device/TouchscreenGestureSettings.java [new file with mode: 0644]

index 687b0310d7c454dfa06496f332a18e801292f935..a153362476b77f205bf3a1884eb5519eb9e5c665 100644 (file)
@@ -14,7 +14,7 @@ LOCAL_STATIC_JAVA_LIBRARIES := \
     android-support-v7-appcompat \
     android-support-v7-preference \
     android-support-v7-recyclerview \
-    org.cyanogenmod.platform.internal
+    org.lineageos.platform.internal
 
 LOCAL_PROGUARD_FLAG_FILES := proguard.flags
 
index f9cbcec02665a4f1906721cb41951411823e1d46..e8ad9dec6b50423c218c6f948a9ffa1ff976b01c 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="com.cyanogenmod.settings.device"
+    package="org.lineageos.settings.device"
     android:versionCode="1"
     android:versionName="1.0"
     android:sharedUserId="android.uid.system">
         android:label="@string/device_settings_app_name"
         android:persistent="true">
 
-        <receiver android:name="com.cyanogenmod.settings.device.BootCompletedReceiver">
+        <receiver android:name="org.lineageos.settings.device.BootCompletedReceiver">
             <intent-filter>
                 <action android:name="android.intent.action.BOOT_COMPLETED" />
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
         </receiver>
 
-        <service android:name="com.cyanogenmod.settings.device.SamsungDozeService"
+        <service android:name="org.lingeageos.settings.device.SamsungDozeService"
                  android:permission="SamsungDozeService">
         </service>
 
@@ -36,7 +36,7 @@
             android:label="@string/ambient_display_title"
             android:theme="@style/SamsungDozeSettings">
             <intent-filter>
-                <action android:name="org.cyanogenmod.settings.device.DOZE_SETTINGS" />
+                <action android:name="org.lineageos.settings.device.DOZE_SETTINGS" />
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
         </activity>
index 0a629417fe5045e511e4bd55161f781ca2efb291..ca04a2199d43e99b99c3575309d3058b88acb598 100644 (file)
@@ -1,4 +1,4 @@
--keep class com.cyanogenmod.settings.device.* {
+-keep class org.lineageos.settings.device.* {
   *;
 }
 
index 47ff26e392fec2af0960bc1ac983ab34db45b518..1a063d168a58039d774843dc48c4e2b68e3ba36b 100644 (file)
@@ -20,7 +20,7 @@
         android:key="ambient_display_key"
         android:title="@string/ambient_display_title">
 
-        <cyanogenmod.preference.SecureSettingSwitchPreference
+        <lineageos.preference.SecureSettingSwitchPreference
             android:key="doze_enabled"
             android:defaultValue="true"
             android:title="@string/ambient_display_enable_title"
diff --git a/doze/src/com/cyanogenmod/settings/device/BootCompletedReceiver.java b/doze/src/com/cyanogenmod/settings/device/BootCompletedReceiver.java
deleted file mode 100644 (file)
index 9fe615e..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 2015 The CyanogenMod 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.
- */
-
-package com.cyanogenmod.settings.device;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.util.Log;
-
-public class BootCompletedReceiver extends BroadcastReceiver {
-
-    private static final boolean DEBUG = false;
-    private static final String TAG = "SamsungDoze";
-
-    @Override
-    public void onReceive(final Context context, Intent intent) {
-        if (DEBUG) Log.d(TAG, "Starting service");
-        context.startService(new Intent(context, SamsungDozeService.class));
-    }
-
-}
diff --git a/doze/src/com/cyanogenmod/settings/device/SamsungDozeActivity.java b/doze/src/com/cyanogenmod/settings/device/SamsungDozeActivity.java
deleted file mode 100644 (file)
index 229ceef..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2016 The CyanogenMod 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.
- */
-package com.cyanogenmod.settings.device;
-
-import android.app.Fragment;
-import android.app.FragmentTransaction;
-import android.os.Bundle;
-import android.view.MenuItem;
-
-import com.android.settingslib.drawer.SettingsDrawerActivity;
-
-public class SamsungDozeActivity extends SettingsDrawerActivity {
-
-    private static final String TAG = "samsung_doze";
-
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-
-        getFragmentManager().beginTransaction().replace(R.id.content_frame,
-                new TouchscreenGestureSettings(), TAG).commit();
-
-        getActionBar().setDisplayHomeAsUpEnabled(true);
-    }
-
-    @Override
-    public boolean onOptionsItemSelected(MenuItem item) {
-        if (item.getItemId() == android.R.id.home) {
-            onBackPressed();
-            return true;
-        }
-        return false;
-    }
-}
diff --git a/doze/src/com/cyanogenmod/settings/device/SamsungDozeService.java b/doze/src/com/cyanogenmod/settings/device/SamsungDozeService.java
deleted file mode 100644 (file)
index b748a71..0000000
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * Copyright (c) 2015 The CyanogenMod 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.
- */
-
-package com.cyanogenmod.settings.device;
-
-import android.app.Service;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.SharedPreferences;
-import android.hardware.Sensor;
-import android.hardware.SensorEvent;
-import android.hardware.SensorEventListener;
-import android.hardware.SensorManager;
-import android.os.IBinder;
-import android.os.PowerManager;
-import android.os.UserHandle;
-import android.preference.PreferenceManager;
-import android.provider.Settings;
-import android.util.Log;
-
-import java.lang.System;
-import java.util.ArrayList;
-import java.util.concurrent.TimeUnit;
-import java.util.List;
-
-public class SamsungDozeService extends Service {
-    private static final String TAG = "SamsungDozeService";
-    private static final boolean DEBUG = false;
-
-    private static final String DOZE_INTENT = "com.android.systemui.doze.pulse";
-
-    private static final String GESTURE_HAND_WAVE_KEY = "gesture_hand_wave";
-    private static final String GESTURE_POCKET_KEY = "gesture_pocket";
-    private static final String PROXIMITY_WAKE_KEY = "proximity_wake_enable";
-
-    private static final int POCKET_DELTA_NS = 1000 * 1000 * 1000;
-
-    private Context mContext;
-    private SamsungProximitySensor mSensor;
-    private PowerManager mPowerManager;
-
-    private boolean mHandwaveGestureEnabled = false;
-    private boolean mPocketGestureEnabled = false;
-    private boolean mProximityWakeEnabled = false;
-
-    class SamsungProximitySensor implements SensorEventListener {
-        private SensorManager mSensorManager;
-        private Sensor mSensor;
-
-        private boolean mSawNear = false;
-        private long mInPocketTime = 0;
-
-        public SamsungProximitySensor(Context context) {
-            mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
-            mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
-        }
-
-        @Override
-        public void onSensorChanged(SensorEvent event) {
-            boolean isNear = event.values[0] < mSensor.getMaximumRange();
-            if (mSawNear && !isNear) {
-                if (shouldPulse(event.timestamp)) {
-                    launchDozePulse();
-                }
-            } else {
-                mInPocketTime = event.timestamp;
-            }
-            mSawNear = isNear;
-        }
-
-        @Override
-        public void onAccuracyChanged(Sensor sensor, int accuracy) {
-            /* Empty */
-        }
-
-        private boolean shouldPulse(long timestamp) {
-            long delta = timestamp - mInPocketTime;
-
-            if (mHandwaveGestureEnabled && mPocketGestureEnabled) {
-                return true;
-            } else if (mProximityWakeEnabled && (delta < POCKET_DELTA_NS)) {
-                mPowerManager.wakeUp(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()));
-                return false;
-            } else if (mHandwaveGestureEnabled && !mPocketGestureEnabled) {
-                return delta < POCKET_DELTA_NS;
-            } else if (!mHandwaveGestureEnabled && mPocketGestureEnabled) {
-                return delta >= POCKET_DELTA_NS;
-            }
-            return false;
-        }
-
-        public void testAndEnable() {
-            if ((isDozeEnabled() && (mHandwaveGestureEnabled || mPocketGestureEnabled)) ||
-                    mProximityWakeEnabled) {
-                mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
-            }
-        }
-
-        public void disable() {
-            mSensorManager.unregisterListener(this, mSensor);
-        }
-    }
-
-    @Override
-    public void onCreate() {
-        if (DEBUG) Log.d(TAG, "SamsungDozeService Started");
-        mContext = this;
-        mPowerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
-        mSensor = new SamsungProximitySensor(mContext);
-        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
-        loadPreferences(sharedPrefs);
-        sharedPrefs.registerOnSharedPreferenceChangeListener(mPrefListener);
-        if (!isInteractive()) {
-            mSensor.testAndEnable();
-        }
-    }
-
-    @Override
-    public int onStartCommand(Intent intent, int flags, int startId) {
-        if (DEBUG) Log.d(TAG, "Starting service");
-        IntentFilter screenStateFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
-        screenStateFilter.addAction(Intent.ACTION_SCREEN_OFF);
-        mContext.registerReceiver(mScreenStateReceiver, screenStateFilter);
-        return START_STICKY;
-    }
-
-    @Override
-    public IBinder onBind(Intent intent) {
-        return null;
-    }
-
-    private void launchDozePulse() {
-        mContext.sendBroadcastAsUser(new Intent(DOZE_INTENT),
-                new UserHandle(UserHandle.USER_CURRENT));
-    }
-
-    private boolean isInteractive() {
-        return mPowerManager.isInteractive();
-    }
-
-    private boolean isDozeEnabled() {
-        return Settings.Secure.getInt(mContext.getContentResolver(),
-                Settings.Secure.DOZE_ENABLED, 1) != 0;
-    }
-
-    private void onDisplayOn() {
-        if (DEBUG) Log.d(TAG, "Display on");
-        mSensor.disable();
-    }
-
-    private void onDisplayOff() {
-        if (DEBUG) Log.d(TAG, "Display off");
-        mSensor.testAndEnable();
-    }
-
-    private void loadPreferences(SharedPreferences sharedPreferences) {
-        mHandwaveGestureEnabled = sharedPreferences.getBoolean(GESTURE_HAND_WAVE_KEY, false);
-        mPocketGestureEnabled = sharedPreferences.getBoolean(GESTURE_POCKET_KEY, false);
-        mProximityWakeEnabled = sharedPreferences.getBoolean(PROXIMITY_WAKE_KEY, false);
-    }
-
-    private BroadcastReceiver mScreenStateReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
-                onDisplayOff();
-            } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
-                onDisplayOn();
-            }
-        }
-    };
-
-    private SharedPreferences.OnSharedPreferenceChangeListener mPrefListener =
-            new SharedPreferences.OnSharedPreferenceChangeListener() {
-        @Override
-        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
-            if (GESTURE_HAND_WAVE_KEY.equals(key)) {
-                mHandwaveGestureEnabled = sharedPreferences.getBoolean(GESTURE_HAND_WAVE_KEY, false);
-            } else if (GESTURE_POCKET_KEY.equals(key)) {
-                mPocketGestureEnabled = sharedPreferences.getBoolean(GESTURE_POCKET_KEY, false);
-            } else if (PROXIMITY_WAKE_KEY.equals(key)) {
-                mProximityWakeEnabled = sharedPreferences.getBoolean(PROXIMITY_WAKE_KEY, false);
-            }
-        }
-    };
-}
diff --git a/doze/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java b/doze/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java
deleted file mode 100644 (file)
index 9256afe..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2015 The CyanogenMod 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.
- */
-
-package com.cyanogenmod.settings.device;
-
-import android.os.Bundle;
-import android.support.v14.preference.PreferenceFragment;
-import android.support.v14.preference.SwitchPreference;
-import android.support.v7.preference.Preference;
-import android.provider.Settings;
-
-import org.cyanogenmod.internal.util.ScreenType;
-
-public class TouchscreenGestureSettings extends PreferenceFragment {
-
-    private static final String KEY_HAND_WAVE = "gesture_hand_wave";
-    private static final String KEY_PROXIMITY_WAKE = "proximity_wake_enable";
-
-    private SwitchPreference mHandwavePreference;
-    private SwitchPreference mProximityWakePreference;
-
-    @Override
-    public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
-        addPreferencesFromResource(R.xml.gesture_panel);
-
-        mHandwavePreference =
-            (SwitchPreference) findPreference(KEY_HAND_WAVE);
-        mHandwavePreference.setOnPreferenceChangeListener(mProximityListener);
-        mProximityWakePreference =
-            (SwitchPreference) findPreference(KEY_PROXIMITY_WAKE);
-        mProximityWakePreference.setOnPreferenceChangeListener(mProximityListener);
-    }
-
-    @Override
-    public void onResume() {
-        super.onResume();
-
-        // If running on a phone, remove padding around the listview
-        if (!ScreenType.isTablet(getContext())) {
-            getListView().setPadding(0, 0, 0, 0);
-        }
-    }
-
-    private Preference.OnPreferenceChangeListener mProximityListener =
-        new Preference.OnPreferenceChangeListener() {
-        @Override
-        public boolean onPreferenceChange(Preference preference, Object newValue) {
-            if ((boolean) newValue) {
-                if (preference.getKey().equals(KEY_HAND_WAVE)) {
-                    mProximityWakePreference.setChecked(false);
-                } else if (preference.getKey().equals(KEY_PROXIMITY_WAKE)) {
-                    mHandwavePreference.setChecked(false);
-                }
-            }
-            return true;
-        }
-    };
-}
diff --git a/doze/src/org/lineageos/settings/device/BootCompletedReceiver.java b/doze/src/org/lineageos/settings/device/BootCompletedReceiver.java
new file mode 100644 (file)
index 0000000..fa8de8e
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2015 The CyanogenMod 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.
+ */
+
+package org.lineageos.settings.device;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+
+public class BootCompletedReceiver extends BroadcastReceiver {
+
+    private static final boolean DEBUG = false;
+    private static final String TAG = "SamsungDoze";
+
+    @Override
+    public void onReceive(final Context context, Intent intent) {
+        if (DEBUG) Log.d(TAG, "Starting service");
+        context.startService(new Intent(context, SamsungDozeService.class));
+    }
+
+}
diff --git a/doze/src/org/lineageos/settings/device/SamsungDozeActivity.java b/doze/src/org/lineageos/settings/device/SamsungDozeActivity.java
new file mode 100644 (file)
index 0000000..7ea9853
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2016 The CyanogenMod 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.
+ */
+package org.lineageos.settings.device;
+
+import android.app.Fragment;
+import android.app.FragmentTransaction;
+import android.os.Bundle;
+import android.view.MenuItem;
+
+import com.android.settingslib.drawer.SettingsDrawerActivity;
+
+public class SamsungDozeActivity extends SettingsDrawerActivity {
+
+    private static final String TAG = "samsung_doze";
+
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        getFragmentManager().beginTransaction().replace(R.id.content_frame,
+                new TouchscreenGestureSettings(), TAG).commit();
+
+        getActionBar().setDisplayHomeAsUpEnabled(true);
+    }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        if (item.getItemId() == android.R.id.home) {
+            onBackPressed();
+            return true;
+        }
+        return false;
+    }
+}
diff --git a/doze/src/org/lineageos/settings/device/SamsungDozeService.java b/doze/src/org/lineageos/settings/device/SamsungDozeService.java
new file mode 100644 (file)
index 0000000..fc3f2d0
--- /dev/null
@@ -0,0 +1,201 @@
+/*
+ * Copyright (c) 2015 The CyanogenMod 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.
+ */
+
+package org.lineageos.settings.device;
+
+import android.app.Service;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.SharedPreferences;
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.hardware.SensorManager;
+import android.os.IBinder;
+import android.os.PowerManager;
+import android.os.UserHandle;
+import android.preference.PreferenceManager;
+import android.provider.Settings;
+import android.util.Log;
+
+import java.lang.System;
+import java.util.ArrayList;
+import java.util.concurrent.TimeUnit;
+import java.util.List;
+
+public class SamsungDozeService extends Service {
+    private static final String TAG = "SamsungDozeService";
+    private static final boolean DEBUG = false;
+
+    private static final String DOZE_INTENT = "com.android.systemui.doze.pulse";
+
+    private static final String GESTURE_HAND_WAVE_KEY = "gesture_hand_wave";
+    private static final String GESTURE_POCKET_KEY = "gesture_pocket";
+    private static final String PROXIMITY_WAKE_KEY = "proximity_wake_enable";
+
+    private static final int POCKET_DELTA_NS = 1000 * 1000 * 1000;
+
+    private Context mContext;
+    private SamsungProximitySensor mSensor;
+    private PowerManager mPowerManager;
+
+    private boolean mHandwaveGestureEnabled = false;
+    private boolean mPocketGestureEnabled = false;
+    private boolean mProximityWakeEnabled = false;
+
+    class SamsungProximitySensor implements SensorEventListener {
+        private SensorManager mSensorManager;
+        private Sensor mSensor;
+
+        private boolean mSawNear = false;
+        private long mInPocketTime = 0;
+
+        public SamsungProximitySensor(Context context) {
+            mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
+            mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
+        }
+
+        @Override
+        public void onSensorChanged(SensorEvent event) {
+            boolean isNear = event.values[0] < mSensor.getMaximumRange();
+            if (mSawNear && !isNear) {
+                if (shouldPulse(event.timestamp)) {
+                    launchDozePulse();
+                }
+            } else {
+                mInPocketTime = event.timestamp;
+            }
+            mSawNear = isNear;
+        }
+
+        @Override
+        public void onAccuracyChanged(Sensor sensor, int accuracy) {
+            /* Empty */
+        }
+
+        private boolean shouldPulse(long timestamp) {
+            long delta = timestamp - mInPocketTime;
+
+            if (mHandwaveGestureEnabled && mPocketGestureEnabled) {
+                return true;
+            } else if (mProximityWakeEnabled && (delta < POCKET_DELTA_NS)) {
+                mPowerManager.wakeUp(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()));
+                return false;
+            } else if (mHandwaveGestureEnabled && !mPocketGestureEnabled) {
+                return delta < POCKET_DELTA_NS;
+            } else if (!mHandwaveGestureEnabled && mPocketGestureEnabled) {
+                return delta >= POCKET_DELTA_NS;
+            }
+            return false;
+        }
+
+        public void testAndEnable() {
+            if ((isDozeEnabled() && (mHandwaveGestureEnabled || mPocketGestureEnabled)) ||
+                    mProximityWakeEnabled) {
+                mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
+            }
+        }
+
+        public void disable() {
+            mSensorManager.unregisterListener(this, mSensor);
+        }
+    }
+
+    @Override
+    public void onCreate() {
+        if (DEBUG) Log.d(TAG, "SamsungDozeService Started");
+        mContext = this;
+        mPowerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
+        mSensor = new SamsungProximitySensor(mContext);
+        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
+        loadPreferences(sharedPrefs);
+        sharedPrefs.registerOnSharedPreferenceChangeListener(mPrefListener);
+        if (!isInteractive()) {
+            mSensor.testAndEnable();
+        }
+    }
+
+    @Override
+    public int onStartCommand(Intent intent, int flags, int startId) {
+        if (DEBUG) Log.d(TAG, "Starting service");
+        IntentFilter screenStateFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
+        screenStateFilter.addAction(Intent.ACTION_SCREEN_OFF);
+        mContext.registerReceiver(mScreenStateReceiver, screenStateFilter);
+        return START_STICKY;
+    }
+
+    @Override
+    public IBinder onBind(Intent intent) {
+        return null;
+    }
+
+    private void launchDozePulse() {
+        mContext.sendBroadcastAsUser(new Intent(DOZE_INTENT),
+                new UserHandle(UserHandle.USER_CURRENT));
+    }
+
+    private boolean isInteractive() {
+        return mPowerManager.isInteractive();
+    }
+
+    private boolean isDozeEnabled() {
+        return Settings.Secure.getInt(mContext.getContentResolver(),
+                Settings.Secure.DOZE_ENABLED, 1) != 0;
+    }
+
+    private void onDisplayOn() {
+        if (DEBUG) Log.d(TAG, "Display on");
+        mSensor.disable();
+    }
+
+    private void onDisplayOff() {
+        if (DEBUG) Log.d(TAG, "Display off");
+        mSensor.testAndEnable();
+    }
+
+    private void loadPreferences(SharedPreferences sharedPreferences) {
+        mHandwaveGestureEnabled = sharedPreferences.getBoolean(GESTURE_HAND_WAVE_KEY, false);
+        mPocketGestureEnabled = sharedPreferences.getBoolean(GESTURE_POCKET_KEY, false);
+        mProximityWakeEnabled = sharedPreferences.getBoolean(PROXIMITY_WAKE_KEY, false);
+    }
+
+    private BroadcastReceiver mScreenStateReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
+                onDisplayOff();
+            } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
+                onDisplayOn();
+            }
+        }
+    };
+
+    private SharedPreferences.OnSharedPreferenceChangeListener mPrefListener =
+            new SharedPreferences.OnSharedPreferenceChangeListener() {
+        @Override
+        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+            if (GESTURE_HAND_WAVE_KEY.equals(key)) {
+                mHandwaveGestureEnabled = sharedPreferences.getBoolean(GESTURE_HAND_WAVE_KEY, false);
+            } else if (GESTURE_POCKET_KEY.equals(key)) {
+                mPocketGestureEnabled = sharedPreferences.getBoolean(GESTURE_POCKET_KEY, false);
+            } else if (PROXIMITY_WAKE_KEY.equals(key)) {
+                mProximityWakeEnabled = sharedPreferences.getBoolean(PROXIMITY_WAKE_KEY, false);
+            }
+        }
+    };
+}
diff --git a/doze/src/org/lineageos/settings/device/TouchscreenGestureSettings.java b/doze/src/org/lineageos/settings/device/TouchscreenGestureSettings.java
new file mode 100644 (file)
index 0000000..4bf2900
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2015 The CyanogenMod 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.
+ */
+
+package org.lineageos.settings.device;
+
+import android.os.Bundle;
+import android.support.v14.preference.PreferenceFragment;
+import android.support.v14.preference.SwitchPreference;
+import android.support.v7.preference.Preference;
+import android.provider.Settings;
+
+import org.lineageos.internal.util.ScreenType;
+
+public class TouchscreenGestureSettings extends PreferenceFragment {
+
+    private static final String KEY_HAND_WAVE = "gesture_hand_wave";
+    private static final String KEY_PROXIMITY_WAKE = "proximity_wake_enable";
+
+    private SwitchPreference mHandwavePreference;
+    private SwitchPreference mProximityWakePreference;
+
+    @Override
+    public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+        addPreferencesFromResource(R.xml.gesture_panel);
+
+        mHandwavePreference =
+            (SwitchPreference) findPreference(KEY_HAND_WAVE);
+        mHandwavePreference.setOnPreferenceChangeListener(mProximityListener);
+        mProximityWakePreference =
+            (SwitchPreference) findPreference(KEY_PROXIMITY_WAKE);
+        mProximityWakePreference.setOnPreferenceChangeListener(mProximityListener);
+    }
+
+    @Override
+    public void onResume() {
+        super.onResume();
+
+        // If running on a phone, remove padding around the listview
+        if (!ScreenType.isTablet(getContext())) {
+            getListView().setPadding(0, 0, 0, 0);
+        }
+    }
+
+    private Preference.OnPreferenceChangeListener mProximityListener =
+        new Preference.OnPreferenceChangeListener() {
+        @Override
+        public boolean onPreferenceChange(Preference preference, Object newValue) {
+            if ((boolean) newValue) {
+                if (preference.getKey().equals(KEY_HAND_WAVE)) {
+                    mProximityWakePreference.setChecked(false);
+                } else if (preference.getKey().equals(KEY_PROXIMITY_WAKE)) {
+                    mHandwavePreference.setChecked(false);
+                }
+            }
+            return true;
+        }
+    };
+}