Merge "Invalidate cached result of getPackagesForUid" into sc-dev

This commit is contained in:
Jackal Guo
2021-02-03 06:57:20 +00:00
committed by Android (Google) Code Review
3 changed files with 45 additions and 26 deletions

View File

@@ -588,9 +588,12 @@ public class AppsFilter implements Watchable, Snappable {
* *
* @param recipientUid the uid gaining visibility of the {@code visibleUid}. * @param recipientUid the uid gaining visibility of the {@code visibleUid}.
* @param visibleUid the uid becoming visible to the {@recipientUid} * @param visibleUid the uid becoming visible to the {@recipientUid}
* @return {@code true} if implicit access was not already granted.
*/ */
public void grantImplicitAccess(int recipientUid, int visibleUid) { public boolean grantImplicitAccess(int recipientUid, int visibleUid) {
if (recipientUid != visibleUid) { if (recipientUid == visibleUid) {
return false;
}
final boolean changed = mImplicitlyQueryable.add(recipientUid, visibleUid); final boolean changed = mImplicitlyQueryable.add(recipientUid, visibleUid);
if (changed && DEBUG_LOGGING) { if (changed && DEBUG_LOGGING) {
Slog.i(TAG, "implicit access granted: " + recipientUid + " -> " + visibleUid); Slog.i(TAG, "implicit access granted: " + recipientUid + " -> " + visibleUid);
@@ -610,7 +613,7 @@ public class AppsFilter implements Watchable, Snappable {
if (changed) { if (changed) {
onChanged(); onChanged();
} }
} return changed;
} }
public void onSystemReady() { public void onSystemReady() {

View File

@@ -470,23 +470,34 @@ class InstantAppRegistry implements Watchable, Snappable {
return instantGrantList.get(instantAppId); return instantGrantList.get(instantAppId);
} }
/**
* Allows an app to see an instant app.
*
* @param userId the userId in which this access is being granted
* @param intent when provided, this serves as the intent that caused
* this access to be granted
* @param recipientUid the uid of the app receiving visibility
* @param instantAppId the app ID of the instant app being made visible
* to the recipient
* @return {@code true} if access is granted.
*/
@GuardedBy("mService.mLock") @GuardedBy("mService.mLock")
public void grantInstantAccessLPw(@UserIdInt int userId, @Nullable Intent intent, public boolean grantInstantAccessLPw(@UserIdInt int userId, @Nullable Intent intent,
int recipientUid, int instantAppId) { int recipientUid, int instantAppId) {
if (mInstalledInstantAppUids == null) { if (mInstalledInstantAppUids == null) {
return; // no instant apps installed; no need to grant return false; // no instant apps installed; no need to grant
} }
WatchedSparseBooleanArray instantAppList = mInstalledInstantAppUids.get(userId); WatchedSparseBooleanArray instantAppList = mInstalledInstantAppUids.get(userId);
if (instantAppList == null || !instantAppList.get(instantAppId)) { if (instantAppList == null || !instantAppList.get(instantAppId)) {
return; // instant app id isn't installed; no need to grant return false; // instant app id isn't installed; no need to grant
} }
if (instantAppList.get(recipientUid)) { if (instantAppList.get(recipientUid)) {
return; // target app id is an instant app; no need to grant return false; // target app id is an instant app; no need to grant
} }
if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) { if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) {
final Set<String> categories = intent.getCategories(); final Set<String> categories = intent.getCategories();
if (categories != null && categories.contains(Intent.CATEGORY_BROWSABLE)) { if (categories != null && categories.contains(Intent.CATEGORY_BROWSABLE)) {
return; // launched via VIEW/BROWSABLE intent; no need to grant return false; // launched via VIEW/BROWSABLE intent; no need to grant
} }
} }
WatchedSparseArray<WatchedSparseBooleanArray> targetAppList = mInstantGrants.get(userId); WatchedSparseArray<WatchedSparseBooleanArray> targetAppList = mInstantGrants.get(userId);
@@ -500,6 +511,7 @@ class InstantAppRegistry implements Watchable, Snappable {
targetAppList.put(recipientUid, instantGrantList); targetAppList.put(recipientUid, instantGrantList);
} }
instantGrantList.put(instantAppId, true /*granted*/); instantGrantList.put(instantAppId, true /*granted*/);
return true;
} }
@GuardedBy("mService.mLock") @GuardedBy("mService.mLock")

View File

@@ -27188,6 +27188,7 @@ public class PackageManagerService extends IPackageManager.Stub
final boolean instantApp = final boolean instantApp =
isInstantAppInternal(visiblePackage.getPackageName(), userId, visibleUid); isInstantAppInternal(visiblePackage.getPackageName(), userId, visibleUid);
final boolean accessGranted;
if (instantApp) { if (instantApp) {
if (!direct) { if (!direct) {
// if the interaction that lead to this granting access to an instant app // if the interaction that lead to this granting access to an instant app
@@ -27195,10 +27196,13 @@ public class PackageManagerService extends IPackageManager.Stub
// grant. // grant.
return; return;
} }
mInstantAppRegistry.grantInstantAccessLPw(userId, intent, accessGranted = mInstantAppRegistry.grantInstantAccessLPw(userId, intent,
recipientAppId, UserHandle.getAppId(visibleUid) /*instantAppId*/); recipientAppId, UserHandle.getAppId(visibleUid) /*instantAppId*/);
} else { } else {
mAppsFilter.grantImplicitAccess(recipientUid, visibleUid); accessGranted = mAppsFilter.grantImplicitAccess(recipientUid, visibleUid);
}
if (accessGranted) {
ApplicationPackageManager.invalidateGetPackagesForUidCache();
} }
} }
} }