Moving bt stats logging to BatteryStats.

Tag: #feature
Bug: 211851706
Test: manual
Change-Id: I7e40b64eaa334792dd409837fb9f512714f65eec
This commit is contained in:
Etienne Ruffieux
2022-01-27 23:45:41 +00:00
parent 86d5713de2
commit 5166da8664
4 changed files with 68 additions and 0 deletions

View File

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

View File

@@ -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.
*

View File

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

View File

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