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

Commit e08a2bbc authored by Stanislav Zholnin's avatar Stanislav Zholnin
Browse files

Precache calls to PermissionManager to avoid calls which use shared PackageManager and

PermissionManager lock.

Test: stastsd_testdrive 10075 and observe that is_runtime_permission filled correctly.
Bug: 143519689
Change-Id: I6a23a673092fd072a5aef8edadde7816d937e997
parent eb84f960
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
@@ -524,6 +525,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() {
@@ -3110,22 +3130,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);
        }
        }