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

Commit 03340735 authored by Christopher Tate's avatar Christopher Tate Committed by Android Git Automerger
Browse files

am 5454ac6b: Merge "Expand install observer semantics"

* commit '5454ac6b':
  Expand install observer semantics
parents 904f3ec8 5454ac6b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -120,6 +120,7 @@ LOCAL_SRC_FILES += \
	core/java/android/content/pm/IPackageDataObserver.aidl \
	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/IPackageManager.aidl \
	core/java/android/content/pm/IPackageMoveObserver.aidl \
	core/java/android/content/pm/IPackageStatsObserver.aidl \
+27 −7
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import android.content.pm.ContainerEncryptionParams;
import android.content.pm.FeatureInfo;
import android.content.pm.IPackageDataObserver;
import android.content.pm.IPackageDeleteObserver;
import android.content.pm.IPackageInstallObserver;
import android.content.pm.IPackageInstallObserver2;
import android.content.pm.IPackageManager;
import android.content.pm.InstrumentationInfo;
import android.content.pm.PackageInfo;
@@ -39,6 +39,7 @@ import android.content.pm.VerificationParams;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.os.IUserManager;
import android.os.Process;
import android.os.RemoteException;
@@ -700,14 +701,23 @@ public final class Pm {
        ActivityManager.dumpPackageStateStatic(FileDescriptor.out, pkg);
    }

    class PackageInstallObserver extends IPackageInstallObserver.Stub {
    class PackageInstallObserver extends IPackageInstallObserver2.Stub {
        boolean finished;
        int result;
        String extraPermission;
        String extraPackage;

        public void packageInstalled(String name, int status) {
        @Override
        public void packageInstalled(String name, Bundle extras, int status) {
            synchronized( this) {
                finished = true;
                result = status;
                if (status == PackageManager.INSTALL_FAILED_DUPLICATE_PERMISSION) {
                    extraPermission = extras.getString(
                            PackageManager.EXTRA_FAILURE_EXISTING_PERMISSION);
                    extraPackage = extras.getString(
                            PackageManager.EXTRA_FAILURE_EXISTING_PACKAGE);
                }
                notifyAll();
            }
        }
@@ -717,7 +727,8 @@ public final class Pm {
     * Converts a failure code into a string by using reflection to find a matching constant
     * in PackageManager.
     */
    private String installFailureToString(int result) {
    private String installFailureToString(PackageInstallObserver obs) {
        final int result = obs.result;
        Field[] fields = PackageManager.class.getFields();
        for (Field f: fields) {
            if (f.getType() == int.class) {
@@ -732,7 +743,16 @@ public final class Pm {
                        // get the int value and compare it to result.
                        try {
                            if (result == f.getInt(null)) {
                                return fieldName;
                                StringBuilder sb = new StringBuilder(64);
                                sb.append(fieldName);
                                if (obs.extraPermission != null) {
                                    sb.append(" perm=");
                                    sb.append(obs.extraPermission);
                                }
                                if (obs.extraPackage != null) {
                                    sb.append(" pkg=" + obs.extraPackage);
                                }
                                return sb.toString();
                            }
                        } catch (IllegalAccessException e) {
                            // this shouldn't happen since we only look for public static fields.
@@ -956,7 +976,7 @@ public final class Pm {
            VerificationParams verificationParams = new VerificationParams(verificationURI,
                    originatingURI, referrerURI, VerificationParams.NO_UID, null);

            mPm.installPackageWithVerificationAndEncryption(apkURI, obs, installFlags,
            mPm.installPackageWithVerificationAndEncryptionEtc(apkURI, null, obs, installFlags,
                    installerPackageName, verificationParams, encryptionParams);

            synchronized (obs) {
@@ -970,7 +990,7 @@ public final class Pm {
                    System.out.println("Success");
                } else {
                    System.err.println("Failure ["
                            + installFailureToString(obs.result)
                            + installFailureToString(obs)
                            + "]");
                }
            }
+44 −5
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.content.pm.FeatureInfo;
import android.content.pm.IPackageDataObserver;
import android.content.pm.IPackageDeleteObserver;
import android.content.pm.IPackageInstallObserver;
import android.content.pm.IPackageInstallObserver2;
import android.content.pm.IPackageManager;
import android.content.pm.IPackageMoveObserver;
import android.content.pm.IPackageStatsObserver;
@@ -1073,7 +1074,7 @@ final class ApplicationPackageManager extends PackageManager {
    public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags,
                               String installerPackageName) {
        try {
            mPM.installPackage(packageURI, observer, flags, installerPackageName);
            mPM.installPackageEtc(packageURI, observer, null, flags, installerPackageName);
        } catch (RemoteException e) {
            // Should never happen!
        }
@@ -1084,8 +1085,8 @@ final class ApplicationPackageManager extends PackageManager {
            int flags, String installerPackageName, Uri verificationURI,
            ManifestDigest manifestDigest, ContainerEncryptionParams encryptionParams) {
        try {
            mPM.installPackageWithVerification(packageURI, observer, flags, installerPackageName,
                    verificationURI, manifestDigest, encryptionParams);
            mPM.installPackageWithVerificationEtc(packageURI, observer, null, flags,
                    installerPackageName, verificationURI, manifestDigest, encryptionParams);
        } catch (RemoteException e) {
            // Should never happen!
        }
@@ -1096,8 +1097,46 @@ final class ApplicationPackageManager extends PackageManager {
            IPackageInstallObserver observer, int flags, String installerPackageName,
            VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) {
        try {
            mPM.installPackageWithVerificationAndEncryption(packageURI, observer, flags,
                    installerPackageName, verificationParams, encryptionParams);
            mPM.installPackageWithVerificationAndEncryptionEtc(packageURI, observer, null,
                    flags, installerPackageName, verificationParams, encryptionParams);
        } catch (RemoteException e) {
            // Should never happen!
        }
    }

    // Expanded observer-API versions
    @Override
    public void installPackage(Uri packageURI, PackageInstallObserver observer,
            int flags, String installerPackageName) {
        try {
            mPM.installPackageEtc(packageURI, null, observer.mObserver,
                    flags, installerPackageName);
        } catch (RemoteException e) {
            // Should never happen!
        }
    }

    @Override
    public void installPackageWithVerification(Uri packageURI,
            PackageInstallObserver observer, int flags, String installerPackageName,
            Uri verificationURI, ManifestDigest manifestDigest,
            ContainerEncryptionParams encryptionParams) {
        try {
            mPM.installPackageWithVerificationEtc(packageURI, null, observer.mObserver, flags,
                    installerPackageName, verificationURI, manifestDigest, encryptionParams);
        } catch (RemoteException e) {
            // Should never happen!
        }
    }

    @Override
    public void installPackageWithVerificationAndEncryption(Uri packageURI,
            PackageInstallObserver observer, int flags, String installerPackageName,
            VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) {
        try {
            mPM.installPackageWithVerificationAndEncryptionEtc(packageURI, null,
                    observer.mObserver, flags, installerPackageName, verificationParams,
                    encryptionParams);
        } catch (RemoteException e) {
            // Should never happen!
        }
+49 −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.IPackageInstallObserver2;
import android.os.Bundle;
import android.os.RemoteException;

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

    /**
     * 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
     */
    public void packageInstalled(String pkgName, Bundle extras, int result) {
    }
}
+45 −0
Original line number Diff line number Diff line
/*
**
** Copyright 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.content.pm;

import android.os.Bundle;

/**
 * API for installation callbacks from the Package Manager.  In certain result cases
 * additional information will be provided.
 * @hide
 */
oneway interface IPackageInstallObserver2 {
    /**
     * The install operation has completed.  {@code returnCode} holds a numeric code
     * indicating success or failure.  In certain cases the {@code extras} Bundle will
     * contain additional details:
     *
     * <p><table>
     * <tr>
     *   <td>INSTALL_FAILED_DUPLICATE_PERMISSION</td>
     *   <td>Two strings are provided in the extras bundle: EXTRA_EXISTING_PERMISSION
     *       is the name of the permission that the app is attempting to define, and
     *       EXTRA_EXISTING_PACKAGE is the package name of the app which has already
     *       defined the permission.</td>
     * </tr>
     * </table>
     */
    void packageInstalled(in String packageName, in Bundle extras, int returnCode);
}
Loading