[IT04] Add uid as parameter of interfaceClassDataActivityChanged

Add uid into interfaceClassDataActivityChanged in
INetworkManagementEventObserver. This helps the listeners to use
BaseNetworkObserver to listen for target evnets instead of using
whole INetdUnsolicitedEventListener with no-op in other event
that listeners do not care about.

Bug: 170598012
Test: m ; atest FrameworksNetTests
Change-Id: I2a42a522c2ff9b1e0be88261a8574bb7f5292fa6
This commit is contained in:
Chiachang Wang
2020-12-21 13:34:55 +08:00
parent 3f01a7a8c1
commit 9c133bc4e9
5 changed files with 18 additions and 14 deletions

View File

@@ -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.

View File

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

View File

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

View File

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

View File

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