am 234b0b03: Merge "Fix, MountService now only sends one onShutDownComplete"

* commit '234b0b037ee1f8dc50c846279216a8e4d779ff56':
  Fix, MountService now only sends one onShutDownComplete
This commit is contained in:
Jeff Sharkey
2014-02-18 09:12:57 -08:00
committed by Android Git Automerger

View File

@ -91,6 +91,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@ -384,18 +385,37 @@ class MountService extends IMountService.Stub
}
class ShutdownCallBack extends UnmountCallBack {
IMountShutdownObserver observer;
ShutdownCallBack(String path, IMountShutdownObserver observer) {
MountShutdownLatch mMountShutdownLatch;
ShutdownCallBack(String path, final MountShutdownLatch mountShutdownLatch) {
super(path, true, false);
this.observer = observer;
mMountShutdownLatch = mountShutdownLatch;
}
@Override
void handleFinished() {
int ret = doUnmountVolume(path, true, removeEncryption);
if (observer != null) {
Slog.i(TAG, "Unmount completed: " + path + ", result code: " + ret);
mMountShutdownLatch.countDown();
}
}
static class MountShutdownLatch {
private IMountShutdownObserver mObserver;
private AtomicInteger mCount;
MountShutdownLatch(final IMountShutdownObserver observer, int count) {
mObserver = observer;
mCount = new AtomicInteger(count);
}
void countDown() {
boolean sendShutdown = false;
if (mCount.decrementAndGet() == 0) {
sendShutdown = true;
}
if (sendShutdown && mObserver != null) {
try {
observer.onShutDownComplete(ret);
mObserver.onShutDownComplete(StorageResultCode.OperationSucceeded);
} catch (RemoteException e) {
Slog.w(TAG, "RemoteException when shutting down");
}
@ -1426,6 +1446,10 @@ class MountService extends IMountService.Stub
Slog.i(TAG, "Shutting down");
synchronized (mVolumesLock) {
// Get all volumes to be unmounted.
MountShutdownLatch mountShutdownLatch = new MountShutdownLatch(observer,
mVolumeStates.size());
for (String path : mVolumeStates.keySet()) {
String state = mVolumeStates.get(path);
@ -1461,19 +1485,16 @@ class MountService extends IMountService.Stub
if (state.equals(Environment.MEDIA_MOUNTED)) {
// Post a unmount message.
ShutdownCallBack ucb = new ShutdownCallBack(path, observer);
ShutdownCallBack ucb = new ShutdownCallBack(path, mountShutdownLatch);
mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_PM_UPDATE, ucb));
} else if (observer != null) {
/*
* Observer is waiting for onShutDownComplete when we are done.
* Since nothing will be done send notification directly so shutdown
* sequence can continue.
* Count down, since nothing will be done. The observer will be
* notified when we are done so shutdown sequence can continue.
*/
try {
observer.onShutDownComplete(StorageResultCode.OperationSucceeded);
} catch (RemoteException e) {
Slog.w(TAG, "RemoteException when shutting down");
}
mountShutdownLatch.countDown();
Slog.i(TAG, "Unmount completed: " + path +
", result code: " + StorageResultCode.OperationSucceeded);
}
}
}