diff options
| author | TheStrix <parthbhatia98@gmail.com> | 2016-10-15 13:42:00 +0530 |
|---|---|---|
| committer | Faiz Authar <faizauthar@gmail.com> | 2016-12-22 21:53:23 +0700 |
| commit | 2644e6168f944106d4e48fc4a4c7c3ff78c368c0 (patch) | |
| tree | ef6e6bc7bb5895589d63aee31e6336a2b040895d | |
| parent | e27ce6a6bbc1683fbd0b0f00dd3adb48ca2696b1 (diff) | |
ferrari: Add XiaomiDoze package
* Update doze overlays
* Package kanged from OnePlus3 (OnePlusDoze -> XiaomiDoze)
* Squashed commit of:
oneplus3: add doze package
Taken from yu lettuce
Includes the following patches
YUDoze: Add service for using proximity sensor for wake-up
Author: Patrick Lower <devvortex@gmail.com>
Date: Mon May 11 16:14:17 2015 -0400
YUDoze: Set gesture to disabled by default
Author: Arne Coucheron <arco68@gmail.com>
Date: Wed May 20 00:56:19 2015 +0200
YUDoze: Consolidate doze settings
Author: Christopher R. Palmer <crpalmer@gmail.com>
Date: Sat May 23 11:42:49 2015 -0700
YUDoze: fix defaults
Author: Dave Daynard <nardholio@gmail.com>
Date: Sat May 23 18:29:13 2015 -0400
YUDoze: Add back button to action bar
Author: luca020400 <luca.stefani.ge1@gmail.com>
Date: Sun May 24 15:47:17 2015 -0700
YUDoze: add proximity wake
Author: Dave Daynard <nardholio@gmail.com>
Date: Mon May 25 12:54:00 2015 -0400
YUDoze: restore proximity wake preference on boot
Author: Dave Daynard <nardholio@gmail.com>
Date: Sat Jul 4 13:44:53 2015 -0400
YUDozeService: Prevent a pm wakeup with a timestamp in the future
Author: Brandon McAnsh <brandon.mcansh@gmail.com>
Date: Fri Jul 24 15:40:45 2015 -0400
YUDozeService: properly fix future timestamp error
Author: Patrick Lower <devvortex@gmail.com>
Date: Wed Aug 5 10:51:03 2015 -0400
YUDoze: fix typo
Author: Dave Daynard <nardholio@gmail.com>
Date: Tue Sep 8 22:56:10 2015 -0400
YUDoze: Use ScreenType util from cmsdk
Author: Michael Bestas <mikeioannina@gmail.com>
Date: Sun Dec 13 02:51:09 2015 -0500
YUDOze: Remove summary for YUDoze
Author: TheStrix <parthbhatia98@gmail.com>
Date: Sun Dec 13 07:25:36 2015 -0500
oneplus2: doze improvements
Author: Altaf-Mahdi <altaf.mahdi@gmail.com>
Date: 2016-04-24 23:01:57 +0100
op3: doze: clean up
Author: Altaf-Mahdi <altaf.mahdi@gmail.com>
Date: 2016-08-21 08:47:12 +0100
op3: Bring DozeSettings up to date
Author: Steve Kondik <steve@cyngn.com>
Date: Oct 15, 2016 9:48 AM
op3: doze: Use commonized strings translations
Author: Abhisek Devkota <ciwrl@cyanogenmod.com>
Date: Nov 24, 2016 7:43 AM
Change-Id: Ie2960d7f3897dd7f77d31c31813972a42c230c3b
27 files changed, 874 insertions, 302 deletions
diff --git a/aicp.dependencies b/aicp.dependencies index e44829d..fdf296f 100644 --- a/aicp.dependencies +++ b/aicp.dependencies @@ -28,5 +28,10 @@ "repository": "CyanogenMod/android_external_stlport", "target_path": "external/stlport", "branch": "cm-14.1" + }, + { + "repository": "CyanogenMod/android_packages_resources_devicesettings", + "target_path": "packages/resources/devicesettings", + "branch": "cm-14.1" } ] diff --git a/doze/Android.mk b/doze/Android.mk index 731ad7b..095f7d8 100644 --- a/doze/Android.mk +++ b/doze/Android.mk @@ -5,12 +5,33 @@ LOCAL_MODULE_TAGS := optional LOCAL_SRC_FILES := $(call all-java-files-under, src) -LOCAL_PACKAGE_NAME := FerrariDoze +LOCAL_PACKAGE_NAME := XiaomiDoze LOCAL_CERTIFICATE := platform LOCAL_PRIVILEGED_MODULE := true +LOCAL_STATIC_JAVA_LIBRARIES := \ + android-support-v4 \ + android-support-v13 \ + android-support-v7-recyclerview \ + android-support-v7-preference \ + android-support-v7-appcompat \ + android-support-v14-preference \ + org.cyanogenmod.platform.internal + +LOCAL_RESOURCE_DIR := \ + $(LOCAL_PATH)/res \ + $(LOCAL_PATH)/../../../../packages/resources/devicesettings/res \ + frameworks/support/v7/preference/res \ + frameworks/support/v14/preference/res \ + frameworks/support/v7/appcompat/res \ + frameworks/support/v7/recyclerview/res + +LOCAL_AAPT_FLAGS := --auto-add-overlay \ + --extra-packages android.support.v7.preference:android.support.v14.preference:android.support.v17.preference:android.support.v7.appcompat:android.support.v7.recyclerview LOCAL_PROGUARD_FLAG_FILES := proguard.flags +include frameworks/base/packages/SettingsLib/common.mk + include $(BUILD_PACKAGE) include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/doze/AndroidManifest.xml b/doze/AndroidManifest.xml index 265f8d0..ddae3af 100644 --- a/doze/AndroidManifest.xml +++ b/doze/AndroidManifest.xml @@ -1,37 +1,48 @@ <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="org.cyanogenmod.doze" + package="com.cyanogenmod.settings.doze" 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.WAKE_LOCK" /> + <uses-permission android:name="cyanogenmod.permission.MANAGE_REMOTE_PREFERENCES" /> - <application android:label="FerrariDoze" - android:persistent="true"> + <uses-sdk + android:minSdkVersion="24" + android:targetSdkVersion="24"/> - <receiver android:name="org.cyanogenmod.doze.ferrari.BootCompletedReceiver"> + <application + android:label="@string/device_settings_app_name" + android:persistent="true"> + + <receiver android:name="com.cyanogenmod.settings.doze.DozeReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> + <action android:name="cyanogenmod.intent.action.UPDATE_PREFERENCE" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </receiver> - <service android:name="org.cyanogenmod.doze.ferrari.DozeService" - android:permission="FerrariDozeService"> + <service android:name="com.cyanogenmod.settings.doze.DozeService" + android:permission="XiaomiDozeService"> </service> - <activity android:name="FerrariDoze" - android:label="FerrariDoze" - android:excludeFromRecents="true" - android:launchMode="singleInstance" - android:screenOrientation="portrait" - android:theme="@style/FerrariDozeTheme" - android:windowAnimationStyle="@null"> + <activity + android:name=".DozeSettings" + android:label="@string/ambient_display_title" + android:theme="@style/DozeSettings"> <intent-filter> - <action android:name="android.intent.action.MAIN" /> + <action android:name="org.cyanogenmod.settings.device.DOZE_SETTINGS" /> + <category android:name="android.intent.category.DEFAULT" /> </intent-filter> + <meta-data + android:name="org.cyanogenmod.settings.summary.receiver" + android:value="com.cyanogenmod.settings.doze.DozeReceiver" /> + <meta-data + android:name="org.cyanogenmod.settings.summary.key" + android:value="doze_device_settings" /> </activity> </application> diff --git a/doze/proguard.flags b/doze/proguard.flags index 9294e22..7f3d4c7 100644 --- a/doze/proguard.flags +++ b/doze/proguard.flags @@ -1,3 +1,8 @@ --keep class org.cyanogenmod.doze.ferrari.* { +-keepclasseswithmembers class * { + public <init>(android.content.Context, android.util.AttributeSet); +} + +-keep class ** extends android.support.v14.preference.PreferenceFragment +-keep class com.cyanogenmod.settings.doze.* { *; } diff --git a/doze/res/drawable/ic_settings_doze.xml b/doze/res/drawable/ic_settings_doze.xml new file mode 100644 index 0000000..8386024 --- /dev/null +++ b/doze/res/drawable/ic_settings_doze.xml @@ -0,0 +1,51 @@ +<!-- +Copyright (C) 2014 The Android Open Source 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. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="64dp" + android:height="64dp" + android:viewportWidth="64" + android:viewportHeight="64"> + + <group + android:translateY="-988.583"> + <path + android:fillColor="@android:color/white" + android:pathData="M15.0133 +1051.24c-1.3615-0.2479-2.37425-1.2789-2.57968-2.6262-0.06554-0.4298-0.06571-55.8484-0.00018-56.28 +0.09875-0.65024 0.367851-1.20544 0.812983-1.6773 0.402211-0.42637 +0.920053-0.7356 1.49909-0.8952l0.299302-0.0825h16.845 16.845l0.291174 +0.0804c1.24697 0.34447 2.13039 1.32473 2.32019 2.57456 0.06515 0.42898 0.06541 +55.8484 0.0003 56.28-0.188067 1.2461-1.07608 2.2305-2.32306 2.5752l-0.288567 +0.08h-16.755c-13.5267 0-16.7958 +0-16.9665-0.034zm29.8065-31.1862v-19.23h-12.99-12.99v19.23 19.23h12.99 +12.99v-19.23zm-13.459 +11.687c-1.03547-0.2354-1.77837-1.1208-1.83292-2.1845l-0.01654-0.3225h1.87175c1.02946 +0 2.10645 0.01 2.3933 0.02l0.521553 0.02-0.01945 0.253c-0.02847 0.3705-0.09559 +0.6134-0.267159 0.9672-0.135477 0.2794-0.18522 0.3474-0.439626 0.6013-0.31197 +0.3114-0.571617 0.4707-0.976866 0.5995-0.269196 0.085-0.949163 0.111-1.23404 +0.046zm-9.04096-4.1842v-0.6872l1.10534-1.0831 1.10534-1.0831 +0.02483-1.2072c0.01366-0.664 0.02781-2.213 0.03145-3.4422 0.007-2.3727 +0.01776-2.5909 0.162279-3.3 0.234013-1.1483 0.861931-2.2993 1.7263-3.1643 +0.762874-0.7634 1.91951-1.4813 3.00204-1.8633 0.262572-0.093 0.512691-0.1813 +0.555819-0.1969l0.07842-0.029 0.01577-0.426c0.01284-0.3469 0.03018-0.4706 +0.09332-0.666 0.197394-0.6109 0.642609-1.0525 1.21018-1.2004 0.365688-0.095 +0.860153-0.043 1.2089 0.1282 0.234414 0.1149 0.589851 0.4783 0.725931 0.7422 +0.171483 0.3325 0.207933 0.491 0.225975 0.9825 0.01148 0.3126 0.02671 0.4425 +0.0519 0.4425 0.01961 0 0.2844 0.088 0.588423 0.1954 2.74734 0.9715 4.21726 +2.7794 4.71985 5.805 0.171696 1.0336 0.211308 1.7926 0.259098 4.9646l0.03345 +2.22 1.10911 1.095 1.1091 1.095-0.0014 0.6825-0.0014 0.6825h-9.57-9.57v-0.6872z" /> + </group> +</vector> diff --git a/doze/res/drawable/switchbar_background.xml b/doze/res/drawable/switchbar_background.xml new file mode 100644 index 0000000..45f1578 --- /dev/null +++ b/doze/res/drawable/switchbar_background.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 The Android Open Source 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. +--> + +<ripple xmlns:android="http://schemas.android.com/apk/res/android" + android:color="?android:attr/colorControlHighlight"> + <item android:drawable="@color/switch_bar_background" /> +</ripple> + diff --git a/doze/res/layout/doze.xml b/doze/res/layout/doze.xml new file mode 100644 index 0000000..941cdf6 --- /dev/null +++ b/doze/res/layout/doze.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* +** Copyright 2014, The Android Open Source 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. +*/ +--> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_height="match_parent" + android:layout_width="match_parent"> + + <include layout="@layout/switch_bar" /> + +</LinearLayout> + diff --git a/doze/res/layout/switch_bar.xml b/doze/res/layout/switch_bar.xml new file mode 100644 index 0000000..f98de96 --- /dev/null +++ b/doze/res/layout/switch_bar.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2016 The Android Open Source 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. +--> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/switch_bar" + android:layout_width="match_parent" + android:layout_height="?android:attr/actionBarSize" + android:background="@drawable/switchbar_background" + android:paddingStart="16dp" + android:paddingEnd="16dp" + android:clickable="true" + android:gravity="center"> + + <TextView android:id="@+id/switch_text" + android:layout_height="wrap_content" + android:layout_width="0dp" + android:layout_weight="1" + android:layout_gravity="center_vertical" + android:paddingStart="48dp" + android:maxLines="2" + android:ellipsize="end" + android:textAppearance="@android:style/TextAppearance.Material.Title" + android:textColor="?android:attr/textColorPrimaryInverse" + android:textAlignment="viewStart" + android:text="@string/switch_bar_on" /> + + <Switch + android:id="@android:id/switch_widget" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:background="@null" + android:theme="@style/ThemeOverlay.SwitchBar" /> + +</LinearLayout> diff --git a/doze/res/values/colors.xml b/doze/res/values/colors.xml new file mode 100644 index 0000000..d598598 --- /dev/null +++ b/doze/res/values/colors.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* + * Copyright 2010, The Android Open Source 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> + <color name="switch_bar_background">#ff37474f</color> + <color name="switch_accent_color">#ff7fcac3</color> + <color name="system_secondary_color">#ff37474F</color> +</resources> diff --git a/doze/res/values/style.xml b/doze/res/values/style.xml deleted file mode 100644 index 7052b5e..0000000 --- a/doze/res/values/style.xml +++ /dev/null @@ -1,9 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<resources> - <style name="FerrariDozeTheme" parent="android:Theme.NoTitleBar.Fullscreen"> - <item name="android:background">@android:color/black</item> - <item name="android:windowBackground">@android:color/black</item> - <item name="android:colorBackground">@android:color/black</item> - <item name="android:windowAnimationStyle">@null</item> - </style> -</resources> diff --git a/doze/res/values/styles.xml b/doze/res/values/styles.xml new file mode 100644 index 0000000..78d2d59 --- /dev/null +++ b/doze/res/values/styles.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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. +--> +<resources xmlns:android="http://schemas.android.com/apk/res/android"> + <style name="DozeSettings" parent="@android:style/Theme.Material.Settings"> + <item name="android:windowActionBar">false</item> + <item name="preferenceTheme">@style/DozePreferenceTheme</item> + </style> + + <style name="DozePreferenceTheme" parent="@android:style/Theme.Material.Settings"> + <item name="dropdownPreferenceStyle">@style/Preference.DropDown.Material</item> + </style> + + <style name="ThemeOverlay.SwitchBar" parent="@android:style/ThemeOverlay"> + <item name="android:colorAccent">@color/switch_accent_color</item> + </style> + + <style name="ThemeOverlay.SwitchBar.Secondary" parent="@android:style/ThemeOverlay"> + <item name="android:colorAccent">@color/system_secondary_color</item> + </style> + +</resources> diff --git a/doze/res/xml/doze_settings.xml b/doze/res/xml/doze_settings.xml new file mode 100644 index 0000000..005c6ae --- /dev/null +++ b/doze/res/xml/doze_settings.xml @@ -0,0 +1,49 @@ +<?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"> + + <PreferenceCategory + android:key="tilt_sensor" + android:title="@string/tilt_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> + + <PreferenceCategory + android:key="proximity_sensor" + android:title="@string/proximity_sensor_title"> + + <SwitchPreference + android:key="gesture_hand_wave" + android:defaultValue="false" + 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" /> + + </PreferenceCategory> + +</PreferenceScreen> diff --git a/doze/src/org/cyanogenmod/doze/ferrari/BootCompletedReceiver.java b/doze/src/com/cyanogenmod/settings/doze/BootCompletedReceiver.java index 9775bc6..5d6f17a 100644 --- a/doze/src/org/cyanogenmod/doze/ferrari/BootCompletedReceiver.java +++ b/doze/src/com/cyanogenmod/settings/doze/BootCompletedReceiver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 The CyanogenMod Project + * 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.cyanogenmod.doze.ferrari; +package com.cyanogenmod.settings.doze; import android.content.BroadcastReceiver; import android.content.Context; @@ -24,11 +24,14 @@ import android.util.Log; public class BootCompletedReceiver extends BroadcastReceiver { private static final boolean DEBUG = false; - private static final String TAG = "FerrariDoze"; + private static final String TAG = "XiaomiDoze"; @Override public void onReceive(final Context context, Intent intent) { - if (DEBUG) Log.d(TAG, "Starting service"); - context.startService(new Intent(context, DozeService.class)); + if (Utils.isDozeEnabled(context) && Utils.sensorsEnabled(context)) { + if (DEBUG) Log.d(TAG, "Starting service"); + Utils.startService(context); + } } + } diff --git a/doze/src/com/cyanogenmod/settings/doze/DozeReceiver.java b/doze/src/com/cyanogenmod/settings/doze/DozeReceiver.java new file mode 100644 index 0000000..4bf4e36 --- /dev/null +++ b/doze/src/com/cyanogenmod/settings/doze/DozeReceiver.java @@ -0,0 +1,54 @@ +/* + * 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.doze; + +import android.content.Context; +import android.content.Intent; +import android.util.Log; + +import cyanogenmod.preference.RemotePreferenceUpdater; + +public class DozeReceiver extends RemotePreferenceUpdater { + + private static final boolean DEBUG = false; + private static final String TAG = "XiaomiDoze"; + + private static final String DOZE_CATEGORY_KEY = "doze_device_settings"; + + @Override + public void onReceive(Context context, Intent intent) { + super.onReceive(context, intent); + + if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) { + if (Utils.isDozeEnabled(context) && Utils.sensorsEnabled(context)) { + if (DEBUG) Log.d(TAG, "Starting service"); + Utils.startService(context); + } + } + } + + @Override + public String getSummary(Context context, String key) { + if (DOZE_CATEGORY_KEY.equals(key)) { + return DozeSettingsFragment.getDozeSummary(context); + } + return null; + } + + static void notifyChanged(Context context) { + notifyChanged(context, DOZE_CATEGORY_KEY); + } +} diff --git a/doze/src/org/cyanogenmod/doze/ferrari/DozeService.java b/doze/src/com/cyanogenmod/settings/doze/DozeService.java index ebd664a..2ee79bf 100644 --- a/doze/src/org/cyanogenmod/doze/ferrari/DozeService.java +++ b/doze/src/com/cyanogenmod/settings/doze/DozeService.java @@ -14,44 +14,37 @@ * limitations under the License. */ -package org.cyanogenmod.doze.ferrari; +package com.cyanogenmod.settings.doze; -import android.app.Activity; -import android.app.IntentService; import android.app.Service; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.os.Bundle; import android.os.IBinder; -import android.provider.Settings; import android.util.Log; public class DozeService extends Service { - - private static final boolean DEBUG = false; private static final String TAG = "DozeService"; + private static final boolean DEBUG = false; - private Context mContext; - private TiltSensor mTiltSensor; private ProximitySensor mProximitySensor; + private TiltSensor mTiltSensor; @Override public void onCreate() { if (DEBUG) Log.d(TAG, "Creating service"); - super.onCreate(); - mContext = this; - mTiltSensor = new TiltSensor(mContext); - mProximitySensor = new ProximitySensor(mContext); + mProximitySensor = new ProximitySensor(this); + mTiltSensor = new TiltSensor(this); + + IntentFilter screenStateFilter = new IntentFilter(Intent.ACTION_SCREEN_ON); + screenStateFilter.addAction(Intent.ACTION_SCREEN_OFF); + registerReceiver(mScreenStateReceiver, screenStateFilter); } @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; } @@ -59,8 +52,9 @@ public class DozeService extends Service { public void onDestroy() { if (DEBUG) Log.d(TAG, "Destroying service"); super.onDestroy(); - mTiltSensor.disable(); + this.unregisterReceiver(mScreenStateReceiver); mProximitySensor.disable(); + mTiltSensor.disable(); } @Override @@ -68,21 +62,24 @@ public class DozeService extends Service { return null; } - 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"); - mTiltSensor.disable(); - mProximitySensor.disable(); + if (Utils.pickUpEnabled(this)) { + mTiltSensor.disable(); + } + if (Utils.handwaveGestureEnabled(this) || + Utils.pocketGestureEnabled(this)) { + mProximitySensor.disable(); + } } private void onDisplayOff() { if (DEBUG) Log.d(TAG, "Display off"); - if (isDozeEnabled()) { + if (Utils.pickUpEnabled(this)) { mTiltSensor.enable(); + } + if (Utils.handwaveGestureEnabled(this) || + Utils.pocketGestureEnabled(this)) { mProximitySensor.enable(); } } @@ -90,10 +87,10 @@ public class DozeService extends Service { 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)) { + if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) { onDisplayOn(); + } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { + onDisplayOff(); } } }; diff --git a/doze/src/com/cyanogenmod/settings/doze/DozeSettings.java b/doze/src/com/cyanogenmod/settings/doze/DozeSettings.java new file mode 100644 index 0000000..76ac5fe --- /dev/null +++ b/doze/src/com/cyanogenmod/settings/doze/DozeSettings.java @@ -0,0 +1,50 @@ +/* + * 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.doze; + +import android.app.Activity; +import android.os.Bundle; +import android.view.MenuItem; + +import com.android.settingslib.drawer.SettingsDrawerActivity; + +/** + * Created by shade on 10/14/16. + */ + +public class DozeSettings extends SettingsDrawerActivity { + + private static final String TAG_DOZE = "doze"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.doze); + + getFragmentManager().beginTransaction().replace(R.id.content_frame, + new DozeSettingsFragment(), TAG_DOZE).commit(); + } + + @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/doze/DozeSettingsFragment.java b/doze/src/com/cyanogenmod/settings/doze/DozeSettingsFragment.java new file mode 100644 index 0000000..0da6f69 --- /dev/null +++ b/doze/src/com/cyanogenmod/settings/doze/DozeSettingsFragment.java @@ -0,0 +1,197 @@ +/* + * 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.doze; + +import android.app.ActionBar; +import android.app.Activity; +import android.app.AlertDialog; +import android.app.Dialog; +import android.app.DialogFragment; +import android.content.Context; +import android.content.DialogInterface; +import android.content.SharedPreferences; +import android.database.ContentObserver; +import android.os.Bundle; +import android.os.Handler; +import android.support.v14.preference.PreferenceFragment; +import android.support.v14.preference.SwitchPreference; +import android.support.v7.preference.Preference; +import android.support.v7.preference.Preference.OnPreferenceChangeListener; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.CompoundButton; +import android.widget.Switch; + +public class DozeSettingsFragment extends PreferenceFragment implements OnPreferenceChangeListener, + CompoundButton.OnCheckedChangeListener { + + private SharedPreferences mPreferences; + + private Switch mSwitch; + + private SwitchPreference mPickUpPreference; + private SwitchPreference mHandwavePreference; + private SwitchPreference mPocketPreference; + + private ContentObserver mDozeObserver = new ContentObserver(new Handler()) { + @Override + public void onChange(boolean selfChange) { + super.onChange(selfChange); + + boolean enabled = Utils.isDozeEnabled(getActivity()); + + updateSwitches(Utils.isDozeEnabled(getActivity())); + DozeReceiver.notifyChanged(getActivity()); + } + }; + + static String getDozeSummary(Context context) { + if (Utils.isDozeEnabled(context)) { + return context.getString(R.string.ambient_display_summary_on); + } + return context.getString(R.string.ambient_display_summary_off); + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + getActivity().getActionBar().setDisplayHomeAsUpEnabled(true); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + final View view = LayoutInflater.from(getContext()).inflate(R.layout.doze, container, false); + ((ViewGroup) view).addView(super.onCreateView(inflater, container, savedInstanceState)); + return view; + } + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + addPreferencesFromResource(R.xml.doze_settings); + + // get shared preference + mPreferences = getActivity().getSharedPreferences("doze_settings", Activity.MODE_PRIVATE); + + if (savedInstanceState == null && !mPreferences.getBoolean("first_help_shown", false)) { + showHelp(); + } + + mPickUpPreference = + (SwitchPreference) findPreference(Utils.GESTURE_PICK_UP_KEY); + mPickUpPreference.setOnPreferenceChangeListener(this); + + mHandwavePreference = + (SwitchPreference) findPreference(Utils.GESTURE_HAND_WAVE_KEY); + mHandwavePreference.setOnPreferenceChangeListener(this); + + mPocketPreference = + (SwitchPreference) findPreference(Utils.GESTURE_POCKET_KEY); + mPocketPreference.setOnPreferenceChangeListener(this); + } + + @Override + public void onResume() { + super.onResume(); + getActivity().getContentResolver().registerContentObserver( + Utils.DOZE_ENABLED_URI, false, mDozeObserver); + updateSwitches(Utils.isDozeEnabled(getActivity())); + } + + @Override + public void onPause() { + super.onPause(); + getActivity().getContentResolver().unregisterContentObserver(mDozeObserver); + } + + private void updateSwitches(boolean enabled) { + mPickUpPreference.setEnabled(enabled); + mHandwavePreference.setEnabled(enabled); + mPocketPreference.setEnabled(enabled); + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + View switchBar = view.findViewById(R.id.switch_bar); + mSwitch = (Switch) switchBar.findViewById(android.R.id.switch_widget); + mSwitch.setChecked(Utils.isDozeEnabled(getActivity())); + mSwitch.setOnCheckedChangeListener(this); + + switchBar.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + mSwitch.setChecked(!mSwitch.isChecked()); + } + }); + } + + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + final String key = preference.getKey(); + final boolean value = (Boolean) newValue; + if (Utils.GESTURE_PICK_UP_KEY.equals(key)) { + mPickUpPreference.setChecked(value); + } else if (Utils.GESTURE_HAND_WAVE_KEY.equals(key)) { + mHandwavePreference.setChecked(value); + } else if (Utils.GESTURE_POCKET_KEY.equals(key)) { + mPocketPreference.setChecked(value); + } else { + return false; + } + + Utils.startService(getActivity()); + return true; + } + + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean b) { + Utils.enableDoze(b, getActivity()); + } + + public static class HelpDialogFragment extends DialogFragment { + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + return new AlertDialog.Builder(getActivity()) + .setTitle(R.string.doze_settings_help_title) + .setMessage(R.string.doze_settings_help_text) + .setNegativeButton(R.string.dialog_ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.cancel(); + } + }) + .create(); + } + + @Override + public void onCancel(DialogInterface dialog) { + getActivity().getSharedPreferences("doze_settings", Activity.MODE_PRIVATE) + .edit() + .putBoolean("first_help_shown", true) + .commit(); + } + } + + private void showHelp() { + HelpDialogFragment fragment = new HelpDialogFragment(); + fragment.show(getFragmentManager(), "help_dialog"); + } +} diff --git a/doze/src/com/cyanogenmod/settings/doze/ProximitySensor.java b/doze/src/com/cyanogenmod/settings/doze/ProximitySensor.java new file mode 100644 index 0000000..0f62b11 --- /dev/null +++ b/doze/src/com/cyanogenmod/settings/doze/ProximitySensor.java @@ -0,0 +1,91 @@ +/* + * 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.doze; + +import android.content.Context; +import android.hardware.Sensor; +import android.hardware.SensorEvent; +import android.hardware.SensorEventListener; +import android.hardware.SensorManager; +import android.util.Log; + +public class ProximitySensor implements SensorEventListener { + + private static final boolean DEBUG = false; + private static final String TAG = "ProximitySensor"; + + private static final int POCKET_DELTA_NS = 1000 * 1000 * 1000; + + private SensorManager mSensorManager; + private Sensor mSensor; + private Context mContext; + + private boolean mSawNear = false; + private long mInPocketTime = 0; + + public ProximitySensor(Context context) { + mContext = context; + mSensorManager = (SensorManager) + mContext.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)) { + Utils.launchDozePulse(mContext); + } + } else { + mInPocketTime = event.timestamp; + } + mSawNear = isNear; + } + + private boolean shouldPulse(long timestamp) { + long delta = timestamp - mInPocketTime; + + if (Utils.handwaveGestureEnabled(mContext) + && Utils.pocketGestureEnabled(mContext)) { + return true; + } else if (Utils.handwaveGestureEnabled(mContext) + && !Utils.pocketGestureEnabled(mContext)) { + return delta < POCKET_DELTA_NS; + } else if (!Utils.handwaveGestureEnabled(mContext) + && Utils.pocketGestureEnabled(mContext)) { + return delta >= POCKET_DELTA_NS; + } + return false; + } + + @Override + public void onAccuracyChanged(Sensor sensor, int accuracy) { + /* Empty */ + } + + protected void enable() { + if (DEBUG) Log.d(TAG, "Enabling"); + mSensorManager.registerListener(this, mSensor, + SensorManager.SENSOR_DELAY_NORMAL); + } + + protected void disable() { + if (DEBUG) Log.d(TAG, "Disabling"); + mSensorManager.unregisterListener(this, mSensor); + } +} diff --git a/doze/src/org/cyanogenmod/doze/ferrari/TiltSensor.java b/doze/src/com/cyanogenmod/settings/doze/TiltSensor.java index 3da3273..443a10d 100644 --- a/doze/src/org/cyanogenmod/doze/ferrari/TiltSensor.java +++ b/doze/src/com/cyanogenmod/settings/doze/TiltSensor.java @@ -14,43 +14,46 @@ * limitations under the License. */ -package org.cyanogenmod.doze.ferrari; +package com.cyanogenmod.settings.doze; import android.content.Context; import android.hardware.Sensor; import android.hardware.SensorEvent; +import android.hardware.SensorEventListener; +import android.hardware.SensorManager; +import android.os.PowerManager; +import android.os.PowerManager.WakeLock; import android.os.SystemClock; import android.util.Log; -public class TiltSensor extends FerrariSensor { +public class TiltSensor implements SensorEventListener { private static final boolean DEBUG = false; private static final String TAG = "TiltSensor"; + private static final int SENSOR_WAKELOCK_DURATION = 200; + private static final int BATCH_LATENCY_IN_MS = 100; private static final int MIN_PULSE_INTERVAL_MS = 2500; + private PowerManager mPowerManager; + private SensorManager mSensorManager; + private Sensor mSensor; + private WakeLock mSensorWakeLock; + private Context mContext; + private long mEntryTimestamp; - private AccelSensor mAccelSensor; public TiltSensor(Context context) { - super(context, Sensor.TYPE_TILT_DETECTOR); - } - - @Override - public void enable() { - if (DEBUG) Log.d(TAG, "Enabling"); - super.enable(); - mEntryTimestamp = SystemClock.elapsedRealtime(); - } - - @Override - public void disable() { - if (DEBUG) Log.d(TAG, "Disabling"); - super.disable(); + mContext = context; + mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); + mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); + mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_TILT_DETECTOR); + mSensorWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, + "SensorWakeLock"); } @Override - protected void onSensorEvent(SensorEvent event) { + public void onSensorChanged(SensorEvent event) { if (DEBUG) Log.d(TAG, "Got sensor event: " + event.values[0]); long delta = SystemClock.elapsedRealtime() - mEntryTimestamp; @@ -61,8 +64,24 @@ public class TiltSensor extends FerrariSensor { } if (event.values[0] == 1) { - mAccelSensor = new AccelSensor(mContext); - mAccelSensor.enable(); + Utils.launchDozePulse(mContext); } } + + @Override + public void onAccuracyChanged(Sensor sensor, int accuracy) { + /* Empty */ + } + + protected void enable() { + if (DEBUG) Log.d(TAG, "Enabling"); + mSensorManager.registerListener(this, mSensor, + SensorManager.SENSOR_DELAY_NORMAL, BATCH_LATENCY_IN_MS * 1000); + mEntryTimestamp = SystemClock.elapsedRealtime(); + } + + protected void disable() { + if (DEBUG) Log.d(TAG, "Disabling"); + mSensorManager.unregisterListener(this, mSensor); + } } diff --git a/doze/src/com/cyanogenmod/settings/doze/Utils.java b/doze/src/com/cyanogenmod/settings/doze/Utils.java new file mode 100644 index 0000000..ef22157 --- /dev/null +++ b/doze/src/com/cyanogenmod/settings/doze/Utils.java @@ -0,0 +1,94 @@ +/* + * 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.doze; + +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.os.UserHandle; +import android.support.v7.preference.PreferenceManager; +import android.provider.Settings; +import android.util.Log; + +import static android.provider.Settings.Secure.DOZE_ENABLED; + +public final class Utils { + + private static final String TAG = "DozeUtils"; + private static final boolean DEBUG = false; + + private static final String DOZE_INTENT = "com.android.systemui.doze.pulse"; + + protected static final String AMBIENT_DISPLAY_KEY = "doze_enabled"; + protected static final String GESTURE_PICK_UP_KEY = "gesture_pick_up"; + protected static final String GESTURE_HAND_WAVE_KEY = "gesture_hand_wave"; + protected static final String GESTURE_POCKET_KEY = "gesture_pocket"; + + public static final Uri DOZE_ENABLED_URI = Settings.Secure.getUriFor(DOZE_ENABLED); + + protected static void startService(Context context) { + if (DEBUG) Log.d(TAG, "Starting service"); + context.startService(new Intent(context, DozeService.class)); + } + + protected static void stopService(Context context) { + if (DEBUG) Log.d(TAG, "Stopping service"); + context.stopService(new Intent(context, DozeService.class)); + } + + protected static boolean isDozeEnabled(Context context) { + return Settings.Secure.getInt(context.getContentResolver(), + DOZE_ENABLED, 1) != 0; + } + + protected static boolean enableDoze(boolean enable, Context context) { + boolean dozeEnabled = Settings.Secure.putInt(context.getContentResolver(), + DOZE_ENABLED, enable ? 1 : 0); + if (enable) { + startService(context); + } else { + stopService(context); + } + return dozeEnabled; + } + + protected static void launchDozePulse(Context context) { + if (DEBUG) Log.d(TAG, "Launch doze pulse"); + context.sendBroadcastAsUser(new Intent(DOZE_INTENT), + new UserHandle(UserHandle.USER_CURRENT)); + } + + protected static boolean pickUpEnabled(Context context) { + return PreferenceManager.getDefaultSharedPreferences(context) + .getBoolean(GESTURE_PICK_UP_KEY, false); + } + + protected static boolean handwaveGestureEnabled(Context context) { + return PreferenceManager.getDefaultSharedPreferences(context) + .getBoolean(GESTURE_HAND_WAVE_KEY, false); + } + + protected static boolean pocketGestureEnabled(Context context) { + return PreferenceManager.getDefaultSharedPreferences(context) + .getBoolean(GESTURE_POCKET_KEY, false); + } + + protected static boolean sensorsEnabled(Context context) { + return pickUpEnabled(context) || handwaveGestureEnabled(context) + || pocketGestureEnabled(context); + } +} diff --git a/doze/src/org/cyanogenmod/doze/ferrari/AccelSensor.java b/doze/src/org/cyanogenmod/doze/ferrari/AccelSensor.java deleted file mode 100644 index 4fce63f..0000000 --- a/doze/src/org/cyanogenmod/doze/ferrari/AccelSensor.java +++ /dev/null @@ -1,57 +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 org.cyanogenmod.doze.ferrari; - -import android.content.Context; -import android.hardware.Sensor; -import android.hardware.SensorEvent; -import android.util.Log; - -public class AccelSensor extends FerrariSensor { - - private static final boolean DEBUG = false; - private static final String TAG = "AccelSensor"; - - private static final int ACCELERATION_FORCE_Y_MIN = 5; - - public AccelSensor(Context context) { - super(context, Sensor.TYPE_ACCELEROMETER); - } - - @Override - public void enable() { - if (DEBUG) Log.d(TAG, "Enabling"); - super.enable(); - } - - @Override - public void disable() { - if (DEBUG) Log.d(TAG, "Disabling"); - super.disable(); - } - - @Override - protected void onSensorEvent(SensorEvent event) { - if (DEBUG) Log.d(TAG, "Got sensor event: y = " + event.values[1]); - - if (event.values[1] > ACCELERATION_FORCE_Y_MIN) { - launchDozePulse(); - } - - disable(); - } -} diff --git a/doze/src/org/cyanogenmod/doze/ferrari/FerrariSensor.java b/doze/src/org/cyanogenmod/doze/ferrari/FerrariSensor.java deleted file mode 100644 index 1cb95f6..0000000 --- a/doze/src/org/cyanogenmod/doze/ferrari/FerrariSensor.java +++ /dev/null @@ -1,89 +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 org.cyanogenmod.doze.ferrari; - -import android.content.ActivityNotFoundException; -import android.content.Context; -import android.content.Intent; -import android.hardware.Sensor; -import android.hardware.SensorEvent; -import android.hardware.SensorEventListener; -import android.hardware.SensorManager; -import android.os.PowerManager; -import android.os.PowerManager.WakeLock; -import android.os.UserHandle; -import android.os.SystemClock; -import android.provider.MediaStore; -import android.util.Log; - -public abstract class FerrariSensor { - - private static final String TAG = "FerrariSensor"; - - private static final String DOZE_INTENT = "com.android.systemui.doze.pulse"; - - private static final int SENSOR_WAKELOCK_DURATION = 200; - - protected static final int BATCH_LATENCY_IN_MS = 100; - - protected Context mContext; - protected PowerManager mPowerManager; - protected SensorManager mSensorManager; - protected Sensor mSensor; - protected int mType; - - private WakeLock mSensorWakeLock; - - public FerrariSensor(Context context, int type) { - mContext = context; - mType = type; - mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); - mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); - mSensor = mSensorManager.getDefaultSensor(mType); - mSensorWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, - "FerrariSensorWakeLock"); - } - - public void enable() { - mSensorManager.registerListener(mSensorEventListener, mSensor, - SensorManager.SENSOR_DELAY_NORMAL, BATCH_LATENCY_IN_MS * 1000); - } - - public void disable() { - mSensorManager.unregisterListener(mSensorEventListener); - } - - protected void launchDozePulse() { - Log.d(TAG, "Launch doze pulse"); - mContext.sendBroadcastAsUser(new Intent(DOZE_INTENT), - new UserHandle(UserHandle.USER_CURRENT)); - } - - protected abstract void onSensorEvent(SensorEvent event); - - private SensorEventListener mSensorEventListener = new SensorEventListener() { - @Override - public void onSensorChanged(SensorEvent event) { - onSensorEvent(event); - } - - @Override - public void onAccuracyChanged(Sensor sensor, int accuracy) { - /* Empty */ - } - }; -} diff --git a/doze/src/org/cyanogenmod/doze/ferrari/ProximitySensor.java b/doze/src/org/cyanogenmod/doze/ferrari/ProximitySensor.java deleted file mode 100644 index 14795b3..0000000 --- a/doze/src/org/cyanogenmod/doze/ferrari/ProximitySensor.java +++ /dev/null @@ -1,62 +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 org.cyanogenmod.doze.ferrari; - -import android.content.Context; -import android.hardware.Sensor; -import android.hardware.SensorEvent; -import android.os.SystemClock; -import android.util.Log; - -public class ProximitySensor extends FerrariSensor { - - private static final boolean DEBUG = false; - private static final String TAG = "ProximitySensor"; - private long mEntryTimestamp; - private static final int DELTA_MS = 250; // 250ms - - public ProximitySensor(Context context) { - super(context, Sensor.TYPE_PROXIMITY); - } - - @Override - public void enable() { - if (DEBUG) Log.d(TAG, "Enabling"); - super.enable(); - mEntryTimestamp = 0; - } - - @Override - public void disable() { - if (DEBUG) Log.d(TAG, "Disabling"); - super.disable(); - } - - @Override - protected void onSensorEvent(SensorEvent event) { - if (DEBUG) Log.d(TAG, "Got sensor event: " + event.values[0]); - - long delta = SystemClock.elapsedRealtime() - mEntryTimestamp; - boolean isNear = event.values[0] == 0; - - if ( !isNear && delta < DELTA_MS ) - { - launchDozePulse(); - } - mEntryTimestamp = SystemClock.elapsedRealtime(); - } -} diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml index 3090988..38d9975 100644 --- a/overlay/frameworks/base/core/res/res/values/config.xml +++ b/overlay/frameworks/base/core/res/res/values/config.xml @@ -208,9 +208,6 @@ that can be set by the user. --> <integer name="config_screenBrightnessDoze">17</integer> - <!-- enable doze powersaving mode --> - <bool name="config_enableAutoPowerModes">true</bool> - <!-- Whether device supports double tap to wake --> <bool name="config_supportDoubleTapWake">true</bool> diff --git a/overlay/frameworks/base/packages/SystemUI/res/values/config.xml b/overlay/frameworks/base/packages/SystemUI/res/values/config.xml index 389e929..643ceb8 100644 --- a/overlay/frameworks/base/packages/SystemUI/res/values/config.xml +++ b/overlay/frameworks/base/packages/SystemUI/res/values/config.xml @@ -23,20 +23,17 @@ <resources> <!-- Doze: does this device support STATE_DOZE and STATE_DOZE_SUSPEND? --> - <bool name="doze_display_state_supported">true</bool> + <bool name="doze_display_state_supported">false</bool> <!-- Doze: should the pickup sensor be used as a pulse signal? --> - <bool name="doze_pulse_on_pick_up">false</bool> + <bool name="doze_pulse_on_pick_up">true</bool> <!-- Doze: when to pulse after a buzzworthy notification arrives --> - <string name="doze_pulse_schedule" translatable="false">1s,5s,10s,30s,60s,180s</string> + <string name="doze_pulse_schedule" translatable="false">10s,30s,60s,180s</string> <!-- Doze: check proximity sensor before pulsing from intent? --> <bool name="doze_proximity_check_before_pulse_intent">true</bool> - <!-- Doze: pulse parameter - how long does it take to fade in after an intent? --> - <integer name="doze_pulse_duration_in_intent">0</integer> - <!-- Doze: pulse parameter - delay to wait for the screen to wake up after an intent --> <integer name="doze_pulse_delay_in_intent">0</integer> diff --git a/overlay/vendor/cmsdk/cm/res/res/values/config.xml b/overlay/vendor/cmsdk/cm/res/res/values/config.xml index 32637b5..caafe21 100644 --- a/overlay/vendor/cmsdk/cm/res/res/values/config.xml +++ b/overlay/vendor/cmsdk/cm/res/res/values/config.xml @@ -13,12 +13,6 @@ --> <resources> - <!-- Default value for proximity check on screen wake - NOTE ! - Enable for devices that have a fast response proximity sensor (ideally < 300ms)--> - <bool name="config_proximityCheckOnWake">true</bool> - <integer name="config_proximityCheckTimeout">200</integer> - <bool name="config_proximityCheckOnWakeEnabledByDefault">true</bool> - <!-- All the capabilities of the LEDs on this device, stored as a bit field. This integer should equal the sum of the corresponding value for each of the following capabilities present: diff --git a/product/doze.mk b/product/doze.mk index cebb18c..0d46ad7 100644 --- a/product/doze.mk +++ b/product/doze.mk @@ -1,3 +1,3 @@ # Doze PRODUCT_PACKAGES += \ - FerrariDoze + XiaomiDoze |
