Fix a race in setExplicitHealthCheckEnabled() (4/n)
Sometimes the property change callback is not called within the sleep timeout. Let's call updateConfigs() to apply device config changes immediately to eliminate the race condition. Bug: 178675924 Test: atest PackageWatchdogTest Change-Id: I2b3ce79eac36cfc5ef98a62750142bb6d936e043
This commit is contained in:
@@ -994,7 +994,8 @@ public class PackageWatchdog {
|
||||
* Health check is enabled or disabled after reading the flags
|
||||
* from DeviceConfig.
|
||||
*/
|
||||
private void updateConfigs() {
|
||||
@VisibleForTesting
|
||||
void updateConfigs() {
|
||||
synchronized (mLock) {
|
||||
mTriggerFailureCount = DeviceConfig.getInt(
|
||||
DeviceConfig.NAMESPACE_ROLLBACK,
|
||||
|
||||
@@ -98,6 +98,8 @@ public class PackageWatchdogTest {
|
||||
private final TestClock mTestClock = new TestClock();
|
||||
private TestLooper mTestLooper;
|
||||
private Context mSpyContext;
|
||||
// Keep track of all created watchdogs to apply device config changes
|
||||
private List<PackageWatchdog> mAllocatedWatchdogs;
|
||||
@Mock
|
||||
private ConnectivityModuleConnector mConnectivityModuleConnector;
|
||||
@Mock
|
||||
@@ -166,12 +168,15 @@ public class PackageWatchdogTest {
|
||||
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_ROLLBACK,
|
||||
PackageWatchdog.PROPERTY_WATCHDOG_TRIGGER_FAILURE_COUNT,
|
||||
Integer.toString(PackageWatchdog.DEFAULT_TRIGGER_FAILURE_COUNT), false);
|
||||
|
||||
mAllocatedWatchdogs = new ArrayList<>();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
dropShellPermissions();
|
||||
mSession.finishMocking();
|
||||
mAllocatedWatchdogs.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1295,11 +1300,9 @@ public class PackageWatchdogTest {
|
||||
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_ROLLBACK,
|
||||
PackageWatchdog.PROPERTY_WATCHDOG_EXPLICIT_HEALTH_CHECK_ENABLED,
|
||||
Boolean.toString(enabled), /*makeDefault*/false);
|
||||
//give time for DeviceConfig to broadcast the property value change
|
||||
try {
|
||||
Thread.sleep(SHORT_DURATION);
|
||||
} catch (InterruptedException e) {
|
||||
fail("Thread.sleep unexpectedly failed!");
|
||||
// Call updateConfigs() so device config changes take effect immediately
|
||||
for (PackageWatchdog watchdog : mAllocatedWatchdogs) {
|
||||
watchdog.updateConfigs();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1348,6 +1351,7 @@ public class PackageWatchdogTest {
|
||||
verify(mConnectivityModuleConnector).registerHealthListener(
|
||||
mConnectivityModuleCallbackCaptor.capture());
|
||||
}
|
||||
mAllocatedWatchdogs.add(watchdog);
|
||||
return watchdog;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user