Run pre-commit run --all

Change-Id: Iedb907afb4da921dfc9e2b706cfa63fd1467394d
This commit is contained in:
LuK1337
2026-01-01 14:10:48 +01:00
committed by TechPanelGM
parent af8b5b2101
commit 7a26bb680c
19 changed files with 339 additions and 305 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -14,35 +14,34 @@ import android.util.Log
object EuiccDisabler {
private const val TAG = "OplusEuiccDisabler"
private val EUICC_DEPENDENCIES = listOf(
"com.google.android.gms",
"com.google.android.gsf",
)
private val EUICC_DEPENDENCIES = listOf("com.google.android.gms", "com.google.android.gsf")
private val EUICC_PACKAGES = listOf(
"com.google.android.euicc",
"com.google.android.ims",
)
private val EUICC_PACKAGES = listOf("com.google.android.euicc", "com.google.android.ims")
private fun isInstalled(pm: PackageManager, pkgName: String) = runCatching {
val info = pm.getApplicationInfo(pkgName, ApplicationInfoFlags.of(0))
info.flags and ApplicationInfo.FLAG_INSTALLED != 0
}.getOrDefault(false)
private fun isInstalled(pm: PackageManager, pkgName: String) =
runCatching {
val info = pm.getApplicationInfo(pkgName, ApplicationInfoFlags.of(0))
info.flags and ApplicationInfo.FLAG_INSTALLED != 0
}
.getOrDefault(false)
private fun isInstalledAndEnabled(pm: PackageManager, pkgName: String) = runCatching {
val info = pm.getApplicationInfo(pkgName, ApplicationInfoFlags.of(0))
Log.d(TAG, "package $pkgName installed, enabled = ${info.enabled}")
info.enabled
}.getOrDefault(false)
private fun isInstalledAndEnabled(pm: PackageManager, pkgName: String) =
runCatching {
val info = pm.getApplicationInfo(pkgName, ApplicationInfoFlags.of(0))
Log.d(TAG, "package $pkgName installed, enabled = ${info.enabled}")
info.enabled
}
.getOrDefault(false)
fun enableOrDisableEuicc(context: Context) {
val pm = context.packageManager
val disable = EUICC_DEPENDENCIES.any { !isInstalledAndEnabled(pm, it) }
val flag = if (disable) {
PackageManager.COMPONENT_ENABLED_STATE_DISABLED
} else {
PackageManager.COMPONENT_ENABLED_STATE_ENABLED
}
val flag =
if (disable) {
PackageManager.COMPONENT_ENABLED_STATE_DISABLED
} else {
PackageManager.COMPONENT_ENABLED_STATE_ENABLED
}
for (pkg in EUICC_PACKAGES) {
if (isInstalled(pm, pkg)) {

View File

@@ -22,113 +22,131 @@ import vendor.oplus.hardware.biometrics.fingerprintpay.IFingerprintPay
class IfaaService : Service() {
private var _fpPayService: IFingerprintPay? = null
private val fpPayServiceDeathRecipient = IBinder.DeathRecipient {
Log.i(LOG_TAG, "aidl FingerprintPay hal died, reset hal proxy!")
_fpPayService = null
}
private val fpPayServiceDeathRecipient =
IBinder.DeathRecipient {
Log.i(LOG_TAG, "aidl FingerprintPay hal died, reset hal proxy!")
_fpPayService = null
}
private val fingerprintManager by lazy { getSystemService(FingerprintManager::class.java)!! }
private val keyguardManager by lazy { getSystemService(KeyguardManager::class.java)!! }
private val windowManager by lazy { getSystemService(WindowManager::class.java)!! }
override fun onBind(intent: Intent) = object : IfaaManagerService.Stub() {
private val _supportBIOTypes by lazy {
when (SystemProperties.get(FP_TYPE_PROP, "")) {
"back", "side", "front" -> AUTH_TYPE_FINGERPRINT
"ultrasonic", "optical" -> AUTH_TYPE_OPTICAL_FINGERPRINT
else -> AUTH_TYPE_NOT_SUPPORT
}
}
override fun getSupportBIOTypes() = _supportBIOTypes
override fun startBIOManager(authType: Int) = when (authType) {
AUTH_TYPE_FINGERPRINT -> {
applicationContext.startActivity(
Intent(Settings.ACTION_SECURITY_SETTINGS).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
)
COMMAND_OK
override fun onBind(intent: Intent) =
object : IfaaManagerService.Stub() {
private val _supportBIOTypes by lazy {
when (SystemProperties.get(FP_TYPE_PROP, "")) {
"back",
"side",
"front" -> AUTH_TYPE_FINGERPRINT
"ultrasonic",
"optical" -> AUTH_TYPE_OPTICAL_FINGERPRINT
else -> AUTH_TYPE_NOT_SUPPORT
}
}
else -> COMMAND_FAIL
}
override fun getSupportBIOTypes() = _supportBIOTypes
private val _deviceModel by lazy { SystemProperties.get(IFAA_MODEL_PROP, "OPLUS-Default") }
override fun getDeviceModel() = _deviceModel
override fun startBIOManager(authType: Int) =
when (authType) {
AUTH_TYPE_FINGERPRINT -> {
applicationContext.startActivity(
Intent(Settings.ACTION_SECURITY_SETTINGS).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
)
override fun processCmd(param: ByteArray) = try {
getFpPayService()?.ifaa_invoke_command(param)
} catch (e: Exception) {
Log.e(LOG_TAG, "processCmdImpl: ifaa_invoke_command aidl failed", e)
null
}
override fun getVersion() = 4
override fun getExtInfo(authType: Int, keyExtInfo: String) = when (keyExtInfo) {
KEY_GET_SENSOR_LOCATION -> initExtString()
else -> ""
}
override fun setExtInfo(authType: Int, keyExtInfo: String, valExtInfo: String) {
// Do nothing
}
override fun getEnabled(bioType: Int): Int {
if (!keyguardManager.isKeyguardSecure) {
Log.e(LOG_TAG, "No secure keyguard set.")
return BIOMETRIC_NOUSE_NOSET_KEYGUARD
}
return when (bioType) {
AUTH_TYPE_FINGERPRINT -> when {
!fingerprintManager.isHardwareDetected -> {
Log.e(LOG_TAG, "Fingerprint hardware not available!")
BIOMETRIC_NOUSE_SYSTEMLOCKED
COMMAND_OK
}
fingerprintManager.enrolledFingerprints.isNullOrEmpty() -> {
Log.e(LOG_TAG, "Fingerprint not enrolled!")
BIOMETRIC_NOUSE_NOT_ENROLLED
}
else -> BIOMETRIC_USE_READY
else -> COMMAND_FAIL
}
else -> 0
}
}
override fun getIDList(bioType: Int): IntArray? = when (bioType) {
AUTH_TYPE_FINGERPRINT -> {
val enrolledFingerprintIds = fingerprintManager.enrolledFingerprints?.map {
it.biometricId
}?.toIntArray()
Log.w(LOG_TAG, "getIDList: ${enrolledFingerprintIds}!")
enrolledFingerprintIds
private val _deviceModel by lazy {
SystemProperties.get(IFAA_MODEL_PROP, "OPLUS-Default")
}
else -> null
}
}
override fun getDeviceModel() = _deviceModel
private fun getFpPayService() = _fpPayService ?: run {
val binder = ServiceManager.getService("${IFingerprintPay.DESCRIPTOR}/default")
IFingerprintPay.Stub.asInterface(binder)?.also {
binder.linkToDeath(fpPayServiceDeathRecipient, 0)
_fpPayService = it
override fun processCmd(param: ByteArray) =
try {
getFpPayService()?.ifaa_invoke_command(param)
} catch (e: Exception) {
Log.e(LOG_TAG, "processCmdImpl: ifaa_invoke_command aidl failed", e)
null
}
override fun getVersion() = 4
override fun getExtInfo(authType: Int, keyExtInfo: String) =
when (keyExtInfo) {
KEY_GET_SENSOR_LOCATION -> initExtString()
else -> ""
}
override fun setExtInfo(authType: Int, keyExtInfo: String, valExtInfo: String) {
// Do nothing
}
override fun getEnabled(bioType: Int): Int {
if (!keyguardManager.isKeyguardSecure) {
Log.e(LOG_TAG, "No secure keyguard set.")
return BIOMETRIC_NOUSE_NOSET_KEYGUARD
}
return when (bioType) {
AUTH_TYPE_FINGERPRINT ->
when {
!fingerprintManager.isHardwareDetected -> {
Log.e(LOG_TAG, "Fingerprint hardware not available!")
BIOMETRIC_NOUSE_SYSTEMLOCKED
}
fingerprintManager.enrolledFingerprints.isNullOrEmpty() -> {
Log.e(LOG_TAG, "Fingerprint not enrolled!")
BIOMETRIC_NOUSE_NOT_ENROLLED
}
else -> BIOMETRIC_USE_READY
}
else -> 0
}
}
override fun getIDList(bioType: Int): IntArray? =
when (bioType) {
AUTH_TYPE_FINGERPRINT -> {
val enrolledFingerprintIds =
fingerprintManager.enrolledFingerprints
?.map { it.biometricId }
?.toIntArray()
Log.w(LOG_TAG, "getIDList: ${enrolledFingerprintIds}!")
enrolledFingerprintIds
}
else -> null
}
}
}
private fun getFpPayService() =
_fpPayService
?: run {
val binder = ServiceManager.getService("${IFingerprintPay.DESCRIPTOR}/default")
IFingerprintPay.Stub.asInterface(binder)?.also {
binder.linkToDeath(fpPayServiceDeathRecipient, 0)
_fpPayService = it
}
}
private val defaultDisplayDimension by lazy {
val dim1 = displayNoVerify?.supportedModes?.maxByOrNull { it.physicalHeight }
?.run { Point(physicalWidth, physicalHeight) }
val dim2 = windowManager.maximumWindowMetrics.bounds
.run { Point(width(), height()) }
val dim1 =
displayNoVerify
?.supportedModes
?.maxByOrNull { it.physicalHeight }
?.run { Point(physicalWidth, physicalHeight) }
val dim2 = windowManager.maximumWindowMetrics.bounds.run { Point(width(), height()) }
dim1?.let { Point(maxOf(dim1.x, dim2.x), maxOf(dim1.y, dim2.y)) } ?: dim2
}
@@ -140,33 +158,37 @@ class IfaaService : Service() {
val iconLocationBottom = SystemProperties.getInt(FP_ICON_LOCATION_PROP, 278)
Point(
(defaultDisplayDimension.x - iconDiameter) / 2,
defaultDisplayDimension.y - iconLocationBottom - iconDiameter / 2
defaultDisplayDimension.y - iconLocationBottom - iconDiameter / 2,
)
}
private fun initExtString() = run {
val displayDimension = windowManager.maximumWindowMetrics.bounds.run {
Point(width(), height())
}
val displayDimension =
windowManager.maximumWindowMetrics.bounds.run { Point(width(), height()) }
val scale = { pos: Point ->
Point(
pos.x * displayDimension.x / defaultDisplayDimension.x,
pos.y * displayDimension.y / defaultDisplayDimension.y
pos.y * displayDimension.y / defaultDisplayDimension.y,
)
}
val scaledLocation = scale(iconLocation)
val scaledDiameter = scale(Point(iconDiameter, iconDiameter))
JSONObject().apply {
put("type", 0)
put("fullView", JSONObject().apply {
put("startX", scaledLocation.x)
put("startY", scaledLocation.y)
put("width", scaledDiameter.x)
put("height", scaledDiameter.y)
put("navConflict", true)
})
}.toString()
JSONObject()
.apply {
put("type", 0)
put(
"fullView",
JSONObject().apply {
put("startX", scaledLocation.x)
put("startY", scaledLocation.y)
put("width", scaledDiameter.x)
put("height", scaledDiameter.y)
put("navConflict", true)
},
)
}
.toString()
}
companion object {

View File

@@ -16,8 +16,9 @@ class ButtonSettingsActivity : CollapsingToolbarBaseActivity() {
.replace(
com.android.settingslib.collapsingtoolbar.R.id.content_frame,
ButtonSettingsFragment(),
TAG
).commit()
TAG,
)
.commit()
}
companion object {

View File

@@ -8,7 +8,6 @@ package org.lineageos.settings.device
import android.database.Cursor
import android.database.MatrixCursor
import android.provider.SearchIndexableResource
import android.provider.SearchIndexablesProvider
import android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_CLASS_NAME
import android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_ICON_RESID
import android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_ACTION
@@ -19,15 +18,14 @@ import android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_RESID
import android.provider.SearchIndexablesContract.INDEXABLES_RAW_COLUMNS
import android.provider.SearchIndexablesContract.INDEXABLES_XML_RES_COLUMNS
import android.provider.SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS
import android.provider.SearchIndexablesProvider
class ConfigPanelSearchIndexablesProvider : SearchIndexablesProvider() {
override fun onCreate(): Boolean = true
override fun queryXmlResources(projection: Array<String?>?): Cursor {
val cursor = MatrixCursor(INDEXABLES_XML_RES_COLUMNS)
INDEXABLE_RES.forEach {
cursor.addRow(generateResourceRef(it))
}
INDEXABLE_RES.forEach { cursor.addRow(generateResourceRef(it)) }
return cursor
}
@@ -54,10 +52,14 @@ class ConfigPanelSearchIndexablesProvider : SearchIndexablesProvider() {
companion object {
private const val TAG = "ConfigPanelSearchIndexablesProvider"
private val INDEXABLE_RES = arrayOf<SearchIndexableResource>(
SearchIndexableResource(
1, R.xml.button_panel, ButtonSettingsActivity::class.java.name, 0
private val INDEXABLE_RES =
arrayOf<SearchIndexableResource>(
SearchIndexableResource(
1,
R.xml.button_panel,
ButtonSettingsActivity::class.java.name,
0,
)
)
)
}
}

View File

@@ -18,7 +18,6 @@ import android.os.Vibrator
import android.provider.Settings
import android.view.KeyEvent
import com.android.internal.os.DeviceKeyHandler
import java.io.File
import java.util.concurrent.Executors
@@ -27,35 +26,35 @@ class KeyHandler(context: Context) : DeviceKeyHandler {
private val notificationManager = context.getSystemService(NotificationManager::class.java)!!
private val vibrator = context.getSystemService(Vibrator::class.java)!!
private val packageContext = context.createPackageContext(
KeyHandler::class.java.getPackage()!!.name, 0
)
private val packageContext =
context.createPackageContext(KeyHandler::class.java.getPackage()!!.name, 0)
private val sharedPreferences
get() = packageContext.getSharedPreferences(
packageContext.packageName + "_preferences",
Context.MODE_PRIVATE or Context.MODE_MULTI_PROCESS
)
get() =
packageContext.getSharedPreferences(
packageContext.packageName + "_preferences",
Context.MODE_PRIVATE or Context.MODE_MULTI_PROCESS,
)
private val executorService = Executors.newSingleThreadExecutor()
private var wasMuted = false
private val broadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
when (intent.action) {
AudioManager.STREAM_MUTE_CHANGED_ACTION -> {
val stream = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1)
val state = intent.getBooleanExtra(
AudioManager.EXTRA_STREAM_VOLUME_MUTED, false
)
if (stream == AudioSystem.STREAM_MUSIC && !state) {
wasMuted = false
private val broadcastReceiver =
object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
when (intent.action) {
AudioManager.STREAM_MUTE_CHANGED_ACTION -> {
val stream = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1)
val state =
intent.getBooleanExtra(AudioManager.EXTRA_STREAM_VOLUME_MUTED, false)
if (stream == AudioSystem.STREAM_MUSIC && !state) {
wasMuted = false
}
}
}
Intent.ACTION_BOOT_COMPLETED -> populateKeyState(false)
Intent.ACTION_BOOT_COMPLETED -> populateKeyState(false)
}
}
}
}
init {
context.registerReceiver(
@@ -63,7 +62,7 @@ class KeyHandler(context: Context) : DeviceKeyHandler {
IntentFilter().apply {
addAction(AudioManager.STREAM_MUTE_CHANGED_ACTION)
addAction(Intent.ACTION_BOOT_COMPLETED)
}
},
)
}
@@ -93,26 +92,25 @@ class KeyHandler(context: Context) : DeviceKeyHandler {
private fun vibrateIfNeeded(mode: Int) {
when (mode) {
AudioManager.RINGER_MODE_VIBRATE -> vibrator.vibrate(
MODE_VIBRATION_EFFECT,
HARDWARE_FEEDBACK_VIBRATION_ATTRIBUTES
)
AudioManager.RINGER_MODE_NORMAL -> vibrator.vibrate(
MODE_NORMAL_EFFECT,
HARDWARE_FEEDBACK_VIBRATION_ATTRIBUTES
)
AudioManager.RINGER_MODE_VIBRATE ->
vibrator.vibrate(MODE_VIBRATION_EFFECT, HARDWARE_FEEDBACK_VIBRATION_ATTRIBUTES)
AudioManager.RINGER_MODE_NORMAL ->
vibrator.vibrate(MODE_NORMAL_EFFECT, HARDWARE_FEEDBACK_VIBRATION_ATTRIBUTES)
}
}
private fun handleMode(position: Int, vibrate: Boolean) {
val muteMedia = sharedPreferences.getBoolean(MUTE_MEDIA_WITH_SILENT, false)
val mode = when (position) {
POSITION_TOP -> sharedPreferences.getString(ALERT_SLIDER_TOP_KEY, "0")!!.toInt()
POSITION_MIDDLE -> sharedPreferences.getString(ALERT_SLIDER_MIDDLE_KEY, "1")!!.toInt()
POSITION_BOTTOM -> sharedPreferences.getString(ALERT_SLIDER_BOTTOM_KEY, "2")!!.toInt()
else -> return
}
val mode =
when (position) {
POSITION_TOP -> sharedPreferences.getString(ALERT_SLIDER_TOP_KEY, "0")!!.toInt()
POSITION_MIDDLE ->
sharedPreferences.getString(ALERT_SLIDER_MIDDLE_KEY, "1")!!.toInt()
POSITION_BOTTOM ->
sharedPreferences.getString(ALERT_SLIDER_BOTTOM_KEY, "2")!!.toInt()
else -> return
}
executorService.submit {
when (mode) {
@@ -124,14 +122,17 @@ class KeyHandler(context: Context) : DeviceKeyHandler {
wasMuted = true
}
}
AudioManager.RINGER_MODE_VIBRATE, AudioManager.RINGER_MODE_NORMAL -> {
AudioManager.RINGER_MODE_VIBRATE,
AudioManager.RINGER_MODE_NORMAL -> {
setZenMode(Settings.Global.ZEN_MODE_OFF)
audioManager.ringerModeInternal = mode
if (muteMedia && wasMuted) {
audioManager.adjustVolume(AudioManager.ADJUST_UNMUTE, 0)
}
}
ZEN_PRIORITY_ONLY, ZEN_TOTAL_SILENCE, ZEN_ALARMS_ONLY -> {
ZEN_PRIORITY_ONLY,
ZEN_TOTAL_SILENCE,
ZEN_ALARMS_ONLY -> {
audioManager.ringerModeInternal = AudioManager.RINGER_MODE_NORMAL
setZenMode(mode - ZEN_OFFSET)
if (muteMedia && wasMuted) {

View File

@@ -15,7 +15,6 @@ import android.bluetooth.le.ScanCallback
import android.bluetooth.le.ScanFilter
import android.bluetooth.le.ScanResult
import android.bluetooth.le.ScanSettings
import android.content.Context
import android.content.Intent
import android.database.ContentObserver
import android.hardware.input.InputManager
@@ -31,41 +30,45 @@ class PenService : Service() {
private val inputManager by lazy { getSystemService(InputManager::class.java) }
private val notificationManager by lazy { getSystemService(NotificationManager::class.java) }
private val penSupportedRefreshRate by lazy { getString(R.string.config_penSupportedRefreshRate) }
private val penSupportedRefreshRate by lazy {
getString(R.string.config_penSupportedRefreshRate)
}
private val handler by lazy { Handler(mainLooper) }
private val observer = object : UEventObserver() {
private val lock = Any()
private val observer =
object : UEventObserver() {
private val lock = Any()
override fun onUEvent(event: UEvent) {
synchronized(lock) {
val pencilStatus = event.get("pencil_status") ?: return
val pencilAddr = event.get("pencil_addr")?.chunked(2)?.joinToString(":") {
it.uppercase()
} ?: return
override fun onUEvent(event: UEvent) {
synchronized(lock) {
val pencilStatus = event.get("pencil_status") ?: return
val pencilAddr =
event.get("pencil_addr")?.chunked(2)?.joinToString(":") { it.uppercase() }
?: return
when (pencilStatus) {
"0" -> notificationManager.cancel(NOTIFICATION_ID)
"1" -> postNotification(pencilAddr)
when (pencilStatus) {
"0" -> notificationManager.cancel(NOTIFICATION_ID)
"1" -> postNotification(pencilAddr)
}
}
}
}
}
private val inputObserver = object : InputManager.InputDeviceListener {
override fun onInputDeviceAdded(deviceId: Int) {
overridePeakRefreshRateIfNeeded()
}
private val inputObserver =
object : InputManager.InputDeviceListener {
override fun onInputDeviceAdded(deviceId: Int) {
overridePeakRefreshRateIfNeeded()
}
override fun onInputDeviceRemoved(deviceId: Int) {
overridePeakRefreshRateIfNeeded()
}
override fun onInputDeviceRemoved(deviceId: Int) {
overridePeakRefreshRateIfNeeded()
}
override fun onInputDeviceChanged(deviceId: Int) {
// Do nothing
override fun onInputDeviceChanged(deviceId: Int) {
// Do nothing
}
}
}
private val peakRefreshRateSettingsObserver by lazy {
object : ContentObserver(handler) {
@@ -78,9 +81,7 @@ class PenService : Service() {
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
intent?.getStringExtra(EXTRA_PENCIL_ADDR)?.let {
bondBtDevice(it)
}
intent?.getStringExtra(EXTRA_PENCIL_ADDR)?.let { bondBtDevice(it) }
return START_STICKY
}
@@ -94,7 +95,7 @@ class PenService : Service() {
contentResolver.registerContentObserver(
Settings.System.getUriFor(PEAK_REFRESH_RATE),
false,
peakRefreshRateSettingsObserver
peakRefreshRateSettingsObserver,
)
peakRefreshRateSettingsObserver.onChange(true)
@@ -151,24 +152,27 @@ class PenService : Service() {
super.onScanFailed(errorCode)
scanner.stopScan(this)
}
}
},
)
}
private fun overridePeakRefreshRateIfNeeded() {
val isPenConnected = inputManager.inputDeviceIds.firstOrNull {
val device = inputManager.getInputDevice(it) ?: return@firstOrNull false
if (device.vendorId != 0x22D9 && device.vendorId != 0x330A) {
// Not an OPPO/Maxeye vendor ID
return@firstOrNull false
}
if (device.bluetoothAddress?.startsWith("C0:87:06") == false &&
device.bluetoothAddress?.startsWith("F8:6F:DE") == false) {
// Not a Maxeye/Goodix MAC prefix
return@firstOrNull false
}
return@firstOrNull true
} != null
val isPenConnected =
inputManager.inputDeviceIds.firstOrNull {
val device = inputManager.getInputDevice(it) ?: return@firstOrNull false
if (device.vendorId != 0x22D9 && device.vendorId != 0x330A) {
// Not an OPPO/Maxeye vendor ID
return@firstOrNull false
}
if (
device.bluetoothAddress?.startsWith("C0:87:06") == false &&
device.bluetoothAddress?.startsWith("F8:6F:DE") == false
) {
// Not a Maxeye/Goodix MAC prefix
return@firstOrNull false
}
return@firstOrNull true
} != null
val peakRefreshRate = Settings.System.getString(contentResolver, PEAK_REFRESH_RATE)
if (isPenConnected && peakRefreshRate == "Infinity") {
@@ -191,27 +195,29 @@ class PenService : Service() {
NotificationChannel(
NOTIFICATION_CHANNEL_ID,
NOTIFICATION_CHANNEL_ID,
NotificationManager.IMPORTANCE_HIGH
NotificationManager.IMPORTANCE_HIGH,
)
)
}
val contentIntent = PendingIntent.getService(
this,
0,
Intent(this, PenService::class.java).apply {
putExtra(EXTRA_PENCIL_ADDR, pencilAddr)
},
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
val contentIntent =
PendingIntent.getService(
this,
0,
Intent(this, PenService::class.java).apply {
putExtra(EXTRA_PENCIL_ADDR, pencilAddr)
},
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,
)
val notification = Notification.Builder(this, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_stylus)
.setContentTitle(getString(R.string.pen_attached))
.setContentText(getString(R.string.tap_to_connect))
.setContentIntent(contentIntent)
.setAutoCancel(true)
.build()
val notification =
Notification.Builder(this, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_stylus)
.setContentTitle(getString(R.string.pen_attached))
.setContentText(getString(R.string.tap_to_connect))
.setContentIntent(contentIntent)
.setAutoCancel(true)
.build()
notificationManager.notify(NOTIFICATION_ID, notification)
}

View File

@@ -648,4 +648,3 @@ ndk::ScopedAStatus Vibrator::alwaysOnDisable(int32_t id __unused) {
} // namespace hardware
} // namespace android
} // namespace aidl

View File

@@ -17,27 +17,30 @@ class DozeService : Service() {
private lateinit var pickupSensor: PickupSensor
private lateinit var pocketSensor: PocketSensor
private val screenStateReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
when (intent.action) {
Intent.ACTION_SCREEN_ON -> onDisplayOn()
Intent.ACTION_SCREEN_OFF -> onDisplayOff()
private val screenStateReceiver =
object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
when (intent.action) {
Intent.ACTION_SCREEN_ON -> onDisplayOn()
Intent.ACTION_SCREEN_OFF -> onDisplayOff()
}
}
}
}
override fun onCreate() {
Log.d(TAG, "Creating service")
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)
)
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)

View File

@@ -16,8 +16,9 @@ class DozeSettingsActivity : CollapsingToolbarBaseActivity() {
.replace(
com.android.settingslib.collapsingtoolbar.R.id.content_frame,
DozeSettingsFragment(),
TAG
).commit()
TAG,
)
.commit()
}
companion object {

View File

@@ -5,7 +5,6 @@
package org.lineageos.settings.doze
import android.app.Activity
import android.app.AlertDialog
import android.content.Context
import android.os.Bundle
@@ -104,5 +103,4 @@ class DozeSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreference
handler.post { Utils.checkDozeService(requireContext()) }
return true
}
}

View File

@@ -14,11 +14,12 @@ import android.os.PowerManager
import android.os.SystemClock
import android.util.Log
import android.view.Display
import java.util.concurrent.Executors
class PickupSensor(
private val context: Context, sensorType: String, private val sensorValue: Float
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)
@@ -43,7 +44,7 @@ class PickupSensor(
SystemClock.uptimeMillis(),
PowerManager.WAKE_REASON_GESTURE,
TAG,
Display.DEFAULT_DISPLAY
Display.DEFAULT_DISPLAY,
)
} else {
Utils.launchDozePulse(context)
@@ -61,15 +62,12 @@ class PickupSensor(
sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL)
}
}
}
fun disable() {
if (sensor != null) {
Log.d(TAG, "Disabling")
executorService.submit {
sensorManager.unregisterListener(this, sensor)
}
executorService.submit { sensorManager.unregisterListener(this, sensor) }
}
}

View File

@@ -12,11 +12,12 @@ import android.hardware.SensorEventListener
import android.hardware.SensorManager
import android.os.SystemClock
import android.util.Log
import java.util.concurrent.Executors
class PocketSensor(
private val context: Context, sensorType: String, private val sensorValue: Float
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)
@@ -51,9 +52,7 @@ class PocketSensor(
fun disable() {
if (sensor != null) {
Log.d(TAG, "Disabling")
executorService.submit {
sensorManager.unregisterListener(this, sensor)
}
executorService.submit { sensorManager.unregisterListener(this, sensor) }
}
}

View File

@@ -64,13 +64,19 @@ object Utils {
fun enableAlwaysOn(context: Context, enable: Boolean): Boolean {
return Settings.Secure.putIntForUser(
context.contentResolver, DOZE_ALWAYS_ON, if (enable) 1 else 0, UserHandle.USER_CURRENT
context.contentResolver,
DOZE_ALWAYS_ON,
if (enable) 1 else 0,
UserHandle.USER_CURRENT,
)
}
fun isAlwaysOnEnabled(context: Context): Boolean {
return Settings.Secure.getIntForUser(
context.contentResolver, DOZE_ALWAYS_ON, 0, UserHandle.USER_CURRENT
context.contentResolver,
DOZE_ALWAYS_ON,
0,
UserHandle.USER_CURRENT,
) != 0
}
@@ -79,8 +85,7 @@ object Utils {
}
private fun isGestureEnabled(context: Context, gesture: String?): Boolean {
return PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(gesture, false)
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(gesture, false)
}
fun isPickUpEnabled(context: Context): Boolean {

View File

@@ -16,9 +16,10 @@ class BootCompletedReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
Log.d(TAG, "Received boot completed intent")
val hasNonRemovableEuicc = context.resources.getIntArray(
com.android.internal.R.array.non_removable_euicc_slots
).isNotEmpty()
val hasNonRemovableEuicc =
context.resources
.getIntArray(com.android.internal.R.array.non_removable_euicc_slots)
.isNotEmpty()
setComponentEnabled(context, EsimSettingsActivity::class.java.name, hasNonRemovableEuicc)
}
@@ -26,11 +27,12 @@ class BootCompletedReceiver : BroadcastReceiver() {
private fun setComponentEnabled(context: Context, component: String, enabled: Boolean) {
val name = ComponentName(context, component)
val pm = context.packageManager
val newState = if (enabled) {
PackageManager.COMPONENT_ENABLED_STATE_ENABLED
} else {
PackageManager.COMPONENT_ENABLED_STATE_DISABLED
}
val newState =
if (enabled) {
PackageManager.COMPONENT_ENABLED_STATE_ENABLED
} else {
PackageManager.COMPONENT_ENABLED_STATE_DISABLED
}
if (pm.getComponentEnabledSetting(name) != newState) {
pm.setComponentEnabledSetting(name, newState, PackageManager.DONT_KILL_APP)

View File

@@ -8,13 +8,10 @@ package org.lineageos.settings.esimswitcher
import android.content.Context
import android.os.ServiceManager
import android.os.SystemProperties
import android.se.omapi.Channel
import android.se.omapi.Reader
import android.se.omapi.SEService
import android.se.omapi.Session
import android.util.Log
import kotlinx.coroutines.asExecutor
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.asExecutor
import vendor.oplus.hardware.esim.IOplusEsim
class EsimController(private val context: Context) {
@@ -49,33 +46,34 @@ class EsimController(private val context: Context) {
private fun specialSetEsimGpio(state: Int) {
var seService: SEService? = null
val listener = object : SEService.OnConnectedListener {
override fun onConnected() {
Log.d(TAG, "SEService connected")
val listener =
object : SEService.OnConnectedListener {
override fun onConnected() {
Log.d(TAG, "SEService connected")
val service = seService ?: return
val service = seService ?: return
try {
val reader = service.readers.firstOrNull { it.name == "eSE1" }
val session = reader?.openSession()
val channel = session?.openLogicalChannel(null)
oplusEsimService?.setEsimGpio(state)
oplusEsimService?.setUimPower(1)
channel?.close()
session?.close()
} catch (e: Exception) {
Log.e(TAG, "Failed to open eSE session", e)
} finally {
try {
service.shutdown()
val reader = service.readers.firstOrNull { it.name == "eSE1" }
val session = reader?.openSession()
val channel = session?.openLogicalChannel(null)
oplusEsimService?.setEsimGpio(state)
oplusEsimService?.setUimPower(1)
channel?.close()
session?.close()
} catch (e: Exception) {
Log.e(TAG, "Failed to shutdown SEService", e)
Log.e(TAG, "Failed to open eSE session", e)
} finally {
try {
service.shutdown()
} catch (e: Exception) {
Log.e(TAG, "Failed to shutdown SEService", e)
}
}
}
}
}
try {
seService = SEService(context, Dispatchers.IO.asExecutor(), listener)

View File

@@ -16,8 +16,9 @@ class EsimSettingsActivity : CollapsingToolbarBaseActivity() {
.replace(
com.android.settingslib.collapsingtoolbar.R.id.content_frame,
EsimSettingsFragment(),
TAG
).commit()
TAG,
)
.commit()
}
companion object {

View File

@@ -10,7 +10,6 @@ import android.os.Bundle
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreferenceCompat
import org.lineageos.settings.esimswitcher.R
class EsimSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener {
private lateinit var controller: EsimController