doze: Make all features optional
This change makes all users of doze app declare supported sensors in their device tree overlays. Change-Id: I6444da1e8b42d0064a04981632c84f6c90ddaee7
This commit is contained in:
21
doze/res/values/config.xml
Normal file
21
doze/res/values/config.xml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2021 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>
|
||||||
|
<!-- Sensor types -->
|
||||||
|
<string name="pickup_sensor_type"></string>
|
||||||
|
<string name="pocket_sensor_type"></string>
|
||||||
|
</resources>
|
||||||
@@ -93,6 +93,16 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
|
|||||||
pickupSensorCategory.setDependency(Utils.ALWAYS_ON_DISPLAY);
|
pickupSensorCategory.setDependency(Utils.ALWAYS_ON_DISPLAY);
|
||||||
proximitySensorCategory.setDependency(Utils.ALWAYS_ON_DISPLAY);
|
proximitySensorCategory.setDependency(Utils.ALWAYS_ON_DISPLAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hide pickup sensor category if its sensor type is empty
|
||||||
|
if (getString(R.string.pickup_sensor_type).isEmpty()) {
|
||||||
|
getPreferenceScreen().removePreference(pickupSensorCategory);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hide proximity sensor category if its sensor type is empty
|
||||||
|
if (getString(R.string.pocket_sensor_type).isEmpty()) {
|
||||||
|
getPreferenceScreen().removePreference(proximitySensorCategory);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -53,7 +53,8 @@ public class PickupSensor implements SensorEventListener {
|
|||||||
mContext = context;
|
mContext = context;
|
||||||
mPowerManager = mContext.getSystemService(PowerManager.class);
|
mPowerManager = mContext.getSystemService(PowerManager.class);
|
||||||
mSensorManager = mContext.getSystemService(SensorManager.class);
|
mSensorManager = mContext.getSystemService(SensorManager.class);
|
||||||
mSensor = Utils.getSensor(mSensorManager, "oneplus.sensor.pickup");
|
mSensor = Utils.getSensor(mSensorManager,
|
||||||
|
context.getResources().getString(R.string.pickup_sensor_type));
|
||||||
mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
|
mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
|
||||||
mExecutorService = Executors.newSingleThreadExecutor();
|
mExecutorService = Executors.newSingleThreadExecutor();
|
||||||
}
|
}
|
||||||
@@ -90,6 +91,7 @@ public class PickupSensor implements SensorEventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void enable() {
|
protected void enable() {
|
||||||
|
if (mSensor == null) return;
|
||||||
if (DEBUG) Log.d(TAG, "Enabling");
|
if (DEBUG) Log.d(TAG, "Enabling");
|
||||||
submit(() -> {
|
submit(() -> {
|
||||||
mEntryTimestamp = SystemClock.elapsedRealtime();
|
mEntryTimestamp = SystemClock.elapsedRealtime();
|
||||||
@@ -99,6 +101,7 @@ public class PickupSensor implements SensorEventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void disable() {
|
protected void disable() {
|
||||||
|
if (mSensor == null) return;
|
||||||
if (DEBUG) Log.d(TAG, "Disabling");
|
if (DEBUG) Log.d(TAG, "Disabling");
|
||||||
submit(() -> {
|
submit(() -> {
|
||||||
mSensorManager.unregisterListener(this, mSensor);
|
mSensorManager.unregisterListener(this, mSensor);
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ public class PocketSensor implements SensorEventListener {
|
|||||||
public PocketSensor(Context context) {
|
public PocketSensor(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mSensorManager = mContext.getSystemService(SensorManager.class);
|
mSensorManager = mContext.getSystemService(SensorManager.class);
|
||||||
mSensor = Utils.getSensor(mSensorManager, "oneplus.sensor.pocket");
|
mSensor = Utils.getSensor(mSensorManager,
|
||||||
|
context.getResources().getString(R.string.pocket_sensor_type));
|
||||||
mExecutorService = Executors.newSingleThreadExecutor();
|
mExecutorService = Executors.newSingleThreadExecutor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,6 +77,7 @@ public class PocketSensor implements SensorEventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void enable() {
|
protected void enable() {
|
||||||
|
if (mSensor == null) return;
|
||||||
if (DEBUG) Log.d(TAG, "Enabling");
|
if (DEBUG) Log.d(TAG, "Enabling");
|
||||||
submit(() -> {
|
submit(() -> {
|
||||||
mEntryTimestamp = SystemClock.elapsedRealtime();
|
mEntryTimestamp = SystemClock.elapsedRealtime();
|
||||||
@@ -85,6 +87,7 @@ public class PocketSensor implements SensorEventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void disable() {
|
protected void disable() {
|
||||||
|
if (mSensor == null) return;
|
||||||
if (DEBUG) Log.d(TAG, "Disabling");
|
if (DEBUG) Log.d(TAG, "Disabling");
|
||||||
submit(() -> {
|
submit(() -> {
|
||||||
mSensorManager.unregisterListener(this, mSensor);
|
mSensorManager.unregisterListener(this, mSensor);
|
||||||
|
|||||||
Reference in New Issue
Block a user