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

Commit d1b5cfc9 authored by rich cannings's avatar rich cannings
Browse files

Notify verifiers that verification is complete

Send the Intent.ACTION_PACKAGE_VERIFIED to all verifiers when
verification is complete (either one verifier verified the package or a
timeout occurred). Details of what occurred is in a new extra,
PackageManager.EXTRA_VERIFICATION_RESULT.

Bug: 7048930
Change-Id: I4f9855a29b0eb6d77f469891402c69e2e8922945
parent 0fa814d7
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -5758,6 +5758,7 @@ package android.content {
    field public static final java.lang.String ACTION_PACKAGE_REMOVED = "android.intent.action.PACKAGE_REMOVED";
    field public static final java.lang.String ACTION_PACKAGE_REPLACED = "android.intent.action.PACKAGE_REPLACED";
    field public static final java.lang.String ACTION_PACKAGE_RESTARTED = "android.intent.action.PACKAGE_RESTARTED";
    field public static final java.lang.String ACTION_PACKAGE_VERIFIED = "android.intent.action.PACKAGE_VERIFIED";
    field public static final java.lang.String ACTION_PASTE = "android.intent.action.PASTE";
    field public static final java.lang.String ACTION_PICK = "android.intent.action.PICK";
    field public static final java.lang.String ACTION_PICK_ACTIVITY = "android.intent.action.PICK_ACTIVITY";
@@ -6550,6 +6551,7 @@ package android.content.pm {
    field public static final int COMPONENT_ENABLED_STATE_ENABLED = 1; // 0x1
    field public static final int DONT_KILL_APP = 1; // 0x1
    field public static final java.lang.String EXTRA_VERIFICATION_ID = "android.content.pm.extra.VERIFICATION_ID";
    field public static final java.lang.String EXTRA_VERIFICATION_RESULT = "android.content.pm.extra.VERIFICATION_RESULT";
    field public static final java.lang.String FEATURE_AUDIO_LOW_LATENCY = "android.hardware.audio.low_latency";
    field public static final java.lang.String FEATURE_BLUETOOTH = "android.hardware.bluetooth";
    field public static final java.lang.String FEATURE_CAMERA = "android.hardware.camera";
+9 −0
Original line number Diff line number Diff line
@@ -1640,6 +1640,15 @@ public class Intent implements Parcelable, Cloneable {
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_PACKAGE_NEEDS_VERIFICATION = "android.intent.action.PACKAGE_NEEDS_VERIFICATION";

    /**
     * Broadcast Action: Sent to the system package verifier when a package is
     * verified. The data contains the package URI.
     * <p class="note">
     * This is a protected intent that can only be sent by the system.
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_PACKAGE_VERIFIED = "android.intent.action.PACKAGE_VERIFIED";

    /**
     * Broadcast Action: Resources for a set of packages (which were
     * previously unavailable) are currently
+17 −2
Original line number Diff line number Diff line
@@ -1150,6 +1150,14 @@ public abstract class PackageManager {
    public static final String EXTRA_VERIFICATION_INSTALL_FLAGS
            = "android.content.pm.extra.VERIFICATION_INSTALL_FLAGS";

    /**
     * Extra field name for the result of a verification, either
     * {@link #VERIFICATION_ALLOW}, or {@link #VERIFICATION_REJECT}.
     * Passed to package verifiers after a package is verified.
     */
    public static final String EXTRA_VERIFICATION_RESULT
            = "android.content.pm.extra.VERIFICATION_RESULT";

    /**
     * Retrieve overall information about an application package that is
     * installed on the system.
@@ -2341,12 +2349,19 @@ public abstract class PackageManager {
     *            {@link PackageManager#EXTRA_VERIFICATION_ID} Intent extra
     * @param verificationCodeAtTimeout either
     *            {@link PackageManager#VERIFICATION_ALLOW} or
     *            {@link PackageManager#VERIFICATION_REJECT}. If
     *            {@code verificationCodeAtTimeout} is neither
     *            {@link PackageManager#VERIFICATION_ALLOW} or
     *            {@link PackageManager#VERIFICATION_REJECT}, then
     *            {@code verificationCodeAtTimeout} will default to
     *            {@link PackageManager#VERIFICATION_REJECT}.
     * @param millisecondsToDelay the amount of time requested for the timeout.
     *            Must be positive and less than
     *            {@link PackageManager#MAXIMUM_VERIFICATION_TIMEOUT}. If
     *            {@code millisecondsToDelay} is out of bounds,
     *            {@code millisecondsToDelay} will be set to the closest in
     *            bounds value; namely, 0 or
     *            {@link PackageManager#MAXIMUM_VERIFICATION_TIMEOUT}.
     * @throws IllegalArgumentException if {@code millisecondsToDelay} is out
     *            of bounds or {@code verificationCodeAtTimeout} is unknown.
     * @throws SecurityException if the caller does not have the
     *            {@link android.Manifest.permission#PACKAGE_VERIFICATION_AGENT}
     *            permission.
+1 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@
    <protected-broadcast android:name="android.intent.action.PACKAGE_DATA_CLEARED" />
    <protected-broadcast android:name="android.intent.action.PACKAGE_FIRST_LAUNCH" />
    <protected-broadcast android:name="android.intent.action.PACKAGE_NEEDS_VERIFICATION" />
    <protected-broadcast android:name="android.intent.action.PACKAGE_VERIFIED" />
    <protected-broadcast android:name="android.intent.action.UID_REMOVED" />
    <protected-broadcast android:name="android.intent.action.CONFIGURATION_CHANGED" />
    <protected-broadcast android:name="android.intent.action.LOCALE_CHANGED" />
+25 −5
Original line number Diff line number Diff line
@@ -851,11 +851,16 @@ public class PackageManagerService extends IPackageManager.Stub {
                                    + args.packageURI.toString());
                            state.setVerifierResponse(Binder.getCallingUid(),
                                    PackageManager.VERIFICATION_ALLOW_WITHOUT_SUFFICIENT);
                            broadcastPackageVerified(verificationId, args.packageURI,
                                    PackageManager.VERIFICATION_ALLOW);
                            try {
                                ret = args.copyApk(mContainerService, true);
                            } catch (RemoteException e) {
                                Slog.e(TAG, "Could not contact the ContainerService");
                            }
                        } else {
                            broadcastPackageVerified(verificationId, args.packageURI,
                                    PackageManager.VERIFICATION_REJECT);
                        }

                        processPendingInstall(args, ret);
@@ -884,6 +889,8 @@ public class PackageManagerService extends IPackageManager.Stub {
                        int ret;
                        if (state.isInstallAllowed()) {
                            ret = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
                            broadcastPackageVerified(verificationId, args.packageURI,
                                    response.code);
                            try {
                                ret = args.copyApk(mContainerService, true);
                            } catch (RemoteException e) {
@@ -5602,13 +5609,15 @@ public class PackageManagerService extends IPackageManager.Stub {
        final PackageVerificationResponse response = new PackageVerificationResponse(
                verificationCodeAtTimeout, Binder.getCallingUid());

        if ((millisecondsToDelay > PackageManager.MAXIMUM_VERIFICATION_TIMEOUT)
                || (millisecondsToDelay < 0)) {
            throw new IllegalArgumentException("millisecondsToDelay is out of bounds.");
        if (millisecondsToDelay > PackageManager.MAXIMUM_VERIFICATION_TIMEOUT) {
            millisecondsToDelay = PackageManager.MAXIMUM_VERIFICATION_TIMEOUT;
        }
        if (millisecondsToDelay < 0) {
            millisecondsToDelay = 0;
        }
        if ((verificationCodeAtTimeout != PackageManager.VERIFICATION_ALLOW)
              || (verificationCodeAtTimeout != PackageManager.VERIFICATION_REJECT)) {
            throw new IllegalArgumentException("verificationCodeAtTimeout is unknown.");
                && (verificationCodeAtTimeout != PackageManager.VERIFICATION_REJECT)) {
            verificationCodeAtTimeout = PackageManager.VERIFICATION_REJECT;
        }

        if ((state != null) && !state.timeoutExtended()) {
@@ -5621,6 +5630,17 @@ public class PackageManagerService extends IPackageManager.Stub {
        }
    }

    private void broadcastPackageVerified(int verificationId, Uri packageUri,
            int verificationCode) {
        final Intent intent = new Intent(Intent.ACTION_PACKAGE_VERIFIED);
        intent.setDataAndType(packageUri, PACKAGE_MIME_TYPE);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.putExtra(PackageManager.EXTRA_VERIFICATION_ID, verificationId);
        intent.putExtra(PackageManager.EXTRA_VERIFICATION_RESULT, verificationCode);

        mContext.sendBroadcast(intent, android.Manifest.permission.PACKAGE_VERIFICATION_AGENT);
    }

    private ComponentName matchComponentForVerifier(String packageName,
            List<ResolveInfo> receivers) {
        ActivityInfo targetReceiver = null;