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

Commit 349e214d authored by Holly Jiuyu Sun's avatar Holly Jiuyu Sun
Browse files

Add grant and revoke default permissions to active LUI app.

Grant the camera permission to the active LUI app since LUI uses QR scanner
to download profile.
Before it, revoke the previously granted permissions first.

Bug: 35068517
Test: test on phone
Change-Id: I2db9597eed423835b9499ef6000579b5ee5b2cb6
parent bf47ae31
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -619,6 +619,8 @@ interface IPackageManager {
            in String[] packageNames, int userId);
    void revokeDefaultPermissionsFromDisabledTelephonyDataServices(
            in String[] packageNames, int userId);
    void grantDefaultPermissionsToActiveLuiApp(in String packageName, int userId);
    void revokeDefaultPermissionsFromLuiApps(in String[] packageNames, int userId);

    boolean isPermissionRevokedByPolicy(String permission, String packageName, int userId);

+27 −0
Original line number Diff line number Diff line
@@ -24053,6 +24053,33 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
        }
    }
    @Override
    public void grantDefaultPermissionsToActiveLuiApp(String packageName, int userId) {
        enforceSystemOrPhoneCaller("grantDefaultPermissionsToActiveLuiApp");
        synchronized (mPackages) {
            final long identity = Binder.clearCallingIdentity();
            try {
                mDefaultPermissionPolicy.grantDefaultPermissionsToActiveLuiApp(
                        packageName, userId);
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
        }
    }
    @Override
    public void revokeDefaultPermissionsFromLuiApps(String[] packageNames, int userId) {
        enforceSystemOrPhoneCaller("revokeDefaultPermissionsFromLuiApps");
        synchronized (mPackages) {
            final long identity = Binder.clearCallingIdentity();
            try {
                mDefaultPermissionPolicy.revokeDefaultPermissionsFromLuiApps(packageNames, userId);
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
        }
    }
    private static void enforceSystemOrPhoneCaller(String tag) {
        int callingUid = Binder.getCallingUid();
        if (callingUid != Process.PHONE_UID && callingUid != Process.SYSTEM_UID) {
+26 −0
Original line number Diff line number Diff line
@@ -1010,6 +1010,32 @@ public final class DefaultPermissionGrantPolicy {
        }
    }

    public void grantDefaultPermissionsToActiveLuiApp(String packageName, int userId) {
        Log.i(TAG, "Granting permissions to active LUI app for user:" + userId);
        if (packageName == null) {
            return;
        }
        PackageParser.Package luiAppPackage = getSystemPackage(packageName);
        if (luiAppPackage != null
                && doesPackageSupportRuntimePermissions(luiAppPackage)) {
            grantRuntimePermissions(luiAppPackage, CAMERA_PERMISSIONS, true, userId);
        }
    }

    public void revokeDefaultPermissionsFromLuiApps(String[] packageNames, int userId) {
        Log.i(TAG, "Revoke permissions from LUI apps for user:" + userId);
        if (packageNames == null) {
            return;
        }
        for (String packageName : packageNames) {
            PackageParser.Package luiAppPackage = getSystemPackage(packageName);
            if (luiAppPackage != null
                    && doesPackageSupportRuntimePermissions(luiAppPackage)) {
                revokeRuntimePermissions(luiAppPackage, CAMERA_PERMISSIONS, true, userId);
            }
        }
    }

    public void grantDefaultPermissionsToDefaultBrowser(String packageName, int userId) {
        Log.i(TAG, "Granting permissions to default browser for user:" + userId);
        if (packageName == null) {