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

Commit 9724fdbe authored by Bookatz's avatar Bookatz
Browse files

StatsLog BleScanResults moved out of BatteryStats

Move the StatsLog.write for BleScanResults to AppScanStats, out of
BatteryStatsImpl.

Bug: 80308558
Test: cts-tradefed run cts-dev -m CtsStatsdHostTestCases -t android.cts.statsd.atom.UidAtomTests#testBleScanResult
Change-Id: Ia58205bc6d8dea6854894a119a8f676668078ec8
Merged-In: Ia4c0882f024710699c55e182fedf747c0bdd3c8d
parent 42103bd1
Loading
Loading
Loading
Loading
+11 −24
Original line number Diff line number Diff line
@@ -122,16 +122,17 @@ import java.util.List;
    synchronized void addResult(int scannerId) {
        LastScan scan = getScanFromScannerId(scannerId);
        if (scan != null) {
            int batteryStatsResults = ++scan.results;
            scan.results++;

            // Only update battery stats after receiving 100 new results in order
            // to lower the cost of the binder transaction
            if (batteryStatsResults % 100 == 0) {
            if (scan.results % 100 == 0) {
                try {
                    mBatteryStats.noteBleScanResults(mWorkSource, 100);
                } catch (RemoteException e) {
                    /* ignore */
                }
                StatsLog.write(StatsLog.BLE_SCAN_RESULT_RECEIVED, mWorkSource, 100);
            }
        }

@@ -178,7 +179,9 @@ import java.util.List;
        } catch (RemoteException e) {
            /* ignore */
        }
        writeToStatsLog(scan, StatsLog.BLE_SCAN_STATE_CHANGED__STATE__ON);
        StatsLog.write(StatsLog.BLE_SCAN_STATE_CHANGED, mWorkSource,
                StatsLog.BLE_SCAN_STATE_CHANGED__STATE__ON,
                scan.filtered, scan.background, scan.opportunistic);

        mOngoingScans.put(scannerId, scan);
    }
@@ -221,15 +224,17 @@ import java.util.List;
        }

        try {
            // Inform battery stats of any results it might be missing on
            // scan stop
            // Inform battery stats of any results it might be missing on scan stop
            boolean isUnoptimized = !(scan.filtered || scan.background || scan.opportunistic);
            mBatteryStats.noteBleScanResults(mWorkSource, scan.results % 100);
            mBatteryStats.noteBleScanStopped(mWorkSource, isUnoptimized);
        } catch (RemoteException e) {
            /* ignore */
        }
        writeToStatsLog(scan, StatsLog.BLE_SCAN_STATE_CHANGED__STATE__OFF);
        StatsLog.write(StatsLog.BLE_SCAN_RESULT_RECEIVED, mWorkSource, scan.results % 100);
        StatsLog.write(StatsLog.BLE_SCAN_STATE_CHANGED, mWorkSource,
                StatsLog.BLE_SCAN_STATE_CHANGED__STATE__OFF,
                scan.filtered, scan.background, scan.opportunistic);
    }

    synchronized void recordScanSuspend(int scannerId) {
@@ -254,24 +259,6 @@ import java.util.List;
        mTotalSuspendTime += suspendDuration;
    }

    private void writeToStatsLog(LastScan scan, int statsLogState) {
        for (int i = 0; i < mWorkSource.size(); i++) {
            StatsLog.write_non_chained(StatsLog.BLE_SCAN_STATE_CHANGED,
                    mWorkSource.get(i), null,
                    statsLogState, scan.filtered, scan.background, scan.opportunistic);
        }

        final List<WorkSource.WorkChain> workChains = mWorkSource.getWorkChains();
        if (workChains != null) {
            for (int i = 0; i < workChains.size(); ++i) {
                WorkSource.WorkChain workChain = workChains.get(i);
                StatsLog.write(StatsLog.BLE_SCAN_STATE_CHANGED,
                        workChain.getUids(), workChain.getTags(),
                        statsLogState, scan.filtered, scan.background, scan.opportunistic);
            }
        }
    }

    synchronized void setScanTimeout(int scannerId) {
        if (!isScanning()) {
            return;