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

Commit 4d487a40 authored by Jackal Guo's avatar Jackal Guo Committed by Android (Google) Code Review
Browse files

Merge changes from topic "update-ownership-enforcement"

* changes:
  Add adb command for requesting update ownership (3/n)
  Revise the logic of computing user intervention (2/n)
  Introduce the concept of the update owner (1/n)
parents 4751d357 688b46e3
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -88,6 +88,7 @@ package android {
    field public static final String DIAGNOSTIC = "android.permission.DIAGNOSTIC";
    field public static final String DISABLE_KEYGUARD = "android.permission.DISABLE_KEYGUARD";
    field public static final String DUMP = "android.permission.DUMP";
    field public static final String ENFORCE_UPDATE_OWNERSHIP = "android.permission.ENFORCE_UPDATE_OWNERSHIP";
    field public static final String EXPAND_STATUS_BAR = "android.permission.EXPAND_STATUS_BAR";
    field public static final String FACTORY_TEST = "android.permission.FACTORY_TEST";
    field public static final String FOREGROUND_SERVICE = "android.permission.FOREGROUND_SERVICE";
@@ -11691,6 +11692,7 @@ package android.content.pm {
    method @Nullable public String getInstallingPackageName();
    method @Nullable public String getOriginatingPackageName();
    method public int getPackageSource();
    method @Nullable public String getUpdateOwnerPackageName();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.content.pm.InstallSourceInfo> CREATOR;
  }
@@ -11981,6 +11983,7 @@ package android.content.pm {
    method public int getParentSessionId();
    method public boolean isKeepApplicationEnabledSetting();
    method public boolean isMultiPackage();
    method public boolean isRequestUpdateOwnership();
    method public boolean isStaged();
    method @NonNull public java.io.InputStream openRead(@NonNull String) throws java.io.IOException;
    method @NonNull public java.io.OutputStream openWrite(@NonNull String, long, long) throws java.io.IOException;
@@ -12036,6 +12039,7 @@ package android.content.pm {
    method public boolean isCommitted();
    method public boolean isKeepApplicationEnabledSetting();
    method public boolean isMultiPackage();
    method public boolean isRequestUpdateOwnership();
    method public boolean isSealed();
    method public boolean isStaged();
    method public boolean isStagedSessionActive();
@@ -12074,6 +12078,7 @@ package android.content.pm {
    method public void setOriginatingUri(@Nullable android.net.Uri);
    method public void setPackageSource(int);
    method public void setReferrerUri(@Nullable android.net.Uri);
    method @RequiresPermission(android.Manifest.permission.ENFORCE_UPDATE_OWNERSHIP) public void setRequestUpdateOwnership(boolean);
    method public void setRequireUserAction(int);
    method public void setSize(long);
    method public void setWhitelistedRestrictedPermissions(@Nullable java.util.Set<java.lang.String>);
+4 −0
Original line number Diff line number Diff line
@@ -3592,6 +3592,9 @@ package android.content.pm {
    field public static final int LOCATION_DATA_APP = 0; // 0x0
    field public static final int LOCATION_MEDIA_DATA = 2; // 0x2
    field public static final int LOCATION_MEDIA_OBB = 1; // 0x1
    field public static final int REASON_CONFIRM_PACKAGE_CHANGE = 0; // 0x0
    field public static final int REASON_OWNERSHIP_CHANGED = 1; // 0x1
    field public static final int REASON_REMIND_OWNERSHIP = 2; // 0x2
  }
  public static class PackageInstaller.InstallInfo {
@@ -3621,6 +3624,7 @@ package android.content.pm {
    method public boolean getInstallAsFullApp(boolean);
    method public boolean getInstallAsInstantApp(boolean);
    method public boolean getInstallAsVirtualPreload();
    method public int getPendingUserActionReason();
    method public boolean getRequestDowngrade();
    method public int getRollbackDataPolicy();
    method @NonNull public java.util.Set<java.lang.String> getWhitelistedRestrictedPermissions();
+1 −0
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ interface IPackageInstallerSession {
    void requestUserPreapproval(in PackageInstaller.PreapprovalDetails details, in IntentSender statusReceiver);

    boolean isKeepApplicationEnabledSetting();
    boolean isRequestUpdateOwnership();

    ParcelFileDescriptor getAppMetadataFd();
    ParcelFileDescriptor openWriteAppMetadata();
+23 −2
Original line number Diff line number Diff line
@@ -35,6 +35,8 @@ public final class InstallSourceInfo implements Parcelable {

    @Nullable private final String mInstallingPackageName;

    @Nullable private final String mUpdateOwnerPackageName;

    @Nullable private final int mPackageSource;

    /** @hide */
@@ -42,18 +44,20 @@ public final class InstallSourceInfo implements Parcelable {
            @Nullable SigningInfo initiatingPackageSigningInfo,
            @Nullable String originatingPackageName, @Nullable String installingPackageName) {
        this(initiatingPackageName, initiatingPackageSigningInfo, originatingPackageName,
                installingPackageName, PackageInstaller.PACKAGE_SOURCE_UNSPECIFIED);
                installingPackageName, null /* updateOwnerPackageName */,
                PackageInstaller.PACKAGE_SOURCE_UNSPECIFIED);
    }

    /** @hide */
    public InstallSourceInfo(@Nullable String initiatingPackageName,
            @Nullable SigningInfo initiatingPackageSigningInfo,
            @Nullable String originatingPackageName, @Nullable String installingPackageName,
            int packageSource) {
            @Nullable String updateOwnerPackageName, int packageSource) {
        mInitiatingPackageName = initiatingPackageName;
        mInitiatingPackageSigningInfo = initiatingPackageSigningInfo;
        mOriginatingPackageName = originatingPackageName;
        mInstallingPackageName = installingPackageName;
        mUpdateOwnerPackageName = updateOwnerPackageName;
        mPackageSource = packageSource;
    }

@@ -69,6 +73,7 @@ public final class InstallSourceInfo implements Parcelable {
        dest.writeParcelable(mInitiatingPackageSigningInfo, flags);
        dest.writeString(mOriginatingPackageName);
        dest.writeString(mInstallingPackageName);
        dest.writeString8(mUpdateOwnerPackageName);
        dest.writeInt(mPackageSource);
    }

@@ -77,6 +82,7 @@ public final class InstallSourceInfo implements Parcelable {
        mInitiatingPackageSigningInfo = source.readParcelable(SigningInfo.class.getClassLoader(), android.content.pm.SigningInfo.class);
        mOriginatingPackageName = source.readString();
        mInstallingPackageName = source.readString();
        mUpdateOwnerPackageName = source.readString8();
        mPackageSource = source.readInt();
    }

@@ -136,6 +142,21 @@ public final class InstallSourceInfo implements Parcelable {
        return mInstallingPackageName;
    }

    /**
     * The name of the package that is the update owner, or null if not available.
     *
     * This indicates the update ownership enforcement is enabled for this app,
     * and which package is the update owner.
     *
     * Returns null if the update ownership enforcement is disabled for the app.
     *
     * @see PackageInstaller.SessionParams#setRequestUpdateOwnership
     */
    @Nullable
    public String getUpdateOwnerPackageName() {
        return mUpdateOwnerPackageName;
    }

    /**
     * Information about the package source when installer installed this app.
     */
+114 −3
Original line number Diff line number Diff line
@@ -544,6 +544,46 @@ public class PackageInstaller {
    @Retention(RetentionPolicy.SOURCE)
    @interface PackageSourceType{}

    /**
     * Indicate the user intervention is required when the installer attempts to commit the session.
     * This is the default case.
     *
     * @hide
     */
    @SystemApi
    public static final int REASON_CONFIRM_PACKAGE_CHANGE = 0;

    /**
     * Indicate the user intervention is required because the update ownership enforcement is
     * enabled, and the update owner will change.
     *
     * @see PackageInstaller.SessionParams#setRequestUpdateOwnership
     * @see InstallSourceInfo#getUpdateOwnerPackageName
     * @hide
     */
    @SystemApi
    public static final int REASON_OWNERSHIP_CHANGED = 1;

    /**
     * Indicate the user intervention is required because the update ownership enforcement is
     * enabled, and remind the update owner will retain.
     *
     * @see PackageInstaller.SessionParams#setRequestUpdateOwnership
     * @see InstallSourceInfo#getUpdateOwnerPackageName
     * @hide
     */
    @SystemApi
    public static final int REASON_REMIND_OWNERSHIP = 2;

    /** @hide */
    @IntDef(prefix = { "REASON_" }, value = {
            REASON_CONFIRM_PACKAGE_CHANGE,
            REASON_OWNERSHIP_CHANGED,
            REASON_REMIND_OWNERSHIP,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface UserActionReason {}

    /** Default set of checksums - includes all available checksums.
     * @see Session#requestChecksums  */
    private static final int DEFAULT_CHECKSUMS =
@@ -1910,6 +1950,20 @@ public class PackageInstaller {
                throw e.rethrowFromSystemServer();
            }
        }

        /**
         * @return {@code true} if the installer requested the update ownership enforcement
         * for the packages in this session.
         *
         * @see PackageInstaller.SessionParams#setRequestUpdateOwnership
         */
        public boolean isRequestUpdateOwnership() {
            try {
                return mSession.isRequestUpdateOwnership();
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }
    }

    /**
@@ -2672,9 +2726,18 @@ public class PackageInstaller {
         *              Android S ({@link android.os.Build.VERSION_CODES#S API 31})</li>
         *          </ul>
         *     </li>
         *     <li>The installer is the {@link InstallSourceInfo#getInstallingPackageName()
         *     installer of record} of an existing version of the app (in other words, this install
         *     session is an app update) or the installer is updating itself.</li>
         *     <li>The installer is:
         *         <ul>
         *             <li>The {@link InstallSourceInfo#getUpdateOwnerPackageName() update owner}
         *             of an existing version of the app (in other words, this install session is
         *             an app update) if the update ownership enforcement is enabled.</li>
         *             <li>The {@link InstallSourceInfo#getInstallingPackageName() installer of
         *             record} of an existing version of the app (in other words, this install
         *             session is an app update) if the update ownership enforcement isn't
         *             enabled.</li>
         *             <li>Updating itself.</li>
         *         </ul>
         *     </li>>
         *     <li>The installer declares the
         *     {@link android.Manifest.permission#UPDATE_PACKAGES_WITHOUT_USER_ACTION
         *     UPDATE_PACKAGES_WITHOUT_USER_ACTION} permission.</li>
@@ -2713,6 +2776,30 @@ public class PackageInstaller {
            this.keepApplicationEnabledSetting = true;
        }

        /**
         * Optionally indicate whether the package being installed needs the update ownership
         * enforcement. Once the update ownership enforcement is enabled, the other installers
         * will need the user action to update the package even if the installers have been
         * granted the {@link android.Manifest.permission#INSTALL_PACKAGES INSTALL_PACKAGES}
         * permission. Default to {@code false}.
         *
         * The update ownership enforcement can only be enabled on initial installation. Set
         * this to {@code true} on package update indicates the installer package wants to be
         * the update owner if the update ownership enforcement has enabled.
         *
         * Note: To enable the update ownership enforcement, the installer must have the
         * {@link android.Manifest.permission#ENFORCE_UPDATE_OWNERSHIP ENFORCE_UPDATE_OWNERSHIP}
         * permission.
         */
        @RequiresPermission(Manifest.permission.ENFORCE_UPDATE_OWNERSHIP)
        public void setRequestUpdateOwnership(boolean enable) {
            if (enable) {
                this.installFlags |= PackageManager.INSTALL_REQUEST_UPDATE_OWNERSHIP;
            } else {
                this.installFlags &= ~PackageManager.INSTALL_REQUEST_UPDATE_OWNERSHIP;
            }
        }

        /** {@hide} */
        public void dump(IndentingPrintWriter pw) {
            pw.printPair("mode", mode);
@@ -2987,6 +3074,9 @@ public class PackageInstaller {
        /** @hide */
        public boolean keepApplicationEnabledSetting;

        /** @hide */
        public int pendingUserActionReason;

        /** {@hide} */
        @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
        public SessionInfo() {
@@ -3041,6 +3131,7 @@ public class PackageInstaller {
            installerUid = source.readInt();
            packageSource = source.readInt();
            keepApplicationEnabledSetting = source.readBoolean();
            pendingUserActionReason = source.readInt();
        }

        /**
@@ -3585,6 +3676,25 @@ public class PackageInstaller {
            return isPreapprovalRequested;
        }

        /**
         * @return {@code true} if the installer requested the update ownership enforcement
         * for the packages in this session.
         *
         * @see PackageInstaller.SessionParams#setRequestUpdateOwnership
         */
        public boolean isRequestUpdateOwnership() {
            return (installFlags & PackageManager.INSTALL_REQUEST_UPDATE_OWNERSHIP) != 0;
        }

        /**
         * Return the reason for requiring the user action.
         * @hide
         */
        @SystemApi
        public @UserActionReason int getPendingUserActionReason() {
            return pendingUserActionReason;
        }

        @Override
        public int describeContents() {
            return 0;
@@ -3635,6 +3745,7 @@ public class PackageInstaller {
            dest.writeInt(installerUid);
            dest.writeInt(packageSource);
            dest.writeBoolean(keepApplicationEnabledSetting);
            dest.writeInt(pendingUserActionReason);
        }

        public static final Parcelable.Creator<SessionInfo>
Loading