sdm845-common: Add OnePlusDoze app for pickup sensor handling
* Based off android_device_oneplus_oneplus3 doze app but with proximity related features stripped out and updated pickup sensor name. Change-Id: I9f81b153948069cd4370c75817f12e91f6869e1d
This commit is contained in:
parent
73f4be30aa
commit
ee329ad0bb
16 changed files with 774 additions and 0 deletions
|
@ -70,6 +70,10 @@ PRODUCT_PACKAGES += \
|
||||||
PRODUCT_PACKAGES += \
|
PRODUCT_PACKAGES += \
|
||||||
libvulkan
|
libvulkan
|
||||||
|
|
||||||
|
# Doze
|
||||||
|
PRODUCT_PACKAGES += \
|
||||||
|
OnePlusDoze
|
||||||
|
|
||||||
# HotwordEnrollement app permissions
|
# HotwordEnrollement app permissions
|
||||||
PRODUCT_COPY_FILES += \
|
PRODUCT_COPY_FILES += \
|
||||||
$(LOCAL_PATH)/configs/privapp-permissions-hotword.xml:system/etc/permissions/privapp-permissions-hotword.xml
|
$(LOCAL_PATH)/configs/privapp-permissions-hotword.xml:system/etc/permissions/privapp-permissions-hotword.xml
|
||||||
|
|
29
doze/Android.mk
Normal file
29
doze/Android.mk
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
LOCAL_PATH := $(call my-dir)
|
||||||
|
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
|
||||||
|
LOCAL_MODULE_TAGS := optional
|
||||||
|
|
||||||
|
LOCAL_SRC_FILES := $(call all-java-files-under, src)
|
||||||
|
|
||||||
|
LOCAL_PACKAGE_NAME := OnePlusDoze
|
||||||
|
LOCAL_CERTIFICATE := platform
|
||||||
|
LOCAL_PRIVILEGED_MODULE := true
|
||||||
|
|
||||||
|
LOCAL_USE_AAPT2 := true
|
||||||
|
|
||||||
|
LOCAL_STATIC_ANDROID_LIBRARIES := \
|
||||||
|
android-support-v4 \
|
||||||
|
android-support-v13 \
|
||||||
|
android-support-v7-recyclerview \
|
||||||
|
android-support-v7-preference \
|
||||||
|
android-support-v7-appcompat \
|
||||||
|
android-support-v14-preference
|
||||||
|
|
||||||
|
LOCAL_RESOURCE_DIR := \
|
||||||
|
$(LOCAL_PATH)/res \
|
||||||
|
$(TOP)/packages/resources/devicesettings/res
|
||||||
|
|
||||||
|
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
|
||||||
|
|
||||||
|
include $(BUILD_PACKAGE)
|
59
doze/AndroidManifest.xml
Normal file
59
doze/AndroidManifest.xml
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2015-2016 The CyanogenMod Project
|
||||||
|
2017 The LineageOS 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.
|
||||||
|
-->
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="org.lineageos.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" />
|
||||||
|
|
||||||
|
<protected-broadcast android:name="com.android.systemui.doze.pulse" />
|
||||||
|
|
||||||
|
<uses-sdk
|
||||||
|
android:minSdkVersion="24"
|
||||||
|
android:targetSdkVersion="24"/>
|
||||||
|
|
||||||
|
<application
|
||||||
|
android:label="@string/device_settings_app_name"
|
||||||
|
android:persistent="true">
|
||||||
|
|
||||||
|
<receiver android:name=".BootCompletedReceiver">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
|
||||||
|
<service android:name=".DozeService"
|
||||||
|
android:permission="OneplusDozeService">
|
||||||
|
</service>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".DozeSettingsActivity"
|
||||||
|
android:label="@string/ambient_display_title"
|
||||||
|
android:theme="@style/Theme.Main">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="org.lineageos.settings.device.DOZE_SETTINGS" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
</application>
|
||||||
|
</manifest>
|
8
doze/proguard.flags
Normal file
8
doze/proguard.flags
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
-keepclasseswithmembers class * {
|
||||||
|
public <init>(android.content.Context, android.util.AttributeSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
-keep class ** extends android.support.v14.preference.PreferenceFragment
|
||||||
|
-keep class org.lineageos.settings.doze.* {
|
||||||
|
*;
|
||||||
|
}
|
20
doze/res/drawable/switchbar_background.xml
Normal file
20
doze/res/drawable/switchbar_background.xml
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<?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="?android:attr/colorSecondary" />
|
||||||
|
</ripple>
|
27
doze/res/layout/doze.xml
Normal file
27
doze/res/layout/doze.xml
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<?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>
|
47
doze/res/layout/switch_bar.xml
Normal file
47
doze/res/layout/switch_bar.xml
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
<?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/textColorPrimary"
|
||||||
|
android:textAlignment="viewStart" />
|
||||||
|
|
||||||
|
<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/Theme.Main.SwitchBar" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
55
doze/res/values/styles.xml
Normal file
55
doze/res/values/styles.xml
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2015-2016 The CyanogenMod Project
|
||||||
|
2017 The LineageOS 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">
|
||||||
|
<style name="Theme.Main" parent="@android:style/Theme.DeviceDefault.Settings">
|
||||||
|
<item name="dialogPreferenceStyle">@style/Theme.Main.DialogPreferenceStyle</item>
|
||||||
|
<item name="preferenceCategoryStyle">@style/Theme.Main.PreferenceCategoryStyle</item>
|
||||||
|
<item name="preferenceFragmentStyle">@style/Theme.Main.PreferenceFragmentStyle</item>
|
||||||
|
<item name="preferenceStyle">@style/Theme.Main.PreferenceStyle</item>
|
||||||
|
<item name="preferenceTheme">@style/Theme.Main.PreferenceTheme</item>
|
||||||
|
<item name="switchPreferenceStyle">@style/Theme.Main.SwitchPreferenceStyle</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="Theme.Main.DialogPreferenceStyle" parent="@style/Theme.Main.PreferenceStyle" />
|
||||||
|
|
||||||
|
<style name="Theme.Main.PreferenceCategoryStyle" parent="@*android:style/Preference.DeviceDefault.Category">
|
||||||
|
<item name="allowDividerAbove">true</item>
|
||||||
|
<item name="allowDividerBelow">true</item>
|
||||||
|
<item name="android:layout">@layout/preference_category_material_settings</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="Theme.Main.PreferenceFragmentStyle" parent="@*android:style/PreferenceFragment.Material">
|
||||||
|
<item name="allowDividerAfterLastItem">false</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="Theme.Main.PreferenceStyle" parent="@*android:style/Preference.DeviceDefault">
|
||||||
|
<item name="allowDividerAbove">false</item>
|
||||||
|
<item name="allowDividerBelow">true</item>
|
||||||
|
<item name="singleLineTitle">false</item>
|
||||||
|
<item name="android:layout">@layout/preference_material_settings</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="Theme.Main.PreferenceTheme" />
|
||||||
|
|
||||||
|
<style name="Theme.Main.SwitchPreferenceStyle" parent="@style/Theme.Main.PreferenceStyle">
|
||||||
|
<item name="widgetLayout">@*android:layout/preference_widget_switch</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="Theme.Main.SwitchBar" parent="@android:style/ThemeOverlay.Material.ActionBar">
|
||||||
|
</style>
|
||||||
|
</resources>
|
31
doze/res/xml/doze_settings.xml
Normal file
31
doze/res/xml/doze_settings.xml
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
<?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="pickup_sensor"
|
||||||
|
android:title="@string/pickup_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>
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 The CyanogenMod Project
|
||||||
|
* 2017 The LineageOS 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.doze;
|
||||||
|
|
||||||
|
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 = "OnePlusDoze";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(final Context context, Intent intent) {
|
||||||
|
if (Utils.isDozeEnabled(context) && Utils.isPickUpEnabled(context)) {
|
||||||
|
if (DEBUG) Log.d(TAG, "Starting service");
|
||||||
|
Utils.startService(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
88
doze/src/org/lineageos/settings/doze/DozeService.java
Normal file
88
doze/src/org/lineageos/settings/doze/DozeService.java
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 The CyanogenMod Project
|
||||||
|
* 2017-2018 The LineageOS 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.doze;
|
||||||
|
|
||||||
|
import android.app.Service;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
import android.os.IBinder;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
public class DozeService extends Service {
|
||||||
|
private static final String TAG = "DozeService";
|
||||||
|
private static final boolean DEBUG = false;
|
||||||
|
|
||||||
|
private PickupSensor mPickupSensor;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate() {
|
||||||
|
if (DEBUG) Log.d(TAG, "Creating service");
|
||||||
|
mPickupSensor = new PickupSensor(this);
|
||||||
|
|
||||||
|
IntentFilter screenStateFilter = new IntentFilter();
|
||||||
|
screenStateFilter.addAction(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");
|
||||||
|
return START_STICKY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
if (DEBUG) Log.d(TAG, "Destroying service");
|
||||||
|
super.onDestroy();
|
||||||
|
this.unregisterReceiver(mScreenStateReceiver);
|
||||||
|
mPickupSensor.disable();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IBinder onBind(Intent intent) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onDisplayOn() {
|
||||||
|
if (DEBUG) Log.d(TAG, "Display on");
|
||||||
|
if (Utils.isPickUpEnabled(this)) {
|
||||||
|
mPickupSensor.disable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onDisplayOff() {
|
||||||
|
if (DEBUG) Log.d(TAG, "Display off");
|
||||||
|
if (Utils.isPickUpEnabled(this)) {
|
||||||
|
mPickupSensor.enable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private BroadcastReceiver mScreenStateReceiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
|
||||||
|
onDisplayOn();
|
||||||
|
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
|
||||||
|
onDisplayOff();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015-2016 The CyanogenMod Project
|
||||||
|
* 2017 The LineageOS 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.doze;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceActivity;
|
||||||
|
|
||||||
|
public class DozeSettingsActivity extends PreferenceActivity {
|
||||||
|
|
||||||
|
private static final String TAG_DOZE = "doze";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
getFragmentManager().beginTransaction().replace(android.R.id.content,
|
||||||
|
new DozeSettingsFragment(), TAG_DOZE).commit();
|
||||||
|
}
|
||||||
|
}
|
141
doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java
Normal file
141
doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java
Normal file
|
@ -0,0 +1,141 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 The CyanogenMod Project
|
||||||
|
* 2017-2018 The LineageOS 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.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.os.Bundle;
|
||||||
|
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.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
|
import android.widget.Switch;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
public class DozeSettingsFragment extends PreferenceFragment implements OnPreferenceChangeListener,
|
||||||
|
CompoundButton.OnCheckedChangeListener {
|
||||||
|
|
||||||
|
private TextView mTextView;
|
||||||
|
|
||||||
|
private SwitchPreference mPickUpPreference;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||||
|
addPreferencesFromResource(R.xml.doze_settings);
|
||||||
|
final ActionBar actionBar = getActivity().getActionBar();
|
||||||
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
|
SharedPreferences prefs = getActivity().getSharedPreferences("doze_settings",
|
||||||
|
Activity.MODE_PRIVATE);
|
||||||
|
if (savedInstanceState == null && !prefs.getBoolean("first_help_shown", false)) {
|
||||||
|
showHelp();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean dozeEnabled = Utils.isDozeEnabled(getActivity());
|
||||||
|
|
||||||
|
mPickUpPreference = (SwitchPreference) findPreference(Utils.GESTURE_PICK_UP_KEY);
|
||||||
|
mPickUpPreference.setEnabled(dozeEnabled);
|
||||||
|
mPickUpPreference.setOnPreferenceChangeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 onViewCreated(View view, Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
|
boolean dozeEnabled = Utils.isDozeEnabled(getActivity());
|
||||||
|
|
||||||
|
mTextView = view.findViewById(R.id.switch_text);
|
||||||
|
mTextView.setText(getString(dozeEnabled ?
|
||||||
|
R.string.switch_bar_on : R.string.switch_bar_off));
|
||||||
|
|
||||||
|
View switchBar = view.findViewById(R.id.switch_bar);
|
||||||
|
Switch switchWidget = switchBar.findViewById(android.R.id.switch_widget);
|
||||||
|
switchWidget.setChecked(dozeEnabled);
|
||||||
|
switchWidget.setOnCheckedChangeListener(this);
|
||||||
|
switchBar.setOnClickListener(v -> switchWidget.setChecked(!switchWidget.isChecked()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
Utils.enablePickUp(getActivity(), (Boolean) newValue);
|
||||||
|
Utils.checkDozeService(getActivity());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
|
||||||
|
Utils.enableDoze(getActivity(), isChecked);
|
||||||
|
Utils.checkDozeService(getActivity());
|
||||||
|
|
||||||
|
mTextView.setText(getString(isChecked ? R.string.switch_bar_on : R.string.switch_bar_off));
|
||||||
|
|
||||||
|
mPickUpPreference.setEnabled(isChecked);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
if (item.getItemId() == android.R.id.home) {
|
||||||
|
getActivity().onBackPressed();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private 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, (dialog, 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");
|
||||||
|
}
|
||||||
|
}
|
93
doze/src/org/lineageos/settings/doze/PickupSensor.java
Normal file
93
doze/src/org/lineageos/settings/doze/PickupSensor.java
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 The CyanogenMod Project
|
||||||
|
* 2017-2018 The LineageOS 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.doze;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.hardware.Sensor;
|
||||||
|
import android.hardware.SensorEvent;
|
||||||
|
import android.hardware.SensorEventListener;
|
||||||
|
import android.hardware.SensorManager;
|
||||||
|
import android.os.SystemClock;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
|
public class PickupSensor implements SensorEventListener {
|
||||||
|
|
||||||
|
private static final boolean DEBUG = false;
|
||||||
|
private static final String TAG = "PickupSensor";
|
||||||
|
|
||||||
|
private static final int MIN_PULSE_INTERVAL_MS = 2500;
|
||||||
|
|
||||||
|
private SensorManager mSensorManager;
|
||||||
|
private Sensor mSensor;
|
||||||
|
private Context mContext;
|
||||||
|
private ExecutorService mExecutorService;
|
||||||
|
|
||||||
|
private long mEntryTimestamp;
|
||||||
|
|
||||||
|
public PickupSensor(Context context) {
|
||||||
|
mContext = context;
|
||||||
|
mSensorManager = mContext.getSystemService(SensorManager.class);
|
||||||
|
mSensor = Utils.getSensor(mSensorManager, "oneplus.sensor.pickup");
|
||||||
|
mExecutorService = Executors.newSingleThreadExecutor();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Future<?> submit(Runnable runnable) {
|
||||||
|
return mExecutorService.submit(runnable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSensorChanged(SensorEvent event) {
|
||||||
|
if (DEBUG) Log.d(TAG, "Got sensor event: " + event.values[0]);
|
||||||
|
|
||||||
|
long delta = SystemClock.elapsedRealtime() - mEntryTimestamp;
|
||||||
|
if (delta < MIN_PULSE_INTERVAL_MS) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mEntryTimestamp = SystemClock.elapsedRealtime();
|
||||||
|
|
||||||
|
if (event.values[0] == 1) {
|
||||||
|
Utils.launchDozePulse(mContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||||
|
/* Empty */
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void enable() {
|
||||||
|
if (DEBUG) Log.d(TAG, "Enabling");
|
||||||
|
submit(() -> {
|
||||||
|
mSensorManager.registerListener(this, mSensor,
|
||||||
|
SensorManager.SENSOR_DELAY_NORMAL);
|
||||||
|
mEntryTimestamp = SystemClock.elapsedRealtime();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void disable() {
|
||||||
|
if (DEBUG) Log.d(TAG, "Disabling");
|
||||||
|
submit(() -> {
|
||||||
|
mSensorManager.unregisterListener(this, mSensor);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
94
doze/src/org/lineageos/settings/doze/Utils.java
Normal file
94
doze/src/org/lineageos/settings/doze/Utils.java
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 The CyanogenMod Project
|
||||||
|
* 2017-2018 The LineageOS 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.doze;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.hardware.Sensor;
|
||||||
|
import android.hardware.SensorManager;
|
||||||
|
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 GESTURE_PICK_UP_KEY = "gesture_pick_up";
|
||||||
|
|
||||||
|
protected static void startService(Context context) {
|
||||||
|
if (DEBUG) Log.d(TAG, "Starting service");
|
||||||
|
context.startServiceAsUser(new Intent(context, DozeService.class),
|
||||||
|
UserHandle.CURRENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void stopService(Context context) {
|
||||||
|
if (DEBUG) Log.d(TAG, "Stopping service");
|
||||||
|
context.stopServiceAsUser(new Intent(context, DozeService.class),
|
||||||
|
UserHandle.CURRENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void checkDozeService(Context context) {
|
||||||
|
if (isDozeEnabled(context) && isPickUpEnabled(context)) {
|
||||||
|
startService(context);
|
||||||
|
} else {
|
||||||
|
stopService(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static boolean isDozeEnabled(Context context) {
|
||||||
|
return Settings.Secure.getInt(context.getContentResolver(),
|
||||||
|
DOZE_ENABLED, 1) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static boolean enableDoze(Context context, boolean enable) {
|
||||||
|
return Settings.Secure.putInt(context.getContentResolver(),
|
||||||
|
DOZE_ENABLED, enable ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 void enablePickUp(Context context, boolean enable) {
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(context).edit()
|
||||||
|
.putBoolean(GESTURE_PICK_UP_KEY, enable).apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static boolean isPickUpEnabled(Context context) {
|
||||||
|
return PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
.getBoolean(GESTURE_PICK_UP_KEY, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static Sensor getSensor(SensorManager sm, String type) {
|
||||||
|
for (Sensor sensor : sm.getSensorList(Sensor.TYPE_ALL)) {
|
||||||
|
if (type.equals(sensor.getStringType())) {
|
||||||
|
return sensor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
6
lineage.dependencies
Normal file
6
lineage.dependencies
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"repository": "android_packages_resources_devicesettings",
|
||||||
|
"target_path": "packages/resources/devicesettings"
|
||||||
|
}
|
||||||
|
]
|
Loading…
Reference in a new issue