From 88b369a4872ed26cd90ce61eb27284adc00da7de Mon Sep 17 00:00:00 2001 From: Ricky Wai Date: Fri, 7 Feb 2020 16:26:29 +0000 Subject: [PATCH] Mount private volume hook after prepareUserData As CE and DE data directory may not be ready when volume is mounted (like a new volume). We try to mount data mirror after user data is prepared. It will skip mounting data mirror if it's already mounted. Bug: 149027213 Test: After reverting ag/10156695 and aosp/1218838, can see virtual disk is mounted correctly in adb shell mount, and test app works and mounted correctly after pm move-package. Change-Id: If433914a93f7e6154f31715869f52b387157b2dd --- .../android/server/StorageManagerService.java | 16 +++++++++------- .../java/com/android/server/pm/Installer.java | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/services/core/java/com/android/server/StorageManagerService.java b/services/core/java/com/android/server/StorageManagerService.java index c9ba988000e04..2b2a6edb55bd5 100644 --- a/services/core/java/com/android/server/StorageManagerService.java +++ b/services/core/java/com/android/server/StorageManagerService.java @@ -1300,13 +1300,6 @@ class StorageManagerService extends IStorageManager.Stub vol.state = newState; onVolumeStateChangedLocked(vol, oldState, newState); } - try { - if (vol.type == VolumeInfo.TYPE_PRIVATE && state == VolumeInfo.STATE_MOUNTED) { - mInstaller.onPrivateVolumeMounted(vol.getFsUuid()); - } - } catch (Installer.InstallerException e) { - Slog.i(TAG, "Failed when private volume mounted " + vol, e); - } } } @@ -3110,6 +3103,15 @@ class StorageManagerService extends IStorageManager.Stub try { mVold.prepareUserStorage(volumeUuid, userId, serialNumber, flags); + // After preparing user storage, we should check if we should mount data mirror again, + // and we do it for user 0 only as we only need to do once for all users. + if (volumeUuid != null) { + final StorageManager storage = mContext.getSystemService(StorageManager.class); + VolumeInfo info = storage.findVolumeByUuid(volumeUuid); + if (info != null && userId == 0 && info.type == VolumeInfo.TYPE_PRIVATE) { + mInstaller.tryMountDataMirror(volumeUuid); + } + } } catch (Exception e) { Slog.wtf(TAG, e); } diff --git a/services/core/java/com/android/server/pm/Installer.java b/services/core/java/com/android/server/pm/Installer.java index b98bb0831b0ef..8ad3e9df8bdf5 100644 --- a/services/core/java/com/android/server/pm/Installer.java +++ b/services/core/java/com/android/server/pm/Installer.java @@ -611,10 +611,10 @@ public class Installer extends SystemService { /** * Bind mount private volume CE and DE mirror storage. */ - public void onPrivateVolumeMounted(String volumeUuid) throws InstallerException { + public void tryMountDataMirror(String volumeUuid) throws InstallerException { if (!checkBeforeRemote()) return; try { - mInstalld.onPrivateVolumeMounted(volumeUuid); + mInstalld.tryMountDataMirror(volumeUuid); } catch (Exception e) { throw InstallerException.from(e); }