Merge "Grants app visibility to both ends of instrumentation" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
bb5769554d
@@ -481,6 +481,12 @@ public class AppsFilter {
|
||||
mQueriesViaPackage.add(newPkgSetting.appId, existingSetting.appId);
|
||||
}
|
||||
}
|
||||
// if either package instruments the other, mark both as visible to one another
|
||||
if (pkgInstruments(newPkgSetting, existingSetting)
|
||||
|| pkgInstruments(existingSetting, newPkgSetting)) {
|
||||
mQueriesViaPackage.add(newPkgSetting.appId, existingSetting.appId);
|
||||
mQueriesViaPackage.add(existingSetting.appId, newPkgSetting.appId);
|
||||
}
|
||||
}
|
||||
|
||||
int existingSize = existingSettings.size();
|
||||
@@ -715,19 +721,6 @@ public class AppsFilter {
|
||||
Trace.endSection();
|
||||
}
|
||||
|
||||
if (callingPkgSetting != null) {
|
||||
if (callingPkgInstruments(callingPkgSetting, targetPkgSetting, targetName)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
for (int i = callingSharedPkgSettings.size() - 1; i >= 0; i--) {
|
||||
if (callingPkgInstruments(callingSharedPkgSettings.valueAt(i),
|
||||
targetPkgSetting, targetName)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
Trace.beginSection("mOverlayReferenceMapper");
|
||||
if (callingSharedPkgSettings != null) {
|
||||
@@ -762,16 +755,16 @@ public class AppsFilter {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean callingPkgInstruments(PackageSetting callingPkgSetting,
|
||||
PackageSetting targetPkgSetting,
|
||||
String targetName) {
|
||||
/** Returns {@code true} if the source package instruments the target package. */
|
||||
private static boolean pkgInstruments(PackageSetting source, PackageSetting target) {
|
||||
try {
|
||||
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "callingPkgInstruments");
|
||||
final List<ParsedInstrumentation> inst = callingPkgSetting.pkg.getInstrumentations();
|
||||
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "pkgInstruments");
|
||||
final String packageName = target.pkg.getPackageName();
|
||||
final List<ParsedInstrumentation> inst = source.pkg.getInstrumentations();
|
||||
for (int i = ArrayUtils.size(inst) - 1; i >= 0; i--) {
|
||||
if (Objects.equals(inst.get(i).getTargetPackage(), targetName)) {
|
||||
if (Objects.equals(inst.get(i).getTargetPackage(), packageName)) {
|
||||
if (DEBUG_LOGGING) {
|
||||
log(callingPkgSetting, targetPkgSetting, "instrumentation");
|
||||
log(source, target, "instrumentation");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import android.content.pm.PackageParser;
|
||||
import android.content.pm.Signature;
|
||||
import android.content.pm.parsing.ParsingPackage;
|
||||
import android.content.pm.parsing.component.ParsedActivity;
|
||||
import android.content.pm.parsing.component.ParsedInstrumentation;
|
||||
import android.content.pm.parsing.component.ParsedIntentInfo;
|
||||
import android.content.pm.parsing.component.ParsedProvider;
|
||||
import android.os.Build;
|
||||
@@ -135,6 +136,13 @@ public class AppsFilterTest {
|
||||
.addActivity(activity);
|
||||
}
|
||||
|
||||
private static ParsingPackage pkgWithInstrumentation(
|
||||
String packageName, String instrumentationTargetPackage) {
|
||||
ParsedInstrumentation instrumentation = new ParsedInstrumentation();
|
||||
instrumentation.setTargetPackage(instrumentationTargetPackage);
|
||||
return pkg(packageName).addInstrumentation(instrumentation);
|
||||
}
|
||||
|
||||
private static ParsingPackage pkgWithProvider(String packageName, String authority) {
|
||||
ParsedProvider provider = new ParsedProvider();
|
||||
provider.setPackageName(packageName);
|
||||
@@ -608,6 +616,25 @@ public class AppsFilterTest {
|
||||
assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_UID, calling, target, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInstrumentation_DoesntFilter() {
|
||||
final AppsFilter appsFilter =
|
||||
new AppsFilter(mFeatureConfigMock, new String[]{}, false, null);
|
||||
appsFilter.onSystemReady();
|
||||
|
||||
|
||||
PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"),
|
||||
DUMMY_TARGET_UID);
|
||||
PackageSetting instrumentation = simulateAddPackage(appsFilter,
|
||||
pkgWithInstrumentation("com.some.other.package", "com.some.package"),
|
||||
DUMMY_CALLING_UID);
|
||||
|
||||
assertFalse(
|
||||
appsFilter.shouldFilterApplication(DUMMY_CALLING_UID, instrumentation, target, 0));
|
||||
assertFalse(
|
||||
appsFilter.shouldFilterApplication(DUMMY_TARGET_UID, target, instrumentation, 0));
|
||||
}
|
||||
|
||||
private interface WithSettingBuilder {
|
||||
PackageSettingBuilder withBuilder(PackageSettingBuilder builder);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user