2019-04-19 14:32:01 +00:00
|
|
|
package com.topjohnwu.magisk.utils
|
|
|
|
|
2019-05-03 07:36:39 +00:00
|
|
|
import android.content.Context
|
2019-04-19 14:32:01 +00:00
|
|
|
import android.content.pm.ApplicationInfo
|
|
|
|
import android.content.pm.ComponentInfo
|
|
|
|
import android.content.pm.PackageInfo
|
|
|
|
import android.content.pm.PackageManager
|
|
|
|
import android.content.pm.PackageManager.*
|
|
|
|
|
|
|
|
val PackageInfo.processes
|
|
|
|
get() = activities?.processNames.orEmpty() +
|
|
|
|
services?.processNames.orEmpty() +
|
|
|
|
receivers?.processNames.orEmpty() +
|
|
|
|
providers?.processNames.orEmpty()
|
|
|
|
|
|
|
|
val Array<out ComponentInfo>.processNames get() = mapNotNull { it.processName }
|
|
|
|
|
|
|
|
val ApplicationInfo.packageInfo: PackageInfo?
|
|
|
|
get() {
|
|
|
|
val pm: PackageManager by inject()
|
|
|
|
|
|
|
|
return try {
|
|
|
|
val request = GET_ACTIVITIES or
|
|
|
|
GET_SERVICES or
|
|
|
|
GET_RECEIVERS or
|
|
|
|
GET_PROVIDERS
|
|
|
|
pm.getPackageInfo(packageName, request)
|
|
|
|
} catch (e1: Exception) {
|
|
|
|
try {
|
|
|
|
pm.activities(packageName).apply {
|
|
|
|
services = pm.services(packageName)
|
|
|
|
receivers = pm.receivers(packageName)
|
|
|
|
providers = pm.providers(packageName)
|
|
|
|
}
|
|
|
|
} catch (e2: Exception) {
|
|
|
|
null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun PackageManager.activities(packageName: String) =
|
|
|
|
getPackageInfo(packageName, GET_ACTIVITIES)
|
|
|
|
|
|
|
|
fun PackageManager.services(packageName: String) =
|
|
|
|
getPackageInfo(packageName, GET_SERVICES).services
|
|
|
|
|
|
|
|
fun PackageManager.receivers(packageName: String) =
|
|
|
|
getPackageInfo(packageName, GET_RECEIVERS).receivers
|
|
|
|
|
|
|
|
fun PackageManager.providers(packageName: String) =
|
2019-05-03 07:36:39 +00:00
|
|
|
getPackageInfo(packageName, GET_PROVIDERS).providers
|
|
|
|
|
|
|
|
fun Context.rawResource(id: Int) = resources.openRawResource(id)
|