mirror of
https://github.com/oplus-giulia-dev/android_hardware_oplus
synced 2025-11-04 05:45:34 +08:00
doze: Move sensor trigger values to resources
This lets us use android.sensor.tilt_detector on Oplus. Change-Id: I21db794d86656bfa41dfe32d33b272d4b55ec199
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2021 The LineageOS Project
|
||||
Copyright (C) 2021-2022 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.
|
||||
@@ -18,4 +18,8 @@
|
||||
<!-- Sensor types -->
|
||||
<string name="pickup_sensor_type"></string>
|
||||
<string name="pocket_sensor_type"></string>
|
||||
|
||||
<!-- Sensor trigger values -->
|
||||
<item name="pickup_sensor_value" format="float" type="dimen">1.0</item>
|
||||
<item name="pocket_sensor_value" format="float" type="dimen">0.0</item>
|
||||
</resources>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The LineageOS Project
|
||||
* Copyright (C) 2021-2022 The LineageOS Project
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
@@ -28,8 +28,16 @@ class DozeService : Service() {
|
||||
|
||||
override fun onCreate() {
|
||||
Log.d(TAG, "Creating service")
|
||||
pickupSensor = PickupSensor(this, resources.getString(R.string.pickup_sensor_type))
|
||||
pocketSensor = PocketSensor(this, resources.getString(R.string.pocket_sensor_type))
|
||||
pickupSensor = PickupSensor(
|
||||
this,
|
||||
resources.getString(R.string.pickup_sensor_type),
|
||||
resources.getFloat(R.dimen.pickup_sensor_value),
|
||||
)
|
||||
pocketSensor = PocketSensor(
|
||||
this,
|
||||
resources.getString(R.string.pocket_sensor_type),
|
||||
resources.getFloat(R.dimen.pocket_sensor_value)
|
||||
)
|
||||
|
||||
val screenStateFilter = IntentFilter()
|
||||
screenStateFilter.addAction(Intent.ACTION_SCREEN_ON)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The LineageOS Project
|
||||
* Copyright (C) 2021-2022 The LineageOS Project
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
@@ -16,7 +16,9 @@ import android.util.Log
|
||||
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
class PickupSensor(private val context: Context, sensorType: String) : SensorEventListener {
|
||||
class PickupSensor(
|
||||
private val context: Context, sensorType: String, private val sensorValue: Float
|
||||
) : SensorEventListener {
|
||||
private val powerManager = context.getSystemService(PowerManager::class.java)
|
||||
private val wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG)
|
||||
|
||||
@@ -33,7 +35,7 @@ class PickupSensor(private val context: Context, sensorType: String) : SensorEve
|
||||
return
|
||||
}
|
||||
entryTimestamp = SystemClock.elapsedRealtime()
|
||||
if (event.values[0] == 1.0f) {
|
||||
if (event.values[0] == sensorValue) {
|
||||
if (Utils.isPickUpSetToWake(context)) {
|
||||
wakeLock.acquire(WAKELOCK_TIMEOUT_MS)
|
||||
powerManager.wakeUpWithProximityCheck(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The LineageOS Project
|
||||
* Copyright (C) 2021-2022 The LineageOS Project
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
@@ -15,7 +15,9 @@ import android.util.Log
|
||||
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
class PocketSensor(private val context: Context, sensorType: String) : SensorEventListener {
|
||||
class PocketSensor(
|
||||
private val context: Context, sensorType: String, private val sensorValue: Float
|
||||
) : SensorEventListener {
|
||||
private val sensorManager = context.getSystemService(SensorManager::class.java)
|
||||
private val sensor = Utils.getSensor(sensorManager, sensorType)
|
||||
|
||||
@@ -29,7 +31,7 @@ class PocketSensor(private val context: Context, sensorType: String) : SensorEve
|
||||
return
|
||||
}
|
||||
entryTimestamp = SystemClock.elapsedRealtime()
|
||||
if (event.values[0] == 0.0f) {
|
||||
if (event.values[0] == sensorValue) {
|
||||
Utils.launchDozePulse(context)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user