Add activities from Android API 33.

This commit is contained in:
yostyle 2022-09-27 00:24:10 +02:00
parent bd64749b48
commit 8dc71e07ed

View file

@ -59,6 +59,26 @@ class VectorActivityLifecycleCallbacks constructor(private val popupAlertManager
override fun onActivityStopped(activity: Activity) {}
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
if (activitiesInfo.isEmpty()) {
val context = activity.applicationContext
val packageManager: PackageManager = context.packageManager
// Get all activities from element android
activitiesInfo = packageManager.getPackageInfo(context.packageName, PackageManager.GET_ACTIVITIES).activities
// Get all activities from PermissionController module
// See https://source.android.com/docs/core/architecture/modular-system/permissioncontroller#package-format
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.S_V2) {
activitiesInfo += tryOrNull {
packageManager.getPackageInfo("com.google.android.permissioncontroller", PackageManager.GET_ACTIVITIES).activities
} ?: tryOrNull {
packageManager.getModuleInfo("com.google.android.permission", 1).packageName?.let {
packageManager.getPackageInfo(it, PackageManager.GET_ACTIVITIES or PackageManager.MATCH_APEX).activities
}
}.orEmpty()
}
}
// restart the app if the task contains an unknown activity
coroutineScope.launch {
val isTaskCorrupted = try {
@ -93,16 +113,6 @@ class VectorActivityLifecycleCallbacks constructor(private val popupAlertManager
*/
private suspend fun isTaskCorrupted(activity: Activity): Boolean = withContext(Dispatchers.Default) {
val context = activity.applicationContext
val packageManager: PackageManager = context.packageManager
// Get all activities from element android and android permission controller app
if (activitiesInfo.isEmpty()) {
activitiesInfo = packageManager.getPackageInfo(context.packageName, PackageManager.GET_ACTIVITIES).activities
activitiesInfo += tryOrNull {
packageManager.getPackageInfo("com.google.android.permissioncontroller", PackageManager.GET_ACTIVITIES).activities
} ?: emptyArray()
}
// Get all running activities on app task
// and compare to activities declared in manifest
@ -127,7 +137,7 @@ class VectorActivityLifecycleCallbacks constructor(private val popupAlertManager
runningTaskInfo.topActivity?.let {
// Check whether the activity task affinity matches with app task affinity.
// The activity is considered safe when its task affinity doesn't correspond to app task affinity.
if (packageManager.getActivityInfo(it, 0).taskAffinity == context.applicationInfo.taskAffinity) {
if (context.packageManager.getActivityInfo(it, 0).taskAffinity == context.applicationInfo.taskAffinity) {
isPotentialMaliciousActivity(it)
} else false
} ?: false