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

Commit 04f7391f authored by Alex Buynytskyy's avatar Alex Buynytskyy
Browse files

Incremental installations in PackageManagerShellCommand.

- onPrepareImage in native,
- allow to check installation type and choose native or managed
dataloaders,
- native data loader for Incremental,
- install-incremental shell command.

Test: atest PackageManagerShellCommandTest
Test: atest IncrementalServiceTest
Bug: b/136132412 b/133435829
Change-Id: I530a8a203fb50132c1869abd0b869036add18699
parent ad1c9607
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -33,7 +33,4 @@ interface IIncrementalManager {
    boolean startDataLoader(int mountId);
    void showHealthBlockedUI(int mountId);
    void destroyDataLoader(int mountId);

    // fileId is a 16 byte long identifier.
    void newFileForDataLoader(int mountId, in byte[] fileId, in byte[] metadata);
}
+2 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.os.incremental;

import android.content.pm.DataLoaderParamsParcel;
import android.content.pm.IDataLoaderStatusListener;
import android.os.incremental.IncrementalNewFileParams;

/** @hide */
@@ -33,7 +34,7 @@ interface IIncrementalService {
     * Opens or creates a storage given a target path and data loader params. Returns the storage ID.
     */
    int openStorage(in @utf8InCpp String path);
    int createStorage(in @utf8InCpp String path, in DataLoaderParamsParcel params, int createMode);
    int createStorage(in @utf8InCpp String path, in DataLoaderParamsParcel params, in IDataLoaderStatusListener listener, int createMode);
    int createLinkedStorage(in @utf8InCpp String path, int otherStorageId, int createMode);

    /**
+17 −8
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import android.content.pm.DataLoaderParams;
import android.content.pm.IDataLoaderStatusListener;
import android.content.pm.InstallationFile;
import android.text.TextUtils;
import android.util.Slog;
@@ -74,6 +75,7 @@ public final class IncrementalFileStorages {
    public static IncrementalFileStorages initialize(Context context,
            @NonNull File stageDir,
            @NonNull DataLoaderParams dataLoaderParams,
            @Nullable IDataLoaderStatusListener dataLoaderStatusListener,
            List<InstallationFile> addedFiles) throws IOException {
        // TODO(b/136132412): sanity check if session should not be incremental
        IncrementalManager incrementalManager = (IncrementalManager) context.getSystemService(
@@ -85,7 +87,13 @@ public final class IncrementalFileStorages {

        IncrementalFileStorages result = null;
        try {
            result = new IncrementalFileStorages(stageDir, incrementalManager, dataLoaderParams);
            result = new IncrementalFileStorages(stageDir, incrementalManager, dataLoaderParams,
                    dataLoaderStatusListener);

            if (!addedFiles.isEmpty()) {
                result.mDefaultStorage.bind(stageDir.getAbsolutePath());
            }

            for (InstallationFile file : addedFiles) {
                if (file.getLocation() == LOCATION_DATA_APP) {
                    try {
@@ -93,14 +101,15 @@ public final class IncrementalFileStorages {
                    } catch (IOException e) {
                        // TODO(b/146080380): add incremental-specific error code
                        throw new IOException(
                                "Failed to add and configure Incremental File: " + file.getName(),
                                e);
                                "Failed to add file to IncFS: " + file.getName() + ", reason: "
                                        + e.getMessage(), e.getCause());
                    }
                } else {
                    throw new IOException("Unknown file location: " + file.getLocation());
                }
            }

            // TODO(b/146080380): remove 5 secs wait in startLoading
            if (!result.mDefaultStorage.startLoading()) {
                // TODO(b/146080380): add incremental-specific error code
                throw new IOException("Failed to start loading data for Incremental installation.");
@@ -117,7 +126,8 @@ public final class IncrementalFileStorages {

    private IncrementalFileStorages(@NonNull File stageDir,
            @NonNull IncrementalManager incrementalManager,
            @NonNull DataLoaderParams dataLoaderParams) throws IOException {
            @NonNull DataLoaderParams dataLoaderParams,
            @Nullable IDataLoaderStatusListener dataLoaderStatusListener) throws IOException {
        mStageDir = stageDir;
        mIncrementalManager = incrementalManager;
        if (dataLoaderParams.getComponentName().getPackageName().equals("local")) {
@@ -134,6 +144,7 @@ public final class IncrementalFileStorages {
            }
            mDefaultStorage = mIncrementalManager.createStorage(mDefaultDir,
                    dataLoaderParams,
                    dataLoaderStatusListener,
                    IncrementalManager.CREATE_MODE_CREATE
                            | IncrementalManager.CREATE_MODE_TEMPORARY_BIND, false);
        }
@@ -144,10 +155,8 @@ public final class IncrementalFileStorages {
    }

    private void addApkFile(@NonNull InstallationFile apk) throws IOException {
        final String stageDirPath = mStageDir.getAbsolutePath();
        mDefaultStorage.bind(stageDirPath);
        String apkName = apk.getName();
        File targetFile = Paths.get(stageDirPath, apkName).toFile();
        final String apkName = apk.getName();
        final File targetFile = new File(mStageDir, apkName);
        if (!targetFile.exists()) {
            mDefaultStorage.makeFile(apkName, apk.getLengthBytes(), null, apk.getMetadata(),
                    apk.getSignature());
+4 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.Nullable;
import android.annotation.SystemService;
import android.content.Context;
import android.content.pm.DataLoaderParams;
import android.content.pm.IDataLoaderStatusListener;
import android.os.RemoteException;
import android.util.SparseArray;

@@ -103,10 +104,11 @@ public final class IncrementalManager {
     */
    @Nullable
    public IncrementalStorage createStorage(@NonNull String path,
            @NonNull DataLoaderParams params, @CreateMode int createMode,
            @NonNull DataLoaderParams params, @Nullable IDataLoaderStatusListener listener,
            @CreateMode int createMode,
            boolean autoStartDataLoader) {
        try {
            final int id = mService.createStorage(path, params.getData(), createMode);
            final int id = mService.createStorage(path, params.getData(), listener, createMode);
            if (id < 0) {
                return null;
            }
+1 −1
Original line number Diff line number Diff line
@@ -240,7 +240,7 @@ public abstract class DataLoaderService extends Service {
    private native boolean nativeDestroyDataLoader(int storageId);

    private native boolean nativePrepareImage(int storageId,
            Collection<InstallationFile> addedFiles, Collection<String> removedFiles);
            List<InstallationFile> addedFiles, List<String> removedFiles);

    private static native void nativeWriteData(long nativeInstance, String name, long offsetBytes,
            long lengthBytes, ParcelFileDescriptor incomingFd);
Loading