Fixes NON_BROWSER flag behavior
This change modifies the time we do filtering / blocking based on the non browser flag. Before this we would filter out browsers from results in the component resolver, leading to the potential to ignore user preferences. With this change, we apply user preferences and only fail the start if the single resolve info or all potential targets sent to the resolver activity are browsers. Test: atest MatchFlagTests Fixes: 154766920 Change-Id: I0451eb2e199342d369851294ebaf4affb5fe86c6
This commit is contained in:
@@ -33,7 +33,6 @@ import android.content.pm.AuxiliaryResolveInfo;
|
||||
import android.content.pm.InstantAppResolveInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManagerInternal;
|
||||
import android.content.pm.PackageManagerInternal.PrivateResolveFlags;
|
||||
import android.content.pm.PackageUserState;
|
||||
import android.content.pm.ProviderInfo;
|
||||
import android.content.pm.ResolveInfo;
|
||||
@@ -261,10 +260,9 @@ public class ComponentResolver {
|
||||
|
||||
@Nullable
|
||||
List<ResolveInfo> queryActivities(Intent intent, String resolvedType, int flags,
|
||||
@PrivateResolveFlags int privateResolveFlags, int userId) {
|
||||
int userId) {
|
||||
synchronized (mLock) {
|
||||
return mActivities.queryIntent(
|
||||
intent, resolvedType, flags, privateResolveFlags, userId);
|
||||
return mActivities.queryIntent(intent, resolvedType, flags, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -427,7 +425,7 @@ public class ComponentResolver {
|
||||
@Nullable
|
||||
List<ResolveInfo> queryReceivers(Intent intent, String resolvedType, int flags, int userId) {
|
||||
synchronized (mLock) {
|
||||
return mReceivers.queryIntent(intent, resolvedType, flags, 0, userId);
|
||||
return mReceivers.queryIntent(intent, resolvedType, flags, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1293,12 +1291,11 @@ public class ComponentResolver {
|
||||
}
|
||||
|
||||
List<ResolveInfo> queryIntent(Intent intent, String resolvedType, int flags,
|
||||
int privateResolveFlags, int userId) {
|
||||
int userId) {
|
||||
if (!sUserManager.exists(userId)) {
|
||||
return null;
|
||||
}
|
||||
mFlags = flags;
|
||||
mPrivateResolveFlags = privateResolveFlags;
|
||||
return super.queryIntent(intent, resolvedType,
|
||||
(flags & PackageManager.MATCH_DEFAULT_ONLY) != 0,
|
||||
userId);
|
||||
@@ -1495,11 +1492,6 @@ public class ComponentResolver {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
final boolean matchNonBrowserOnly =
|
||||
(mPrivateResolveFlags & PackageManagerInternal.RESOLVE_NON_BROWSER_ONLY) != 0;
|
||||
if (matchNonBrowserOnly && info.handleAllWebDataURI()) {
|
||||
return null;
|
||||
}
|
||||
final ResolveInfo res = new ResolveInfo();
|
||||
res.activityInfo = ai;
|
||||
if ((mFlags & PackageManager.GET_RESOLVED_FILTER) != 0) {
|
||||
@@ -1579,7 +1571,6 @@ public class ComponentResolver {
|
||||
private final ArrayMap<ComponentName, ParsedActivity> mActivities =
|
||||
new ArrayMap<>();
|
||||
private int mFlags;
|
||||
private int mPrivateResolveFlags;
|
||||
}
|
||||
|
||||
// Both receivers and activities share a class, but point to different get methods
|
||||
|
||||
@@ -6388,6 +6388,11 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
final ResolveInfo bestChoice =
|
||||
chooseBestActivity(
|
||||
intent, resolvedType, flags, privateResolveFlags, query, userId);
|
||||
final boolean nonBrowserOnly =
|
||||
(privateResolveFlags & PackageManagerInternal.RESOLVE_NON_BROWSER_ONLY) != 0;
|
||||
if (nonBrowserOnly && bestChoice != null && bestChoice.handleAllWebDataURI) {
|
||||
return null;
|
||||
}
|
||||
return bestChoice;
|
||||
} finally {
|
||||
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
|
||||
@@ -6575,9 +6580,13 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
if (ri != null) {
|
||||
return ri;
|
||||
}
|
||||
// If we have an ephemeral app, use it
|
||||
int browserCount = 0;
|
||||
for (int i = 0; i < N; i++) {
|
||||
ri = query.get(i);
|
||||
if (ri.handleAllWebDataURI) {
|
||||
browserCount++;
|
||||
}
|
||||
// If we have an ephemeral app, use it
|
||||
if (ri.activityInfo.applicationInfo.isInstantApp()) {
|
||||
final String packageName = ri.activityInfo.packageName;
|
||||
final PackageSetting ps = mSettings.mPackages.get(packageName);
|
||||
@@ -6593,6 +6602,9 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
return null;
|
||||
}
|
||||
ri = new ResolveInfo(mResolveInfo);
|
||||
// if all resolve options are browsers, mark the resolver's info as if it were
|
||||
// also a browser.
|
||||
ri.handleAllWebDataURI = browserCount == N;
|
||||
ri.activityInfo = new ActivityInfo(ri.activityInfo);
|
||||
ri.activityInfo.labelRes = ResolverActivity.getLabelRes(intent.getAction());
|
||||
// If all of the options come from the same package, show the application's
|
||||
@@ -7103,7 +7115,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
|
||||
// Check for results in the current profile.
|
||||
result = filterIfNotSystemUser(mComponentResolver.queryActivities(
|
||||
intent, resolvedType, flags, privateResolveFlags, userId), userId);
|
||||
intent, resolvedType, flags, userId), userId);
|
||||
addInstant = isInstantAppResolutionAllowed(intent, result, userId,
|
||||
false /*skipPackageCheck*/);
|
||||
// Check for cross profile results.
|
||||
@@ -7202,7 +7214,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
| PackageManager.GET_RESOLVED_FILTER
|
||||
| PackageManager.MATCH_INSTANT
|
||||
| PackageManager.MATCH_VISIBLE_TO_INSTANT_APP_ONLY,
|
||||
0, userId);
|
||||
userId);
|
||||
for (int i = instantApps.size() - 1; i >= 0; --i) {
|
||||
final ResolveInfo info = instantApps.get(i);
|
||||
final String packageName = info.activityInfo.packageName;
|
||||
@@ -7306,7 +7318,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
return null;
|
||||
}
|
||||
List<ResolveInfo> resultTargetUser = mComponentResolver.queryActivities(intent,
|
||||
resolvedType, flags, 0, parentUserId);
|
||||
resolvedType, flags, parentUserId);
|
||||
|
||||
if (resultTargetUser == null || resultTargetUser.isEmpty()) {
|
||||
return null;
|
||||
@@ -7754,7 +7766,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
String resolvedType, int flags, int sourceUserId) {
|
||||
int targetUserId = filter.getTargetUserId();
|
||||
List<ResolveInfo> resultTargetUser = mComponentResolver.queryActivities(intent,
|
||||
resolvedType, flags, 0, targetUserId);
|
||||
resolvedType, flags, targetUserId);
|
||||
if (resultTargetUser != null && isUserEnabled(targetUserId)) {
|
||||
// If all the matches in the target profile are suspended, return null.
|
||||
for (int i = resultTargetUser.size() - 1; i >= 0; i--) {
|
||||
|
||||
Reference in New Issue
Block a user