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);
|
||||
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
|
||||
|
||||
@@ -53,7 +53,8 @@ public class PickupSensor implements SensorEventListener {
|
||||
mContext = context;
|
||||
mPowerManager = mContext.getSystemService(PowerManager.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);
|
||||
mExecutorService = Executors.newSingleThreadExecutor();
|
||||
}
|
||||
@@ -90,6 +91,7 @@ public class PickupSensor implements SensorEventListener {
|
||||
}
|
||||
|
||||
protected void enable() {
|
||||
if (mSensor == null) return;
|
||||
if (DEBUG) Log.d(TAG, "Enabling");
|
||||
submit(() -> {
|
||||
mEntryTimestamp = SystemClock.elapsedRealtime();
|
||||
@@ -99,6 +101,7 @@ public class PickupSensor implements SensorEventListener {
|
||||
}
|
||||
|
||||
protected void disable() {
|
||||
if (mSensor == null) return;
|
||||
if (DEBUG) Log.d(TAG, "Disabling");
|
||||
submit(() -> {
|
||||
mSensorManager.unregisterListener(this, mSensor);
|
||||
|
||||
@@ -46,7 +46,8 @@ public class PocketSensor implements SensorEventListener {
|
||||
public PocketSensor(Context context) {
|
||||
mContext = context;
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -76,6 +77,7 @@ public class PocketSensor implements SensorEventListener {
|
||||
}
|
||||
|
||||
protected void enable() {
|
||||
if (mSensor == null) return;
|
||||
if (DEBUG) Log.d(TAG, "Enabling");
|
||||
submit(() -> {
|
||||
mEntryTimestamp = SystemClock.elapsedRealtime();
|
||||
@@ -85,6 +87,7 @@ public class PocketSensor implements SensorEventListener {
|
||||
}
|
||||
|
||||
protected void disable() {
|
||||
if (mSensor == null) return;
|
||||
if (DEBUG) Log.d(TAG, "Disabling");
|
||||
submit(() -> {
|
||||
mSensorManager.unregisterListener(this, mSensor);
|
||||
|
||||
Reference in New Issue
Block a user