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

Commit 1e0167e2 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "SM: Remount emulated volumes on Move Storage" into main am: f2a97bef...

Merge "SM: Remount emulated volumes on Move Storage" into main am: f2a97bef am: 4bb705f2 am: aa69d4ac

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2682226



Change-Id: Iaa418087de7876e2f205bba03b1b0984b3247457
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 6d0fcd34 aa69d4ac
Loading
Loading
Loading
Loading
+44 −0
Original line number Original line Diff line number Diff line
@@ -676,6 +676,7 @@ class StorageManagerService extends IStorageManager.Stub
    private static final int H_VOLUME_STATE_CHANGED = 15;
    private static final int H_VOLUME_STATE_CHANGED = 15;
    private static final int H_CLOUD_MEDIA_PROVIDER_CHANGED = 16;
    private static final int H_CLOUD_MEDIA_PROVIDER_CHANGED = 16;
    private static final int H_SECURE_KEYGUARD_STATE_CHANGED = 17;
    private static final int H_SECURE_KEYGUARD_STATE_CHANGED = 17;
    private static final int H_REMOUNT_VOLUMES_ON_MOVE = 18;


    class StorageManagerServiceHandler extends Handler {
    class StorageManagerServiceHandler extends Handler {
        public StorageManagerServiceHandler(Looper looper) {
        public StorageManagerServiceHandler(Looper looper) {
@@ -831,6 +832,10 @@ class StorageManagerService extends IStorageManager.Stub
                    }
                    }
                    break;
                    break;
                }
                }
                case H_REMOUNT_VOLUMES_ON_MOVE: {
                    remountVolumesForRunningUsersOnMove();
                    break;
                }
            }
            }
        }
        }
    }
    }
@@ -1284,6 +1289,44 @@ class StorageManagerService extends IStorageManager.Stub
        }
        }
    }
    }


    /**
     * This method informs vold and storaged that the user has stopped and started whenever move
     * storage is performed. This ensures that the correct emulated volumes are mounted for the
     * users other than the current user. This solves an edge case wherein the correct emulated
     * volumes are not mounted, this will cause the media data to be still stored on internal
     * storage whereas the data should be stored in the adopted primary storage. This method stops
     * the users at vold first which will remove the old volumes which and starts the users at vold
     * which will reattach the correct volumes. This does not performs a full reset as full reset
     * clears every state from vold and SMS {@link #resetIfRebootedAndConnected} which is expensive
     * and causes instability.
     */
    private void remountVolumesForRunningUsersOnMove() {
        // Do not want to hold the lock for long
        final List<Integer> unlockedUsers = new ArrayList<>();
        synchronized (mLock) {
            for (int userId : mSystemUnlockedUsers) {
                if (userId == mCurrentUserId) continue;
                unlockedUsers.add(userId);
            }
        }
        for (Integer userId : unlockedUsers) {
            try {
                mVold.onUserStopped(userId);
                mStoraged.onUserStopped(userId);
            } catch (Exception e) {
                Slog.wtf(TAG, e);
            }
        }
        for (Integer userId : unlockedUsers) {
            try {
                mVold.onUserStarted(userId);
                mStoraged.onUserStarted(userId);
            } catch (Exception e) {
                Slog.wtf(TAG, e);
            }
        }
    }

    private boolean supportsBlockCheckpoint() throws RemoteException {
    private boolean supportsBlockCheckpoint() throws RemoteException {
        enforcePermission(android.Manifest.permission.MOUNT_FORMAT_FILESYSTEMS);
        enforcePermission(android.Manifest.permission.MOUNT_FORMAT_FILESYSTEMS);
        return mVold.supportsBlockCheckpoint();
        return mVold.supportsBlockCheckpoint();
@@ -1818,6 +1861,7 @@ class StorageManagerService extends IStorageManager.Stub


            mPrimaryStorageUuid = mMoveTargetUuid;
            mPrimaryStorageUuid = mMoveTargetUuid;
            writeSettingsLocked();
            writeSettingsLocked();
            mHandler.obtainMessage(H_REMOUNT_VOLUMES_ON_MOVE).sendToTarget();
        }
        }


        if (PackageManager.isMoveStatusFinished(status)) {
        if (PackageManager.isMoveStatusFinished(status)) {