summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Lower <devvortex@gmail.com>2015-05-11 16:14:17 -0400
committerJan Altensen <info@stricted.net>2020-03-20 14:56:24 +0100
commitc8668b27555702ea17f0411d8e44e20d1879ebe4 (patch)
tree9322f79e084b30c9f8d2ccd6d3baf764140dd4a9
parent365786323c247526cd167f8be2751203ec1d9caa (diff)
downloadandroid_hardware_samsung-c8668b27555702ea17f0411d8e44e20d1879ebe4.tar.gz
android_hardware_samsung-c8668b27555702ea17f0411d8e44e20d1879ebe4.tar.bz2
android_hardware_samsung-c8668b27555702ea17f0411d8e44e20d1879ebe4.zip
samsung: doze: Add service for using proximity sensor for wake-up
* Added custom service that uses proximity sensor in wake-up mode to trigger display on * If more sensor triggers are suitable to use, they can be added to the service Change-Id: Id0849fb5c17ff569d771a19cebfc579dc93dbc48
-rw-r--r--Android.mk1
-rw-r--r--doze/Android.mk16
-rw-r--r--doze/AndroidManifest.xml47
-rw-r--r--doze/proguard.flags3
-rw-r--r--doze/res/values/strings.xml26
-rw-r--r--doze/res/xml/gesture_panel.xml28
-rw-r--r--doze/src/com/cyanogenmod/settings/device/BootCompletedReceiver.java35
-rw-r--r--doze/src/com/cyanogenmod/settings/device/SamsungDozeService.java190
-rw-r--r--doze/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java41
9 files changed, 387 insertions, 0 deletions
diff --git a/Android.mk b/Android.mk
index 5cc8f62..a5ad563 100644
--- a/Android.mk
+++ b/Android.mk
@@ -43,6 +43,7 @@ endif
ifeq ($(BOARD_VENDOR),samsung)
include $(SAM_ROOT)/AdvancedDisplay/Android.mk
include $(SAM_ROOT)/audio/Android.mk
+include $(SAM_ROOT)/doze/Android.mk
include $(SAM_ROOT)/dtbhtool/Android.mk
include $(SAM_ROOT)/hidl/Android.mk
include $(SAM_ROOT)/modemloader/Android.mk
diff --git a/doze/Android.mk b/doze/Android.mk
new file mode 100644
index 0000000..6d597c6
--- /dev/null
+++ b/doze/Android.mk
@@ -0,0 +1,16 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := SamsungDoze
+LOCAL_CERTIFICATE := platform
+LOCAL_PRIVILEGED_MODULE := true
+
+LOCAL_PROGUARD_FLAG_FILES := proguard.flags
+
+include $(BUILD_PACKAGE)
+
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/doze/AndroidManifest.xml b/doze/AndroidManifest.xml
new file mode 100644
index 0000000..804b80d
--- /dev/null
+++ b/doze/AndroidManifest.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.cyanogenmod.settings.device"
+ android:versionCode="1"
+ android:versionName="1.0"
+ android:sharedUserId="android.uid.system">
+
+ <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
+ <uses-permission android:name="android.permission.VIBRATE"/>
+ <uses-permission android:name="android.permission.WAKE_LOCK" />
+
+ <uses-sdk
+ android:minSdkVersion="21"
+ android:targetSdkVersion="21"/>
+
+ <application
+ android:label="SamsungDoze"
+ android:persistent="true">
+
+ <receiver android:name="com.cyanogenmod.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"
+ android:permission="SamsungDozeService">
+ </service>
+
+ <activity
+ android:name=".TouchscreenGestureSettings"
+ android:label="@string/screen_gestures_panel_title"
+ android:theme="@android:style/Theme.Material.Settings">>
+ <intent-filter>
+ <action android:name="com.cyanogenmod.action.LAUNCH_TOUCHSCREEN_GESTURE_SETTINGS" />
+ </intent-filter>
+ <meta-data
+ android:name="com.android.settings.title"
+ android:resource="@string/screen_gestures_panel_title"/>
+ <meta-data
+ android:name="com.android.settings.summary"
+ android:resource="@string/screen_gestures_panel_summary"/>
+ </activity>
+
+ </application>
+</manifest>
diff --git a/doze/proguard.flags b/doze/proguard.flags
new file mode 100644
index 0000000..3bb1f2c
--- /dev/null
+++ b/doze/proguard.flags
@@ -0,0 +1,3 @@
+-keep class com.cyanogenmod.settings.device.* {
+ *;
+}
diff --git a/doze/res/values/strings.xml b/doze/res/values/strings.xml
new file mode 100644
index 0000000..2b54bfb
--- /dev/null
+++ b/doze/res/values/strings.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+-->
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+
+ <!-- Gesture shortcuts -->
+ <string name="screen_gestures_panel_title">Gestures</string>
+ <string name="screen_gestures_panel_summary">Use gestures to perform actions</string>
+
+ <string name="hand_wave_gesture_title">Hand wave</string>
+ <string name="hand_wave_gesture_summary">Pulse notifications on hand wave</string>
+
+ <string name="pocket_gesture_title">Pocket</string>
+ <string name="pocket_gesture_summary">Pulse notifications on removal from pocket</string>
+
+</resources>
diff --git a/doze/res/xml/gesture_panel.xml b/doze/res/xml/gesture_panel.xml
new file mode 100644
index 0000000..29963d1
--- /dev/null
+++ b/doze/res/xml/gesture_panel.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+-->
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <SwitchPreference
+ android:key="gesture_hand_wave"
+ android:defaultValue="true"
+ android:title="@string/hand_wave_gesture_title"
+ android:summary="@string/hand_wave_gesture_summary" />
+
+ <SwitchPreference
+ android:key="gesture_pocket"
+ android:defaultValue="false"
+ android:title="@string/pocket_gesture_title"
+ android:summary="@string/pocket_gesture_summary" />
+
+</PreferenceScreen>
diff --git a/doze/src/com/cyanogenmod/settings/device/BootCompletedReceiver.java b/doze/src/com/cyanogenmod/settings/device/BootCompletedReceiver.java
new file mode 100644
index 0000000..9fe615e
--- /dev/null
+++ b/doze/src/com/cyanogenmod/settings/device/BootCompletedReceiver.java
@@ -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 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/SamsungDozeService.java b/doze/src/com/cyanogenmod/settings/device/SamsungDozeService.java
new file mode 100644
index 0000000..0eff337
--- /dev/null
+++ b/doze/src/com/cyanogenmod/settings/device/SamsungDozeService.java
@@ -0,0 +1,190 @@
+/*
+ * 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.preference.PreferenceManager;
+import android.provider.Settings;
+import android.util.Log;
+
+import java.util.ArrayList;
+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 int POCKET_DELTA_NS = 1000 * 1000 * 1000;
+
+ private Context mContext;
+ private SamsungProximitySensor mSensor;
+ private PowerManager mPowerManager;
+
+ private boolean mHandwaveGestureEnabled = false;
+ private boolean mPocketGestureEnabled = 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 (mHandwaveGestureEnabled && !mPocketGestureEnabled) {
+ return delta < POCKET_DELTA_NS;
+ } else if (!mHandwaveGestureEnabled && mPocketGestureEnabled) {
+ return delta >= POCKET_DELTA_NS;
+ }
+ return false;
+ }
+
+ public void enable() {
+ if (mHandwaveGestureEnabled || mPocketGestureEnabled) {
+ 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() && isDozeEnabled()) {
+ mSensor.enable();
+ }
+ }
+
+ @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.sendBroadcast(new Intent(DOZE_INTENT));
+ }
+
+ 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");
+ if (isDozeEnabled()) {
+ mSensor.enable();
+ }
+ }
+
+ private void loadPreferences(SharedPreferences sharedPreferences) {
+ mHandwaveGestureEnabled = sharedPreferences.getBoolean(GESTURE_HAND_WAVE_KEY, true);
+ mPocketGestureEnabled = sharedPreferences.getBoolean(GESTURE_POCKET_KEY, true);
+ }
+
+ 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, true);
+ } else if (GESTURE_POCKET_KEY.equals(key)) {
+ mPocketGestureEnabled = sharedPreferences.getBoolean(key, true);
+ }
+ }
+ };
+}
diff --git a/doze/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java b/doze/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java
new file mode 100644
index 0000000..bb40546
--- /dev/null
+++ b/doze/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java
@@ -0,0 +1,41 @@
+/*
+ * 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 com.android.internal.util.cm.ScreenType;
+
+import android.os.Bundle;
+import android.preference.PreferenceActivity;
+
+public class TouchscreenGestureSettings extends PreferenceActivity {
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.gesture_panel);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+
+ // If running on a phone, remove padding around the listview
+ if (!ScreenType.isTablet(this)) {
+ getListView().setPadding(0, 0, 0, 0);
+ }
+ }
+}