diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2019-12-11 03:26:58 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-12-11 03:26:58 +0000 |
commit | baf35c1a15b0b1edcbe1007d6c662136a8d223e0 (patch) | |
tree | 345fc48fcce96bdcd5770aa228ba9c8f9a910ddc | |
parent | a7a18eeefe0051efe19e0da7a9aa2ebe68129bba (diff) | |
parent | c08a0be59d17c85568e5f8c0b3de67564bba6f2c (diff) |
Merge "wifi: Use auto-generated statsd code for logging (contd)"
5 files changed, 86 insertions, 44 deletions
diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java index 46d36758f..cf52eead0 100644 --- a/service/java/com/android/server/wifi/ClientModeImpl.java +++ b/service/java/com/android/server/wifi/ClientModeImpl.java @@ -92,7 +92,6 @@ import android.text.TextUtils; import android.util.Log; import android.util.Pair; import android.util.SparseArray; -import android.util.StatsLog; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; @@ -107,6 +106,7 @@ import com.android.server.wifi.hotspot2.NetworkDetail; import com.android.server.wifi.hotspot2.PasspointManager; import com.android.server.wifi.hotspot2.WnmData; import com.android.server.wifi.p2p.WifiP2pServiceImpl; +import com.android.server.wifi.proto.WifiStatsLog; import com.android.server.wifi.proto.nano.WifiMetricsProto; import com.android.server.wifi.proto.nano.WifiMetricsProto.StaEvent; import com.android.server.wifi.proto.nano.WifiMetricsProto.WifiIsUnusableEvent; @@ -2364,7 +2364,7 @@ public class ClientModeImpl extends StateMachine { private void sendRssiChangeBroadcast(final int newRssi) { mBatteryStatsManager.noteWifiRssiChanged(newRssi); - StatsLog.write(StatsLog.WIFI_SIGNAL_STRENGTH_CHANGED, + WifiStatsLog.write(WifiStatsLog.WIFI_SIGNAL_STRENGTH_CHANGED, RssiUtil.calculateSignalLevel(mContext, newRssi)); Intent intent = new Intent(WifiManager.RSSI_CHANGED_ACTION); diff --git a/service/java/com/android/server/wifi/WifiLockManager.java b/service/java/com/android/server/wifi/WifiLockManager.java index 4745f6e68..db7f5ea1f 100644 --- a/service/java/com/android/server/wifi/WifiLockManager.java +++ b/service/java/com/android/server/wifi/WifiLockManager.java @@ -31,6 +31,7 @@ import android.util.Pair; import android.util.SparseArray; import com.android.server.wifi.proto.WifiStatsLog; +import com.android.server.wifi.util.WorkSourceUtil; import java.io.PrintWriter; import java.util.ArrayList; @@ -708,45 +709,22 @@ public class WifiLockManager { return uidCount; } - private Pair<List<Integer>, List<String>> getUidsAndTagsForWs(WorkSource ws) { - List<Integer> uids = new ArrayList<>(); - List<String> tags = new ArrayList<>(); - - for (int i = 0; i < ws.size(); i++) { - uids.add(ws.getUid(i)); - tags.add(ws.getPackageName(i)); - } - - final List<WorkChain> workChains = ws.getWorkChains(); - if (workChains != null) { - for (int i = 0; i < workChains.size(); ++i) { - final WorkChain workChain = workChains.get(i); - uids.add(workChain.getAttributionUid()); - tags.add(workChain.getAttributionTag()); - } - } - return Pair.create(uids, tags); - } - - private void setBlameHiPerfWs(WorkSource ws, boolean shouldBlame) { long ident = Binder.clearCallingIdentity(); - Pair<List<Integer>, List<String>> uidsAndTags = getUidsAndTagsForWs(ws); + Pair<int[], String[]> uidsAndTags = WorkSourceUtil.getUidsAndTagsForWs(ws); try { if (shouldBlame) { mBatteryStats.noteFullWifiLockAcquiredFromSource(ws); WifiStatsLog.write(WifiStatsLog.WIFI_LOCK_STATE_CHANGED, - uidsAndTags.first.stream().mapToInt(Integer::intValue).toArray(), - uidsAndTags.second.toArray(new String[0]), + uidsAndTags.first, uidsAndTags.second, WifiStatsLog.WIFI_LOCK_STATE_CHANGED__STATE__ON, - WifiManager.WIFI_MODE_FULL_HIGH_PERF); + WifiStatsLog.WIFI_LOCK_STATE_CHANGED__MODE__WIFI_MODE_FULL_HIGH_PERF); } else { mBatteryStats.noteFullWifiLockReleasedFromSource(ws); WifiStatsLog.write(WifiStatsLog.WIFI_LOCK_STATE_CHANGED, - uidsAndTags.first.stream().mapToInt(Integer::intValue).toArray(), - uidsAndTags.second.toArray(new String[0]), + uidsAndTags.first, uidsAndTags.second, WifiStatsLog.WIFI_LOCK_STATE_CHANGED__STATE__OFF, - WifiManager.WIFI_MODE_FULL_HIGH_PERF); + WifiStatsLog.WIFI_LOCK_STATE_CHANGED__MODE__WIFI_MODE_FULL_HIGH_PERF); } } finally { Binder.restoreCallingIdentity(ident); @@ -760,12 +738,12 @@ public class WifiLockManager { mBatteryStats.noteFullWifiLockAcquiredFromSource(new WorkSource(uid)); WifiStatsLog.write_non_chained(WifiStatsLog.WIFI_LOCK_STATE_CHANGED, uid, null, WifiStatsLog.WIFI_LOCK_STATE_CHANGED__STATE__ON, - WifiManager.WIFI_MODE_FULL_LOW_LATENCY); + WifiStatsLog.WIFI_LOCK_STATE_CHANGED__MODE__WIFI_MODE_FULL_LOW_LATENCY); } else { mBatteryStats.noteFullWifiLockReleasedFromSource(new WorkSource(uid)); WifiStatsLog.write_non_chained(WifiStatsLog.WIFI_LOCK_STATE_CHANGED, uid, null, WifiStatsLog.WIFI_LOCK_STATE_CHANGED__STATE__OFF, - WifiManager.WIFI_MODE_FULL_LOW_LATENCY); + WifiStatsLog.WIFI_LOCK_STATE_CHANGED__MODE__WIFI_MODE_FULL_LOW_LATENCY); } } finally { Binder.restoreCallingIdentity(ident); diff --git a/service/java/com/android/server/wifi/WifiMulticastLockManager.java b/service/java/com/android/server/wifi/WifiMulticastLockManager.java index d152c3d6f..010252791 100644 --- a/service/java/com/android/server/wifi/WifiMulticastLockManager.java +++ b/service/java/com/android/server/wifi/WifiMulticastLockManager.java @@ -21,7 +21,8 @@ import android.os.Binder; import android.os.IBinder; import android.os.RemoteException; import android.util.Log; -import android.util.StatsLog; + +import com.android.server.wifi.proto.WifiStatsLog; import java.io.PrintWriter; import java.util.ArrayList; @@ -150,9 +151,9 @@ public class WifiMulticastLockManager { int uid = Binder.getCallingUid(); final long ident = Binder.clearCallingIdentity(); mBatteryStats.noteWifiMulticastEnabled(uid); - StatsLog.write_non_chained( - StatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED, uid, null, - StatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED__STATE__ON, tag); + WifiStatsLog.write_non_chained( + WifiStatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED, uid, null, + WifiStatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED__STATE__ON, tag); Binder.restoreCallingIdentity(ident); } @@ -184,9 +185,9 @@ public class WifiMulticastLockManager { final long ident = Binder.clearCallingIdentity(); mBatteryStats.noteWifiMulticastDisabled(uid); - StatsLog.write_non_chained( - StatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED, uid, null, - StatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED__STATE__OFF, tag); + WifiStatsLog.write_non_chained( + WifiStatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED, uid, null, + WifiStatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED__STATE__OFF, tag); Binder.restoreCallingIdentity(ident); } diff --git a/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java b/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java index bc727591e..a00781ccb 100644 --- a/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java +++ b/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java @@ -47,7 +47,6 @@ import android.util.ArraySet; import android.util.LocalLog; import android.util.Log; import android.util.Pair; -import android.util.StatsLog; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.AsyncChannel; @@ -61,12 +60,14 @@ import com.android.server.wifi.WifiInjector; import com.android.server.wifi.WifiLog; import com.android.server.wifi.WifiMetrics; import com.android.server.wifi.WifiNative; +import com.android.server.wifi.proto.WifiStatsLog; import com.android.server.wifi.proto.nano.WifiMetricsProto; import com.android.server.wifi.scanner.ChannelHelper.ChannelCollection; import com.android.server.wifi.util.ArrayUtils; import com.android.server.wifi.util.ScanResultUtil; import com.android.server.wifi.util.WifiHandler; import com.android.server.wifi.util.WifiPermissionsUtil; +import com.android.server.wifi.util.WorkSourceUtil; import java.io.FileDescriptor; import java.io.PrintWriter; @@ -963,16 +964,22 @@ public class WifiScanningServiceImpl extends IWifiScanner.Stub { public void enter() { mScanWorkSource = mActiveScans.createMergedWorkSource(); mBatteryStats.noteWifiScanStartedFromSource(mScanWorkSource); - StatsLog.write(StatsLog.WIFI_SCAN_STATE_CHANGED, mScanWorkSource, - StatsLog.WIFI_SCAN_STATE_CHANGED__STATE__ON); + Pair<int[], String[]> uidsAndTags = + WorkSourceUtil.getUidsAndTagsForWs(mScanWorkSource); + WifiStatsLog.write(WifiStatsLog.WIFI_SCAN_STATE_CHANGED, + uidsAndTags.first, uidsAndTags.second, + WifiStatsLog.WIFI_SCAN_STATE_CHANGED__STATE__ON); } @Override public void exit() { mActiveScanSettings = null; mBatteryStats.noteWifiScanStoppedFromSource(mScanWorkSource); - StatsLog.write(StatsLog.WIFI_SCAN_STATE_CHANGED, mScanWorkSource, - StatsLog.WIFI_SCAN_STATE_CHANGED__STATE__OFF); + Pair<int[], String[]> uidsAndTags = + WorkSourceUtil.getUidsAndTagsForWs(mScanWorkSource); + WifiStatsLog.write(WifiStatsLog.WIFI_SCAN_STATE_CHANGED, + uidsAndTags.first, uidsAndTags.second, + WifiStatsLog.WIFI_SCAN_STATE_CHANGED__STATE__OFF); // if any scans are still active (never got results available then indicate failure) mWifiMetrics.incrementScanReturnEntry( diff --git a/service/java/com/android/server/wifi/util/WorkSourceUtil.java b/service/java/com/android/server/wifi/util/WorkSourceUtil.java new file mode 100644 index 000000000..54852fb8a --- /dev/null +++ b/service/java/com/android/server/wifi/util/WorkSourceUtil.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2018 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.util; + +import android.os.WorkSource; +import android.util.Pair; + +import java.util.ArrayList; +import java.util.List; + +/** + * Class for general helper methods for WorkSource operations. + */ +public class WorkSourceUtil { + + /** + * Retrieve an array of uids & tags within the worksource. + */ + public static Pair<int[], String[]> getUidsAndTagsForWs(WorkSource ws) { + List<Integer> uids = new ArrayList<>(); + List<String> tags = new ArrayList<>(); + + for (int i = 0; i < ws.size(); i++) { + uids.add(ws.getUid(i)); + tags.add(ws.getPackageName(i)); + } + + final List<WorkSource.WorkChain> workChains = ws.getWorkChains(); + if (workChains != null) { + for (int i = 0; i < workChains.size(); ++i) { + final WorkSource.WorkChain workChain = workChains.get(i); + uids.add(workChain.getAttributionUid()); + tags.add(workChain.getAttributionTag()); + } + } + return Pair.create( + uids.stream().mapToInt(Integer::intValue).toArray(), + tags.toArray(new String[0])); + } + + +} |