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

Commit 5b3ec801 authored by Jack Yu's avatar Jack Yu
Browse files

Fixed get packages for HSUM devices

On HSUM devices, packages installed on secondary users can't
be retrieved by the system users' package manager. Fixed by
using corresponding user's package manager.

Fix: 356827794
Fix: 362253919
Test: Basic telephony functionality tests
Test: atest FrameworksTelephonyTests TeleServicesTests
Flag: com.android.internal.telephony.flags.hsum_broadcast
Change-Id: Ia1ce62dab3c46f9f048724850d66eab3c6542207
parent 30c37da0
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.util.Log;
import android.widget.Toast;

import com.android.internal.telephony.TelephonyPermissions;
import com.android.internal.telephony.flags.Flags;
import com.android.internal.telephony.util.TelephonyUtils;

/**
@@ -283,6 +284,8 @@ public final class LocationAccessPolicy {
        int minSdkVersion = Manifest.permission.ACCESS_FINE_LOCATION.equals(permissionToCheck)
                ? query.minSdkVersionForFine : query.minSdkVersionForCoarse;

        UserHandle callingUserHandle = UserHandle.getUserHandleForUid(query.callingUid);

        // If the app fails for some reason, see if it should be allowed to proceed.
        if (minSdkVersion > MAX_SDK_FOR_ANY_ENFORCEMENT) {
            String errorMsg = "Allowing " + query.callingPackage + " " + locationTypeForLog
@@ -291,7 +294,8 @@ public final class LocationAccessPolicy {
                    + query.method;
            logError(context, query, errorMsg);
            return null;
        } else if (!isAppAtLeastSdkVersion(context, query.callingPackage, minSdkVersion)) {
        } else if (!isAppAtLeastSdkVersion(context, callingUserHandle, query.callingPackage,
                minSdkVersion)) {
            String errorMsg = "Allowing " + query.callingPackage + " " + locationTypeForLog
                    + " because it doesn't target API " + minSdkVersion + " yet."
                    + " Please fix this app. Called from " + query.method;
@@ -420,12 +424,20 @@ public final class LocationAccessPolicy {
        }
    }

    private static boolean isAppAtLeastSdkVersion(Context context, String pkgName, int sdkVersion) {
    private static boolean isAppAtLeastSdkVersion(Context context,
            @NonNull UserHandle callingUserHandle, String pkgName, int sdkVersion) {
        try {
            if (Flags.hsumPackageManager()) {
                if (context.getPackageManager().getApplicationInfoAsUser(
                        pkgName, 0, callingUserHandle).targetSdkVersion >= sdkVersion) {
                    return true;
                }
            } else {
                if (context.getPackageManager().getApplicationInfo(pkgName, 0).targetSdkVersion
                        >= sdkVersion) {
                    return true;
                }
            }
        } catch (PackageManager.NameNotFoundException e) {
            // In case of exception, assume known app (more strict checking)
            // Note: This case will never happen since checkPackage is