Skip to content

Commit

Permalink
Fix label lookup
Browse files Browse the repository at this point in the history
On my test device the MIUI security center didn't contain any relevant strings under that ID
  • Loading branch information
d4rken committed Jan 30, 2025
1 parent 42cda6b commit 007b9d3
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,60 @@ import android.content.Context
import dagger.Reusable
import dagger.hilt.android.qualifiers.ApplicationContext
import eu.darken.sdmse.appcontrol.core.automation.specs.AppControlLabelSource
import eu.darken.sdmse.appcontrol.core.automation.specs.aosp.AOSPLabels
import eu.darken.sdmse.common.debug.logging.logTag
import eu.darken.sdmse.common.pkgs.toPkgId
import javax.inject.Inject

@Reusable
class HyperOsLabels @Inject constructor(
@ApplicationContext private val context: Context,
private val aospLabels: AOSPLabels,
) : AppControlLabelSource {

fun getForceStopButtonDynamic(): Set<String> = setOf(
"force_stop",
).getAsStringResources(context, SETTINGS_PKG)
fun getForceStopButtonDynamic(): Set<String> {
val labels = mutableSetOf<String>()
setOf("force_stop")
.getAsStringResources(context, SETTINGS_PKG)
.run { labels.addAll(this) }
if (labels.isEmpty()) {
labels.addAll(aospLabels.getForceStopButtonDynamic())
}
return labels
}

fun getForceStopDialogTitleDynamic(): Set<String> = setOf(
"force_stop_dlg_title",
).getAsStringResources(context, SETTINGS_PKG)
fun getForceStopDialogTitleDynamic(): Set<String> {
val labels = mutableSetOf<String>()
setOf("force_stop_dlg_title")
.getAsStringResources(context, SETTINGS_PKG)
.run { labels.addAll(this) }
if (labels.isEmpty()) {
labels.addAll(aospLabels.getForceStopDialogTitleDynamic())
}
return labels
}

fun getForceStopDialogOkDynamic(): Set<String> = setOf(
"okay",
"dlg_ok",
).getAsStringResources(context, SETTINGS_PKG)
fun getForceStopDialogOkDynamic(): Set<String> {
val labels = mutableSetOf<String>()
setOf("okay", "dlg_ok")
.getAsStringResources(context, SETTINGS_PKG)
.run { labels.addAll(this) }
if (labels.isEmpty()) {
labels.addAll(aospLabels.getForceStopDialogOkDynamic())
}
return labels
}

fun getForceStopDialogCancelDynamic(): Set<String> = setOf(
"cancel",
"dlg_cancel",
).getAsStringResources(context, SETTINGS_PKG)
fun getForceStopDialogCancelDynamic(): Set<String> {
val labels = mutableSetOf<String>()
setOf("cancel", "dlg_cancel")
.getAsStringResources(context, SETTINGS_PKG)
.run { labels.addAll(this) }
if (labels.isEmpty()) {
labels.addAll(aospLabels.getForceStopDialogOkDynamic())
}
return labels
}

companion object {
val SETTINGS_PKG = "com.miui.securitycenter".toPkgId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,62 @@ import android.content.Context
import dagger.Reusable
import dagger.hilt.android.qualifiers.ApplicationContext
import eu.darken.sdmse.appcontrol.core.automation.specs.AppControlLabelSource
import eu.darken.sdmse.appcontrol.core.automation.specs.aosp.AOSPLabels
import eu.darken.sdmse.appcontrol.core.automation.specs.hyperos.HyperOsLabels
import eu.darken.sdmse.common.debug.logging.logTag
import eu.darken.sdmse.common.pkgs.toPkgId
import javax.inject.Inject

@Reusable
class MIUILabels @Inject constructor(
@ApplicationContext private val context: Context,
private val aospLabels: AOSPLabels,
) : AppControlLabelSource {

fun getForceStopButtonDynamic(): Set<String> = setOf(
"force_stop",
).getAsStringResources(context, SETTINGS_PKG)
fun getForceStopButtonDynamic(): Set<String> {
val labels = mutableSetOf<String>()
setOf("force_stop")
.getAsStringResources(context, HyperOsLabels.SETTINGS_PKG)
.run { labels.addAll(this) }
if (labels.isEmpty()) {
labels.addAll(aospLabels.getForceStopButtonDynamic())
}
return labels
}

fun getForceStopDialogTitleDynamic(): Set<String> = setOf(
"force_stop_dlg_title",
).getAsStringResources(context, SETTINGS_PKG)
fun getForceStopDialogTitleDynamic(): Set<String> {
val labels = mutableSetOf<String>()
setOf("force_stop_dlg_title")
.getAsStringResources(context, HyperOsLabels.SETTINGS_PKG)
.run { labels.addAll(this) }
if (labels.isEmpty()) {
labels.addAll(aospLabels.getForceStopDialogTitleDynamic())
}
return labels
}

fun getForceStopDialogOkDynamic(): Set<String> = setOf(
"okay",
"dlg_ok",
).getAsStringResources(context, SETTINGS_PKG)
fun getForceStopDialogOkDynamic(): Set<String> {
val labels = mutableSetOf<String>()
setOf("okay", "dlg_ok")
.getAsStringResources(context, HyperOsLabels.SETTINGS_PKG)
.run { labels.addAll(this) }
if (labels.isEmpty()) {
labels.addAll(aospLabels.getForceStopDialogOkDynamic())
}
return labels
}

fun getForceStopDialogCancelDynamic(): Set<String> {
val labels = mutableSetOf<String>()
setOf("cancel", "dlg_cancel")
.getAsStringResources(context, HyperOsLabels.SETTINGS_PKG)
.run { labels.addAll(this) }
if (labels.isEmpty()) {
labels.addAll(aospLabels.getForceStopDialogOkDynamic())
}
return labels
}

fun getForceStopDialogCancelDynamic(): Set<String> = setOf(
"cancel",
"dlg_cancel",
).getAsStringResources(context, SETTINGS_PKG)

companion object {
val SETTINGS_PKG = "com.miui.securitycenter".toPkgId()
Expand Down

0 comments on commit 007b9d3

Please sign in to comment.