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

Commit 3a44f3f1 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Initial support for split APKs, PackageInstaller.

Defines a new PackageInstaller class that will be used for installing
and upgrading packages.  An application desiring to install an
application creates a session, stages one or more package files in
that session, and then kicks off the install.

Previously, PackageManager would always make its own copy of a package
before inspecting it, to ensure the data could be trusted.  This new
session concept allows the installer to write package data directly to
its final resting place on disk, reducing disk I/O and footprint
requirements.  Writes are directed through an intermediate pipe
to ensure we can prevent mutations once an install has been initiated.
Also uses fallocate() internally to support optimal ext4 block
allocation using extents to reduce fragmentation.

Sessions are also the way we support installing multiple "split" APKs
in a single atomic operation.  For a set of packages to form a valid
application, they must have exactly the same package name, version
code, and certificates.  A session can also be used to add a small
handful of splits to an application by inheriting existing packages
when not performing a full install.

Add PackageParser support for extracting split names and certificates.

Bug: 14975160
Change-Id: I23d1bf4fbeb9f99a8c83be0c458900a0f0d1bccc
parent 89b77cde
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -126,6 +126,8 @@ LOCAL_SRC_FILES += \
	core/java/android/content/pm/IPackageDeleteObserver.aidl \
	core/java/android/content/pm/IPackageInstallObserver.aidl \
	core/java/android/content/pm/IPackageInstallObserver2.aidl \
	core/java/android/content/pm/IPackageInstaller.aidl \
	core/java/android/content/pm/IPackageInstallerSession.aidl \
	core/java/android/content/pm/IPackageManager.aidl \
	core/java/android/content/pm/IPackageMoveObserver.aidl \
	core/java/android/content/pm/IPackageStatsObserver.aidl \
+14 −3
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.content.pm.IPackageMoveObserver;
import android.content.pm.IPackageStatsObserver;
import android.content.pm.InstrumentationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageManager;
import android.content.pm.ParceledListSlice;
import android.content.pm.PermissionGroupInfo;
@@ -1127,7 +1128,7 @@ final class ApplicationPackageManager extends PackageManager {
    public void installPackage(Uri packageURI, PackageInstallObserver observer,
            int flags, String installerPackageName) {
        try {
            mPM.installPackageEtc(packageURI, null, observer.mObserver,
            mPM.installPackageEtc(packageURI, null, observer.getBinder(),
                    flags, installerPackageName);
        } catch (RemoteException e) {
            // Should never happen!
@@ -1140,7 +1141,7 @@ final class ApplicationPackageManager extends PackageManager {
            Uri verificationURI, ManifestDigest manifestDigest,
            ContainerEncryptionParams encryptionParams) {
        try {
            mPM.installPackageWithVerificationEtc(packageURI, null, observer.mObserver, flags,
            mPM.installPackageWithVerificationEtc(packageURI, null, observer.getBinder(), flags,
                    installerPackageName, verificationURI, manifestDigest, encryptionParams);
        } catch (RemoteException e) {
            // Should never happen!
@@ -1153,7 +1154,7 @@ final class ApplicationPackageManager extends PackageManager {
            VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) {
        try {
            mPM.installPackageWithVerificationAndEncryptionEtc(packageURI, null,
                    observer.mObserver, flags, installerPackageName, verificationParams,
                    observer.getBinder(), flags, installerPackageName, verificationParams,
                    encryptionParams);
        } catch (RemoteException e) {
            // Should never happen!
@@ -1440,6 +1441,16 @@ final class ApplicationPackageManager extends PackageManager {
        return null;
    }

    @Override
    public PackageInstaller getPackageInstaller() {
        try {
            return new PackageInstaller(this, mPM.getPackageInstaller(), mContext.getUserId(),
                    mContext.getPackageName());
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
    }

    /**
     * @hide
     */
+22 −18
Original line number Diff line number Diff line
@@ -18,32 +18,36 @@ package android.app;

import android.content.pm.IPackageInstallObserver2;
import android.os.Bundle;
import android.os.RemoteException;

/**
 * @hide
 *
 * New-style observer for package installers to use.
 */
/** {@hide} */
public class PackageInstallObserver {
    IPackageInstallObserver2.Stub mObserver = new IPackageInstallObserver2.Stub() {
    private final IPackageInstallObserver2.Stub mBinder = new IPackageInstallObserver2.Stub() {
        @Override
        public void packageInstalled(String pkgName, Bundle extras, int result)
                throws RemoteException {
            PackageInstallObserver.this.packageInstalled(pkgName, extras, result);
        public void packageInstalled(String basePackageName, Bundle extras, int returnCode) {
            PackageInstallObserver.this.packageInstalled(basePackageName, extras, returnCode);
        }
    };

    /** {@hide} */
    public IPackageInstallObserver2.Stub getBinder() {
        return mBinder;
    }

    /**
     * This method will be called to report the result of the package installation attempt.
     * This method will be called to report the result of the package
     * installation attempt.
     *
     * @param pkgName Name of the package whose installation was attempted
     * @param extras If non-null, this Bundle contains extras providing additional information
     *        about an install failure.  See {@link android.content.pm.PackageManager} for
     *        documentation about which extras apply to various failures; in particular the
     *        strings named EXTRA_FAILURE_*.
     * @param result The numeric success or failure code indicating the basic outcome
     * @param basePackageName Name of the package whose installation was
     *            attempted
     * @param extras If non-null, this Bundle contains extras providing
     *            additional information about an install failure. See
     *            {@link android.content.pm.PackageManager} for documentation
     *            about which extras apply to various failures; in particular
     *            the strings named EXTRA_FAILURE_*.
     * @param returnCode The numeric success or failure code indicating the
     *            basic outcome
     * @hide
     */
    public void packageInstalled(String pkgName, Bundle extras, int result) {
    public void packageInstalled(String basePackageName, Bundle extras, int returnCode) {
    }
}
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.app;

import android.content.pm.IPackageDeleteObserver;

/** {@hide} */
public class PackageUninstallObserver {
    private final IPackageDeleteObserver.Stub mBinder = new IPackageDeleteObserver.Stub() {
        @Override
        public void packageDeleted(String basePackageName, int returnCode) {
            PackageUninstallObserver.this.onUninstallFinished(basePackageName, returnCode);
        }
    };

    /** {@hide} */
    public IPackageDeleteObserver.Stub getBinder() {
        return mBinder;
    }

    public void onUninstallFinished(String basePackageName, int returnCode) {
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -32,9 +32,11 @@ import javax.crypto.spec.IvParameterSpec;
/**
 * Represents encryption parameters used to read a container.
 *
 * @deprecated encrypted containers are legacy.
 * @hide
 */
@PrivateApi
@Deprecated
public class ContainerEncryptionParams implements Parcelable {
    protected static final String TAG = "ContainerEncryptionParams";

Loading