Add a new API in BatteryStatsManager for connectivity service am: 3ae5bdab6e

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1475899

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I97fc5426d302d6084e8434daa3f6c9b2389be449
This commit is contained in:
Aaron Huang
2021-03-09 11:11:49 +00:00
committed by Automerger Merge Worker
3 changed files with 30 additions and 3 deletions

View File

@@ -56,6 +56,10 @@ package android.net {
package android.os {
public final class BatteryStatsManager {
method @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK}) public void reportNetworkInterfaceForTransports(@NonNull String, @NonNull int[]) throws java.lang.RuntimeException;
}
public class Binder implements android.os.IBinder {
method public final void markVintfStability();
}

View File

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

View File

@@ -73,6 +73,7 @@ import com.android.internal.util.DumpUtils;
import com.android.internal.util.FrameworkStatsLog;
import com.android.internal.util.ParseUtils;
import com.android.net.module.util.NetworkCapabilitiesUtils;
import com.android.net.module.util.PermissionUtils;
import com.android.server.LocalServices;
import com.android.server.net.BaseNetworkObserver;
@@ -1102,7 +1103,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
@Override
public void noteNetworkInterfaceForTransports(final String iface, int[] transportTypes) {
enforceCallingPermission();
PermissionUtils.enforceNetworkStackPermission(mContext);
mStats.noteNetworkInterfaceForTransports(iface, transportTypes);
}