intentfilterxiaomimiuiandroid-tiramisu

Crash when trying to open MIUI system Activity in Android 13


i am trying to call MIUI system activity by this code:

val intent = Intent()
intent.setClassName("com.miui.powerkeeper", "com.miui.powerkeeper.ui.HiddenAppsConfigActivity")
intent.putExtra("package_name", activity.packageName)
intent.putExtra("package_label", getText(R.string.app_name))
startActivity(intent)

Before Android 13 everything works fine, but on Android 13 I catch an error:

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.miui.powerkeeper/com.miui.powerkeeper.ui.HiddenAppsConfigActivity}; have you declared this activity in your AndroidManifest.xml, or does your intent not match its declared <intent-filter>?

Tried to add default intent-filter, but it never helps:

<activity android:name="com.miui.powerkeeper.ui.HiddenAppsConfigActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="foo" />
            <category
                android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

How to define external intent-filter?


Solution

  • The problem was that I determined the presence of the MIUI firmware like this:

    fun isMIUI() = !TextUtils.isEmpty(AndroidUtilities.getSystemProperty("ro.miui.ui.version.name"))
    

    But the bug was reproduced on the magnificent Redmi A2+, which has the firmware Android 13 (Go).

    These firmwares do not have proprietary MIUI applications installed and that's why I couldn't run them.

    As a result, to solve the problem, you need to change the firmware identification to this:

    fun isMIUI(context: Context): Boolean {
        val intentList = listOf(
            Intent("miui.intent.action.OP_AUTO_START").addCategory(Intent.CATEGORY_DEFAULT),
            Intent().setComponent(ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity")),
            Intent("miui.intent.action.POWER_HIDE_MODE_APP_LIST").addCategory(Intent.CATEGORY_DEFAULT),
            Intent().setComponent(ComponentName("com.miui.securitycenter", "com.miui.powercenter.PowerSettings"))
        )
        intentList.forEach { intent ->
            val resolved = Internal.resolveActivityList(context, intent).isNotEmpty()
            if (resolved) return true
        }
        return false
    }
    

    And resolve method:

    @Suppress("DEPRECATION")
    fun resolveActivityList(context: Context, intent: Intent): List<ResolveInfo> = with(context.packageManager) {
        return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            queryIntentActivities(intent, PackageManager.ResolveInfoFlags.of(PackageManager.MATCH_DEFAULT_ONLY.toLong()))
        } else queryIntentActivities(intent, PackageManager.GET_META_DATA)
    }