Merge "Grants visibility on uri permission grant" into rvc-dev am: cb2d2ec786 am: 062ecb1f48

Change-Id: Ie52beab8e99bf9b7b53c7d0d079bf69b174fe1d6
This commit is contained in:
Automerger Merge Worker
2020-02-25 16:11:51 +00:00
9 changed files with 48 additions and 34 deletions

View File

@@ -458,8 +458,8 @@ public abstract class PackageManagerInternal {
Bundle verificationBundle, int userId);
/**
* Grants implicit access based on an interaction between two apps. This grants the target app
* access to the calling application's package metadata.
* Grants implicit access based on an interaction between two apps. This grants access to the
* from one application to the other's package metadata.
* <p>
* When an application explicitly tries to interact with another application [via an
* activity, service or provider that is either declared in the caller's
@@ -468,14 +468,22 @@ public abstract class PackageManagerInternal {
* metadata about the calling app. If the calling application uses an implicit intent [ie
* action VIEW, category BROWSABLE], it remains hidden from the launched app.
* <p>
* If an interaction is not explicit, the {@code direct} argument should be set to false as
* visibility should not be granted in some cases. This method handles that logic.
* <p>
* @param userId the user
* @param intent the intent that triggered the grant
* @param callingUid The uid of the calling application
* @param targetAppId The app ID of the target application
* @param recipientAppId The app ID of the application that is being given access to {@code
* visibleUid}
* @param visibleUid The uid of the application that is becoming accessible to {@code
* recipientAppId}
* @param direct true if the access is being made due to direct interaction between visibleUid
* and recipientAppId.
*/
public abstract void grantImplicitAccess(
@UserIdInt int userId, Intent intent, int callingUid,
@AppIdInt int targetAppId);
@UserIdInt int userId, Intent intent,
@AppIdInt int recipientAppId, int visibleUid,
boolean direct);
public abstract boolean isInstantAppInstallerComponent(ComponentName component);
/**

View File

@@ -6287,9 +6287,9 @@ public class ActivityManagerService extends IActivityManager.Stub
}
@VisibleForTesting
public void grantImplicitAccess(int userId, Intent intent, int callingUid, int targetAppId) {
public void grantImplicitAccess(int userId, Intent intent, int visibleUid, int recipientAppId) {
getPackageManagerInternalLocked().
grantImplicitAccess(userId, intent, callingUid, targetAppId);
grantImplicitAccess(userId, intent, recipientAppId, visibleUid, true /*direct*/);
}
/**

View File

@@ -354,14 +354,13 @@ public class AppsFilter {
* Grants access based on an interaction between a calling and target package, granting
* visibility of the caller from the target.
*
* @param callingUid the uid initiating the interaction
* @param targetUid the uid being interacted with and thus gaining visibility of the
* initiating uid.
* @param recipientUid the uid gaining visibility of the {@code visibleUid}.
* @param visibleUid the uid becoming visible to the {@recipientUid}
*/
public void grantImplicitAccess(int callingUid, int targetUid) {
if (targetUid != callingUid
&& mImplicitlyQueryable.add(targetUid, callingUid) && DEBUG_LOGGING) {
Slog.wtf(TAG, "implicit access granted: " + targetUid + " -> " + callingUid);
public void grantImplicitAccess(int recipientUid, int visibleUid) {
if (recipientUid != visibleUid
&& mImplicitlyQueryable.add(recipientUid, visibleUid) && DEBUG_LOGGING) {
Slog.wtf(TAG, "implicit access granted: " + recipientUid + " -> " + visibleUid);
}
}

View File

@@ -403,7 +403,7 @@ class InstantAppRegistry {
@GuardedBy("mService.mLock")
public void grantInstantAccessLPw(@UserIdInt int userId, @Nullable Intent intent,
int instantAppId, int targetAppId) {
int recipientUid, int instantAppId) {
if (mInstalledInstantAppUids == null) {
return; // no instant apps installed; no need to grant
}
@@ -411,7 +411,7 @@ class InstantAppRegistry {
if (instantAppList == null || !instantAppList.get(instantAppId)) {
return; // instant app id isn't installed; no need to grant
}
if (instantAppList.get(targetAppId)) {
if (instantAppList.get(recipientUid)) {
return; // target app id is an instant app; no need to grant
}
if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) {
@@ -428,10 +428,10 @@ class InstantAppRegistry {
targetAppList = new SparseArray<>();
mInstantGrants.put(userId, targetAppList);
}
SparseBooleanArray instantGrantList = targetAppList.get(targetAppId);
SparseBooleanArray instantGrantList = targetAppList.get(recipientUid);
if (instantGrantList == null) {
instantGrantList = new SparseBooleanArray();
targetAppList.put(targetAppId, instantGrantList);
targetAppList.put(recipientUid, instantGrantList);
}
instantGrantList.put(instantAppId, true /*granted*/);
}

View File

@@ -23589,22 +23589,27 @@ public class PackageManagerService extends IPackageManager.Stub
@Override
public void grantImplicitAccess(int userId, Intent intent,
int callingUid, int targetAppId) {
int recipientAppId, int visibleUid, boolean direct) {
synchronized (mLock) {
final AndroidPackage callingPackage = getPackage(callingUid);
final int targetUid = UserHandle.getUid(userId, targetAppId);
final AndroidPackage targetPackage = getPackage(targetUid);
if (callingPackage == null || targetPackage == null) {
final AndroidPackage visiblePackage = getPackage(visibleUid);
final int recipientUid = UserHandle.getUid(userId, recipientAppId);
if (visiblePackage == null || getPackage(recipientUid) == null) {
return;
}
final boolean instantApp = isInstantAppInternal(callingPackage.getPackageName(),
userId, callingUid);
final boolean instantApp =
isInstantAppInternal(visiblePackage.getPackageName(), userId, visibleUid);
if (instantApp) {
if (!direct) {
// if the interaction that lead to this granting access to an instant app
// was indirect (i.e.: URI permission grant), do not actually execute the
// grant.
return;
}
mInstantAppRegistry.grantInstantAccessLPw(userId, intent,
UserHandle.getAppId(callingUid), targetAppId);
recipientAppId, UserHandle.getAppId(visibleUid) /*instantAppId*/);
} else {
mAppsFilter.grantImplicitAccess(callingUid, targetUid);
mAppsFilter.grantImplicitAccess(recipientUid, visibleUid);
}
}
}

View File

@@ -739,6 +739,8 @@ public class UriGrantsManagerService extends IUriGrantsManager.Stub {
final UriPermission perm = findOrCreateUriPermission(
pi.packageName, targetPkg, targetUid, grantUri);
perm.grantModes(modeFlags, owner);
getPmInternal().grantImplicitAccess(UserHandle.getUserId(targetUid), null,
UserHandle.getAppId(targetUid), pi.applicationInfo.uid, false /*direct*/);
}
/** Like grantUriPermissionUnchecked, but takes an Intent. */

View File

@@ -211,8 +211,9 @@ public class WebViewUpdateService extends SystemService {
PackageManagerInternal.class);
final int webviewUid = pmInternal.getPackageUidInternal(
webViewPackageName, 0, UserHandle.getUserId(callingUid));
pmInternal.grantImplicitAccess(UserHandle.getUserId(callingUid), null, webviewUid,
UserHandle.getAppId(callingUid));
pmInternal.grantImplicitAccess(UserHandle.getUserId(callingUid), null,
UserHandle.getAppId(callingUid), webviewUid,
true /*direct*/);
}
/**

View File

@@ -1565,9 +1565,8 @@ class ActivityStarter {
mIntent, mStartActivity.getUriPermissionsLocked(), mStartActivity.mUserId);
mService.getPackageManagerInternalLocked().grantImplicitAccess(
mStartActivity.mUserId, mIntent,
mCallingUid,
UserHandle.getAppId(mStartActivity.info.applicationInfo.uid)
);
UserHandle.getAppId(mStartActivity.info.applicationInfo.uid), mCallingUid,
true /*direct*/);
if (newTask) {
EventLogTags.writeWmCreateTask(mStartActivity.mUserId,
mStartActivity.getTask().mTaskId);

View File

@@ -348,7 +348,7 @@ public class ActivityStarterTests extends ActivityTestsBase {
// Never review permissions
doReturn(false).when(mMockPackageManager).isPermissionsReviewRequired(any(), anyInt());
doNothing().when(mMockPackageManager).grantImplicitAccess(
anyInt(), any(), anyInt(), anyInt());
anyInt(), any(), anyInt(), anyInt(), anyBoolean());
doNothing().when(mMockPackageManager).notifyPackageUse(anyString(), anyInt());
final Intent intent = new Intent();