Use java BpfMap in BpfNetMaps#removeNiceApp
Bug: 217624062 Test: atest BpfNetMapsTest HostsideRestrictBackgroundNetworkTests Change-Id: I0433459ec43b6a84c4417152884d10fae5fecee6
This commit is contained in:
@@ -27,6 +27,7 @@ import static android.net.ConnectivityManager.FIREWALL_CHAIN_STANDBY;
|
||||
import static android.net.INetd.PERMISSION_INTERNET;
|
||||
|
||||
import static com.android.server.BpfNetMaps.DOZABLE_MATCH;
|
||||
import static com.android.server.BpfNetMaps.HAPPY_BOX_MATCH;
|
||||
import static com.android.server.BpfNetMaps.IIF_MATCH;
|
||||
import static com.android.server.BpfNetMaps.NO_MATCH;
|
||||
import static com.android.server.BpfNetMaps.PENALTY_BOX_MATCH;
|
||||
@@ -332,4 +333,42 @@ public final class BpfNetMapsTest {
|
||||
assertThrows(UnsupportedOperationException.class,
|
||||
() -> mBpfNetMaps.addNaughtyApp(TEST_UID));
|
||||
}
|
||||
|
||||
private void doTestRemoveNiceApp(final long iif, final long match) throws Exception {
|
||||
mUidOwnerMap.updateEntry(new U32(TEST_UID), new UidOwnerValue(iif, match));
|
||||
|
||||
mBpfNetMaps.removeNiceApp(TEST_UID);
|
||||
|
||||
checkUidOwnerValue(TEST_UID, iif, match & ~HAPPY_BOX_MATCH);
|
||||
}
|
||||
|
||||
@Test
|
||||
@IgnoreUpTo(Build.VERSION_CODES.S_V2)
|
||||
public void testRemoveNiceApp() throws Exception {
|
||||
doTestRemoveNiceApp(NO_IIF, HAPPY_BOX_MATCH);
|
||||
|
||||
// HAPPY_BOX_MATCH with other matches
|
||||
doTestRemoveNiceApp(NO_IIF, HAPPY_BOX_MATCH | DOZABLE_MATCH | POWERSAVE_MATCH);
|
||||
|
||||
// HAPPY_BOX_MATCH with IIF_MATCH
|
||||
doTestRemoveNiceApp(TEST_IF_INDEX, HAPPY_BOX_MATCH | IIF_MATCH);
|
||||
|
||||
// HAPPY_BOX_MATCH is not enabled
|
||||
doTestRemoveNiceApp(NO_IIF, DOZABLE_MATCH | POWERSAVE_MATCH | RESTRICTED_MATCH);
|
||||
}
|
||||
|
||||
@Test
|
||||
@IgnoreUpTo(Build.VERSION_CODES.S_V2)
|
||||
public void testRemoveNiceAppMissingUid() {
|
||||
// UidOwnerMap does not have entry for TEST_UID
|
||||
assertThrows(ServiceSpecificException.class,
|
||||
() -> mBpfNetMaps.removeNiceApp(TEST_UID));
|
||||
}
|
||||
|
||||
@Test
|
||||
@IgnoreAfter(Build.VERSION_CODES.S_V2)
|
||||
public void testRemoveNiceAppBeforeT() {
|
||||
assertThrows(UnsupportedOperationException.class,
|
||||
() -> mBpfNetMaps.removeNiceApp(TEST_UID));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user