Merge "Retry getting DynamicSystem service" into qt-dev

This commit is contained in:
TreeHugger Robot
2019-04-11 15:53:52 +00:00
committed by Android (Google) Code Review

View File

@@ -47,7 +47,7 @@ public class DynamicSystemService extends IDynamicSystemService.Stub implements
private static IGsiService connect(DeathRecipient recipient) throws RemoteException { private static IGsiService connect(DeathRecipient recipient) throws RemoteException {
IBinder binder = ServiceManager.getService("gsiservice"); IBinder binder = ServiceManager.getService("gsiservice");
if (binder == null) { if (binder == null) {
throw new RemoteException(NO_SERVICE_ERROR); return null;
} }
/** /**
* The init will restart gsiservice if it crashed and the proxy object will need to be * The init will restart gsiservice if it crashed and the proxy object will need to be
@@ -68,26 +68,31 @@ public class DynamicSystemService extends IDynamicSystemService.Stub implements
private IGsiService getGsiService() throws RemoteException { private IGsiService getGsiService() throws RemoteException {
checkPermission(); checkPermission();
if (!"running".equals(SystemProperties.get("init.svc.gsid"))) { if (!"running".equals(SystemProperties.get("init.svc.gsid"))) {
SystemProperties.set("ctl.start", "gsid"); SystemProperties.set("ctl.start", "gsid");
for (int sleepMs = 64; sleepMs <= (GSID_ROUGH_TIMEOUT_MS << 1); sleepMs <<= 1) { }
try {
Thread.sleep(sleepMs); for (int sleepMs = 64; sleepMs <= (GSID_ROUGH_TIMEOUT_MS << 1); sleepMs <<= 1) {
} catch (InterruptedException e) { synchronized (this) {
Slog.e(TAG, "Interrupted when waiting for GSID"); if (mGsiService == null) {
break; mGsiService = connect(this);
} }
if ("running".equals(SystemProperties.get("init.svc.gsid"))) { if (mGsiService != null) {
break; return mGsiService;
} }
} }
}
synchronized (this) { try {
if (mGsiService == null) { Slog.d(TAG, "GsiService is not ready, wait for " + sleepMs + "ms");
mGsiService = connect(this); Thread.sleep(sleepMs);
} catch (InterruptedException e) {
Slog.e(TAG, "Interrupted when waiting for GSID");
return null;
} }
return mGsiService;
} }
throw new RemoteException(NO_SERVICE_ERROR);
} }
private void checkPermission() { private void checkPermission() {