Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2eebc9ef authored by Patrick Baumann's avatar Patrick Baumann
Browse files

Adds additional tracing to AppsFilter

This adds more fine-grained traces to AppsFilter to better troubleshoot
performance issues in the individual branches.

Test: manual; run with tracing and observe results
Bug: 136675067
Change-Id: Ia03f9f390a5144691a37afec51c032b40a1be039
parent dca6d8fe
Loading
Loading
Loading
Loading
+66 −31
Original line number Diff line number Diff line
@@ -449,6 +449,7 @@ public class AppsFilter {
            }
            final PackageSetting callingPkgSetting;
            final ArraySet<PackageSetting> callingSharedPkgSettings;
            Trace.beginSection("callingSetting instanceof");
            if (callingSetting instanceof PackageSetting) {
                callingPkgSetting = (PackageSetting) callingSetting;
                callingSharedPkgSettings = null;
@@ -456,6 +457,7 @@ public class AppsFilter {
                callingPkgSetting = null;
                callingSharedPkgSettings = ((SharedUserSetting) callingSetting).packages;
            }
            Trace.endSection();

            if (callingPkgSetting != null) {
                if (!mFeatureConfig.packageIsEnabled(callingPkgSetting.pkg)) {
@@ -485,6 +487,7 @@ public class AppsFilter {
                return true;
            }
            final String targetName = targetPkg.getPackageName();
            Trace.beginSection("getAppId");
            final int callingAppId;
            if (callingPkgSetting != null) {
                callingAppId = callingPkgSetting.appId;
@@ -492,6 +495,7 @@ public class AppsFilter {
                callingAppId = callingSharedPkgSettings.valueAt(0).appId; // all should be the same
            }
            final int targetAppId = targetPkgSetting.appId;
            Trace.endSection();
            if (callingAppId == targetAppId) {
                if (DEBUG_LOGGING) {
                    log(callingSetting, targetPkgSetting, "same app id");
@@ -499,6 +503,8 @@ public class AppsFilter {
                return false;
            }

            try {
                Trace.beginSection("hasPermission");
                if (callingSetting.getPermissionsState().hasPermission(
                        Manifest.permission.QUERY_ALL_PACKAGES, UserHandle.getUserId(callingUid))) {
                    if (DEBUG_LOGGING) {
@@ -506,25 +512,46 @@ public class AppsFilter {
                    }
                    return false;
                }
            } finally {
                Trace.endSection();
            }
            try {
                Trace.beginSection("mForceQueryable");
                if (mForceQueryable.contains(targetAppId)) {
                    if (DEBUG_LOGGING) {
                        log(callingSetting, targetPkgSetting, "force queryable");
                    }
                    return false;
                }
            } finally {
                Trace.endSection();
            }
            try {
                Trace.beginSection("mQueriesViaPackage");
                if (mQueriesViaPackage.contains(callingAppId, targetAppId)) {
                    // the calling package has explicitly declared the target package; allow
                    if (DEBUG_LOGGING) {
                        log(callingSetting, targetPkgSetting, "queries package");
                    }
                    return false;
            } else if (mQueriesViaIntent.contains(callingAppId, targetAppId)) {
                }
            } finally {
                Trace.endSection();
            }
            try {
                Trace.beginSection("mQueriesViaIntent");
                if (mQueriesViaIntent.contains(callingAppId, targetAppId)) {
                    if (DEBUG_LOGGING) {
                        log(callingSetting, targetPkgSetting, "queries intent");
                    }
                    return false;
                }
            } finally {
                Trace.endSection();
            }

            try {
                Trace.beginSection("mImplicitlyQueryable");
                final int targetUid = UserHandle.getUid(userId, targetAppId);
                if (mImplicitlyQueryable.contains(callingUid, targetUid)) {
                    if (DEBUG_LOGGING) {
@@ -532,6 +559,9 @@ public class AppsFilter {
                    }
                    return false;
                }
            } finally {
                Trace.endSection();
            }
            if (callingPkgSetting != null) {
                if (callingPkgInstruments(callingPkgSetting, targetPkgSetting, targetName)) {
                    return false;
@@ -576,6 +606,8 @@ public class AppsFilter {
    private static boolean callingPkgInstruments(PackageSetting callingPkgSetting,
            PackageSetting targetPkgSetting,
            String targetName) {
        try {
            Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "callingPkgInstruments");
            final List<ComponentParseUtils.ParsedInstrumentation> inst =
                    callingPkgSetting.pkg.getInstrumentations();
            for (int i = ArrayUtils.size(inst) - 1; i >= 0; i--) {
@@ -587,6 +619,9 @@ public class AppsFilter {
                }
            }
            return false;
        } finally {
            Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
        }
    }

    private static void log(SettingBase callingPkgSetting, PackageSetting targetPkgSetting,