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

Commit c673e6fc authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Adds basic tracing to AppsFilter"

parents 5c6e9567 88318e05
Loading
Loading
Loading
Loading
+180 −147
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.pm;

import static android.content.pm.PackageParser.Component;
import static android.content.pm.PackageParser.IntentInfo;
import static android.os.Trace.TRACE_TAG_PACKAGE_MANAGER;
import static android.provider.DeviceConfig.NAMESPACE_PACKAGE_MANAGER_SERVICE;

import android.Manifest;
@@ -32,6 +33,7 @@ import android.os.Build;
import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.Trace;
import android.permission.IPermissionManager;
import android.provider.DeviceConfig;
import android.util.ArraySet;
@@ -152,13 +154,23 @@ public class AppsFilter {

        @Override
        public boolean isGloballyEnabled() {
            Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "isGloballyEnabled");
            try {
                return mFeatureEnabled;
            } finally {
                Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
            }
        }

        @Override
        public boolean packageIsEnabled(PackageParser.Package pkg) {
            Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "packageIsEnabled");
            try {
                return mInjector.getCompatibility().isChangeEnabled(
                        PackageManager.FILTER_APPLICATION_QUERY, pkg.applicationInfo);
            } finally {
                Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
            }
        }
    }

@@ -292,9 +304,12 @@ public class AppsFilter {
     */
    public void addPackage(PackageParser.Package newPkg,
            Map<String, PackageParser.Package> existing) {
        Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "filter.addPackage");
        try {
            // let's re-evaluate the ability of already added packages to see this new package
            if (newPkg.mForceQueryable
                || (mSystemAppsQueryable && (newPkg.isSystem() || newPkg.isUpdatedSystemApp()))) {
                    || (mSystemAppsQueryable && (newPkg.isSystem()
                    || newPkg.isUpdatedSystemApp()))) {
                mForceQueryable.add(newPkg.packageName);
            } else {
                for (String packageName : mQueriesViaIntent.keySet()) {
@@ -328,6 +343,9 @@ public class AppsFilter {
                queriesPackages.addAll(newPkg.mQueriesPackages);
            }
            mQueriesViaPackage.put(newPkg.packageName, queriesPackages);
        } finally {
            Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
        }
    }

    /**
@@ -365,6 +383,8 @@ public class AppsFilter {
     */
    public boolean shouldFilterApplication(int callingUid, @Nullable SettingBase callingSetting,
            PackageSetting targetPkgSetting, int userId) {
        Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "shouldFilterApplication");
        try {
            final boolean featureEnabled = mFeatureConfig.isGloballyEnabled();
            if (!featureEnabled) {
                if (DEBUG_LOGGING) {
@@ -418,10 +438,15 @@ public class AppsFilter {
                        DEBUG_ALLOW_ALL ? "ALLOWED" : "BLOCKED");
            }
            return !DEBUG_ALLOW_ALL;
        } finally {
            Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
        }
    }

    private boolean shouldFilterApplicationInternal(
            PackageSetting callingPkgSetting, PackageSetting targetPkgSetting, int userId) {
        Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "shouldFilterApplicationInternal");
        try {
            final String callingName = callingPkgSetting.pkg.packageName;
            final PackageParser.Package targetPkg = targetPkgSetting.pkg;

@@ -487,9 +512,11 @@ public class AppsFilter {
                }
                return false;
            }
        if (callingPkgSetting.pkg.instrumentation.size() > 0) {
            for (int i = 0, max = callingPkgSetting.pkg.instrumentation.size(); i < max; i++) {
                if (callingPkgSetting.pkg.instrumentation.get(i).info.targetPackage == targetName) {
            final ArrayList<PackageParser.Instrumentation> inst =
                    callingPkgSetting.pkg.instrumentation;
            if (inst.size() > 0) {
                for (int i = 0, max = inst.size(); i < max; i++) {
                    if (inst.get(i).info.targetPackage == targetName) {
                        if (DEBUG_LOGGING) {
                            log(callingPkgSetting, targetPkgSetting, "instrumentation");
                        }
@@ -497,6 +524,7 @@ public class AppsFilter {
                    }
                }
            }
            Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "filter.checkPermission");
            try {
                if (mPermissionManager.checkPermission(
                        Manifest.permission.QUERY_ALL_PACKAGES, callingName, userId)
@@ -508,8 +536,13 @@ public class AppsFilter {
                }
            } catch (RemoteException e) {
                return true;
            } finally {
                Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
            }
            return true;
        } finally {
            Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
        }
    }

    private static void log(PackageSetting callingPkgSetting, PackageSetting targetPkgSetting,