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 Original line 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
     * 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.
     * @return {@code true} if the call succeeds. {@code false} if there is no installed image.
     */
     */
    @RequiresPermission(android.Manifest.permission.MANAGE_DYNAMIC_SYSTEM)
    @RequiresPermission(android.Manifest.permission.MANAGE_DYNAMIC_SYSTEM)
    public boolean toggle() {
    public boolean setEnable(boolean enable) {
        try {
        try {
            return mService.toggle();
            return mService.setEnable(enable);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw new RuntimeException(e.toString());
            throw new RuntimeException(e.toString());
        }
        }
+7 −2
Original line number Original line Diff line number Diff line
@@ -57,6 +57,11 @@ interface IDynamicSystemService
     */
     */
    boolean isInstalled();
    boolean isInstalled();


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

    /**
    /**
     * Remove DynamicSystem installation if present
     * Remove DynamicSystem installation if present
     *
     *
@@ -65,11 +70,11 @@ interface IDynamicSystemService
    boolean remove();
    boolean remove();


    /**
    /**
     * Enable DynamicSystem when it's not enabled, otherwise, disable it.
     * Enable or disable DynamicSystem.
     *
     *
     * @return true if the call succeeds
     * @return true if the call succeeds
     */
     */
    boolean toggle();
    boolean setEnable(boolean enable);


    /**
    /**
     * Write a chunk of the DynamicSystem system image
     * Write a chunk of the DynamicSystem system image
+24 −20
Original line number Original line Diff line number Diff line
@@ -70,7 +70,6 @@ public class DynamicSystemService extends IDynamicSystemService.Stub implements
        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) {
            for (int sleepMs = 64; sleepMs <= (GSID_ROUGH_TIMEOUT_MS << 1); sleepMs <<= 1) {
                try {
                try {
                    Thread.sleep(sleepMs);
                    Thread.sleep(sleepMs);
@@ -79,6 +78,10 @@ public class DynamicSystemService extends IDynamicSystemService.Stub implements
                    break;
                    break;
                }
                }
                if ("running".equals(SystemProperties.get("init.svc.gsid"))) {
                if ("running".equals(SystemProperties.get("init.svc.gsid"))) {
                    break;
                }
            }
        }
        synchronized (this) {
        synchronized (this) {
            if (mGsiService == null) {
            if (mGsiService == null) {
                mGsiService = connect(this);
                mGsiService = connect(this);
@@ -86,10 +89,6 @@ public class DynamicSystemService extends IDynamicSystemService.Stub implements
            return mGsiService;
            return mGsiService;
        }
        }
    }
    }
        }
        Slog.e(TAG, "Unable to start gsid");
        return null;
    }


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


    @Override
    public boolean isEnabled() throws RemoteException {
        return getGsiService().isGsiEnabled();
    }

    @Override
    @Override
    public boolean remove() throws RemoteException {
    public boolean remove() throws RemoteException {
        return getGsiService().removeGsiInstall();
        return getGsiService().removeGsiInstall();
    }
    }


    @Override
    @Override
    public boolean toggle() throws RemoteException {
    public boolean setEnable(boolean enable) throws RemoteException {
        IGsiService gsiService = getGsiService();
        IGsiService gsiService = getGsiService();
        if (gsiService.isGsiRunning()) {
        if (enable) {
            return gsiService.disableGsiInstall();
        } else {
            final int status = gsiService.getGsiBootStatus();
            final int status = gsiService.getGsiBootStatus();
            final boolean singleBoot = (status == IGsiService.BOOT_STATUS_SINGLE_BOOT);
            final boolean singleBoot = (status == IGsiService.BOOT_STATUS_SINGLE_BOOT);
            return gsiService.setGsiBootable(singleBoot) == 0;
            return gsiService.setGsiBootable(singleBoot) == 0;
        } else {
            return gsiService.disableGsiInstall();
        }
        }
    }
    }