Merge "Statsd BroadcastSubscribers can receive 'cookies'" into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
81cacb274c
@@ -377,6 +377,7 @@ package android.app {
|
||||
method public boolean setBroadcastSubscriber(long, long, android.app.PendingIntent);
|
||||
method public boolean setDataFetchOperation(long, android.app.PendingIntent);
|
||||
field public static final java.lang.String ACTION_STATSD_STARTED = "android.app.action.STATSD_STARTED";
|
||||
field public static final java.lang.String EXTRA_STATS_BROADCAST_SUBSCRIBER_COOKIES = "android.app.extra.STATS_BROADCAST_SUBSCRIBER_COOKIES";
|
||||
field public static final java.lang.String EXTRA_STATS_CONFIG_KEY = "android.app.extra.STATS_CONFIG_KEY";
|
||||
field public static final java.lang.String EXTRA_STATS_CONFIG_UID = "android.app.extra.STATS_CONFIG_UID";
|
||||
field public static final java.lang.String EXTRA_STATS_DIMENSIONS_VALUE = "android.app.extra.STATS_DIMENSIONS_VALUE";
|
||||
|
||||
@@ -295,6 +295,7 @@ message PerfettoDetails {
|
||||
|
||||
message BroadcastSubscriberDetails {
|
||||
optional int64 subscriber_id = 1;
|
||||
repeated string cookie = 2;
|
||||
}
|
||||
|
||||
message Subscription {
|
||||
|
||||
@@ -77,6 +77,12 @@ void SubscriberReporter::alertBroadcastSubscriber(const ConfigKey& configKey,
|
||||
}
|
||||
int64_t subscriberId = subscription.broadcast_subscriber_details().subscriber_id();
|
||||
|
||||
vector<String16> cookies;
|
||||
cookies.reserve(subscription.broadcast_subscriber_details().cookie_size());
|
||||
for (auto& cookie : subscription.broadcast_subscriber_details().cookie()) {
|
||||
cookies.push_back(String16(cookie.c_str()));
|
||||
}
|
||||
|
||||
auto it1 = mIntentMap.find(configKey);
|
||||
if (it1 == mIntentMap.end()) {
|
||||
ALOGW("Cannot inform subscriber for missing config key %s ", configKey.ToString().c_str());
|
||||
@@ -88,12 +94,13 @@ void SubscriberReporter::alertBroadcastSubscriber(const ConfigKey& configKey,
|
||||
configKey.ToString().c_str(), (long long)subscriberId);
|
||||
return;
|
||||
}
|
||||
sendBroadcastLocked(it2->second, configKey, subscription, dimKey);
|
||||
sendBroadcastLocked(it2->second, configKey, subscription, cookies, dimKey);
|
||||
}
|
||||
|
||||
void SubscriberReporter::sendBroadcastLocked(const sp<IBinder>& intentSender,
|
||||
const ConfigKey& configKey,
|
||||
const Subscription& subscription,
|
||||
const vector<String16>& cookies,
|
||||
const MetricDimensionKey& dimKey) const {
|
||||
VLOG("SubscriberReporter::sendBroadcastLocked called.");
|
||||
if (mStatsCompanionService == nullptr) {
|
||||
@@ -101,11 +108,16 @@ void SubscriberReporter::sendBroadcastLocked(const sp<IBinder>& intentSender,
|
||||
return;
|
||||
}
|
||||
mStatsCompanionService->sendSubscriberBroadcast(
|
||||
intentSender, configKey.GetUid(), configKey.GetId(), subscription.id(),
|
||||
subscription.rule_id(), getStatsDimensionsValue(dimKey.getDimensionKeyInWhat()));
|
||||
intentSender,
|
||||
configKey.GetUid(),
|
||||
configKey.GetId(),
|
||||
subscription.id(),
|
||||
subscription.rule_id(),
|
||||
cookies,
|
||||
getStatsDimensionsValue(dimKey.getDimensionKeyInWhat()));
|
||||
}
|
||||
|
||||
void getStatsDimensionsValueHelper(const std::vector<FieldValue>& dims, size_t* index, int depth,
|
||||
void getStatsDimensionsValueHelper(const vector<FieldValue>& dims, size_t* index, int depth,
|
||||
int prefix, vector<StatsDimensionsValue>* output) {
|
||||
size_t count = dims.size();
|
||||
while (*index < count) {
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace android {
|
||||
namespace os {
|
||||
@@ -102,6 +103,7 @@ private:
|
||||
void sendBroadcastLocked(const sp<android::IBinder>& intentSender,
|
||||
const ConfigKey& configKey,
|
||||
const Subscription& subscription,
|
||||
const std::vector<String16>& cookies,
|
||||
const MetricDimensionKey& dimKey) const;
|
||||
};
|
||||
|
||||
|
||||
@@ -53,6 +53,12 @@ public final class StatsManager {
|
||||
*/
|
||||
public static final String EXTRA_STATS_SUBSCRIPTION_RULE_ID =
|
||||
"android.app.extra.STATS_SUBSCRIPTION_RULE_ID";
|
||||
/**
|
||||
* List<String> of the relevant statsd_config.proto's BroadcastSubscriberDetails.cookie.
|
||||
* Obtain using {@link android.content.Intent#getStringArrayListExtra(String)}.
|
||||
*/
|
||||
public static final String EXTRA_STATS_BROADCAST_SUBSCRIBER_COOKIES =
|
||||
"android.app.extra.STATS_BROADCAST_SUBSCRIBER_COOKIES";
|
||||
/**
|
||||
* Extra of a {@link android.os.StatsDimensionsValue} representing sliced dimension value
|
||||
* information.
|
||||
@@ -146,7 +152,8 @@ public final class StatsManager {
|
||||
* {@link #EXTRA_STATS_CONFIG_UID},
|
||||
* {@link #EXTRA_STATS_CONFIG_KEY},
|
||||
* {@link #EXTRA_STATS_SUBSCRIPTION_ID},
|
||||
* {@link #EXTRA_STATS_SUBSCRIPTION_RULE_ID}, and
|
||||
* {@link #EXTRA_STATS_SUBSCRIPTION_RULE_ID},
|
||||
* {@link #EXTRA_STATS_BROADCAST_SUBSCRIBER_COOKIES}, and
|
||||
* {@link #EXTRA_STATS_DIMENSIONS_VALUE}.
|
||||
* <p>
|
||||
* This function can only be called by the owner (uid) of the config. It must be called each
|
||||
|
||||
@@ -74,6 +74,7 @@ interface IStatsCompanionService {
|
||||
*/
|
||||
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. */
|
||||
|
||||
@@ -73,6 +73,7 @@ import com.android.server.SystemService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
@@ -196,6 +197,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
|
||||
@Override
|
||||
public void sendSubscriberBroadcast(IBinder intentSenderBinder, long configUid, long configKey,
|
||||
long subscriptionId, long subscriptionRuleId,
|
||||
String[] cookies,
|
||||
StatsDimensionsValue dimensionsValue) {
|
||||
enforceCallingPermission();
|
||||
IntentSender intentSender = new IntentSender(intentSenderBinder);
|
||||
@@ -205,10 +207,17 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
|
||||
.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}",
|
||||
configUid, configKey, subscriptionId,
|
||||
subscriptionRuleId, dimensionsValue));
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user