From 1392c145d71316defa97b0347dd5b50d8045adfb Mon Sep 17 00:00:00 2001 From: Howard Chen Date: Tue, 5 Mar 2019 14:23:47 +0800 Subject: [PATCH] Support starting gsid lazily The aosp/914714 made the gsid to start when needed. The DynamicAndroidService must support this behavior as well. Bug:126622385 Test: adb shell am start-activity \ -n com.android.dynandroid/com.android.dynandroid.VerificationActivity \ -a android.content.action.START_INSTALL \ --es KEY_SYSTEM_URL file:///storage/emulated/0/Download/system.raw.gz \ --el KEY_SYSTEM_SIZE $(du -b system.raw) \ --el KEY_USERDATA_SIZE 8589934592 Change-Id: Ifb9d642d183ed3e7181ed643f9415850178ef58d --- .../android/server/DynamicAndroidService.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/DynamicAndroidService.java b/services/core/java/com/android/server/DynamicAndroidService.java index 8488941587fbc..b02bfb1117273 100644 --- a/services/core/java/com/android/server/DynamicAndroidService.java +++ b/services/core/java/com/android/server/DynamicAndroidService.java @@ -25,6 +25,7 @@ import android.os.IBinder.DeathRecipient; import android.os.IDynamicAndroidService; import android.os.RemoteException; import android.os.ServiceManager; +import android.os.SystemProperties; import android.util.Slog; /** @@ -34,6 +35,7 @@ import android.util.Slog; public class DynamicAndroidService extends IDynamicAndroidService.Stub implements DeathRecipient { private static final String TAG = "DynamicAndroidService"; private static final String NO_SERVICE_ERROR = "no gsiservice"; + private static final int GSID_ROUGH_TIMEOUT_MS = 8192; private Context mContext; private volatile IGsiService mGsiService; @@ -66,12 +68,27 @@ public class DynamicAndroidService extends IDynamicAndroidService.Stub implement private IGsiService getGsiService() throws RemoteException { checkPermission(); - synchronized (this) { - if (mGsiService == null) { - mGsiService = connect(this); - } - return mGsiService; + if (!"running".equals(SystemProperties.get("init.svc.gsid"))) { + SystemProperties.set("ctl.start", "gsid"); } + for (int sleepMs = 64; sleepMs <= (GSID_ROUGH_TIMEOUT_MS << 1); sleepMs <<= 1) { + try { + Thread.sleep(sleepMs); + } catch (InterruptedException e) { + Slog.e(TAG, "Interrupted when waiting for GSID"); + break; + } + if ("running".equals(SystemProperties.get("init.svc.gsid"))) { + synchronized (this) { + if (mGsiService == null) { + mGsiService = connect(this); + } + return mGsiService; + } + } + } + Slog.e(TAG, "Unable to start gsid"); + return null; } private void checkPermission() {