Adopted Storage: Prepare user storage before move

Moving "primary storage" between internal and adoptable storage involves
accessing the CE and DE storage of all users.  Similarly, moving an app
involves accessing the CE and DE storage of all users who have the app
installed.  CE and DE storage must be unlocked and prepared on both
volumes for all these users.  Currently this as handled as follows:

- Before starting either operation, Settings requires LSKF verification
  for each user whose CE storage is currently locked.

- For "move app", PMS prepares CE and DE storage on the target volume
  for users who don't have a CE directory on the target volume.

This isn't enough, however.  First, because unlocking of adoptable
storage is done by SMS.prepareUserStorage and not by SMS.unlockUserKey,
LSKF verification doesn't do it unless the user is already running.
Therefore, CE adoptable storage isn't unlocked for stopped users.
Second, since a stopped user might never have had adoptable storage
prepared at all, and "move primary storage" skips the prepare, the
target directory /mnt/expand/${volume_uuid}/media/${user_id} can end up
with the wrong SELinux label, encryption policy, and other metadata.

Fix both issues by making PMS and SMS call prepareUserStorage on the
source and target volumes for all relevant users for both types of move.

Test: manual
Test A: Check move storage works as expected:
    1. Create multiple users via Settings
    2. Switch to one user and set a lockscreen credentail
    3. Switch back to system user
    4. Execute adb shell am stop-user <user_id>
    5. Format SD card as adopted storage.
    6. Opt in for Move storage
    7. Check that the storage is prepared before moving the storage
       by checking the logs:
       adb logcat | grep fscrypt_prepare_user_storage
    8. Also check move storage is successful

Test B: Check move app works as expected:
    1. Create multiple users apart from system user
    2. Make ExternalLocTestApp and install for all the
       users.
    3. Go to Settings > All Apps >  ExternalLocTestApp > Storage & Cache
    4. Tap on Change under Storage User and Select Adopted storage.
    5. Check that the process is not failing

Change-Id: I8aef053968af957d52261bfe86d8fea64dcae6e7
3 files changed