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
This commit is contained in:
@@ -1941,6 +1941,22 @@ package android.bluetooth {
|
||||
field @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public static final String ACTION_CONNECTION_STATE_CHANGED = "android.bluetooth.a2dp-sink.profile.action.CONNECTION_STATE_CHANGED";
|
||||
}
|
||||
|
||||
public final class BluetoothActivityEnergyInfo implements android.os.Parcelable {
|
||||
method public int getBluetoothStackState();
|
||||
method public long getControllerEnergyUsed();
|
||||
method public long getControllerIdleTimeMillis();
|
||||
method public long getControllerRxTimeMillis();
|
||||
method public long getControllerTxTimeMillis();
|
||||
method public long getTimeStamp();
|
||||
method @NonNull public java.util.List<android.bluetooth.UidTraffic> getUidTraffic();
|
||||
method public boolean isValid();
|
||||
field public static final int BT_STACK_STATE_INVALID = 0; // 0x0
|
||||
field public static final int BT_STACK_STATE_STATE_ACTIVE = 1; // 0x1
|
||||
field public static final int BT_STACK_STATE_STATE_IDLE = 3; // 0x3
|
||||
field public static final int BT_STACK_STATE_STATE_SCANNING = 2; // 0x2
|
||||
field @NonNull public static final android.os.Parcelable.Creator<android.bluetooth.BluetoothActivityEnergyInfo> CREATOR;
|
||||
}
|
||||
|
||||
public final class BluetoothAdapter {
|
||||
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean addOnMetadataChangedListener(@NonNull android.bluetooth.BluetoothDevice, @NonNull java.util.concurrent.Executor, @NonNull android.bluetooth.BluetoothAdapter.OnMetadataChangedListener);
|
||||
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean disable(boolean);
|
||||
@@ -2240,6 +2256,13 @@ package android.bluetooth {
|
||||
method @NonNull public android.bluetooth.OobData.LeBuilder setRandomizerHash(@NonNull byte[]);
|
||||
}
|
||||
|
||||
public final class UidTraffic implements java.lang.Cloneable android.os.Parcelable {
|
||||
method public long getRxBytes();
|
||||
method public long getTxBytes();
|
||||
method public int getUid();
|
||||
field @NonNull public static final android.os.Parcelable.Creator<android.bluetooth.UidTraffic> CREATOR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package android.bluetooth.le {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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="
|
||||
|
||||
@@ -12526,7 +12526,7 @@ public class BatteryStatsImpl extends BatteryStats {
|
||||
rxTimeMs = info.getControllerRxTimeMillis();
|
||||
txTimeMs = info.getControllerTxTimeMillis();
|
||||
energy = info.getControllerEnergyUsed();
|
||||
if (info.getUidTraffic() != null) {
|
||||
if (!info.getUidTraffic().isEmpty()) {
|
||||
for (UidTraffic traffic : info.getUidTraffic()) {
|
||||
uidRxBytes.put(traffic.getUid(), traffic.getRxBytes());
|
||||
uidTxBytes.put(traffic.getUid(), traffic.getTxBytes());
|
||||
@@ -12677,10 +12677,10 @@ public class BatteryStatsImpl extends BatteryStats {
|
||||
long totalTxBytes = 0;
|
||||
long totalRxBytes = 0;
|
||||
|
||||
final UidTraffic[] uidTraffic = info.getUidTraffic();
|
||||
final int numUids = uidTraffic != null ? uidTraffic.length : 0;
|
||||
final List<UidTraffic> uidTraffic = info.getUidTraffic();
|
||||
final int numUids = uidTraffic.size();
|
||||
for (int i = 0; i < numUids; i++) {
|
||||
final UidTraffic traffic = uidTraffic[i];
|
||||
final UidTraffic traffic = uidTraffic.get(i);
|
||||
final long rxBytes = traffic.getRxBytes() - mLastBluetoothActivityInfo.uidRxBytes.get(
|
||||
traffic.getUid());
|
||||
final long txBytes = traffic.getTxBytes() - mLastBluetoothActivityInfo.uidTxBytes.get(
|
||||
@@ -12703,7 +12703,7 @@ public class BatteryStatsImpl extends BatteryStats {
|
||||
if ((totalTxBytes != 0 || totalRxBytes != 0) && (leftOverRxTimeMs != 0
|
||||
|| leftOverTxTimeMs != 0)) {
|
||||
for (int i = 0; i < numUids; i++) {
|
||||
final UidTraffic traffic = uidTraffic[i];
|
||||
final UidTraffic traffic = uidTraffic.get(i);
|
||||
final int uid = traffic.getUid();
|
||||
final long rxBytes =
|
||||
traffic.getRxBytes() - mLastBluetoothActivityInfo.uidRxBytes.get(uid);
|
||||
|
||||
@@ -33,6 +33,8 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class BluetoothPowerCalculatorTest {
|
||||
@@ -105,10 +107,10 @@ public class BluetoothPowerCalculatorTest {
|
||||
final BluetoothActivityEnergyInfo info = new BluetoothActivityEnergyInfo(1000,
|
||||
BluetoothActivityEnergyInfo.BT_STACK_STATE_STATE_ACTIVE, 7000, 5000, 0,
|
||||
reportedEnergyUc);
|
||||
info.setUidTraffic(new UidTraffic[]{
|
||||
new UidTraffic(Process.BLUETOOTH_UID, 1000, 2000),
|
||||
new UidTraffic(APP_UID, 3000, 4000)
|
||||
});
|
||||
info.setUidTraffic(new ArrayList<UidTraffic>(){{
|
||||
add(new UidTraffic(Process.BLUETOOTH_UID, 1000, 2000));
|
||||
add(new UidTraffic(APP_UID, 3000, 4000));
|
||||
}});
|
||||
mStatsRule.getBatteryStats().updateBluetoothStateLocked(info,
|
||||
consumedEnergyUc, 1000, 1000);
|
||||
}
|
||||
|
||||
@@ -1611,7 +1611,7 @@ public class StatsPullAtomService extends SystemService {
|
||||
|
||||
int pullBluetoothBytesTransferLocked(int atomTag, List<StatsEvent> pulledData) {
|
||||
BluetoothActivityEnergyInfo info = fetchBluetoothData();
|
||||
if (info == null || info.getUidTraffic() == null) {
|
||||
if (info == null) {
|
||||
return StatsManager.PULL_SKIP;
|
||||
}
|
||||
for (UidTraffic traffic : info.getUidTraffic()) {
|
||||
|
||||
Reference in New Issue
Block a user