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

Commit e756364b authored by Patrick Baumann's avatar Patrick Baumann Committed by Automerger Merge Worker
Browse files

Merge "Expose grantImplicitAccess in IPackageManager" am: 638bab6e am: 76f1cd8f am: 11b68dfb

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1441675

Change-Id: Ia83d20322964e280241c4eac54af68b51a0e304e
parents 198e7d36 11b68dfb
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -785,4 +785,6 @@ interface IPackageManager {
    List<String> getMimeGroup(String packageName, String group);

    boolean isAutoRevokeWhitelisted(String packageName);

    void grantImplicitAccess(int queryingUid, String visibleAuthority);
}
+14 −0
Original line number Diff line number Diff line
@@ -8018,6 +8018,20 @@ public abstract class PackageManager {
                "getMimeGroup not implemented in subclass");
    }

    /**
     * Grants implicit visibility of the package that provides an authority to a querying UID.
     *
     * @throws SecurityException when called by a package other than the contacts provider
     * @hide
     */
    public void grantImplicitAccess(int queryingUid, String visibleAuthority) {
        try {
            ActivityThread.getPackageManager().grantImplicitAccess(queryingUid, visibleAuthority);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    // Some of the flags don't affect the query result, but let's be conservative and cache
    // each combination of flags separately.

+27 −0
Original line number Diff line number Diff line
@@ -280,6 +280,7 @@ import android.os.storage.StorageManagerInternal;
import android.os.storage.VolumeInfo;
import android.os.storage.VolumeRecord;
import android.permission.IPermissionManager;
import android.provider.ContactsContract;
import android.provider.DeviceConfig;
import android.provider.Settings.Global;
import android.provider.Settings.Secure;
@@ -25418,6 +25419,32 @@ public class PackageManagerService extends IPackageManager.Stub
        }
    }
    @Override
    public void grantImplicitAccess(int recipientUid, String visibleAuthority) {
        // This API is exposed temporarily to only the contacts provider. (b/158688602)
        final int callingUid = Binder.getCallingUid();
        ProviderInfo contactsProvider = resolveContentProviderInternal(
                        ContactsContract.AUTHORITY, 0, UserHandle.getUserId(callingUid));
        if (contactsProvider == null || contactsProvider.applicationInfo == null
                || !UserHandle.isSameApp(contactsProvider.applicationInfo.uid, callingUid)) {
            throw new SecurityException(callingUid + " is not allow to call grantImplicitAccess");
        }
        final int userId = UserHandle.getUserId(recipientUid);
        final long token = Binder.clearCallingIdentity();
        final ProviderInfo providerInfo;
        try {
            providerInfo = resolveContentProvider(visibleAuthority, 0 /*flags*/, userId);
        } finally {
            Binder.restoreCallingIdentity(token);
        }
        if (providerInfo == null) {
            return;
        }
        int visibleUid = providerInfo.applicationInfo.uid;
        mPmInternal.grantImplicitAccess(userId, null /*Intent*/, UserHandle.getAppId(recipientUid),
                visibleUid, false);
    }
    boolean canHaveOatDir(String packageName) {
        synchronized (mLock) {
            AndroidPackage p = mPackages.get(packageName);