Skip to content

Commit

Permalink
feat: read application label
Browse files Browse the repository at this point in the history
  • Loading branch information
septs committed Sep 1, 2024
1 parent 9ac239c commit f885916
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {
applicationId = "app.septs.euiccprobe"
minSdk = 21
targetSdk = 34
versionCode = 5
versionCode = 6
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission
android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />
<uses-permission android:name="org.simalliance.openmobileapi.SMARTCARD" />

<application
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/app/septs/euiccprobe/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ class MainActivity : AppCompatActivity() {
appendLine()
appendLine("System LPAs:")
for (pkg in pkgs) {
appendLine("- ${pkg.packageName}")
val label = SystemApps.getApplicationLabel(packageManager, pkg.packageName)
if (label != null) {
appendLine("- $label (${pkg.packageName})")
} else {
appendLine("- ${pkg.packageName} [uninstalled]")
}
}
}
val properties = arrayOf(
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/java/app/septs/euiccprobe/SystemApps.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package app.septs.euiccprobe

import android.content.Context
import android.content.pm.PackageManager
import java.io.File

object SystemApps {
Expand All @@ -25,7 +27,6 @@ object SystemApps {
if (!file.canRead()) continue
if (!file.name.startsWith("privapp-permissions")) continue
if (file.extension != "xml") continue
if (!file.name.contains("permission")) continue
file.inputStream().use(parser::parse)
}
}
Expand All @@ -34,4 +35,13 @@ object SystemApps {
perm.allowedPermissions.any(optionalPermissions::contains)
}
}

fun getApplicationLabel(pm: PackageManager, packageName: String): String? {
return try {
val appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_ACTIVITIES)
pm.getApplicationLabel(appInfo).toString()
} catch (e: Exception) {
null
}
}
}

0 comments on commit f885916

Please sign in to comment.