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

Commit 2e51bef4 authored by Adam Lesinski's avatar Adam Lesinski Committed by android-build-merger
Browse files

Merge commit \\'303ef0bd\\' into...

Merge commit \\'303ef0bd\\' into manual_merge_303ef0b am: d2d127b9
am: a2c9d344

Change-Id: If3f3daafeb62e92a10045203e619c0ef5cc6816a
parents d81a12b1 a2c9d344
Loading
Loading
Loading
Loading
+38 −11
Original line number Original line Diff line number Diff line
@@ -57,6 +57,7 @@ import android.text.TextUtils;
import android.util.Base64;
import android.util.Base64;
import android.util.EventLog;
import android.util.EventLog;
import android.util.Log;
import android.util.Log;
import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseArray;


import com.android.bluetooth.a2dp.A2dpService;
import com.android.bluetooth.a2dp.A2dpService;
@@ -96,10 +97,10 @@ public class AdapterService extends Service {


    private final Object mEnergyInfoLock = new Object();
    private final Object mEnergyInfoLock = new Object();
    private int mStackReportedState;
    private int mStackReportedState;
    private int mTxTimeTotalMs;
    private long mTxTimeTotalMs;
    private int mRxTimeTotalMs;
    private long mRxTimeTotalMs;
    private int mIdleTimeTotalMs;
    private long mIdleTimeTotalMs;
    private int mEnergyUsedTotalVoltAmpSecMicro;
    private long mEnergyUsedTotalVoltAmpSecMicro;
    private SparseArray<UidTraffic> mUidTraffic = new SparseArray<>();
    private SparseArray<UidTraffic> mUidTraffic = new SparseArray<>();


    private final ArrayList<ProfileService> mProfiles = new ArrayList<ProfileService>();
    private final ArrayList<ProfileService> mProfiles = new ArrayList<ProfileService>();
@@ -2373,17 +2374,43 @@ public class AdapterService extends Service {
            // Energy is product of mA, V and ms. If the chipset doesn't
            // Energy is product of mA, V and ms. If the chipset doesn't
            // report it, we have to compute it from time
            // report it, we have to compute it from time
            if (energy_used == 0) {
            if (energy_used == 0) {
                energy_used = (long)((tx_time * getTxCurrentMa()
                try {
                        + rx_time * getRxCurrentMa()
                    final long txMah = Math.multiplyExact(tx_time, getTxCurrentMa());
                        + idle_time * getIdleCurrentMa()) * getOperatingVolt());
                    final long rxMah = Math.multiplyExact(rx_time, getRxCurrentMa());
                    final long idleMah = Math.multiplyExact(idle_time, getIdleCurrentMa());
                    energy_used = (long) (Math.addExact(Math.addExact(txMah, rxMah), idleMah)
                            * getOperatingVolt());
                } catch (ArithmeticException e) {
                    Slog.wtf(TAG, "overflow in bluetooth energy callback", e);
                    // Energy is already 0 if the exception was thrown.
                }
            }
            }


            synchronized (mEnergyInfoLock) {
            synchronized (mEnergyInfoLock) {
                mStackReportedState = ctrl_state;
                mStackReportedState = ctrl_state;
                mTxTimeTotalMs += tx_time;
                long totalTxTimeMs;
                mRxTimeTotalMs += rx_time;
                long totalRxTimeMs;
                mIdleTimeTotalMs += idle_time;
                long totalIdleTimeMs;
                mEnergyUsedTotalVoltAmpSecMicro += energy_used;
                long totalEnergy;
                try {
                    totalTxTimeMs = Math.addExact(mTxTimeTotalMs, tx_time);
                    totalRxTimeMs = Math.addExact(mRxTimeTotalMs, rx_time);
                    totalIdleTimeMs = Math.addExact(mIdleTimeTotalMs, idle_time);
                    totalEnergy = Math.addExact(mEnergyUsedTotalVoltAmpSecMicro, energy_used);
                } catch (ArithmeticException e) {
                    // This could be because we accumulated a lot of time, or we got a very strange
                    // value from the controller (more likely). Discard this data.
                    Slog.wtf(TAG, "overflow in bluetooth energy callback", e);
                    totalTxTimeMs = mTxTimeTotalMs;
                    totalRxTimeMs = mRxTimeTotalMs;
                    totalIdleTimeMs = mIdleTimeTotalMs;
                    totalEnergy = mEnergyUsedTotalVoltAmpSecMicro;
                }

                mTxTimeTotalMs = totalTxTimeMs;
                mRxTimeTotalMs = totalRxTimeMs;
                mIdleTimeTotalMs = totalIdleTimeMs;
                mEnergyUsedTotalVoltAmpSecMicro = totalEnergy;


                for (UidTraffic traffic : data) {
                for (UidTraffic traffic : data) {
                    UidTraffic existingTraffic = mUidTraffic.get(traffic.getUid());
                    UidTraffic existingTraffic = mUidTraffic.get(traffic.getUid());