diff options
| author | 2020-12-23 15:52:13 +0800 | |
|---|---|---|
| committer | 2021-01-13 14:10:15 +0800 | |
| commit | 3ce298dff1afe84dfdd6dc0022c717a57a70fcd4 (patch) | |
| tree | 65ea45d1d107710140b7fd56052ab1d3eac886b3 | |
| parent | f0341dc38b9d2a7b055c29e9dbb834cfc0434c61 (diff) | |
[IT4.21] Update the label type of idle timer
The first parameter of adding idle timer is an unique identity
to communicate between ConnectivityService and netd. Netd will
notify the activity change using the identity, so it's fine to
replace the legacy type with transport type since we should
deprecate the usage of legacy type.
Bug: 170598012
Test: atest FrameworksNetTests
Change-Id: Ia00606539b86872cca9a92285bd940c8a720a033
4 files changed, 27 insertions, 11 deletions
diff --git a/core/java/android/net/INetworkManagementEventObserver.aidl b/core/java/android/net/INetworkManagementEventObserver.aidl index 37813ce11a5f..0a6be20226b8 100644 --- a/core/java/android/net/INetworkManagementEventObserver.aidl +++ b/core/java/android/net/INetworkManagementEventObserver.aidl @@ -85,14 +85,14 @@ oneway interface INetworkManagementEventObserver { /** * Interface data activity status is changed. * - * @param networkType The legacy network type of the data activity change. + * @param transportType The transport type of the data activity change. * @param active True if the interface is actively transmitting data, false if it is idle. * @param tsNanos Elapsed realtime in nanos when the state of the network interface changed. * @param uid Uid of this event. It represents the uid that was responsible for waking the * radio. For those events that are reported by system itself, not from specific uid, * use -1 for the events which means no uid. */ - void interfaceClassDataActivityChanged(int networkType, boolean active, long tsNanos, int uid); + void interfaceClassDataActivityChanged(int transportType, boolean active, long tsNanos, int uid); /** * Information about available DNS servers has been received. diff --git a/core/java/com/android/server/net/BaseNetworkObserver.java b/core/java/com/android/server/net/BaseNetworkObserver.java index 93f89b5db820..139b88b108c5 100644 --- a/core/java/com/android/server/net/BaseNetworkObserver.java +++ b/core/java/com/android/server/net/BaseNetworkObserver.java @@ -64,7 +64,7 @@ public class BaseNetworkObserver extends INetworkManagementEventObserver.Stub { } @Override - public void interfaceClassDataActivityChanged(int networkType, boolean active, long tsNanos, + public void interfaceClassDataActivityChanged(int transportType, boolean active, long tsNanos, int uid) { // default no-op } diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 397eeb23396c..7ebc345a49e6 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -1779,12 +1779,28 @@ public class ConnectivityService extends IConnectivityManager.Stub private INetworkManagementEventObserver mDataActivityObserver = new BaseNetworkObserver() { @Override - public void interfaceClassDataActivityChanged(int networkType, boolean active, long tsNanos, - int uid) { - sendDataActivityBroadcast(networkType, active, tsNanos); + public void interfaceClassDataActivityChanged(int transportType, boolean active, + long tsNanos, int uid) { + sendDataActivityBroadcast(transportTypeToLegacyType(transportType), active, tsNanos); } }; + // This is deprecated and only to support legacy use cases. + private int transportTypeToLegacyType(int type) { + switch (type) { + case NetworkCapabilities.TRANSPORT_CELLULAR: + return ConnectivityManager.TYPE_MOBILE; + case NetworkCapabilities.TRANSPORT_WIFI: + return ConnectivityManager.TYPE_WIFI; + case NetworkCapabilities.TRANSPORT_BLUETOOTH: + return ConnectivityManager.TYPE_BLUETOOTH; + case NetworkCapabilities.TRANSPORT_ETHERNET: + return ConnectivityManager.TYPE_ETHERNET; + default: + loge("Unexpected transport in transportTypeToLegacyType: " + type); + } + return ConnectivityManager.TYPE_NONE; + } /** * Ensures that the system cannot call a particular method. */ @@ -2368,13 +2384,13 @@ public class ConnectivityService extends IConnectivityManager.Stub timeout = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.DATA_ACTIVITY_TIMEOUT_MOBILE, 10); - type = ConnectivityManager.TYPE_MOBILE; + type = NetworkCapabilities.TRANSPORT_CELLULAR; } else if (networkAgent.networkCapabilities.hasTransport( NetworkCapabilities.TRANSPORT_WIFI)) { timeout = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.DATA_ACTIVITY_TIMEOUT_WIFI, 15); - type = ConnectivityManager.TYPE_WIFI; + type = NetworkCapabilities.TRANSPORT_WIFI; } else { return; // do not track any other networks } diff --git a/tests/net/java/com/android/server/ConnectivityServiceTest.java b/tests/net/java/com/android/server/ConnectivityServiceTest.java index 9421acde7b97..0a4806862b16 100644 --- a/tests/net/java/com/android/server/ConnectivityServiceTest.java +++ b/tests/net/java/com/android/server/ConnectivityServiceTest.java @@ -7202,7 +7202,7 @@ public class ConnectivityServiceTest { mCellNetworkAgent.connect(true); networkCallback.expectAvailableThenValidatedCallbacks(mCellNetworkAgent); verify(mNetworkManagementService, times(1)).addIdleTimer(eq(MOBILE_IFNAME), anyInt(), - eq(ConnectivityManager.TYPE_MOBILE)); + eq(NetworkCapabilities.TRANSPORT_CELLULAR)); mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI); final LinkProperties wifiLp = new LinkProperties(); @@ -7216,7 +7216,7 @@ public class ConnectivityServiceTest { networkCallback.expectCallback(CallbackEntry.LOSING, mCellNetworkAgent); networkCallback.expectCapabilitiesWith(NET_CAPABILITY_VALIDATED, mWiFiNetworkAgent); verify(mNetworkManagementService, times(1)).addIdleTimer(eq(WIFI_IFNAME), anyInt(), - eq(ConnectivityManager.TYPE_WIFI)); + eq(NetworkCapabilities.TRANSPORT_WIFI)); verify(mNetworkManagementService, times(1)).removeIdleTimer(eq(MOBILE_IFNAME)); // Disconnect wifi and switch back to cell @@ -7226,7 +7226,7 @@ public class ConnectivityServiceTest { assertNoCallbacks(networkCallback); verify(mNetworkManagementService, times(1)).removeIdleTimer(eq(WIFI_IFNAME)); verify(mNetworkManagementService, times(1)).addIdleTimer(eq(MOBILE_IFNAME), anyInt(), - eq(ConnectivityManager.TYPE_MOBILE)); + eq(NetworkCapabilities.TRANSPORT_CELLULAR)); // reconnect wifi mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI); |