Compare commits
54 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8779e0c9b7 | ||
|
|
3b57cb0e21 | ||
|
|
2e8813cff3 | ||
|
|
9e7d30109e | ||
|
|
6a757abc99 | ||
|
|
d4f9d673b0 | ||
|
|
c28c6d4069 | ||
|
|
5d17397ac7 | ||
|
|
58134fc19d | ||
|
|
bf7da37064 | ||
|
|
19a83c73a1 | ||
|
|
99c08b4e77 | ||
|
|
b6ff3d7cd7 | ||
|
|
0a0cc34354 | ||
|
|
df2974eefd | ||
|
|
57c743ec56 | ||
|
|
483836e95e | ||
|
|
df78b9324a | ||
|
|
ed12c16996 | ||
|
|
a5b9c1aaa5 | ||
|
|
e559d54d8f | ||
|
|
d6f0b19935 | ||
|
|
9834c8f80e | ||
|
|
1763d012e5 | ||
|
|
5e0fd308c3 | ||
|
|
0305e83275 | ||
|
|
d62096c187 | ||
|
|
4f438b9ae5 | ||
|
|
90c0306b75 | ||
|
|
c82f3f31fa | ||
|
|
f920f15040 | ||
|
|
71c471385e | ||
|
|
47750a4610 | ||
|
|
a8f34aa099 | ||
|
|
d13d47f8c3 | ||
|
|
c74487aa38 | ||
|
|
9e55a99e45 | ||
|
|
5b0f4d63f8 | ||
|
|
e3c118b877 | ||
|
|
b2d953cb26 | ||
|
|
7329a9d67c | ||
|
|
a750435b3e | ||
|
|
977f5036a4 | ||
|
|
13c7a39154 | ||
|
|
03ae5d3bc3 | ||
|
|
dc3069c44b | ||
|
|
c8cd550f87 | ||
|
|
35d550916c | ||
|
|
1b81776dd7 | ||
|
|
864199e705 | ||
|
|
94ac6370ad | ||
|
|
ba11fe6f76 | ||
|
|
4ed4bb5c77 | ||
|
|
1c49eb9f6c |
48
DSPVolumeSynchronizer/Android.bp
Normal file
48
DSPVolumeSynchronizer/Android.bp
Normal file
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// Copyright (C) 2024-2025 The LineageOS Project
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
android_app {
|
||||
name: "DSPVolumeSynchronizer",
|
||||
certificate: "platform",
|
||||
srcs: ["src/**/*.java"],
|
||||
platform_apis: true,
|
||||
privileged: true,
|
||||
system_ext_specific: true,
|
||||
static_libs: [
|
||||
"androidx.core_core",
|
||||
"SettingsLib",
|
||||
],
|
||||
|
||||
required: [
|
||||
"privapp-permissions-dspvolume",
|
||||
"config-dspvolume",
|
||||
"preinstalled-packages-platform-dspvolume",
|
||||
],
|
||||
}
|
||||
|
||||
prebuilt_etc {
|
||||
name: "privapp-permissions-dspvolume",
|
||||
relative_install_path: "permissions",
|
||||
src: "privapp-permissions-dspvolume.xml",
|
||||
system_ext_specific: true,
|
||||
filename_from_src: true,
|
||||
}
|
||||
|
||||
prebuilt_etc {
|
||||
name: "config-dspvolume",
|
||||
relative_install_path: "sysconfig",
|
||||
src: "config-dspvolume.xml",
|
||||
system_ext_specific: true,
|
||||
filename_from_src: true,
|
||||
}
|
||||
|
||||
prebuilt_etc {
|
||||
name: "preinstalled-packages-platform-dspvolume",
|
||||
relative_install_path: "sysconfig",
|
||||
src: "preinstalled-packages-platform-dspvolume.xml",
|
||||
system_ext_specific: true,
|
||||
filename_from_src: true,
|
||||
}
|
||||
30
DSPVolumeSynchronizer/AndroidManifest.xml
Normal file
30
DSPVolumeSynchronizer/AndroidManifest.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.lineageos.dspvolume.xiaomi"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0"
|
||||
android:sharedUserId="android.uid.system">
|
||||
|
||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||
|
||||
<application
|
||||
android:label="@string/app_name"
|
||||
android:persistent="true"
|
||||
android:defaultToDeviceProtectedStorage="true"
|
||||
android:directBootAware="true">
|
||||
|
||||
<receiver
|
||||
android:name=".BootReceiver"
|
||||
android:exported="true"
|
||||
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
|
||||
<intent-filter android:priority="999">
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<service
|
||||
android:name=".VolumeListenerService" />
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
5
DSPVolumeSynchronizer/config-dspvolume.xml
Normal file
5
DSPVolumeSynchronizer/config-dspvolume.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<config>
|
||||
<allow-in-power-save package="org.lineageos.dspvolume.xiaomi" />
|
||||
<hidden-api-whitelisted-app package="org.lineageos.dspvolume.xiaomi" />
|
||||
</config>
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2025 crDroid Android 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.
|
||||
-->
|
||||
<config>
|
||||
|
||||
<!-- Dolby -->
|
||||
<install-in-user-type package="org.lineageos.dspvolume.xiaomi">
|
||||
<install-in user-type="FULL" />
|
||||
<install-in user-type="PROFILE" />
|
||||
<do-not-install-in user-type="android.os.usertype.profile.CLONE" />
|
||||
<do-not-install-in user-type="android.os.usertype.profile.PRIVATE" />
|
||||
</install-in-user-type>
|
||||
</config>
|
||||
9
DSPVolumeSynchronizer/privapp-permissions-dspvolume.xml
Normal file
9
DSPVolumeSynchronizer/privapp-permissions-dspvolume.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<permissions>
|
||||
<privapp-permissions package="org.lineageos.dspvolume.xiaomi">
|
||||
<permission name="android.permission.INTERACT_ACROSS_USERS" />
|
||||
<permission name="android.permission.INTERACT_ACROSS_USERS_FULL" />
|
||||
<permission name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||
<permission name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
</privapp-permissions>
|
||||
</permissions>
|
||||
5
DSPVolumeSynchronizer/res/values/strings.xml
Normal file
5
DSPVolumeSynchronizer/res/values/strings.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- App Name -->
|
||||
<string name="app_name">DSP Volume Synchronizer</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.lineageos.dspvolume.xiaomi;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
|
||||
public class BootReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(final Context context, Intent intent) {
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
context.startService(new Intent(context, VolumeListenerService.class));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.lineageos.dspvolume.xiaomi;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.media.AudioManager;
|
||||
import android.util.Log;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
public class VolumeListenerReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(intent.getIntExtra("android.media.EXTRA_VOLUME_STREAM_TYPE", 0) == AudioManager.STREAM_MUSIC) {
|
||||
AudioManager audioManager = context.getSystemService(AudioManager.class);
|
||||
int current = intent.getIntExtra(
|
||||
"android.media.EXTRA_VOLUME_STREAM_VALUE",
|
||||
0
|
||||
);
|
||||
audioManager.setParameters("volume_change=" + current + ";flags=8");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.lineageos.dspvolume.xiaomi;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.media.AudioManager;
|
||||
import android.os.IBinder;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public class VolumeListenerService extends Service {
|
||||
@Nullable
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
IntentFilter intentFilter = new IntentFilter();
|
||||
intentFilter.addAction("android.media.VOLUME_CHANGED_ACTION");
|
||||
registerReceiver(new VolumeListenerReceiver(), intentFilter);
|
||||
|
||||
AudioManager audioManager = getSystemService(AudioManager.class);
|
||||
int current = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
|
||||
audioManager.setParameters("volume_change=" + current + ";flags=8");
|
||||
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
}
|
||||
41
Euicc/Android.bp
Normal file
41
Euicc/Android.bp
Normal file
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// Copyright (C) 2023 The LineageOS Project
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
android_app {
|
||||
name: "XiaomiEuicc",
|
||||
|
||||
srcs: ["src/**/*.kt"],
|
||||
resource_dirs: ["res"],
|
||||
|
||||
sdk_version: "current",
|
||||
product_specific: true,
|
||||
certificate: "platform",
|
||||
privileged: true,
|
||||
|
||||
optimize: {
|
||||
proguard_flags_files: ["proguard.flags"],
|
||||
},
|
||||
required: [
|
||||
"co.aospa.euicc.xml",
|
||||
"hidden-api-whitelist-co.aospa.euicc.xml",
|
||||
],
|
||||
}
|
||||
|
||||
prebuilt_etc {
|
||||
sub_dir: "permissions",
|
||||
name: "co.aospa.euicc.xml",
|
||||
filename: "co.aospa.euicc.xml",
|
||||
src: "co.aospa.euicc.xml",
|
||||
product_specific: true,
|
||||
}
|
||||
|
||||
prebuilt_etc {
|
||||
sub_dir: "sysconfig",
|
||||
name: "hidden-api-whitelist-co.aospa.euicc.xml",
|
||||
filename: "hidden-api-whitelist-co.aospa.euicc.xml",
|
||||
src: "hidden-api-whitelist-co.aospa.euicc.xml",
|
||||
product_specific: true,
|
||||
}
|
||||
42
Euicc/AndroidManifest.xml
Normal file
42
Euicc/AndroidManifest.xml
Normal file
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2023-2024 The LineageOS Project
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="co.aospa.euicc">
|
||||
|
||||
<queries>
|
||||
<package android:name="com.google.android.gms" />
|
||||
<package android:name="com.google.android.gsf" />
|
||||
<package android:name="com.google.android.euicc" />
|
||||
<package android:name="com.google.android.ims" />
|
||||
</queries>
|
||||
|
||||
<uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS" />
|
||||
|
||||
<application
|
||||
android:persistent="true"
|
||||
android:usesNonSdkApi="true">
|
||||
<receiver
|
||||
android:exported="true"
|
||||
android:name=".BootCompletedReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<receiver
|
||||
android:directBootAware="true"
|
||||
android:exported="true"
|
||||
android:name=".EuiccReceiver"
|
||||
android:permission="android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS">
|
||||
<intent-filter>
|
||||
<action android:name="com.google.android.euicc.action.PARTNER_CUSTOMIZATION"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</application>
|
||||
</manifest>
|
||||
7
Euicc/co.aospa.euicc.xml
Normal file
7
Euicc/co.aospa.euicc.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<permissions>
|
||||
<privapp-permissions package="co.aospa.euicc">
|
||||
<permission name="android.permission.CHANGE_COMPONENT_ENABLED_STATE"/>
|
||||
<permission name="android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS"/>
|
||||
</privapp-permissions>
|
||||
</permissions>
|
||||
4
Euicc/hidden-api-whitelist-co.aospa.euicc.xml
Normal file
4
Euicc/hidden-api-whitelist-co.aospa.euicc.xml
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<config>
|
||||
<hidden-api-whitelisted-app package="co.aospa.euicc" />
|
||||
</config>
|
||||
3
Euicc/proguard.flags
Normal file
3
Euicc/proguard.flags
Normal file
@@ -0,0 +1,3 @@
|
||||
-keep class co.aospa.euicc.* {
|
||||
*;
|
||||
}
|
||||
1
Euicc/res/raw/esim_intro_illustration_lottie.json
Normal file
1
Euicc/res/raw/esim_intro_illustration_lottie.json
Normal file
File diff suppressed because one or more lines are too long
1
Euicc/res/raw/sim_illustration_lottie_bottom.json
Normal file
1
Euicc/res/raw/sim_illustration_lottie_bottom.json
Normal file
File diff suppressed because one or more lines are too long
9
Euicc/res/values/strings.xml
Normal file
9
Euicc/res/values/strings.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2023 The LineageOS Project
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
<resources>
|
||||
<string name="sim_illustration_lottie_mappings_json">{\"sim_illustration_lottie_mappings\":[{\"devices\":[\"diting\"],\"illustration_lottie\":\"sim_illustration_lottie_bottom\"}]}</string>
|
||||
<string name="sim_slot_mappings_json">{\"sim-slot-mappings\":[{\"devices\":[\"diting\"],\"esim-slot-ids\":[1],\"psim-slot-ids\":[0]}]}</string>
|
||||
</resources>
|
||||
22
Euicc/src/co/aospa/euicc/BootCompletedReceiver.kt
Normal file
22
Euicc/src/co/aospa/euicc/BootCompletedReceiver.kt
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The LineageOS Project
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package co.aospa.euicc
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
|
||||
class BootCompletedReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
Log.d(TAG, "Received boot completed intent")
|
||||
EuiccDisabler.enableOrDisableEuicc(context)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "XiaomiEuiccBootReceiver"
|
||||
}
|
||||
}
|
||||
53
Euicc/src/co/aospa/euicc/EuiccDisabler.kt
Normal file
53
Euicc/src/co/aospa/euicc/EuiccDisabler.kt
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2024 The LineageOS Project
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package co.aospa.euicc
|
||||
|
||||
import android.content.Context
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.pm.PackageManager.ApplicationInfoFlags
|
||||
import android.util.Log
|
||||
|
||||
object EuiccDisabler {
|
||||
private const val TAG = "XiaomiEuiccDisabler"
|
||||
|
||||
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 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)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
for (pkg in EUICC_PACKAGES) {
|
||||
if (isInstalled(pm, pkg)) {
|
||||
pm.setApplicationEnabledSetting(pkg, flag, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
Euicc/src/co/aospa/euicc/EuiccReceiver.kt
Normal file
21
Euicc/src/co/aospa/euicc/EuiccReceiver.kt
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The LineageOS Project
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package co.aospa.euicc
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
|
||||
class EuiccReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
Log.d(TAG, "Received PARTNER_CUSTOMIZATION intent")
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "XiaomiEuiccReceiver"
|
||||
}
|
||||
}
|
||||
74
aidl/fingerprint/Android.bp
Normal file
74
aidl/fingerprint/Android.bp
Normal file
@@ -0,0 +1,74 @@
|
||||
//
|
||||
// Copyright (C) 2024 The LineageOS Project
|
||||
// 2024 Paranoid Android
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
soong_config_module_type {
|
||||
name: "xiaomi_hardware_biometrics_config_default",
|
||||
module_type: "cc_defaults",
|
||||
config_namespace: "xiaomi_hardware_biometrics",
|
||||
bool_variables: [
|
||||
"run_32bit",
|
||||
],
|
||||
properties: ["compile_multilib"],
|
||||
}
|
||||
|
||||
xiaomi_hardware_biometrics_config_default {
|
||||
name: "xiaomi_hardware_biometrics_config_default",
|
||||
|
||||
soong_config_variables: {
|
||||
run_32bit: {
|
||||
conditions_default: {
|
||||
compile_multilib: "64",
|
||||
},
|
||||
compile_multilib: "prefer32",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
cc_binary {
|
||||
name: "android.hardware.biometrics.fingerprint-service.xiaomi",
|
||||
defaults: ["xiaomi_hardware_biometrics_config_default"],
|
||||
relative_install_path: "hw",
|
||||
init_rc: ["android.hardware.biometrics.fingerprint-service.xiaomi.rc"],
|
||||
vintf_fragments: ["android.hardware.biometrics.fingerprint-service.xiaomi.xml"],
|
||||
srcs: [
|
||||
"CancellationSignal.cpp",
|
||||
"Fingerprint.cpp",
|
||||
"FingerprintConfig.cpp",
|
||||
"LockoutTracker.cpp",
|
||||
"Session.cpp",
|
||||
"service.cpp",
|
||||
],
|
||||
local_include_dirs: [
|
||||
"include",
|
||||
],
|
||||
shared_libs: [
|
||||
"libbase",
|
||||
"libbinder_ndk",
|
||||
"libcutils",
|
||||
"libhardware",
|
||||
"libdl",
|
||||
"liblog",
|
||||
"android.hardware.biometrics.fingerprint-V4-ndk",
|
||||
"android.hardware.biometrics.common-V4-ndk",
|
||||
"android.hardware.biometrics.common.config",
|
||||
"android.hardware.biometrics.common.thread",
|
||||
"android.hardware.biometrics.common.util",
|
||||
],
|
||||
static_libs: [
|
||||
"libandroid.hardware.biometrics.fingerprint.Props",
|
||||
"libudfpshandlerfactory",
|
||||
],
|
||||
vendor: true,
|
||||
header_libs: ["xiaomifingerprint_headers"],
|
||||
}
|
||||
|
||||
sysprop_library {
|
||||
name: "android.hardware.biometrics.fingerprint.Props",
|
||||
srcs: ["fingerprint.sysprop"],
|
||||
property_owner: "Vendor",
|
||||
vendor: true,
|
||||
}
|
||||
17
aidl/fingerprint/CancellationSignal.cpp
Normal file
17
aidl/fingerprint/CancellationSignal.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "CancellationSignal.h"
|
||||
|
||||
namespace aidl::android::hardware::biometrics::fingerprint {
|
||||
|
||||
CancellationSignal::CancellationSignal(Session* session) : mSession(session) {}
|
||||
|
||||
ndk::ScopedAStatus CancellationSignal::cancel() {
|
||||
return mSession->cancel();
|
||||
}
|
||||
|
||||
} // namespace aidl::android::hardware::biometrics::fingerprint
|
||||
25
aidl/fingerprint/CancellationSignal.h
Normal file
25
aidl/fingerprint/CancellationSignal.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <aidl/android/hardware/biometrics/common/BnCancellationSignal.h>
|
||||
|
||||
#include "Session.h"
|
||||
|
||||
namespace aidl::android::hardware::biometrics::fingerprint {
|
||||
|
||||
class CancellationSignal
|
||||
: public ::aidl::android::hardware::biometrics::common::BnCancellationSignal {
|
||||
public:
|
||||
CancellationSignal(Session* session);
|
||||
ndk::ScopedAStatus cancel() override;
|
||||
|
||||
private:
|
||||
Session* mSession;
|
||||
};
|
||||
|
||||
} // namespace aidl::android::hardware::biometrics::fingerprint
|
||||
248
aidl/fingerprint/Fingerprint.cpp
Normal file
248
aidl/fingerprint/Fingerprint.cpp
Normal file
@@ -0,0 +1,248 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
* 2024 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "Fingerprint.h"
|
||||
|
||||
#include <android-base/properties.h>
|
||||
#include <fingerprint.sysprop.h>
|
||||
#include "util/Util.h"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <android-base/strings.h>
|
||||
|
||||
namespace aidl::android::hardware::biometrics::fingerprint {
|
||||
|
||||
namespace {
|
||||
constexpr int MAX_ENROLLMENTS_PER_USER = 5;
|
||||
constexpr char HW_COMPONENT_ID[] = "fingerprintSensor";
|
||||
constexpr char HW_VERSION[] = "vendor/model/revision";
|
||||
constexpr char FW_VERSION[] = "1.01";
|
||||
constexpr char SERIAL_NUMBER[] = "00000001";
|
||||
constexpr char SW_COMPONENT_ID[] = "matchingAlgorithm";
|
||||
constexpr char SW_VERSION[] = "vendor/version/revision";
|
||||
|
||||
typedef struct fingerprint_hal {
|
||||
const char* class_name;
|
||||
} fingerprint_hal_t;
|
||||
|
||||
static const fingerprint_hal_t kModules[] = {
|
||||
{"fortsense"}, {"fpc"}, {"fpc_fod"}, {"goodix"}, {"goodix:gf_fingerprint"},
|
||||
{"goodix_fod"}, {"goodix_fod6"}, {"silead"}, {"syna"},
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
static const uint16_t kVersion = HARDWARE_MODULE_API_VERSION(2, 1);
|
||||
static Fingerprint* sInstance;
|
||||
|
||||
Fingerprint::Fingerprint(std::shared_ptr<FingerprintConfig> config) : mConfig(std::move(config)) {
|
||||
sInstance = this; // keep track of the most recent instance
|
||||
|
||||
if (mDevice) {
|
||||
ALOGI("fingerprint HAL already opened");
|
||||
} else {
|
||||
for (auto& [module] : kModules) {
|
||||
std::string class_name;
|
||||
std::string class_module_id;
|
||||
|
||||
auto parts = ::android::base::Split(module, ":");
|
||||
|
||||
if (parts.size() == 2) {
|
||||
class_name = parts[0];
|
||||
class_module_id = parts[1];
|
||||
} else {
|
||||
class_name = module;
|
||||
class_module_id = FINGERPRINT_HARDWARE_MODULE_ID;
|
||||
}
|
||||
|
||||
mDevice = openFingerprintHal(class_name.c_str(), class_module_id.c_str());
|
||||
if (!mDevice) {
|
||||
ALOGE("Can't open HAL module, class: %s, module_id: %s", class_name.c_str(),
|
||||
class_module_id.c_str());
|
||||
continue;
|
||||
}
|
||||
ALOGI("Opened fingerprint HAL, class: %s, module_id: %s", class_name.c_str(),
|
||||
class_module_id.c_str());
|
||||
break;
|
||||
}
|
||||
if (!mDevice) {
|
||||
ALOGE("Can't open any fingerprint HAL module");
|
||||
}
|
||||
}
|
||||
|
||||
std::string sensorTypeProp = mConfig->get<std::string>("type");
|
||||
if (sensorTypeProp == "udfps" || sensorTypeProp == "udfps_optical") {
|
||||
if (sensorTypeProp == "udfps") {
|
||||
mSensorType = FingerprintSensorType::UNDER_DISPLAY_ULTRASONIC;
|
||||
} else {
|
||||
mSensorType = FingerprintSensorType::UNDER_DISPLAY_OPTICAL;
|
||||
}
|
||||
mUdfpsHandlerFactory = getUdfpsHandlerFactory();
|
||||
if (!mUdfpsHandlerFactory) {
|
||||
ALOGE("Can't get UdfpsHandlerFactory");
|
||||
} else {
|
||||
mUdfpsHandler = mUdfpsHandlerFactory->create();
|
||||
if (!mUdfpsHandler) {
|
||||
ALOGE("Can't create UdfpsHandler");
|
||||
} else {
|
||||
mUdfpsHandler->init(mDevice);
|
||||
}
|
||||
}
|
||||
} else if (sensorTypeProp == "side") {
|
||||
mSensorType = FingerprintSensorType::POWER_BUTTON;
|
||||
} else if (sensorTypeProp == "home") {
|
||||
mSensorType = FingerprintSensorType::HOME_BUTTON;
|
||||
} else if (sensorTypeProp == "rear") {
|
||||
mSensorType = FingerprintSensorType::REAR;
|
||||
} else {
|
||||
mSensorType = FingerprintSensorType::UNKNOWN;
|
||||
UNIMPLEMENTED(FATAL) << "unrecognized or unimplemented fingerprint behavior: "
|
||||
<< sensorTypeProp;
|
||||
}
|
||||
ALOGI("sensorTypeProp: %s", sensorTypeProp.c_str());
|
||||
}
|
||||
|
||||
Fingerprint::~Fingerprint() {
|
||||
ALOGV("~Fingerprint()");
|
||||
if (mUdfpsHandler) {
|
||||
mUdfpsHandlerFactory->destroy(mUdfpsHandler);
|
||||
}
|
||||
if (mDevice == nullptr) {
|
||||
ALOGE("No valid device");
|
||||
return;
|
||||
}
|
||||
int err;
|
||||
if (0 != (err = mDevice->common.close(reinterpret_cast<hw_device_t*>(mDevice)))) {
|
||||
ALOGE("Can't close fingerprint module, error: %d", err);
|
||||
return;
|
||||
}
|
||||
mDevice = nullptr;
|
||||
}
|
||||
|
||||
fingerprint_device_t* Fingerprint::openFingerprintHal(const char* class_name,
|
||||
const char* module_id) {
|
||||
const hw_module_t* hw_mdl = nullptr;
|
||||
|
||||
ALOGD("Opening fingerprint hal library...");
|
||||
if (hw_get_module_by_class(module_id, class_name, &hw_mdl) != 0) {
|
||||
ALOGE("Can't open fingerprint HW Module");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!hw_mdl) {
|
||||
ALOGE("No valid fingerprint module");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto module = reinterpret_cast<const fingerprint_module_t*>(hw_mdl);
|
||||
if (!module->common.methods->open) {
|
||||
ALOGE("No valid open method");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
hw_device_t* device = nullptr;
|
||||
if (module->common.methods->open(hw_mdl, nullptr, &device) != 0) {
|
||||
ALOGE("Can't open fingerprint methods");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto fp_device = reinterpret_cast<fingerprint_device_t*>(device);
|
||||
if (fp_device->set_notify(fp_device, Fingerprint::notify) != 0) {
|
||||
ALOGE("Can't register fingerprint module callback");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return fp_device;
|
||||
}
|
||||
|
||||
std::vector<SensorLocation> Fingerprint::getSensorLocations() {
|
||||
std::vector<SensorLocation> locations;
|
||||
|
||||
auto loc = mConfig->get<std::string>("sensor_location");
|
||||
auto entries = ::android::base::Split(loc, ",");
|
||||
|
||||
for (const auto& entry : entries) {
|
||||
auto isValidStr = false;
|
||||
auto dim = ::android::base::Split(entry, "|");
|
||||
|
||||
if (dim.size() != 3 and dim.size() != 4) {
|
||||
if (!loc.empty()) {
|
||||
ALOGE("Invalid sensor location input (x|y|radius) or (x|y|radius|display): %s",
|
||||
loc.c_str());
|
||||
}
|
||||
} else {
|
||||
int32_t x, y, r;
|
||||
std::string d;
|
||||
isValidStr = ParseInt(dim[0], &x) && ParseInt(dim[1], &y) && ParseInt(dim[2], &r);
|
||||
if (dim.size() == 4) {
|
||||
d = dim[3];
|
||||
isValidStr = isValidStr && !d.empty();
|
||||
}
|
||||
if (isValidStr)
|
||||
locations.push_back({.sensorLocationX = x,
|
||||
.sensorLocationY = y,
|
||||
.sensorRadius = r,
|
||||
.display = d});
|
||||
}
|
||||
}
|
||||
|
||||
return locations;
|
||||
}
|
||||
|
||||
void Fingerprint::notify(const fingerprint_msg_t* msg) {
|
||||
Fingerprint* thisPtr = sInstance;
|
||||
if (thisPtr == nullptr || thisPtr->mSession == nullptr || thisPtr->mSession->isClosed()) {
|
||||
ALOGE("Receiving callbacks before a session is opened.");
|
||||
return;
|
||||
}
|
||||
thisPtr->mSession->notify(msg);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Fingerprint::getSensorProps(std::vector<SensorProps>* out) {
|
||||
std::vector<common::ComponentInfo> componentInfo = {
|
||||
{HW_COMPONENT_ID, HW_VERSION, FW_VERSION, SERIAL_NUMBER, "" /* softwareVersion */},
|
||||
{SW_COMPONENT_ID, "" /* hardwareVersion */, "" /* firmwareVersion */,
|
||||
"" /* serialNumber */, SW_VERSION}};
|
||||
auto sensorId = mConfig->get<std::int32_t>("sensor_id");
|
||||
auto sensorStrength = mConfig->get<std::int32_t>("sensor_strength");
|
||||
auto navigationGuesture = mConfig->get<bool>("navigation_gesture");
|
||||
auto detectInteraction = mConfig->get<bool>("detect_interaction");
|
||||
auto displayTouch = mConfig->get<bool>("display_touch");
|
||||
auto controlIllumination = mConfig->get<bool>("control_illumination");
|
||||
|
||||
common::CommonProps commonProps = {sensorId, (common::SensorStrength)sensorStrength,
|
||||
MAX_ENROLLMENTS_PER_USER, componentInfo};
|
||||
|
||||
std::vector<SensorLocation> sensorLocations = getSensorLocations();
|
||||
|
||||
std::vector<std::string> sensorLocationStrings;
|
||||
std::transform(sensorLocations.begin(), sensorLocations.end(),
|
||||
std::back_inserter(sensorLocationStrings),
|
||||
[](const SensorLocation& obj) { return obj.toString(); });
|
||||
|
||||
ALOGI("sensor type: %s, location: %s", ::android::internal::ToString(mSensorType).c_str(),
|
||||
::android::base::Join(sensorLocationStrings, ", ").c_str());
|
||||
|
||||
*out = {{commonProps, mSensorType, sensorLocations, navigationGuesture, detectInteraction,
|
||||
displayTouch, controlIllumination, std::nullopt}};
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Fingerprint::createSession(int32_t /*sensorId*/, int32_t userId,
|
||||
const std::shared_ptr<ISessionCallback>& cb,
|
||||
std::shared_ptr<ISession>* out) {
|
||||
CHECK(mSession == nullptr || mSession->isClosed()) << "Open session already exists!";
|
||||
|
||||
mSession = SharedRefBase::make<Session>(mDevice, mUdfpsHandler, userId, cb, mLockoutTracker);
|
||||
*out = mSession;
|
||||
|
||||
mSession->linkToDeath(cb->asBinder().get());
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
} // namespace aidl::android::hardware::biometrics::fingerprint
|
||||
49
aidl/fingerprint/Fingerprint.h
Normal file
49
aidl/fingerprint/Fingerprint.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
* 2024 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <aidl/android/hardware/biometrics/fingerprint/BnFingerprint.h>
|
||||
|
||||
#include "FingerprintConfig.h"
|
||||
#include "LockoutTracker.h"
|
||||
#include "Session.h"
|
||||
#include "UdfpsHandler.h"
|
||||
|
||||
using ::aidl::android::hardware::biometrics::fingerprint::FingerprintSensorType;
|
||||
using ::aidl::android::hardware::biometrics::fingerprint::ISession;
|
||||
using ::aidl::android::hardware::biometrics::fingerprint::ISessionCallback;
|
||||
using ::aidl::android::hardware::biometrics::fingerprint::SensorProps;
|
||||
|
||||
namespace aidl::android::hardware::biometrics::fingerprint {
|
||||
|
||||
class Fingerprint : public BnFingerprint {
|
||||
public:
|
||||
Fingerprint(std::shared_ptr<FingerprintConfig> config);
|
||||
~Fingerprint();
|
||||
|
||||
ndk::ScopedAStatus getSensorProps(std::vector<SensorProps>* _aidl_return) override;
|
||||
ndk::ScopedAStatus createSession(int32_t sensorId, int32_t userId,
|
||||
const std::shared_ptr<ISessionCallback>& cb,
|
||||
std::shared_ptr<ISession>* out) override;
|
||||
|
||||
private:
|
||||
fingerprint_device_t* openFingerprintHal(const char* class_name, const char* module_id);
|
||||
std::vector<SensorLocation> getSensorLocations();
|
||||
static void notify(const fingerprint_msg_t* msg);
|
||||
|
||||
std::shared_ptr<FingerprintConfig> mConfig;
|
||||
std::shared_ptr<Session> mSession;
|
||||
LockoutTracker mLockoutTracker;
|
||||
FingerprintSensorType mSensorType;
|
||||
|
||||
fingerprint_device_t* mDevice;
|
||||
UdfpsHandlerFactory* mUdfpsHandlerFactory;
|
||||
UdfpsHandler* mUdfpsHandler;
|
||||
};
|
||||
|
||||
} // namespace aidl::android::hardware::biometrics::fingerprint
|
||||
56
aidl/fingerprint/FingerprintConfig.cpp
Normal file
56
aidl/fingerprint/FingerprintConfig.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Android Open Source Project
|
||||
* 2024 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define LOG_TAG "FingerprintConfig"
|
||||
|
||||
#include "FingerprintConfig.h"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
|
||||
#include <fingerprint.sysprop.h>
|
||||
|
||||
using namespace ::android::fingerprint::xiaomi;
|
||||
|
||||
namespace aidl::android::hardware::biometrics::fingerprint {
|
||||
|
||||
// Wrapper to system property access functions
|
||||
#define CREATE_GETTER_SETTER_WRAPPER(_NAME_, _T_) \
|
||||
ConfigValue _NAME_##Getter() { \
|
||||
return FingerprintHalProperties::_NAME_(); \
|
||||
} \
|
||||
bool _NAME_##Setter(const ConfigValue& v) { \
|
||||
return FingerprintHalProperties::_NAME_(std::get<_T_>(v)); \
|
||||
}
|
||||
|
||||
CREATE_GETTER_SETTER_WRAPPER(type, OptString)
|
||||
CREATE_GETTER_SETTER_WRAPPER(sensor_id, OptInt32)
|
||||
CREATE_GETTER_SETTER_WRAPPER(sensor_location, OptString)
|
||||
CREATE_GETTER_SETTER_WRAPPER(sensor_strength, OptInt32)
|
||||
CREATE_GETTER_SETTER_WRAPPER(navigation_gesture, OptBool)
|
||||
CREATE_GETTER_SETTER_WRAPPER(detect_interaction, OptBool)
|
||||
CREATE_GETTER_SETTER_WRAPPER(display_touch, OptBool)
|
||||
CREATE_GETTER_SETTER_WRAPPER(control_illumination, OptBool)
|
||||
|
||||
// Name, Getter, Setter, Parser and default value
|
||||
#define NGS(_NAME_) #_NAME_, _NAME_##Getter, _NAME_##Setter
|
||||
static Config::Data configData[] = {
|
||||
{NGS(type), &Config::parseString, ""},
|
||||
{NGS(sensor_id), &Config::parseInt32, "0"},
|
||||
{NGS(sensor_location), &Config::parseString, ""},
|
||||
{NGS(sensor_strength), &Config::parseInt32, "2"}, // STRONG
|
||||
{NGS(navigation_gesture), &Config::parseBool, "false"},
|
||||
{NGS(detect_interaction), &Config::parseBool, "false"},
|
||||
{NGS(display_touch), &Config::parseBool, "false"},
|
||||
{NGS(control_illumination), &Config::parseBool, "false"},
|
||||
};
|
||||
|
||||
Config::Data* FingerprintConfig::getConfigData(int* size) {
|
||||
*size = sizeof(configData) / sizeof(configData[0]);
|
||||
return configData;
|
||||
}
|
||||
|
||||
} // namespace aidl::android::hardware::biometrics::fingerprint
|
||||
18
aidl/fingerprint/FingerprintConfig.h
Normal file
18
aidl/fingerprint/FingerprintConfig.h
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Android Open Source Project
|
||||
* 2024 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "config/Config.h"
|
||||
|
||||
namespace aidl::android::hardware::biometrics::fingerprint {
|
||||
|
||||
class FingerprintConfig : public Config {
|
||||
Config::Data* getConfigData(int* size) override;
|
||||
};
|
||||
|
||||
} // namespace aidl::android::hardware::biometrics::fingerprint
|
||||
62
aidl/fingerprint/LockoutTracker.cpp
Normal file
62
aidl/fingerprint/LockoutTracker.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
* 2024 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "LockoutTracker.h"
|
||||
#include <fingerprint.sysprop.h>
|
||||
#include "Fingerprint.h"
|
||||
#include "util/Util.h"
|
||||
|
||||
using namespace ::android::fingerprint::xiaomi;
|
||||
|
||||
namespace aidl::android::hardware::biometrics::fingerprint {
|
||||
|
||||
void LockoutTracker::reset(bool clearAttemptCounter) {
|
||||
if (clearAttemptCounter) {
|
||||
mFailedCount = 0;
|
||||
}
|
||||
mLockoutTimedStart = 0;
|
||||
mCurrentMode = LockoutMode::kNone;
|
||||
}
|
||||
|
||||
void LockoutTracker::addFailedAttempt() {
|
||||
mFailedCount++;
|
||||
if (mFailedCount >= LOCKOUT_PERMANENT_THRESHOLD) {
|
||||
mCurrentMode = LockoutMode::kPermanent;
|
||||
} else if (mFailedCount >= LOCKOUT_TIMED_THRESHOLD) {
|
||||
if (mCurrentMode == LockoutMode::kNone) {
|
||||
mCurrentMode = LockoutMode::kTimed;
|
||||
mLockoutTimedStart = Util::getSystemNanoTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LockoutTracker::LockoutMode LockoutTracker::getMode() {
|
||||
if (mCurrentMode == LockoutMode::kTimed) {
|
||||
if (Util::hasElapsed(mLockoutTimedStart, LOCKOUT_TIMED_DURATION)) {
|
||||
mCurrentMode = LockoutMode::kNone;
|
||||
mLockoutTimedStart = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return mCurrentMode;
|
||||
}
|
||||
|
||||
int64_t LockoutTracker::getLockoutTimeLeft() {
|
||||
int64_t res = 0;
|
||||
|
||||
if (mLockoutTimedStart > 0) {
|
||||
auto now = Util::getSystemNanoTime();
|
||||
auto elapsed = (now - mLockoutTimedStart) / 1000000LL;
|
||||
res = LOCKOUT_TIMED_DURATION - elapsed;
|
||||
LOG(INFO) << "elapsed=" << elapsed << " now = " << now
|
||||
<< " mLockoutTimedStart=" << mLockoutTimedStart << " res=" << res;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
} // namespace aidl::android::hardware::biometrics::fingerprint
|
||||
46
aidl/fingerprint/LockoutTracker.h
Normal file
46
aidl/fingerprint/LockoutTracker.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
* 2024 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <android/binder_to_string.h>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
#define LOCKOUT_TIMED_THRESHOLD 5
|
||||
#define LOCKOUT_TIMED_DURATION 10000
|
||||
#define LOCKOUT_PERMANENT_THRESHOLD 20
|
||||
|
||||
namespace aidl::android::hardware::biometrics::fingerprint {
|
||||
|
||||
class LockoutTracker {
|
||||
public:
|
||||
LockoutTracker() : mFailedCount(0) {}
|
||||
~LockoutTracker() {}
|
||||
|
||||
enum class LockoutMode : int8_t { kNone = 0, kTimed, kPermanent };
|
||||
|
||||
void reset(bool clearAttemptCounter);
|
||||
LockoutMode getMode();
|
||||
void addFailedAttempt();
|
||||
int64_t getLockoutTimeLeft();
|
||||
inline std::string toString() const {
|
||||
std::ostringstream os;
|
||||
os << "----- LockoutTracker:: -----" << std::endl;
|
||||
os << "LockoutTracker::mFailedCount:" << mFailedCount;
|
||||
os << ", LockoutTracker::mCurrentMode:" << (int)mCurrentMode;
|
||||
os << std::endl;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
private:
|
||||
int32_t mFailedCount;
|
||||
int64_t mLockoutTimedStart;
|
||||
LockoutMode mCurrentMode;
|
||||
};
|
||||
|
||||
} // namespace aidl::android::hardware::biometrics::fingerprint
|
||||
388
aidl/fingerprint/Session.cpp
Normal file
388
aidl/fingerprint/Session.cpp
Normal file
@@ -0,0 +1,388 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <thread>
|
||||
|
||||
#include "Legacy2Aidl.h"
|
||||
#include "Session.h"
|
||||
|
||||
#include "CancellationSignal.h"
|
||||
|
||||
namespace aidl::android::hardware::biometrics::fingerprint {
|
||||
|
||||
void onClientDeath(void* cookie) {
|
||||
ALOGI("FingerprintService has died");
|
||||
Session* session = static_cast<Session*>(cookie);
|
||||
if (session && !session->isClosed()) {
|
||||
session->close();
|
||||
}
|
||||
}
|
||||
|
||||
Session::Session(fingerprint_device_t* device, UdfpsHandler* udfpsHandler, int userId,
|
||||
std::shared_ptr<ISessionCallback> cb, LockoutTracker lockoutTracker)
|
||||
: mDevice(device),
|
||||
mLockoutTracker(lockoutTracker),
|
||||
mUserId(userId),
|
||||
mCb(cb),
|
||||
mUdfpsHandler(udfpsHandler) {
|
||||
mDeathRecipient = AIBinder_DeathRecipient_new(onClientDeath);
|
||||
|
||||
auto path = std::format("/data/vendor_de/{}/fpdata/", userId);
|
||||
mDevice->set_active_group(mDevice, mUserId, path.c_str());
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Session::generateChallenge() {
|
||||
uint64_t challenge = mDevice->pre_enroll(mDevice);
|
||||
ALOGI("generateChallenge: %ld", challenge);
|
||||
mCb->onChallengeGenerated(challenge);
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Session::revokeChallenge(int64_t challenge) {
|
||||
ALOGI("revokeChallenge: %ld", challenge);
|
||||
mDevice->post_enroll(mDevice);
|
||||
mCb->onChallengeRevoked(challenge);
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Session::enroll(const HardwareAuthToken& hat,
|
||||
std::shared_ptr<ICancellationSignal>* out) {
|
||||
hw_auth_token_t authToken;
|
||||
translate(hat, authToken);
|
||||
int error = mDevice->enroll(mDevice, &authToken, mUserId, 60);
|
||||
if (error) {
|
||||
ALOGE("enroll failed: %d", error);
|
||||
mCb->onError(Error::UNABLE_TO_PROCESS, error);
|
||||
}
|
||||
|
||||
*out = SharedRefBase::make<CancellationSignal>(this);
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Session::authenticate(int64_t operationId,
|
||||
std::shared_ptr<ICancellationSignal>* out) {
|
||||
checkSensorLockout();
|
||||
int error = mDevice->authenticate(mDevice, operationId, mUserId);
|
||||
if (error) {
|
||||
ALOGE("authenticate failed: %d", error);
|
||||
mCb->onError(Error::UNABLE_TO_PROCESS, error);
|
||||
}
|
||||
|
||||
*out = SharedRefBase::make<CancellationSignal>(this);
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Session::detectInteraction(std::shared_ptr<ICancellationSignal>* out) {
|
||||
ALOGD("Detect interaction is not supported");
|
||||
mCb->onError(Error::UNABLE_TO_PROCESS, 0 /* vendorCode */);
|
||||
|
||||
*out = SharedRefBase::make<CancellationSignal>(this);
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Session::enumerateEnrollments() {
|
||||
int error = mDevice->enumerate(mDevice);
|
||||
if (error) {
|
||||
ALOGE("enumerate failed: %d", error);
|
||||
}
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Session::removeEnrollments(const std::vector<int32_t>& enrollmentIds) {
|
||||
ALOGI("removeEnrollments, size: %zu", enrollmentIds.size());
|
||||
|
||||
for (int32_t fid : enrollmentIds) {
|
||||
int error = mDevice->remove(mDevice, mUserId, fid);
|
||||
if (error) {
|
||||
ALOGE("remove failed: %d", error);
|
||||
}
|
||||
}
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Session::getAuthenticatorId() {
|
||||
uint64_t auth_id = mDevice->get_authenticator_id(mDevice);
|
||||
ALOGI("getAuthenticatorId: %ld", auth_id);
|
||||
mCb->onAuthenticatorIdRetrieved(auth_id);
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Session::invalidateAuthenticatorId() {
|
||||
uint64_t auth_id = mDevice->get_authenticator_id(mDevice);
|
||||
ALOGI("invalidateAuthenticatorId: %ld", auth_id);
|
||||
mCb->onAuthenticatorIdInvalidated(auth_id);
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Session::resetLockout(const HardwareAuthToken& /*hat*/) {
|
||||
clearLockout(true);
|
||||
if (mIsLockoutTimerStarted) mIsLockoutTimerAborted = true;
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Session::onPointerDown(int32_t /*pointerId*/, int32_t x, int32_t y, float minor,
|
||||
float major) {
|
||||
if (mUdfpsHandler) {
|
||||
mUdfpsHandler->onFingerDown(x, y, minor, major);
|
||||
}
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Session::onPointerUp(int32_t /*pointerId*/) {
|
||||
if (mUdfpsHandler) {
|
||||
mUdfpsHandler->onFingerUp();
|
||||
}
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Session::onUiReady() {
|
||||
// TODO: stub
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Session::authenticateWithContext(
|
||||
int64_t operationId, const common::OperationContext& /*context*/,
|
||||
std::shared_ptr<common::ICancellationSignal>* out) {
|
||||
return authenticate(operationId, out);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Session::enrollWithContext(const keymaster::HardwareAuthToken& hat,
|
||||
const common::OperationContext& /*context*/,
|
||||
std::shared_ptr<common::ICancellationSignal>* out) {
|
||||
return enroll(hat, out);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Session::detectInteractionWithContext(
|
||||
const common::OperationContext& /*context*/,
|
||||
std::shared_ptr<common::ICancellationSignal>* out) {
|
||||
return detectInteraction(out);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Session::onPointerDownWithContext(const PointerContext& context) {
|
||||
return onPointerDown(context.pointerId, context.x, context.y, context.minor, context.major);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Session::onPointerUpWithContext(const PointerContext& context) {
|
||||
return onPointerUp(context.pointerId);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Session::onContextChanged(const common::OperationContext& /*context*/) {
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Session::onPointerCancelWithContext(const PointerContext& /*context*/) {
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Session::setIgnoreDisplayTouches(bool /*shouldIgnore*/) {
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Session::cancel() {
|
||||
if (mUdfpsHandler) {
|
||||
mUdfpsHandler->cancel();
|
||||
}
|
||||
|
||||
int ret = mDevice->cancel(mDevice);
|
||||
|
||||
if (ret == 0) {
|
||||
mCb->onError(Error::CANCELED, 0 /* vendorCode */);
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
return ndk::ScopedAStatus::fromServiceSpecificError(ret);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Session::close() {
|
||||
mClosed = true;
|
||||
mCb->onSessionClosed();
|
||||
AIBinder_DeathRecipient_delete(mDeathRecipient);
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
binder_status_t Session::linkToDeath(AIBinder* binder) {
|
||||
return AIBinder_linkToDeath(binder, mDeathRecipient, this);
|
||||
}
|
||||
|
||||
bool Session::isClosed() {
|
||||
return mClosed;
|
||||
}
|
||||
|
||||
// Translate from errors returned by traditional HAL (see fingerprint.h) to
|
||||
// AIDL-compliant Error
|
||||
Error Session::VendorErrorFilter(int32_t error, int32_t* vendorCode) {
|
||||
*vendorCode = 0;
|
||||
|
||||
switch (error) {
|
||||
case FINGERPRINT_ERROR_HW_UNAVAILABLE:
|
||||
return Error::HW_UNAVAILABLE;
|
||||
case FINGERPRINT_ERROR_UNABLE_TO_PROCESS:
|
||||
return Error::UNABLE_TO_PROCESS;
|
||||
case FINGERPRINT_ERROR_TIMEOUT:
|
||||
return Error::TIMEOUT;
|
||||
case FINGERPRINT_ERROR_NO_SPACE:
|
||||
return Error::NO_SPACE;
|
||||
case FINGERPRINT_ERROR_CANCELED:
|
||||
return Error::CANCELED;
|
||||
case FINGERPRINT_ERROR_UNABLE_TO_REMOVE:
|
||||
return Error::UNABLE_TO_REMOVE;
|
||||
case FINGERPRINT_ERROR_LOCKOUT: {
|
||||
*vendorCode = FINGERPRINT_ERROR_LOCKOUT;
|
||||
return Error::VENDOR;
|
||||
}
|
||||
default:
|
||||
if (error >= FINGERPRINT_ERROR_VENDOR_BASE) {
|
||||
// vendor specific code.
|
||||
*vendorCode = error - FINGERPRINT_ERROR_VENDOR_BASE;
|
||||
return Error::VENDOR;
|
||||
}
|
||||
}
|
||||
ALOGE("Unknown error from fingerprint vendor library: %d", error);
|
||||
return Error::UNABLE_TO_PROCESS;
|
||||
}
|
||||
|
||||
// Translate acquired messages returned by traditional HAL (see fingerprint.h)
|
||||
// to AIDL-compliant AcquiredInfo
|
||||
AcquiredInfo Session::VendorAcquiredFilter(int32_t info, int32_t* vendorCode) {
|
||||
*vendorCode = 0;
|
||||
|
||||
switch (info) {
|
||||
case FINGERPRINT_ACQUIRED_GOOD:
|
||||
return AcquiredInfo::GOOD;
|
||||
case FINGERPRINT_ACQUIRED_PARTIAL:
|
||||
return AcquiredInfo::PARTIAL;
|
||||
case FINGERPRINT_ACQUIRED_INSUFFICIENT:
|
||||
return AcquiredInfo::INSUFFICIENT;
|
||||
case FINGERPRINT_ACQUIRED_IMAGER_DIRTY:
|
||||
return AcquiredInfo::SENSOR_DIRTY;
|
||||
case FINGERPRINT_ACQUIRED_TOO_SLOW:
|
||||
return AcquiredInfo::TOO_SLOW;
|
||||
case FINGERPRINT_ACQUIRED_TOO_FAST:
|
||||
return AcquiredInfo::TOO_FAST;
|
||||
default:
|
||||
if (info >= FINGERPRINT_ACQUIRED_VENDOR_BASE) {
|
||||
// vendor specific code.
|
||||
*vendorCode = info - FINGERPRINT_ACQUIRED_VENDOR_BASE;
|
||||
return AcquiredInfo::VENDOR;
|
||||
}
|
||||
}
|
||||
ALOGE("Unknown acquired message from fingerprint vendor library: %d", info);
|
||||
return AcquiredInfo::UNKNOWN;
|
||||
}
|
||||
|
||||
bool Session::checkSensorLockout() {
|
||||
LockoutTracker::LockoutMode lockoutMode = mLockoutTracker.getMode();
|
||||
if (lockoutMode == LockoutTracker::LockoutMode::kPermanent) {
|
||||
ALOGE("Fail: lockout permanent");
|
||||
mCb->onLockoutPermanent();
|
||||
mIsLockoutTimerAborted = true;
|
||||
return true;
|
||||
}
|
||||
if (lockoutMode == LockoutTracker::LockoutMode::kTimed) {
|
||||
int64_t timeLeft = mLockoutTracker.getLockoutTimeLeft();
|
||||
ALOGE("Fail: lockout timed: %ld", timeLeft);
|
||||
mCb->onLockoutTimed(timeLeft);
|
||||
if (!mIsLockoutTimerStarted) startLockoutTimer(timeLeft);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Session::clearLockout(bool clearAttemptCounter) {
|
||||
mLockoutTracker.reset(clearAttemptCounter);
|
||||
mCb->onLockoutCleared();
|
||||
}
|
||||
|
||||
void Session::startLockoutTimer(int64_t timeout) {
|
||||
std::function<void()> action = std::bind(&Session::lockoutTimerExpired, this);
|
||||
std::thread([timeout, action]() {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(timeout));
|
||||
action();
|
||||
}).detach();
|
||||
|
||||
mIsLockoutTimerStarted = true;
|
||||
}
|
||||
|
||||
void Session::lockoutTimerExpired() {
|
||||
if (!mIsLockoutTimerAborted) clearLockout(false);
|
||||
|
||||
mIsLockoutTimerStarted = false;
|
||||
mIsLockoutTimerAborted = false;
|
||||
}
|
||||
|
||||
void Session::notify(const fingerprint_msg_t* msg) {
|
||||
// const uint64_t devId = reinterpret_cast<uint64_t>(mDevice);
|
||||
switch (msg->type) {
|
||||
case FINGERPRINT_ERROR: {
|
||||
int32_t vendorCode = 0;
|
||||
Error result = VendorErrorFilter(msg->data.error, &vendorCode);
|
||||
ALOGD("onError(%hhd, %d)", result, vendorCode);
|
||||
mCb->onError(result, vendorCode);
|
||||
} break;
|
||||
case FINGERPRINT_ACQUIRED: {
|
||||
int32_t vendorCode = 0;
|
||||
AcquiredInfo result =
|
||||
VendorAcquiredFilter(msg->data.acquired.acquired_info, &vendorCode);
|
||||
ALOGD("onAcquired(%hhd, %d)", result, vendorCode);
|
||||
if (mUdfpsHandler) {
|
||||
mUdfpsHandler->onAcquired(static_cast<int32_t>(result), vendorCode);
|
||||
}
|
||||
// don't process vendor messages further since frameworks try to disable
|
||||
// udfps display mode on vendor acquired messages but our sensors send a
|
||||
// vendor message during processing...
|
||||
if (result != AcquiredInfo::VENDOR) {
|
||||
mCb->onAcquired(result, vendorCode);
|
||||
}
|
||||
} break;
|
||||
case FINGERPRINT_TEMPLATE_ENROLLING: {
|
||||
ALOGD("onEnrollResult(fid=%d, gid=%d, rem=%d)", msg->data.enroll.finger.fid,
|
||||
msg->data.enroll.finger.gid, msg->data.enroll.samples_remaining);
|
||||
mCb->onEnrollmentProgress(msg->data.enroll.finger.fid,
|
||||
msg->data.enroll.samples_remaining);
|
||||
} break;
|
||||
case FINGERPRINT_TEMPLATE_REMOVED: {
|
||||
ALOGD("onRemove(fid=%d, gid=%d, rem=%d)", msg->data.removed.finger.fid,
|
||||
msg->data.removed.finger.gid, msg->data.removed.remaining_templates);
|
||||
std::vector<int> enrollments;
|
||||
enrollments.push_back(msg->data.removed.finger.fid);
|
||||
mCb->onEnrollmentsRemoved(enrollments);
|
||||
} break;
|
||||
case FINGERPRINT_AUTHENTICATED: {
|
||||
ALOGD("onAuthenticated(fid=%d, gid=%d)", msg->data.authenticated.finger.fid,
|
||||
msg->data.authenticated.finger.gid);
|
||||
if (msg->data.authenticated.finger.fid != 0) {
|
||||
const hw_auth_token_t hat = msg->data.authenticated.hat;
|
||||
HardwareAuthToken authToken;
|
||||
translate(hat, authToken);
|
||||
|
||||
mCb->onAuthenticationSucceeded(msg->data.authenticated.finger.fid, authToken);
|
||||
mLockoutTracker.reset(true);
|
||||
} else {
|
||||
mCb->onAuthenticationFailed();
|
||||
mLockoutTracker.addFailedAttempt();
|
||||
checkSensorLockout();
|
||||
}
|
||||
} break;
|
||||
case FINGERPRINT_TEMPLATE_ENUMERATING: {
|
||||
ALOGD("onEnumerate(fid=%d, gid=%d, rem=%d)", msg->data.enumerated.finger.fid,
|
||||
msg->data.enumerated.finger.gid, msg->data.enumerated.remaining_templates);
|
||||
static std::vector<int> enrollments;
|
||||
enrollments.push_back(msg->data.enumerated.finger.fid);
|
||||
if (msg->data.enumerated.remaining_templates == 0) {
|
||||
mCb->onEnrollmentsEnumerated(enrollments);
|
||||
enrollments.clear();
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace aidl::android::hardware::biometrics::fingerprint
|
||||
100
aidl/fingerprint/Session.h
Normal file
100
aidl/fingerprint/Session.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#define LOG_TAG "android.hardware.biometrics.fingerprint-service.xiaomi"
|
||||
|
||||
#include <aidl/android/hardware/biometrics/fingerprint/BnSession.h>
|
||||
#include <aidl/android/hardware/biometrics/fingerprint/ISessionCallback.h>
|
||||
#include <android/log.h>
|
||||
#include <hardware/hardware.h>
|
||||
#include <log/log.h>
|
||||
#include "fingerprint.h"
|
||||
|
||||
#include "LockoutTracker.h"
|
||||
#include "UdfpsHandler.h"
|
||||
|
||||
using ::aidl::android::hardware::biometrics::common::ICancellationSignal;
|
||||
using ::aidl::android::hardware::biometrics::common::OperationContext;
|
||||
using ::aidl::android::hardware::biometrics::fingerprint::PointerContext;
|
||||
using ::aidl::android::hardware::keymaster::HardwareAuthToken;
|
||||
|
||||
namespace aidl::android::hardware::biometrics::fingerprint {
|
||||
|
||||
void onClientDeath(void* cookie);
|
||||
|
||||
class Session : public BnSession {
|
||||
public:
|
||||
Session(fingerprint_device_t* device, UdfpsHandler* udfpsHandler, int userId,
|
||||
std::shared_ptr<ISessionCallback> cb, LockoutTracker lockoutTracker);
|
||||
ndk::ScopedAStatus generateChallenge() override;
|
||||
ndk::ScopedAStatus revokeChallenge(int64_t challenge) override;
|
||||
ndk::ScopedAStatus enroll(const HardwareAuthToken& hat,
|
||||
std::shared_ptr<ICancellationSignal>* out) override;
|
||||
ndk::ScopedAStatus authenticate(int64_t operationId,
|
||||
std::shared_ptr<ICancellationSignal>* out) override;
|
||||
ndk::ScopedAStatus detectInteraction(std::shared_ptr<ICancellationSignal>* out) override;
|
||||
ndk::ScopedAStatus enumerateEnrollments() override;
|
||||
ndk::ScopedAStatus removeEnrollments(const std::vector<int32_t>& enrollmentIds) override;
|
||||
ndk::ScopedAStatus getAuthenticatorId() override;
|
||||
ndk::ScopedAStatus invalidateAuthenticatorId() override;
|
||||
ndk::ScopedAStatus resetLockout(const HardwareAuthToken& hat) override;
|
||||
ndk::ScopedAStatus close() override;
|
||||
ndk::ScopedAStatus onPointerDown(int32_t pointerId, int32_t x, int32_t y, float minor,
|
||||
float major) override;
|
||||
ndk::ScopedAStatus onPointerUp(int32_t pointerId) override;
|
||||
ndk::ScopedAStatus onUiReady() override;
|
||||
ndk::ScopedAStatus authenticateWithContext(int64_t operationId, const OperationContext& context,
|
||||
std::shared_ptr<ICancellationSignal>* out) override;
|
||||
ndk::ScopedAStatus enrollWithContext(const HardwareAuthToken& hat,
|
||||
const OperationContext& context,
|
||||
std::shared_ptr<ICancellationSignal>* out) override;
|
||||
ndk::ScopedAStatus detectInteractionWithContext(
|
||||
const OperationContext& context, std::shared_ptr<ICancellationSignal>* out) override;
|
||||
ndk::ScopedAStatus onPointerDownWithContext(const PointerContext& context) override;
|
||||
ndk::ScopedAStatus onPointerUpWithContext(const PointerContext& context) override;
|
||||
ndk::ScopedAStatus onContextChanged(const OperationContext& context) override;
|
||||
ndk::ScopedAStatus onPointerCancelWithContext(const PointerContext& context) override;
|
||||
ndk::ScopedAStatus setIgnoreDisplayTouches(bool shouldIgnore) override;
|
||||
|
||||
ndk::ScopedAStatus cancel();
|
||||
binder_status_t linkToDeath(AIBinder* binder);
|
||||
bool isClosed();
|
||||
void notify(const fingerprint_msg_t* msg);
|
||||
|
||||
private:
|
||||
fingerprint_device_t* mDevice;
|
||||
LockoutTracker mLockoutTracker;
|
||||
bool mClosed = false;
|
||||
|
||||
// static ndk::ScopedAStatus ErrorFilter(int32_t error);
|
||||
static Error VendorErrorFilter(int32_t error, int32_t* vendorCode);
|
||||
static AcquiredInfo VendorAcquiredFilter(int32_t info, int32_t* vendorCode);
|
||||
|
||||
bool checkSensorLockout();
|
||||
void clearLockout(bool clearAttemptCounter);
|
||||
void startLockoutTimer(int64_t timeout);
|
||||
void lockoutTimerExpired();
|
||||
|
||||
// lockout timer
|
||||
bool mIsLockoutTimerStarted = false;
|
||||
bool mIsLockoutTimerAborted = false;
|
||||
|
||||
// The user ID for which this session was created.
|
||||
int32_t mUserId;
|
||||
|
||||
// Callback for talking to the framework. This callback must only be called from non-binder
|
||||
// threads to prevent nested binder calls and consequently a binder thread exhaustion.
|
||||
// Practically, it means that this callback should always be called from the worker thread.
|
||||
std::shared_ptr<ISessionCallback> mCb;
|
||||
|
||||
// Binder death handler.
|
||||
AIBinder_DeathRecipient* mDeathRecipient;
|
||||
|
||||
UdfpsHandler* mUdfpsHandler;
|
||||
};
|
||||
|
||||
} // namespace aidl::android::hardware::biometrics::fingerprint
|
||||
@@ -0,0 +1,9 @@
|
||||
service vendor.fingerprint-default /vendor/bin/hw/android.hardware.biometrics.fingerprint-service.xiaomi
|
||||
# "class hal" causes a race condition on some devices due to files created
|
||||
# in /data. As a workaround, postpone startup until later in boot once
|
||||
# /data is mounted.
|
||||
class late_start
|
||||
user system
|
||||
group system input uhid
|
||||
shutdown critical
|
||||
task_profiles ProcessCapacityHigh MaxPerformance
|
||||
@@ -0,0 +1,7 @@
|
||||
<manifest version="1.0" type="device">
|
||||
<hal format="aidl">
|
||||
<name>android.hardware.biometrics.fingerprint</name>
|
||||
<version>4</version>
|
||||
<fqname>IFingerprint/default</fqname>
|
||||
</hal>
|
||||
</manifest>
|
||||
79
aidl/fingerprint/fingerprint.sysprop
Normal file
79
aidl/fingerprint/fingerprint.sysprop
Normal file
@@ -0,0 +1,79 @@
|
||||
# fingerprint.sysprop
|
||||
# module becomes static class (Java) / namespace (C++) for serving API
|
||||
module: "android.fingerprint.xiaomi.FingerprintHalProperties"
|
||||
owner: Vendor
|
||||
|
||||
# type of fingerprint sensor (default: none)
|
||||
prop {
|
||||
prop_name: "persist.vendor.fingerprint.type"
|
||||
type: String
|
||||
scope: Internal
|
||||
access: ReadWrite
|
||||
enum_values: "udfps|udfps_optical|side|home|rear"
|
||||
api_name: "type"
|
||||
}
|
||||
|
||||
# sensor location
|
||||
# <x>|<y>|<radius>|<display> in pixel, can have multiple values separated by comma
|
||||
prop {
|
||||
prop_name: "persist.vendor.fingerprint.sensor_location"
|
||||
type: String
|
||||
scope: Internal
|
||||
access: ReadWrite
|
||||
api_name: "sensor_location"
|
||||
}
|
||||
|
||||
# sensor id (default: 0)
|
||||
prop {
|
||||
prop_name: "persist.vendor.fingerprint.sensor_id"
|
||||
type: Integer
|
||||
scope: Internal
|
||||
access: ReadWrite
|
||||
api_name: "sensor_id"
|
||||
}
|
||||
|
||||
# sensor strength (default: 2)
|
||||
# [0=CONVENIENCE, 1=WEAK, 2=STRONG]
|
||||
prop {
|
||||
prop_name: "persist.vendor.fingerprint.sensor_strength"
|
||||
type: Integer
|
||||
scope: Internal
|
||||
access: ReadWrite
|
||||
api_name: "sensor_strength"
|
||||
}
|
||||
|
||||
# whether support navigation guestures (default: false)
|
||||
prop {
|
||||
prop_name: "persist.vendor.fingerprint.navigation_gesture"
|
||||
type: Boolean
|
||||
scope: Internal
|
||||
access: ReadWrite
|
||||
api_name: "navigation_gesture"
|
||||
}
|
||||
|
||||
# whether support detect interaction (default: false)
|
||||
prop {
|
||||
prop_name: "persist.vendor.fingerprint.detect_interaction"
|
||||
type: Boolean
|
||||
scope: Internal
|
||||
access: ReadWrite
|
||||
api_name: "detect_interaction"
|
||||
}
|
||||
|
||||
# whether support display touch by hal (default: false)
|
||||
prop {
|
||||
prop_name: "persist.vendor.fingerprint.udfps.display_touch"
|
||||
type: Boolean
|
||||
scope: Internal
|
||||
access: ReadWrite
|
||||
api_name: "display_touch"
|
||||
}
|
||||
|
||||
# whether support illumination control by hal (default: false)
|
||||
prop {
|
||||
prop_name: "persist.vendor.fingerprint.udfps.control_illumination"
|
||||
type: Boolean
|
||||
scope: Internal
|
||||
access: ReadWrite
|
||||
api_name: "control_illumination"
|
||||
}
|
||||
41
aidl/fingerprint/include/Legacy2Aidl.h
Normal file
41
aidl/fingerprint/include/Legacy2Aidl.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <aidl/android/hardware/keymaster/HardwareAuthToken.h>
|
||||
|
||||
#include <hardware/hw_auth_token.h>
|
||||
|
||||
#include <endian.h>
|
||||
|
||||
namespace aidl::android::hardware::biometrics::fingerprint {
|
||||
|
||||
inline void translate(const ::aidl::android::hardware::keymaster::HardwareAuthToken& authToken,
|
||||
hw_auth_token_t& hat) {
|
||||
hat.challenge = authToken.challenge;
|
||||
hat.user_id = authToken.userId;
|
||||
hat.authenticator_id = authToken.authenticatorId;
|
||||
// these are in host order: translate to network order
|
||||
hat.authenticator_type = htobe32(static_cast<uint32_t>(authToken.authenticatorType));
|
||||
hat.timestamp = htobe64(authToken.timestamp.milliSeconds);
|
||||
std::copy(authToken.mac.begin(), authToken.mac.end(), hat.hmac);
|
||||
}
|
||||
|
||||
inline void translate(const hw_auth_token_t& hat,
|
||||
::aidl::android::hardware::keymaster::HardwareAuthToken& authToken) {
|
||||
authToken.challenge = hat.challenge;
|
||||
authToken.userId = hat.user_id;
|
||||
authToken.authenticatorId = hat.authenticator_id;
|
||||
// these are in network order: translate to host
|
||||
authToken.authenticatorType =
|
||||
static_cast<::aidl::android::hardware::keymaster::HardwareAuthenticatorType>(
|
||||
be32toh(hat.authenticator_type));
|
||||
authToken.timestamp.milliSeconds = be64toh(hat.timestamp);
|
||||
authToken.mac.insert(authToken.mac.begin(), std::begin(hat.hmac), std::end(hat.hmac));
|
||||
}
|
||||
|
||||
} // namespace aidl::android::hardware::biometrics::fingerprint
|
||||
32
aidl/fingerprint/service.cpp
Normal file
32
aidl/fingerprint/service.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "Fingerprint.h"
|
||||
#include "FingerprintConfig.h"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <android/binder_manager.h>
|
||||
#include <android/binder_process.h>
|
||||
|
||||
using ::aidl::android::hardware::biometrics::fingerprint::Fingerprint;
|
||||
using ::aidl::android::hardware::biometrics::fingerprint::FingerprintConfig;
|
||||
|
||||
int main() {
|
||||
ABinderProcess_setThreadPoolMaxThreadCount(0);
|
||||
|
||||
std::shared_ptr<FingerprintConfig> config = std::make_shared<FingerprintConfig>();
|
||||
config->init();
|
||||
|
||||
std::shared_ptr<Fingerprint> fingerprint = ndk::SharedRefBase::make<Fingerprint>(config);
|
||||
|
||||
const std::string instance = std::string() + Fingerprint::descriptor + "/default";
|
||||
binder_status_t status =
|
||||
AServiceManager_addService(fingerprint->asBinder().get(), instance.c_str());
|
||||
CHECK(status == STATUS_OK);
|
||||
|
||||
ABinderProcess_joinThreadPool();
|
||||
return EXIT_FAILURE; // should not reach
|
||||
}
|
||||
48
aidl/health/Android.bp
Normal file
48
aidl/health/Android.bp
Normal file
@@ -0,0 +1,48 @@
|
||||
cc_defaults {
|
||||
name: "android.hardware.health-service.xiaomi-defaults",
|
||||
relative_install_path: "hw",
|
||||
vintf_fragments: ["android.hardware.health-service.xiaomi.xml"],
|
||||
vendor: true,
|
||||
recovery_available: true,
|
||||
|
||||
defaults: [
|
||||
"libhealth_aidl_impl_user",
|
||||
],
|
||||
|
||||
include_dirs: [
|
||||
"system/core/healthd",
|
||||
"system/core/healthd/include",
|
||||
"system/core/healthd/include_charger"
|
||||
],
|
||||
|
||||
static_libs: [
|
||||
"libhealth_aidl_impl",
|
||||
],
|
||||
|
||||
srcs: [
|
||||
"main.cpp",
|
||||
],
|
||||
|
||||
cflags: [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
],
|
||||
}
|
||||
|
||||
cc_binary {
|
||||
name: "android.hardware.health-service.xiaomi",
|
||||
recovery: false,
|
||||
vendor: true,
|
||||
defaults: ["android.hardware.health-service.xiaomi-defaults"],
|
||||
init_rc: ["android.hardware.health-service.xiaomi.rc"],
|
||||
overrides: ["charger","android.hardware.health-service.qti"],
|
||||
}
|
||||
|
||||
cc_binary {
|
||||
name: "android.hardware.health-service.xiaomi_recovery",
|
||||
vendor: false,
|
||||
recovery: true,
|
||||
defaults: ["android.hardware.health-service.xiaomi-defaults"],
|
||||
init_rc: ["android.hardware.health-service.xiaomi_recovery.rc"],
|
||||
overrides: ["charger.recovery", "android.hardware.health-service.qti_recovery"],
|
||||
}
|
||||
14
aidl/health/android.hardware.health-service.xiaomi.rc
Normal file
14
aidl/health/android.hardware.health-service.xiaomi.rc
Normal file
@@ -0,0 +1,14 @@
|
||||
service vendor.health-default /vendor/bin/hw/android.hardware.health-service.xiaomi
|
||||
class hal
|
||||
user system
|
||||
group system
|
||||
capabilities WAKE_ALARM BLOCK_SUSPEND
|
||||
file /dev/kmsg w
|
||||
|
||||
service vendor.charger /vendor/bin/hw/android.hardware.health-service.xiaomi --charger
|
||||
class charger
|
||||
seclabel u:r:charger_vendor:s0
|
||||
user system
|
||||
group system wakelock input graphics
|
||||
capabilities SYS_BOOT WAKE_ALARM BLOCK_SUSPEND
|
||||
file /dev/kmsg w
|
||||
12
aidl/health/android.hardware.health-service.xiaomi.xml
Normal file
12
aidl/health/android.hardware.health-service.xiaomi.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<!--
|
||||
Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||
-->
|
||||
|
||||
<manifest version="1.0" type="device">
|
||||
<hal format="aidl">
|
||||
<name>android.hardware.health</name>
|
||||
<version>3</version>
|
||||
<fqname>IHealth/default</fqname>
|
||||
</hal>
|
||||
</manifest>
|
||||
@@ -0,0 +1,7 @@
|
||||
service vendor.health-recovery /system/bin/hw/android.hardware.health-service.xiaomi_recovery
|
||||
class hal
|
||||
seclabel u:r:hal_health_default:s0
|
||||
user system
|
||||
group system
|
||||
capabilities WAKE_ALARM BLOCK_SUSPEND
|
||||
file /dev/kmsg w
|
||||
123
aidl/health/main.cpp
Normal file
123
aidl/health/main.cpp
Normal file
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
* SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||
*/
|
||||
|
||||
#define LOG_TAG "android.hardware.health-service.xiaomi"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <android/binder_interface_utils.h>
|
||||
#include <health/utils.h>
|
||||
#include <health-impl/ChargerUtils.h>
|
||||
#include <health-impl/Health.h>
|
||||
#include <cutils/klog.h>
|
||||
|
||||
using aidl::android::hardware::health::HalHealthLoop;
|
||||
using aidl::android::hardware::health::Health;
|
||||
|
||||
#if !CHARGER_FORCE_NO_UI
|
||||
using aidl::android::hardware::health::charger::ChargerCallback;
|
||||
using aidl::android::hardware::health::charger::ChargerModeMain;
|
||||
namespace aidl::android::hardware::health {
|
||||
class ChargerCallbackImpl : public ChargerCallback {
|
||||
public:
|
||||
ChargerCallbackImpl(const std::shared_ptr<Health>& service) : ChargerCallback(service) {}
|
||||
bool ChargerEnableSuspend() override { return true; }
|
||||
};
|
||||
} //namespace aidl::android::hardware::health
|
||||
#endif
|
||||
|
||||
namespace aidl::android::hardware::health {
|
||||
static constexpr int kChargeCounterMultiplier = 1000; // mAh to uAh
|
||||
static constexpr int kChargeTimeToFullMultiplier = 60; // mins to secs
|
||||
class HealthImpl : public Health {
|
||||
public:
|
||||
using Health::Health;
|
||||
virtual ~HealthImpl() {}
|
||||
ndk::ScopedAStatus getChargeCounterUah(int32_t* out) override;
|
||||
protected:
|
||||
void UpdateHealthInfo(HealthInfo* health_info) override;
|
||||
};
|
||||
void HealthImpl::UpdateHealthInfo(HealthInfo* health_info) {
|
||||
if (health_info->batteryChargeTimeToFullNowSeconds == 65535) {
|
||||
health_info->batteryChargeTimeToFullNowSeconds = -1;
|
||||
} else {
|
||||
health_info->batteryChargeTimeToFullNowSeconds *= kChargeTimeToFullMultiplier;
|
||||
}
|
||||
health_info->batteryChargeCounterUah *= kChargeCounterMultiplier;
|
||||
}
|
||||
ndk::ScopedAStatus HealthImpl::getChargeCounterUah(int32_t* out) {
|
||||
*out *= kChargeCounterMultiplier;
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
} // namespace aidl::android::hardware::health
|
||||
|
||||
static constexpr const char* gInstanceName = "default";
|
||||
static constexpr std::string_view gChargerArg{"--charger"};
|
||||
|
||||
constexpr char ucsiPSYName[]{"ucsi-source-psy-soc:qcom,pmic_glink:qcom,ucsi1"};
|
||||
|
||||
#define RETRY_COUNT 100
|
||||
|
||||
void qti_healthd_board_init(struct healthd_config *hc)
|
||||
{
|
||||
int fd;
|
||||
unsigned char retries = RETRY_COUNT;
|
||||
int ret = 0;
|
||||
unsigned char buf;
|
||||
|
||||
hc->ignorePowerSupplyNames.push_back(android::String8(ucsiPSYName));
|
||||
retry:
|
||||
if (!retries) {
|
||||
KLOG_ERROR(LOG_TAG, "Cannot open battery/capacity, fd=%d\n", fd);
|
||||
return;
|
||||
}
|
||||
|
||||
fd = open("/sys/class/power_supply/battery/capacity", 0440);
|
||||
if (fd >= 0) {
|
||||
KLOG_INFO(LOG_TAG, "opened battery/capacity after %d retries\n", RETRY_COUNT - retries);
|
||||
while (retries) {
|
||||
ret = read(fd, &buf, 1);
|
||||
if(ret >= 0) {
|
||||
KLOG_INFO(LOG_TAG, "Read Batt Capacity after %d retries ret : %d\n", RETRY_COUNT - retries, ret);
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
retries--;
|
||||
usleep(100000);
|
||||
}
|
||||
|
||||
KLOG_ERROR(LOG_TAG, "Failed to read Battery Capacity ret=%d\n", ret);
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
retries--;
|
||||
usleep(100000);
|
||||
goto retry;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
#ifdef __ANDROID_RECOVERY__
|
||||
android::base::InitLogging(argv, android::base::KernelLogger);
|
||||
#endif
|
||||
auto config = std::make_unique<healthd_config>();
|
||||
qti_healthd_board_init(config.get());
|
||||
::android::hardware::health::InitHealthdConfig(config.get());
|
||||
auto binder = ndk::SharedRefBase::make<aidl::android::hardware::health::HealthImpl>(gInstanceName, std::move(config));
|
||||
|
||||
if (argc >= 2 && argv[1] == gChargerArg) {
|
||||
#if !CHARGER_FORCE_NO_UI
|
||||
KLOG_INFO(LOG_TAG, "Starting charger mode with UI.");
|
||||
auto charger_callback = std::make_shared<aidl::android::hardware::health::ChargerCallbackImpl>(binder);
|
||||
return ChargerModeMain(binder, charger_callback);
|
||||
#endif
|
||||
KLOG_INFO(LOG_TAG, "Starting charger mode without UI.");
|
||||
} else {
|
||||
KLOG_INFO(LOG_TAG, "Starting health HAL.");
|
||||
}
|
||||
|
||||
auto hal_health_loop = std::make_shared<HalHealthLoop>(binder, binder);
|
||||
return hal_health_loop->StartLoop();
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
//
|
||||
// Copyright (C) 2021-2024 The LineageOS Project
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
cc_binary {
|
||||
name: "android.hardware.light-service.xiaomi",
|
||||
defaults: ["hidl_defaults"],
|
||||
vendor: true,
|
||||
relative_install_path: "hw",
|
||||
init_rc: ["android.hardware.light-service.xiaomi.rc"],
|
||||
vintf_fragments: ["android.hardware.light-service.xiaomi.xml"],
|
||||
srcs: [
|
||||
"BacklightDevice.cpp",
|
||||
"Devices.cpp",
|
||||
"LedDevice.cpp",
|
||||
"Lights.cpp",
|
||||
"RgbLedDevice.cpp",
|
||||
"Utils.cpp",
|
||||
"service.cpp",
|
||||
],
|
||||
shared_libs: [
|
||||
"libbase",
|
||||
"libbinder_ndk",
|
||||
"android.hardware.light-V2-ndk",
|
||||
],
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2022-2024 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "BacklightDevice.h"
|
||||
|
||||
#define LOG_TAG "BacklightDevice"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <fstream>
|
||||
#include "Utils.h"
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace light {
|
||||
|
||||
static const std::string kBacklightBasePath = "/sys/class/backlight/";
|
||||
static const uint32_t kDefaultMaxBrightness = 255;
|
||||
|
||||
static const std::string kBrightnessNode = "brightness";
|
||||
static const std::string kMaxBrightnessNode = "max_brightness";
|
||||
|
||||
BacklightDevice::BacklightDevice(std::string name)
|
||||
: mName(name), mBasePath(kBacklightBasePath + name + "/") {
|
||||
if (!readFromFile(mBasePath + kMaxBrightnessNode, mMaxBrightness)) {
|
||||
mMaxBrightness = kDefaultMaxBrightness;
|
||||
}
|
||||
};
|
||||
|
||||
std::string BacklightDevice::getName() const {
|
||||
return mName;
|
||||
}
|
||||
|
||||
bool BacklightDevice::exists() const {
|
||||
return std::ifstream(mBasePath + kBrightnessNode).good();
|
||||
}
|
||||
|
||||
bool BacklightDevice::setBrightness(uint8_t value) {
|
||||
return writeToFile(mBasePath + kBrightnessNode, scaleBrightness(value, mMaxBrightness));
|
||||
}
|
||||
|
||||
void BacklightDevice::dump(int fd) const {
|
||||
dprintf(fd, "Name: %s", mName.c_str());
|
||||
dprintf(fd, ", exists: %d", exists());
|
||||
dprintf(fd, ", base path: %s", mBasePath.c_str());
|
||||
dprintf(fd, ", max brightness: %u", mMaxBrightness);
|
||||
}
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2022-2024 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include "IDumpable.h"
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace light {
|
||||
|
||||
/**
|
||||
* A Linux backlight device.
|
||||
* @see https://www.kernel.org/doc/Documentation/ABI/stable/sysfs-class-backlight
|
||||
*/
|
||||
class BacklightDevice : public IDumpable {
|
||||
public:
|
||||
BacklightDevice() = delete;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param name The name of the backlight device
|
||||
*/
|
||||
BacklightDevice(std::string name);
|
||||
|
||||
/**
|
||||
* Get the name of the backlight device.
|
||||
*
|
||||
* @return std::string The name of the backlight device
|
||||
*/
|
||||
std::string getName() const;
|
||||
|
||||
/**
|
||||
* Return whether this backlight device exists.
|
||||
*
|
||||
* @return bool true if the backlight device exists, false otherwise
|
||||
*/
|
||||
bool exists() const;
|
||||
|
||||
/**
|
||||
* Set the brightness of this backlight device.
|
||||
*
|
||||
* @param value The brightness value to set
|
||||
* @return bool true if the brightness was set successfully, false otherwise
|
||||
*/
|
||||
bool setBrightness(uint8_t value);
|
||||
|
||||
void dump(int fd) const override;
|
||||
|
||||
private:
|
||||
std::string mName;
|
||||
std::string mBasePath;
|
||||
uint32_t mMaxBrightness;
|
||||
};
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
@@ -1,220 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "Devices.h"
|
||||
|
||||
#define LOG_TAG "Devices"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace light {
|
||||
|
||||
static const std::string kBacklightDevices[] = {
|
||||
"backlight",
|
||||
"panel0-backlight",
|
||||
};
|
||||
|
||||
static std::vector<BacklightDevice> getBacklightDevices() {
|
||||
std::vector<BacklightDevice> devices;
|
||||
|
||||
for (const auto& device : kBacklightDevices) {
|
||||
BacklightDevice backlight(device);
|
||||
if (backlight.exists()) {
|
||||
LOG(INFO) << "Found backlight device: " << backlight.getName();
|
||||
devices.push_back(backlight);
|
||||
}
|
||||
}
|
||||
|
||||
return devices;
|
||||
}
|
||||
|
||||
static const std::string kLedBacklightDevices[] = {
|
||||
"lcd-backlight",
|
||||
};
|
||||
|
||||
static std::vector<LedDevice> getBacklightLedDevices() {
|
||||
std::vector<LedDevice> devices;
|
||||
|
||||
for (const auto& device : kLedBacklightDevices) {
|
||||
LedDevice backlight(device);
|
||||
if (backlight.exists()) {
|
||||
LOG(INFO) << "Found backlight LED device: " << backlight.getName();
|
||||
devices.push_back(backlight);
|
||||
}
|
||||
}
|
||||
|
||||
return devices;
|
||||
}
|
||||
|
||||
static const std::string kButtonLedDevices[] = {
|
||||
"button-backlight",
|
||||
"button-backlight1",
|
||||
"button-backlight2",
|
||||
};
|
||||
|
||||
static std::vector<LedDevice> getButtonLedDevices() {
|
||||
std::vector<LedDevice> devices;
|
||||
|
||||
for (const auto& device : kButtonLedDevices) {
|
||||
LedDevice button(device);
|
||||
if (button.exists()) {
|
||||
LOG(INFO) << "Found button LED device: " << button.getName();
|
||||
devices.emplace_back(button);
|
||||
}
|
||||
}
|
||||
|
||||
return devices;
|
||||
}
|
||||
|
||||
static const std::string kRgbLedDevices[][4] = {
|
||||
{"red", "green", "blue", "/sys/class/leds/rgb/rgb_blink"},
|
||||
};
|
||||
|
||||
static std::vector<RgbLedDevice> getNotificationRgbLedDevices() {
|
||||
std::vector<RgbLedDevice> devices;
|
||||
|
||||
for (const auto& device : kRgbLedDevices) {
|
||||
LedDevice red(device[0]);
|
||||
LedDevice green(device[1]);
|
||||
LedDevice blue(device[2]);
|
||||
|
||||
RgbLedDevice rgbLedDevice(red, green, blue, device[3]);
|
||||
if (rgbLedDevice.exists()) {
|
||||
LOG(INFO) << "Found notification RGB LED device: " << red.getName() << ", "
|
||||
<< green.getName() << ", " << blue.getName();
|
||||
devices.emplace_back(red, green, blue, device[3]);
|
||||
}
|
||||
}
|
||||
|
||||
return devices;
|
||||
}
|
||||
|
||||
static const std::string kNotificationLedDevices[] = {
|
||||
"left",
|
||||
"white",
|
||||
};
|
||||
|
||||
static std::vector<LedDevice> getNotificationLedDevices() {
|
||||
std::vector<LedDevice> devices;
|
||||
|
||||
for (const auto& device : kNotificationLedDevices) {
|
||||
LedDevice notification(device);
|
||||
if (notification.exists()) {
|
||||
LOG(INFO) << "Found notification LED device: " << notification.getName();
|
||||
devices.emplace_back(notification);
|
||||
}
|
||||
}
|
||||
|
||||
return devices;
|
||||
}
|
||||
|
||||
Devices::Devices()
|
||||
: mBacklightDevices(getBacklightDevices()),
|
||||
mBacklightLedDevices(getBacklightLedDevices()),
|
||||
mButtonLedDevices(getButtonLedDevices()),
|
||||
mNotificationRgbLedDevices(getNotificationRgbLedDevices()),
|
||||
mNotificationLedDevices(getNotificationLedDevices()) {
|
||||
if (!hasBacklightDevices()) {
|
||||
LOG(INFO) << "No backlight devices found";
|
||||
}
|
||||
|
||||
if (!hasButtonDevices()) {
|
||||
LOG(INFO) << "No button devices found";
|
||||
}
|
||||
|
||||
if (!hasNotificationDevices()) {
|
||||
LOG(INFO) << "No notification devices found";
|
||||
}
|
||||
}
|
||||
|
||||
bool Devices::hasBacklightDevices() const {
|
||||
return !mBacklightDevices.empty() || !mBacklightLedDevices.empty();
|
||||
}
|
||||
|
||||
bool Devices::hasButtonDevices() const {
|
||||
return !mButtonLedDevices.empty();
|
||||
}
|
||||
|
||||
bool Devices::hasNotificationDevices() const {
|
||||
return !mNotificationRgbLedDevices.empty() || !mNotificationLedDevices.empty();
|
||||
}
|
||||
|
||||
void Devices::setBacklightColor(rgb color) {
|
||||
for (auto& device : mBacklightDevices) {
|
||||
device.setBrightness(color.toBrightness());
|
||||
}
|
||||
for (auto& device : mBacklightLedDevices) {
|
||||
device.setBrightness(color.toBrightness());
|
||||
}
|
||||
}
|
||||
|
||||
void Devices::setButtonsColor(rgb color) {
|
||||
for (auto& device : mButtonLedDevices) {
|
||||
device.setBrightness(color.toBrightness());
|
||||
}
|
||||
}
|
||||
|
||||
void Devices::setNotificationColor(rgb color, LightMode mode, uint32_t flashOnMs,
|
||||
uint32_t flashOffMs) {
|
||||
for (auto& device : mNotificationRgbLedDevices) {
|
||||
device.setBrightness(color, mode, flashOnMs, flashOffMs);
|
||||
}
|
||||
|
||||
for (auto& device : mNotificationLedDevices) {
|
||||
device.setBrightness(color.toBrightness(), mode, flashOnMs, flashOffMs);
|
||||
}
|
||||
}
|
||||
|
||||
void Devices::dump(int fd) const {
|
||||
dprintf(fd, "Backlight devices:\n");
|
||||
for (const auto& device : mBacklightDevices) {
|
||||
dprintf(fd, "- ");
|
||||
device.dump(fd);
|
||||
dprintf(fd, "\n");
|
||||
}
|
||||
dprintf(fd, "\n");
|
||||
|
||||
dprintf(fd, "Backlight LED devices:\n");
|
||||
for (const auto& device : mBacklightLedDevices) {
|
||||
dprintf(fd, "- ");
|
||||
device.dump(fd);
|
||||
dprintf(fd, "\n");
|
||||
}
|
||||
dprintf(fd, "\n");
|
||||
|
||||
dprintf(fd, "Button LED devices:\n");
|
||||
for (const auto& device : mButtonLedDevices) {
|
||||
dprintf(fd, "- ");
|
||||
device.dump(fd);
|
||||
dprintf(fd, "\n");
|
||||
}
|
||||
dprintf(fd, "\n");
|
||||
|
||||
dprintf(fd, "Notification RGB LED devices:\n");
|
||||
for (const auto& device : mNotificationRgbLedDevices) {
|
||||
dprintf(fd, "- ");
|
||||
device.dump(fd);
|
||||
dprintf(fd, "\n");
|
||||
}
|
||||
dprintf(fd, "\n");
|
||||
|
||||
dprintf(fd, "Notification LED devices:\n");
|
||||
for (const auto& device : mNotificationLedDevices) {
|
||||
dprintf(fd, "- ");
|
||||
device.dump(fd);
|
||||
dprintf(fd, "\n");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "BacklightDevice.h"
|
||||
#include "IDumpable.h"
|
||||
#include "LedDevice.h"
|
||||
#include "RgbLedDevice.h"
|
||||
#include "Utils.h"
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace light {
|
||||
|
||||
class Devices : public IDumpable {
|
||||
public:
|
||||
Devices();
|
||||
|
||||
bool hasBacklightDevices() const;
|
||||
bool hasButtonDevices() const;
|
||||
bool hasNotificationDevices() const;
|
||||
|
||||
void setBacklightColor(rgb color);
|
||||
void setButtonsColor(rgb color);
|
||||
void setNotificationColor(rgb color, LightMode mode = LightMode::STATIC, uint32_t flashOnMs = 0,
|
||||
uint32_t flashOffMs = 0);
|
||||
|
||||
void dump(int fd) const override;
|
||||
|
||||
private:
|
||||
// Backlight
|
||||
std::vector<BacklightDevice> mBacklightDevices;
|
||||
std::vector<LedDevice> mBacklightLedDevices;
|
||||
|
||||
// Buttons
|
||||
std::vector<LedDevice> mButtonLedDevices;
|
||||
|
||||
// Notifications
|
||||
std::vector<RgbLedDevice> mNotificationRgbLedDevices;
|
||||
std::vector<LedDevice> mNotificationLedDevices;
|
||||
};
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace light {
|
||||
|
||||
/**
|
||||
* Interface for dumpable objects using AIDL dump()'s file descriptor.
|
||||
*/
|
||||
class IDumpable {
|
||||
public:
|
||||
virtual ~IDumpable() = default;
|
||||
|
||||
/**
|
||||
* Write information regarding this object to the given file descriptor using dprintf().
|
||||
* You should avoid ending newline, since the caller will add it.
|
||||
* @param fd The file descriptor to write to.
|
||||
*/
|
||||
virtual void dump(int fd) const = 0;
|
||||
};
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
@@ -1,158 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2024 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "LedDevice.h"
|
||||
|
||||
#define LOG_TAG "LedDevice"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <fstream>
|
||||
#include "Utils.h"
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace light {
|
||||
|
||||
static const uint32_t kDefaultMaxBrightness = 255;
|
||||
|
||||
static const std::string kBaseLedsPath = "/sys/class/leds/";
|
||||
|
||||
static const std::string kBrightnessNode = "brightness";
|
||||
static const std::string kMaxBrightnessNode = "max_brightness";
|
||||
|
||||
static const std::string kBreathNodes[] = {
|
||||
"breath",
|
||||
"blink",
|
||||
};
|
||||
|
||||
static const std::string kBlinkNode = "blink";
|
||||
static const std::string kStartIdxNode = "start_idx";
|
||||
static const std::string kDutyPctsNode = "duty_pcts";
|
||||
static const std::string kPauseLoNode = "pause_lo";
|
||||
static const std::string kPauseHiNode = "pause_hi";
|
||||
static const std::string kRampStepMsNode = "ramp_step_ms";
|
||||
|
||||
static constexpr int kRampSteps = 8;
|
||||
static constexpr int kRampMaxStepDurationMs = 50;
|
||||
|
||||
LedDevice::LedDevice(std::string name)
|
||||
: mName(name), mIdx(0), mBasePath(kBaseLedsPath + name + "/") {
|
||||
if (!readFromFile(mBasePath + kMaxBrightnessNode, mMaxBrightness)) {
|
||||
mMaxBrightness = kDefaultMaxBrightness;
|
||||
}
|
||||
|
||||
for (const auto& node : kBreathNodes) {
|
||||
if (std::ifstream(mBasePath + node).good()) {
|
||||
mBreathNode = node;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mSupportsTimed = std::ifstream(mBasePath + kBlinkNode).good() &&
|
||||
std::ifstream(mBasePath + kStartIdxNode).good() &&
|
||||
std::ifstream(mBasePath + kDutyPctsNode).good() &&
|
||||
std::ifstream(mBasePath + kPauseLoNode).good() &&
|
||||
std::ifstream(mBasePath + kPauseHiNode).good() &&
|
||||
std::ifstream(mBasePath + kRampStepMsNode).good();
|
||||
}
|
||||
|
||||
std::string LedDevice::getName() const {
|
||||
return mName;
|
||||
}
|
||||
|
||||
bool LedDevice::supportsBreath() const {
|
||||
return !mBreathNode.empty();
|
||||
}
|
||||
|
||||
bool LedDevice::supportsTimed() const {
|
||||
return mSupportsTimed;
|
||||
}
|
||||
|
||||
bool LedDevice::exists() const {
|
||||
return std::ifstream(mBasePath + kBrightnessNode).good();
|
||||
}
|
||||
|
||||
static std::string getScaledDutyPercent(uint8_t brightness) {
|
||||
std::string output;
|
||||
for (int i = 0; i < kRampSteps; i++) {
|
||||
if (i != 0) {
|
||||
output += ",";
|
||||
}
|
||||
output += std::to_string(i * 100 * brightness / (0xFF * kRampSteps));
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
bool LedDevice::setBrightness(uint8_t value, LightMode mode, uint32_t flashOnMs,
|
||||
uint32_t flashOffMs) {
|
||||
// Disable current blinking
|
||||
if (mSupportsTimed) {
|
||||
writeToFile(mBasePath + kBlinkNode, 0);
|
||||
}
|
||||
if (supportsBreath()) {
|
||||
writeToFile(mBasePath + mBreathNode, 0);
|
||||
}
|
||||
|
||||
switch (mode) {
|
||||
case LightMode::TIMED:
|
||||
if (mSupportsTimed) {
|
||||
int32_t stepDuration = kRampMaxStepDurationMs;
|
||||
int32_t pauseLo = flashOffMs;
|
||||
int32_t pauseHi = flashOnMs - (stepDuration * kRampSteps * 2);
|
||||
|
||||
if (pauseHi < 0) {
|
||||
stepDuration = flashOnMs / (kRampSteps * 2);
|
||||
pauseHi = 0;
|
||||
}
|
||||
|
||||
return writeToFile(mBasePath + kStartIdxNode, mIdx * kRampSteps) &&
|
||||
writeToFile(mBasePath + kDutyPctsNode, getScaledDutyPercent(value)) &&
|
||||
writeToFile(mBasePath + kPauseLoNode, pauseLo) &&
|
||||
writeToFile(mBasePath + kPauseHiNode, pauseHi) &&
|
||||
writeToFile(mBasePath + kRampStepMsNode, stepDuration) &&
|
||||
writeToFile(mBasePath + kBlinkNode, 1);
|
||||
}
|
||||
|
||||
// Fallthrough to breath mode if timed is not supported
|
||||
FALLTHROUGH_INTENDED;
|
||||
case LightMode::BREATH:
|
||||
if (supportsBreath()) {
|
||||
return writeToFile(mBasePath + mBreathNode, value > 0 ? 1 : 0);
|
||||
break;
|
||||
}
|
||||
|
||||
// Fallthrough to static mode if breath is not supported
|
||||
FALLTHROUGH_INTENDED;
|
||||
case LightMode::STATIC:
|
||||
return writeToFile(mBasePath + kBrightnessNode, scaleBrightness(value, mMaxBrightness));
|
||||
break;
|
||||
default:
|
||||
LOG(ERROR) << "Unknown mode: " << mode;
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void LedDevice::setIdx(int idx) {
|
||||
mIdx = idx;
|
||||
}
|
||||
|
||||
void LedDevice::dump(int fd) const {
|
||||
dprintf(fd, "Name: %s", mName.c_str());
|
||||
dprintf(fd, ", index: %d", mIdx);
|
||||
dprintf(fd, ", exists: %d", exists());
|
||||
dprintf(fd, ", base path: %s", mBasePath.c_str());
|
||||
dprintf(fd, ", max brightness: %u", mMaxBrightness);
|
||||
dprintf(fd, ", supports breath: %d", supportsBreath());
|
||||
dprintf(fd, ", supports timed: %d", supportsTimed());
|
||||
dprintf(fd, ", breath node: %s", mBreathNode.c_str());
|
||||
}
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2024 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include "IDumpable.h"
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace light {
|
||||
|
||||
enum LightMode {
|
||||
STATIC,
|
||||
BREATH,
|
||||
TIMED,
|
||||
};
|
||||
|
||||
/**
|
||||
* A Linux LED device.
|
||||
* @see https://docs.kernel.org/leds/leds-class.html
|
||||
*/
|
||||
class LedDevice : public IDumpable {
|
||||
public:
|
||||
LedDevice() = delete;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param name The name of the LED device
|
||||
*/
|
||||
LedDevice(std::string name);
|
||||
|
||||
/**
|
||||
* Get the name of the LED device.
|
||||
*
|
||||
* @return std::string The name of the LED device
|
||||
*/
|
||||
std::string getName() const;
|
||||
|
||||
/**
|
||||
* Return whether this LED device exists.
|
||||
*
|
||||
* @return bool true if the LED device exists, false otherwise
|
||||
*/
|
||||
bool exists() const;
|
||||
|
||||
/**
|
||||
* Return whether this LED device supports breathing.
|
||||
* When it doesn't, calling setBrightness with LightMode::BREATH will behave like
|
||||
* LightMode::STATIC.
|
||||
*
|
||||
* @return bool true if the LED device supports breathing, false otherwise
|
||||
*/
|
||||
bool supportsBreath() const;
|
||||
|
||||
/**
|
||||
* Return whether this LED device supports timed mode.
|
||||
* When it doesn't, calling setBrightness with LightMode::TIMED will behave like
|
||||
* LightMode::BREATH.
|
||||
*
|
||||
* @return bool true if the LED device supports timed mode, false otherwise
|
||||
*/
|
||||
bool supportsTimed() const;
|
||||
|
||||
/**
|
||||
* Set the brightness of the LED device.
|
||||
*
|
||||
* @param value The brightness value to set
|
||||
* @param mode The light mode to use
|
||||
* @return bool true if the brightness was set successfully, false otherwise
|
||||
*/
|
||||
bool setBrightness(uint8_t value, LightMode mode = LightMode::STATIC, uint32_t flashOnMs = 0,
|
||||
uint32_t flashOffMs = 0);
|
||||
|
||||
/**
|
||||
* Set the index of the LED device.
|
||||
*
|
||||
* @param idx The index to set
|
||||
*/
|
||||
void setIdx(int idx);
|
||||
|
||||
void dump(int fd) const override;
|
||||
|
||||
private:
|
||||
std::string mName;
|
||||
int mIdx;
|
||||
std::string mBasePath;
|
||||
uint32_t mMaxBrightness;
|
||||
std::string mBreathNode;
|
||||
bool mSupportsTimed;
|
||||
};
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
@@ -1,133 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2024 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "Lights.h"
|
||||
|
||||
#define LOG_TAG "Lights"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include "Utils.h"
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace light {
|
||||
|
||||
#define AutoHwLight(light) \
|
||||
{ .id = static_cast<int32_t>(light), .ordinal = 0, .type = light }
|
||||
|
||||
Lights::Lights() {
|
||||
if (mDevices.hasBacklightDevices()) {
|
||||
mLights.push_back(AutoHwLight(LightType::BACKLIGHT));
|
||||
}
|
||||
|
||||
if (mDevices.hasButtonDevices()) {
|
||||
mLights.push_back(AutoHwLight(LightType::BUTTONS));
|
||||
}
|
||||
|
||||
if (mDevices.hasNotificationDevices()) {
|
||||
mLights.push_back(AutoHwLight(LightType::BATTERY));
|
||||
mLights.push_back(AutoHwLight(LightType::NOTIFICATIONS));
|
||||
mLights.push_back(AutoHwLight(LightType::ATTENTION));
|
||||
}
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Lights::setLightState(int32_t id, const HwLightState& state) {
|
||||
rgb color(state.color);
|
||||
|
||||
LightType type = static_cast<LightType>(id);
|
||||
switch (type) {
|
||||
case LightType::BACKLIGHT:
|
||||
mDevices.setBacklightColor(color);
|
||||
break;
|
||||
case LightType::BUTTONS:
|
||||
mDevices.setButtonsColor(color);
|
||||
break;
|
||||
case LightType::BATTERY:
|
||||
mLastBatteryState = state;
|
||||
updateNotificationColor();
|
||||
break;
|
||||
case LightType::NOTIFICATIONS:
|
||||
mLastNotificationsState = state;
|
||||
updateNotificationColor();
|
||||
break;
|
||||
case LightType::ATTENTION:
|
||||
mLastAttentionState = state;
|
||||
updateNotificationColor();
|
||||
break;
|
||||
default:
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
break;
|
||||
}
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Lights::getLights(std::vector<HwLight>* _aidl_return) {
|
||||
for (const auto& light : mLights) {
|
||||
_aidl_return->push_back(light);
|
||||
}
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
binder_status_t Lights::dump(int fd, const char** /*args*/, uint32_t /*numArgs*/) {
|
||||
dprintf(fd, "Lights AIDL:\n");
|
||||
dprintf(fd, "\n");
|
||||
|
||||
dprintf(fd, "Lights:\n");
|
||||
for (const auto& light : mLights) {
|
||||
dprintf(fd, "- %d: LightType::%s\n", light.id, toString(light.type).c_str());
|
||||
}
|
||||
dprintf(fd, "\n");
|
||||
|
||||
dprintf(fd, "Devices:\n");
|
||||
mDevices.dump(fd);
|
||||
dprintf(fd, "\n");
|
||||
|
||||
return STATUS_OK;
|
||||
}
|
||||
|
||||
void Lights::updateNotificationColor() {
|
||||
std::lock_guard<std::mutex> lock(mLedMutex);
|
||||
|
||||
bool isBatteryLit = rgb(mLastBatteryState.color).isLit();
|
||||
bool isAttentionLit = rgb(mLastAttentionState.color).isLit();
|
||||
bool isNotificationsLit = rgb(mLastNotificationsState.color).isLit();
|
||||
|
||||
const HwLightState state = isNotificationsLit ? mLastNotificationsState
|
||||
: isAttentionLit ? mLastAttentionState
|
||||
: isBatteryLit ? mLastBatteryState
|
||||
: HwLightState();
|
||||
|
||||
rgb color(state.color);
|
||||
|
||||
LightMode lightMode;
|
||||
switch (state.flashMode) {
|
||||
case FlashMode::NONE:
|
||||
lightMode = LightMode::STATIC;
|
||||
break;
|
||||
case FlashMode::TIMED:
|
||||
lightMode = LightMode::TIMED;
|
||||
break;
|
||||
case FlashMode::HARDWARE:
|
||||
lightMode = LightMode::BREATH;
|
||||
break;
|
||||
default:
|
||||
LOG(ERROR) << "Unknown flash mode: " << static_cast<int>(state.flashMode);
|
||||
lightMode = LightMode::STATIC;
|
||||
break;
|
||||
}
|
||||
|
||||
mDevices.setNotificationColor(color, lightMode, state.flashOnMs, state.flashOffMs);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2024 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <aidl/android/hardware/light/BnLights.h>
|
||||
#include <mutex>
|
||||
#include "Devices.h"
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace light {
|
||||
|
||||
class Lights : public BnLights {
|
||||
public:
|
||||
Lights();
|
||||
|
||||
ndk::ScopedAStatus setLightState(int32_t id, const HwLightState& state) override;
|
||||
ndk::ScopedAStatus getLights(std::vector<HwLight>* _aidl_return) override;
|
||||
|
||||
binder_status_t dump(int fd, const char** args, uint32_t numArgs) override;
|
||||
|
||||
private:
|
||||
std::vector<HwLight> mLights;
|
||||
|
||||
Devices mDevices;
|
||||
|
||||
HwLightState mLastBatteryState;
|
||||
HwLightState mLastNotificationsState;
|
||||
HwLightState mLastAttentionState;
|
||||
std::mutex mLedMutex;
|
||||
|
||||
void updateNotificationColor();
|
||||
};
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
@@ -1,146 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "RgbLedDevice.h"
|
||||
|
||||
#define LOG_TAG "RgbLedDevice"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include "Utils.h"
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace light {
|
||||
|
||||
RgbLedDevice::RgbLedDevice(LedDevice red, LedDevice green, LedDevice blue, std::string rgbSyncNode)
|
||||
: mRed(red), mGreen(green), mBlue(blue), mRgbSyncNode(rgbSyncNode), mColors(Color::NONE) {
|
||||
if (mRed.exists()) {
|
||||
mColors |= Color::RED;
|
||||
}
|
||||
if (mGreen.exists()) {
|
||||
mColors |= Color::GREEN;
|
||||
}
|
||||
if (mBlue.exists()) {
|
||||
mColors |= Color::BLUE;
|
||||
}
|
||||
if (supportsRgbSync()) {
|
||||
mRed.setIdx(0);
|
||||
mGreen.setIdx(1);
|
||||
mBlue.setIdx(2);
|
||||
}
|
||||
}
|
||||
|
||||
bool RgbLedDevice::exists() const {
|
||||
return mColors != Color::NONE;
|
||||
}
|
||||
|
||||
bool RgbLedDevice::supportsBreath() const {
|
||||
return (!mRed.exists() || mRed.supportsBreath()) &&
|
||||
(!mGreen.exists() || mGreen.supportsBreath()) &&
|
||||
(!mBlue.exists() || mBlue.supportsBreath());
|
||||
}
|
||||
|
||||
bool RgbLedDevice::supportsTimed() const {
|
||||
return (!mRed.exists() || mRed.supportsTimed()) &&
|
||||
(!mGreen.exists() || mGreen.supportsTimed()) &&
|
||||
(!mBlue.exists() || mBlue.supportsTimed());
|
||||
}
|
||||
|
||||
bool RgbLedDevice::supportsRgbSync() const {
|
||||
return std::ifstream(mRgbSyncNode).good();
|
||||
}
|
||||
|
||||
bool RgbLedDevice::setBrightness(rgb color, LightMode mode, uint32_t flashOnMs,
|
||||
uint32_t flashOffMs) {
|
||||
bool rc = true;
|
||||
|
||||
if (mColors == Color::NONE) {
|
||||
LOG(ERROR) << "No LEDs found";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mode == LightMode::TIMED && !supportsTimed()) {
|
||||
// Not all LEDs support timed mode, force breathing mode
|
||||
mode = LightMode::BREATH;
|
||||
}
|
||||
|
||||
if (mode == LightMode::BREATH && !supportsBreath()) {
|
||||
// Not all LEDs support breathing, force static mode
|
||||
mode = LightMode::STATIC;
|
||||
}
|
||||
|
||||
if (mode == LightMode::TIMED && supportsRgbSync()) {
|
||||
rc &= writeToFile(mRgbSyncNode, 0);
|
||||
}
|
||||
|
||||
if (mColors == Color::ALL) {
|
||||
rc &= mRed.setBrightness(color.red, mode, flashOnMs, flashOffMs);
|
||||
rc &= mGreen.setBrightness(color.green, mode, flashOnMs, flashOffMs);
|
||||
rc &= mBlue.setBrightness(color.blue, mode, flashOnMs, flashOffMs);
|
||||
} else {
|
||||
// Check if we have only one LED
|
||||
if (mColors == Color::RED) {
|
||||
rc &= mRed.setBrightness(color.toBrightness(), mode, flashOnMs, flashOffMs);
|
||||
} else if (mColors == Color::GREEN) {
|
||||
rc &= mGreen.setBrightness(color.toBrightness(), mode, flashOnMs, flashOffMs);
|
||||
} else if (mColors == Color::BLUE) {
|
||||
rc &= mBlue.setBrightness(color.toBrightness(), mode, flashOnMs, flashOffMs);
|
||||
} else {
|
||||
// We only have two LEDs, blend the missing color in the other two
|
||||
if ((mColors & Color::RED) == Color::NONE) {
|
||||
rc &= mBlue.setBrightness((color.blue + color.red) / 2, mode, flashOnMs,
|
||||
flashOffMs);
|
||||
rc &= mGreen.setBrightness((color.green + color.red) / 2, mode, flashOnMs,
|
||||
flashOffMs);
|
||||
} else if ((mColors & Color::GREEN) == Color::NONE) {
|
||||
rc &= mRed.setBrightness((color.red + color.green) / 2, mode, flashOnMs,
|
||||
flashOffMs);
|
||||
rc &= mBlue.setBrightness((color.blue + color.green) / 2, mode, flashOnMs,
|
||||
flashOffMs);
|
||||
} else if ((mColors & Color::BLUE) == Color::NONE) {
|
||||
rc &= mRed.setBrightness((color.red + color.blue) / 2, mode, flashOnMs, flashOffMs);
|
||||
rc &= mGreen.setBrightness((color.green + color.blue) / 2, mode, flashOnMs,
|
||||
flashOffMs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mode == LightMode::TIMED && supportsRgbSync()) {
|
||||
rc &= writeToFile(mRgbSyncNode, 1);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void RgbLedDevice::dump(int fd) const {
|
||||
dprintf(fd, "Exists: %d", exists());
|
||||
dprintf(fd, ", supports breath: %d", supportsBreath());
|
||||
dprintf(fd, ", supports timed: %d", supportsTimed());
|
||||
dprintf(fd, ", supports RGB sync: %d", supportsRgbSync());
|
||||
dprintf(fd, ", colors:");
|
||||
if (mColors != Color::NONE) {
|
||||
if (mColors & Color::RED) {
|
||||
dprintf(fd, "\nRed: ");
|
||||
mRed.dump(fd);
|
||||
}
|
||||
if (mColors & Color::GREEN) {
|
||||
dprintf(fd, "\nGreen: ");
|
||||
mGreen.dump(fd);
|
||||
}
|
||||
if (mColors & Color::BLUE) {
|
||||
dprintf(fd, "\nBlue: ");
|
||||
mBlue.dump(fd);
|
||||
}
|
||||
} else {
|
||||
dprintf(fd, " None");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "IDumpable.h"
|
||||
#include "LedDevice.h"
|
||||
#include "Utils.h"
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace light {
|
||||
|
||||
/**
|
||||
* A pool of LED devices that will be toggled based on the wanted color.
|
||||
* Support all types of LED combinations, with a maximum of 3 LEDs.
|
||||
* Also supports 2 color LEDs (*cough* ASUS *cough*).
|
||||
*/
|
||||
class RgbLedDevice : public IDumpable {
|
||||
public:
|
||||
RgbLedDevice() = delete;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param red The red LED device
|
||||
* @param green The green LED device
|
||||
* @param blue The blue LED device
|
||||
* @param rgbSyncNode The path to RGB sync trigger
|
||||
*/
|
||||
RgbLedDevice(LedDevice red, LedDevice green, LedDevice blue, std::string rgbSyncNode);
|
||||
|
||||
/**
|
||||
* Return whether this RGB LED device exists.
|
||||
* This is true when at least one of the LEDs exists.
|
||||
*
|
||||
* @return bool true if the RGB LED device exists, false otherwise
|
||||
*/
|
||||
bool exists() const;
|
||||
|
||||
/**
|
||||
* Return whether this RGB LED device supports breathing.
|
||||
* This is true when all existing LEDs support breathing.
|
||||
* In case this is false, calling setBrightness with LightMode::BREATH will behave like
|
||||
* LightMode::STATIC.
|
||||
*
|
||||
* @return bool true if the RGB LED device supports breathing, false otherwise
|
||||
*/
|
||||
bool supportsBreath() const;
|
||||
|
||||
/**
|
||||
* Return whether this RGB LED device supports timed mode.
|
||||
* This is true when all existing LEDs support timed mode.
|
||||
* In case this is false, calling setBrightness with LightMode::TIMED will behave like
|
||||
* LightMode::BREATH.
|
||||
*
|
||||
* @return bool true if the RGB LED device supports timed mode, false otherwise
|
||||
*/
|
||||
bool supportsTimed() const;
|
||||
|
||||
/**
|
||||
* Return whether this RGB LED device supports RGB sync.
|
||||
*
|
||||
* @return bool true if the RGB LED device supports RGB sync, false otherwise
|
||||
*/
|
||||
bool supportsRgbSync() const;
|
||||
|
||||
/**
|
||||
* Set the brightness of this RGB LED device.
|
||||
*
|
||||
* @param color The color to set
|
||||
* @param mode The mode to set
|
||||
* @return bool true if the brightness was set successfully, false otherwise
|
||||
*/
|
||||
bool setBrightness(rgb color, LightMode mode = LightMode::STATIC, uint32_t flashOnMs = 0,
|
||||
uint32_t flashOffMs = 0);
|
||||
|
||||
void dump(int fd) const override;
|
||||
|
||||
enum Color {
|
||||
NONE = 0,
|
||||
RED = 1 << 0,
|
||||
GREEN = 1 << 1,
|
||||
BLUE = 1 << 2,
|
||||
ALL = RED | GREEN | BLUE,
|
||||
};
|
||||
|
||||
private:
|
||||
LedDevice mRed;
|
||||
LedDevice mGreen;
|
||||
LedDevice mBlue;
|
||||
std::string mRgbSyncNode;
|
||||
|
||||
int mColors;
|
||||
};
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2024 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "Utils.h"
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace light {
|
||||
|
||||
rgb::rgb() : red(0), green(0), blue(0) {}
|
||||
|
||||
rgb::rgb(uint8_t r, uint8_t g, uint8_t b) : red(r), green(g), blue(b){};
|
||||
|
||||
rgb::rgb(uint32_t color) {
|
||||
// Extract brightness from AARRGGBB.
|
||||
uint8_t alpha = (color >> 24) & 0xFF;
|
||||
|
||||
// Retrieve each of the RGB colors
|
||||
red = (color >> 16) & 0xFF;
|
||||
green = (color >> 8) & 0xFF;
|
||||
blue = color & 0xFF;
|
||||
|
||||
// Scale RGB colors if a brightness has been applied by the user
|
||||
if (alpha > 0 && alpha < 0xFF) {
|
||||
red = red * alpha / 0xFF;
|
||||
green = green * alpha / 0xFF;
|
||||
blue = blue * alpha / 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
bool rgb::isLit() {
|
||||
return !!red || !!green || !!blue;
|
||||
}
|
||||
|
||||
static constexpr uint8_t kRedWeight = 77;
|
||||
static constexpr uint8_t kGreenWeight = 150;
|
||||
static constexpr uint8_t kBlueWeight = 29;
|
||||
|
||||
uint8_t rgb::toBrightness() {
|
||||
return (kRedWeight * red + kGreenWeight * green + kBlueWeight * blue) >> 8;
|
||||
}
|
||||
|
||||
uint32_t scaleBrightness(uint8_t brightness, uint32_t maxBrightness) {
|
||||
return brightness * maxBrightness / 0xFF;
|
||||
}
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2024 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace light {
|
||||
|
||||
struct rgb {
|
||||
rgb();
|
||||
rgb(uint8_t r, uint8_t g, uint8_t b);
|
||||
rgb(uint32_t color);
|
||||
|
||||
uint8_t red;
|
||||
uint8_t green;
|
||||
uint8_t blue;
|
||||
|
||||
bool isLit();
|
||||
uint8_t toBrightness();
|
||||
};
|
||||
|
||||
uint32_t scaleBrightness(uint8_t brightness, uint32_t maxBrightness);
|
||||
|
||||
template <typename T>
|
||||
bool readFromFile(const std::string& file, T& content) {
|
||||
std::ifstream fileStream(file);
|
||||
|
||||
if (!fileStream) {
|
||||
return false;
|
||||
}
|
||||
|
||||
fileStream >> content;
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool writeToFile(const std::string& file, const T content) {
|
||||
std::ofstream fileStream(file);
|
||||
|
||||
if (!fileStream) {
|
||||
return false;
|
||||
}
|
||||
|
||||
fileStream << content;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
@@ -1,106 +0,0 @@
|
||||
on early-boot
|
||||
# Backlight devices
|
||||
chown system system /sys/class/backlight/backlight/brightness
|
||||
chown system system /sys/class/backlight/backlight/max_brightness
|
||||
|
||||
chown system system /sys/class/backlight/panel0-backlight/brightness
|
||||
chown system system /sys/class/backlight/panel0-backlight/max_brightness
|
||||
|
||||
# LED devices
|
||||
chown system system /sys/class/leds/blue/blink
|
||||
chown system system /sys/class/leds/blue/breath
|
||||
chown system system /sys/class/leds/blue/brightness
|
||||
chown system system /sys/class/leds/blue/duty_pcts
|
||||
chown system system /sys/class/leds/blue/max_brightness
|
||||
chown system system /sys/class/leds/blue/pause_hi
|
||||
chown system system /sys/class/leds/blue/pause_lo
|
||||
chown system system /sys/class/leds/blue/ramp_step_ms
|
||||
chown system system /sys/class/leds/blue/start_idx
|
||||
|
||||
chown system system /sys/class/leds/button-backlight/blink
|
||||
chown system system /sys/class/leds/button-backlight/breath
|
||||
chown system system /sys/class/leds/button-backlight/brightness
|
||||
chown system system /sys/class/leds/button-backlight/duty_pcts
|
||||
chown system system /sys/class/leds/button-backlight/max_brightness
|
||||
chown system system /sys/class/leds/button-backlight/pause_hi
|
||||
chown system system /sys/class/leds/button-backlight/pause_lo
|
||||
chown system system /sys/class/leds/button-backlight/ramp_step_ms
|
||||
chown system system /sys/class/leds/button-backlight/start_idx
|
||||
|
||||
chown system system /sys/class/leds/button-backlight1/blink
|
||||
chown system system /sys/class/leds/button-backlight1/breath
|
||||
chown system system /sys/class/leds/button-backlight1/brightness
|
||||
chown system system /sys/class/leds/button-backlight1/duty_pcts
|
||||
chown system system /sys/class/leds/button-backlight1/max_brightness
|
||||
chown system system /sys/class/leds/button-backlight1/pause_hi
|
||||
chown system system /sys/class/leds/button-backlight1/pause_lo
|
||||
chown system system /sys/class/leds/button-backlight1/ramp_step_ms
|
||||
chown system system /sys/class/leds/button-backlight1/start_idx
|
||||
|
||||
chown system system /sys/class/leds/button-backlight2/blink
|
||||
chown system system /sys/class/leds/button-backlight2/breath
|
||||
chown system system /sys/class/leds/button-backlight2/brightness
|
||||
chown system system /sys/class/leds/button-backlight2/duty_pcts
|
||||
chown system system /sys/class/leds/button-backlight2/max_brightness
|
||||
chown system system /sys/class/leds/button-backlight2/pause_hi
|
||||
chown system system /sys/class/leds/button-backlight2/pause_lo
|
||||
chown system system /sys/class/leds/button-backlight2/ramp_step_ms
|
||||
chown system system /sys/class/leds/button-backlight2/start_idx
|
||||
|
||||
chown system system /sys/class/leds/green/blink
|
||||
chown system system /sys/class/leds/green/breath
|
||||
chown system system /sys/class/leds/green/brightness
|
||||
chown system system /sys/class/leds/green/duty_pcts
|
||||
chown system system /sys/class/leds/green/max_brightness
|
||||
chown system system /sys/class/leds/green/pause_hi
|
||||
chown system system /sys/class/leds/green/pause_lo
|
||||
chown system system /sys/class/leds/green/ramp_step_ms
|
||||
chown system system /sys/class/leds/green/start_idx
|
||||
|
||||
chown system system /sys/class/leds/lcd-backlight/blink
|
||||
chown system system /sys/class/leds/lcd-backlight/breath
|
||||
chown system system /sys/class/leds/lcd-backlight/brightness
|
||||
chown system system /sys/class/leds/lcd-backlight/duty_pcts
|
||||
chown system system /sys/class/leds/lcd-backlight/max_brightness
|
||||
chown system system /sys/class/leds/lcd-backlight/pause_hi
|
||||
chown system system /sys/class/leds/lcd-backlight/pause_lo
|
||||
chown system system /sys/class/leds/lcd-backlight/ramp_step_ms
|
||||
chown system system /sys/class/leds/lcd-backlight/start_idx
|
||||
|
||||
chown system system /sys/class/leds/left/blink
|
||||
chown system system /sys/class/leds/left/breath
|
||||
chown system system /sys/class/leds/left/brightness
|
||||
chown system system /sys/class/leds/left/duty_pcts
|
||||
chown system system /sys/class/leds/left/max_brightness
|
||||
chown system system /sys/class/leds/left/pause_hi
|
||||
chown system system /sys/class/leds/left/pause_lo
|
||||
chown system system /sys/class/leds/left/ramp_step_ms
|
||||
chown system system /sys/class/leds/left/start_idx
|
||||
|
||||
chown system system /sys/class/leds/red/blink
|
||||
chown system system /sys/class/leds/red/breath
|
||||
chown system system /sys/class/leds/red/brightness
|
||||
chown system system /sys/class/leds/red/duty_pcts
|
||||
chown system system /sys/class/leds/red/max_brightness
|
||||
chown system system /sys/class/leds/red/pause_hi
|
||||
chown system system /sys/class/leds/red/pause_lo
|
||||
chown system system /sys/class/leds/red/ramp_step_ms
|
||||
chown system system /sys/class/leds/red/start_idx
|
||||
|
||||
chown system system /sys/class/leds/rgb/rgb_blink
|
||||
|
||||
chown system system /sys/class/leds/white/blink
|
||||
chown system system /sys/class/leds/white/breath
|
||||
chown system system /sys/class/leds/white/brightness
|
||||
chown system system /sys/class/leds/white/duty_pcts
|
||||
chown system system /sys/class/leds/white/max_brightness
|
||||
chown system system /sys/class/leds/white/pause_hi
|
||||
chown system system /sys/class/leds/white/pause_lo
|
||||
chown system system /sys/class/leds/white/ramp_step_ms
|
||||
chown system system /sys/class/leds/white/start_idx
|
||||
|
||||
service vendor.light-default /vendor/bin/hw/android.hardware.light-service.xiaomi
|
||||
class hal
|
||||
user system
|
||||
group system
|
||||
shutdown critical
|
||||
@@ -1,7 +0,0 @@
|
||||
<manifest version="1.0" type="device">
|
||||
<hal format="aidl">
|
||||
<name>android.hardware.light</name>
|
||||
<version>2</version>
|
||||
<fqname>ILights/default</fqname>
|
||||
</hal>
|
||||
</manifest>
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2024 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "Lights.h"
|
||||
|
||||
#define LOG_TAG "android.hardware.light-service.xiaomi"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <android/binder_manager.h>
|
||||
#include <android/binder_process.h>
|
||||
|
||||
using ::aidl::android::hardware::light::Lights;
|
||||
|
||||
int main() {
|
||||
ABinderProcess_setThreadPoolMaxThreadCount(0);
|
||||
std::shared_ptr<Lights> lights = ndk::SharedRefBase::make<Lights>();
|
||||
|
||||
const std::string instance = std::string() + Lights::descriptor + "/default";
|
||||
binder_status_t status = AServiceManager_addService(lights->asBinder().get(), instance.c_str());
|
||||
CHECK(status == STATUS_OK);
|
||||
|
||||
ABinderProcess_joinThreadPool();
|
||||
return EXIT_FAILURE; // should not reach
|
||||
}
|
||||
37
dolby/Android.bp
Normal file
37
dolby/Android.bp
Normal file
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// Copyright (C) 2017-2021 The LineageOS Project
|
||||
// (C) 2023-24 Paranoid Android
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
android_app {
|
||||
name: "XiaomiDolby",
|
||||
|
||||
srcs: ["src/**/*.kt"],
|
||||
resource_dirs: ["res"],
|
||||
certificate: "platform",
|
||||
platform_apis: true,
|
||||
system_ext_specific: true,
|
||||
privileged: true,
|
||||
|
||||
overrides: ["MusicFX", "AudioFX"],
|
||||
static_libs: [
|
||||
"SettingsLib",
|
||||
"SpaLib",
|
||||
"androidx.activity_activity-compose",
|
||||
"androidx.compose.material3_material3",
|
||||
"androidx.compose.runtime_runtime",
|
||||
"androidx.preference_preference",
|
||||
"org.lineageos.settings.resources",
|
||||
],
|
||||
|
||||
required: ["preinstalled-packages-platform-dolby.xml"],
|
||||
}
|
||||
|
||||
prebuilt_etc {
|
||||
name: "preinstalled-packages-platform-dolby.xml",
|
||||
src: "preinstalled-packages-platform-dolby.xml",
|
||||
sub_dir: "sysconfig",
|
||||
system_ext_specific: true,
|
||||
}
|
||||
74
dolby/AndroidManifest.xml
Normal file
74
dolby/AndroidManifest.xml
Normal file
@@ -0,0 +1,74 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2023-24 Paranoid Android
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="co.aospa.dolby.xiaomi"
|
||||
android:sharedUserId="android.uid.system">
|
||||
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:label="@string/dolby_title"
|
||||
android:persistent="true">
|
||||
|
||||
<receiver
|
||||
android:name=".BootCompletedReceiver"
|
||||
android:exported="true">
|
||||
<intent-filter android:priority="1000">
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<activity
|
||||
android:name=".DolbyActivity"
|
||||
android:label="@string/dolby_title"
|
||||
android:theme="@style/Theme.SubSettingsBase"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="com.android.settings.action.IA_SETTINGS" />
|
||||
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES"/>
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.media.action.DISPLAY_AUDIO_EFFECT_CONTROL_PANEL" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.CATEGORY_CONTENT_MUSIC" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="com.android.settings.category"
|
||||
android:value="com.android.settings.category.ia.sound" />
|
||||
<meta-data android:name="com.android.settings.summary_uri"
|
||||
android:value="content://co.aospa.dolby.xiaomi.summary/dolby" />
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".geq.EqualizerActivity"
|
||||
android:label="@string/dolby_preset"
|
||||
android:theme="@style/Theme.SubSettingsBase"
|
||||
android:exported="true" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<service
|
||||
android:name=".DolbyTileService"
|
||||
android:icon="@drawable/ic_dolby_qs"
|
||||
android:label="@string/dolby_title"
|
||||
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.service.quicksettings.action.QS_TILE"/>
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<provider
|
||||
android:name=".SummaryProvider"
|
||||
android:authorities="co.aospa.dolby.xiaomi.summary">
|
||||
</provider>
|
||||
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
26
dolby/preinstalled-packages-platform-dolby.xml
Normal file
26
dolby/preinstalled-packages-platform-dolby.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2024 crDroid Android 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.
|
||||
-->
|
||||
<config>
|
||||
|
||||
<!-- Dolby -->
|
||||
<install-in-user-type package="co.aospa.dolby.xiaomi">
|
||||
<install-in user-type="FULL" />
|
||||
<install-in user-type="PROFILE" />
|
||||
<do-not-install-in user-type="android.os.usertype.profile.CLONE" />
|
||||
<do-not-install-in user-type="android.os.usertype.profile.PRIVATE" />
|
||||
</install-in-user-type>
|
||||
</config>
|
||||
8
dolby/res/drawable/ic_dolby.xml
Normal file
8
dolby/res/drawable/ic_dolby.xml
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:width="24dp" android:viewportWidth="24" android:viewportHeight="24" android:tint="?android:attr/colorControlNormal">
|
||||
<path android:fillColor="#000000" android:pathData="M1,4.0214C2.2767,4.0743 3.5798,3.9866 4.8252,4.2063C8.8352,4.9133 11.4129,8.3489 11.0507,12.3402C10.7124,16.0695 7.3661,18.9511 3.3484,18.9651C2.5657,18.9678 1.7827,18.9441 1,18.9324L1,4.0214Z" android:strokeColor="#00000000" android:strokeWidth="1" android:fillType="evenOdd"/>
|
||||
<group>
|
||||
<clip-path android:pathData="M12.9332,4l10.0668,0l0,15l-10.0668,0z"/>
|
||||
<path android:fillColor="#000000" android:pathData="M23,4.0924L23,18.8825C19.4973,19.298 16.399,18.6968 14.3366,15.6947C12.5148,13.043 12.4594,10.2265 14.2129,7.5241C16.244,4.394 19.3953,3.7204 23,4.0924" android:strokeColor="#00000000" android:strokeWidth="1" android:fillType="evenOdd"/>
|
||||
</group>
|
||||
</vector>
|
||||
8
dolby/res/drawable/ic_dolby_qs.xml
Normal file
8
dolby/res/drawable/ic_dolby_qs.xml
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:width="24dp" android:viewportWidth="24" android:viewportHeight="24">
|
||||
<path android:fillColor="#191c1e" android:pathData="M1,4.0214C2.2767,4.0743 3.5798,3.9866 4.8252,4.2063C8.8352,4.9133 11.4129,8.3489 11.0507,12.3402C10.7124,16.0695 7.3661,18.9511 3.3484,18.9651C2.5657,18.9678 1.7827,18.9441 1,18.9324L1,4.0214Z" android:strokeColor="#00000000" android:strokeWidth="1" android:fillType="evenOdd"/>
|
||||
<group>
|
||||
<clip-path android:pathData="M12.9332,4l10.0668,0l0,15l-10.0668,0z"/>
|
||||
<path android:fillColor="#191c1e" android:pathData="M23,4.0924L23,18.8825C19.4973,19.298 16.399,18.6968 14.3366,15.6947C12.5148,13.043 12.4594,10.2265 14.2129,7.5241C16.244,4.394 19.3953,3.7204 23,4.0924" android:strokeColor="#00000000" android:strokeWidth="1" android:fillType="evenOdd"/>
|
||||
</group>
|
||||
</vector>
|
||||
24
dolby/res/drawable/ic_ieq_balanced.xml
Normal file
24
dolby/res/drawable/ic_ieq_balanced.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="192dp"
|
||||
android:height="192dp"
|
||||
android:viewportWidth="192"
|
||||
android:viewportHeight="192"
|
||||
android:tint="?android:attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M 69.584 66.547 L 63.792 70.797 L 38.646 71.697 L 13.5 72.597 L 13.5 89.723 C 13.5 99.143 13.865 111.999 14.313 118.292 L 15.124 129.734 L 178.5 129.734 L 178.5 102.234 L 121.248 102.234 L 99.203 82.234 C 87.078 71.234 76.756 62.248 76.266 62.266 C 75.776 62.282 72.769 64.209 69.584 66.547"
|
||||
android:strokeWidth="1.25"/>
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M 69.125 67.065 L 62.875 71.921 L 38.188 71.99 L 13.5 72.06 L 13.504 81.122 C 13.506 86.106 13.876 99.044 14.325 109.872 L 15.141 129.56 L 178.5 129.56 L 178.5 103.31 L 122.126 103.31 L 99.675 82.997 C 87.326 71.826 76.808 62.577 76.299 62.446 C 75.791 62.315 72.563 64.394 69.125 67.065"
|
||||
android:strokeWidth="1.25"/>
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M 69.854 67.249 L 63.237 72.187 L 13.311 72.187 L 14.119 84.374 C 14.562 91.077 14.929 104.016 14.932 113.124 L 14.939 129.687 L 178.689 129.687 L 178.689 103.437 L 150.251 103.428 L 121.814 103.418 L 99.143 82.865 L 76.471 62.313 L 69.854 67.249"
|
||||
android:strokeWidth="1.25"/>
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M 69.141 67.266 L 63.221 71.609 L 45.888 71.609 C 36.354 71.609 25.238 71.956 21.184 72.378 L 13.813 73.147 L 14.115 93.316 C 14.281 104.408 14.748 117.001 15.151 121.297 L 15.886 129.109 L 178.188 129.109 L 178.188 102.859 L 120.703 102.859 L 98.696 82.859 C 86.594 71.859 76.324 62.873 75.876 62.891 C 75.429 62.907 72.399 64.876 69.141 67.266"
|
||||
android:strokeWidth="1.25"/>
|
||||
</vector>
|
||||
24
dolby/res/drawable/ic_ieq_detailed.xml
Normal file
24
dolby/res/drawable/ic_ieq_detailed.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="192dp"
|
||||
android:height="192dp"
|
||||
android:viewportWidth="192"
|
||||
android:viewportHeight="192"
|
||||
android:tint="?android:attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M 126.625 63.749 C 120.886 65.812 115.12 69.774 103.5 79.643 C 85.566 94.873 77.207 98.716 62.179 98.637 C 51.344 98.582 42.841 96.091 34.946 90.659 C 29.282 86.763 22.25 77.097 22.25 73.209 C 22.25 71.466 21.259 70.954 17.875 70.954 L 13.5 70.954 L 13.5 129.704 L 178.5 129.704 L 178.5 86.329 L 174.915 81.381 C 169.567 73.999 161.404 67.534 153.865 64.714 C 146.447 61.939 132.988 61.463 126.625 63.749"
|
||||
android:strokeWidth="1.25"/>
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M 128.493 63.479 C 122.229 65.384 117.026 68.819 104.59 79.26 C 89.19 92.189 83.945 95.359 73.54 98.024 C 60.438 101.381 44.281 98.268 33.966 90.4 C 28.19 85.994 22.25 77.679 22.25 73.999 C 22.25 71.475 21.634 71.061 17.875 71.061 L 13.5 71.061 L 13.5 129.811 L 178.5 129.811 L 178.494 108.249 L 178.488 86.686 L 173.807 80.541 C 163.119 66.51 143.193 59.008 128.493 63.479"
|
||||
android:strokeWidth="1.25"/>
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M 129.75 63.348 C 122.865 65.451 115.829 70.014 103.442 80.413 C 96.136 86.547 86.969 92.947 82.48 95.048 C 60.304 105.426 32.044 97.046 23.267 77.492 C 21.242 72.979 20.328 72.179 17.191 72.179 L 13.5 72.179 L 13.5 129.679 L 178.5 129.679 L 178.456 108.742 C 178.41 86.981 178.329 86.587 172.313 78.669 C 163.463 67.022 142.469 59.466 129.75 63.348"
|
||||
android:strokeWidth="1.25"/>
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M 131.184 63.546 C 123.825 64.992 117.559 68.919 103.5 80.894 C 96.969 86.458 87.98 92.824 83.526 95.043 C 75.941 98.821 74.591 99.077 62.25 99.077 C 49.875 99.077 48.564 98.827 40.714 94.962 C 31.655 90.503 24.469 83.298 22.19 76.396 C 21.04 72.909 20.19 72.202 17.152 72.202 L 13.5 72.202 L 13.5 129.702 L 178.5 129.702 L 178.5 87.577 L 174.965 82.702 C 170.49 76.532 163.525 70.403 157.488 67.323 C 153.545 65.312 139.684 61.884 137.333 62.339 C 136.944 62.414 134.176 62.957 131.184 63.546"
|
||||
android:strokeWidth="1.25"/>
|
||||
</vector>
|
||||
13
dolby/res/drawable/ic_ieq_off.xml
Normal file
13
dolby/res/drawable/ic_ieq_off.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="192dp"
|
||||
android:height="192dp"
|
||||
android:viewportWidth="192"
|
||||
android:viewportHeight="192"
|
||||
android:tint="?android:attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M 13.5 96 L 13.5 103.5 L 178.5 103.5 L 178.5 88.5 L 13.5 88.5 L 13.5 96"
|
||||
android:strokeWidth="1.25"
|
||||
android:fillType="evenOdd"/>
|
||||
</vector>
|
||||
28
dolby/res/drawable/ic_ieq_warm.xml
Normal file
28
dolby/res/drawable/ic_ieq_warm.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="192dp"
|
||||
android:height="192dp"
|
||||
android:viewportWidth="192"
|
||||
android:viewportHeight="192"
|
||||
android:tint="?android:attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M 48.789 64.919 C 45.865 66.366 40.885 70.429 37.721 73.948 C 28.465 84.243 13.479 116.446 13.479 126.041 L 13.479 129.786 L 95.979 129.786 C 141.354 129.786 178.479 129.486 178.479 129.12 C 178.479 128.753 177.131 125.8 175.483 122.558 C 170.413 112.579 162.723 104.006 155.705 100.509 C 149.673 97.503 148.053 97.286 131.582 97.286 C 105.944 97.286 102.89 95.881 86.335 76.454 C 74.977 63.124 61.056 58.848 48.789 64.919"
|
||||
android:strokeWidth="1.25"
|
||||
android:fillType="evenOdd"/>
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M 49.712 64.871 C 40.942 68.842 33.167 78.157 25.45 93.941 C 18.063 109.047 13.462 121.585 13.462 126.604 L 13.462 129.769 L 178.496 129.769 L 176.673 125.407 C 171.895 113.971 159.81 101.317 151.203 98.739 C 148.476 97.921 138.591 97.264 128.942 97.256 C 107.671 97.241 102.106 95.265 93.347 84.617 C 76.128 63.684 64.227 58.297 49.712 64.871"
|
||||
android:strokeWidth="1.25"
|
||||
android:fillType="evenOdd"/>
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M 52.781 63.452 C 47.321 65.482 40.256 70.907 35.792 76.496 C 27.971 86.29 13.406 119.09 13.406 126.91 L 13.406 129.502 L 178.552 129.502 L 174.586 122.06 C 169.31 112.162 163.213 105.23 156.113 101.056 C 150.453 97.729 149.705 97.625 130.807 97.53 C 107.81 97.414 103.646 96.04 94.012 85.387 C 80.912 70.9 77.898 68.045 73.171 65.632 C 67.157 62.565 57.846 61.569 52.781 63.452"
|
||||
android:strokeWidth="1.25"
|
||||
android:fillType="evenOdd"/>
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M 56.078 63.069 C 44.607 65.852 35.711 75.314 26.246 94.802 C 19.707 108.263 16.537 116.731 14.817 125.334 L 14.005 129.397 L 95.98 129.397 C 165.857 129.397 177.953 129.136 177.953 127.627 C 177.953 124.146 165.22 106.857 160.048 103.314 C 152.515 98.156 150.572 97.791 129.828 97.641 C 111.478 97.507 110.935 97.424 104.33 93.776 C 99.905 91.331 95.316 87.208 91 81.798 C 80.578 68.737 74.351 64.324 64.203 62.812 C 61.797 62.453 58.141 62.568 56.078 63.069"
|
||||
android:strokeWidth="1.25"
|
||||
android:fillType="evenOdd"/>
|
||||
</vector>
|
||||
11
dolby/res/drawable/ic_profile_custom.xml
Executable file
11
dolby/res/drawable/ic_profile_custom.xml
Executable file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?android:attr/colorControlNormal"
|
||||
android:height="24dp"
|
||||
android:width="24dp"
|
||||
android:viewportWidth="72.0"
|
||||
android:viewportHeight="72.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M45,9L45,27L51,27L51,21L63,21L63,15L51,15L51,9L45,9M9,15L9,21L39,21L39,15L9,15M21,27L21,33L9,33L9,39L21,39L21,45L27,45L27,27L21,27M33,33L33,39L63,39L63,33L33,33M33,45L33,63L39,63L39,57L63,57L63,51L39,51L39,45L33,45M9,51L9,57L27,57L27,51L9,51z"/>
|
||||
</vector>
|
||||
11
dolby/res/drawable/ic_profile_dynamic.xml
Executable file
11
dolby/res/drawable/ic_profile_dynamic.xml
Executable file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?android:attr/colorControlNormal"
|
||||
android:height="24dp"
|
||||
android:width="24dp"
|
||||
android:viewportWidth="72.0"
|
||||
android:viewportHeight="72.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M21,6L21,39L30,39L30,66C34.0185,62.1036 36.3516,56.7839 39.2006,52C43.3436,45.0435 48.7076,37.7933 51,30L40,30C43.3656,21.916 48.5711,14.4315 51,6L21,6z"/>
|
||||
</vector>
|
||||
11
dolby/res/drawable/ic_profile_movie.xml
Executable file
11
dolby/res/drawable/ic_profile_movie.xml
Executable file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?android:attr/colorControlNormal"
|
||||
android:height="24dp"
|
||||
android:width="24dp"
|
||||
android:viewportWidth="72.0"
|
||||
android:viewportHeight="72.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M7.84,13.82C9.62,11.74 12.52,12.02 14.98,11.95C16.97,15.97 19,19.98 21,24C24,24 27,24 30,24C28,20 26,16 24,12C26,12 28,12 30,12C32,16 34,20 36,24C39,24 42,24 45,24C43,20 41,16 39,12C41,12 43,12 45,12C47,16 49,20 51,24C54,24 57,24 60,24C58,20 56,16 54,12C58,12 62,12 66,12C65.99,25.69 66.01,39.38 66,53.07C66.42,56.49 63.62,59.98 60.12,59.96C44.39,60.06 28.66,59.97 12.93,60C9.52,60.43 6.02,57.62 6.04,54.12C5.93,42.75 6.06,31.37 6,19.99C5.95,17.82 6.08,15.36 7.84,13.82Z"/>
|
||||
</vector>
|
||||
11
dolby/res/drawable/ic_profile_music.xml
Executable file
11
dolby/res/drawable/ic_profile_music.xml
Executable file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?android:attr/colorControlNormal"
|
||||
android:height="24dp"
|
||||
android:width="24dp"
|
||||
android:viewportWidth="72.0"
|
||||
android:viewportHeight="72.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M36,9L36,40C32.245,38.8901 27.6726,38.2912 24.0154,40.179C17.5734,43.5044 15.8784,53.3215 20.4336,58.8912C25.822,65.4796 38.0937,64.1632 41.2577,55.9961C42.655,52.3894 42,47.7931 42,44L42,21L54,21L54,9L36,9z"/>
|
||||
</vector>
|
||||
9
dolby/res/drawable/reset_settings_24px.xml
Normal file
9
dolby/res/drawable/reset_settings_24px.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="?android:attr/colorControlNormal"
|
||||
android:pathData="M520,630L520,570L680,570L680,630L520,630ZM580,840L580,790L520,790L520,730L580,730L580,680L640,680L640,840L580,840ZM680,790L680,730L840,730L840,790L680,790ZM720,680L720,520L780,520L780,570L840,570L840,630L780,630L780,680L720,680ZM831,400L748,400Q722,312 649,256Q576,200 480,200Q363,200 281.5,281.5Q200,363 200,480Q200,552 232.5,612Q265,672 320,710L320,600L400,600L400,840L160,840L160,760L254,760Q192,710 156,637.5Q120,565 120,480Q120,405 148.5,339.5Q177,274 225.5,225.5Q274,177 339.5,148.5Q405,120 480,120Q609,120 706.5,199.5Q804,279 831,400Z" />
|
||||
</vector>
|
||||
9
dolby/res/drawable/save_as_24px.xml
Normal file
9
dolby/res/drawable/save_as_24px.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="?android:attr/colorControlNormal"
|
||||
android:pathData="M200,840Q167,840 143.5,816.5Q120,793 120,760L120,200Q120,167 143.5,143.5Q167,120 200,120L680,120L840,280L840,492Q821,484 800.5,481.5Q780,479 760,482L760,313L647,200L200,200Q200,200 200,200Q200,200 200,200L200,760Q200,760 200,760Q200,760 200,760L440,760L440,764L440,840L200,840ZM200,200L200,313L200,482Q200,485 200,494.5Q200,504 200,519L200,760L200,760L200,760Q200,760 200,760Q200,760 200,760L200,200Q200,200 200,200Q200,200 200,200ZM520,920L520,797L741,577Q750,568 761,564Q772,560 783,560Q795,560 806,564.5Q817,569 826,578L863,615Q871,624 875.5,635Q880,646 880,657Q880,668 876,679.5Q872,691 863,700L643,920L520,920ZM820,657L820,657L783,620L783,620L820,657ZM580,860L618,860L739,738L721,719L702,701L580,822L580,860ZM721,719L702,701L702,701L739,738L739,738L721,719ZM240,400L600,400L600,240L240,240L240,400ZM480,720Q481,720 482,720Q483,720 484,720L600,605Q600,603 600,602.5Q600,602 600,600Q600,550 565,515Q530,480 480,480Q430,480 395,515Q360,550 360,600Q360,650 395,685Q430,720 480,720Z"/>
|
||||
</vector>
|
||||
41
dolby/res/layout/ieq_icon_layout.xml
Normal file
41
dolby/res/layout/ieq_icon_layout.xml
Normal file
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2021 The Android Open Source Project
|
||||
(C) 2024 Paranoid Android
|
||||
|
||||
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.
|
||||
-->
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@android:id/widget_frame"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minWidth="56dp"
|
||||
android:gravity="end|center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingRight="0dp"
|
||||
android:paddingEnd="0dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingBottom="4dp">
|
||||
|
||||
<androidx.preference.internal.PreferenceImageView
|
||||
android:id="@+id/ieq_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:maxWidth="56dp"
|
||||
app:maxHeight="56dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
70
dolby/res/values-ru/strings.xml
Normal file
70
dolby/res/values-ru/strings.xml
Normal file
@@ -0,0 +1,70 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2023-24 Paranoid Android
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
<resources>
|
||||
|
||||
<!-- Dolby Atmos -->
|
||||
<string name="dolby_title">Dolby Atmos</string>
|
||||
<string name="dolby_enable">Использовать Dolby Atmos</string>
|
||||
<string name="dolby_profile_title">Выберите профиль</string>
|
||||
<string name="dolby_preset">Графический эквалайзер</string>
|
||||
<string name="dolby_off">Выключено</string>
|
||||
<string name="dolby_on">Включено</string>
|
||||
<string name="dolby_low">Низкий</string>
|
||||
<string name="dolby_medium">Средний</string>
|
||||
<string name="dolby_high">Высокий</string>
|
||||
<string name="dolby_max">Максимальный</string>
|
||||
<string name="dolby_unknown">Неизвестно</string>
|
||||
<string name="dolby_on_with_profile">Включено (%1$s)</string>
|
||||
<string name="dolby_category_settings">Настройки</string>
|
||||
<string name="dolby_bass_enhancer">Усилитель басов</string>
|
||||
<string name="dolby_dialogue_enhancer">Усиление диалогов</string>
|
||||
<string name="dolby_spk_virtualizer">Виртуализация динамиков</string>
|
||||
<string name="dolby_hp_virtualizer">Виртуализация наушников</string>
|
||||
<string name="dolby_stereo_widening">Расширение стерео</string>
|
||||
<string name="dolby_volume_leveler">Выравниватель громкости</string>
|
||||
<string name="dolby_connect_headphones">Подключите наушники</string>
|
||||
<string name="dolby_reset_profile">Сбросить до настроек по умолчанию</string>
|
||||
<string name="dolby_reset_profile_toast">Настройки для профиля %1$s успешно сброшены</string>
|
||||
|
||||
<!-- Dolby profiles -->
|
||||
<string name="dolby_profile_dynamic">Динамический</string>
|
||||
<string name="dolby_profile_video">Кино/Видео</string>
|
||||
<string name="dolby_profile_music">Музыка</string>
|
||||
<string name="dolby_profile_voice">Голос</string>
|
||||
|
||||
<!-- Dolby equalizer presets -->
|
||||
<string name="dolby_preset_default">Плоский (выключено)</string>
|
||||
<string name="dolby_preset_rock">Рок</string>
|
||||
<string name="dolby_preset_jazz">Джаз</string>
|
||||
<string name="dolby_preset_pop">Поп</string>
|
||||
<string name="dolby_preset_classical">Классика</string>
|
||||
<string name="dolby_preset_hiphop">Хип-хоп</string>
|
||||
<string name="dolby_preset_blues">Блюз</string>
|
||||
<string name="dolby_preset_electronic">Электронная музыка</string>
|
||||
<string name="dolby_preset_country">Кантри</string>
|
||||
<string name="dolby_preset_dance">Танцевальная музыка</string>
|
||||
<string name="dolby_preset_metal">Метал</string>
|
||||
|
||||
<!-- Dolby equalizer UI -->
|
||||
<string name="dolby_geq_slider_label_gain">Усиление</string>
|
||||
<string name="dolby_geq_preset">Предустановка</string>
|
||||
<string name="dolby_geq_preset_name">Название предустановки</string>
|
||||
<string name="dolby_geq_new_preset">Новая предустановка</string>
|
||||
<string name="dolby_geq_rename_preset">Переименовать предустановку</string>
|
||||
<string name="dolby_geq_delete_preset">Удалить предустановку</string>
|
||||
<string name="dolby_geq_delete_preset_prompt">Вы хотите удалить эту предустановку?</string>
|
||||
<string name="dolby_geq_reset_gains">Сбросить усиление</string>
|
||||
<string name="dolby_geq_reset_gains_prompt">Вы хотите сбросить эту предустановку до настроек по умолчанию?</string>
|
||||
<string name="dolby_geq_preset_name_exists">Имя предустановки уже существует!</string>
|
||||
<string name="dolby_geq_preset_name_too_long">Имя предустановки слишком длинное!</string>
|
||||
|
||||
<!-- Dolby intelligent EQ -->
|
||||
<string name="dolby_ieq">Интеллектуальный эквалайзер</string>
|
||||
<string name="dolby_balanced">Сбалансированный</string>
|
||||
<string name="dolby_warm">Тёплый</string>
|
||||
<string name="dolby_detailed">Детализированный</string>
|
||||
|
||||
</resources>
|
||||
102
dolby/res/values/arrays.xml
Normal file
102
dolby/res/values/arrays.xml
Normal file
@@ -0,0 +1,102 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2023-24 Paranoid Android
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
<resources>
|
||||
|
||||
<!-- Dolby Atmos -->
|
||||
<string-array name="dolby_profile_entries">
|
||||
<item>@string/dolby_profile_dynamic</item>
|
||||
<item>@string/dolby_profile_movie</item>
|
||||
<item>@string/dolby_profile_music</item>
|
||||
<item>@string/dolby_profile_custom</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="dolby_profile_values">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
<item>3</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="dolby_preset_entries" translatable="false">
|
||||
<item>@string/dolby_preset_default</item>
|
||||
<item>@string/dolby_preset_rock</item>
|
||||
<item>@string/dolby_preset_jazz</item>
|
||||
<item>@string/dolby_preset_pop</item>
|
||||
<item>@string/dolby_preset_classical</item>
|
||||
<item>@string/dolby_preset_hiphop</item>
|
||||
<item>@string/dolby_preset_blues</item>
|
||||
<item>@string/dolby_preset_electronic</item>
|
||||
<item>@string/dolby_preset_metal</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="dolby_preset_values">
|
||||
<!--
|
||||
<item>0,0,0,0,0,0,0,0,0,0</item>
|
||||
<item>4,1,-2,-0.25,0,-2,0,-2,0.5,4</item>
|
||||
<item>0,0,0,-1,-1,-3,-0.5,0,0,0</item>
|
||||
<item>-2,-0.5,-5,-1,0,0,-0.5,-3,-0.5,0</item>
|
||||
<item>0,0,0,0,0.5,3,1,6,2,6</item>
|
||||
<item>3,0,-3,-0.5,-0.5,-3,-0.5,0,0,2</item>
|
||||
<item>2,2,-6,-2,3,1,0,1,0,2</item>
|
||||
<item>3,1,-1,0,-0.5,-3,-0.5,0,0,0</item>
|
||||
<item>2,0,0,-1.25,-1,-4,0,0,0,0</item>
|
||||
-->
|
||||
<item>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</item>
|
||||
<item>60,36,12,-12,-36,-24,-12,-8,-4,-20,-36,-20,-4,-20,-36,-16,4,32,60,60</item>
|
||||
<item>8,8,8,8,8,0,-8,-8,-8,-24,-40,-20,0,4,8,8,8,8,8,8</item>
|
||||
<item>-13,-1,11,-25,-61,-29,3,11,19,19,19,15,11,-9,-29,-9,11,15,19,19</item>
|
||||
<item>-32,-32,-32,-32,-32,-32,-32,-28,-24,-4,16,0,-16,24,64,32,0,32,64,64</item>
|
||||
<item>52,28,4,-20,-44,-24,-4,-4,-4,-24,-44,-24,-4,0,4,4,4,20,36,36</item>
|
||||
<item>28,28,28,-36,-100,-68,-36,4,44,28,12,4,-4,4,12,4,-4,12,28,28</item>
|
||||
<item>50,34,18,2,-14,-6,2,-2,-6,-26,-46,-26,-6,-2,2,2,2,2,2,2</item>
|
||||
<item>40,24,8,8,8,-4,-16,-12,-8,-32,-56,-24,8,8,8,8,8,8,8,8</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="dolby_dialogue_entries">
|
||||
<item>@string/dolby_off</item>
|
||||
<item>@string/dolby_low</item>
|
||||
<item>@string/dolby_medium</item>
|
||||
<item>@string/dolby_high</item>
|
||||
<item>@string/dolby_max</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="dolby_dialogue_values">
|
||||
<item>0</item>
|
||||
<item>2</item>
|
||||
<item>6</item>
|
||||
<item>9</item>
|
||||
<item>12</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="dolby_stereo_entries">
|
||||
<item>@string/dolby_low</item>
|
||||
<item>@string/dolby_medium</item>
|
||||
<item>@string/dolby_high</item>
|
||||
<item>@string/dolby_max</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="dolby_stereo_values">
|
||||
<item>4</item>
|
||||
<item>24</item>
|
||||
<item>44</item>
|
||||
<item>64</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="dolby_ieq_entries">
|
||||
<item>@string/dolby_off</item>
|
||||
<item>@string/dolby_balanced</item>
|
||||
<item>@string/dolby_warm</item>
|
||||
<item>@string/dolby_detailed</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="dolby_ieq_values">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
<item>3</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
70
dolby/res/values/strings.xml
Normal file
70
dolby/res/values/strings.xml
Normal file
@@ -0,0 +1,70 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2023-24 Paranoid Android
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
<resources>
|
||||
|
||||
<!-- Dolby Atmos -->
|
||||
<string name="dolby_title">Dolby Atmos</string>
|
||||
<string name="dolby_enable">Use Dolby Atmos</string>
|
||||
<string name="dolby_profile_title">Choose a profile</string>
|
||||
<string name="dolby_preset">Graphic equalizer</string>
|
||||
<string name="dolby_off">Off</string>
|
||||
<string name="dolby_on">On</string>
|
||||
<string name="dolby_low">Low</string>
|
||||
<string name="dolby_medium">Medium</string>
|
||||
<string name="dolby_high">High</string>
|
||||
<string name="dolby_max">Max</string>
|
||||
<string name="dolby_unknown">Unknown</string>
|
||||
<string name="dolby_on_with_profile">On (%1$s)</string>
|
||||
<string name="dolby_category_settings">Settings</string>
|
||||
<string name="dolby_bass_enhancer">Bass enhancer</string>
|
||||
<string name="dolby_dialogue_enhancer">Dialogue enhancer</string>
|
||||
<string name="dolby_spk_virtualizer">Speaker virtualization</string>
|
||||
<string name="dolby_hp_virtualizer">Headphone virtualization</string>
|
||||
<string name="dolby_stereo_widening">Stereo widening</string>
|
||||
<string name="dolby_volume_leveler">Volume leveler</string>
|
||||
<string name="dolby_connect_headphones">Connect headphones</string>
|
||||
<string name="dolby_reset_profile">Reset to defaults</string>
|
||||
<string name="dolby_reset_profile_toast">Successfully reset settings for %1$s profile</string>
|
||||
|
||||
<!-- Dolby profiles -->
|
||||
<string name="dolby_profile_dynamic">Dynamic</string>
|
||||
<string name="dolby_profile_movie">Movie</string>
|
||||
<string name="dolby_profile_music">Music</string>
|
||||
<string name="dolby_profile_custom">Custom</string>
|
||||
|
||||
<!-- Dolby equalizer presets -->
|
||||
<string name="dolby_preset_default">Flat (off)</string>
|
||||
<string name="dolby_preset_rock">Rock</string>
|
||||
<string name="dolby_preset_jazz">Jazz</string>
|
||||
<string name="dolby_preset_pop">Pop</string>
|
||||
<string name="dolby_preset_classical">Classical</string>
|
||||
<string name="dolby_preset_hiphop">Hip Hop</string>
|
||||
<string name="dolby_preset_blues">Blues</string>
|
||||
<string name="dolby_preset_electronic">Electronic</string>
|
||||
<string name="dolby_preset_country">Country</string>
|
||||
<string name="dolby_preset_dance">Dance</string>
|
||||
<string name="dolby_preset_metal">Metal</string>
|
||||
|
||||
<!-- Dolby equalizer UI -->
|
||||
<string name="dolby_geq_slider_label_gain">Gain</string>
|
||||
<string name="dolby_geq_preset">Preset</string>
|
||||
<string name="dolby_geq_preset_name">Preset name</string>
|
||||
<string name="dolby_geq_new_preset">New preset</string>
|
||||
<string name="dolby_geq_rename_preset">Rename preset</string>
|
||||
<string name="dolby_geq_delete_preset">Delete preset</string>
|
||||
<string name="dolby_geq_delete_preset_prompt">Do you want to delete this preset?</string>
|
||||
<string name="dolby_geq_reset_gains">Reset gains</string>
|
||||
<string name="dolby_geq_reset_gains_prompt">Do you want to reset this preset to defaults?</string>
|
||||
<string name="dolby_geq_preset_name_exists">Preset name already exists!</string>
|
||||
<string name="dolby_geq_preset_name_too_long">Preset name is too long!</string>
|
||||
|
||||
<!-- Dolby intelligent EQ -->
|
||||
<string name="dolby_ieq">Intelligent equalizer</string>
|
||||
<string name="dolby_balanced">Balanced</string>
|
||||
<string name="dolby_warm">Warm</string>
|
||||
<string name="dolby_detailed">Detailed</string>
|
||||
|
||||
</resources>
|
||||
76
dolby/res/xml/dolby_settings.xml
Normal file
76
dolby/res/xml/dolby_settings.xml
Normal file
@@ -0,0 +1,76 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2023-24 Paranoid Android
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:title="@string/dolby_title">
|
||||
|
||||
<com.android.settingslib.widget.MainSwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:key="dolby_enable"
|
||||
android:title="@string/dolby_enable" />
|
||||
|
||||
<ListPreference
|
||||
android:key="dolby_profile"
|
||||
android:entries="@array/dolby_profile_entries"
|
||||
android:entryValues="@array/dolby_profile_values"
|
||||
android:defaultValue="0"
|
||||
android:title="@string/dolby_profile_title"
|
||||
android:summary="%s" />
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/dolby_category_settings">
|
||||
|
||||
<Preference
|
||||
android:key="dolby_preset"
|
||||
android:title="@string/dolby_preset">
|
||||
<intent
|
||||
android:action="android.intent.action.MAIN"
|
||||
android:targetPackage="co.aospa.dolby.xiaomi"
|
||||
android:targetClass="co.aospa.dolby.xiaomi.geq.EqualizerActivity" />
|
||||
</Preference>
|
||||
|
||||
<co.aospa.dolby.xiaomi.preference.DolbyIeqPreference
|
||||
android:key="dolby_ieq"
|
||||
android:entries="@array/dolby_ieq_entries"
|
||||
android:entryValues="@array/dolby_ieq_values"
|
||||
android:title="@string/dolby_ieq" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:key="dolby_spk_virtualizer"
|
||||
android:title="@string/dolby_spk_virtualizer" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:key="dolby_virtualizer"
|
||||
android:title="@string/dolby_hp_virtualizer" />
|
||||
|
||||
<ListPreference
|
||||
android:key="dolby_stereo"
|
||||
android:entries="@array/dolby_stereo_entries"
|
||||
android:entryValues="@array/dolby_stereo_values"
|
||||
android:title="@string/dolby_stereo_widening"
|
||||
android:dependency="dolby_virtualizer" />
|
||||
|
||||
<ListPreference
|
||||
android:key="dolby_dialogue"
|
||||
android:entries="@array/dolby_dialogue_entries"
|
||||
android:entryValues="@array/dolby_dialogue_values"
|
||||
android:title="@string/dolby_dialogue_enhancer" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:key="dolby_bass"
|
||||
android:title="@string/dolby_bass_enhancer" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:key="dolby_volume"
|
||||
android:title="@string/dolby_volume_leveler" />
|
||||
|
||||
<Preference
|
||||
android:key="dolby_reset"
|
||||
android:title="@string/dolby_reset_profile" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
27
dolby/src/co/aospa/dolby/xiaomi/BootCompletedReceiver.kt
Normal file
27
dolby/src/co/aospa/dolby/xiaomi/BootCompletedReceiver.kt
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (C) 2023-24 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package co.aospa.dolby.xiaomi
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
|
||||
private const val TAG = "XiaomiDolby-Boot"
|
||||
|
||||
class BootCompletedReceiver : BroadcastReceiver() {
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
Log.d(TAG, "Received intent: ${intent.action}")
|
||||
if (intent.action != Intent.ACTION_BOOT_COMPLETED) {
|
||||
return
|
||||
}
|
||||
|
||||
Log.i(TAG, "Boot completed, starting dolby")
|
||||
DolbyController.getInstance(context).onBootCompleted()
|
||||
}
|
||||
}
|
||||
23
dolby/src/co/aospa/dolby/xiaomi/DolbyActivity.kt
Normal file
23
dolby/src/co/aospa/dolby/xiaomi/DolbyActivity.kt
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) 2023-24 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package co.aospa.dolby.xiaomi
|
||||
|
||||
import android.os.Bundle
|
||||
import co.aospa.dolby.xiaomi.preference.DolbySettingsFragment
|
||||
import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity
|
||||
|
||||
private const val TAG = "DolbyActivity"
|
||||
|
||||
class DolbyActivity : CollapsingToolbarBaseActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
fragmentManager.beginTransaction()
|
||||
.replace(com.android.settingslib.collapsingtoolbar.R.id.content_frame, DolbySettingsFragment(), TAG)
|
||||
.commit()
|
||||
}
|
||||
}
|
||||
136
dolby/src/co/aospa/dolby/xiaomi/DolbyAudioEffect.kt
Normal file
136
dolby/src/co/aospa/dolby/xiaomi/DolbyAudioEffect.kt
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright (C) 2023-24 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package co.aospa.dolby.xiaomi
|
||||
|
||||
import android.media.audiofx.AudioEffect
|
||||
import co.aospa.dolby.xiaomi.DolbyConstants.Companion.dlog
|
||||
import co.aospa.dolby.xiaomi.DolbyConstants.DsParam
|
||||
import java.util.UUID
|
||||
|
||||
class DolbyAudioEffect(priority: Int, audioSession: Int) : AudioEffect(
|
||||
EFFECT_TYPE_NULL, EFFECT_TYPE_DAP, priority, audioSession
|
||||
) {
|
||||
|
||||
var dsOn: Boolean
|
||||
get() = getIntParam(EFFECT_PARAM_ENABLE) == 1
|
||||
set(value) {
|
||||
setIntParam(EFFECT_PARAM_ENABLE, if (value) 1 else 0)
|
||||
enabled = value
|
||||
}
|
||||
|
||||
var profile: Int
|
||||
get() = getIntParam(EFFECT_PARAM_PROFILE)
|
||||
set(value) {
|
||||
setIntParam(EFFECT_PARAM_PROFILE, value)
|
||||
}
|
||||
|
||||
private fun setIntParam(param: Int, value: Int) {
|
||||
dlog(TAG, "setIntParam($param, $value)")
|
||||
val buf = ByteArray(12)
|
||||
int32ToByteArray(param, buf, 0)
|
||||
int32ToByteArray(1, buf, 4)
|
||||
int32ToByteArray(value, buf, 8)
|
||||
checkStatus(setParameter(EFFECT_PARAM_CPDP_VALUES, buf))
|
||||
}
|
||||
|
||||
private fun getIntParam(param: Int): Int {
|
||||
val buf = ByteArray(12)
|
||||
int32ToByteArray(param, buf, 0)
|
||||
checkStatus(getParameter(EFFECT_PARAM_CPDP_VALUES + param, buf))
|
||||
return byteArrayToInt32(buf).also {
|
||||
dlog(TAG, "getIntParam($param): $it")
|
||||
}
|
||||
}
|
||||
|
||||
fun resetProfileSpecificSettings(profile: Int = this.profile) {
|
||||
dlog(TAG, "resetProfileSpecificSettings: profile=$profile")
|
||||
setIntParam(EFFECT_PARAM_RESET_PROFILE_SETTINGS, profile)
|
||||
}
|
||||
|
||||
fun setDapParameter(param: DsParam, values: IntArray, profile: Int = this.profile) {
|
||||
dlog(TAG, "setDapParameter: profile=$profile param=$param")
|
||||
val length = values.size
|
||||
val buf = ByteArray((length + 4) * 4)
|
||||
int32ToByteArray(EFFECT_PARAM_SET_PROFILE_PARAMETER, buf, 0)
|
||||
int32ToByteArray(length + 1, buf, 4)
|
||||
int32ToByteArray(profile, buf, 8)
|
||||
int32ToByteArray(param.id, buf, 12)
|
||||
int32ArrayToByteArray(values, buf, 16)
|
||||
checkStatus(setParameter(EFFECT_PARAM_CPDP_VALUES, buf))
|
||||
}
|
||||
|
||||
fun setDapParameter(param: DsParam, enable: Boolean, profile: Int = this.profile) =
|
||||
setDapParameter(param, intArrayOf(if (enable) 1 else 0), profile)
|
||||
|
||||
fun setDapParameter(param: DsParam, value: Int, profile: Int = this.profile) =
|
||||
setDapParameter(param, intArrayOf(value), profile)
|
||||
|
||||
fun getDapParameter(param: DsParam, profile: Int = this.profile): IntArray {
|
||||
dlog(TAG, "getDapParameter: profile=$profile param=$param")
|
||||
val length = param.length
|
||||
val buf = ByteArray((length + 2) * 4)
|
||||
val p = (param.id shl 16) + (profile shl 8) + EFFECT_PARAM_GET_PROFILE_PARAMETER
|
||||
checkStatus(getParameter(p, buf))
|
||||
return byteArrayToInt32Array(buf, length)
|
||||
}
|
||||
|
||||
fun getDapParameterBool(param: DsParam, profile: Int = this.profile): Boolean =
|
||||
getDapParameter(param, profile)[0] == 1
|
||||
|
||||
fun getDapParameterInt(param: DsParam, profile: Int = this.profile): Int =
|
||||
getDapParameter(param, profile)[0]
|
||||
|
||||
companion object {
|
||||
private const val TAG = "DolbyAudioEffect"
|
||||
private val EFFECT_TYPE_DAP =
|
||||
UUID.fromString("9d4921da-8225-4f29-aefa-39537a04bcaa")
|
||||
|
||||
private const val EFFECT_PARAM_ENABLE = 0
|
||||
private const val EFFECT_PARAM_CPDP_VALUES = 5
|
||||
private const val EFFECT_PARAM_PROFILE = 0xA000000
|
||||
private const val EFFECT_PARAM_SET_PROFILE_PARAMETER = 0x1000000
|
||||
private const val EFFECT_PARAM_GET_PROFILE_PARAMETER = 0x1000005
|
||||
private const val EFFECT_PARAM_RESET_PROFILE_SETTINGS = 0xC000000
|
||||
|
||||
private fun int32ToByteArray(value: Int, dst: ByteArray, index: Int) {
|
||||
var idx = index
|
||||
dst[idx++] = (value and 0xff).toByte()
|
||||
dst[idx++] = ((value ushr 8) and 0xff).toByte()
|
||||
dst[idx++] = ((value ushr 16) and 0xff).toByte()
|
||||
dst[idx] = ((value ushr 24) and 0xff).toByte()
|
||||
}
|
||||
|
||||
private fun byteArrayToInt32(ba: ByteArray): Int {
|
||||
return ((ba[3].toInt() and 0xff) shl 24) or
|
||||
((ba[2].toInt() and 0xff) shl 16) or
|
||||
((ba[1].toInt() and 0xff) shl 8) or
|
||||
(ba[0].toInt() and 0xff)
|
||||
}
|
||||
|
||||
private fun int32ArrayToByteArray(src: IntArray, dst: ByteArray, index: Int) {
|
||||
var idx = index
|
||||
for (x in src) {
|
||||
dst[idx++] = (x and 0xff).toByte()
|
||||
dst[idx++] = ((x ushr 8) and 0xff).toByte()
|
||||
dst[idx++] = ((x ushr 16) and 0xff).toByte()
|
||||
dst[idx++] = ((x ushr 24) and 0xff).toByte()
|
||||
}
|
||||
}
|
||||
|
||||
private fun byteArrayToInt32Array(ba: ByteArray, dstLength: Int): IntArray {
|
||||
val srcLength = ba.size shr 2
|
||||
val dst = IntArray(dstLength.coerceAtMost(srcLength))
|
||||
for (i in dst.indices) {
|
||||
dst[i] = ((ba[i * 4 + 3].toInt() and 0xff) shl 24) or
|
||||
((ba[i * 4 + 2].toInt() and 0xff) shl 16) or
|
||||
((ba[i * 4 + 1].toInt() and 0xff) shl 8) or
|
||||
(ba[i * 4].toInt() and 0xff)
|
||||
}
|
||||
return dst
|
||||
}
|
||||
}
|
||||
}
|
||||
60
dolby/src/co/aospa/dolby/xiaomi/DolbyConstants.kt
Normal file
60
dolby/src/co/aospa/dolby/xiaomi/DolbyConstants.kt
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2023-24 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package co.aospa.dolby.xiaomi
|
||||
|
||||
import android.util.Log
|
||||
|
||||
class DolbyConstants {
|
||||
|
||||
enum class DsParam(val id: Int, val length: Int = 1) {
|
||||
HEADPHONE_VIRTUALIZER(101),
|
||||
SPEAKER_VIRTUALIZER(102),
|
||||
VOLUME_LEVELER_ENABLE(103),
|
||||
IEQ_PRESET(104),
|
||||
DIALOGUE_ENHANCER_ENABLE(105),
|
||||
DIALOGUE_ENHANCER_AMOUNT(108),
|
||||
GEQ_BAND_GAINS(110, 20),
|
||||
BASS_ENHANCER_ENABLE(111),
|
||||
STEREO_WIDENING_AMOUNT(113);
|
||||
|
||||
override fun toString(): String {
|
||||
return "${name}(${id})"
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG = "XiaomiDolby"
|
||||
const val PREF_ENABLE = "dolby_enable"
|
||||
const val PREF_PROFILE = "dolby_profile"
|
||||
const val PREF_PRESET = "dolby_preset"
|
||||
const val PREF_IEQ = "dolby_ieq"
|
||||
const val PREF_HP_VIRTUALIZER = "dolby_virtualizer"
|
||||
const val PREF_SPK_VIRTUALIZER = "dolby_spk_virtualizer"
|
||||
const val PREF_STEREO = "dolby_stereo"
|
||||
const val PREF_DIALOGUE = "dolby_dialogue"
|
||||
const val PREF_BASS = "dolby_bass"
|
||||
const val PREF_VOLUME = "dolby_volume"
|
||||
const val PREF_RESET = "dolby_reset"
|
||||
|
||||
val PROFILE_SPECIFIC_PREFS = setOf(
|
||||
PREF_PRESET,
|
||||
PREF_IEQ,
|
||||
PREF_HP_VIRTUALIZER,
|
||||
PREF_SPK_VIRTUALIZER,
|
||||
PREF_STEREO,
|
||||
PREF_DIALOGUE,
|
||||
PREF_BASS,
|
||||
PREF_VOLUME
|
||||
)
|
||||
|
||||
fun dlog(tag: String, msg: String) {
|
||||
if (Log.isLoggable(TAG, Log.DEBUG)) {
|
||||
Log.d(tag, msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
316
dolby/src/co/aospa/dolby/xiaomi/DolbyController.kt
Normal file
316
dolby/src/co/aospa/dolby/xiaomi/DolbyController.kt
Normal file
@@ -0,0 +1,316 @@
|
||||
/*
|
||||
* Copyright (C) 2023-24 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package co.aospa.dolby.xiaomi
|
||||
|
||||
import android.content.Context
|
||||
import android.media.AudioDeviceCallback
|
||||
import android.media.AudioDeviceInfo
|
||||
import android.media.AudioManager
|
||||
import android.media.AudioManager.AudioPlaybackCallback
|
||||
import android.media.AudioPlaybackConfiguration
|
||||
import android.os.Handler
|
||||
import android.util.Log
|
||||
import androidx.preference.PreferenceManager
|
||||
import co.aospa.dolby.xiaomi.DolbyConstants.Companion.dlog
|
||||
import co.aospa.dolby.xiaomi.DolbyConstants.DsParam
|
||||
import co.aospa.dolby.xiaomi.R
|
||||
|
||||
internal class DolbyController private constructor(
|
||||
private val context: Context
|
||||
) {
|
||||
private var dolbyEffect = DolbyAudioEffect(EFFECT_PRIORITY, audioSession = 0)
|
||||
private val audioManager = context.getSystemService(AudioManager::class.java)
|
||||
private val handler = Handler(context.mainLooper)
|
||||
|
||||
// Restore current profile on every media session
|
||||
private val playbackCallback = object : AudioPlaybackCallback() {
|
||||
override fun onPlaybackConfigChanged(configs: List<AudioPlaybackConfiguration>) {
|
||||
val isPlaying = configs.any {
|
||||
it.playerState == AudioPlaybackConfiguration.PLAYER_STATE_STARTED
|
||||
}
|
||||
dlog(TAG, "onPlaybackConfigChanged: isPlaying=$isPlaying")
|
||||
if (isPlaying)
|
||||
setCurrentProfile()
|
||||
}
|
||||
}
|
||||
|
||||
// Restore current profile on audio device change
|
||||
private val audioDeviceCallback = object : AudioDeviceCallback() {
|
||||
override fun onAudioDevicesAdded(addedDevices: Array<AudioDeviceInfo>) {
|
||||
dlog(TAG, "onAudioDevicesAdded")
|
||||
setCurrentProfile()
|
||||
}
|
||||
|
||||
override fun onAudioDevicesRemoved(removedDevices: Array<AudioDeviceInfo>) {
|
||||
dlog(TAG, "onAudioDevicesRemoved")
|
||||
setCurrentProfile()
|
||||
}
|
||||
}
|
||||
|
||||
private var registerCallbacks = false
|
||||
set(value) {
|
||||
if (field == value) return
|
||||
field = value
|
||||
dlog(TAG, "setRegisterCallbacks($value)")
|
||||
if (value) {
|
||||
audioManager!!.registerAudioPlaybackCallback(playbackCallback, handler)
|
||||
audioManager.registerAudioDeviceCallback(audioDeviceCallback, handler)
|
||||
} else {
|
||||
audioManager!!.unregisterAudioPlaybackCallback(playbackCallback)
|
||||
audioManager.unregisterAudioDeviceCallback(audioDeviceCallback)
|
||||
}
|
||||
}
|
||||
|
||||
var dsOn: Boolean
|
||||
get() =
|
||||
dolbyEffect.dsOn.also {
|
||||
dlog(TAG, "getDsOn: $it")
|
||||
}
|
||||
set(value) {
|
||||
dlog(TAG, "setDsOn: $value")
|
||||
checkEffect()
|
||||
dolbyEffect.dsOn = value
|
||||
registerCallbacks = value
|
||||
if (value)
|
||||
setCurrentProfile()
|
||||
}
|
||||
|
||||
var profile: Int
|
||||
get() =
|
||||
dolbyEffect.profile.also {
|
||||
dlog(TAG, "getProfile: $it")
|
||||
}
|
||||
set(value) {
|
||||
dlog(TAG, "setProfile: $value")
|
||||
checkEffect()
|
||||
dolbyEffect.profile = value
|
||||
}
|
||||
|
||||
init {
|
||||
dlog(TAG, "initialized")
|
||||
}
|
||||
|
||||
fun onBootCompleted() {
|
||||
dlog(TAG, "onBootCompleted")
|
||||
|
||||
// Restore our main settings
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
dsOn = prefs.getBoolean(DolbyConstants.PREF_ENABLE, true)
|
||||
|
||||
context.resources.getStringArray(R.array.dolby_profile_values)
|
||||
.map { it.toInt() }
|
||||
.forEach { profile ->
|
||||
// Reset dolby first to prevent it from loading bad settings
|
||||
dolbyEffect.resetProfileSpecificSettings(profile)
|
||||
// Now restore our profile-specific settings
|
||||
restoreSettings(profile)
|
||||
}
|
||||
|
||||
// Finally restore the current profile.
|
||||
setCurrentProfile()
|
||||
}
|
||||
|
||||
private fun restoreSettings(profile: Int) {
|
||||
dlog(TAG, "restoreSettings(profile=$profile)")
|
||||
val prefs = context.getSharedPreferences("profile_$profile", Context.MODE_PRIVATE)
|
||||
setPreset(
|
||||
prefs.getString(DolbyConstants.PREF_PRESET, getPreset(profile))!!,
|
||||
profile
|
||||
)
|
||||
setIeqPreset(
|
||||
prefs.getString(
|
||||
DolbyConstants.PREF_IEQ,
|
||||
getIeqPreset(profile).toString()
|
||||
)!!.toInt(),
|
||||
profile
|
||||
)
|
||||
setHeadphoneVirtEnabled(
|
||||
prefs.getBoolean(DolbyConstants.PREF_HP_VIRTUALIZER, getHeadphoneVirtEnabled(profile)),
|
||||
profile
|
||||
)
|
||||
setSpeakerVirtEnabled(
|
||||
prefs.getBoolean(DolbyConstants.PREF_SPK_VIRTUALIZER, getSpeakerVirtEnabled(profile)),
|
||||
profile
|
||||
)
|
||||
setStereoWideningAmount(
|
||||
prefs.getString(
|
||||
DolbyConstants.PREF_STEREO,
|
||||
getStereoWideningAmount(profile).toString()
|
||||
)!!.toInt(),
|
||||
profile
|
||||
)
|
||||
setDialogueEnhancerAmount(
|
||||
prefs.getString(
|
||||
DolbyConstants.PREF_DIALOGUE,
|
||||
getDialogueEnhancerAmount(profile).toString()
|
||||
)!!.toInt(),
|
||||
profile
|
||||
)
|
||||
setBassEnhancerEnabled(
|
||||
prefs.getBoolean(DolbyConstants.PREF_BASS, getBassEnhancerEnabled(profile)),
|
||||
profile
|
||||
)
|
||||
setVolumeLevelerEnabled(
|
||||
prefs.getBoolean(DolbyConstants.PREF_VOLUME, getVolumeLevelerEnabled(profile)),
|
||||
profile
|
||||
)
|
||||
}
|
||||
|
||||
private fun checkEffect() {
|
||||
if (!dolbyEffect.hasControl()) {
|
||||
Log.w(TAG, "lost control, recreating effect")
|
||||
dolbyEffect.release()
|
||||
dolbyEffect = DolbyAudioEffect(EFFECT_PRIORITY, audioSession = 0)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setCurrentProfile() {
|
||||
dlog(TAG, "setCurrentProfile")
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
profile = prefs.getString(DolbyConstants.PREF_PROFILE, "0" /*dynamic*/)!!.toInt()
|
||||
}
|
||||
|
||||
fun getProfileName(): String? {
|
||||
val profile = dolbyEffect.profile.toString()
|
||||
val profiles = context.resources.getStringArray(R.array.dolby_profile_values)
|
||||
val profileIndex = profiles.indexOf(profile)
|
||||
dlog(TAG, "getProfileName: profile=$profile index=$profileIndex")
|
||||
return if (profileIndex == -1) null else context.resources.getStringArray(
|
||||
R.array.dolby_profile_entries
|
||||
)[profileIndex]
|
||||
}
|
||||
|
||||
fun resetProfileSpecificSettings() {
|
||||
dlog(TAG, "resetProfileSpecificSettings")
|
||||
checkEffect()
|
||||
dolbyEffect.resetProfileSpecificSettings()
|
||||
context.deleteSharedPreferences("profile_$profile")
|
||||
}
|
||||
|
||||
fun getPreset(profile: Int = this.profile): String {
|
||||
val gains = dolbyEffect.getDapParameter(DsParam.GEQ_BAND_GAINS, profile)
|
||||
return gains.joinToString(separator = ",").also {
|
||||
dlog(TAG, "getPreset: $it")
|
||||
}
|
||||
}
|
||||
|
||||
fun setPreset(value: String, profile: Int = this.profile) {
|
||||
dlog(TAG, "setPreset: $value")
|
||||
checkEffect()
|
||||
val gains = value.split(",")
|
||||
.map { it.toInt() }
|
||||
.toIntArray()
|
||||
dolbyEffect.setDapParameter(DsParam.GEQ_BAND_GAINS, gains, profile)
|
||||
}
|
||||
|
||||
fun getPresetName(): String {
|
||||
val presets = context.resources.getStringArray(R.array.dolby_preset_values)
|
||||
val presetIndex = presets.indexOf(getPreset())
|
||||
return if (presetIndex == -1) {
|
||||
"Custom"
|
||||
} else {
|
||||
context.resources.getStringArray(
|
||||
R.array.dolby_preset_entries
|
||||
)[presetIndex]
|
||||
}
|
||||
}
|
||||
|
||||
fun getHeadphoneVirtEnabled(profile: Int = this.profile) =
|
||||
dolbyEffect.getDapParameterBool(DsParam.HEADPHONE_VIRTUALIZER, profile).also {
|
||||
dlog(TAG, "getHeadphoneVirtEnabled: $it")
|
||||
}
|
||||
|
||||
fun setHeadphoneVirtEnabled(value: Boolean, profile: Int = this.profile) {
|
||||
dlog(TAG, "setHeadphoneVirtEnabled: $value")
|
||||
checkEffect()
|
||||
dolbyEffect.setDapParameter(DsParam.HEADPHONE_VIRTUALIZER, value, profile)
|
||||
}
|
||||
|
||||
fun getSpeakerVirtEnabled(profile: Int = this.profile) =
|
||||
dolbyEffect.getDapParameterBool(DsParam.SPEAKER_VIRTUALIZER, profile).also {
|
||||
dlog(TAG, "getSpeakerVirtEnabled: $it")
|
||||
}
|
||||
|
||||
fun setSpeakerVirtEnabled(value: Boolean, profile: Int = this.profile) {
|
||||
dlog(TAG, "setSpeakerVirtEnabled: $value")
|
||||
checkEffect()
|
||||
dolbyEffect.setDapParameter(DsParam.SPEAKER_VIRTUALIZER, value, profile)
|
||||
}
|
||||
|
||||
fun getBassEnhancerEnabled(profile: Int = this.profile) =
|
||||
dolbyEffect.getDapParameterBool(DsParam.BASS_ENHANCER_ENABLE, profile).also {
|
||||
dlog(TAG, "getBassEnhancerEnabled: $it")
|
||||
}
|
||||
|
||||
fun setBassEnhancerEnabled(value: Boolean, profile: Int = this.profile) {
|
||||
dlog(TAG, "setBassEnhancerEnabled: $value")
|
||||
checkEffect()
|
||||
dolbyEffect.setDapParameter(DsParam.BASS_ENHANCER_ENABLE, value, profile)
|
||||
}
|
||||
|
||||
fun getVolumeLevelerEnabled(profile: Int = this.profile) =
|
||||
dolbyEffect.getDapParameterBool(DsParam.VOLUME_LEVELER_ENABLE, profile).also {
|
||||
dlog(TAG, "getVolumeLevelerEnabled: $it")
|
||||
}
|
||||
|
||||
fun setVolumeLevelerEnabled(value: Boolean, profile: Int = this.profile) {
|
||||
dlog(TAG, "setVolumeLevelerEnabled: $value")
|
||||
checkEffect()
|
||||
dolbyEffect.setDapParameter(DsParam.VOLUME_LEVELER_ENABLE, value, profile)
|
||||
}
|
||||
|
||||
fun getStereoWideningAmount(profile: Int = this.profile) =
|
||||
dolbyEffect.getDapParameterInt(DsParam.STEREO_WIDENING_AMOUNT, profile).also {
|
||||
dlog(TAG, "getStereoWideningAmount: $it")
|
||||
}
|
||||
|
||||
fun setStereoWideningAmount(value: Int, profile: Int = this.profile) {
|
||||
dlog(TAG, "setStereoWideningAmount: $value")
|
||||
checkEffect()
|
||||
dolbyEffect.setDapParameter(DsParam.STEREO_WIDENING_AMOUNT, value, profile)
|
||||
}
|
||||
|
||||
fun getDialogueEnhancerAmount(profile: Int = this.profile): Int {
|
||||
val enabled = dolbyEffect.getDapParameterBool(DsParam.DIALOGUE_ENHANCER_ENABLE, profile)
|
||||
val amount = if (enabled) {
|
||||
dolbyEffect.getDapParameterInt(DsParam.DIALOGUE_ENHANCER_AMOUNT, profile)
|
||||
} else 0
|
||||
dlog(TAG, "getDialogueEnhancerAmount: enabled=$enabled amount=$amount")
|
||||
return amount
|
||||
}
|
||||
|
||||
fun setDialogueEnhancerAmount(value: Int, profile: Int = this.profile) {
|
||||
dlog(TAG, "setDialogueEnhancerAmount: $value")
|
||||
checkEffect()
|
||||
dolbyEffect.setDapParameter(DsParam.DIALOGUE_ENHANCER_ENABLE, (value > 0), profile)
|
||||
dolbyEffect.setDapParameter(DsParam.DIALOGUE_ENHANCER_AMOUNT, value, profile)
|
||||
}
|
||||
|
||||
fun getIeqPreset(profile: Int = this.profile) =
|
||||
dolbyEffect.getDapParameterInt(DsParam.IEQ_PRESET, profile).also {
|
||||
dlog(TAG, "getIeqPreset: $it")
|
||||
}
|
||||
|
||||
fun setIeqPreset(value: Int, profile: Int = this.profile) {
|
||||
dlog(TAG, "setIeqPreset: $value")
|
||||
checkEffect()
|
||||
dolbyEffect.setDapParameter(DsParam.IEQ_PRESET, value, profile)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "DolbyController"
|
||||
private const val EFFECT_PRIORITY = 100
|
||||
|
||||
@Volatile
|
||||
private var instance: DolbyController? = null
|
||||
|
||||
fun getInstance(context: Context) =
|
||||
instance ?: synchronized(this) {
|
||||
instance ?: DolbyController(context).also { instance = it }
|
||||
}
|
||||
}
|
||||
}
|
||||
36
dolby/src/co/aospa/dolby/xiaomi/DolbyTileService.kt
Normal file
36
dolby/src/co/aospa/dolby/xiaomi/DolbyTileService.kt
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2023-24 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package co.aospa.dolby.xiaomi
|
||||
|
||||
import android.service.quicksettings.Tile
|
||||
import android.service.quicksettings.TileService
|
||||
|
||||
private const val TAG = "DolbyTileService"
|
||||
|
||||
class DolbyTileService : TileService() {
|
||||
|
||||
private val dolbyController by lazy { DolbyController.getInstance(applicationContext) }
|
||||
|
||||
override fun onStartListening() {
|
||||
qsTile.apply {
|
||||
state = if (dolbyController.dsOn) Tile.STATE_ACTIVE else Tile.STATE_INACTIVE
|
||||
subtitle = dolbyController.getProfileName() ?: getString(R.string.dolby_unknown)
|
||||
updateTile()
|
||||
}
|
||||
super.onStartListening()
|
||||
}
|
||||
|
||||
override fun onClick() {
|
||||
val isDsOn = dolbyController.dsOn
|
||||
dolbyController.dsOn = !isDsOn
|
||||
qsTile.apply {
|
||||
state = if (isDsOn) Tile.STATE_INACTIVE else Tile.STATE_ACTIVE
|
||||
updateTile()
|
||||
}
|
||||
super.onClick()
|
||||
}
|
||||
}
|
||||
70
dolby/src/co/aospa/dolby/xiaomi/SummaryProvider.kt
Normal file
70
dolby/src/co/aospa/dolby/xiaomi/SummaryProvider.kt
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
* (C) 2023-24 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package co.aospa.dolby.xiaomi
|
||||
|
||||
import android.content.ContentProvider
|
||||
import android.content.ContentValues
|
||||
import android.database.Cursor
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import co.aospa.dolby.xiaomi.R
|
||||
import com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_SUMMARY
|
||||
|
||||
private const val KEY_DOLBY = "dolby"
|
||||
|
||||
/** Provide preference summary for injected items. */
|
||||
class SummaryProvider : ContentProvider() {
|
||||
|
||||
override fun call(
|
||||
method: String,
|
||||
arg: String?,
|
||||
extras: Bundle?
|
||||
): Bundle? {
|
||||
val summary = when (method) {
|
||||
KEY_DOLBY -> getDolbySummary()
|
||||
else -> return null
|
||||
}
|
||||
return Bundle().apply {
|
||||
putString(META_DATA_PREFERENCE_SUMMARY, summary)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(): Boolean = true
|
||||
|
||||
override fun query(
|
||||
uri: Uri,
|
||||
projection: Array<String>?,
|
||||
selection: String?,
|
||||
selectionArgs: Array<String>?,
|
||||
sortOrder: String?
|
||||
): Cursor? = null
|
||||
|
||||
override fun getType(uri: Uri): String? = null
|
||||
|
||||
override fun insert(uri: Uri, values: ContentValues?): Uri? = null
|
||||
|
||||
override fun delete(uri: Uri, selection: String?, selectionArgs: Array<String>?): Int = 0
|
||||
|
||||
override fun update(
|
||||
uri: Uri,
|
||||
values: ContentValues?,
|
||||
selection: String?,
|
||||
selectionArgs: Array<String>?
|
||||
): Int = 0
|
||||
|
||||
private fun getDolbySummary(): String {
|
||||
val dolbyController = DolbyController.getInstance(context!!)
|
||||
if (!dolbyController.dsOn) {
|
||||
return context!!.getString(R.string.dolby_off)
|
||||
}
|
||||
return dolbyController.getProfileName()?.let {
|
||||
context!!.getString(R.string.dolby_on_with_profile, it)
|
||||
} ?: context!!.getString(R.string.dolby_on)
|
||||
}
|
||||
|
||||
}
|
||||
53
dolby/src/co/aospa/dolby/xiaomi/geq/EqualizerActivity.kt
Normal file
53
dolby/src/co/aospa/dolby/xiaomi/geq/EqualizerActivity.kt
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package co.aospa.dolby.xiaomi.geq
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.viewModels
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import co.aospa.dolby.xiaomi.R
|
||||
import co.aospa.dolby.xiaomi.geq.ui.EqualizerScreen
|
||||
import co.aospa.dolby.xiaomi.geq.ui.EqualizerViewModel
|
||||
import com.android.settingslib.spa.framework.compose.localNavController
|
||||
import com.android.settingslib.spa.framework.theme.SettingsTheme
|
||||
import com.android.settingslib.spa.widget.scaffold.SettingsScaffold
|
||||
|
||||
class EqualizerActivity : ComponentActivity() {
|
||||
|
||||
private val viewModel: EqualizerViewModel by viewModels { EqualizerViewModel.Factory }
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContent {
|
||||
SettingsTheme {
|
||||
MainContent()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun MainContent() {
|
||||
val navController = rememberNavController()
|
||||
CompositionLocalProvider(navController.localNavController()) {
|
||||
SettingsScaffold(
|
||||
title = stringResource(id = R.string.dolby_preset)
|
||||
) { paddingValues ->
|
||||
EqualizerScreen(
|
||||
viewModel = viewModel,
|
||||
modifier = Modifier.padding(paddingValues)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
dolby/src/co/aospa/dolby/xiaomi/geq/data/BandGain.kt
Normal file
12
dolby/src/co/aospa/dolby/xiaomi/geq/data/BandGain.kt
Normal file
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package co.aospa.dolby.xiaomi.geq.data
|
||||
|
||||
data class BandGain(
|
||||
val band: Int,
|
||||
var gain: Int = 0
|
||||
)
|
||||
183
dolby/src/co/aospa/dolby/xiaomi/geq/data/EqualizerRepository.kt
Normal file
183
dolby/src/co/aospa/dolby/xiaomi/geq/data/EqualizerRepository.kt
Normal file
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package co.aospa.dolby.xiaomi.geq.data
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.util.Log
|
||||
import co.aospa.dolby.xiaomi.DolbyConstants.Companion.PREF_PRESET
|
||||
import co.aospa.dolby.xiaomi.DolbyConstants.Companion.dlog
|
||||
import co.aospa.dolby.xiaomi.DolbyController
|
||||
import co.aospa.dolby.xiaomi.R
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class EqualizerRepository(
|
||||
private val context: Context
|
||||
) {
|
||||
|
||||
private val dolbyController by lazy { DolbyController.getInstance(context) }
|
||||
|
||||
// Preset is saved as a string of comma separated gains in SharedPreferences
|
||||
// and is unique to each profile ID
|
||||
private val profile = dolbyController.profile
|
||||
private val profileSharedPrefs by lazy {
|
||||
context.getSharedPreferences(
|
||||
"profile_$profile",
|
||||
Context.MODE_PRIVATE
|
||||
)
|
||||
}
|
||||
|
||||
private val presetsSharedPrefs by lazy {
|
||||
context.getSharedPreferences(
|
||||
"presets",
|
||||
Context.MODE_PRIVATE
|
||||
)
|
||||
}
|
||||
|
||||
val builtInPresets: List<Preset> by lazy {
|
||||
val names = context.resources.getStringArray(
|
||||
R.array.dolby_preset_entries
|
||||
)
|
||||
val presets = context.resources.getStringArray(
|
||||
R.array.dolby_preset_values
|
||||
)
|
||||
List(names.size) { index ->
|
||||
Preset(
|
||||
name = names[index],
|
||||
bandGains = deserializeGains(presets[index]),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val defaultPreset by lazy { builtInPresets[0] } // Flat
|
||||
|
||||
// User defined presets are stored in a SharedPreferences as
|
||||
// key - preset name
|
||||
// value - comma separated string of gains
|
||||
val userPresets: Flow<List<Preset>> = callbackFlow {
|
||||
val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, _ ->
|
||||
dlog(TAG, "presetsSharedPrefs changed")
|
||||
trySend(
|
||||
presetsSharedPrefs.all.map { (key, value) ->
|
||||
Preset(
|
||||
name = key,
|
||||
bandGains = deserializeGains(value.toString()),
|
||||
isUserDefined = true
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
presetsSharedPrefs.registerOnSharedPreferenceChangeListener(listener)
|
||||
dlog(TAG, "presetsSharedPrefs registered listener")
|
||||
// trigger an initial emission
|
||||
listener.onSharedPreferenceChanged(presetsSharedPrefs, null)
|
||||
|
||||
awaitClose {
|
||||
presetsSharedPrefs.unregisterOnSharedPreferenceChangeListener(listener)
|
||||
dlog(TAG, "presetsSharedPrefs unregistered listener")
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getBandGains(): List<BandGain> = withContext(Dispatchers.IO) {
|
||||
val gains = profileSharedPrefs.getString(PREF_PRESET, dolbyController.getPreset())
|
||||
return@withContext if (gains.isNullOrEmpty()) {
|
||||
defaultPreset.bandGains
|
||||
} else {
|
||||
deserializeGains(gains)
|
||||
}.also {
|
||||
dlog(TAG, "getBandGains: $it")
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun setBandGains(bandGains: List<BandGain>) = withContext(Dispatchers.IO) {
|
||||
dlog(TAG, "setBandGains($bandGains)")
|
||||
val gains = serializeGains(bandGains)
|
||||
dolbyController.setPreset(gains)
|
||||
profileSharedPrefs.edit()
|
||||
.putString(PREF_PRESET, gains)
|
||||
.apply()
|
||||
}
|
||||
|
||||
suspend fun addPreset(preset: Preset) = withContext(Dispatchers.IO) {
|
||||
dlog(TAG, "addPreset($preset)")
|
||||
presetsSharedPrefs.edit()
|
||||
.putString(preset.name, serializeGains(preset.bandGains))
|
||||
.apply()
|
||||
}
|
||||
|
||||
suspend fun removePreset(preset: Preset) = withContext(Dispatchers.IO) {
|
||||
dlog(TAG, "removePreset($preset)")
|
||||
presetsSharedPrefs.edit()
|
||||
.remove(preset.name)
|
||||
.apply()
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val TAG = "EqRepository"
|
||||
|
||||
val tenBandFreqs = intArrayOf(
|
||||
32,
|
||||
64,
|
||||
125,
|
||||
250,
|
||||
500,
|
||||
1000,
|
||||
2000,
|
||||
4000,
|
||||
8000,
|
||||
16000
|
||||
)
|
||||
|
||||
fun deserializeGains(bandGains: String): List<BandGain> {
|
||||
val gains: List<Int> =
|
||||
bandGains.split(",").runCatching {
|
||||
require(size == 20) {
|
||||
"Preset must have 20 elements, has only $size!"
|
||||
}
|
||||
map { it.toInt() }
|
||||
.twentyToTenBandGains()
|
||||
}.onFailure { exception ->
|
||||
Log.e(TAG, "Failed to parse preset", exception)
|
||||
}.getOrDefault(
|
||||
// fallback to flat
|
||||
List<Int>(10) { 0 }
|
||||
)
|
||||
return List(10) { index ->
|
||||
BandGain(
|
||||
band = tenBandFreqs[index],
|
||||
gain = gains[index]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun serializeGains(bandGains: List<BandGain>): String {
|
||||
return bandGains.map { it.gain }
|
||||
.tenToTwentyBandGains()
|
||||
.joinToString(",")
|
||||
}
|
||||
|
||||
// we show only 10 bands in UI however backend requires 20 bands
|
||||
fun List<Int>.tenToTwentyBandGains() =
|
||||
List<Int>(20) { index ->
|
||||
if (index % 2 == 1 && index < 19) {
|
||||
// every odd element is the average of its surrounding elements
|
||||
(this[(index - 1) / 2] + this[(index + 1) / 2]) / 2
|
||||
} else {
|
||||
this[index / 2]
|
||||
}
|
||||
}
|
||||
|
||||
fun List<Int>.twentyToTenBandGains() =
|
||||
// skip every odd element
|
||||
filterIndexed { index, _ -> index % 2 == 0 }
|
||||
}
|
||||
}
|
||||
14
dolby/src/co/aospa/dolby/xiaomi/geq/data/Preset.kt
Normal file
14
dolby/src/co/aospa/dolby/xiaomi/geq/data/Preset.kt
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package co.aospa.dolby.xiaomi.geq.data
|
||||
|
||||
data class Preset(
|
||||
var name: String,
|
||||
val bandGains: List<BandGain>,
|
||||
var isUserDefined: Boolean = false,
|
||||
var isMutated: Boolean = false
|
||||
)
|
||||
101
dolby/src/co/aospa/dolby/xiaomi/geq/ui/BandGainSlider.kt
Normal file
101
dolby/src/co/aospa/dolby/xiaomi/geq/ui/BandGainSlider.kt
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package co.aospa.dolby.xiaomi.geq.ui
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.material3.Slider
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.TransformOrigin
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.layout.layout
|
||||
import androidx.compose.ui.unit.Constraints
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import co.aospa.dolby.xiaomi.geq.data.BandGain
|
||||
|
||||
@Composable
|
||||
fun BandGainSlider(
|
||||
bandGain: BandGain,
|
||||
onValueChangeFinished: (Int) -> Unit
|
||||
) {
|
||||
// Gain range is of -1->1 in UI, -100->100 in backend, but actually is -10->10 dB.
|
||||
|
||||
// Ensure we update the slider when gain is changed,
|
||||
// for eg. when changing the preset
|
||||
var sliderPosition by remember(bandGain.gain) {
|
||||
mutableFloatStateOf(bandGain.gain / 100f)
|
||||
}
|
||||
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
SliderText(
|
||||
"%.1f".format(sliderPosition * 10f)
|
||||
)
|
||||
Slider(
|
||||
value = sliderPosition,
|
||||
onValueChange = { sliderPosition = it },
|
||||
onValueChangeFinished = {
|
||||
onValueChangeFinished((sliderPosition * 100f).toInt())
|
||||
},
|
||||
valueRange = -1f..1f,
|
||||
modifier = Modifier
|
||||
.graphicsLayer {
|
||||
rotationZ = 270f
|
||||
transformOrigin = TransformOrigin(0f, 0f)
|
||||
}
|
||||
.layout { measurable, constraints ->
|
||||
val placeable = measurable.measure(
|
||||
Constraints(
|
||||
minWidth = constraints.minHeight,
|
||||
maxWidth = constraints.maxHeight,
|
||||
minHeight = constraints.minWidth,
|
||||
maxHeight = constraints.maxHeight,
|
||||
)
|
||||
)
|
||||
layout(placeable.height, placeable.width) {
|
||||
placeable.place(-placeable.width, 0)
|
||||
}
|
||||
}
|
||||
// horizontal and vertical dimensions are inverted due to rotation
|
||||
.width(200.dp)
|
||||
.height(40.dp)
|
||||
.padding(8.dp)
|
||||
)
|
||||
SliderText(
|
||||
with(bandGain.band) {
|
||||
if (this >= 1000) {
|
||||
"${this / 1000}k"
|
||||
} else {
|
||||
"$this"
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SliderText(
|
||||
text: String,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Text(
|
||||
text = text,
|
||||
modifier = modifier,
|
||||
fontSize = 12.sp
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package co.aospa.dolby.xiaomi.geq.ui
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import co.aospa.dolby.xiaomi.R
|
||||
|
||||
@Composable
|
||||
fun BandGainSliderLabels() {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.End,
|
||||
modifier = Modifier.padding(end = 8.dp)
|
||||
) {
|
||||
LabelText(
|
||||
stringResource(id = R.string.dolby_geq_slider_label_gain)
|
||||
)
|
||||
Column(
|
||||
modifier = Modifier.height(200.dp),
|
||||
horizontalAlignment = Alignment.End
|
||||
) {
|
||||
LabelText(
|
||||
"+10 dB",
|
||||
modifier = Modifier.padding(
|
||||
top = 10.dp
|
||||
)
|
||||
)
|
||||
Spacer(
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
LabelText("0 dB")
|
||||
Spacer(
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
LabelText(
|
||||
"-10 dB",
|
||||
modifier = Modifier.padding(
|
||||
bottom = 10.dp
|
||||
)
|
||||
)
|
||||
}
|
||||
LabelText("Hz")
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun LabelText(
|
||||
text: String,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Text(
|
||||
text = text,
|
||||
modifier = modifier,
|
||||
color = MaterialTheme.colorScheme.secondary,
|
||||
fontSize = 12.sp
|
||||
)
|
||||
}
|
||||
58
dolby/src/co/aospa/dolby/xiaomi/geq/ui/ConfirmationDialog.kt
Normal file
58
dolby/src/co/aospa/dolby/xiaomi/geq/ui/ConfirmationDialog.kt
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package co.aospa.dolby.xiaomi.geq.ui
|
||||
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.res.stringResource
|
||||
|
||||
@Composable
|
||||
fun ConfirmationDialog(
|
||||
text: String,
|
||||
onConfirm: () -> Unit,
|
||||
onDismiss: () -> Unit
|
||||
) {
|
||||
var showDialog by remember { mutableStateOf(true) }
|
||||
if (!showDialog) {
|
||||
onDismiss()
|
||||
return
|
||||
}
|
||||
|
||||
AlertDialog(
|
||||
onDismissRequest = { showDialog = false },
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
showDialog = false
|
||||
onConfirm()
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
stringResource(id = android.R.string.ok)
|
||||
)
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(
|
||||
onClick = { showDialog = false }
|
||||
) {
|
||||
Text(
|
||||
stringResource(id = android.R.string.cancel)
|
||||
)
|
||||
}
|
||||
},
|
||||
text = {
|
||||
Text(text)
|
||||
}
|
||||
)
|
||||
}
|
||||
39
dolby/src/co/aospa/dolby/xiaomi/geq/ui/EqualizerBands.kt
Normal file
39
dolby/src/co/aospa/dolby/xiaomi/geq/ui/EqualizerBands.kt
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package co.aospa.dolby.xiaomi.geq.ui
|
||||
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.lazy.LazyRow
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
|
||||
@Composable
|
||||
fun EqualizerBands(viewModel: EqualizerViewModel) {
|
||||
val preset by viewModel.preset.collectAsState()
|
||||
val bandGains = preset.bandGains
|
||||
|
||||
LazyRow(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
item {
|
||||
BandGainSliderLabels()
|
||||
}
|
||||
items(bandGains.size) { index ->
|
||||
BandGainSlider(
|
||||
bandGains[index],
|
||||
onValueChangeFinished = {
|
||||
viewModel.setGain(index, it)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
42
dolby/src/co/aospa/dolby/xiaomi/geq/ui/EqualizerScreen.kt
Normal file
42
dolby/src/co/aospa/dolby/xiaomi/geq/ui/EqualizerScreen.kt
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package co.aospa.dolby.xiaomi.geq.ui
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.android.settingslib.spa.framework.theme.settingsBackground
|
||||
import com.android.settingslib.spa.framework.theme.SettingsDimension
|
||||
|
||||
@Composable
|
||||
fun EqualizerScreen(
|
||||
viewModel: EqualizerViewModel,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Surface(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(SettingsDimension.itemPadding)
|
||||
.then(modifier),
|
||||
color = MaterialTheme.colorScheme.settingsBackground
|
||||
) {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.Top,
|
||||
modifier = Modifier.fillMaxHeight()
|
||||
) {
|
||||
PresetSelector(viewModel = viewModel)
|
||||
EqualizerBands(viewModel = viewModel)
|
||||
}
|
||||
}
|
||||
}
|
||||
175
dolby/src/co/aospa/dolby/xiaomi/geq/ui/EqualizerViewModel.kt
Normal file
175
dolby/src/co/aospa/dolby/xiaomi/geq/ui/EqualizerViewModel.kt
Normal file
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package co.aospa.dolby.xiaomi.geq.ui
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.lifecycle.viewmodel.initializer
|
||||
import androidx.lifecycle.viewmodel.viewModelFactory
|
||||
import co.aospa.dolby.xiaomi.geq.data.EqualizerRepository
|
||||
import co.aospa.dolby.xiaomi.geq.data.Preset
|
||||
import co.aospa.dolby.xiaomi.DolbyConstants.Companion.dlog
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
const val TAG = "EqViewModel"
|
||||
|
||||
class EqualizerViewModel(
|
||||
private val repository: EqualizerRepository
|
||||
) : ViewModel() {
|
||||
|
||||
private val _presets = MutableStateFlow(repository.builtInPresets)
|
||||
val presets = _presets.asStateFlow()
|
||||
|
||||
private val _preset = MutableStateFlow(repository.defaultPreset)
|
||||
val preset = _preset.asStateFlow()
|
||||
|
||||
private var presetRestored = false
|
||||
|
||||
init {
|
||||
// Update the list of presets: combined list of user defined presets if any,
|
||||
// and then the built in presets.
|
||||
repository.userPresets
|
||||
.onEach { presets ->
|
||||
dlog(TAG, "updated userPresets: $presets")
|
||||
_presets.value = mutableListOf<Preset>().apply {
|
||||
addAll(presets)
|
||||
addAll(repository.builtInPresets)
|
||||
}.toList()
|
||||
|
||||
// We can restore the active preset only after the presets list is populated,
|
||||
// since we do not save the preset name but only its gains.
|
||||
if (!presetRestored) {
|
||||
val bandGains = repository.getBandGains()
|
||||
_preset.value = _presets.value.find {
|
||||
bandGains == it.bandGains
|
||||
} ?: Preset(
|
||||
name = "Custom",
|
||||
bandGains = bandGains
|
||||
)
|
||||
dlog(TAG, "restored preset: ${_preset.value}")
|
||||
presetRestored = true
|
||||
}
|
||||
}
|
||||
.launchIn(viewModelScope)
|
||||
|
||||
// Update the preset in repository everytime we set it here
|
||||
_preset
|
||||
.drop(1) // skip the initial value
|
||||
.onEach {
|
||||
// wait till the active preset is restored
|
||||
if (!presetRestored) {
|
||||
return@onEach
|
||||
}
|
||||
dlog(TAG, "updated preset: $it")
|
||||
repository.setBandGains(it.bandGains)
|
||||
if (it.isUserDefined) {
|
||||
repository.addPreset(it)
|
||||
}
|
||||
}
|
||||
.launchIn(viewModelScope)
|
||||
}
|
||||
|
||||
fun reset() {
|
||||
dlog(TAG, "reset()")
|
||||
if (_preset.value.isUserDefined) {
|
||||
// Reset gains to 0
|
||||
_preset.value = _preset.value.copy(
|
||||
bandGains = repository.defaultPreset.bandGains
|
||||
)
|
||||
} else {
|
||||
// Switch to flat preset
|
||||
_preset.value = repository.defaultPreset
|
||||
}
|
||||
}
|
||||
|
||||
fun setPreset(preset: Preset) {
|
||||
dlog(TAG, "setPreset($preset)")
|
||||
_preset.value = preset
|
||||
}
|
||||
|
||||
fun setGain(index: Int, gain: Int) {
|
||||
dlog(TAG, "setGain($index, $gain)")
|
||||
_preset.value = _preset.value.run {
|
||||
copy(
|
||||
name = if (!isUserDefined) "Custom" else name,
|
||||
bandGains = bandGains
|
||||
.toMutableList()
|
||||
// create a new object to ensure the flow emits an update.
|
||||
.apply { this[index] = this[index].copy(gain = gain) }
|
||||
.toList(),
|
||||
isMutated = true
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Returns string containing the error message if it failed, otherwise null
|
||||
private fun validatePresetName(name: String): PresetNameValidationError? {
|
||||
// Ensure we don't have another preset with the same name
|
||||
return if (
|
||||
_presets.value
|
||||
.any { it.name.equals(name.trim(), ignoreCase = true) }
|
||||
) {
|
||||
PresetNameValidationError.NAME_EXISTS
|
||||
} else if (name.length > 50) {
|
||||
PresetNameValidationError.NAME_TOO_LONG
|
||||
} else null
|
||||
}
|
||||
|
||||
fun createNewPreset(name: String): PresetNameValidationError? {
|
||||
dlog(TAG, "createNewPreset($name)")
|
||||
validatePresetName(name)?.let {
|
||||
dlog(TAG, "createNewPreset failed: $it")
|
||||
return it
|
||||
}
|
||||
_preset.value = _preset.value.copy(
|
||||
name = name.trim(),
|
||||
isUserDefined = true,
|
||||
isMutated = false
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
fun renamePreset(preset: Preset, name: String): PresetNameValidationError? {
|
||||
dlog(TAG, "renamePreset($preset, $name)")
|
||||
// create a preset with the new name and same gains
|
||||
createNewPreset(name = name)?.let {
|
||||
dlog(TAG, "renamePreset failed")
|
||||
return it
|
||||
}
|
||||
// and delete the old one.
|
||||
deletePreset(preset, shouldReset = false)
|
||||
return null
|
||||
}
|
||||
|
||||
fun deletePreset(preset: Preset, shouldReset: Boolean = true) {
|
||||
dlog(TAG, "deletePreset($preset)")
|
||||
viewModelScope.launch {
|
||||
repository.removePreset(preset)
|
||||
}
|
||||
if (shouldReset) {
|
||||
_preset.value = repository.defaultPreset
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val Factory = viewModelFactory {
|
||||
initializer {
|
||||
EqualizerViewModel(
|
||||
repository = EqualizerRepository(
|
||||
this[ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY]!!
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
94
dolby/src/co/aospa/dolby/xiaomi/geq/ui/PresetNameDialog.kt
Normal file
94
dolby/src/co/aospa/dolby/xiaomi/geq/ui/PresetNameDialog.kt
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package co.aospa.dolby.xiaomi.geq.ui
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import co.aospa.dolby.xiaomi.R
|
||||
|
||||
@Composable
|
||||
fun PresetNameDialog(
|
||||
title: String,
|
||||
presetName: String = "",
|
||||
onPresetNameSet: (String) -> PresetNameValidationError?,
|
||||
onDismissDialog: () -> Unit
|
||||
) {
|
||||
var showDialog by remember { mutableStateOf(true) }
|
||||
if (!showDialog) {
|
||||
onDismissDialog()
|
||||
return
|
||||
}
|
||||
var text by remember { mutableStateOf(presetName) }
|
||||
var error by remember { mutableStateOf<PresetNameValidationError?>(null) }
|
||||
|
||||
AlertDialog(
|
||||
onDismissRequest = { showDialog = false },
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
onPresetNameSet(text)?.let {
|
||||
// validation failed
|
||||
error = it
|
||||
return@TextButton
|
||||
}
|
||||
// succeeded
|
||||
showDialog = false
|
||||
error = null
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
stringResource(id = android.R.string.ok)
|
||||
)
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(
|
||||
onClick = { showDialog = false }
|
||||
) {
|
||||
Text(
|
||||
stringResource(id = android.R.string.cancel)
|
||||
)
|
||||
}
|
||||
},
|
||||
title = { Text(title) },
|
||||
text = {
|
||||
Column {
|
||||
OutlinedTextField(
|
||||
value = text,
|
||||
onValueChange = { text = it },
|
||||
label = {
|
||||
Text(
|
||||
stringResource(id = R.string.dolby_geq_preset_name)
|
||||
)
|
||||
},
|
||||
isError = error != null,
|
||||
singleLine = true
|
||||
)
|
||||
error?.let {
|
||||
Text(
|
||||
text = it.toErrorMessage(),
|
||||
color = MaterialTheme.colorScheme.error,
|
||||
modifier = Modifier.padding(top = 8.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package co.aospa.dolby.xiaomi.geq.ui
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import co.aospa.dolby.xiaomi.R
|
||||
|
||||
enum class PresetNameValidationError {
|
||||
NAME_EXISTS,
|
||||
NAME_TOO_LONG;
|
||||
|
||||
@Composable
|
||||
fun toErrorMessage() =
|
||||
stringResource(
|
||||
id = when (this) {
|
||||
NAME_EXISTS -> R.string.dolby_geq_preset_name_exists
|
||||
NAME_TOO_LONG -> R.string.dolby_geq_preset_name_too_long
|
||||
}
|
||||
)
|
||||
}
|
||||
176
dolby/src/co/aospa/dolby/xiaomi/geq/ui/PresetSelector.kt
Normal file
176
dolby/src/co/aospa/dolby/xiaomi/geq/ui/PresetSelector.kt
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package co.aospa.dolby.xiaomi.geq.ui
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material.icons.filled.Edit
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.ExposedDropdownMenuBox
|
||||
import androidx.compose.material3.ExposedDropdownMenuDefaults
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextField
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.focusProperties
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.res.vectorResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import co.aospa.dolby.xiaomi.R
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun PresetSelector(viewModel: EqualizerViewModel) {
|
||||
val presets by viewModel.presets.collectAsState()
|
||||
val currentPreset by viewModel.preset.collectAsState()
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
var showNewPresetDialog by remember { mutableStateOf(false) }
|
||||
var showRenamePresetDialog by remember { mutableStateOf(false) }
|
||||
var showDeleteConfirmDialog by remember { mutableStateOf(false) }
|
||||
var showResetConfirmDialog by remember { mutableStateOf(false) }
|
||||
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 24.dp),
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
ExposedDropdownMenuBox(
|
||||
expanded = expanded,
|
||||
onExpandedChange = { expanded = !expanded },
|
||||
modifier = Modifier
|
||||
.padding(end = 8.dp)
|
||||
.weight(1f)
|
||||
) {
|
||||
TextField(
|
||||
value = currentPreset.name,
|
||||
onValueChange = { },
|
||||
readOnly = true,
|
||||
label = {
|
||||
Text(
|
||||
stringResource(id = R.string.dolby_geq_preset)
|
||||
)
|
||||
},
|
||||
singleLine = true,
|
||||
trailingIcon = {
|
||||
ExposedDropdownMenuDefaults.TrailingIcon(
|
||||
expanded = expanded
|
||||
)
|
||||
},
|
||||
colors = ExposedDropdownMenuDefaults.textFieldColors(),
|
||||
modifier = Modifier.menuAnchor()
|
||||
// prevent keyboard from popping up
|
||||
.focusProperties { canFocus = false }
|
||||
)
|
||||
ExposedDropdownMenu(
|
||||
expanded = expanded,
|
||||
onDismissRequest = { expanded = false }
|
||||
) {
|
||||
presets.forEach { preset ->
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = preset.name) },
|
||||
onClick = {
|
||||
viewModel.setPreset(preset)
|
||||
expanded = false
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TooltipIconButton(
|
||||
icon = ImageVector.vectorResource(
|
||||
id = R.drawable.save_as_24px
|
||||
),
|
||||
text = stringResource(id = R.string.dolby_geq_new_preset),
|
||||
onClick = { showNewPresetDialog = true }
|
||||
)
|
||||
|
||||
if (currentPreset.isUserDefined) {
|
||||
TooltipIconButton(
|
||||
icon = Icons.Default.Edit,
|
||||
text = stringResource(id = R.string.dolby_geq_rename_preset),
|
||||
onClick = { showRenamePresetDialog = true }
|
||||
)
|
||||
TooltipIconButton(
|
||||
icon = Icons.Default.Delete,
|
||||
text = stringResource(id = R.string.dolby_geq_delete_preset),
|
||||
onClick = { showDeleteConfirmDialog = true }
|
||||
)
|
||||
}
|
||||
|
||||
TooltipIconButton(
|
||||
icon = ImageVector.vectorResource(
|
||||
id = R.drawable.reset_settings_24px
|
||||
),
|
||||
text = stringResource(id = R.string.dolby_geq_reset_gains),
|
||||
onClick = {
|
||||
if (currentPreset.isUserDefined) {
|
||||
showResetConfirmDialog = true
|
||||
} else {
|
||||
viewModel.reset()
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// Dialogs
|
||||
|
||||
if (showNewPresetDialog) {
|
||||
PresetNameDialog(
|
||||
title = stringResource(id = R.string.dolby_geq_new_preset),
|
||||
onPresetNameSet = {
|
||||
return@PresetNameDialog viewModel.createNewPreset(name = it)
|
||||
},
|
||||
onDismissDialog = { showNewPresetDialog = false }
|
||||
)
|
||||
}
|
||||
|
||||
if (showRenamePresetDialog) {
|
||||
PresetNameDialog(
|
||||
title = stringResource(id = R.string.dolby_geq_rename_preset),
|
||||
presetName = currentPreset.name,
|
||||
onPresetNameSet = {
|
||||
return@PresetNameDialog viewModel.renamePreset(
|
||||
preset = currentPreset,
|
||||
name = it
|
||||
)
|
||||
},
|
||||
onDismissDialog = { showRenamePresetDialog = false }
|
||||
)
|
||||
}
|
||||
|
||||
if (showDeleteConfirmDialog) {
|
||||
ConfirmationDialog(
|
||||
text = stringResource(id = R.string.dolby_geq_delete_preset_prompt),
|
||||
onConfirm = { viewModel.deletePreset(currentPreset) },
|
||||
onDismiss = { showDeleteConfirmDialog = false }
|
||||
)
|
||||
}
|
||||
|
||||
if (showResetConfirmDialog) {
|
||||
ConfirmationDialog(
|
||||
text = stringResource(id = R.string.dolby_geq_reset_gains_prompt),
|
||||
onConfirm = { viewModel.reset() },
|
||||
onDismiss = { showResetConfirmDialog = false }
|
||||
)
|
||||
}
|
||||
}
|
||||
46
dolby/src/co/aospa/dolby/xiaomi/geq/ui/TooltipIconButton.kt
Normal file
46
dolby/src/co/aospa/dolby/xiaomi/geq/ui/TooltipIconButton.kt
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package co.aospa.dolby.xiaomi.geq.ui
|
||||
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TooltipBox
|
||||
import androidx.compose.material3.TooltipDefaults
|
||||
import androidx.compose.material3.rememberTooltipState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun TooltipIconButton(
|
||||
icon: ImageVector,
|
||||
text: String,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
TooltipBox(
|
||||
positionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider(),
|
||||
tooltip = {
|
||||
Text(text)
|
||||
},
|
||||
state = rememberTooltipState()
|
||||
) {
|
||||
IconButton(
|
||||
onClick = onClick
|
||||
) {
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
contentDescription = text,
|
||||
modifier = Modifier.size(24.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Paranoid Android
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package co.aospa.dolby.xiaomi.preference
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import androidx.preference.ListPreference
|
||||
import androidx.preference.PreferenceViewHolder
|
||||
import co.aospa.dolby.xiaomi.R
|
||||
|
||||
// Preference with icon on the right side
|
||||
class DolbyIeqPreference(
|
||||
context: Context,
|
||||
attrs: AttributeSet?,
|
||||
) : ListPreference(context, attrs) {
|
||||
|
||||
init {
|
||||
widgetLayoutResource = R.layout.ieq_icon_layout
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
super.onBindViewHolder(holder)
|
||||
val iconView = holder.findViewById(R.id.ieq_icon)!! as ImageView
|
||||
val icon = AppCompatResources.getDrawable(context, getIeqIconResId())
|
||||
iconView.setImageDrawable(icon)
|
||||
}
|
||||
|
||||
private fun getIeqIconResId(): Int {
|
||||
val ieqValue = value?.toIntOrNull() ?: 0
|
||||
return when (ieqValue) {
|
||||
0 -> R.drawable.ic_ieq_off
|
||||
1 -> R.drawable.ic_ieq_balanced
|
||||
2 -> R.drawable.ic_ieq_warm
|
||||
3 -> R.drawable.ic_ieq_detailed
|
||||
else -> 0 // should never hit this!
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user