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

Commit 137aed14 authored by Daniel Rosenberg's avatar Daniel Rosenberg
Browse files

Mount adopted storage after boot completed

Ensure we set up adopted devices after boot complete to avoid
interactions with checkpointing

Test: sm set-force-adoptable on
      sm set-virtual-disk true
      then set up virtual disk
      atest android.appsecurity.cts.AdoptableHostTest
Change-Id: I4cc79a6d8a2d231c739a2b8cae1c1f8e7616ca81
parent f3d7dd6b
Loading
Loading
Loading
Loading
+20 −12
Original line number Diff line number Diff line
@@ -611,6 +611,7 @@ class StorageManagerService extends IStorageManager.Stub
    private static final int H_RESET = 10;
    private static final int H_RUN_IDLE_MAINT = 11;
    private static final int H_ABORT_IDLE_MAINT = 12;
    private static final int H_BOOT_COMPLETED = 13;

    class StorageManagerServiceHandler extends Handler {
        public StorageManagerServiceHandler(Looper looper) {
@@ -624,6 +625,10 @@ class StorageManagerService extends IStorageManager.Stub
                    handleSystemReady();
                    break;
                }
                case H_BOOT_COMPLETED: {
                    handleBootCompleted();
                    break;
                }
                case H_DAEMON_CONNECTED: {
                    handleDaemonConnected();
                    break;
@@ -712,7 +717,7 @@ class StorageManagerService extends IStorageManager.Stub
                    break;
                }
                case H_RESET: {
                    resetIfReadyAndConnected();
                    resetIfBootedAndConnected();
                    break;
                }
                case H_RUN_IDLE_MAINT: {
@@ -785,9 +790,6 @@ class StorageManagerService extends IStorageManager.Stub
    }

    private void handleSystemReady() {
        initIfReadyAndConnected();
        resetIfReadyAndConnected();

        // Start scheduling nominally-daily fstrim operations
        MountServiceIdler.scheduleIdlePass(mContext);

@@ -933,10 +935,10 @@ class StorageManagerService extends IStorageManager.Stub
        mVolumes.put(internal.id, internal);
    }

    private void initIfReadyAndConnected() {
        Slog.d(TAG, "Thinking about init, mSystemReady=" + mSystemReady
    private void initIfBootedAndConnected() {
        Slog.d(TAG, "Thinking about init, mBootCompleted=" + mBootCompleted
                + ", mDaemonConnected=" + mDaemonConnected);
        if (mSystemReady && mDaemonConnected
        if (mBootCompleted && mDaemonConnected
                && !StorageManager.isFileEncryptedNativeOnly()) {
            // When booting a device without native support, make sure that our
            // user directories are locked or unlocked based on the current
@@ -959,10 +961,10 @@ class StorageManagerService extends IStorageManager.Stub
        }
    }

    private void resetIfReadyAndConnected() {
        Slog.d(TAG, "Thinking about reset, mSystemReady=" + mSystemReady
    private void resetIfBootedAndConnected() {
        Slog.d(TAG, "Thinking about reset, mBootCompleted=" + mBootCompleted
                + ", mDaemonConnected=" + mDaemonConnected);
        if (mSystemReady && mDaemonConnected) {
        if (mBootCompleted && mDaemonConnected) {
            final List<UserInfo> users = mContext.getSystemService(UserManager.class).getUsers();
            killMediaProvider(users);

@@ -1121,8 +1123,8 @@ class StorageManagerService extends IStorageManager.Stub
    }

    private void handleDaemonConnected() {
        initIfReadyAndConnected();
        resetIfReadyAndConnected();
        initIfBootedAndConnected();
        resetIfBootedAndConnected();

        // On an encrypted device we can't see system properties yet, so pull
        // the system locale out of the mount service.
@@ -1856,6 +1858,12 @@ class StorageManagerService extends IStorageManager.Stub

    private void bootCompleted() {
        mBootCompleted = true;
        mHandler.obtainMessage(H_BOOT_COMPLETED).sendToTarget();
    }

    private void handleBootCompleted() {
        initIfBootedAndConnected();
        resetIfBootedAndConnected();
    }

    private String getDefaultPrimaryStorageUuid() {