diff options
| author | Rahul Sabnis <rahulsabnis@google.com> | 2021-10-25 17:24:00 +0000 |
|---|---|---|
| committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-10-25 17:24:00 +0000 |
| commit | 01eb71be0094eb6718d59684defba426b1d19b8b (patch) | |
| tree | 3625046b0bfaa581079de256bc05e5455d5a5cb7 /core/java/android | |
| parent | bedc062659fb725ceb050b63b767e1200667ef23 (diff) | |
| parent | 6f74b5dd8b4287d055d41d2c893d85c6383761a6 (diff) | |
Merge "Adding @SystemApi annotation to Bluetooth energy stats." am: a12c77ab44 am: a125c31d21 am: f91171d35e am: 6f74b5dd8b
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1854179
Change-Id: I9e271a266c640fb739a5c394d0f5d091803143f4
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/bluetooth/BluetoothActivityEnergyInfo.java | 65 | ||||
| -rw-r--r-- | core/java/android/bluetooth/UidTraffic.java | 29 |
2 files changed, 71 insertions, 23 deletions
diff --git a/core/java/android/bluetooth/BluetoothActivityEnergyInfo.java b/core/java/android/bluetooth/BluetoothActivityEnergyInfo.java index df065bf1bf8d..f371c6d78221 100644 --- a/core/java/android/bluetooth/BluetoothActivityEnergyInfo.java +++ b/core/java/android/bluetooth/BluetoothActivityEnergyInfo.java @@ -16,18 +16,25 @@ package android.bluetooth; +import android.annotation.IntDef; +import android.annotation.NonNull; +import android.annotation.SystemApi; import android.os.Parcel; import android.os.Parcelable; -import java.util.Arrays; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.util.Collections; +import java.util.List; /** * Record of energy and activity information from controller and * underlying bt stack state.Timestamp the record with system - * time + * time. * * @hide */ +@SystemApi(client = SystemApi.Client.PRIVILEGED_APPS) public final class BluetoothActivityEnergyInfo implements Parcelable { private final long mTimestamp; private int mBluetoothStackState; @@ -35,13 +42,24 @@ public final class BluetoothActivityEnergyInfo implements Parcelable { private long mControllerRxTimeMs; private long mControllerIdleTimeMs; private long mControllerEnergyUsed; - private UidTraffic[] mUidTraffic; + private List<UidTraffic> mUidTraffic; + + /** @hide */ + @IntDef(prefix = { "BT_STACK_STATE_" }, value = { + BT_STACK_STATE_INVALID, + BT_STACK_STATE_STATE_ACTIVE, + BT_STACK_STATE_STATE_SCANNING, + BT_STACK_STATE_STATE_IDLE + }) + @Retention(RetentionPolicy.SOURCE) + public @interface BluetoothStackState {} public static final int BT_STACK_STATE_INVALID = 0; public static final int BT_STACK_STATE_STATE_ACTIVE = 1; public static final int BT_STACK_STATE_STATE_SCANNING = 2; public static final int BT_STACK_STATE_STATE_IDLE = 3; + /** @hide */ public BluetoothActivityEnergyInfo(long timestamp, int stackState, long txTime, long rxTime, long idleTime, long energyUsed) { mTimestamp = timestamp; @@ -52,17 +70,18 @@ public final class BluetoothActivityEnergyInfo implements Parcelable { mControllerEnergyUsed = energyUsed; } - @SuppressWarnings("unchecked") - BluetoothActivityEnergyInfo(Parcel in) { + /** @hide */ + private BluetoothActivityEnergyInfo(Parcel in) { mTimestamp = in.readLong(); mBluetoothStackState = in.readInt(); mControllerTxTimeMs = in.readLong(); mControllerRxTimeMs = in.readLong(); mControllerIdleTimeMs = in.readLong(); mControllerEnergyUsed = in.readLong(); - mUidTraffic = in.createTypedArray(UidTraffic.CREATOR); + mUidTraffic = in.createTypedArrayList(UidTraffic.CREATOR); } + /** @hide */ @Override public String toString() { return "BluetoothActivityEnergyInfo{" @@ -72,11 +91,11 @@ public final class BluetoothActivityEnergyInfo implements Parcelable { + " mControllerRxTimeMs=" + mControllerRxTimeMs + " mControllerIdleTimeMs=" + mControllerIdleTimeMs + " mControllerEnergyUsed=" + mControllerEnergyUsed - + " mUidTraffic=" + Arrays.toString(mUidTraffic) + + " mUidTraffic=" + mUidTraffic + " }"; } - public static final @android.annotation.NonNull Parcelable.Creator<BluetoothActivityEnergyInfo> CREATOR = + public static final @NonNull Parcelable.Creator<BluetoothActivityEnergyInfo> CREATOR = new Parcelable.Creator<BluetoothActivityEnergyInfo>() { public BluetoothActivityEnergyInfo createFromParcel(Parcel in) { return new BluetoothActivityEnergyInfo(in); @@ -87,9 +106,8 @@ public final class BluetoothActivityEnergyInfo implements Parcelable { } }; - + /** @hide */ @Override - @SuppressWarnings("unchecked") public void writeToParcel(Parcel out, int flags) { out.writeLong(mTimestamp); out.writeInt(mBluetoothStackState); @@ -97,17 +115,21 @@ public final class BluetoothActivityEnergyInfo implements Parcelable { out.writeLong(mControllerRxTimeMs); out.writeLong(mControllerIdleTimeMs); out.writeLong(mControllerEnergyUsed); - out.writeTypedArray(mUidTraffic, flags); + out.writeTypedList(mUidTraffic); } + /** @hide */ @Override public int describeContents() { return 0; } /** - * @return bt stack reported state + * Get the Bluetooth stack state associated with the energy info. + * + * @return one of {@link #BluetoothStackState} states */ + @BluetoothStackState public int getBluetoothStackState() { return mBluetoothStackState; } @@ -134,7 +156,7 @@ public final class BluetoothActivityEnergyInfo implements Parcelable { } /** - * product of current(mA), voltage(V) and time(ms) + * Get the product of current (mA), voltage (V), and time (ms). * * @return energy used */ @@ -143,22 +165,31 @@ public final class BluetoothActivityEnergyInfo implements Parcelable { } /** - * @return timestamp(real time elapsed in milliseconds since boot) of record creation. + * @return timestamp (real time elapsed in milliseconds since boot) of record creation */ public long getTimeStamp() { return mTimestamp; } - public UidTraffic[] getUidTraffic() { + /** + * Get the {@link List} of each application {@link android.bluetooth.UidTraffic}. + * + * @return current {@link List} of {@link android.bluetooth.UidTraffic} + */ + public @NonNull List<UidTraffic> getUidTraffic() { + if (mUidTraffic == null) { + return Collections.emptyList(); + } return mUidTraffic; } - public void setUidTraffic(UidTraffic[] traffic) { + /** @hide */ + public void setUidTraffic(List<UidTraffic> traffic) { mUidTraffic = traffic; } /** - * @return if the record is valid + * @return true if the record is valid */ public boolean isValid() { return ((mControllerTxTimeMs >= 0) && (mControllerRxTimeMs >= 0) diff --git a/core/java/android/bluetooth/UidTraffic.java b/core/java/android/bluetooth/UidTraffic.java index 2ee786a59091..9982fa6121e4 100644 --- a/core/java/android/bluetooth/UidTraffic.java +++ b/core/java/android/bluetooth/UidTraffic.java @@ -15,6 +15,7 @@ */ package android.bluetooth; +import android.annotation.SystemApi; import android.os.Parcel; import android.os.Parcelable; @@ -23,27 +24,27 @@ import android.os.Parcelable; * * @hide */ -public class UidTraffic implements Cloneable, Parcelable { +@SystemApi(client = SystemApi.Client.PRIVILEGED_APPS) +public final class UidTraffic implements Cloneable, Parcelable { private final int mAppUid; private long mRxBytes; private long mTxBytes; - public UidTraffic(int appUid) { - mAppUid = appUid; - } - + /** @hide */ public UidTraffic(int appUid, long rx, long tx) { mAppUid = appUid; mRxBytes = rx; mTxBytes = tx; } - UidTraffic(Parcel in) { + /** @hide */ + private UidTraffic(Parcel in) { mAppUid = in.readInt(); mRxBytes = in.readLong(); mTxBytes = in.readLong(); } + /** @hide */ @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(mAppUid); @@ -51,44 +52,60 @@ public class UidTraffic implements Cloneable, Parcelable { dest.writeLong(mTxBytes); } + /** @hide */ public void setRxBytes(long bytes) { mRxBytes = bytes; } + /** @hide */ public void setTxBytes(long bytes) { mTxBytes = bytes; } + /** @hide */ public void addRxBytes(long bytes) { mRxBytes += bytes; } + /** @hide */ public void addTxBytes(long bytes) { mTxBytes += bytes; } + /** + * @return corresponding app Uid + */ public int getUid() { return mAppUid; } + /** + * @return rx bytes count + */ public long getRxBytes() { return mRxBytes; } + /** + * @return tx bytes count + */ public long getTxBytes() { return mTxBytes; } + /** @hide */ @Override public int describeContents() { return 0; } + /** @hide */ @Override public UidTraffic clone() { return new UidTraffic(mAppUid, mRxBytes, mTxBytes); } + /** @hide */ @Override public String toString() { return "UidTraffic{mAppUid=" + mAppUid + ", mRxBytes=" + mRxBytes + ", mTxBytes=" |
