Compare commits
1 commit
6cdbcca741
...
45e443a622
Author | SHA1 | Date | |
---|---|---|---|
45e443a622 |
1 changed files with 7 additions and 9 deletions
|
@ -9,15 +9,15 @@ import im.angry.openeuicc.BuildConfig
|
||||||
|
|
||||||
class Partner {
|
class Partner {
|
||||||
companion object {
|
companion object {
|
||||||
private val intent = Intent("com.google.android.euicc.action.PARTNER_CUSTOMIZATION")
|
private const val ACTION = "com.google.android.euicc.action.PARTNER_CUSTOMIZATION"
|
||||||
|
|
||||||
fun getInstance(context: Context): Partner? {
|
fun getInstance(context: Context, action: String = ACTION): Partner? {
|
||||||
var flags = if (BuildConfig.DEBUG)
|
var flags = if (BuildConfig.DEBUG)
|
||||||
PackageManager.MATCH_UNINSTALLED_PACKAGES else
|
PackageManager.MATCH_UNINSTALLED_PACKAGES else
|
||||||
PackageManager.MATCH_SYSTEM_ONLY
|
PackageManager.MATCH_SYSTEM_ONLY
|
||||||
flags = flags or PackageManager.MATCH_DISABLED_COMPONENTS
|
flags = flags or PackageManager.MATCH_DISABLED_COMPONENTS
|
||||||
val apps = context.packageManager
|
val apps = context.packageManager
|
||||||
.queryBroadcastReceivers(intent, flags)
|
.queryBroadcastReceivers(Intent(action), flags)
|
||||||
.mapNotNull { it.activityInfo?.applicationInfo }
|
.mapNotNull { it.activityInfo?.applicationInfo }
|
||||||
for (app in apps) {
|
for (app in apps) {
|
||||||
try {
|
try {
|
||||||
|
@ -32,17 +32,15 @@ class Partner {
|
||||||
}
|
}
|
||||||
|
|
||||||
private val resources: Resources
|
private val resources: Resources
|
||||||
private val ids = mutableMapOf<String, Int>()
|
|
||||||
|
|
||||||
private constructor(resources: Resources) {
|
private constructor(resources: Resources) {
|
||||||
this.resources = resources
|
this.resources = resources
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getIdentifier(name: String) = ids.getOrPut(name) {
|
private fun getIdentifier(name: String) =
|
||||||
resources.getIdentifier(name, null, null)
|
resources.getIdentifier(name, null, null).takeIf { it != 0 }
|
||||||
}
|
|
||||||
|
|
||||||
fun getString(name: String) = getIdentifier(name).let(resources::getString)
|
fun getString(name: String) = getIdentifier(name)?.let(resources::getString)
|
||||||
|
|
||||||
fun getBoolean(name: String) = getIdentifier(name).let(resources::getBoolean)
|
fun getBoolean(name: String) = getIdentifier(name)?.let(resources::getBoolean)
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue