From 293251318168ad2dbfeb3d18176936fe2cc16325 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Wed, 21 May 2014 15:01:03 -0700 Subject: [PATCH] (DO NOT MERGE) 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 --- .../android/internal/os/BatteryStatsImpl.java | 19 ++++++++++++++----- .../android/server/ConnectivityService.java | 9 +++++---- .../server/NetworkManagementService.java | 5 ++--- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java index 8428f66951cfe..24e55e49f6d49 100644 --- a/core/java/com/android/internal/os/BatteryStatsImpl.java +++ b/core/java/com/android/internal/os/BatteryStatsImpl.java @@ -328,11 +328,13 @@ public final class BatteryStatsImpl extends BatteryStats { int mLastDischargeStepLevel; long mLastDischargeStepTime; + int mMinDischargeStepLevel; int mNumDischargeStepDurations; final long[] mDischargeStepDurations = new long[MAX_LEVEL_STEPS]; int mLastChargeStepLevel; long mLastChargeStepTime; + int mMaxChargeStepLevel; int mNumChargeStepDurations; final long[] mChargeStepDurations = new long[MAX_LEVEL_STEPS]; @@ -887,6 +889,7 @@ public final class BatteryStatsImpl extends BatteryStats { mLastTime = 0; mUnpluggedTime = in.readLong(); timeBase.add(this); + if (DEBUG) Log.i(TAG, "**** READ TIMER #" + mType + ": mTotalTime=" + mTotalTime); } Timer(int type, TimeBase timeBase) { @@ -917,6 +920,8 @@ public final class BatteryStatsImpl extends BatteryStats { } 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(mLoadedCount); out.writeInt(mUnpluggedCount); @@ -5550,6 +5555,7 @@ public final class BatteryStatsImpl extends BatteryStats { for (int i=0; i level) { mNumDischargeStepDurations = addLevelSteps(mDischargeStepDurations, mNumDischargeStepDurations, mLastDischargeStepTime, mLastDischargeStepLevel - level, elapsedRealtime); mLastDischargeStepLevel = level; + mMinDischargeStepLevel = level; mLastDischargeStepTime = elapsedRealtime; } } else { - if (mLastChargeStepLevel != level) { + if (mLastChargeStepLevel != level && mMaxChargeStepLevel < level) { mNumChargeStepDurations = addLevelSteps(mChargeStepDurations, mNumChargeStepDurations, mLastChargeStepTime, level - mLastChargeStepLevel, elapsedRealtime); mLastChargeStepLevel = level; + mMaxChargeStepLevel = level; mLastChargeStepTime = elapsedRealtime; } } @@ -7495,6 +7504,8 @@ public final class BatteryStatsImpl extends BatteryStats { mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mOnBatteryTimeBase, in); } + mInteractive = false; + mInteractiveTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase, in); mPhoneOn = false; mLowPowerModeEnabledTimer = new StopwatchTimer(null, -2, 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); mVideoOn = false; mVideoOnTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase); - mInteractive = false; - mInteractiveTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase, in); mDischargeUnplugLevel = in.readInt(); mDischargePlugLevel = in.readInt(); mDischargeCurrentLevel = in.readInt(); diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 0ad5ce269abaf..7ecf248291560 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -5750,10 +5750,11 @@ public class ConnectivityService extends IConnectivityManager.Stub { // updateNetworkSettings(); } // notify battery stats service about this network -// try { - // TODO - //BatteryStatsService.getService().noteNetworkInterfaceType(iface, netType); -// } catch (RemoteException e) { } + try { + BatteryStatsService.getService().noteNetworkInterfaceType( + newNetwork.linkProperties.getInterfaceName(), + newNetwork.networkInfo.getType()); + } catch (RemoteException e) { } notifyNetworkCallbacks(newNetwork, ConnectivityManager.CALLBACK_AVAILABLE); } else { if (DBG && newNetwork.networkRequests.size() != 0) { diff --git a/services/core/java/com/android/server/NetworkManagementService.java b/services/core/java/com/android/server/NetworkManagementService.java index cf917827dfd75..137387e17ef55 100644 --- a/services/core/java/com/android/server/NetworkManagementService.java +++ b/services/core/java/com/android/server/NetworkManagementService.java @@ -240,9 +240,8 @@ public class NetworkManagementService extends INetworkManagementService.Stub mPhoneStateListener = new PhoneStateListener(mDaemonHandler.getLooper()) { public void onDataConnectionRealTimeInfoChanged( DataConnectionRealTimeInfo dcRtInfo) { - // Disabled for now, until we are getting good data. - //notifyInterfaceClassActivity(ConnectivityManager.TYPE_MOBILE, - // dcRtInfo.getDcPowerState(), dcRtInfo.getTime(), true); + notifyInterfaceClassActivity(ConnectivityManager.TYPE_MOBILE, + dcRtInfo.getDcPowerState(), dcRtInfo.getTime(), true); } };