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

Commit 2acd49a9 authored by Bookatz's avatar Bookatz Committed by android-build-merger
Browse files

Merge "StatsLog BleScanResults moved out of BatteryStats"

am: f7e62719

Change-Id: I137fecd9af87fb66b03c26bc02a5d86383afeca0
parents 68ae74e0 f7e62719
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;