From 3ae5bdab6eab95febb4886ca51ef260f9783d006 Mon Sep 17 00:00:00 2001 From: Aaron Huang Date: Mon, 26 Oct 2020 17:34:50 +0800 Subject: Add a new API in BatteryStatsManager for connectivity service Connectivity service(CS) is going to be a mainline module and currently it uses IBatteryStats to communicate with battery stats service directly. CS cannot use this way after becomes a mainline module so add new system APIs to communicate with battery stats service through BatteryStatsManger. The new API reportNetworkInterfaceForTransports requires system-only permission NETWORK_STACK or MAINLINE_NETWORK_STACK so that given the only caller was in ConnectivityService. This change only add new surface, the usage in CS will be updated in follow-up CL. Bug: 171686421 Test: builds, boot, mobile and wifi work. Change-Id: Ifbd4a9784ed7664751e69d530f8204e292fa6b39 Merged-In: Ifbd4a9784ed7664751e69d530f8204e292fa6b39 --- core/java/android/os/BatteryStatsManager.java | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'core/java/android') diff --git a/core/java/android/os/BatteryStatsManager.java b/core/java/android/os/BatteryStatsManager.java index 258e58d7d019..3f4a21878687 100644 --- a/core/java/android/os/BatteryStatsManager.java +++ b/core/java/android/os/BatteryStatsManager.java @@ -24,6 +24,7 @@ import android.annotation.RequiresPermission; import android.annotation.SystemApi; import android.annotation.SystemService; import android.content.Context; +import android.net.NetworkStack; import android.os.connectivity.CellularBatteryStats; import android.os.connectivity.WifiBatteryStats; import android.telephony.DataConnectionRealTimeInfo; @@ -416,10 +417,31 @@ public final class BatteryStatsManager { } } + /** + * Notifies the battery stats of a new interface, and the transport types of the network that + * includes that interface. + * + * @param iface The interface of the network. + * @param transportTypes The transport type of the network {@link Transport}. + * @hide + */ + @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) + @RequiresPermission(anyOf = { + NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, + android.Manifest.permission.NETWORK_STACK}) + public void reportNetworkInterfaceForTransports(@NonNull String iface, + @NonNull int[] transportTypes) throws RuntimeException { + try { + mBatteryStats.noteNetworkInterfaceForTransports(iface, transportTypes); + } catch (RemoteException e) { + e.rethrowFromSystemServer(); + } + } + private static int getDataConnectionPowerState(boolean isActive) { // TODO: DataConnectionRealTimeInfo is under telephony package but the constants are used - // for both Wifi and mobile. It would make more sense to separate the constants to a generic - // class or move it to generic package. + // for both Wifi and mobile. It would make more sense to separate the constants to a + // generic class or move it to generic package. return isActive ? DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH : DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; } -- cgit v1.2.3