aboutsummaryrefslogtreecommitdiff
path: root/pocketmode
diff options
context:
space:
mode:
authorBruno Martins <bgcngm@gmail.com>2019-05-10 21:25:31 +0200
committerDavide Garberi <dade.garberi@gmail.com>2019-05-10 23:26:10 +0200
commitc3d328b6be521feff20f9d10f755716d4d639cc7 (patch)
treee4ff8fa2805d9349181c7cdf976f2ed5f3e01e77 /pocketmode
parente95cf897590b5ab6b25ac286e8baf6eaec9dd297 (diff)
msm8996-common: pocketmode: Allow control over PocketMode service
* Once the service is running, proximity sensor is constantly active when the display is turned off, resulting into a residual increase in battery consumption. Add a toggle so that users can decide whether they accept that and prefer to prevent accidental wake-ups triggered by the fingerprint sensor. * Keep the receiver that listens for the screen status registered only if the fingerprint wake-up feature is enabled at the same time as the accidental wake-up prevention feature. * Set PocketMode as a required module of ConfigPanel, to make sure it is only shipped on devices building the latter. * The configpanel part is integrated in b07a633bdeda835867aa3dc5a033529d7bd712dc Change-Id: Icfa23d2aef971e368476b6f1f7612493c2b69a20
Diffstat (limited to 'pocketmode')
-rw-r--r--pocketmode/AndroidManifest.xml38
-rw-r--r--pocketmode/src/org/lineageos/pocketmode/PocketModeService.java36
-rw-r--r--pocketmode/src/org/lineageos/pocketmode/ProximitySensor.java11
-rw-r--r--pocketmode/src/org/lineageos/pocketmode/Startup.java (renamed from pocketmode/src/org/lineageos/pocketmode/BootCompletedReceiver.java)15
4 files changed, 74 insertions, 26 deletions
diff --git a/pocketmode/AndroidManifest.xml b/pocketmode/AndroidManifest.xml
index e462eb2..fe9e42f 100644
--- a/pocketmode/AndroidManifest.xml
+++ b/pocketmode/AndroidManifest.xml
@@ -1,29 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2016 The CyanogenMod Project
+ Copyright (C) 2017-2019 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.pocketmode"
android:versionCode="1"
- android:versionName="1.1"
+ android:versionName="1.2"
android:sharedUserId="android.uid.system">
- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
+ <uses-permission android:name="lineageos.permission.HARDWARE_ABSTRACTION_ACCESS" />
<uses-sdk
- android:minSdkVersion="27"
- android:targetSdkVersion="27"/>
+ android:minSdkVersion="27" />
<application
android:label="ZukPocketMode"
- android:persistent="true">
+ android:persistent="true"
+ android:defaultToDeviceProtectedStorage="true"
+ android:directBootAware="true">
- <receiver android:name="org.lineageos.pocketmode.BootCompletedReceiver">
- <intent-filter>
- <action android:name="android.intent.action.BOOT_COMPLETED" />
- <category android:name="android.intent.category.DEFAULT" />
+ <receiver android:name=".Startup" >
+ <intent-filter android:priority="99" >
+ <action android:name="lineageos.intent.action.INITIALIZE_LINEAGE_HARDWARE" />
</intent-filter>
</receiver>
- <service android:name="org.lineageos.pocketmode.PocketModeService"
- android:permission="ZukPocketModeService">
+ <service android:name=".PocketModeService"
+ android:permission="PocketModeService">
</service>
<activity android:name="PocketMode"
diff --git a/pocketmode/src/org/lineageos/pocketmode/PocketModeService.java b/pocketmode/src/org/lineageos/pocketmode/PocketModeService.java
index 42658b9..3af4654 100644
--- a/pocketmode/src/org/lineageos/pocketmode/PocketModeService.java
+++ b/pocketmode/src/org/lineageos/pocketmode/PocketModeService.java
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2016 The CyanogenMod Project
- * Copyright (c) 2018 The LineageOS Project
+ * 2018-2019 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.
@@ -25,10 +25,18 @@ import android.content.IntentFilter;
import android.os.IBinder;
import android.util.Log;
+import java.util.ArrayList;
+import java.util.List;
+
public class PocketModeService extends Service {
private static final String TAG = "PocketModeService";
private static final boolean DEBUG = false;
+ private static final String CUST_INTENT = "org.lineageos.settings.device.CUST_UPDATE";
+ private static final String CUST_INTENT_EXTRA = "pocketmode_service";
+
+ private static List<BroadcastReceiver> receivers = new ArrayList<BroadcastReceiver>();
+
private ProximitySensor mProximitySensor;
@Override
@@ -36,9 +44,8 @@ public class PocketModeService extends Service {
if (DEBUG) Log.d(TAG, "Creating service");
mProximitySensor = new ProximitySensor(this);
- IntentFilter screenStateFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
- screenStateFilter.addAction(Intent.ACTION_SCREEN_OFF);
- registerReceiver(mScreenStateReceiver, screenStateFilter);
+ IntentFilter custFilter = new IntentFilter(CUST_INTENT);
+ registerReceiver(mUpdateReceiver, custFilter);
}
@Override
@@ -51,7 +58,10 @@ public class PocketModeService extends Service {
public void onDestroy() {
if (DEBUG) Log.d(TAG, "Destroying service");
super.onDestroy();
- this.unregisterReceiver(mScreenStateReceiver);
+ if (receivers.contains(mScreenStateReceiver)) {
+ this.unregisterReceiver(mScreenStateReceiver);
+ }
+ this.unregisterReceiver(mUpdateReceiver);
mProximitySensor.disable();
}
@@ -80,4 +90,20 @@ public class PocketModeService extends Service {
}
}
};
+
+ private BroadcastReceiver mUpdateReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent.getBooleanExtra(CUST_INTENT_EXTRA, false)) {
+ IntentFilter screenStateFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
+ screenStateFilter.addAction(Intent.ACTION_SCREEN_OFF);
+ registerReceiver(mScreenStateReceiver, screenStateFilter);
+ receivers.add(mScreenStateReceiver);
+ } else if (receivers.contains(mScreenStateReceiver)) {
+ unregisterReceiver(mScreenStateReceiver);
+ receivers.remove(mScreenStateReceiver);
+ mProximitySensor.disable();
+ }
+ }
+ };
}
diff --git a/pocketmode/src/org/lineageos/pocketmode/ProximitySensor.java b/pocketmode/src/org/lineageos/pocketmode/ProximitySensor.java
index c1af4e8..4f1402c 100644
--- a/pocketmode/src/org/lineageos/pocketmode/ProximitySensor.java
+++ b/pocketmode/src/org/lineageos/pocketmode/ProximitySensor.java
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2016 The CyanogenMod Project
- * Copyright (c) 2018 The LineageOS Project
+ * 2018-2019 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.
@@ -31,7 +31,7 @@ public class ProximitySensor implements SensorEventListener {
private static final boolean DEBUG = false;
private static final String TAG = "PocketModeProximity";
- private static final String FPC_FILE = "/sys/devices/soc/soc:fpc1020/proximity_state";
+ private static final String FP_PROX_NODE = "/sys/devices/soc/soc:fpc1020/proximity_state";
private SensorManager mSensorManager;
private Sensor mSensor;
@@ -39,15 +39,16 @@ public class ProximitySensor implements SensorEventListener {
public ProximitySensor(Context context) {
mContext = context;
- mSensorManager = mContext.getSystemService(SensorManager.class);
+ 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 (FileUtils.isFileWritable(FPC_FILE)) {
- FileUtils.writeLine(FPC_FILE, isNear ? "1" : "0");
+ if (FileUtils.isFileWritable(FP_PROX_NODE)) {
+ FileUtils.writeLine(FP_PROX_NODE, isNear ? "1" : "0");
}
}
diff --git a/pocketmode/src/org/lineageos/pocketmode/BootCompletedReceiver.java b/pocketmode/src/org/lineageos/pocketmode/Startup.java
index b967946..39b3371 100644
--- a/pocketmode/src/org/lineageos/pocketmode/BootCompletedReceiver.java
+++ b/pocketmode/src/org/lineageos/pocketmode/Startup.java
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2016 The CyanogenMod Project
- * Copyright (c) 2018 The LineageOS Project
+ * 2018-2019 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.
@@ -20,15 +20,20 @@ package org.lineageos.pocketmode;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.os.UserHandle;
import android.util.Log;
-public class BootCompletedReceiver extends BroadcastReceiver {
+public class Startup extends BroadcastReceiver {
private static final String TAG = "ZukPocketMode";
@Override
- public void onReceive(final Context context, Intent intent) {
- Log.d(TAG, "Starting");
- context.startService(new Intent(context, PocketModeService.class));
+ public void onReceive(Context context, Intent intent) {
+ final String action = intent.getAction();
+ if (lineageos.content.Intent.ACTION_INITIALIZE_LINEAGE_HARDWARE.equals(action)) {
+ Log.d(TAG, "Starting");
+ context.startServiceAsUser(new Intent(context, PocketModeService.class),
+ UserHandle.CURRENT);
+ }
}
}