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

Commit 5166da86 authored by Etienne Ruffieux's avatar Etienne Ruffieux
Browse files

Moving bt stats logging to BatteryStats.

Tag: #feature
Bug: 211851706
Test: manual
Change-Id: I7e40b64eaa334792dd409837fb9f512714f65eec
parent 86d5713d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -8918,6 +8918,8 @@ package android.os {
    method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportBleScanResults(@NonNull android.os.WorkSource, int);
    method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportBleScanStarted(@NonNull android.os.WorkSource, boolean);
    method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportBleScanStopped(@NonNull android.os.WorkSource, boolean);
    method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public void reportBluetoothOff(int, int, @NonNull String);
    method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public void reportBluetoothOn(int, int, @NonNull String);
    method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportFullWifiLockAcquiredFromSource(@NonNull android.os.WorkSource);
    method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportFullWifiLockReleasedFromSource(@NonNull android.os.WorkSource);
    method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportMobileRadioPowerState(boolean, int);
+38 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.bluetooth.annotations.RequiresBluetoothConnectPermission;
import android.bluetooth.annotations.RequiresLegacyBluetoothAdminPermission;
import android.content.Context;
import android.net.NetworkStack;
import android.os.connectivity.CellularBatteryStats;
@@ -514,6 +516,42 @@ public final class BatteryStatsManager {
        }
    }

    /**
     * Indicates that Bluetooth was toggled on.
     *
     * @param uid calling package uid
     * @param reason why Bluetooth has been turned on
     * @param packageName package responsible for this change
     */
    @RequiresLegacyBluetoothAdminPermission
    @RequiresBluetoothConnectPermission
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    public void reportBluetoothOn(int uid, int reason, @NonNull String packageName) {
        try {
            mBatteryStats.noteBluetoothOn(uid, reason, packageName);
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
        }
    }

    /**
     * Indicates that Bluetooth was toggled off.
     *
     * @param uid calling package uid
     * @param reason why Bluetooth has been turned on
     * @param packageName package responsible for this change
     */
    @RequiresLegacyBluetoothAdminPermission
    @RequiresBluetoothConnectPermission
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    public void reportBluetoothOff(int uid, int reason, @NonNull String packageName) {
        try {
            mBatteryStats.noteBluetoothOff(uid, reason, packageName);
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
        }
    }

    /**
     * Indicates that a new Bluetooth LE scan has started.
     *
+2 −0
Original line number Diff line number Diff line
@@ -145,6 +145,8 @@ interface IBatteryStats {
    long getAwakeTimeBattery();
    long getAwakeTimePlugged();

    void noteBluetoothOn(int uid, int reason, String packageName);
    void noteBluetoothOff(int uid, int reason, String packageName);
    void noteBleScanStarted(in WorkSource ws, boolean isUnoptimized);
    void noteBleScanStopped(in WorkSource ws, boolean isUnoptimized);
    void noteBleScanReset();
+26 −0
Original line number Diff line number Diff line
@@ -1962,6 +1962,32 @@ public final class BatteryStatsService extends IBatteryStats.Stub
        }
    }

    /**
     * Bluetooth on stat logging
     */
    public void noteBluetoothOn(int uid, int reason, String packageName) {
        if (Binder.getCallingPid() != Process.myPid()) {
            mContext.enforcePermission(android.Manifest.permission.BLUETOOTH_CONNECT,
                    Binder.getCallingPid(), uid, null);
        }
        FrameworkStatsLog.write_non_chained(FrameworkStatsLog.BLUETOOTH_ENABLED_STATE_CHANGED,
                uid, null, FrameworkStatsLog.BLUETOOTH_ENABLED_STATE_CHANGED__STATE__ENABLED,
                reason, packageName);
    }

    /**
     * Bluetooth off stat logging
     */
    public void noteBluetoothOff(int uid, int reason, String packageName) {
        if (Binder.getCallingPid() != Process.myPid()) {
            mContext.enforcePermission(android.Manifest.permission.BLUETOOTH_CONNECT,
                    Binder.getCallingPid(), uid, null);
        }
        FrameworkStatsLog.write_non_chained(FrameworkStatsLog.BLUETOOTH_ENABLED_STATE_CHANGED,
                uid, null, FrameworkStatsLog.BLUETOOTH_ENABLED_STATE_CHANGED__STATE__DISABLED,
                reason, packageName);
    }

    @Override
    public void noteBleScanStarted(final WorkSource ws, final boolean isUnoptimized) {
        enforceCallingPermission();