[NFCT.TETHER.14] Clear the BPF maps in BpfCoordinator ctor am: 499d3cac73 am: 129077bd58
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1623669 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I63ab27a10a04180ac9faf038350c36ff7aec71fe
This commit is contained in:
@@ -84,12 +84,46 @@ public class BpfCoordinatorShimImpl
|
|||||||
|
|
||||||
public BpfCoordinatorShimImpl(@NonNull final Dependencies deps) {
|
public BpfCoordinatorShimImpl(@NonNull final Dependencies deps) {
|
||||||
mLog = deps.getSharedLog().forSubComponent(TAG);
|
mLog = deps.getSharedLog().forSubComponent(TAG);
|
||||||
|
|
||||||
mBpfDownstream4Map = deps.getBpfDownstream4Map();
|
mBpfDownstream4Map = deps.getBpfDownstream4Map();
|
||||||
mBpfUpstream4Map = deps.getBpfUpstream4Map();
|
mBpfUpstream4Map = deps.getBpfUpstream4Map();
|
||||||
mBpfDownstream6Map = deps.getBpfDownstream6Map();
|
mBpfDownstream6Map = deps.getBpfDownstream6Map();
|
||||||
mBpfUpstream6Map = deps.getBpfUpstream6Map();
|
mBpfUpstream6Map = deps.getBpfUpstream6Map();
|
||||||
mBpfStatsMap = deps.getBpfStatsMap();
|
mBpfStatsMap = deps.getBpfStatsMap();
|
||||||
mBpfLimitMap = deps.getBpfLimitMap();
|
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
|
@Override
|
||||||
|
|||||||
@@ -224,6 +224,7 @@ public class BpfCoordinator {
|
|||||||
maybeSchedulePollingStats();
|
maybeSchedulePollingStats();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: add BpfMap<TetherDownstream64Key, TetherDownstream64Value> retrieving function.
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public abstract static class Dependencies {
|
public abstract static class Dependencies {
|
||||||
/** Get handler. */
|
/** Get handler. */
|
||||||
|
|||||||
@@ -150,6 +150,12 @@ public class BpfCoordinatorTest {
|
|||||||
// BpfMap#getValue treats that the entry is not found as no error.
|
// BpfMap#getValue treats that the entry is not found as no error.
|
||||||
return mMap.get(key);
|
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;
|
@Mock private NetworkStatsManager mStatsManager;
|
||||||
@@ -986,6 +992,24 @@ public class BpfCoordinatorTest {
|
|||||||
checkBpfDisabled();
|
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
|
@Test
|
||||||
@IgnoreUpTo(Build.VERSION_CODES.R)
|
@IgnoreUpTo(Build.VERSION_CODES.R)
|
||||||
public void testBpfDisabledbyNoBpfStatsMap() throws Exception {
|
public void testBpfDisabledbyNoBpfStatsMap() throws Exception {
|
||||||
@@ -1004,6 +1028,20 @@ public class BpfCoordinatorTest {
|
|||||||
checkBpfDisabled();
|
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
|
@Test
|
||||||
public void testTetheringConfigSetPollingInterval() throws Exception {
|
public void testTetheringConfigSetPollingInterval() throws Exception {
|
||||||
setupFunctioningNetdInterface();
|
setupFunctioningNetdInterface();
|
||||||
|
|||||||
Reference in New Issue
Block a user