From dc1abb79781af776315cd7b673225ffd4f648a96 Mon Sep 17 00:00:00 2001 From: yostyle Date: Fri, 23 Sep 2022 15:46:09 +0200 Subject: [PATCH 1/3] Add Activities of android permission controller in the whitelist --- .../features/lifecycle/VectorActivityLifecycleCallbacks.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/lifecycle/VectorActivityLifecycleCallbacks.kt b/vector/src/main/java/im/vector/app/features/lifecycle/VectorActivityLifecycleCallbacks.kt index c884843f5c..6fc1bcf6c7 100644 --- a/vector/src/main/java/im/vector/app/features/lifecycle/VectorActivityLifecycleCallbacks.kt +++ b/vector/src/main/java/im/vector/app/features/lifecycle/VectorActivityLifecycleCallbacks.kt @@ -33,6 +33,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import org.matrix.android.sdk.api.extensions.tryOrNull import timber.log.Timber class VectorActivityLifecycleCallbacks constructor(private val popupAlertManager: PopupAlertManager) : Application.ActivityLifecycleCallbacks { @@ -94,9 +95,13 @@ class VectorActivityLifecycleCallbacks constructor(private val popupAlertManager val context = activity.applicationContext val packageManager: PackageManager = context.packageManager - // Get all activities from app manifest + // 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 From bd64749b48098864d91e76aadc74ea71bff52a23 Mon Sep 17 00:00:00 2001 From: yostyle Date: Fri, 23 Sep 2022 18:03:54 +0200 Subject: [PATCH 2/3] Add changelog --- changelog.d/7224.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/7224.bugfix diff --git a/changelog.d/7224.bugfix b/changelog.d/7224.bugfix new file mode 100644 index 0000000000..e48925e9e6 --- /dev/null +++ b/changelog.d/7224.bugfix @@ -0,0 +1 @@ +Fix app restarts in loop on Android 13 on the first run of the app. From 8dc71e07edef7666f27489e419c093197082d989 Mon Sep 17 00:00:00 2001 From: yostyle Date: Tue, 27 Sep 2022 00:24:10 +0200 Subject: [PATCH 3/3] Add activities from Android API 33. --- .../VectorActivityLifecycleCallbacks.kt | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/lifecycle/VectorActivityLifecycleCallbacks.kt b/vector/src/main/java/im/vector/app/features/lifecycle/VectorActivityLifecycleCallbacks.kt index 6fc1bcf6c7..5bdd92dcf4 100644 --- a/vector/src/main/java/im/vector/app/features/lifecycle/VectorActivityLifecycleCallbacks.kt +++ b/vector/src/main/java/im/vector/app/features/lifecycle/VectorActivityLifecycleCallbacks.kt @@ -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