Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dc18f008 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Ensure launch intent matches boot unaware packages" into rvc-dev

parents 3220af70 2702e5f5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -113,7 +113,7 @@ class UserSensitivityLiveData private constructor(
                // The launcher packages set will only be null when it is uninitialized.
                LauncherPackagesLiveData.value?.contains(pkg.packageName) ?: return
            } else {
                pm.getLaunchIntentForPackage(pkg.packageName) != null
                KotlinUtils.packageHasLaunchIntent(context, pkg.packageName)
            }
            val pkgIsSystemApp = pkg.appFlags and ApplicationInfo.FLAG_SYSTEM != 0
            // Iterate through all runtime perms, setting their keys
+42 −10
Original line number Diff line number Diff line
@@ -26,6 +26,10 @@ import android.app.AppOpsManager.MODE_IGNORED
import android.app.AppOpsManager.permissionToOp
import android.app.Application
import android.content.Context
import android.content.Intent
import android.content.Intent.ACTION_MAIN
import android.content.Intent.CATEGORY_INFO
import android.content.Intent.CATEGORY_LAUNCHER
import android.content.pm.PackageManager
import android.content.pm.PackageManager.FLAG_PERMISSION_AUTO_REVOKED
import android.content.pm.PackageManager.FLAG_PERMISSION_ONE_TIME
@@ -33,6 +37,8 @@ import android.content.pm.PackageManager.FLAG_PERMISSION_REVIEW_REQUIRED
import android.content.pm.PackageManager.FLAG_PERMISSION_REVOKED_COMPAT
import android.content.pm.PackageManager.FLAG_PERMISSION_USER_FIXED
import android.content.pm.PackageManager.FLAG_PERMISSION_USER_SET
import android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AWARE
import android.content.pm.PackageManager.MATCH_DIRECT_BOOT_UNAWARE
import android.content.pm.PermissionGroupInfo
import android.content.pm.PermissionInfo
import android.graphics.drawable.Drawable
@@ -796,6 +802,32 @@ object KotlinUtils {
        manager.setUidMode(op, uid, mode)
        return true
    }

    /**
     * Determine if a given package has a launch intent. Will function correctly even if called
     * before user is unlocked.
     *
     * @param context: The context from which to retrieve the package
     * @param packageName: The package name to check
     *
     * @return whether or not the given package has a launch intent
     */
    fun packageHasLaunchIntent(context: Context, packageName: String): Boolean {
        val intentToResolve = Intent(ACTION_MAIN)
        intentToResolve.addCategory(CATEGORY_INFO)
        intentToResolve.setPackage(packageName)
        var resolveInfos = context.packageManager.queryIntentActivities(intentToResolve,
            MATCH_DIRECT_BOOT_AWARE or MATCH_DIRECT_BOOT_UNAWARE)

        if (resolveInfos == null || resolveInfos.size <= 0) {
            intentToResolve.removeCategory(CATEGORY_INFO)
            intentToResolve.addCategory(CATEGORY_LAUNCHER)
            intentToResolve.setPackage(packageName)
            resolveInfos = context.packageManager.queryIntentActivities(intentToResolve,
                MATCH_DIRECT_BOOT_AWARE or MATCH_DIRECT_BOOT_UNAWARE)
        }
        return resolveInfos != null && resolveInfos.size > 0
    }
}

/**