summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/api/module-lib-current.txt4
-rw-r--r--core/java/android/os/BatteryStatsManager.java26
-rw-r--r--services/core/java/com/android/server/ConnectivityService.java14
-rw-r--r--services/core/java/com/android/server/am/BatteryStatsService.java3
-rw-r--r--tests/net/java/com/android/server/ConnectivityServiceTest.java21
5 files changed, 55 insertions, 13 deletions
diff --git a/core/api/module-lib-current.txt b/core/api/module-lib-current.txt
index 3529858a0c95..b3562e5f496d 100644
--- a/core/api/module-lib-current.txt
+++ b/core/api/module-lib-current.txt
@@ -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();
}
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;
}
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index 2c9837d38dc2..9a5e4ca0068a 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -1038,6 +1038,16 @@ public class ConnectivityService extends IConnectivityManager.Stub
public IBatteryStats getBatteryStatsService() {
return BatteryStatsService.getService();
}
+
+ /**
+ * @see BatteryStatsManager
+ */
+ public void reportNetworkInterfaceForTransports(Context context, String iface,
+ int[] transportTypes) {
+ final BatteryStatsManager batteryStats =
+ context.getSystemService(BatteryStatsManager.class);
+ batteryStats.reportNetworkInterfaceForTransports(iface, transportTypes);
+ }
}
public ConnectivityService(Context context) {
@@ -6281,13 +6291,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
oldLp != null ? oldLp.getAllInterfaceNames() : null,
newLp != null ? newLp.getAllInterfaceNames() : null);
if (!interfaceDiff.added.isEmpty()) {
- final IBatteryStats bs = mDeps.getBatteryStatsService();
for (final String iface : interfaceDiff.added) {
try {
if (DBG) log("Adding iface " + iface + " to network " + netId);
mNetd.networkAddInterface(netId, iface);
wakeupModifyInterface(iface, caps, true);
- bs.noteNetworkInterfaceForTransports(iface, caps.getTransportTypes());
+ mDeps.reportNetworkInterfaceForTransports(mContext, iface,
+ caps.getTransportTypes());
} catch (Exception e) {
loge("Exception adding interface: " + e);
}
diff --git a/services/core/java/com/android/server/am/BatteryStatsService.java b/services/core/java/com/android/server/am/BatteryStatsService.java
index 3f9811c2ce24..226802c74f25 100644
--- a/services/core/java/com/android/server/am/BatteryStatsService.java
+++ b/services/core/java/com/android/server/am/BatteryStatsService.java
@@ -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);
}
diff --git a/tests/net/java/com/android/server/ConnectivityServiceTest.java b/tests/net/java/com/android/server/ConnectivityServiceTest.java
index 2546580e1802..0eef0160370e 100644
--- a/tests/net/java/com/android/server/ConnectivityServiceTest.java
+++ b/tests/net/java/com/android/server/ConnectivityServiceTest.java
@@ -7808,7 +7808,8 @@ public class ConnectivityServiceTest {
mCellNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR, cellLp);
mCellNetworkAgent.connect(true);
waitForIdle();
- verify(mBatteryStatsService).noteNetworkInterfaceForTransports(cellLp.getInterfaceName(),
+ verify(mDeps).reportNetworkInterfaceForTransports(mServiceContext,
+ cellLp.getInterfaceName(),
new int[] { TRANSPORT_CELLULAR });
reset(mBatteryStatsService);
@@ -7817,7 +7818,8 @@ public class ConnectivityServiceTest {
mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI, wifiLp);
mWiFiNetworkAgent.connect(true);
waitForIdle();
- verify(mBatteryStatsService).noteNetworkInterfaceForTransports(wifiLp.getInterfaceName(),
+ verify(mDeps).reportNetworkInterfaceForTransports(mServiceContext,
+ wifiLp.getInterfaceName(),
new int[] { TRANSPORT_WIFI });
reset(mBatteryStatsService);
@@ -7828,7 +7830,8 @@ public class ConnectivityServiceTest {
mCellNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR, cellLp);
mCellNetworkAgent.connect(true);
waitForIdle();
- verify(mBatteryStatsService).noteNetworkInterfaceForTransports(cellLp.getInterfaceName(),
+ verify(mDeps).reportNetworkInterfaceForTransports(mServiceContext,
+ cellLp.getInterfaceName(),
new int[] { TRANSPORT_CELLULAR });
mCellNetworkAgent.disconnect();
}
@@ -7912,7 +7915,8 @@ public class ConnectivityServiceTest {
assertRoutesAdded(cellNetId, ipv6Subnet, defaultRoute);
verify(mMockDnsResolver, times(1)).createNetworkCache(eq(cellNetId));
verify(mMockNetd, times(1)).networkAddInterface(cellNetId, MOBILE_IFNAME);
- verify(mBatteryStatsService).noteNetworkInterfaceForTransports(cellLp.getInterfaceName(),
+ verify(mDeps).reportNetworkInterfaceForTransports(mServiceContext,
+ cellLp.getInterfaceName(),
new int[] { TRANSPORT_CELLULAR });
networkCallback.expectAvailableThenValidatedCallbacks(mCellNetworkAgent);
@@ -7933,8 +7937,8 @@ public class ConnectivityServiceTest {
// Make sure BatteryStats was not told about any v4- interfaces, as none should have
// come online yet.
waitForIdle();
- verify(mBatteryStatsService, never()).noteNetworkInterfaceForTransports(startsWith("v4-"),
- any());
+ verify(mDeps, never())
+ .reportNetworkInterfaceForTransports(eq(mServiceContext), startsWith("v4-"), any());
verifyNoMoreInteractions(mMockNetd);
verifyNoMoreInteractions(mMockDnsResolver);
@@ -7986,8 +7990,9 @@ public class ConnectivityServiceTest {
assertTrue(ArrayUtils.contains(resolvrParams.servers, "8.8.8.8"));
for (final LinkProperties stackedLp : stackedLpsAfterChange) {
- verify(mBatteryStatsService).noteNetworkInterfaceForTransports(
- stackedLp.getInterfaceName(), new int[] { TRANSPORT_CELLULAR });
+ verify(mDeps).reportNetworkInterfaceForTransports(
+ mServiceContext, stackedLp.getInterfaceName(),
+ new int[] { TRANSPORT_CELLULAR });
}
reset(mMockNetd);
when(mMockNetd.interfaceGetCfg(CLAT_PREFIX + MOBILE_IFNAME))