Merge changes I1d1f0d2d,Ifbd4a978
* changes: Communicate with BatteryStatsService through BatteryStatsManager Add a new API in BatteryStatsManager for connectivity service
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user