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

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

Final adjustments to privacy metrics:

- remove unnecessary lock - after statsd added locks for each puller, there
is no need to create additional lock for sampling rate estimation
- adjust sampling target value for AppOps atom based on Beta1 results
- adjust sampling ratio for Dangerous Permission state atom

Test: statds_testdrive 10069, 10075, atest UidAtomTests#testAppOps
--iterations=20, atest UidAtomTests#testDangerousPermissionState
--iterations=20, atest UidAtomTests#testDangerousPermissionStateSampled
--iterations=20
Bug: 143519689
Change-Id: I05fec5f602c7e1c5ba38749147c04aec79da2a46
parent 2a02c8e3
Loading
Loading
Loading
Loading
+18 −23
Original line number Original line Diff line number Diff line
@@ -212,7 +212,7 @@ public class StatsPullAtomService extends SystemService {
    private static final int DIMENSION_KEY_SIZE_HARD_LIMIT = 800;
    private static final int DIMENSION_KEY_SIZE_HARD_LIMIT = 800;
    private static final int DIMENSION_KEY_SIZE_SOFT_LIMIT = 500;
    private static final int DIMENSION_KEY_SIZE_SOFT_LIMIT = 500;
    private static final long APP_OPS_SAMPLING_INITIALIZATION_DELAY_MILLIS = 45000;
    private static final long APP_OPS_SAMPLING_INITIALIZATION_DELAY_MILLIS = 45000;
    private static final int APP_OPS_SIZE_ESTIMATE = 5000;
    private static final int APP_OPS_SIZE_ESTIMATE = 2000;


    private static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity";
    private static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity";
    /**
    /**
@@ -320,8 +320,7 @@ public class StatsPullAtomService extends SystemService {


    private StatsPullAtomCallbackImpl mStatsCallbackImpl;
    private StatsPullAtomCallbackImpl mStatsCallbackImpl;


    private final Object mAppOpsSamplingRateLock = new Object();
    @GuardedBy("mAttributedAppOpsLock")
    @GuardedBy("mAppOpsSamplingRateLock")
    private int mAppOpsSamplingRate = 0;
    private int mAppOpsSamplingRate = 0;
    private final Object mDangerousAppOpsListLock = new Object();
    private final Object mDangerousAppOpsListLock = new Object();
    @GuardedBy("mDangerousAppOpsListLock")
    @GuardedBy("mDangerousAppOpsListLock")
@@ -3084,7 +3083,7 @@ public class StatsPullAtomService extends SystemService {
    int pullDangerousPermissionStateLocked(int atomTag, List<StatsEvent> pulledData) {
    int pullDangerousPermissionStateLocked(int atomTag, List<StatsEvent> pulledData) {
        final long token = Binder.clearCallingIdentity();
        final long token = Binder.clearCallingIdentity();
        float samplingRate = DeviceConfig.getFloat(DeviceConfig.NAMESPACE_PERMISSIONS,
        float samplingRate = DeviceConfig.getFloat(DeviceConfig.NAMESPACE_PERMISSIONS,
                DANGEROUS_PERMISSION_STATE_SAMPLE_RATE, 0.02f);
                DANGEROUS_PERMISSION_STATE_SAMPLE_RATE, 0.015f);
        Set<Integer> reportedUids = new HashSet<>();
        Set<Integer> reportedUids = new HashSet<>();
        try {
        try {
            PackageManager pm = mContext.getPackageManager();
            PackageManager pm = mContext.getPackageManager();
@@ -3479,7 +3478,6 @@ public class StatsPullAtomService extends SystemService {
            HistoricalOps histOps = ops.get(EXTERNAL_STATS_SYNC_TIMEOUT_MILLIS,
            HistoricalOps histOps = ops.get(EXTERNAL_STATS_SYNC_TIMEOUT_MILLIS,
                    TimeUnit.MILLISECONDS);
                    TimeUnit.MILLISECONDS);


            synchronized (mAppOpsSamplingRateLock) {
            if (mAppOpsSamplingRate == 0) {
            if (mAppOpsSamplingRate == 0) {
                mContext.getMainThreadHandler().postDelayed(new Runnable() {
                mContext.getMainThreadHandler().postDelayed(new Runnable() {
                    @Override
                    @Override
@@ -3488,7 +3486,7 @@ public class StatsPullAtomService extends SystemService {
                            estimateAppOpsSamplingRate();
                            estimateAppOpsSamplingRate();
                        } catch (Throwable e) {
                        } catch (Throwable e) {
                            Slog.e(TAG, "AppOps sampling ratio estimation failed: ", e);
                            Slog.e(TAG, "AppOps sampling ratio estimation failed: ", e);
                                synchronized (mAppOpsSamplingRateLock) {
                            synchronized (mAttributedAppOpsLock) {
                                mAppOpsSamplingRate = min(mAppOpsSamplingRate, 10);
                                mAppOpsSamplingRate = min(mAppOpsSamplingRate, 10);
                            }
                            }
                        }
                        }
@@ -3496,16 +3494,13 @@ public class StatsPullAtomService extends SystemService {
                }, APP_OPS_SAMPLING_INITIALIZATION_DELAY_MILLIS);
                }, APP_OPS_SAMPLING_INITIALIZATION_DELAY_MILLIS);
                mAppOpsSamplingRate = 100;
                mAppOpsSamplingRate = 100;
            }
            }
            }


            List<AppOpEntry> opsList =
            List<AppOpEntry> opsList =
                    processHistoricalOps(histOps, atomTag, mAppOpsSamplingRate);
                    processHistoricalOps(histOps, atomTag, mAppOpsSamplingRate);


            int newSamplingRate = sampleAppOps(pulledData, opsList, atomTag, mAppOpsSamplingRate);
            int newSamplingRate = sampleAppOps(pulledData, opsList, atomTag, mAppOpsSamplingRate);


            synchronized (mAppOpsSamplingRateLock) {
            mAppOpsSamplingRate = min(mAppOpsSamplingRate, newSamplingRate);
            mAppOpsSamplingRate = min(mAppOpsSamplingRate, newSamplingRate);
            }
        } catch (Throwable t) {
        } catch (Throwable t) {
            // TODO: catch exceptions at a more granular level
            // TODO: catch exceptions at a more granular level
            Slog.e(TAG, "Could not read appops", t);
            Slog.e(TAG, "Could not read appops", t);
@@ -3544,7 +3539,7 @@ public class StatsPullAtomService extends SystemService {
        }
        }
        int estimatedSamplingRate = (int) constrain(
        int estimatedSamplingRate = (int) constrain(
                appOpsTargetCollectionSize * 100 / estimatedSize, 0, 100);
                appOpsTargetCollectionSize * 100 / estimatedSize, 0, 100);
        synchronized (mAppOpsSamplingRateLock) {
        synchronized (mAttributedAppOpsLock) {
            mAppOpsSamplingRate = min(mAppOpsSamplingRate, estimatedSamplingRate);
            mAppOpsSamplingRate = min(mAppOpsSamplingRate, estimatedSamplingRate);
        }
        }
    }
    }