android: add optmized charge limit config

This commit is contained in:
Kavish Devar
2026-05-05 13:05:54 +05:30
parent d1933c3b67
commit f08769e62f
4 changed files with 39 additions and 6 deletions

View File

@@ -109,7 +109,8 @@ class AACPManager {
EAR_DETECTION_CONFIG(0x0A), AUTOMATIC_CONNECTION_CONFIG(0x20), OWNS_CONNECTION(0x06), PPE_TOGGLE_CONFIG( EAR_DETECTION_CONFIG(0x0A), AUTOMATIC_CONNECTION_CONFIG(0x20), OWNS_CONNECTION(0x06), PPE_TOGGLE_CONFIG(
0x37 0x37
), ),
PPE_CAP_LEVEL_CONFIG(0x38); PPE_CAP_LEVEL_CONFIG(0x38),
DYNAMIC_END_OF_CHARGE(0x3B);
companion object { companion object {
fun fromByte(byte: Byte): ControlCommandIdentifiers? = fun fromByte(byte: Byte): ControlCommandIdentifiers? =

View File

@@ -398,6 +398,16 @@ fun AirPodsSettingsScreen(viewModel: AirPodsViewModel, navController: NavControl
} }
} }
item(key = "spacer_dynamic_end_of_charge") { Spacer(modifier = Modifier.height(16.dp)) }
item(key = "dynamic_end_of_charge") {
StyledToggle(
label = stringResource(R.string.optimized_charging),
description = stringResource(R.string.optimized_charging_description),
checked = state.dynamicEndOfCharge,
onCheckedChange = viewModel::setDynamicEndOfCharge
)
}
item(key = "spacer_accessibility") { Spacer(modifier = Modifier.height(16.dp)) } item(key = "spacer_accessibility") { Spacer(modifier = Modifier.height(16.dp)) }
item(key = "accessibility") { item(key = "accessibility") {
NavigationButton( NavigationButton(

View File

@@ -89,7 +89,9 @@ data class AirPodsUiState(
val hearingAidData: ByteArray = byteArrayOf(), val hearingAidData: ByteArray = byteArrayOf(),
val isPremium: Boolean = false, val isPremium: Boolean = false,
val vendorIdHook: Boolean = false val vendorIdHook: Boolean = false,
val dynamicEndOfCharge: Boolean = false
) )
class AirPodsViewModel( class AirPodsViewModel(
@@ -268,9 +270,16 @@ class AirPodsViewModel(
val current = state.controlStates[identifier] val current = state.controlStates[identifier]
if (current?.contentEquals(value) == true) return@update state if (current?.contentEquals(value) == true) return@update state
state.copy( if (identifier == ControlCommandIdentifiers.DYNAMIC_END_OF_CHARGE) {
controlStates = state.controlStates + (identifier to value) state.copy(
) dynamicEndOfCharge = value[0] == 0x01.toByte(),
controlStates = state.controlStates + (identifier to value)
)
} else {
state.copy(
controlStates = state.controlStates + (identifier to value)
)
}
} }
} }
@@ -305,6 +314,7 @@ class AirPodsViewModel(
ControlCommandIdentifiers.AUTOMATIC_CONNECTION_CONFIG, ControlCommandIdentifiers.AUTOMATIC_CONNECTION_CONFIG,
ControlCommandIdentifiers.OWNS_CONNECTION, ControlCommandIdentifiers.OWNS_CONNECTION,
ControlCommandIdentifiers.PPE_TOGGLE_CONFIG, ControlCommandIdentifiers.PPE_TOGGLE_CONFIG,
ControlCommandIdentifiers.DYNAMIC_END_OF_CHARGE
) )
for (identifier in identifiersList) { for (identifier in identifiersList) {
observeControl(identifier) observeControl(identifier)
@@ -342,6 +352,7 @@ class AirPodsViewModel(
) ?: "CYCLE_NOISE_CONTROL_MODES" ) ?: "CYCLE_NOISE_CONTROL_MODES"
) )
val vendorIdHook = xposedRemotePref.getBoolean("vendor_id_hook", false) val vendorIdHook = xposedRemotePref.getBoolean("vendor_id_hook", false)
val dynamicEndOfCharge = sharedPreferences.getBoolean("dynamic_end_of_charge", false)
_uiState.update { _uiState.update {
it.copy( it.copy(
@@ -351,7 +362,8 @@ class AirPodsViewModel(
headGesturesEnabled = headGesturesEnabled, headGesturesEnabled = headGesturesEnabled,
leftAction = leftAction, leftAction = leftAction,
rightAction = rightAction, rightAction = rightAction,
vendorIdHook = vendorIdHook vendorIdHook = vendorIdHook,
dynamicEndOfCharge = dynamicEndOfCharge
) )
} }
} }
@@ -371,6 +383,14 @@ class AirPodsViewModel(
} }
} }
fun setDynamicEndOfCharge(enabled: Boolean) {
service.aacpManager.sendControlCommand(ControlCommandIdentifiers.DYNAMIC_END_OF_CHARGE.value, enabled)
sharedPreferences.edit { putBoolean("dynamic_end_of_charge", enabled) }
_uiState.update {
it.copy(dynamicEndOfCharge = enabled)
}
}
private fun loadControlList() { private fun loadControlList() {
_uiState.update { _uiState.update {
it.copy( it.copy(

View File

@@ -272,4 +272,6 @@
<string name="app_enabled_in_xposed">App enabled in Xposed</string> <string name="app_enabled_in_xposed">App enabled in Xposed</string>
<string name="subject">Subject</string> <string name="subject">Subject</string>
<string name="describe_your_issue">Describe your issue</string> <string name="describe_your_issue">Describe your issue</string>
<string name="optimized_charging">Optimized Charge Limit</string>
<string name="optimized_charging_description">AirPods can learn from your daily usage and determine when to charge to an optmized limit and when to allow or full charge. This limit adapts to your daily usage and preserves your battery lifespan over time.\\nThis setting may not affect unsupported AirPods, or AirPods on an older firmware version.</string>
</resources> </resources>