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

Commit bf7a664b authored by Vinay Kalia's avatar Vinay Kalia
Browse files

Fix time stats in bluetooth_manager dumpsys

1. If an application starts an unfiltered scan on screen-off
then it is immediately suspended. However, the "Suspended Time"
for such a scan is not updated in bluetooth_manager dumpsys.
With this change "Suspended Time" is updated for such scans as below:

2017/08/10 15:04:01 - 5945ms Suspended 0 results (6)
      └ Suspended Time: 5942ms

2. Fix a bug in calculating "Total time suspended".

Test: Tested BLE scanning application with screen off.
Change-Id: I489cf5d6854e10fc25d4ce8e7817126391d0bc89
parent 2abed10e
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -176,8 +176,9 @@ import com.android.bluetooth.btservice.BluetoothProto;
        long scanDuration = stopTime - scan.timestamp;
        scan.duration = scanDuration;
        if (scan.isSuspended) {
            scan.suspendDuration += stopTime - scan.suspendStartTime;
            mTotalSuspendTime += scan.suspendDuration;
            long suspendDuration = stopTime - scan.suspendStartTime;
            scan.suspendDuration += suspendDuration;
            mTotalSuspendTime += suspendDuration;
        }
        ongoingScans.remove(scannerId);
        if (lastScans.size() >= NUM_SCAN_DURATIONS_KEPT) {
@@ -216,13 +217,15 @@ import com.android.bluetooth.btservice.BluetoothProto;

    synchronized void recordScanResume(int scannerId) {
        LastScan scan = getScanFromScannerId(scannerId);
        long suspendDuration = 0;
        if (scan == null || !scan.isSuspended) {
            return;
        }
        scan.isSuspended = false;
        stopTime = SystemClock.elapsedRealtime();
        scan.suspendDuration += stopTime - scan.suspendStartTime;
        mTotalSuspendTime += scan.suspendDuration;
        suspendDuration = stopTime - scan.suspendStartTime;
        scan.suspendDuration += suspendDuration;
        mTotalSuspendTime += suspendDuration;
    }

    synchronized void setScanTimeout(int scannerId) {
+4 −1
Original line number Diff line number Diff line
@@ -260,10 +260,13 @@ public class ScanManager {
            }

            if (!mScanNative.isOpportunisticScanClient(client) && !isScreenOn() && !isFiltered) {
                Log.e(TAG,
                Log.w(TAG,
                        "Cannot start unfiltered scan in screen-off. This scan will be resumed later: "
                                + client.scannerId);
                mSuspendedScanClients.add(client);
                if (client.stats != null) {
                    client.stats.recordScanSuspend(client.scannerId);
                }
                return;
            }