Compare commits
1 commit
9673de4d07
...
b59a85e120
Author | SHA1 | Date | |
---|---|---|---|
b59a85e120 |
3 changed files with 33 additions and 38 deletions
|
@ -1,12 +1,7 @@
|
|||
package im.angry.openeuicc.ui
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.provider.Settings
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.widget.Toast
|
||||
import im.angry.easyeuicc.R
|
||||
import im.angry.openeuicc.util.SIMToolkit
|
||||
import im.angry.openeuicc.util.newInstanceEuicc
|
||||
|
@ -30,22 +25,8 @@ class UnprivilegedEuiccManagementFragment : EuiccManagementFragment() {
|
|||
inflater.inflate(R.menu.fragment_sim_toolkit, menu)
|
||||
menu.findItem(R.id.open_sim_toolkit).apply {
|
||||
val slot = stk[slotId] ?: return@apply
|
||||
isVisible = slot.intent != null
|
||||
setOnMenuItemClickListener {
|
||||
val intent = slot.intent ?: return@setOnMenuItemClickListener false
|
||||
if (intent.action == Settings.ACTION_APPLICATION_DETAILS_SETTINGS) {
|
||||
val packageName = intent.data!!.schemeSpecificPart
|
||||
val label = requireContext().packageManager.getApplicationLabel(packageName)
|
||||
val message = requireContext().getString(R.string.toast_prompt_to_enable_sim_toolkit, label)
|
||||
Toast.makeText(context, message, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
startActivity(intent)
|
||||
true
|
||||
isVisible = slot.available
|
||||
setOnMenuItemClickListener { slot.launch() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun PackageManager.getApplicationLabel(packageName: String): CharSequence =
|
||||
getApplicationLabel(getApplicationInfo(packageName, 0))
|
||||
|
|
|
@ -43,7 +43,10 @@ class SIMToolkit(private val context: Context) {
|
|||
get() = packageNames.flatMap(packageManager::getActivities)
|
||||
.filter(ActivityInfo::exported).map { ComponentName(it.packageName, it.name) }
|
||||
|
||||
private fun getActivityIntent(): Intent? {
|
||||
val available: Boolean
|
||||
get() = getIntent() != null || getDisabledPackageName() != null
|
||||
|
||||
private fun getIntent(): Intent? {
|
||||
for (activity in activities) {
|
||||
if (!components.contains(activity)) continue
|
||||
if (isDisabledState(packageManager.getComponentEnabledSetting(activity))) continue
|
||||
|
@ -52,23 +55,31 @@ class SIMToolkit(private val context: Context) {
|
|||
return launchIntent
|
||||
}
|
||||
|
||||
private fun getDisabledPackageIntent(): Intent? {
|
||||
val disabledPackageName = packageNames.find {
|
||||
private fun getDisabledPackageName() = packageNames.find {
|
||||
try {
|
||||
isDisabledState(packageManager.getApplicationEnabledSetting(it))
|
||||
} catch (_: IllegalArgumentException) {
|
||||
false
|
||||
}
|
||||
}
|
||||
if (disabledPackageName == null) return null
|
||||
return Intent(
|
||||
Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
|
||||
Uri.fromParts("package", disabledPackageName, null)
|
||||
)
|
||||
}
|
||||
|
||||
val intent: Intent?
|
||||
get() = getActivityIntent() ?: getDisabledPackageIntent()
|
||||
fun launch(): Boolean {
|
||||
var intent = getIntent()
|
||||
if (intent == null) {
|
||||
val pkgName = getDisabledPackageName() ?: return false
|
||||
val message = context.getString(
|
||||
R.string.toast_prompt_to_enable_sim_toolkit,
|
||||
packageManager.getApplicationLabel(pkgName)
|
||||
)
|
||||
intent = Intent(
|
||||
Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
|
||||
Uri.fromParts("package", pkgName, null)
|
||||
)
|
||||
Toast.makeText(context, message, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
context.startActivity(intent)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,6 +89,9 @@ private fun isDisabledState(state: Int) = when (state) {
|
|||
else -> false
|
||||
}
|
||||
|
||||
private fun PackageManager.getApplicationLabel(packageName: String): CharSequence =
|
||||
getApplicationLabel(getApplicationInfo(packageName, 0))
|
||||
|
||||
private fun PackageManager.getLaunchIntent(packageName: String) = try {
|
||||
getLaunchIntentForPackage(packageName)
|
||||
} catch (_: PackageManager.NameNotFoundException) {
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
<!-- Toast -->
|
||||
<string name="toast_ara_m_copied">ARA-M SHA-1 copied to clipboard</string>
|
||||
<string name="toast_prompt_to_enable_sim_toolkit">Please ENABLE your \"%s\" application</string>
|
||||
<string name="toast_prompt_to_enable_sim_toolkit">Please ENABLE your \"%s\" application</string>
|
||||
|
||||
<!-- Compatibility Check Descriptions -->
|
||||
<string name="compatibility_check_system_features">System Features</string>
|
||||
|
|
Loading…
Add table
Reference in a new issue