Merge "Apply package visibility to cached ServiceRecord" into sc-dev

This commit is contained in:
Jackal Guo
2021-02-02 05:31:42 +00:00
committed by Android (Google) Code Review

View File

@@ -2815,12 +2815,24 @@ public final class ActiveServices {
r = smap.mServicesByIntent.get(filter); r = smap.mServicesByIntent.get(filter);
if (DEBUG_SERVICE && r != null) Slog.v(TAG_SERVICE, "Retrieved by intent: " + r); if (DEBUG_SERVICE && r != null) Slog.v(TAG_SERVICE, "Retrieved by intent: " + r);
} }
if (r != null && (r.serviceInfo.flags & ServiceInfo.FLAG_EXTERNAL_SERVICE) != 0 if (r != null) {
&& !callingPackage.equals(r.packageName)) { // Compared to resolveService below, the ServiceRecord here is retrieved from
// If an external service is running within its own package, other packages // ServiceMap so the package visibility doesn't apply to it. We need to filter it.
// should not bind to that instance. if (mAm.getPackageManagerInternal().filterAppAccess(r.packageName, callingUid,
r = null; userId)) {
if (DEBUG_SERVICE) Slog.v(TAG_SERVICE, "Whoops, can't use existing external service"); Slog.w(TAG_SERVICE, "Unable to start service " + service + " U=" + userId
+ ": not found");
return null;
}
if ((r.serviceInfo.flags & ServiceInfo.FLAG_EXTERNAL_SERVICE) != 0
&& !callingPackage.equals(r.packageName)) {
// If an external service is running within its own package, other packages
// should not bind to that instance.
r = null;
if (DEBUG_SERVICE) {
Slog.v(TAG_SERVICE, "Whoops, can't use existing external service");
}
}
} }
if (r == null) { if (r == null) {
try { try {