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

Commit 2d4b4ed6 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Battery monitoring fixes:

- Improve monitoring of level changes to not be confused
  when it goes up while draining or down while charging.
- Put back in connectivity service code to tell battery
  stats about the interfaces.
- Turn back on reporting of mobile radio active state
  from the RIL.
- Fix bug in marshalling/unmarshalling that would cause
  the UI to show bad data.

Change-Id: I733ef52702894cca81a0813eccdfc1023e546fce
parent 45f302c8
Loading
Loading
Loading
Loading
+14 −5
Original line number Original line Diff line number Diff line
@@ -328,11 +328,13 @@ public final class BatteryStatsImpl extends BatteryStats {


    int mLastDischargeStepLevel;
    int mLastDischargeStepLevel;
    long mLastDischargeStepTime;
    long mLastDischargeStepTime;
    int mMinDischargeStepLevel;
    int mNumDischargeStepDurations;
    int mNumDischargeStepDurations;
    final long[] mDischargeStepDurations = new long[MAX_LEVEL_STEPS];
    final long[] mDischargeStepDurations = new long[MAX_LEVEL_STEPS];


    int mLastChargeStepLevel;
    int mLastChargeStepLevel;
    long mLastChargeStepTime;
    long mLastChargeStepTime;
    int mMaxChargeStepLevel;
    int mNumChargeStepDurations;
    int mNumChargeStepDurations;
    final long[] mChargeStepDurations = new long[MAX_LEVEL_STEPS];
    final long[] mChargeStepDurations = new long[MAX_LEVEL_STEPS];


@@ -887,6 +889,7 @@ public final class BatteryStatsImpl extends BatteryStats {
            mLastTime = 0;
            mLastTime = 0;
            mUnpluggedTime = in.readLong();
            mUnpluggedTime = in.readLong();
            timeBase.add(this);
            timeBase.add(this);
            if (DEBUG) Log.i(TAG, "**** READ TIMER #" + mType + ": mTotalTime=" + mTotalTime);
        }
        }


        Timer(int type, TimeBase timeBase) {
        Timer(int type, TimeBase timeBase) {
@@ -917,6 +920,8 @@ public final class BatteryStatsImpl extends BatteryStats {
        }
        }


        public void writeToParcel(Parcel out, long elapsedRealtimeUs) {
        public void writeToParcel(Parcel out, long elapsedRealtimeUs) {
            if (DEBUG) Log.i(TAG, "**** WRITING TIMER #" + mType + ": mTotalTime="
                    + computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)));
            out.writeInt(mCount);
            out.writeInt(mCount);
            out.writeInt(mLoadedCount);
            out.writeInt(mLoadedCount);
            out.writeInt(mUnpluggedCount);
            out.writeInt(mUnpluggedCount);
@@ -5550,6 +5555,7 @@ public final class BatteryStatsImpl extends BatteryStats {
        for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
        for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
            mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mOnBatteryTimeBase);
            mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mOnBatteryTimeBase);
        }
        }
        mInteractiveTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase);
        mLowPowerModeEnabledTimer = new StopwatchTimer(null, -2, null, mOnBatteryTimeBase);
        mLowPowerModeEnabledTimer = new StopwatchTimer(null, -2, null, mOnBatteryTimeBase);
        mPhoneOnTimer = new StopwatchTimer(null, -3, null, mOnBatteryTimeBase);
        mPhoneOnTimer = new StopwatchTimer(null, -3, null, mOnBatteryTimeBase);
        for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
        for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
@@ -5581,7 +5587,6 @@ public final class BatteryStatsImpl extends BatteryStats {
        }
        }
        mAudioOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase);
        mAudioOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase);
        mVideoOnTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase);
        mVideoOnTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase);
        mInteractiveTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase);
        mOnBattery = mOnBatteryInternal = false;
        mOnBattery = mOnBatteryInternal = false;
        long uptime = SystemClock.uptimeMillis() * 1000;
        long uptime = SystemClock.uptimeMillis() * 1000;
        long realtime = SystemClock.elapsedRealtime() * 1000;
        long realtime = SystemClock.elapsedRealtime() * 1000;
@@ -5958,6 +5963,7 @@ public final class BatteryStatsImpl extends BatteryStats {
                mNumDischargeStepDurations = 0;
                mNumDischargeStepDurations = 0;
            }
            }
            mLastDischargeStepLevel = level;
            mLastDischargeStepLevel = level;
            mMinDischargeStepLevel = level;
            mLastDischargeStepTime = -1;
            mLastDischargeStepTime = -1;
            pullPendingStateUpdatesLocked();
            pullPendingStateUpdatesLocked();
            mHistoryCur.batteryLevel = (byte)level;
            mHistoryCur.batteryLevel = (byte)level;
@@ -5996,6 +6002,7 @@ public final class BatteryStatsImpl extends BatteryStats {
            updateTimeBasesLocked(false, !screenOn, uptime, realtime);
            updateTimeBasesLocked(false, !screenOn, uptime, realtime);
            mNumChargeStepDurations = 0;
            mNumChargeStepDurations = 0;
            mLastChargeStepLevel = level;
            mLastChargeStepLevel = level;
            mMaxChargeStepLevel = level;
            mLastChargeStepTime = -1;
            mLastChargeStepTime = -1;
        }
        }
        if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) {
        if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) {
@@ -6117,19 +6124,21 @@ public final class BatteryStatsImpl extends BatteryStats {
                    addHistoryRecordLocked(elapsedRealtime, uptime);
                    addHistoryRecordLocked(elapsedRealtime, uptime);
                }
                }
                if (onBattery) {
                if (onBattery) {
                    if (mLastDischargeStepLevel != level) {
                    if (mLastDischargeStepLevel != level && mMinDischargeStepLevel > level) {
                        mNumDischargeStepDurations = addLevelSteps(mDischargeStepDurations,
                        mNumDischargeStepDurations = addLevelSteps(mDischargeStepDurations,
                                mNumDischargeStepDurations, mLastDischargeStepTime,
                                mNumDischargeStepDurations, mLastDischargeStepTime,
                                mLastDischargeStepLevel - level, elapsedRealtime);
                                mLastDischargeStepLevel - level, elapsedRealtime);
                        mLastDischargeStepLevel = level;
                        mLastDischargeStepLevel = level;
                        mMinDischargeStepLevel = level;
                        mLastDischargeStepTime = elapsedRealtime;
                        mLastDischargeStepTime = elapsedRealtime;
                    }
                    }
                } else {
                } else {
                    if (mLastChargeStepLevel != level) {
                    if (mLastChargeStepLevel != level && mMaxChargeStepLevel < level) {
                        mNumChargeStepDurations = addLevelSteps(mChargeStepDurations,
                        mNumChargeStepDurations = addLevelSteps(mChargeStepDurations,
                                mNumChargeStepDurations, mLastChargeStepTime,
                                mNumChargeStepDurations, mLastChargeStepTime,
                                level - mLastChargeStepLevel, elapsedRealtime);
                                level - mLastChargeStepLevel, elapsedRealtime);
                        mLastChargeStepLevel = level;
                        mLastChargeStepLevel = level;
                        mMaxChargeStepLevel = level;
                        mLastChargeStepTime = elapsedRealtime;
                        mLastChargeStepTime = elapsedRealtime;
                    }
                    }
                }
                }
@@ -7495,6 +7504,8 @@ public final class BatteryStatsImpl extends BatteryStats {
            mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mOnBatteryTimeBase,
            mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mOnBatteryTimeBase,
                    in);
                    in);
        }
        }
        mInteractive = false;
        mInteractiveTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase, in);
        mPhoneOn = false;
        mPhoneOn = false;
        mLowPowerModeEnabledTimer = new StopwatchTimer(null, -2, null, mOnBatteryTimeBase, in);
        mLowPowerModeEnabledTimer = new StopwatchTimer(null, -2, null, mOnBatteryTimeBase, in);
        mPhoneOnTimer = new StopwatchTimer(null, -3, null, mOnBatteryTimeBase, in);
        mPhoneOnTimer = new StopwatchTimer(null, -3, null, mOnBatteryTimeBase, in);
@@ -7536,8 +7547,6 @@ public final class BatteryStatsImpl extends BatteryStats {
        mAudioOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase);
        mAudioOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase);
        mVideoOn = false;
        mVideoOn = false;
        mVideoOnTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase);
        mVideoOnTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase);
        mInteractive = false;
        mInteractiveTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase, in);
        mDischargeUnplugLevel = in.readInt();
        mDischargeUnplugLevel = in.readInt();
        mDischargePlugLevel = in.readInt();
        mDischargePlugLevel = in.readInt();
        mDischargeCurrentLevel = in.readInt();
        mDischargeCurrentLevel = in.readInt();
+5 −4
Original line number Original line Diff line number Diff line
@@ -5754,10 +5754,11 @@ public class ConnectivityService extends IConnectivityManager.Stub {
                // updateNetworkSettings();
                // updateNetworkSettings();
            }
            }
            // notify battery stats service about this network
            // notify battery stats service about this network
//            try {
            try {
                // TODO
                BatteryStatsService.getService().noteNetworkInterfaceType(
                //BatteryStatsService.getService().noteNetworkInterfaceType(iface, netType);
                        newNetwork.linkProperties.getInterfaceName(),
//            } catch (RemoteException e) { }
                        newNetwork.networkInfo.getType());
            } catch (RemoteException e) { }
            notifyNetworkCallbacks(newNetwork, ConnectivityManager.CALLBACK_AVAILABLE);
            notifyNetworkCallbacks(newNetwork, ConnectivityManager.CALLBACK_AVAILABLE);
        } else {
        } else {
            if (DBG && newNetwork.networkRequests.size() != 0) {
            if (DBG && newNetwork.networkRequests.size() != 0) {
+2 −3
Original line number Original line Diff line number Diff line
@@ -240,9 +240,8 @@ public class NetworkManagementService extends INetworkManagementService.Stub
        mPhoneStateListener = new PhoneStateListener(mDaemonHandler.getLooper()) {
        mPhoneStateListener = new PhoneStateListener(mDaemonHandler.getLooper()) {
            public void onDataConnectionRealTimeInfoChanged(
            public void onDataConnectionRealTimeInfoChanged(
                    DataConnectionRealTimeInfo dcRtInfo) {
                    DataConnectionRealTimeInfo dcRtInfo) {
                // Disabled for now, until we are getting good data.
                notifyInterfaceClassActivity(ConnectivityManager.TYPE_MOBILE,
                //notifyInterfaceClassActivity(ConnectivityManager.TYPE_MOBILE,
                        dcRtInfo.getDcPowerState(), dcRtInfo.getTime(), true);
                //        dcRtInfo.getDcPowerState(), dcRtInfo.getTime(), true);
            }
            }
        };
        };