diff options
author | Kenny Root <kroot@google.com> | 2012-05-17 13:30:28 -0700 |
---|---|---|
committer | Kenny Root <kroot@google.com> | 2012-05-17 16:06:54 -0700 |
commit | 51a573c76737733638c475f52e441c814e6645cc (patch) | |
tree | 74f38cdf51785be396ecf39c344097d8f9695081 /services/java/com/android/server/MountService.java | |
parent | 468a2ac63a065680da30f5e796583d53f70f8e25 (diff) |
Wait for ASECs to be scanned before proceeding
Move MountService up the list, then pause waiting for MountService to
finish scanning ASECs before the services that require those packages to
be ready.
Additionally, don't automatically mark all ASEC apps as FLAG_EXTERNAL on
reboot. This prevents AppWidgets and other things from being used with
ASECs which are on internal storage.
Bug: 6445613
Change-Id: I3e0b3e244fec966814d7a5ea93de5d337aea79bd
Diffstat (limited to 'services/java/com/android/server/MountService.java')
-rw-r--r-- | services/java/com/android/server/MountService.java | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/services/java/com/android/server/MountService.java b/services/java/com/android/server/MountService.java index d6606f63a686..13ab586a5080 100644 --- a/services/java/com/android/server/MountService.java +++ b/services/java/com/android/server/MountService.java @@ -79,6 +79,8 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import java.util.Set; import javax.crypto.SecretKey; @@ -178,7 +180,8 @@ class MountService extends IMountService.Stub final private ArrayList<MountServiceBinderListener> mListeners = new ArrayList<MountServiceBinderListener>(); private boolean mBooted = false; - private boolean mReady = false; + private CountDownLatch mConnectedSignal = new CountDownLatch(1); + private CountDownLatch mAsecsScanned = new CountDownLatch(1); private boolean mSendUmsConnectedOnBoot = false; // true if we should fake MEDIA_MOUNTED state for external storage private boolean mEmulateExternalStorage = false; @@ -446,15 +449,30 @@ class MountService extends IMountService.Stub final private HandlerThread mHandlerThread; final private Handler mHandler; + void waitForAsecScan() { + waitForLatch(mAsecsScanned); + } + private void waitForReady() { - while (mReady == false) { - for (int retries = 5; retries > 0; retries--) { - if (mReady) { + waitForLatch(mConnectedSignal); + } + + private void waitForLatch(CountDownLatch latch) { + if (latch == null) { + return; + } + + for (;;) { + try { + if (latch.await(5000, TimeUnit.MILLISECONDS)) { return; + } else { + Slog.w(TAG, "Thread " + Thread.currentThread().getName() + + " still waiting for MountService ready..."); } - SystemClock.sleep(1000); + } catch (InterruptedException e) { + Slog.w(TAG, "Interrupt while waiting for MountService to be ready."); } - Slog.w(TAG, "Waiting too long for mReady!"); } } @@ -627,7 +645,7 @@ class MountService extends IMountService.Stub * Since we'll be calling back into the NativeDaemonConnector, * we need to do our work in a new thread. */ - new Thread() { + new Thread("MountService#onDaemonConnected") { @Override public void run() { /** @@ -668,14 +686,19 @@ class MountService extends IMountService.Stub updatePublicVolumeState(mExternalStoragePath, Environment.MEDIA_REMOVED); } - // Let package manager load internal ASECs. - mPms.updateExternalMediaStatus(true, false); - /* * Now that we've done our initialization, release * the hounds! */ - mReady = true; + mConnectedSignal.countDown(); + mConnectedSignal = null; + + // Let package manager load internal ASECs. + mPms.scanAvailableAsecs(); + + // Notify people waiting for ASECs to be scanned that it's done. + mAsecsScanned.countDown(); + mAsecsScanned = null; } }.start(); } @@ -1159,22 +1182,12 @@ class MountService extends IMountService.Stub mObbActionHandler = new ObbActionHandler(mHandlerThread.getLooper()); /* - * Vold does not run in the simulator, so pretend the connector thread - * ran and did its thing. - */ - if ("simulator".equals(SystemProperties.get("ro.product.device"))) { - mReady = true; - mUmsEnabling = true; - return; - } - - /* * Create the connection to vold with a maximum queue of twice the * amount of containers we'd ever expect to have. This keeps an * "asec list" from blocking a thread repeatedly. */ mConnector = new NativeDaemonConnector(this, "vold", MAX_CONTAINERS * 2, VOLD_TAG, 25); - mReady = false; + Thread thread = new Thread(mConnector, VOLD_TAG); thread.start(); |