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

Commit c68c069d authored by Howard Chen's avatar Howard Chen Committed by Gerrit Code Review
Browse files

Merge "Use the new gsid interface"

parents dbdaa06d 6ea5bedd
Loading
Loading
Loading
Loading
+27 −3
Original line number Diff line number Diff line
@@ -100,6 +100,19 @@ public class DynamicSystemManager {
            }
        }
    }
    /**
     * Start DynamicSystem installation.
     *
     * @return true if the call succeeds
     */
    @RequiresPermission(android.Manifest.permission.MANAGE_DYNAMIC_SYSTEM)
    public boolean startInstallation() {
        try {
            return mService.startInstallation();
        } catch (RemoteException e) {
            throw new RuntimeException(e.toString());
        }
    }
    /**
     * Start DynamicSystem installation. This call may take an unbounded amount of time. The caller
     * may use another thread to call the getStartProgress() to get the progress.
@@ -112,9 +125,9 @@ public class DynamicSystemManager {
     *     true.
     */
    @RequiresPermission(android.Manifest.permission.MANAGE_DYNAMIC_SYSTEM)
    public Session startInstallation(String name, long size, boolean readOnly) {
    public Session createPartition(String name, long size, boolean readOnly) {
        try {
            if (mService.startInstallation(name, size, readOnly)) {
            if (mService.createPartition(name, size, readOnly)) {
                return new Session();
            } else {
                return null;
@@ -123,7 +136,18 @@ public class DynamicSystemManager {
            throw new RuntimeException(e.toString());
        }
    }

    /**
     * Finish a previously started installation. Installations without a cooresponding
     * finishInstallation() will be cleaned up during device boot.
     */
    @RequiresPermission(android.Manifest.permission.MANAGE_DYNAMIC_SYSTEM)
    public boolean finishInstallation() {
        try {
            return mService.finishInstallation();
        } catch (RemoteException e) {
            throw new RuntimeException(e.toString());
        }
    }
    /**
     * Query the progress of the current installation operation. This can be called while the
     * installation is in progress.
+14 −3
Original line number Diff line number Diff line
@@ -21,15 +21,26 @@ import android.gsi.GsiProgress;
interface IDynamicSystemService
{
    /**
     * Start DynamicSystem installation. This call may take 60~90 seconds. The caller
     * Start DynamicSystem installation.
     * @return true if the call succeeds
     */
    boolean startInstallation();

    /**
     * Create a DSU partition. This call may take 60~90 seconds. The caller
     * may use another thread to call the getStartProgress() to get the progress.
     *
     * @param name The DSU partition name
     * @param size Size of the DSU image in bytes
     * @param readOnly True if this partition is readOnly
     * @return true if the call succeeds
     */
    boolean startInstallation(@utf8InCpp String name, long size, boolean readOnly);
    boolean createPartition(@utf8InCpp String name, long size, boolean readOnly);

    /**
     * Finish a previously started installation. Installations without
     * a cooresponding finishInstallation() will be cleaned up during device boot.
     */
    boolean finishInstallation();

    /**
     * Query the progress of the current installation operation. This can be called while
+4 −2
Original line number Diff line number Diff line
@@ -102,9 +102,10 @@ class InstallationAsyncTask extends AsyncTask<String, Long, Throwable> {
            Thread thread =
                    new Thread(
                            () -> {
                                mDynSystem.startInstallation("userdata", mUserdataSize, false);
                                mDynSystem.startInstallation();
                                mDynSystem.createPartition("userdata", mUserdataSize, false);
                                mInstallationSession =
                                        mDynSystem.startInstallation("system", mSystemSize, true);
                                        mDynSystem.createPartition("system", mSystemSize, true);
                            });

            thread.start();
@@ -157,6 +158,7 @@ class InstallationAsyncTask extends AsyncTask<String, Long, Throwable> {
                    reportedInstalledSize = installedSize;
                }
            }
            mDynSystem.finishInstallation();
            return null;

        } catch (Exception e) {
+27 −10
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.server;

import android.content.Context;
import android.content.pm.PackageManager;
import android.gsi.GsiInstallParams;
import android.gsi.GsiProgress;
import android.gsi.IGsiService;
import android.gsi.IGsid;
@@ -47,6 +46,7 @@ public class DynamicSystemService extends IDynamicSystemService.Stub implements
    private static final int GSID_ROUGH_TIMEOUT_MS = 8192;
    private static final String PATH_DEFAULT = "/data/gsi";
    private Context mContext;
    private String mInstallPath;
    private volatile IGsiService mGsiService;

    DynamicSystemService(Context context) {
@@ -115,8 +115,8 @@ public class DynamicSystemService extends IDynamicSystemService.Stub implements
    }

    @Override
    public boolean startInstallation(String name, long size, boolean readOnly)
            throws RemoteException {
    public boolean startInstallation() throws RemoteException {
        IGsiService service = getGsiService();
        // priority from high to low: sysprop -> sdcard -> /data
        String path = SystemProperties.get("os.aot.path");
        if (path.isEmpty()) {
@@ -138,20 +138,35 @@ public class DynamicSystemService extends IDynamicSystemService.Stub implements
            }
            Slog.i(TAG, "startInstallation -> " + path);
        }
        mInstallPath = path;
        if (service.openInstall(path) != 0) {
            Slog.i(TAG, "Failed to open " + path);
            return false;
        }
        return true;
    }

    @Override
    public boolean createPartition(String name, long size, boolean readOnly)
            throws RemoteException {
        IGsiService service = getGsiService();
        GsiInstallParams installParams = new GsiInstallParams();
        installParams.installDir = path;
        installParams.name = name;
        installParams.size = size;
        installParams.wipe = readOnly;
        installParams.readOnly = readOnly;
        if (service.beginGsiInstall(installParams) != 0) {
        if (service.createPartition(name, size, readOnly) != 0) {
            Slog.i(TAG, "Failed to install " + name);
            return false;
        }
        return true;
    }

    @Override
    public boolean finishInstallation() throws RemoteException {
        IGsiService service = getGsiService();
        if (service.closeInstall() != 0) {
            Slog.i(TAG, "Failed to finish installation");
            return false;
        }
        return true;
    }

    @Override
    public GsiProgress getInstallationProgress() throws RemoteException {
        return getGsiService().getInstallProgress();
@@ -190,6 +205,8 @@ public class DynamicSystemService extends IDynamicSystemService.Stub implements

    @Override
    public boolean remove() throws RemoteException {
        IGsiService gsiService = getGsiService();
        String install_dir = gsiService.getInstalledGsiImageDir();
        return getGsiService().removeGsi();
    }

+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ public class DynamicSystemServiceTest extends AndroidTestCase {
    public void test1() {
        assertTrue("dynamic_system service available", mService != null);
        try {
            mService.startInstallation("userdata", 8L << 30, false);
            mService.startInstallation();
            fail("DynamicSystemService did not throw SecurityException as expected");
        } catch (SecurityException e) {
            // expected