diff options
3 files changed, 44 insertions, 26 deletions
diff --git a/core/java/android/os/image/DynamicSystemManager.java b/core/java/android/os/image/DynamicSystemManager.java index 0458c2a8b735..cec19457dd07 100644 --- a/core/java/android/os/image/DynamicSystemManager.java +++ b/core/java/android/os/image/DynamicSystemManager.java @@ -159,6 +159,16 @@ public class DynamicSystemManager { } } + /** @return {@code true} if the device has a dynamic system enabled */ + @RequiresPermission(android.Manifest.permission.MANAGE_DYNAMIC_SYSTEM) + public boolean isEnabled() { + try { + return mService.isEnabled(); + } catch (RemoteException e) { + throw new RuntimeException(e.toString()); + } + } + /** * Remove DynamicSystem installation if present * @@ -174,14 +184,13 @@ public class DynamicSystemManager { } /** - * Enable DynamicSystem when it's not enabled, otherwise, disable it. - * + * Enable or disable DynamicSystem. * @return {@code true} if the call succeeds. {@code false} if there is no installed image. */ @RequiresPermission(android.Manifest.permission.MANAGE_DYNAMIC_SYSTEM) - public boolean toggle() { + public boolean setEnable(boolean enable) { try { - return mService.toggle(); + return mService.setEnable(enable); } catch (RemoteException e) { throw new RuntimeException(e.toString()); } diff --git a/core/java/android/os/image/IDynamicSystemService.aidl b/core/java/android/os/image/IDynamicSystemService.aidl index 15f5b68e354b..a34daca86ce5 100644 --- a/core/java/android/os/image/IDynamicSystemService.aidl +++ b/core/java/android/os/image/IDynamicSystemService.aidl @@ -58,6 +58,11 @@ interface IDynamicSystemService boolean isInstalled(); /** + * @return true if the device has an DynamicSystem image enabled + */ + boolean isEnabled(); + + /** * Remove DynamicSystem installation if present * * @return true if the call succeeds @@ -65,11 +70,11 @@ interface IDynamicSystemService boolean remove(); /** - * Enable DynamicSystem when it's not enabled, otherwise, disable it. + * Enable or disable DynamicSystem. * * @return true if the call succeeds */ - boolean toggle(); + boolean setEnable(boolean enable); /** * Write a chunk of the DynamicSystem system image diff --git a/services/core/java/com/android/server/DynamicSystemService.java b/services/core/java/com/android/server/DynamicSystemService.java index f5bd11cea779..99bbcf890a0a 100644 --- a/services/core/java/com/android/server/DynamicSystemService.java +++ b/services/core/java/com/android/server/DynamicSystemService.java @@ -70,25 +70,24 @@ public class DynamicSystemService extends IDynamicSystemService.Stub implements checkPermission(); 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; + 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"))) { + break; } } } - Slog.e(TAG, "Unable to start gsid"); - return null; + synchronized (this) { + if (mGsiService == null) { + mGsiService = connect(this); + } + return mGsiService; + } } private void checkPermission() { @@ -125,19 +124,24 @@ public class DynamicSystemService extends IDynamicSystemService.Stub implements } @Override + public boolean isEnabled() throws RemoteException { + return getGsiService().isGsiEnabled(); + } + + @Override public boolean remove() throws RemoteException { return getGsiService().removeGsiInstall(); } @Override - public boolean toggle() throws RemoteException { + public boolean setEnable(boolean enable) throws RemoteException { IGsiService gsiService = getGsiService(); - if (gsiService.isGsiRunning()) { - return gsiService.disableGsiInstall(); - } else { + if (enable) { final int status = gsiService.getGsiBootStatus(); final boolean singleBoot = (status == IGsiService.BOOT_STATUS_SINGLE_BOOT); return gsiService.setGsiBootable(singleBoot) == 0; + } else { + return gsiService.disableGsiInstall(); } } |