Merge "Expose grantImplicitAccess in IPackageManager" into rvc-qpr-dev am: e530998c9e

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

Change-Id: I31db3a2016da589f2c0b7f4bc955a870ebc384c5
This commit is contained in:
Patrick Baumann
2020-09-23 18:28:16 +00:00
committed by Automerger Merge Worker
3 changed files with 43 additions and 0 deletions

View File

@@ -785,4 +785,6 @@ interface IPackageManager {
List<String> getMimeGroup(String packageName, String group);
boolean isAutoRevokeWhitelisted(String packageName);
void grantImplicitAccess(int queryingUid, String visibleAuthority);
}

View File

@@ -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.

View File

@@ -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;
@@ -25426,6 +25427,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.USER_SYSTEM);
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);