Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 72324e4e authored by Howard Chen's avatar Howard Chen Committed by Po-Chien Hsueh
Browse files

Use gsid.isGsiEnabled to refine DynamicSystemService

* Add isEnabled
* Replace toggle with setEnable

Test: Compile passed
Bug: 125079548
Change-Id: I4931e6469388ea05194ba44ccb994f32c08ad40d
parent 4167b42f
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -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());
        }
+7 −2
Original line number Diff line number Diff line
@@ -57,6 +57,11 @@ interface IDynamicSystemService
     */
    boolean isInstalled();

    /**
     * @return true if the device has an DynamicSystem image enabled
     */
    boolean isEnabled();

    /**
     * Remove DynamicSystem installation if present
     *
@@ -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
+24 −20
Original line number Diff line number Diff line
@@ -70,7 +70,6 @@ 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);
@@ -79,6 +78,10 @@ public class DynamicSystemService extends IDynamicSystemService.Stub implements
                    break;
                }
                if ("running".equals(SystemProperties.get("init.svc.gsid"))) {
                    break;
                }
            }
        }
        synchronized (this) {
            if (mGsiService == null) {
                mGsiService = connect(this);
@@ -86,10 +89,6 @@ public class DynamicSystemService extends IDynamicSystemService.Stub implements
            return mGsiService;
        }
    }
        }
        Slog.e(TAG, "Unable to start gsid");
        return null;
    }

    private void checkPermission() {
        if (mContext.checkCallingOrSelfPermission(
@@ -124,20 +123,25 @@ public class DynamicSystemService extends IDynamicSystemService.Stub implements
        return getGsiService().isGsiInstalled();
    }

    @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();
        }
    }