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

Commit 7460c591 authored by Philip P. Moltmann's avatar Philip P. Moltmann
Browse files

Revert "Revert session-transfer change"

This reverts commit 9890f8b4.

Bug: 64467704
Test: cts-tradefed run singleCommand cts-dev -m CtsContentTestCases --test=android.content.pm.cts.InstallSessionParamsUnitTest
      cts-tradefed run singleCommand cts-dev -m CtsContentTestCases --test=android.content.pm.cts.InstallSessionTransferTest
Change-Id: I0cc7e1129d85e4d0de16ade44232a9bd381d6c04
parent 7bec053d
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -10506,6 +10506,7 @@ package android.content.pm {
    method public java.io.OutputStream openWrite(java.lang.String, long, long) throws java.io.IOException;
    method public java.io.OutputStream openWrite(java.lang.String, long, long) throws java.io.IOException;
    method public void removeSplit(java.lang.String) throws java.io.IOException;
    method public void removeSplit(java.lang.String) throws java.io.IOException;
    method public void setStagingProgress(float);
    method public void setStagingProgress(float);
    method public void transfer(java.lang.String) throws android.content.pm.PackageManager.NameNotFoundException;
  }
  }
  public static abstract class PackageInstaller.SessionCallback {
  public static abstract class PackageInstaller.SessionCallback {
@@ -10523,10 +10524,16 @@ package android.content.pm {
    method public android.graphics.Bitmap getAppIcon();
    method public android.graphics.Bitmap getAppIcon();
    method public java.lang.CharSequence getAppLabel();
    method public java.lang.CharSequence getAppLabel();
    method public java.lang.String getAppPackageName();
    method public java.lang.String getAppPackageName();
    method public int getInstallLocation();
    method public int getInstallReason();
    method public int getInstallReason();
    method public java.lang.String getInstallerPackageName();
    method public java.lang.String getInstallerPackageName();
    method public int getMode();
    method public int getOriginatingUid();
    method public android.net.Uri getOriginatingUri();
    method public float getProgress();
    method public float getProgress();
    method public android.net.Uri getReferrerUri();
    method public int getSessionId();
    method public int getSessionId();
    method public long getSize();
    method public boolean isActive();
    method public boolean isActive();
    method public boolean isSealed();
    method public boolean isSealed();
    method public void writeToParcel(android.os.Parcel, int);
    method public void writeToParcel(android.os.Parcel, int);
+15 −0
Original line number Original line Diff line number Diff line
@@ -11180,12 +11180,14 @@ package android.content.pm {
    method public void abandon();
    method public void abandon();
    method public void close();
    method public void close();
    method public void commit(android.content.IntentSender);
    method public void commit(android.content.IntentSender);
    method public void commitTransferred(android.content.IntentSender);
    method public void fsync(java.io.OutputStream) throws java.io.IOException;
    method public void fsync(java.io.OutputStream) throws java.io.IOException;
    method public java.lang.String[] getNames() throws java.io.IOException;
    method public java.lang.String[] getNames() throws java.io.IOException;
    method public java.io.InputStream openRead(java.lang.String) throws java.io.IOException;
    method public java.io.InputStream openRead(java.lang.String) throws java.io.IOException;
    method public java.io.OutputStream openWrite(java.lang.String, long, long) throws java.io.IOException;
    method public java.io.OutputStream openWrite(java.lang.String, long, long) throws java.io.IOException;
    method public void removeSplit(java.lang.String) throws java.io.IOException;
    method public void removeSplit(java.lang.String) throws java.io.IOException;
    method public void setStagingProgress(float);
    method public void setStagingProgress(float);
    method public void transfer(java.lang.String) throws android.content.pm.PackageManager.NameNotFoundException;
  }
  }
  public static abstract class PackageInstaller.SessionCallback {
  public static abstract class PackageInstaller.SessionCallback {
@@ -11200,13 +11202,26 @@ package android.content.pm {
  public static class PackageInstaller.SessionInfo implements android.os.Parcelable {
  public static class PackageInstaller.SessionInfo implements android.os.Parcelable {
    method public android.content.Intent createDetailsIntent();
    method public android.content.Intent createDetailsIntent();
    method public int describeContents();
    method public int describeContents();
    method public boolean getAllocateAggressive();
    method public boolean getAllowDowngrade();
    method public android.graphics.Bitmap getAppIcon();
    method public android.graphics.Bitmap getAppIcon();
    method public java.lang.CharSequence getAppLabel();
    method public java.lang.CharSequence getAppLabel();
    method public java.lang.String getAppPackageName();
    method public java.lang.String getAppPackageName();
    method public boolean getDontKillApp();
    method public java.lang.String[] getGrantedRuntimePermissions();
    method public boolean getInstallAsFullApp(boolean);
    method public boolean getInstallAsInstantApp(boolean);
    method public boolean getInstallAsVirtualPreload();
    method public int getInstallLocation();
    method public int getInstallReason();
    method public int getInstallReason();
    method public java.lang.String getInstallerPackageName();
    method public java.lang.String getInstallerPackageName();
    method public int getMode();
    method public int getOriginatingUid();
    method public android.net.Uri getOriginatingUri();
    method public float getProgress();
    method public float getProgress();
    method public android.net.Uri getReferrerUri();
    method public int getSessionId();
    method public int getSessionId();
    method public long getSize();
    method public boolean isActive();
    method public boolean isActive();
    method public boolean isSealed();
    method public boolean isSealed();
    method public void writeToParcel(android.os.Parcel, int);
    method public void writeToParcel(android.os.Parcel, int);
+7 −0
Original line number Original line Diff line number Diff line
@@ -10544,6 +10544,7 @@ package android.content.pm {
    method public java.io.OutputStream openWrite(java.lang.String, long, long) throws java.io.IOException;
    method public java.io.OutputStream openWrite(java.lang.String, long, long) throws java.io.IOException;
    method public void removeSplit(java.lang.String) throws java.io.IOException;
    method public void removeSplit(java.lang.String) throws java.io.IOException;
    method public void setStagingProgress(float);
    method public void setStagingProgress(float);
    method public void transfer(java.lang.String) throws android.content.pm.PackageManager.NameNotFoundException;
  }
  }
  public static abstract class PackageInstaller.SessionCallback {
  public static abstract class PackageInstaller.SessionCallback {
@@ -10561,10 +10562,16 @@ package android.content.pm {
    method public android.graphics.Bitmap getAppIcon();
    method public android.graphics.Bitmap getAppIcon();
    method public java.lang.CharSequence getAppLabel();
    method public java.lang.CharSequence getAppLabel();
    method public java.lang.String getAppPackageName();
    method public java.lang.String getAppPackageName();
    method public int getInstallLocation();
    method public int getInstallReason();
    method public int getInstallReason();
    method public java.lang.String getInstallerPackageName();
    method public java.lang.String getInstallerPackageName();
    method public int getMode();
    method public int getOriginatingUid();
    method public android.net.Uri getOriginatingUri();
    method public float getProgress();
    method public float getProgress();
    method public android.net.Uri getReferrerUri();
    method public int getSessionId();
    method public int getSessionId();
    method public long getSize();
    method public boolean isActive();
    method public boolean isActive();
    method public boolean isSealed();
    method public boolean isSealed();
    method public void writeToParcel(android.os.Parcel, int);
    method public void writeToParcel(android.os.Parcel, int);
+2 −1
Original line number Original line Diff line number Diff line
@@ -32,6 +32,7 @@ interface IPackageInstallerSession {
    void removeSplit(String splitName);
    void removeSplit(String splitName);


    void close();
    void close();
    void commit(in IntentSender statusReceiver);
    void commit(in IntentSender statusReceiver, boolean forTransferred);
    void transfer(in String packageName);
    void abandon();
    void abandon();
}
}
+235 −2
Original line number Original line Diff line number Diff line
@@ -38,6 +38,7 @@ import android.os.Message;
import android.os.Parcel;
import android.os.Parcel;
import android.os.ParcelFileDescriptor;
import android.os.ParcelFileDescriptor;
import android.os.Parcelable;
import android.os.Parcelable;
import android.os.ParcelableException;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.SystemProperties;
import android.system.ErrnoException;
import android.system.ErrnoException;
@@ -793,7 +794,7 @@ public class PackageInstaller {
         * @throws IOException if trouble opening the file for writing, such as
         * @throws IOException if trouble opening the file for writing, such as
         *             lack of disk space or unavailable media.
         *             lack of disk space or unavailable media.
         * @throws SecurityException if called after the session has been
         * @throws SecurityException if called after the session has been
         *             committed or abandoned.
         *             sealed or abandoned
         */
         */
        public @NonNull OutputStream openWrite(@NonNull String name, long offsetBytes,
        public @NonNull OutputStream openWrite(@NonNull String name, long offsetBytes,
                long lengthBytes) throws IOException {
                long lengthBytes) throws IOException {
@@ -918,7 +919,68 @@ public class PackageInstaller {
         */
         */
        public void commit(@NonNull IntentSender statusReceiver) {
        public void commit(@NonNull IntentSender statusReceiver) {
            try {
            try {
                mSession.commit(statusReceiver);
                mSession.commit(statusReceiver, false);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }

        /**
         * Attempt to commit a session that has been {@link #transfer(String) transferred}.
         *
         * <p>If the device reboots before the session has been finalized, you may commit the
         * session again.
         *
         * <p>The caller of this method is responsible to ensure the safety of the session. As the
         * session was created by another - usually less trusted - app, it is paramount that before
         * committing <u>all</u> public and system {@link SessionInfo properties of the session}
         * and <u>all</u> {@link #openRead(String) APKs} are verified by the caller. It might happen
         * that new properties are added to the session with a new API revision. In this case the
         * callers need to be updated.
         *
         * @param statusReceiver Callbacks called when the state of the session changes.
         *
         * @hide
         */
        @SystemApi
        @RequiresPermission(android.Manifest.permission.INSTALL_PACKAGES)
        public void commitTransferred(@NonNull IntentSender statusReceiver) {
            try {
                mSession.commit(statusReceiver, true);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }

        /**
         * Transfer the session to a new owner.
         * <p>
         * Only sessions that update the installing app can be transferred.
         * <p>
         * After the transfer to a package with a different uid all method calls on the session
         * will cause {@link SecurityException}s.
         * <p>
         * Once this method is called, the session is sealed and no additional mutations beside
         * committing it may be performed on the session.
         *
         * @param packageName The package of the new owner. Needs to hold the INSTALL_PACKAGES
         *                    permission.
         *
         * @throws PackageManager.NameNotFoundException if the new owner could not be found.
         * @throws SecurityException if called after the session has been committed or abandoned.
         * @throws SecurityException if the session does not update the original installer
         * @throws SecurityException if streams opened through
         *                           {@link #openWrite(String, long, long) are still open.
         */
        public void transfer(@NonNull String packageName)
                throws PackageManager.NameNotFoundException {
            Preconditions.checkNotNull(packageName);

            try {
                mSession.transfer(packageName);
            } catch (ParcelableException e) {
                e.maybeRethrow(PackageManager.NameNotFoundException.class);
                throw new RuntimeException(e);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
                throw e.rethrowFromSystemServer();
            }
            }
@@ -1040,6 +1102,26 @@ public class PackageInstaller {
            grantedRuntimePermissions = source.readStringArray();
            grantedRuntimePermissions = source.readStringArray();
        }
        }


        /**
         * Check if there are hidden options set.
         *
         * <p>Hidden options are those options that cannot be verified via public or system-api
         * methods on {@link SessionInfo}.
         *
         * @return {@code true} if any hidden option is set.
         *
         * @hide
         */
        public boolean areHiddenOptionsSet() {
            return (installFlags & (PackageManager.INSTALL_ALLOW_DOWNGRADE
                    | PackageManager.INSTALL_DONT_KILL_APP
                    | PackageManager.INSTALL_INSTANT_APP
                    | PackageManager.INSTALL_FULL_APP
                    | PackageManager.INSTALL_VIRTUAL_PRELOAD
                    | PackageManager.INSTALL_ALLOCATE_AGGRESSIVE)) != installFlags
                    || abiOverride != null || volumeUuid != null;
        }

        /**
        /**
         * Provide value of {@link PackageInfo#installLocation}, which may be used
         * Provide value of {@link PackageInfo#installLocation}, which may be used
         * to determine where the app will be staged. Defaults to
         * to determine where the app will be staged. Defaults to
@@ -1299,6 +1381,19 @@ public class PackageInstaller {
        /** {@hide} */
        /** {@hide} */
        public CharSequence appLabel;
        public CharSequence appLabel;


        /** {@hide} */
        public int installLocation;
        /** {@hide} */
        public Uri originatingUri;
        /** {@hide} */
        public int originatingUid;
        /** {@hide} */
        public Uri referrerUri;
        /** {@hide} */
        public String[] grantedRuntimePermissions;
        /** {@hide} */
        public int installFlags;

        /** {@hide} */
        /** {@hide} */
        public SessionInfo() {
        public SessionInfo() {
        }
        }
@@ -1318,6 +1413,13 @@ public class PackageInstaller {
            appPackageName = source.readString();
            appPackageName = source.readString();
            appIcon = source.readParcelable(null);
            appIcon = source.readParcelable(null);
            appLabel = source.readString();
            appLabel = source.readString();

            installLocation = source.readInt();
            originatingUri = source.readParcelable(null);
            originatingUid = source.readInt();
            referrerUri = source.readParcelable(null);
            grantedRuntimePermissions = source.readStringArray();
            installFlags = source.readInt();
        }
        }


        /**
        /**
@@ -1441,6 +1543,130 @@ public class PackageInstaller {
            return intent;
            return intent;
        }
        }


        /**
         * Get the mode of the session as set in the constructor of the {@link SessionParams}.
         *
         * @return One of {@link SessionParams#MODE_FULL_INSTALL}
         *         or {@link SessionParams#MODE_INHERIT_EXISTING}
         */
        public int getMode() {
            return mode;
        }

        /**
         * Get the value set in {@link SessionParams#setInstallLocation(int)}.
         */
        public int getInstallLocation() {
            return installLocation;
        }

        /**
         * Get the value as set in {@link SessionParams#setSize(long)}.
         *
         * <p>The value is a hint and does not have to match the actual size.
         */
        public long getSize() {
            return sizeBytes;
        }

        /**
         * Get the value set in {@link SessionParams#setOriginatingUri(Uri)}.
         */
        public @Nullable Uri getOriginatingUri() {
            return originatingUri;
        }

        /**
         * Get the value set in {@link SessionParams#setOriginatingUid(int)}.
         */
        public int getOriginatingUid() {
            return originatingUid;
        }

        /**
         * Get the value set in {@link SessionParams#setReferrerUri(Uri)}
         */
        public @Nullable Uri getReferrerUri() {
            return referrerUri;
        }

        /**
         * Get the value set in {@link SessionParams#setGrantedRuntimePermissions(String[])}.
         *
         * @hide
         */
        @SystemApi
        public @Nullable String[] getGrantedRuntimePermissions() {
            return grantedRuntimePermissions;
        }

        /**
         * Get the value set in {@link SessionParams#setAllowDowngrade(boolean)}.
         *
         * @hide
         */
        @SystemApi
        public boolean getAllowDowngrade() {
            return (installFlags & PackageManager.INSTALL_ALLOW_DOWNGRADE) != 0;
        }

        /**
         * Get the value set in {@link SessionParams#setDontKillApp(boolean)}.
         *
         * @hide
         */
        @SystemApi
        public boolean getDontKillApp() {
            return (installFlags & PackageManager.INSTALL_DONT_KILL_APP) != 0;
        }

        /**
         * If {@link SessionParams#setInstallAsInstantApp(boolean)} was called with {@code true},
         * return true. If it was called with {@code false} or if it was not called return false.
         *
         * @hide
         *
         * @see #getInstallAsFullApp
         */
        @SystemApi
        public boolean getInstallAsInstantApp(boolean isInstantApp) {
            return (installFlags & PackageManager.INSTALL_INSTANT_APP) != 0;
        }

        /**
         * If {@link SessionParams#setInstallAsInstantApp(boolean)} was called with {@code false},
         * return true. If it was called with {@code true} or if it was not called return false.
         *
         * @hide
         *
         * @see #getInstallAsInstantApp
         */
        @SystemApi
        public boolean getInstallAsFullApp(boolean isInstantApp) {
            return (installFlags & PackageManager.INSTALL_FULL_APP) != 0;
        }

        /**
         * Get if {@link SessionParams#setInstallAsVirtualPreload()} was called.
         *
         * @hide
         */
        @SystemApi
        public boolean getInstallAsVirtualPreload() {
            return (installFlags & PackageManager.INSTALL_VIRTUAL_PRELOAD) != 0;
        }

        /**
         * Get the value set in {@link SessionParams#setAllocateAggressive(boolean)}.
         *
         * @hide
         */
        @SystemApi
        public boolean getAllocateAggressive() {
            return (installFlags & PackageManager.INSTALL_ALLOCATE_AGGRESSIVE) != 0;
        }


        /** {@hide} */
        /** {@hide} */
        @Deprecated
        @Deprecated
        public @Nullable Intent getDetailsIntent() {
        public @Nullable Intent getDetailsIntent() {
@@ -1467,6 +1693,13 @@ public class PackageInstaller {
            dest.writeString(appPackageName);
            dest.writeString(appPackageName);
            dest.writeParcelable(appIcon, flags);
            dest.writeParcelable(appIcon, flags);
            dest.writeString(appLabel != null ? appLabel.toString() : null);
            dest.writeString(appLabel != null ? appLabel.toString() : null);

            dest.writeInt(installLocation);
            dest.writeParcelable(originatingUri, flags);
            dest.writeInt(originatingUid);
            dest.writeParcelable(referrerUri, flags);
            dest.writeStringArray(grantedRuntimePermissions);
            dest.writeInt(installFlags);
        }
        }


        public static final Parcelable.Creator<SessionInfo>
        public static final Parcelable.Creator<SessionInfo>
Loading