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

Commit 328799c1 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Precache calls to PermissionManager to avoid calls which use shared...

Merge "Precache calls to PermissionManager to avoid calls which use shared PackageManager and PermissionManager lock." into rvc-dev am: f6fa2536 am: 0a0aeeaf am: 09dc8a7e am: a80a1d41

Change-Id: I336453d5df04beaa37c2eb9649a4bf25d92967e8
parents 2ebf90de a80a1d41
Loading
Loading
Loading
Loading
+21 −15
Original line number Diff line number Diff line
@@ -289,6 +289,7 @@ public class StatsPullAtomService extends SystemService {
    private StatsPullAtomCallbackImpl mStatsCallbackImpl;

    private int mAppOpsSamplingRate = 0;
    private final ArraySet<Integer> mDangerousAppOpsList = new ArraySet<>();

    // Baselines that stores list of NetworkStats right after initializing, with associated
    // information. This is used to calculate difference when pulling
@@ -519,6 +520,25 @@ public class StatsPullAtomService extends SystemService {
        } catch (RemoteException e) {
            Slog.e(TAG, "failed to initialize healthHalWrapper");
        }

        // Initialize list of AppOps related to DangerousPermissions
        PackageManager pm = mContext.getPackageManager();
        for (int op = 0; op < AppOpsManager._NUM_OP; op++) {
            String perm = AppOpsManager.opToPermission(op);
            if (perm == null) {
                continue;
            } else {
                PermissionInfo permInfo;
                try {
                    permInfo = pm.getPermissionInfo(perm, 0);
                    if (permInfo.getProtection() == PROTECTION_DANGEROUS) {
                        mDangerousAppOpsList.add(op);
                    }
                } catch (PackageManager.NameNotFoundException exception) {
                    continue;
                }
            }
        }
    }

    void registerEventListeners() {
@@ -3116,22 +3136,8 @@ public class StatsPullAtomService extends SystemService {
        e.writeLong(op.getBackgroundRejectCount(OP_FLAGS_PULLED));
        e.writeLong(op.getForegroundAccessDuration(OP_FLAGS_PULLED));
        e.writeLong(op.getBackgroundAccessDuration(OP_FLAGS_PULLED));
        e.writeBoolean(mDangerousAppOpsList.contains(op.getOpCode()));

        String perm = AppOpsManager.opToPermission(op.getOpCode());
        if (perm == null) {
            e.writeBoolean(false);
        } else {
            PermissionInfo permInfo;
            try {
                permInfo = mContext.getPackageManager().getPermissionInfo(
                        perm,
                        0);
                e.writeBoolean(
                        permInfo.getProtection() == PROTECTION_DANGEROUS);
            } catch (PackageManager.NameNotFoundException exception) {
                e.writeBoolean(false);
            }
        }
        if (atomTag == FrameworkStatsLog.ATTRIBUTED_APP_OPS) {
            e.writeInt(mAppOpsSamplingRate);
        }