Skip to content

Commit

Permalink
Better support for android 11. Restart deamon afte config change
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteCarra committed Oct 3, 2020
1 parent fbcdc21 commit 2d54e31
Show file tree
Hide file tree
Showing 11 changed files with 373 additions and 24 deletions.
7 changes: 6 additions & 1 deletion app/src/main/java/mattecarra/accapp/acc/Acc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ object Acc {
return when {
v >= 202007220 -> "v202007220"
v >= 202007030 -> "v202007030"
v >= 202006140 -> "v202006140"
v >= 202002290 -> "v202002290"
v >= 202002170 -> "v202002170"
v >= 201910130 -> "v201910132"
Expand Down Expand Up @@ -178,6 +179,10 @@ object Acc {
}

private fun getAccVersion(): Int? {
return Shell.su("/dev/acca --version").exec().out.joinToString(separator = "\n").split("(").last().split(")").first().trim().toIntOrNull()
return Shell.su("/dev/acca --version").exec().out.joinToString(separator = "\n").split("(").last().split(")").first().trim().toIntOrNull() ?: getAccVersionLegacy()
}

private fun getAccVersionLegacy(): Int? {
return Shell.su("acc --version").exec().out.joinToString(separator = "\n").split("(").last().split(")").first().trim().toIntOrNull()
}
}
9 changes: 6 additions & 3 deletions app/src/main/java/mattecarra/accapp/acc/ConfigUpdater.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ data class ConfigUpdater(val accConfig: AccConfig) {
acc.updateAccOnBoot(accConfig.configOnBoot),
acc.updateAccOnPlugged(accConfig.configOnPlug),
acc.updateAccChargingSwitch(accConfig.configChargeSwitch, accConfig.configIsAutomaticSwitchingEnabled),
acc.updatePrioritizeBatteryIdleMode(accConfig.prioritizeBatteryIdleMode)
acc.updatePrioritizeBatteryIdleMode(accConfig.prioritizeBatteryIdleMode),
acc.accRestartDaemon()
)
}

Expand Down Expand Up @@ -59,7 +60,8 @@ data class ConfigUpdater(val accConfig: AccConfig) {
acc.getUpdateAccOnBootCommand(accConfig.configOnBoot),
acc.getUpdateAccOnPluggedCommand(accConfig.configOnPlug),
acc.getUpdateAccChargingSwitchCommand(accConfig.configChargeSwitch, accConfig.configIsAutomaticSwitchingEnabled),
acc.getUpdatePrioritizeBatteryIdleModeCommand(accConfig.prioritizeBatteryIdleMode)
acc.getUpdatePrioritizeBatteryIdleModeCommand(accConfig.prioritizeBatteryIdleMode),
acc.getAccRestartDaemon()
).joinToString("; ")
}
}
Expand All @@ -78,7 +80,8 @@ data class ConfigUpdateResult(
val onBootUpdateSuccessful: Boolean,
val onPluggedUpdateSuccessful: Boolean,
val chargingSwitchUpdateSuccessful: Boolean,
val prioritizeBatteryIdleModeSuccessful: Boolean
val prioritizeBatteryIdleModeSuccessful: Boolean,
val restartSuccessful: Boolean
) {
fun debug() {
if(!capacityUpdateSuccessful) println("Update capacity update failed")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ interface AccInterface {

suspend fun abcStartDaemon(): Boolean

suspend fun abcRestartDaemon(): Boolean
fun getAccRestartDaemon(): String
suspend fun accRestartDaemon(): Boolean = withContext(Dispatchers.IO) {
Shell.su(getAccRestartDaemon()).exec().isSuccess
}

suspend fun abcStopDaemon(): Boolean

Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/mattecarra/accapp/acc/legacy/AccHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,7 @@ open class AccHandler(override val version: Int) : AccInterface {
Shell.su("acc -D start").exec().isSuccess
}

override suspend fun abcRestartDaemon(): Boolean = withContext(Dispatchers.IO) {
Shell.su("acc -D restart").exec().isSuccess
}
override fun getAccRestartDaemon(): String = "acc -D restart"

override suspend fun abcStopDaemon(): Boolean = withContext(Dispatchers.IO) {
Shell.su("acc -D stop").exec().isSuccess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,7 @@ open class AccHandler(override val version: Int) : AccInterface {
Shell.su("acc-en -D start").exec().isSuccess
}

override suspend fun abcRestartDaemon(): Boolean = withContext(Dispatchers.IO) {
Shell.su("acc-en -D restart").exec().isSuccess
}
override fun getAccRestartDaemon(): String = "acc-en -D restart"

override suspend fun abcStopDaemon(): Boolean = withContext(Dispatchers.IO) {
Shell.su("acc-en -D stop").exec().isSuccess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,7 @@ open class AccHandler(override val version: Int) : AccInterface {
Shell.su(".acc-en -D start").exec().isSuccess
}

override suspend fun abcRestartDaemon(): Boolean = withContext(Dispatchers.IO) {
Shell.su(".acc-en -D restart").exec().isSuccess
}
override fun getAccRestartDaemon(): String = ".acc-en -D restart"

override suspend fun abcStopDaemon(): Boolean = withContext(Dispatchers.IO) {
Shell.su(".acc-en -D stop").exec().isSuccess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,7 @@ open class AccHandler(override val version: Int) : AccInterface {
Shell.su("/sbin/acca -D start").exec().isSuccess
}

override suspend fun abcRestartDaemon(): Boolean = withContext(Dispatchers.IO) {
Shell.su("/sbin/acca -D restart").exec().isSuccess
}
override fun getAccRestartDaemon(): String = "/sbin/acca -D restart"

override suspend fun abcStopDaemon(): Boolean = withContext(Dispatchers.IO) {
Shell.su("/sbin/acca -D stop").exec().isSuccess
Expand Down
Loading

0 comments on commit 2d54e31

Please sign in to comment.