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

Commit 3bce92e5 authored by Stanislav Zholnin's avatar Stanislav Zholnin Committed by Android (Google) Code Review
Browse files

Merge "Add puller for RuntimeAppOpAccess atom."

parents 940f172e df3eeac5
Loading
Loading
Loading
Loading
+50 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.app.AppOpsManager.HistoricalPackageOps;
import android.app.AppOpsManager.HistoricalUidOps;
import android.app.INotificationManager;
import android.app.ProcessMemoryState;
import android.app.RuntimeAppOpAccessMessage;
import android.app.StatsManager;
import android.app.StatsManager.PullAtomMetadata;
import android.bluetooth.BluetoothActivityEnergyInfo;
@@ -377,6 +378,8 @@ public class StatsPullAtomService extends SystemService {
                    return pullFaceSettings(atomTag, data);
                case FrameworkStatsLog.APP_OPS:
                    return pullAppOps(atomTag, data);
                case FrameworkStatsLog.RUNTIME_APP_OP_ACCESS:
                    return pullRuntimeAppOpAccessMessage(atomTag, data);
                case FrameworkStatsLog.NOTIFICATION_REMOTE_VIEWS:
                    return pullNotificationRemoteViews(atomTag, data);
                case FrameworkStatsLog.DANGEROUS_PERMISSION_STATE_SAMPLED:
@@ -539,6 +542,7 @@ public class StatsPullAtomService extends SystemService {
        registerAppsOnExternalStorageInfo();
        registerFaceSettings();
        registerAppOps();
        registerRuntimeAppOpAccessMessage();
        registerNotificationRemoteViews();
        registerDangerousPermissionState();
        registerDangerousPermissionStateSampled();
@@ -2834,6 +2838,17 @@ public class StatsPullAtomService extends SystemService {

    }

    private void registerRuntimeAppOpAccessMessage() {
        int tagId = FrameworkStatsLog.RUNTIME_APP_OP_ACCESS;
        mStatsManager.registerPullAtomCallback(
                tagId,
                null, // use default PullAtomMetadata values
                BackgroundThread.getExecutor(),
                mStatsCallbackImpl
        );

    }

    int pullAppOps(int atomTag, List<StatsEvent> pulledData) {
        final long token = Binder.clearCallingIdentity();
        try {
@@ -2894,6 +2909,41 @@ public class StatsPullAtomService extends SystemService {
        return StatsManager.PULL_SUCCESS;
    }

    int pullRuntimeAppOpAccessMessage(int atomTag, List<StatsEvent> pulledData) {
        final long token = Binder.clearCallingIdentity();
        try {
            AppOpsManager appOps = mContext.getSystemService(AppOpsManager.class);

            RuntimeAppOpAccessMessage message = appOps.collectRuntimeAppOpAccessMessage();
            if (message == null) {
                Slog.i(TAG, "No runtime appop access message collected");
                return StatsManager.PULL_SUCCESS;
            }

            StatsEvent.Builder e = StatsEvent.newBuilder();
            e.setAtomId(atomTag);
            e.writeInt(message.getUid());
            e.writeString(message.getPackageName());
            e.writeString(message.getOp());
            if (message.getFeatureId() == null) {
                e.writeString("");
            } else {
                e.writeString(message.getFeatureId());
            }
            e.writeString(message.getMessage());
            e.writeInt(message.getSamplingStrategy());

            pulledData.add(e.build());
        } catch (Throwable t) {
            // TODO: catch exceptions at a more granular level
            Slog.e(TAG, "Could not read runtime appop access message", t);
            return StatsManager.PULL_SKIP;
        } finally {
            Binder.restoreCallingIdentity(token);
        }
        return StatsManager.PULL_SUCCESS;
    }

    static void unpackStreamedData(int atomTag, List<StatsEvent> pulledData,
            List<ParcelFileDescriptor> statsFiles) throws IOException {
        InputStream stream = new ParcelFileDescriptor.AutoCloseInputStream(statsFiles.get(0));