[NFCT.TETHER.14] Clear the BPF maps in BpfCoordinator ctor am: 499d3cac73 am: 129077bd58 am: 9dba544999
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1623669 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: Icc33ff9ddc0306bf58df81ff9f6e9756817a1534
This commit is contained in:
@@ -84,12 +84,46 @@ public class BpfCoordinatorShimImpl
|
||||
|
||||
public BpfCoordinatorShimImpl(@NonNull final Dependencies deps) {
|
||||
mLog = deps.getSharedLog().forSubComponent(TAG);
|
||||
|
||||
mBpfDownstream4Map = deps.getBpfDownstream4Map();
|
||||
mBpfUpstream4Map = deps.getBpfUpstream4Map();
|
||||
mBpfDownstream6Map = deps.getBpfDownstream6Map();
|
||||
mBpfUpstream6Map = deps.getBpfUpstream6Map();
|
||||
mBpfStatsMap = deps.getBpfStatsMap();
|
||||
mBpfLimitMap = deps.getBpfLimitMap();
|
||||
|
||||
// Clear the stubs of the maps for handling the system service crash if any.
|
||||
// Doesn't throw the exception and clear the stubs as many as possible.
|
||||
try {
|
||||
if (mBpfDownstream4Map != null) mBpfDownstream4Map.clear();
|
||||
} catch (ErrnoException e) {
|
||||
mLog.e("Could not clear mBpfDownstream4Map: " + e);
|
||||
}
|
||||
try {
|
||||
if (mBpfUpstream4Map != null) mBpfUpstream4Map.clear();
|
||||
} catch (ErrnoException e) {
|
||||
mLog.e("Could not clear mBpfUpstream4Map: " + e);
|
||||
}
|
||||
try {
|
||||
if (mBpfDownstream6Map != null) mBpfDownstream6Map.clear();
|
||||
} catch (ErrnoException e) {
|
||||
mLog.e("Could not clear mBpfDownstream6Map: " + e);
|
||||
}
|
||||
try {
|
||||
if (mBpfUpstream6Map != null) mBpfUpstream6Map.clear();
|
||||
} catch (ErrnoException e) {
|
||||
mLog.e("Could not clear mBpfUpstream6Map: " + e);
|
||||
}
|
||||
try {
|
||||
if (mBpfStatsMap != null) mBpfStatsMap.clear();
|
||||
} catch (ErrnoException e) {
|
||||
mLog.e("Could not clear mBpfStatsMap: " + e);
|
||||
}
|
||||
try {
|
||||
if (mBpfLimitMap != null) mBpfLimitMap.clear();
|
||||
} catch (ErrnoException e) {
|
||||
mLog.e("Could not clear mBpfLimitMap: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -224,6 +224,7 @@ public class BpfCoordinator {
|
||||
maybeSchedulePollingStats();
|
||||
};
|
||||
|
||||
// TODO: add BpfMap<TetherDownstream64Key, TetherDownstream64Value> retrieving function.
|
||||
@VisibleForTesting
|
||||
public abstract static class Dependencies {
|
||||
/** Get handler. */
|
||||
|
||||
@@ -150,6 +150,12 @@ public class BpfCoordinatorTest {
|
||||
// BpfMap#getValue treats that the entry is not found as no error.
|
||||
return mMap.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() throws ErrnoException {
|
||||
// TODO: consider using mocked #getFirstKey and #deleteEntry to implement.
|
||||
mMap.clear();
|
||||
}
|
||||
};
|
||||
|
||||
@Mock private NetworkStatsManager mStatsManager;
|
||||
@@ -986,6 +992,24 @@ public class BpfCoordinatorTest {
|
||||
checkBpfDisabled();
|
||||
}
|
||||
|
||||
@Test
|
||||
@IgnoreUpTo(Build.VERSION_CODES.R)
|
||||
public void testBpfDisabledbyNoBpfDownstream4Map() throws Exception {
|
||||
setupFunctioningNetdInterface();
|
||||
doReturn(null).when(mDeps).getBpfDownstream4Map();
|
||||
|
||||
checkBpfDisabled();
|
||||
}
|
||||
|
||||
@Test
|
||||
@IgnoreUpTo(Build.VERSION_CODES.R)
|
||||
public void testBpfDisabledbyNoBpfUpstream4Map() throws Exception {
|
||||
setupFunctioningNetdInterface();
|
||||
doReturn(null).when(mDeps).getBpfUpstream4Map();
|
||||
|
||||
checkBpfDisabled();
|
||||
}
|
||||
|
||||
@Test
|
||||
@IgnoreUpTo(Build.VERSION_CODES.R)
|
||||
public void testBpfDisabledbyNoBpfStatsMap() throws Exception {
|
||||
@@ -1004,6 +1028,20 @@ public class BpfCoordinatorTest {
|
||||
checkBpfDisabled();
|
||||
}
|
||||
|
||||
@Test
|
||||
@IgnoreUpTo(Build.VERSION_CODES.R)
|
||||
public void testBpfMapClear() throws Exception {
|
||||
setupFunctioningNetdInterface();
|
||||
|
||||
final BpfCoordinator coordinator = makeBpfCoordinator();
|
||||
verify(mBpfDownstream4Map).clear();
|
||||
verify(mBpfUpstream4Map).clear();
|
||||
verify(mBpfDownstream6Map).clear();
|
||||
verify(mBpfUpstream6Map).clear();
|
||||
verify(mBpfStatsMap).clear();
|
||||
verify(mBpfLimitMap).clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTetheringConfigSetPollingInterval() throws Exception {
|
||||
setupFunctioningNetdInterface();
|
||||
|
||||
Reference in New Issue
Block a user