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

Commit 443c9000 authored by Adam Lesinski's avatar Adam Lesinski Committed by Android (Google) Code Review
Browse files

Merge "Record bytes transferred for bluetooth"

parents 14ffbfac 3b3264d5
Loading
Loading
Loading
Loading
+32 −13
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package android.bluetooth;
import android.os.Parcel;
import android.os.Parcelable;

import java.util.Arrays;

/**
 * Record of energy and activity information from controller and
 * underlying bt stack state.Timestamp the record with system
@@ -27,11 +29,12 @@ import android.os.Parcelable;
 */
public final class BluetoothActivityEnergyInfo implements Parcelable {
    private final long mTimestamp;
    private final int mBluetoothStackState;
    private final long mControllerTxTimeMs;
    private final long mControllerRxTimeMs;
    private final long mControllerIdleTimeMs;
    private final long mControllerEnergyUsed;
    private int mBluetoothStackState;
    private long mControllerTxTimeMs;
    private long mControllerRxTimeMs;
    private long mControllerIdleTimeMs;
    private long mControllerEnergyUsed;
    private UidTraffic[] mUidTraffic;

    public static final int BT_STACK_STATE_INVALID = 0;
    public static final int BT_STACK_STATE_STATE_ACTIVE = 1;
@@ -48,6 +51,17 @@ public final class BluetoothActivityEnergyInfo implements Parcelable {
        mControllerEnergyUsed = energyUsed;
    }

    @SuppressWarnings("unchecked")
    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);
    }

    @Override
    public String toString() {
        return "BluetoothActivityEnergyInfo{"
@@ -57,26 +71,22 @@ public final class BluetoothActivityEnergyInfo implements Parcelable {
            + " mControllerRxTimeMs=" + mControllerRxTimeMs
            + " mControllerIdleTimeMs=" + mControllerIdleTimeMs
            + " mControllerEnergyUsed=" + mControllerEnergyUsed
            + " mUidTraffic=" + Arrays.toString(mUidTraffic)
            + " }";
    }

    public static final Parcelable.Creator<BluetoothActivityEnergyInfo> CREATOR =
            new Parcelable.Creator<BluetoothActivityEnergyInfo>() {
        public BluetoothActivityEnergyInfo createFromParcel(Parcel in) {
            long timestamp = in.readLong();
            int stackState = in.readInt();
            long txTime = in.readLong();
            long rxTime = in.readLong();
            long idleTime = in.readLong();
            long energyUsed = in.readLong();
            return new BluetoothActivityEnergyInfo(timestamp, stackState,
                    txTime, rxTime, idleTime, energyUsed);
            return new BluetoothActivityEnergyInfo(in);
        }

        public BluetoothActivityEnergyInfo[] newArray(int size) {
            return new BluetoothActivityEnergyInfo[size];
        }
    };

    @SuppressWarnings("unchecked")
    public void writeToParcel(Parcel out, int flags) {
        out.writeLong(mTimestamp);
        out.writeInt(mBluetoothStackState);
@@ -84,6 +94,7 @@ public final class BluetoothActivityEnergyInfo implements Parcelable {
        out.writeLong(mControllerRxTimeMs);
        out.writeLong(mControllerIdleTimeMs);
        out.writeLong(mControllerEnergyUsed);
        out.writeTypedArray(mUidTraffic, flags);
    }

    public int describeContents() {
@@ -133,6 +144,14 @@ public final class BluetoothActivityEnergyInfo implements Parcelable {
        return mTimestamp;
    }

    public UidTraffic[] getUidTraffic() {
        return mUidTraffic;
    }

    public void setUidTraffic(UidTraffic[] traffic) {
        mUidTraffic = traffic;
    }

    /**
     * @return if the record is valid
     */
+111 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 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.bluetooth;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Record of data traffic (in bytes) by an application identified by its UID.
 * @hide
 */
public class UidTraffic implements Cloneable, Parcelable {
    private final int mAppUid;
    private long mRxBytes;
    private long mTxBytes;

    public UidTraffic(int appUid) {
        mAppUid = appUid;
    }

    public UidTraffic(int appUid, long rx, long tx) {
        mAppUid = appUid;
        mRxBytes = rx;
        mTxBytes = tx;
    }

    UidTraffic(Parcel in) {
        mAppUid = in.readInt();
        mRxBytes = in.readLong();
        mTxBytes = in.readLong();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(mAppUid);
        dest.writeLong(mRxBytes);
        dest.writeLong(mTxBytes);
    }

    public void setRxBytes(long bytes) {
        mRxBytes = bytes;
    }

    public void setTxBytes(long bytes) {
        mTxBytes = bytes;
    }

    public void addRxBytes(long bytes) {
        mRxBytes += bytes;
    }

    public void addTxBytes(long bytes) {
        mTxBytes += bytes;
    }

    public int getUid() {
        return mAppUid;
    }

    public long getRxBytes() {
        return mRxBytes;
    }

    public long getTxBytes() {
        return mTxBytes;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public UidTraffic clone() {
        return new UidTraffic(mAppUid, mRxBytes, mTxBytes);
    }

    @Override
    public String toString() {
        return "UidTraffic{" +
                "mAppUid=" + mAppUid +
                ", mRxBytes=" + mRxBytes +
                ", mTxBytes=" + mTxBytes +
                '}';
    }

    public static final Creator<UidTraffic> CREATOR = new Creator<UidTraffic>() {
        @Override
        public UidTraffic createFromParcel(Parcel source) {
            return new UidTraffic(source);
        }

        @Override
        public UidTraffic[] newArray(int size) {
            return new UidTraffic[size];
        }
    };
}