Hide all AppsFilter tracing behind flag

This is a short term fix to hide all current tracing behind a DEBUG_
flag to avoid the noise it creates while tracing.

Fixes: 170897433
Test: AppEnumerationTests, AppsFilterTests
Change-Id: I53a82bb05a27a2721da6868699b09943608fad4e
This commit is contained in:
Patrick Baumann
2021-05-18 14:30:26 -07:00
parent ded8923d52
commit 586215fe1b

View File

@@ -84,6 +84,7 @@ public class AppsFilter implements Watchable, Snappable {
// Logs all filtering instead of enforcing
private static final boolean DEBUG_ALLOW_ALL = false;
private static final boolean DEBUG_LOGGING = false;
private static final boolean DEBUG_TRACING = false;
/**
* This contains a list of app UIDs that are implicitly queryable because another app explicitly
@@ -363,21 +364,29 @@ public class AppsFilter implements Watchable, Snappable {
@Override
public boolean isGloballyEnabled() {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "isGloballyEnabled");
if (DEBUG_TRACING) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "isGloballyEnabled");
}
try {
return mFeatureEnabled;
} finally {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
if (DEBUG_TRACING) {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
}
}
}
@Override
public boolean packageIsEnabled(AndroidPackage pkg) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "packageIsEnabled");
if (DEBUG_TRACING) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "packageIsEnabled");
}
try {
return !mDisabledPackages.contains(pkg.getPackageName());
} finally {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
if (DEBUG_TRACING) {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
}
}
}
@@ -656,7 +665,9 @@ public class AppsFilter implements Watchable, Snappable {
* @param isReplace if the package is being replaced and may need extra cleanup.
*/
public void addPackage(PackageSetting newPkgSetting, boolean isReplace) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "filter.addPackage");
if (DEBUG_TRACING) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "filter.addPackage");
}
try {
if (isReplace) {
// let's first remove any prior rules for this package
@@ -689,7 +700,9 @@ public class AppsFilter implements Watchable, Snappable {
});
} finally {
onChanged();
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
if (DEBUG_TRACING) {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
}
}
}
@@ -1173,7 +1186,9 @@ public class AppsFilter implements Watchable, Snappable {
*/
public boolean shouldFilterApplication(int callingUid, @Nullable SettingBase callingSetting,
PackageSetting targetPkgSetting, int userId) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "shouldFilterApplication");
if (DEBUG_TRACING) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "shouldFilterApplication");
}
try {
int callingAppId = UserHandle.getAppId(callingUid);
if (callingAppId < Process.FIRST_APPLICATION_UID
@@ -1211,13 +1226,17 @@ public class AppsFilter implements Watchable, Snappable {
}
return !DEBUG_ALLOW_ALL;
} finally {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
if (DEBUG_TRACING) {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
}
}
}
private boolean shouldFilterApplicationInternal(int callingUid, SettingBase callingSetting,
PackageSetting targetPkgSetting, int targetUserId) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "shouldFilterApplicationInternal");
if (DEBUG_TRACING) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "shouldFilterApplicationInternal");
}
try {
final boolean featureEnabled = mFeatureConfig.isGloballyEnabled();
if (!featureEnabled) {
@@ -1232,7 +1251,9 @@ public class AppsFilter implements Watchable, Snappable {
}
final PackageSetting callingPkgSetting;
final ArraySet<PackageSetting> callingSharedPkgSettings;
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "callingSetting instanceof");
if (DEBUG_TRACING) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "callingSetting instanceof");
}
if (callingSetting instanceof PackageSetting) {
if (((PackageSetting) callingSetting).sharedUser == null) {
callingPkgSetting = (PackageSetting) callingSetting;
@@ -1246,7 +1267,9 @@ public class AppsFilter implements Watchable, Snappable {
callingPkgSetting = null;
callingSharedPkgSettings = ((SharedUserSetting) callingSetting).packages;
}
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
if (DEBUG_TRACING) {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
}
if (callingPkgSetting != null) {
if (callingPkgSetting.pkg != null
@@ -1282,7 +1305,9 @@ public class AppsFilter implements Watchable, Snappable {
return false;
}
final String targetName = targetPkg.getPackageName();
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "getAppId");
if (DEBUG_TRACING) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "getAppId");
}
final int callingAppId;
if (callingPkgSetting != null) {
callingAppId = callingPkgSetting.appId;
@@ -1290,7 +1315,9 @@ public class AppsFilter implements Watchable, Snappable {
callingAppId = callingSharedPkgSettings.valueAt(0).appId; // all should be the same
}
final int targetAppId = targetPkgSetting.appId;
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
if (DEBUG_TRACING) {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
}
if (callingAppId == targetAppId) {
if (DEBUG_LOGGING) {
log(callingSetting, targetPkgSetting, "same app id");
@@ -1299,7 +1326,9 @@ public class AppsFilter implements Watchable, Snappable {
}
try {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "requestsQueryAllPackages");
if (DEBUG_TRACING) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "requestsQueryAllPackages");
}
if (callingPkgSetting != null) {
if (callingPkgSetting.pkg != null
&& requestsQueryAllPackages(callingPkgSetting.pkg)) {
@@ -1314,10 +1343,14 @@ public class AppsFilter implements Watchable, Snappable {
}
}
} finally {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
if (DEBUG_TRACING) {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
}
}
try {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "mForceQueryable");
if (DEBUG_TRACING) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "mForceQueryable");
}
if (mForceQueryable.contains(targetAppId)) {
if (DEBUG_LOGGING) {
log(callingSetting, targetPkgSetting, "force queryable");
@@ -1325,10 +1358,14 @@ public class AppsFilter implements Watchable, Snappable {
return false;
}
} finally {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
if (DEBUG_TRACING) {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
}
}
try {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "mQueriesViaPackage");
if (DEBUG_TRACING) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "mQueriesViaPackage");
}
if (mQueriesViaPackage.contains(callingAppId, targetAppId)) {
if (DEBUG_LOGGING) {
log(callingSetting, targetPkgSetting, "queries package");
@@ -1336,10 +1373,14 @@ public class AppsFilter implements Watchable, Snappable {
return false;
}
} finally {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
if (DEBUG_TRACING) {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
}
}
try {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "mQueriesViaComponent");
if (DEBUG_TRACING) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "mQueriesViaComponent");
}
if (mQueriesViaComponentRequireRecompute) {
mStateProvider.runWithState((settings, users) -> {
recomputeComponentVisibility(settings);
@@ -1352,11 +1393,15 @@ public class AppsFilter implements Watchable, Snappable {
return false;
}
} finally {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
if (DEBUG_TRACING) {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
}
}
try {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "mImplicitlyQueryable");
if (DEBUG_TRACING) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "mImplicitlyQueryable");
}
final int targetUid = UserHandle.getUid(targetUserId, targetAppId);
if (mImplicitlyQueryable.contains(callingUid, targetUid)) {
if (DEBUG_LOGGING) {
@@ -1365,11 +1410,15 @@ public class AppsFilter implements Watchable, Snappable {
return false;
}
} finally {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
if (DEBUG_TRACING) {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
}
}
try {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "mOverlayReferenceMapper");
if (DEBUG_TRACING) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "mOverlayReferenceMapper");
}
if (callingSharedPkgSettings != null) {
int size = callingSharedPkgSettings.size();
for (int index = 0; index < size; index++) {
@@ -1392,11 +1441,15 @@ public class AppsFilter implements Watchable, Snappable {
}
}
} finally {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
if (DEBUG_TRACING) {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
}
}
try {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "mQueryableViaUsesLibrary");
if (DEBUG_TRACING) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "mQueryableViaUsesLibrary");
}
if (mQueryableViaUsesLibrary.contains(callingAppId, targetAppId)) {
if (DEBUG_LOGGING) {
log(callingSetting, targetPkgSetting, "queryable for library users");
@@ -1404,12 +1457,16 @@ public class AppsFilter implements Watchable, Snappable {
return false;
}
} finally {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
if (DEBUG_TRACING) {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
}
}
return true;
} finally {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
if (DEBUG_TRACING) {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
}
}
}
@@ -1425,7 +1482,9 @@ public class AppsFilter implements Watchable, Snappable {
private static boolean pkgInstruments(
@NonNull AndroidPackage source, @NonNull AndroidPackage target) {
try {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "pkgInstruments");
if (DEBUG_TRACING) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "pkgInstruments");
}
final String packageName = target.getPackageName();
final List<ParsedInstrumentation> inst = source.getInstrumentations();
for (int i = ArrayUtils.size(inst) - 1; i >= 0; i--) {
@@ -1435,7 +1494,9 @@ public class AppsFilter implements Watchable, Snappable {
}
return false;
} finally {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
if (DEBUG_TRACING) {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
}
}
}