diff options
| author | TreeHugger Robot <treehugger-gerrit@google.com> | 2018-01-25 06:23:36 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-01-25 06:23:36 +0000 |
| commit | 73a331f52490f648d0347cd8856c1196d418a600 (patch) | |
| tree | 8bf4bbc2edb5f4f815cf5c1174eab8f1a2f29f1f /core/java | |
| parent | 6834ec8e54978d076fcf9c414d52f6cb173c24fc (diff) | |
| parent | c697797d43b6932fc7cca1c8d7d850c3fb4d1452 (diff) | |
Merge "Statsd broadcast subscriber"
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/app/StatsManager.java | 238 | ||||
| -rw-r--r-- | core/java/android/app/SystemServiceRegistry.java | 1 | ||||
| -rw-r--r-- | core/java/android/content/Context.java | 2 | ||||
| -rw-r--r-- | core/java/android/os/IStatsCompanionService.aidl | 10 | ||||
| -rw-r--r-- | core/java/android/os/IStatsManager.aidl | 31 | ||||
| -rw-r--r-- | core/java/android/os/StatsDimensionsValue.aidl | 20 | ||||
| -rw-r--r-- | core/java/android/os/StatsDimensionsValue.java | 353 | ||||
| -rw-r--r-- | core/java/android/util/StatsManager.java | 22 |
8 files changed, 670 insertions, 7 deletions
diff --git a/core/java/android/app/StatsManager.java b/core/java/android/app/StatsManager.java new file mode 100644 index 000000000000..963fc7762cba --- /dev/null +++ b/core/java/android/app/StatsManager.java @@ -0,0 +1,238 @@ +/* + * Copyright 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.app; + +import android.Manifest; +import android.annotation.RequiresPermission; +import android.annotation.SystemApi; +import android.os.IBinder; +import android.os.IStatsManager; +import android.os.RemoteException; +import android.os.ServiceManager; +import android.util.Slog; + +/** + * API for statsd clients to send configurations and retrieve data. + * + * @hide + */ +@SystemApi +public final class StatsManager extends android.util.StatsManager { // TODO: Remove the extends. + IStatsManager mService; + private static final String TAG = "StatsManager"; + + /** Long extra of uid that added the relevant stats config. */ + public static final String EXTRA_STATS_CONFIG_UID = + "android.app.extra.STATS_CONFIG_UID"; + /** Long extra of the relevant stats config's configKey. */ + public static final String EXTRA_STATS_CONFIG_KEY = + "android.app.extra.STATS_CONFIG_KEY"; + /** Long extra of the relevant statsd_config.proto's Subscription.id. */ + public static final String EXTRA_STATS_SUBSCRIPTION_ID = + "android.app.extra.STATS_SUBSCRIPTION_ID"; + /** Long extra of the relevant statsd_config.proto's Subscription.rule_id. */ + public static final String EXTRA_STATS_SUBSCRIPTION_RULE_ID = + "android.app.extra.STATS_SUBSCRIPTION_RULE_ID"; + /** + * Extra of a {@link android.os.StatsDimensionsValue} representing sliced dimension value + * information. + */ + public static final String EXTRA_STATS_DIMENSIONS_VALUE = + "android.app.extra.STATS_DIMENSIONS_VALUE"; + + /** + * Constructor for StatsManagerClient. + * + * @hide + */ + public StatsManager() { + } + + /** + * Clients can send a configuration and simultaneously registers the name of a broadcast + * receiver that listens for when it should request data. + * + * @param configKey An arbitrary integer that allows clients to track the configuration. + * @param config Wire-encoded StatsDConfig proto that specifies metrics (and all + * dependencies eg, conditions and matchers). + * @param pkg The package name to receive the broadcast. + * @param cls The name of the class that receives the broadcast. + * @return true if successful + */ + @RequiresPermission(Manifest.permission.DUMP) + public boolean addConfiguration(long configKey, byte[] config, String pkg, String cls) { + synchronized (this) { + try { + IStatsManager service = getIStatsManagerLocked(); + if (service == null) { + Slog.d(TAG, "Failed to find statsd when adding configuration"); + return false; + } + return service.addConfiguration(configKey, config, pkg, cls); + } catch (RemoteException e) { + Slog.d(TAG, "Failed to connect to statsd when adding configuration"); + return false; + } + } + } + + /** + * Remove a configuration from logging. + * + * @param configKey Configuration key to remove. + * @return true if successful + */ + @RequiresPermission(Manifest.permission.DUMP) + public boolean removeConfiguration(long configKey) { + synchronized (this) { + try { + IStatsManager service = getIStatsManagerLocked(); + if (service == null) { + Slog.d(TAG, "Failed to find statsd when removing configuration"); + return false; + } + return service.removeConfiguration(configKey); + } catch (RemoteException e) { + Slog.d(TAG, "Failed to connect to statsd when removing configuration"); + return false; + } + } + } + + /** + * Set the PendingIntent to be used when broadcasting subscriber information to the given + * subscriberId within the given config. + * + * <p> + * Suppose that the calling uid has added a config with key configKey, 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 pendingIntent with + * that subscriberId (for that config), so that this pendingIntent is used to send the broadcast + * when the anomaly is detected. + * + * <p> + * When statsd sends the broadcast, the PendingIntent will used to send an intent with + * information of + * {@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_DIMENSIONS_VALUE}. + * + * <p> + * This function can only be called by the owner (uid) of the config. It must be called each + * time statsd starts. The config must have been added first (via addConfiguration()). + * + * @param configKey The integer naming the config to which this subscriber is attached. + * @param subscriberId ID of the subscriber, as used in the config. + * @param pendingIntent the PendingIntent to use when broadcasting info to the subscriber + * associated with the given subscriberId. May be null, in which case + * it undoes any previous setting of this subscriberId. + * @return true if successful + */ + @RequiresPermission(Manifest.permission.DUMP) + public boolean setBroadcastSubscriber(long configKey, + long subscriberId, + PendingIntent pendingIntent) { + synchronized (this) { + try { + IStatsManager service = getIStatsManagerLocked(); + if (service == null) { + Slog.w(TAG, "Failed to find statsd when adding broadcast subscriber"); + return false; + } + if (pendingIntent != null) { + // Extracts IIntentSender from the PendingIntent and turns it into an IBinder. + IBinder intentSender = pendingIntent.getTarget().asBinder(); + return service.setBroadcastSubscriber(configKey, subscriberId, intentSender); + } else { + return service.unsetBroadcastSubscriber(configKey, subscriberId); + } + } catch (RemoteException e) { + Slog.w(TAG, "Failed to connect to statsd when adding broadcast subscriber", e); + return false; + } + } + } + + /** + * Clients can request data with a binder call. This getter is destructive and also clears + * the retrieved metrics from statsd memory. + * + * @param configKey Configuration key to retrieve data from. + * @return Serialized ConfigMetricsReportList proto. Returns null on failure. + */ + @RequiresPermission(Manifest.permission.DUMP) + public byte[] getData(long configKey) { + synchronized (this) { + try { + IStatsManager service = getIStatsManagerLocked(); + if (service == null) { + Slog.d(TAG, "Failed to find statsd when getting data"); + return null; + } + return service.getData(configKey); + } catch (RemoteException e) { + Slog.d(TAG, "Failed to connecto statsd when getting data"); + return null; + } + } + } + + /** + * Clients can request metadata for statsd. Will contain stats across all configurations but not + * the actual metrics themselves (metrics must be collected via {@link #getData(String)}. + * This getter is not destructive and will not reset any metrics/counters. + * + * @return Serialized StatsdStatsReport proto. Returns null on failure. + */ + @RequiresPermission(Manifest.permission.DUMP) + public byte[] getMetadata() { + synchronized (this) { + try { + IStatsManager service = getIStatsManagerLocked(); + if (service == null) { + Slog.d(TAG, "Failed to find statsd when getting metadata"); + return null; + } + return service.getMetadata(); + } catch (RemoteException e) { + Slog.d(TAG, "Failed to connecto statsd when getting metadata"); + return null; + } + } + } + + private class StatsdDeathRecipient implements IBinder.DeathRecipient { + @Override + public void binderDied() { + synchronized (this) { + mService = null; + } + } + } + + private IStatsManager getIStatsManagerLocked() throws RemoteException { + if (mService != null) { + return mService; + } + mService = IStatsManager.Stub.asInterface(ServiceManager.getService("stats")); + if (mService != null) { + mService.asBinder().linkToDeath(new StatsdDeathRecipient(), 0); + } + return mService; + } +} diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java index fb8d1017e205..4310434c70be 100644 --- a/core/java/android/app/SystemServiceRegistry.java +++ b/core/java/android/app/SystemServiceRegistry.java @@ -141,7 +141,6 @@ import android.telephony.TelephonyManager; import android.telephony.euicc.EuiccCardManager; import android.telephony.euicc.EuiccManager; import android.util.Log; -import android.util.StatsManager; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.WindowManager; diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index f69aab01d821..1b050330ceb6 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -4121,7 +4121,7 @@ public abstract class Context { public static final String STATS_COMPANION_SERVICE = "statscompanion"; /** - * Use with {@link #getSystemService(String)} to retrieve an {@link android.stats.StatsManager}. + * Use with {@link #getSystemService(String)} to retrieve an {@link android.app.StatsManager}. * @hide */ @SystemApi diff --git a/core/java/android/os/IStatsCompanionService.aidl b/core/java/android/os/IStatsCompanionService.aidl index 1d2a40850454..8a27700edc15 100644 --- a/core/java/android/os/IStatsCompanionService.aidl +++ b/core/java/android/os/IStatsCompanionService.aidl @@ -16,6 +16,7 @@ package android.os; +import android.os.StatsDimensionsValue; import android.os.StatsLogEventWrapper; /** @@ -55,8 +56,17 @@ interface IStatsCompanionService { StatsLogEventWrapper[] pullData(int pullCode); /** Send a broadcast to the specified pkg and class that it should getData now. */ + // TODO: Rename this and use a pending intent instead. oneway void sendBroadcast(String pkg, String cls); + /** + * 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 StatsDimensionsValue dimensionsValue); + /** Tells StatsCompaionService to grab the uid map snapshot and send it to statsd. */ oneway void triggerUidSnapshot(); } diff --git a/core/java/android/os/IStatsManager.aidl b/core/java/android/os/IStatsManager.aidl index 29812e8ab06e..679b49dfb974 100644 --- a/core/java/android/os/IStatsManager.aidl +++ b/core/java/android/os/IStatsManager.aidl @@ -81,7 +81,7 @@ interface IStatsManager { /** * Sets a configuration with the specified config key and subscribes to updates for this * configuration key. Broadcasts will be sent if this configuration needs to be collected. - * The configuration must be a wire-encoded StatsDConfig. The caller specifies the name of the + * The configuration must be a wire-encoded StatsdConfig. The caller specifies the name of the * package and class that should receive these broadcasts. * * Returns if this configuration was correctly registered. @@ -95,4 +95,33 @@ interface IStatsManager { * Returns if this configuration key was removed. */ boolean removeConfiguration(in long configKey); + + /** + * Set the IIntentSender (i.e. PendingIntent) 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 + * 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 + * 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. + * + * Returns true if successful. + */ + boolean setBroadcastSubscriber(long configKey, long subscriberId, in IBinder intentSender); + + /** + * Undoes setBroadcastSubscriber() for the (configKey, 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. + * + * Returns true if successful. + */ + boolean unsetBroadcastSubscriber(long configKey, long subscriberId); } diff --git a/core/java/android/os/StatsDimensionsValue.aidl b/core/java/android/os/StatsDimensionsValue.aidl new file mode 100644 index 000000000000..81a14a4b67d9 --- /dev/null +++ b/core/java/android/os/StatsDimensionsValue.aidl @@ -0,0 +1,20 @@ +/** + * Copyright (c) 2018, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.os; + +/** @hide */ +parcelable StatsDimensionsValue cpp_header "android/os/StatsDimensionsValue.h";
\ No newline at end of file diff --git a/core/java/android/os/StatsDimensionsValue.java b/core/java/android/os/StatsDimensionsValue.java new file mode 100644 index 000000000000..257cc5250dad --- /dev/null +++ b/core/java/android/os/StatsDimensionsValue.java @@ -0,0 +1,353 @@ +/* + * Copyright 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.os; + +import android.annotation.SystemApi; +import android.util.Slog; + +import java.util.ArrayList; +import java.util.List; + +/** + * Container for statsd dimension value information, corresponding to a + * stats_log.proto's DimensionValue. + * + * This consists of a field (an int representing a statsd atom field) + * and a value (which may be one of a number of types). + * + * <p> + * Only a single value is held, and it is necessarily one of the following types: + * {@link String}, int, long, boolean, float, + * or tuple (i.e. {@link List} of {@code StatsDimensionsValue}). + * + * The type of value held can be retrieved using {@link #getValueType()}, which returns one of the + * following ints, depending on the type of value: + * <ul> + * <li>{@link #STRING_VALUE_TYPE}</li> + * <li>{@link #INT_VALUE_TYPE}</li> + * <li>{@link #LONG_VALUE_TYPE}</li> + * <li>{@link #BOOLEAN_VALUE_TYPE}</li> + * <li>{@link #FLOAT_VALUE_TYPE}</li> + * <li>{@link #TUPLE_VALUE_TYPE}</li> + * </ul> + * Alternatively, this can be determined using {@link #isValueType(int)} with one of these constants + * as a parameter. + * The value itself can be retrieved using the correct get...Value() function for its type. + * + * <p> + * The field is always an int, and always exists; it can be obtained using {@link #getField()}. + * + * + * @hide + */ +@SystemApi +public final class StatsDimensionsValue implements Parcelable { + private static final String TAG = "StatsDimensionsValue"; + + // Values of the value type correspond to stats_log.proto's DimensionValue fields. + // Keep constants in sync with services/include/android/os/StatsDimensionsValue.h. + /** Indicates that this holds a String. */ + public static final int STRING_VALUE_TYPE = 2; + /** Indicates that this holds an int. */ + public static final int INT_VALUE_TYPE = 3; + /** Indicates that this holds a long. */ + public static final int LONG_VALUE_TYPE = 4; + /** Indicates that this holds a boolean. */ + public static final int BOOLEAN_VALUE_TYPE = 5; + /** Indicates that this holds a float. */ + public static final int FLOAT_VALUE_TYPE = 6; + /** Indicates that this holds a List of StatsDimensionsValues. */ + public static final int TUPLE_VALUE_TYPE = 7; + + /** Value of a stats_log.proto DimensionsValue.field. */ + private final int mField; + + /** Type of stats_log.proto DimensionsValue.value, according to the VALUE_TYPEs above. */ + private final int mValueType; + + /** + * Value of a stats_log.proto DimensionsValue.value. + * String, Integer, Long, Boolean, Float, or StatsDimensionsValue[]. + */ + private final Object mValue; // immutable or array of immutables + + /** + * Creates a {@code StatsDimensionValue} from a parcel. + * + * @hide + */ + public StatsDimensionsValue(Parcel in) { + mField = in.readInt(); + mValueType = in.readInt(); + mValue = readValueFromParcel(mValueType, in); + } + + /** + * Return the field, i.e. the tag of a statsd atom. + * + * @return the field + */ + public int getField() { + return mField; + } + + /** + * Retrieve the String held, if any. + * + * @return the {@link String} held if {@link #getValueType()} == {@link #STRING_VALUE_TYPE}, + * null otherwise + */ + public String getStringValue() { + try { + if (mValueType == STRING_VALUE_TYPE) return (String) mValue; + } catch (ClassCastException e) { + Slog.w(TAG, "Failed to successfully get value", e); + } + return null; + } + + /** + * Retrieve the int held, if any. + * + * @return the int held if {@link #getValueType()} == {@link #INT_VALUE_TYPE}, 0 otherwise + */ + public int getIntValue() { + try { + if (mValueType == INT_VALUE_TYPE) return (Integer) mValue; + } catch (ClassCastException e) { + Slog.w(TAG, "Failed to successfully get value", e); + } + return 0; + } + + /** + * Retrieve the long held, if any. + * + * @return the long held if {@link #getValueType()} == {@link #LONG_VALUE_TYPE}, 0 otherwise + */ + public long getLongValue() { + try { + if (mValueType == LONG_VALUE_TYPE) return (Long) mValue; + } catch (ClassCastException e) { + Slog.w(TAG, "Failed to successfully get value", e); + } + return 0; + } + + /** + * Retrieve the boolean held, if any. + * + * @return the boolean held if {@link #getValueType()} == {@link #BOOLEAN_VALUE_TYPE}, + * false otherwise + */ + public boolean getBooleanValue() { + try { + if (mValueType == BOOLEAN_VALUE_TYPE) return (Boolean) mValue; + } catch (ClassCastException e) { + Slog.w(TAG, "Failed to successfully get value", e); + } + return false; + } + + /** + * Retrieve the float held, if any. + * + * @return the float held if {@link #getValueType()} == {@link #FLOAT_VALUE_TYPE}, 0 otherwise + */ + public float getFloatValue() { + try { + if (mValueType == FLOAT_VALUE_TYPE) return (Float) mValue; + } catch (ClassCastException e) { + Slog.w(TAG, "Failed to successfully get value", e); + } + return 0; + } + + /** + * Retrieve the tuple, in the form of a {@link List} of {@link StatsDimensionsValue}, held, + * if any. + * + * @return the {@link List} of {@link StatsDimensionsValue} held + * if {@link #getValueType()} == {@link #TUPLE_VALUE_TYPE}, + * null otherwise + */ + public List<StatsDimensionsValue> getTupleValueList() { + if (mValueType != TUPLE_VALUE_TYPE) { + return null; + } + try { + StatsDimensionsValue[] orig = (StatsDimensionsValue[]) mValue; + List<StatsDimensionsValue> copy = new ArrayList<>(orig.length); + // Shallow copy since StatsDimensionsValue is immutable anyway + for (int i = 0; i < orig.length; i++) { + copy.add(orig[i]); + } + return copy; + } catch (ClassCastException e) { + Slog.w(TAG, "Failed to successfully get value", e); + return null; + } + } + + /** + * Returns the constant representing the type of value stored, namely one of + * <ul> + * <li>{@link #STRING_VALUE_TYPE}</li> + * <li>{@link #INT_VALUE_TYPE}</li> + * <li>{@link #LONG_VALUE_TYPE}</li> + * <li>{@link #BOOLEAN_VALUE_TYPE}</li> + * <li>{@link #FLOAT_VALUE_TYPE}</li> + * <li>{@link #TUPLE_VALUE_TYPE}</li> + * </ul> + * + * @return the constant representing the type of value stored + */ + public int getValueType() { + return mValueType; + } + + /** + * Returns whether the type of value stored is equal to the given type. + * + * @param valueType int representing the type of value stored, as used in {@link #getValueType} + * @return true if {@link #getValueType()} is equal to {@code valueType}. + */ + public boolean isValueType(int valueType) { + return mValueType == valueType; + } + + /** + * Returns a String representing the information in this StatsDimensionValue. + * No guarantees are made about the format of this String. + * + * @return String representation + * + * @hide + */ + // Follows the format of statsd's dimension.h toString. + public String toString() { + try { + StringBuilder sb = new StringBuilder(); + sb.append(mField); + sb.append(":"); + if (mValueType == TUPLE_VALUE_TYPE) { + sb.append("{"); + StatsDimensionsValue[] sbvs = (StatsDimensionsValue[]) mValue; + for (int i = 0; i < sbvs.length; i++) { + sb.append(sbvs[i].toString()); + sb.append("|"); + } + sb.append("}"); + } else { + sb.append(mValue.toString()); + } + return sb.toString(); + } catch (ClassCastException e) { + Slog.w(TAG, "Failed to successfully get value", e); + } + return ""; + } + + /** + * Parcelable Creator for StatsDimensionsValue. + */ + public static final Parcelable.Creator<StatsDimensionsValue> CREATOR = new + Parcelable.Creator<StatsDimensionsValue>() { + public StatsDimensionsValue createFromParcel(Parcel in) { + return new StatsDimensionsValue(in); + } + + public StatsDimensionsValue[] newArray(int size) { + return new StatsDimensionsValue[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeInt(mField); + out.writeInt(mValueType); + writeValueToParcel(mValueType, mValue, out, flags); + } + + /** Writes mValue to a parcel. Returns true if succeeds. */ + private static boolean writeValueToParcel(int valueType, Object value, Parcel out, int flags) { + try { + switch (valueType) { + case STRING_VALUE_TYPE: + out.writeString((String) value); + return true; + case INT_VALUE_TYPE: + out.writeInt((Integer) value); + return true; + case LONG_VALUE_TYPE: + out.writeLong((Long) value); + return true; + case BOOLEAN_VALUE_TYPE: + out.writeBoolean((Boolean) value); + return true; + case FLOAT_VALUE_TYPE: + out.writeFloat((Float) value); + return true; + case TUPLE_VALUE_TYPE: { + StatsDimensionsValue[] values = (StatsDimensionsValue[]) value; + out.writeInt(values.length); + for (int i = 0; i < values.length; i++) { + values[i].writeToParcel(out, flags); + } + return true; + } + default: + Slog.w(TAG, "readValue of an impossible type " + valueType); + return false; + } + } catch (ClassCastException e) { + Slog.w(TAG, "writeValue cast failed", e); + return false; + } + } + + /** Reads mValue from a parcel. */ + private static Object readValueFromParcel(int valueType, Parcel parcel) { + switch (valueType) { + case STRING_VALUE_TYPE: + return parcel.readString(); + case INT_VALUE_TYPE: + return parcel.readInt(); + case LONG_VALUE_TYPE: + return parcel.readLong(); + case BOOLEAN_VALUE_TYPE: + return parcel.readBoolean(); + case FLOAT_VALUE_TYPE: + return parcel.readFloat(); + case TUPLE_VALUE_TYPE: { + final int sz = parcel.readInt(); + StatsDimensionsValue[] values = new StatsDimensionsValue[sz]; + for (int i = 0; i < sz; i++) { + values[i] = new StatsDimensionsValue(parcel); + } + return values; + } + default: + Slog.w(TAG, "readValue of an impossible type " + valueType); + return null; + } + } +} diff --git a/core/java/android/util/StatsManager.java b/core/java/android/util/StatsManager.java index e0d085cfaa66..687aa8375e01 100644 --- a/core/java/android/util/StatsManager.java +++ b/core/java/android/util/StatsManager.java @@ -17,19 +17,33 @@ package android.util; import android.Manifest; import android.annotation.RequiresPermission; -import android.annotation.SystemApi; import android.os.IBinder; import android.os.IStatsManager; import android.os.RemoteException; import android.os.ServiceManager; + +/* + * + * + * + * + * THIS ENTIRE FILE IS ONLY TEMPORARY TO PREVENT BREAKAGES OF DEPENDENCIES ON OLD APIS. + * The new StatsManager is to be found in android.app.StatsManager. + * TODO: Delete this file! + * + * + * + * + */ + + /** * API for StatsD clients to send configurations and retrieve data. * * @hide */ -@SystemApi -public final class StatsManager { +public class StatsManager { IStatsManager mService; private static final String TAG = "StatsManager"; @@ -55,7 +69,7 @@ public final class StatsManager { * Clients can send a configuration and simultaneously registers the name of a broadcast * receiver that listens for when it should request data. * - * @param configKey An arbitrary string that allows clients to track the configuration. + * @param configKey An arbitrary integer that allows clients to track the configuration. * @param config Wire-encoded StatsDConfig proto that specifies metrics (and all * dependencies eg, conditions and matchers). * @param pkg The package name to receive the broadcast. |
