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

Commit 4f2e6bd6 authored by Jeffrey Huang's avatar Jeffrey Huang
Browse files

Update setBroadcastSubscriber

change #setBroadcastSubscriber and #unsetBroadcastSubscriber
to avoid using intentsender

Bug: 146074295
Test: Ran GTS Tests
Change-Id: I1510e44bcdf49b579fd49f51081c6a40618039fa
parent 47537a1c
Loading
Loading
Loading
Loading
+0 −10
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package android.os;

import android.os.IPullAtomCallback;
import android.os.StatsDimensionsValue;
import android.os.StatsLogEventWrapper;

/**
@@ -66,15 +65,6 @@ interface IStatsCompanionService {
    /** Pull the specified data. Results will be sent to statsd when complete. */
    StatsLogEventWrapper[] pullData(int pullCode);

    /**
     * Requests StatsCompanionService to send a broadcast using the given intentSender
     * (which should cast to an IIntentSender), along with the other information specified.
     */
    oneway void sendSubscriberBroadcast(in IBinder intentSender, long configUid, long configId,
                                        long subscriptionId, long subscriptionRuleId,
                                        in String[] cookies,
                                        in StatsDimensionsValue dimensionsValue);

    /** Tells StatsCompaionService to grab the uid map snapshot and send it to statsd. */
    oneway void triggerUidSnapshot();

+10 −1
Original line number Diff line number Diff line
@@ -72,8 +72,17 @@ interface IStatsManagerService {
     * This function can only be called by the owner (uid) of the config. It must be called each
     * time statsd starts. Later calls overwrite previous calls; only one PendingIntent is stored.
     *
     * Requires Manifest.permission.DUMP.
     * Requires Manifest.permission.DUMP and Manifest.permission.PACKAGE_USAGE_STATS.
     */
    void setBroadcastSubscriber(long configKey, long subscriberId, in PendingIntent pendingIntent,
                                in String packageName);

    /**
     * Undoes setBroadcastSubscriber() for the (configKey, subscriberId) pair.
     * Any broadcasts associated with subscriberId will henceforth not be sent.
     * No-op if this (configKey, subscriberId) pair was not associated with an PendingIntent.
     *
     * Requires Manifest.permission.DUMP and Manifest.permission.PACKAGE_USAGE_STATS.
     */
    void unsetBroadcastSubscriber(long configKey, long subscriberId, in String packageName);
}
 No newline at end of file
+10 −13
Original line number Diff line number Diff line
@@ -151,34 +151,31 @@ interface IStatsd {
    void removeConfiguration(in long configKey, in String packageName);

    /**
     * Set the IIntentSender (i.e. PendingIntent) to be used when broadcasting subscriber
     * Set the PendingIntentRef to be used when broadcasting subscriber
     * information to the given subscriberId within the given config.
     *
     * Suppose that the calling uid has added a config with key configKey, and that in this config
     * Suppose that the calling uid has added a config with key configId, and that in this config
     * it is specified that when a particular anomaly is detected, a broadcast should be sent to
     * a BroadcastSubscriber with id subscriberId. This function links the given intentSender with
     * that subscriberId (for that config), so that this intentSender is used to send the broadcast
     * a BroadcastSubscriber with id subscriberId. This function links the given pendingIntent with
     * that subscriberId (for that config), so that this pendingIntent is used to send the broadcast
     * when the anomaly is detected.
     *
     * This function can only be called by the owner (uid) of the config. It must be called each
     * time statsd starts. Later calls overwrite previous calls; only one intentSender is stored.
     *
     * intentSender must be convertible into an IntentSender using IntentSender(IBinder)
     * and cannot be null.
     * time statsd starts. Later calls overwrite previous calls; only one pendingIntent is stored.
     *
     * Requires Manifest.permission.DUMP.
     */
    void setBroadcastSubscriber(long configKey, long subscriberId, in IBinder intentSender,
                                in String packageName);
    void setBroadcastSubscriber(long configId, long subscriberId, in IPendingIntentRef pir,
                                int callingUid);

    /**
     * Undoes setBroadcastSubscriber() for the (configKey, subscriberId) pair.
     * Undoes setBroadcastSubscriber() for the (configId, subscriberId) pair.
     * Any broadcasts associated with subscriberId will henceforth not be sent.
     * No-op if this (configKey, subsriberId) pair was not associated with an IntentSender.
     * No-op if this (configKey, subscriberId) pair was not associated with an PendingIntentRef.
     *
     * Requires Manifest.permission.DUMP.
     */
    void unsetBroadcastSubscriber(long configKey, long subscriberId, in String packageName);
    void unsetBroadcastSubscriber(long configId, long subscriberId, int callingUid);

    /**
     * Apps can send an atom via this application breadcrumb with the specified label and state for
+32 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.util.Slog;

import com.android.server.SystemService;

import java.util.ArrayList;
import java.util.Arrays;

/**
@@ -101,7 +102,7 @@ public class StatsCompanion {
        private static final String EXTRA_LAST_REPORT_TIME = "android.app.extra.LAST_REPORT_TIME";
        private static final int CODE_DATA_BROADCAST = 1;
        private static final int CODE_ACTIVE_CONFIGS_BROADCAST = 1;

        private static final int CODE_SUBSCRIBER_BROADCAST = 1;

        private final PendingIntent mPendingIntent;
        private final Context mContext;
@@ -141,7 +142,36 @@ public class StatsCompanion {
        @Override
        public void sendSubscriberBroadcast(long configUid, long configId, long subscriptionId,
                long subscriptionRuleId, String[] cookies, StatsDimensionsValue dimensionsValue) {
            // no-op
            enforceStatsCompanionPermission(mContext);
            Intent intent =
                    new Intent()
                            .putExtra(StatsManager.EXTRA_STATS_CONFIG_UID, configUid)
                            .putExtra(StatsManager.EXTRA_STATS_CONFIG_KEY, configId)
                            .putExtra(StatsManager.EXTRA_STATS_SUBSCRIPTION_ID, subscriptionId)
                            .putExtra(StatsManager.EXTRA_STATS_SUBSCRIPTION_RULE_ID,
                                    subscriptionRuleId)
                            .putExtra(StatsManager.EXTRA_STATS_DIMENSIONS_VALUE, dimensionsValue);

            ArrayList<String> cookieList = new ArrayList<>(cookies.length);
            cookieList.addAll(Arrays.asList(cookies));
            intent.putStringArrayListExtra(
                    StatsManager.EXTRA_STATS_BROADCAST_SUBSCRIBER_COOKIES, cookieList);

            if (DEBUG) {
                Slog.d(TAG,
                        String.format(
                                "Statsd sendSubscriberBroadcast with params {%d %d %d %d %s %s}",
                                configUid, configId, subscriptionId, subscriptionRuleId,
                                Arrays.toString(cookies),
                                dimensionsValue));
            }
            try {
                mPendingIntent.send(mContext, CODE_SUBSCRIBER_BROADCAST, intent, null, null);
            } catch (PendingIntent.CanceledException e) {
                Slog.w(TAG,
                        "Unable to send using PendingIntent from uid " + configUid
                                + "; presumably it had been cancelled.");
            }
        }
    }
}
+0 −40
Original line number Diff line number Diff line
@@ -50,7 +50,6 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentSender;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
@@ -88,7 +87,6 @@ import android.os.Parcelable;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.StatFs;
import android.os.StatsDimensionsValue;
import android.os.StatsLogEventWrapper;
import android.os.SynchronousResultReceiver;
import android.os.SystemClock;
@@ -202,7 +200,6 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
    private static final int PACKAGE_NAME_FIELD_ID = 4;
    private static final int INSTALLER_FIELD_ID = 5;

    public static final int CODE_SUBSCRIBER_BROADCAST = 1;
    public static final int DEATH_THRESHOLD = 10;
    /**
     * Which native processes to snapshot memory for.
@@ -442,43 +439,6 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
                KernelCpuThreadReaderSettingsObserver.getSettingsModifiedReader(mContext);
    }

    @Override
    public void sendSubscriberBroadcast(IBinder intentSenderBinder, long configUid, long configKey,
            long subscriptionId, long subscriptionRuleId, String[] cookies,
            StatsDimensionsValue dimensionsValue) {
        StatsCompanion.enforceStatsCompanionPermission(mContext);
        IntentSender intentSender = new IntentSender(intentSenderBinder);
        Intent intent =
                new Intent()
                        .putExtra(StatsManager.EXTRA_STATS_CONFIG_UID, configUid)
                        .putExtra(StatsManager.EXTRA_STATS_CONFIG_KEY, configKey)
                        .putExtra(StatsManager.EXTRA_STATS_SUBSCRIPTION_ID, subscriptionId)
                        .putExtra(StatsManager.EXTRA_STATS_SUBSCRIPTION_RULE_ID, subscriptionRuleId)
                        .putExtra(StatsManager.EXTRA_STATS_DIMENSIONS_VALUE, dimensionsValue);

        ArrayList<String> cookieList = new ArrayList<>(cookies.length);
        for (String cookie : cookies) {
            cookieList.add(cookie);
        }
        intent.putStringArrayListExtra(
                StatsManager.EXTRA_STATS_BROADCAST_SUBSCRIBER_COOKIES, cookieList);

        if (DEBUG) {
            Slog.d(TAG,
                    String.format("Statsd sendSubscriberBroadcast with params {%d %d %d %d %s %s}",
                            configUid, configKey, subscriptionId, subscriptionRuleId,
                            Arrays.toString(cookies),
                            dimensionsValue));
        }
        try {
            intentSender.sendIntent(mContext, CODE_SUBSCRIBER_BROADCAST, intent, null, null);
        } catch (IntentSender.SendIntentException e) {
            Slog.w(TAG,
                    "Unable to send using IntentSender from uid " + configUid
                            + "; presumably it had been cancelled.");
        }
    }

    private final static int[] toIntArray(List<Integer> list) {
        int[] ret = new int[list.size()];
        for (int i = 0; i < ret.length; i++) {
Loading