Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1c620df4 authored by Nikolas Havrikov's avatar Nikolas Havrikov
Browse files

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
parent 5af1c38c
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -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;
+1 −0
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ class CompanionDeviceShellCommand extends android.os.ShellCommand {
                }
                break;
                case "clear-association-memory-cache": {
                    mService.persistState();
                    mService.loadAssociationsFromDisk();
                }
                break;