Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c64a26cb authored by wescande's avatar wescande Committed by William Escande
Browse files

BT_MAINLINE - Clean calls to Ws.getTags Ws.GetUids

Worksource.getTags and getUids are hidden calls
Regroupe Uids and Tags from worksource in an int[] and String[] to keep
BluetoothStatsLogs working.

Bug: 190440540
Tag: #refactor
Test: atest BluetoothInstrumentationTests
Test: atest CtsStatsdAtomHostTestCases:BluetoothStatsTests
Ignore-AOSP-First: Merge conflict resolution
Change-Id: I0ee8e486269a6687ca822854c631a13289fe9f30
parent 7dc3db3d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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"],
}
+12 −7
Original line number Diff line number Diff line
@@ -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;
@@ -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;
@@ -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) {
@@ -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);
            }
        }

@@ -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);

@@ -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);
    }
+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;
    }
}