diff options
5 files changed, 18 insertions, 14 deletions
diff --git a/core/java/android/net/INetworkManagementEventObserver.aidl b/core/java/android/net/INetworkManagementEventObserver.aidl index f0fe92eb8641..55ae2185c226 100644 --- a/core/java/android/net/INetworkManagementEventObserver.aidl +++ b/core/java/android/net/INetworkManagementEventObserver.aidl @@ -85,11 +85,14 @@ oneway interface INetworkManagementEventObserver { /** * Interface data activity status is changed. * - * @param iface The interface. + * @param label Unique identifier indicates the network 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(String label, boolean active, long tsNanos); + void interfaceClassDataActivityChanged(String label, 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 2a9c0b44b45e..0e8d61a04179 100644 --- a/core/java/com/android/server/net/BaseNetworkObserver.java +++ b/core/java/com/android/server/net/BaseNetworkObserver.java @@ -64,7 +64,8 @@ public class BaseNetworkObserver extends INetworkManagementEventObserver.Stub { } @Override - public void interfaceClassDataActivityChanged(String label, boolean active, long tsNanos) { + public void interfaceClassDataActivityChanged(String label, 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 2e1fbb77cd01..01ef69b6654e 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -1803,7 +1803,8 @@ public class ConnectivityService extends IConnectivityManager.Stub private INetworkManagementEventObserver mDataActivityObserver = new BaseNetworkObserver() { @Override - public void interfaceClassDataActivityChanged(String label, boolean active, long tsNanos) { + public void interfaceClassDataActivityChanged(String label, boolean active, long tsNanos, + int uid) { int deviceType = Integer.parseInt(label); sendDataActivityBroadcast(deviceType, active, tsNanos); } diff --git a/services/core/java/com/android/server/NetworkManagementService.java b/services/core/java/com/android/server/NetworkManagementService.java index 636da6f34abc..39e005172b03 100644 --- a/services/core/java/com/android/server/NetworkManagementService.java +++ b/services/core/java/com/android/server/NetworkManagementService.java @@ -438,7 +438,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub { // the radio is the authority for the current state. final boolean active = isActive; invokeForAllObservers(o -> o.interfaceClassDataActivityChanged( - Integer.toString(type), active, tsNanos)); + Integer.toString(type), active, tsNanos, uid)); } boolean report = false; diff --git a/tests/net/java/com/android/server/NetworkManagementServiceTest.java b/tests/net/java/com/android/server/NetworkManagementServiceTest.java index ea763d2e931e..e1502299ab05 100644 --- a/tests/net/java/com/android/server/NetworkManagementServiceTest.java +++ b/tests/net/java/com/android/server/NetworkManagementServiceTest.java @@ -68,11 +68,12 @@ import java.util.function.BiFunction; @SmallTest public class NetworkManagementServiceTest { private NetworkManagementService mNMService; - @Mock private Context mContext; @Mock private IBatteryStats.Stub mBatteryStatsService; @Mock private INetd.Stub mNetdService; + private static final int TEST_UID = 111; + @NonNull @Captor private ArgumentCaptor<INetdUnsolicitedEventListener> mUnsolListenerCaptor; @@ -165,14 +166,14 @@ public class NetworkManagementServiceTest { /** * Interface class activity. */ - unsolListener.onInterfaceClassActivityChanged(true, 1, 1234, 0); - expectSoon(observer).interfaceClassDataActivityChanged("1", true, 1234); + unsolListener.onInterfaceClassActivityChanged(true, 1, 1234, TEST_UID); + expectSoon(observer).interfaceClassDataActivityChanged("1", true, 1234, TEST_UID); - unsolListener.onInterfaceClassActivityChanged(false, 9, 5678, 0); - expectSoon(observer).interfaceClassDataActivityChanged("9", false, 5678); + unsolListener.onInterfaceClassActivityChanged(false, 9, 5678, TEST_UID); + expectSoon(observer).interfaceClassDataActivityChanged("9", false, 5678, TEST_UID); - unsolListener.onInterfaceClassActivityChanged(false, 9, 4321, 0); - expectSoon(observer).interfaceClassDataActivityChanged("9", false, 4321); + unsolListener.onInterfaceClassActivityChanged(false, 9, 4321, TEST_UID); + expectSoon(observer).interfaceClassDataActivityChanged("9", false, 4321, TEST_UID); /** * IP address changes. @@ -222,8 +223,6 @@ public class NetworkManagementServiceTest { assertFalse(mNMService.isFirewallEnabled()); } - private static final int TEST_UID = 111; - @Test public void testNetworkRestrictedDefault() { assertFalse(mNMService.isNetworkRestricted(TEST_UID)); |