Ensure cdm clear cache command persists state
This CL ensures that the clear-association-memory-cache shell command immediately persists all user state before dumping clearing caches. This prevents state change updates from getting lost. This is not a critical issue because this shell command is only used for testing, but it allows for more graceful and reliable test code. Test: atest CtsCompanionDeviceManagerCoreTestCases Test: atest CtsCompanionDeviceManagerUiAutomationTestCases Change-Id: Ib981862c587a86bce57c4a5d67c7c18a40b47235
This commit is contained in:
@@ -77,6 +77,7 @@ import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageItemInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManagerInternal;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.net.MacAddress;
|
||||
import android.net.NetworkPolicyManager;
|
||||
import android.os.Binder;
|
||||
@@ -1358,6 +1359,17 @@ public class CompanionDeviceManagerService extends SystemService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method must only be called from {@link CompanionDeviceShellCommand} for testing
|
||||
* purposes only!
|
||||
*/
|
||||
void persistState() {
|
||||
mUserPersistenceHandler.clearMessages();
|
||||
for (UserInfo user : mUserManager.getAliveUsers()) {
|
||||
persistStateForUser(user.id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class is dedicated to handling requests to persist user state.
|
||||
*/
|
||||
@@ -1376,6 +1388,13 @@ public class CompanionDeviceManagerService extends SystemService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears *ALL* outstanding persist requests for *ALL* users.
|
||||
*/
|
||||
synchronized void clearMessages() {
|
||||
removeCallbacksAndMessages(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(@NonNull Message msg) {
|
||||
final int userId = msg.what;
|
||||
|
||||
@@ -83,6 +83,7 @@ class CompanionDeviceShellCommand extends android.os.ShellCommand {
|
||||
}
|
||||
break;
|
||||
case "clear-association-memory-cache": {
|
||||
mService.persistState();
|
||||
mService.loadAssociationsFromDisk();
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user