diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2018-01-31 22:00:34 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-01-31 22:00:34 +0000 |
commit | d365c3a37324ff8b79f80db34d48a71dde480fac (patch) | |
tree | a7248d7f7ab856ba62ffc55bbfef6ea6445d8260 /service | |
parent | 09bfcfef2ef8ee07e865363c61e966fb37ec0cbe (diff) | |
parent | fb165562c8c77a9e5e2452f33aedb8e4369e7a9b (diff) |
Merge "Wifi power metrics"
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/WifiMetrics.java | 6 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/WifiPowerMetrics.java | 95 |
2 files changed, 101 insertions, 0 deletions
diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java index 643b29894..2fb4413fc 100644 --- a/service/java/com/android/server/wifi/WifiMetrics.java +++ b/service/java/com/android/server/wifi/WifiMetrics.java @@ -187,6 +187,9 @@ public class WifiMetrics { private final SparseIntArray mObservedHotspotR1ApsPerEssInScanHistogram = new SparseIntArray(); private final SparseIntArray mObservedHotspotR2ApsPerEssInScanHistogram = new SparseIntArray(); + /** Wifi power metrics*/ + private WifiPowerMetrics mWifiPowerMetrics = new WifiPowerMetrics(); + class RouterFingerPrint { private WifiMetricsProto.RouterFingerPrint mRouterFingerPrintProto; RouterFingerPrint() { @@ -1852,6 +1855,8 @@ public class WifiMetrics { + mWpsMetrics.numWpsSupplicantFailure); pw.println("mWpsMetrics.numWpsCancellation=" + mWpsMetrics.numWpsCancellation); + + mWifiPowerMetrics.dump(pw); } } } @@ -2137,6 +2142,7 @@ public class WifiMetrics { } mWifiLogProto.wpsMetrics = mWpsMetrics; + mWifiLogProto.wifiPowerStats = mWifiPowerMetrics.buildProto(); } } diff --git a/service/java/com/android/server/wifi/WifiPowerMetrics.java b/service/java/com/android/server/wifi/WifiPowerMetrics.java new file mode 100644 index 000000000..4ad25aba0 --- /dev/null +++ b/service/java/com/android/server/wifi/WifiPowerMetrics.java @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2016 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 com.android.server.wifi; + +import android.os.BatteryStats; +import android.os.RemoteException; +import android.os.ServiceManager; +import android.os.connectivity.WifiBatteryStats; +import android.text.format.DateUtils; +import android.util.Log; + +import com.android.internal.app.IBatteryStats; +import com.android.server.wifi.nano.WifiMetricsProto.WifiPowerStats; + +import java.io.PrintWriter; + +/** + * WifiPowerMetrics holds the wifi power metrics and converts them to WifiPowerStats proto buf. + * This proto buf is included in the Wifi proto buf. + */ +public class WifiPowerMetrics { + + private static final String TAG = WifiPowerMetrics.class.getSimpleName(); + + /* BatteryStats API */ + private final IBatteryStats mBatteryStats; + + public WifiPowerMetrics() { + mBatteryStats = IBatteryStats.Stub.asInterface(ServiceManager.getService( + BatteryStats.SERVICE_NAME)); + } + + /** + * Build WifiPowerStats proto + * A snapshot of Wifi statistics in Batterystats is obtained. Due to reboots multiple correlated + * logs may be uploaded in a day. Resolution is on the server side. The log with longest + * duration is picked. + * @return WifiPowerStats + */ + public WifiPowerStats buildProto() { + WifiPowerStats m = new WifiPowerStats(); + WifiBatteryStats stats = getStats(); + if (stats != null) { + m.loggingDurationMs = stats.getLoggingDurationMs(); + m.energyConsumedMah = stats.getEnergyConsumedMaMs() + / ((double) DateUtils.HOUR_IN_MILLIS); + m.idleTimeMs = stats.getIdleTimeMs(); + m.rxTimeMs = stats.getRxTimeMs(); + m.txTimeMs = stats.getTxTimeMs(); + } + return m; + } + + /** + * Dump all WifiPowerStats to console (pw) + * @param pw + */ + public void dump(PrintWriter pw) { + WifiPowerStats s = buildProto(); + if (s!=null) { + pw.println("Wifi power metrics:"); + pw.println("Logging duration (time on battery): " + s.loggingDurationMs); + pw.println("Energy consumed by wifi (mAh): " + s.energyConsumedMah); + pw.println("Amount of time wifi is in idle (ms): " + s.idleTimeMs); + pw.println("Amount of time wifi is in rx (ms): " + s.rxTimeMs); + pw.println("Amount of time wifi is in tx (ms): " + s.txTimeMs); + } + } + + /** + * Get wifi stats from batterystats + * @return WifiBatteryStats + */ + private WifiBatteryStats getStats() { + try { + return mBatteryStats.getWifiBatteryStats(); + } catch (RemoteException e) { + Log.e(TAG, "Unable to obtain Wifi power stats from BatteryStats"); + } + return null; + } +} |