From cf5916f3fa9e5eabc143dfb3669198e9ba3c3634 Mon Sep 17 00:00:00 2001 From: Martijn Coenen Date: Fri, 3 Jan 2020 14:36:45 +0100 Subject: [PATCH] Also delay creating found disks until user 0 is started. Public and private volumes can be discovered before user 0 is up and running; when using FUSE however, we can't mount these disks yet, because we depend on the user to become unlocked before we can start the FUSE daemon (which is the MediaProvider application process). So besides waiting for any secure keyguard to be dismissed, also wait for user 0 to be started. Bug: 146419093 Test: Boot cuttlefish with a fake public volume; is available after repeated boots. Change-Id: I06fe4d336d1baec3a49886c3cf12d844a1d0eb26 --- VolumeManager.cpp | 24 +++++++++++++++++++----- VolumeManager.h | 1 + 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/VolumeManager.cpp b/VolumeManager.cpp index bc843b4..4d850fb 100644 --- a/VolumeManager.cpp +++ b/VolumeManager.cpp @@ -264,10 +264,17 @@ void VolumeManager::handleBlockEvent(NetlinkEvent* evt) { void VolumeManager::handleDiskAdded(const std::shared_ptr& disk) { // For security reasons, if secure keyguard is showing, wait // until the user unlocks the device to actually touch it + // Additionally, wait until user 0 is actually started, since we need + // the user to be up before we can mount a FUSE daemon to handle the disk. + bool userZeroStarted = mStartedUsers.find(0) != mStartedUsers.end(); if (mSecureKeyguardShowing) { LOG(INFO) << "Found disk at " << disk->getEventPath() << " but delaying scan due to secure keyguard"; mPendingDisks.push_back(disk); + } else if (!userZeroStarted) { + LOG(INFO) << "Found disk at " << disk->getEventPath() + << " but delaying scan due to user zero not having started"; + mPendingDisks.push_back(disk); } else { disk->create(); mDisks.push_back(disk); @@ -482,6 +489,8 @@ int VolumeManager::onUserStarted(userid_t userId) { } mStartedUsers.insert(userId); + + createPendingDisksIfNeeded(); return 0; } @@ -496,17 +505,22 @@ int VolumeManager::onUserStopped(userid_t userId) { return 0; } -int VolumeManager::onSecureKeyguardStateChanged(bool isShowing) { - mSecureKeyguardShowing = isShowing; - if (!mSecureKeyguardShowing) { - // Now that secure keyguard has been dismissed, process - // any pending disks +void VolumeManager::createPendingDisksIfNeeded() { + bool userZeroStarted = mStartedUsers.find(0) != mStartedUsers.end(); + if (!mSecureKeyguardShowing && userZeroStarted) { + // Now that secure keyguard has been dismissed and user 0 has + // started, process any pending disks for (const auto& disk : mPendingDisks) { disk->create(); mDisks.push_back(disk); } mPendingDisks.clear(); } +} + +int VolumeManager::onSecureKeyguardStateChanged(bool isShowing) { + mSecureKeyguardShowing = isShowing; + createPendingDisksIfNeeded(); return 0; } diff --git a/VolumeManager.h b/VolumeManager.h index db32ecd..cacab85 100644 --- a/VolumeManager.h +++ b/VolumeManager.h @@ -94,6 +94,7 @@ class VolumeManager { int onUserStarted(userid_t userId); int onUserStopped(userid_t userId); + void createPendingDisksIfNeeded(); int onSecureKeyguardStateChanged(bool isShowing); int setPrimary(const std::shared_ptr& vol);