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

Commit cc3c2d99 authored by kholoud mohamed's avatar kholoud mohamed Committed by Kholoud Mohamed
Browse files

Fix bug in CrossProfileApps#canInteractAcrossProfiles

Changed canInteractAcrossProfiles to check that all other profiles have the appop enabled to return true,
previously it only checked the appop for the calling uid, which should
theoretically be always in sync with the other profiles, but we got a
bug were it wasn't in sync for an unidentified reason.

Test: atest com.android.cts.devicepolicy.CrossProfileAppsPermissionHostSideTest
Bug: 182396357
Bug: 183188804
Change-Id: Ied170ee87358ffa248bf4315d93a736f7307a3b2
parent 9aeedf48
Loading
Loading
Loading
Loading
+25 −1
Original line number Original line Diff line number Diff line
@@ -288,7 +288,9 @@ public class CrossProfileAppsServiceImpl extends ICrossProfileApps.Stub {
        if (targetUserProfiles.isEmpty()) {
        if (targetUserProfiles.isEmpty()) {
            return false;
            return false;
        }
        }
        return hasCallerGotInteractAcrossProfilesPermission(callingPackage);
        return hasCallerGotInteractAcrossProfilesPermission(callingPackage)
                && haveProfilesGotInteractAcrossProfilesPermission(
                        callingPackage, targetUserProfiles);
    }
    }


    private boolean hasCallerGotInteractAcrossProfilesPermission(String callingPackage) {
    private boolean hasCallerGotInteractAcrossProfilesPermission(String callingPackage) {
@@ -296,6 +298,28 @@ public class CrossProfileAppsServiceImpl extends ICrossProfileApps.Stub {
                callingPackage, mInjector.getCallingUid(), mInjector.getCallingPid());
                callingPackage, mInjector.getCallingUid(), mInjector.getCallingPid());
    }
    }


    private boolean haveProfilesGotInteractAcrossProfilesPermission(
            String packageName, List<UserHandle> profiles) {
        for (UserHandle profile : profiles) {
            final int uid = mInjector.withCleanCallingIdentity(() -> {
                try {
                    return mInjector.getPackageManager().getPackageUidAsUser(
                            packageName, /* flags= */ 0, profile.getIdentifier());
                } catch (PackageManager.NameNotFoundException e) {
                    return -1;
                }
            });
            if (uid == -1) {
                return false;
            }
            if (!hasInteractAcrossProfilesPermission(
                    packageName, uid, PermissionChecker.PID_UNKNOWN)) {
                return false;
            }
        }
        return true;
    }

    private boolean isCrossProfilePackageAllowlisted(String packageName) {
    private boolean isCrossProfilePackageAllowlisted(String packageName) {
        return mInjector.withCleanCallingIdentity(() ->
        return mInjector.withCleanCallingIdentity(() ->
                mInjector.getDevicePolicyManagerInternal()
                mInjector.getDevicePolicyManagerInternal()