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

Commit 0a0aeeaf 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

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


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


    // Baselines that stores list of NetworkStats right after initializing, with associated
    // Baselines that stores list of NetworkStats right after initializing, with associated
    // information. This is used to calculate difference when pulling
    // information. This is used to calculate difference when pulling
@@ -526,6 +527,25 @@ public class StatsPullAtomService extends SystemService {
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Slog.e(TAG, "failed to initialize healthHalWrapper");
            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() {
    void registerEventListeners() {
@@ -3113,22 +3133,8 @@ public class StatsPullAtomService extends SystemService {
        e.writeLong(op.getBackgroundRejectCount(OP_FLAGS_PULLED));
        e.writeLong(op.getBackgroundRejectCount(OP_FLAGS_PULLED));
        e.writeLong(op.getForegroundAccessDuration(OP_FLAGS_PULLED));
        e.writeLong(op.getForegroundAccessDuration(OP_FLAGS_PULLED));
        e.writeLong(op.getBackgroundAccessDuration(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) {
        if (atomTag == FrameworkStatsLog.ATTRIBUTED_APP_OPS) {
            e.writeInt(mAppOpsSamplingRate);
            e.writeInt(mAppOpsSamplingRate);
        }
        }