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

Commit 638bab6e authored by Patrick Baumann's avatar Patrick Baumann Committed by Gerrit Code Review
Browse files

Merge "Expose grantImplicitAccess in IPackageManager"

parents 06c47e70 48afc444
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;
@@ -25400,6 +25401,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);