Init PersistentDatablockService on the worker thread
Other services do not depend on PersistentDatabalockService in the early stages of system server initialization. Initialization is now done on the FgThread. The service also ensures that init is complete before PHASE_ACTIVITY_MANAGER_READY. Change-Id: I3b9a1994e37c1e995ed04257f271c425d48c2e7c Test: Manual, device boots, service is initialized and published Bug: 33199244
This commit is contained in:
@@ -47,6 +47,8 @@ import java.nio.channels.FileChannel;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Service for reading and writing blocks to a persistent partition.
|
||||
@@ -81,6 +83,7 @@ public class PersistentDataBlockService extends SystemService {
|
||||
private final Context mContext;
|
||||
private final String mDataBlockFile;
|
||||
private final Object mLock = new Object();
|
||||
private final CountDownLatch mInitDoneSignal = new CountDownLatch(1);
|
||||
|
||||
private int mAllowedUid = -1;
|
||||
private long mBlockDeviceSize;
|
||||
@@ -110,9 +113,29 @@ public class PersistentDataBlockService extends SystemService {
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
enforceChecksumValidity();
|
||||
formatIfOemUnlockEnabled();
|
||||
publishBinderService(Context.PERSISTENT_DATA_BLOCK_SERVICE, mService);
|
||||
// Do init on a separate thread, will join in PHASE_ACTIVITY_MANAGER_READY
|
||||
FgThread.getHandler().post(() -> {
|
||||
enforceChecksumValidity();
|
||||
formatIfOemUnlockEnabled();
|
||||
publishBinderService(Context.PERSISTENT_DATA_BLOCK_SERVICE, mService);
|
||||
mInitDoneSignal.countDown();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBootPhase(int phase) {
|
||||
// Wait for initialization in onStart to finish
|
||||
if (phase == PHASE_SYSTEM_SERVICES_READY) {
|
||||
try {
|
||||
if (!mInitDoneSignal.await(10, TimeUnit.SECONDS)) {
|
||||
throw new IllegalStateException("Service " + TAG + " init timeout");
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IllegalStateException("Service " + TAG + " init interrupted", e);
|
||||
}
|
||||
}
|
||||
super.onBootPhase(phase);
|
||||
}
|
||||
|
||||
private void formatIfOemUnlockEnabled() {
|
||||
|
||||
@@ -1484,8 +1484,10 @@ public final class SystemServer {
|
||||
@Override
|
||||
public void run() {
|
||||
Slog.i(TAG, "Making services ready");
|
||||
traceBeginAndSlog("StartActivityManagerReadyPhase");
|
||||
mSystemServiceManager.startBootPhase(
|
||||
SystemService.PHASE_ACTIVITY_MANAGER_READY);
|
||||
traceEnd();
|
||||
traceBeginAndSlog("PhaseActivityManagerReady");
|
||||
|
||||
traceBeginAndSlog("StartObservingNativeCrashes");
|
||||
|
||||
Reference in New Issue
Block a user