Loading android/app/Android.bp +2 −1 Original line number Diff line number Diff line Loading @@ -136,6 +136,7 @@ genrule { name: "statslog-bluetooth-java-gen", tools: ["stats-log-api-gen"], cmd: "$(location stats-log-api-gen) --java $(out) --module bluetooth" + " --javaPackage com.android.bluetooth --javaClass BluetoothStatsLog --worksource", + " --javaPackage com.android.bluetooth --javaClass BluetoothStatsLog" + " --minApiLevel 32", out: ["com/android/bluetooth/BluetoothStatsLog.java"], } android/app/src/com/android/bluetooth/gatt/AppScanStats.java +12 −7 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.os.WorkSource; import com.android.bluetooth.BluetoothMetricsProto; import com.android.bluetooth.BluetoothStatsLog; import com.android.bluetooth.btservice.AdapterService; import com.android.bluetooth.util.WorkSourceUtil; import java.text.DateFormat; import java.text.SimpleDateFormat; Loading Loading @@ -119,7 +120,8 @@ import java.util.Objects; } public String appName; public WorkSource mWorkSource; // Used for BatteryStatsManager and BluetoothStatsLog public WorkSource mWorkSource; // Used for BatteryStatsManager public final WorkSourceUtil mWorkSourceUtil; // Used for BluetoothStatsLog private int mScansStarted = 0; private int mScansStopped = 0; public boolean isRegistered = false; Loading Loading @@ -154,6 +156,7 @@ import java.util.Objects; source = new WorkSource(Binder.getCallingUid(), appName); } mWorkSource = source; mWorkSourceUtil = new WorkSourceUtil(source); } synchronized void addResult(int scannerId) { Loading @@ -165,8 +168,8 @@ import java.util.Objects; // to lower the cost of the binder transaction if (scan.results % 100 == 0) { mBatteryStatsManager.reportBleScanResults(mWorkSource, 100); BluetoothStatsLog.write( BluetoothStatsLog.BLE_SCAN_RESULT_RECEIVED, mWorkSource, 100); BluetoothStatsLog.write(BluetoothStatsLog.BLE_SCAN_RESULT_RECEIVED, mWorkSourceUtil.getUids(), mWorkSourceUtil.getTags(), 100); } } Loading Loading @@ -239,7 +242,8 @@ import java.util.Objects; boolean isUnoptimized = !(scan.isFilterScan || scan.isBackgroundScan || scan.isOpportunisticScan); mBatteryStatsManager.reportBleScanStarted(mWorkSource, isUnoptimized); BluetoothStatsLog.write(BluetoothStatsLog.BLE_SCAN_STATE_CHANGED, mWorkSource, BluetoothStatsLog.write(BluetoothStatsLog.BLE_SCAN_STATE_CHANGED, mWorkSourceUtil.getUids(), mWorkSourceUtil.getTags(), BluetoothStatsLog.BLE_SCAN_STATE_CHANGED__STATE__ON, scan.isFilterScan, scan.isBackgroundScan, scan.isOpportunisticScan); Loading Loading @@ -302,9 +306,10 @@ import java.util.Objects; !(scan.isFilterScan || scan.isBackgroundScan || scan.isOpportunisticScan); mBatteryStatsManager.reportBleScanResults(mWorkSource, scan.results % 100); mBatteryStatsManager.reportBleScanStopped(mWorkSource, isUnoptimized); BluetoothStatsLog.write( BluetoothStatsLog.BLE_SCAN_RESULT_RECEIVED, mWorkSource, scan.results % 100); BluetoothStatsLog.write(BluetoothStatsLog.BLE_SCAN_STATE_CHANGED, mWorkSource, BluetoothStatsLog.write(BluetoothStatsLog.BLE_SCAN_RESULT_RECEIVED, mWorkSourceUtil.getUids(), mWorkSourceUtil.getTags(), scan.results % 100); BluetoothStatsLog.write(BluetoothStatsLog.BLE_SCAN_STATE_CHANGED, mWorkSourceUtil.getUids(), mWorkSourceUtil.getTags(), BluetoothStatsLog.BLE_SCAN_STATE_CHANGED__STATE__OFF, scan.isFilterScan, scan.isBackgroundScan, scan.isOpportunisticScan); } Loading android/app/src/com/android/bluetooth/util/WorkSourceUtil.java 0 → 100644 +59 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 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.bluetooth.util; import android.os.WorkSource; import java.util.ArrayList; import java.util.List; /** * Class for general helper methods for WorkSource operations. */ public class WorkSourceUtil { private final int[] mUids; private final String[] mTags; public WorkSourceUtil(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()); } } mUids = uids.stream().mapToInt(Integer::intValue).toArray(); mTags = tags.toArray(new String[0]); } public String[] getTags() { return mTags; } public int[] getUids() { return mUids; } } Loading
android/app/Android.bp +2 −1 Original line number Diff line number Diff line Loading @@ -136,6 +136,7 @@ genrule { name: "statslog-bluetooth-java-gen", tools: ["stats-log-api-gen"], cmd: "$(location stats-log-api-gen) --java $(out) --module bluetooth" + " --javaPackage com.android.bluetooth --javaClass BluetoothStatsLog --worksource", + " --javaPackage com.android.bluetooth --javaClass BluetoothStatsLog" + " --minApiLevel 32", out: ["com/android/bluetooth/BluetoothStatsLog.java"], }
android/app/src/com/android/bluetooth/gatt/AppScanStats.java +12 −7 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.os.WorkSource; import com.android.bluetooth.BluetoothMetricsProto; import com.android.bluetooth.BluetoothStatsLog; import com.android.bluetooth.btservice.AdapterService; import com.android.bluetooth.util.WorkSourceUtil; import java.text.DateFormat; import java.text.SimpleDateFormat; Loading Loading @@ -119,7 +120,8 @@ import java.util.Objects; } public String appName; public WorkSource mWorkSource; // Used for BatteryStatsManager and BluetoothStatsLog public WorkSource mWorkSource; // Used for BatteryStatsManager public final WorkSourceUtil mWorkSourceUtil; // Used for BluetoothStatsLog private int mScansStarted = 0; private int mScansStopped = 0; public boolean isRegistered = false; Loading Loading @@ -154,6 +156,7 @@ import java.util.Objects; source = new WorkSource(Binder.getCallingUid(), appName); } mWorkSource = source; mWorkSourceUtil = new WorkSourceUtil(source); } synchronized void addResult(int scannerId) { Loading @@ -165,8 +168,8 @@ import java.util.Objects; // to lower the cost of the binder transaction if (scan.results % 100 == 0) { mBatteryStatsManager.reportBleScanResults(mWorkSource, 100); BluetoothStatsLog.write( BluetoothStatsLog.BLE_SCAN_RESULT_RECEIVED, mWorkSource, 100); BluetoothStatsLog.write(BluetoothStatsLog.BLE_SCAN_RESULT_RECEIVED, mWorkSourceUtil.getUids(), mWorkSourceUtil.getTags(), 100); } } Loading Loading @@ -239,7 +242,8 @@ import java.util.Objects; boolean isUnoptimized = !(scan.isFilterScan || scan.isBackgroundScan || scan.isOpportunisticScan); mBatteryStatsManager.reportBleScanStarted(mWorkSource, isUnoptimized); BluetoothStatsLog.write(BluetoothStatsLog.BLE_SCAN_STATE_CHANGED, mWorkSource, BluetoothStatsLog.write(BluetoothStatsLog.BLE_SCAN_STATE_CHANGED, mWorkSourceUtil.getUids(), mWorkSourceUtil.getTags(), BluetoothStatsLog.BLE_SCAN_STATE_CHANGED__STATE__ON, scan.isFilterScan, scan.isBackgroundScan, scan.isOpportunisticScan); Loading Loading @@ -302,9 +306,10 @@ import java.util.Objects; !(scan.isFilterScan || scan.isBackgroundScan || scan.isOpportunisticScan); mBatteryStatsManager.reportBleScanResults(mWorkSource, scan.results % 100); mBatteryStatsManager.reportBleScanStopped(mWorkSource, isUnoptimized); BluetoothStatsLog.write( BluetoothStatsLog.BLE_SCAN_RESULT_RECEIVED, mWorkSource, scan.results % 100); BluetoothStatsLog.write(BluetoothStatsLog.BLE_SCAN_STATE_CHANGED, mWorkSource, BluetoothStatsLog.write(BluetoothStatsLog.BLE_SCAN_RESULT_RECEIVED, mWorkSourceUtil.getUids(), mWorkSourceUtil.getTags(), scan.results % 100); BluetoothStatsLog.write(BluetoothStatsLog.BLE_SCAN_STATE_CHANGED, mWorkSourceUtil.getUids(), mWorkSourceUtil.getTags(), BluetoothStatsLog.BLE_SCAN_STATE_CHANGED__STATE__OFF, scan.isFilterScan, scan.isBackgroundScan, scan.isOpportunisticScan); } Loading
android/app/src/com/android/bluetooth/util/WorkSourceUtil.java 0 → 100644 +59 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 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.bluetooth.util; import android.os.WorkSource; import java.util.ArrayList; import java.util.List; /** * Class for general helper methods for WorkSource operations. */ public class WorkSourceUtil { private final int[] mUids; private final String[] mTags; public WorkSourceUtil(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()); } } mUids = uids.stream().mapToInt(Integer::intValue).toArray(); mTags = tags.toArray(new String[0]); } public String[] getTags() { return mTags; } public int[] getUids() { return mUids; } }