Merge "Timeout when partitioning takes too long." into mnc-dev
This commit is contained in:
@@ -59,6 +59,7 @@ import android.os.Process;
|
|||||||
import android.os.RemoteCallbackList;
|
import android.os.RemoteCallbackList;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
|
import android.os.SystemClock;
|
||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
@@ -128,6 +129,7 @@ import java.util.Map.Entry;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import javax.crypto.SecretKey;
|
import javax.crypto.SecretKey;
|
||||||
import javax.crypto.SecretKeyFactory;
|
import javax.crypto.SecretKeyFactory;
|
||||||
@@ -692,6 +694,15 @@ class MountService extends IMountService.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void waitForLatch(CountDownLatch latch, String condition) {
|
private void waitForLatch(CountDownLatch latch, String condition) {
|
||||||
|
try {
|
||||||
|
waitForLatch(latch, condition, -1);
|
||||||
|
} catch (TimeoutException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void waitForLatch(CountDownLatch latch, String condition, long timeoutMillis)
|
||||||
|
throws TimeoutException {
|
||||||
|
final long startMillis = SystemClock.elapsedRealtime();
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
if (latch.await(5000, TimeUnit.MILLISECONDS)) {
|
if (latch.await(5000, TimeUnit.MILLISECONDS)) {
|
||||||
@@ -703,6 +714,10 @@ class MountService extends IMountService.Stub
|
|||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Slog.w(TAG, "Interrupt while waiting for " + condition);
|
Slog.w(TAG, "Interrupt while waiting for " + condition);
|
||||||
}
|
}
|
||||||
|
if (timeoutMillis > 0 && SystemClock.elapsedRealtime() > startMillis + timeoutMillis) {
|
||||||
|
throw new TimeoutException("Thread " + Thread.currentThread().getName()
|
||||||
|
+ " gave up waiting for " + condition + " after " + timeoutMillis + "ms");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1645,10 +1660,12 @@ class MountService extends IMountService.Stub
|
|||||||
final CountDownLatch latch = findOrCreateDiskScanLatch(diskId);
|
final CountDownLatch latch = findOrCreateDiskScanLatch(diskId);
|
||||||
try {
|
try {
|
||||||
mConnector.execute("volume", "partition", diskId, "public");
|
mConnector.execute("volume", "partition", diskId, "public");
|
||||||
|
waitForLatch(latch, "partitionPublic", 3 * DateUtils.MINUTE_IN_MILLIS);
|
||||||
} catch (NativeDaemonConnectorException e) {
|
} catch (NativeDaemonConnectorException e) {
|
||||||
throw e.rethrowAsParcelableException();
|
throw e.rethrowAsParcelableException();
|
||||||
|
} catch (TimeoutException e) {
|
||||||
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
waitForLatch(latch, "partitionPublic");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1660,10 +1677,12 @@ class MountService extends IMountService.Stub
|
|||||||
final CountDownLatch latch = findOrCreateDiskScanLatch(diskId);
|
final CountDownLatch latch = findOrCreateDiskScanLatch(diskId);
|
||||||
try {
|
try {
|
||||||
mConnector.execute("volume", "partition", diskId, "private");
|
mConnector.execute("volume", "partition", diskId, "private");
|
||||||
|
waitForLatch(latch, "partitionPrivate", 3 * DateUtils.MINUTE_IN_MILLIS);
|
||||||
} catch (NativeDaemonConnectorException e) {
|
} catch (NativeDaemonConnectorException e) {
|
||||||
throw e.rethrowAsParcelableException();
|
throw e.rethrowAsParcelableException();
|
||||||
|
} catch (TimeoutException e) {
|
||||||
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
waitForLatch(latch, "partitionPrivate");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1675,10 +1694,12 @@ class MountService extends IMountService.Stub
|
|||||||
final CountDownLatch latch = findOrCreateDiskScanLatch(diskId);
|
final CountDownLatch latch = findOrCreateDiskScanLatch(diskId);
|
||||||
try {
|
try {
|
||||||
mConnector.execute("volume", "partition", diskId, "mixed", ratio);
|
mConnector.execute("volume", "partition", diskId, "mixed", ratio);
|
||||||
|
waitForLatch(latch, "partitionMixed", 3 * DateUtils.MINUTE_IN_MILLIS);
|
||||||
} catch (NativeDaemonConnectorException e) {
|
} catch (NativeDaemonConnectorException e) {
|
||||||
throw e.rethrowAsParcelableException();
|
throw e.rethrowAsParcelableException();
|
||||||
|
} catch (TimeoutException e) {
|
||||||
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
waitForLatch(latch, "partitionMixed");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user