diff options
author | David Su <dysu@google.com> | 2019-10-30 13:29:21 -0700 |
---|---|---|
committer | David Su <dysu@google.com> | 2019-12-02 15:15:53 -0800 |
commit | b89dc5757671dd16963234282ede7f4fc5594cbc (patch) | |
tree | 68655dda219cd0daf69f410d9eb1bf310fd9e6f8 | |
parent | 9f425fafcb6ea743914ce0cd583cf9afe0a60c8e (diff) |
Clean up WifiServiceImpl#reportActivityInfo()
Bug: 145244073
Test: atest FrameworksWifiTests
Change-Id: I4bf2362692e9223b3c71ddb6920182de994e1e52
-rw-r--r-- | service/java/com/android/server/wifi/WifiServiceImpl.java | 121 |
1 files changed, 64 insertions, 57 deletions
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index 27f20f44f..159b1e30a 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -1653,16 +1653,16 @@ public class WifiServiceImpl extends BaseWifiService { @Override public void requestActivityInfo(ResultReceiver result) { - Bundle bundle = new Bundle(); if (mVerboseLoggingEnabled) { mLog.info("requestActivityInfo uid=%").c(Binder.getCallingUid()).flush(); } + Bundle bundle = new Bundle(); bundle.putParcelable(BatteryStats.RESULT_RECEIVER_CONTROLLER_KEY, reportActivityInfo()); result.send(0, bundle); } /** - * see {@link android.net.wifi.WifiManager#getControllerActivityEnergyInfo(int)} + * see {@link android.net.wifi.WifiManager#getControllerActivityEnergyInfo()} */ @Override public WifiActivityEnergyInfo reportActivityInfo() { @@ -1673,64 +1673,71 @@ public class WifiServiceImpl extends BaseWifiService { if ((getSupportedFeatures() & WifiManager.WIFI_FEATURE_LINK_LAYER_STATS) == 0) { return null; } - WifiLinkLayerStats stats; - WifiActivityEnergyInfo energyInfo = null; - if (mClientModeImplChannel != null) { - stats = mClientModeImpl.syncGetLinkLayerStats(mClientModeImplChannel); - if (stats != null) { - final double rxIdleCurrent = mPowerProfile.getAveragePower( - PowerProfile.POWER_WIFI_CONTROLLER_IDLE); - final double rxCurrent = mPowerProfile.getAveragePower( - PowerProfile.POWER_WIFI_CONTROLLER_RX); - final double txCurrent = mPowerProfile.getAveragePower( - PowerProfile.POWER_WIFI_CONTROLLER_TX); - final double voltage = mPowerProfile.getAveragePower( - PowerProfile.POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; - final long rxIdleTime = stats.on_time - stats.tx_time - stats.rx_time; - final long[] txTimePerLevel; - if (stats.tx_time_per_level != null) { - txTimePerLevel = new long[stats.tx_time_per_level.length]; - for (int i = 0; i < txTimePerLevel.length; i++) { - txTimePerLevel[i] = stats.tx_time_per_level[i]; - // TODO(b/27227497): Need to read the power consumed per level from config - } - } else { - // This will happen if the HAL get link layer API returned null. - txTimePerLevel = new long[0]; - } - final long energyUsed = (long)((stats.tx_time * txCurrent + - stats.rx_time * rxCurrent + - rxIdleTime * rxIdleCurrent) * voltage); - if (VDBG || rxIdleTime < 0 || stats.on_time < 0 || stats.tx_time < 0 || - stats.rx_time < 0 || stats.on_time_scan < 0 || energyUsed < 0) { - String sb = " rxIdleCur=" + rxIdleCurrent - + " rxCur=" + rxCurrent - + " txCur=" + txCurrent - + " voltage=" + voltage - + " on_time=" + stats.on_time - + " tx_time=" + stats.tx_time - + " tx_time_per_level=" + Arrays.toString(txTimePerLevel) - + " rx_time=" + stats.rx_time - + " rxIdleTime=" + rxIdleTime - + " scan_time=" + stats.on_time_scan - + " energy=" + energyUsed; - Log.d(TAG, " reportActivityInfo: " + sb); - } - - // Convert the LinkLayerStats into EnergyActivity - energyInfo = new WifiActivityEnergyInfo(mClock.getElapsedSinceBootMillis(), - WifiActivityEnergyInfo.STACK_STATE_STATE_IDLE, stats.tx_time, - txTimePerLevel, stats.rx_time, stats.on_time_scan, rxIdleTime, energyUsed); - } - if (energyInfo != null && energyInfo.isValid()) { - return energyInfo; - } else { - return null; - } - } else { + if (mClientModeImplChannel == null) { Log.e(TAG, "mClientModeImplChannel is not initialized"); return null; } + WifiLinkLayerStats stats = mClientModeImpl.syncGetLinkLayerStats(mClientModeImplChannel); + if (stats == null) { + return null; + } + + final double rxIdleCurrentInMilliAmps = mPowerProfile.getAveragePower( + PowerProfile.POWER_WIFI_CONTROLLER_IDLE); + final double rxCurrentInMilliAmps = mPowerProfile.getAveragePower( + PowerProfile.POWER_WIFI_CONTROLLER_RX); + final double txCurrentInMilliAmps = mPowerProfile.getAveragePower( + PowerProfile.POWER_WIFI_CONTROLLER_TX); + // POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. + final double voltageInVolts = mPowerProfile.getAveragePower( + PowerProfile.POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; + final long rxIdleTimeMillis = stats.on_time - stats.tx_time - stats.rx_time; + final long[] txTimePerLevelMillis; + if (stats.tx_time_per_level == null) { + // This will happen if the HAL get link layer API returned null. + txTimePerLevelMillis = new long[0]; + } else { + // need to manually copy since we are converting an int[] to a long[] + txTimePerLevelMillis = new long[stats.tx_time_per_level.length]; + for (int i = 0; i < txTimePerLevelMillis.length; i++) { + txTimePerLevelMillis[i] = stats.tx_time_per_level[i]; + // TODO(b/27227497): Need to read the power consumed per level from config + } + } + // times are all in milliseconds, currents are all in milliAmps, voltage is in volts => + // resulting energy is in microjoules. + final long energyUsedInMicroJoules = (long) ( + (stats.tx_time * txCurrentInMilliAmps + + stats.rx_time * rxCurrentInMilliAmps + + rxIdleTimeMillis * rxIdleCurrentInMilliAmps + ) * voltageInVolts); + + if (VDBG || rxIdleTimeMillis < 0 || stats.on_time < 0 || stats.tx_time < 0 + || stats.rx_time < 0 || stats.on_time_scan < 0 || energyUsedInMicroJoules < 0) { + Log.d(TAG, " reportActivityInfo: " + + " rxIdleCurrentInMilliAmps=" + rxIdleCurrentInMilliAmps + + " rxCurrentInMilliAmps=" + rxCurrentInMilliAmps + + " txCurrentInMilliAmps=" + txCurrentInMilliAmps + + " voltageInVolts=" + voltageInVolts + + " on_time_millis=" + stats.on_time + + " tx_time_millis=" + stats.tx_time + + " tx_time_per_level_millis=" + Arrays.toString(txTimePerLevelMillis) + + " rx_time_millis=" + stats.rx_time + + " rxIdleTimeMillis=" + rxIdleTimeMillis + + " scan_time_millis=" + stats.on_time_scan + + " energyUsedInMicroJoules=" + energyUsedInMicroJoules); + } + + // Convert the LinkLayerStats into WifiActivityEnergyInfo + WifiActivityEnergyInfo energyInfo = new WifiActivityEnergyInfo( + mClock.getElapsedSinceBootMillis(), + WifiActivityEnergyInfo.STACK_STATE_STATE_IDLE, + stats.tx_time, + stats.rx_time, + stats.on_time_scan, + rxIdleTimeMillis, + energyUsedInMicroJoules); + return energyInfo.isValid() ? energyInfo : null; } /** |