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

Commit 375ac151 authored by Jakob Schneider's avatar Jakob Schneider Committed by Android (Google) Code Review
Browse files

Merge "Add basic implementation of the requestUnarchive() API." into main

parents ba468dc2 5e679931
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -419,6 +419,14 @@ public class PowerExemptionManager {
     */
    public static final int REASON_SYSTEM_EXEMPT_APP_OP = 327;

    /**
     * Granted by {@link com.android.server.pm.PackageArchiverService} to the installer responsible
     * for unarchiving an app.
     *
     * @hide
     */
    public static final int REASON_PACKAGE_UNARCHIVE = 328;

    /** @hide The app requests out-out. */
    public static final int REASON_OPT_OUT_REQUESTED = 1000;

@@ -502,6 +510,7 @@ public class PowerExemptionManager {
            REASON_ACTIVE_DEVICE_ADMIN,
            REASON_MEDIA_NOTIFICATION_TRANSFER,
            REASON_PACKAGE_INSTALLER,
            REASON_PACKAGE_UNARCHIVE,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface ReasonCode {}
+4 −0
Original line number Diff line number Diff line
@@ -3547,6 +3547,7 @@ package android.content {
    field public static final String ACTION_SHOW_SUSPENDED_APP_DETAILS = "android.intent.action.SHOW_SUSPENDED_APP_DETAILS";
    field @Deprecated public static final String ACTION_SIM_STATE_CHANGED = "android.intent.action.SIM_STATE_CHANGED";
    field public static final String ACTION_SPLIT_CONFIGURATION_CHANGED = "android.intent.action.SPLIT_CONFIGURATION_CHANGED";
    field public static final String ACTION_UNARCHIVE_PACKAGE = "android.intent.action.UNARCHIVE_PACKAGE";
    field public static final String ACTION_UPGRADE_SETUP = "android.intent.action.UPGRADE_SETUP";
    field public static final String ACTION_USER_ADDED = "android.intent.action.USER_ADDED";
    field public static final String ACTION_USER_REMOVED = "android.intent.action.USER_REMOVED";
@@ -3796,6 +3797,9 @@ package android.content.pm {
  public class PackageArchiver {
    method @RequiresPermission(anyOf={android.Manifest.permission.DELETE_PACKAGES, android.Manifest.permission.REQUEST_DELETE_PACKAGES}) public void requestArchive(@NonNull String, @NonNull android.content.IntentSender) throws android.content.pm.PackageManager.NameNotFoundException;
    method @RequiresPermission(anyOf={android.Manifest.permission.INSTALL_PACKAGES, android.Manifest.permission.REQUEST_INSTALL_PACKAGES}) public void requestUnarchive(@NonNull String) throws android.content.pm.PackageManager.NameNotFoundException;
    field public static final String EXTRA_UNARCHIVE_ALL_USERS = "android.content.pm.extra.UNARCHIVE_ALL_USERS";
    field public static final String EXTRA_UNARCHIVE_PACKAGE_NAME = "android.content.pm.extra.UNARCHIVE_PACKAGE_NAME";
  }
  public class PackageInfo implements android.os.Parcelable {
+10 −0
Original line number Diff line number Diff line
@@ -5270,6 +5270,16 @@ public class Intent implements Parcelable, Cloneable {
    public static final String ACTION_SHOW_FOREGROUND_SERVICE_MANAGER =
            "android.intent.action.SHOW_FOREGROUND_SERVICE_MANAGER";
    /**
     * Broadcast Action: Sent to the responsible installer of an archived package when unarchival
     * is requested.
     *
     * @see android.content.pm.PackageArchiver
     * @hide
     */
    @SystemApi
    public static final String ACTION_UNARCHIVE_PACKAGE = "android.intent.action.UNARCHIVE_PACKAGE";
    // ---------------------------------------------------------------------
    // ---------------------------------------------------------------------
    // Standard intent categories (see addCategory()).
+3 −0
Original line number Diff line number Diff line
@@ -23,4 +23,7 @@ interface IPackageArchiverService {

    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(anyOf={android.Manifest.permission.DELETE_PACKAGES,android.Manifest.permission.REQUEST_DELETE_PACKAGES})")
    void requestArchive(String packageName, String callerPackageName, in IntentSender statusReceiver, in UserHandle userHandle);

    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(anyOf={android.Manifest.permission.INSTALL_PACKAGES,android.Manifest.permission.REQUEST_INSTALL_PACKAGES})")
    void requestUnarchive(String packageName, String callerPackageName, in UserHandle userHandle);
}
 No newline at end of file
+51 −1
Original line number Diff line number Diff line
@@ -42,6 +42,26 @@ import android.os.RemoteException;
@SystemApi
public class PackageArchiver {

    /**
     * Extra field for the package name of a package that is requested to be unarchived. Sent as
     * part of the {@link android.content.Intent#ACTION_UNARCHIVE_PACKAGE} intent.
     *
     * @hide
     */
    @SystemApi
    public static final String EXTRA_UNARCHIVE_PACKAGE_NAME =
            "android.content.pm.extra.UNARCHIVE_PACKAGE_NAME";

    /**
     * If true, the requestor of the unarchival has specified that the app should be unarchived
     * for {@link android.os.UserHandle#ALL}.
     *
     * @hide
     */
    @SystemApi
    public static final String EXTRA_UNARCHIVE_ALL_USERS =
            "android.content.pm.extra.UNARCHIVE_ALL_USERS";

    private final Context mContext;
    private final IPackageArchiverService mService;

@@ -58,7 +78,7 @@ public class PackageArchiver {
     *
     * @param statusReceiver Callback used to notify when the operation is completed.
     * @throws NameNotFoundException If {@code packageName} isn't found or not available to the
     *                               caller.
     *                               caller or isn't archived.
     * @hide
     */
    @RequiresPermission(anyOf = {
@@ -76,4 +96,34 @@ public class PackageArchiver {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Requests to unarchive a currently archived package.
     *
     * <p> Sends a request to unarchive an app to the responsible installer. The installer is
     * determined by {@link InstallSourceInfo#getUpdateOwnerPackageName()}, or
     * {@link InstallSourceInfo#getInstallingPackageName()} if the former value is null.
     *
     * <p> The installation will happen asynchronously and can be observed through
     * {@link android.content.Intent#ACTION_PACKAGE_ADDED}.
     *
     * @throws NameNotFoundException If {@code packageName} isn't found or not visible to the
     *                               caller or if the package has no installer on the device
     *                               anymore to unarchive it.
     * @hide
     */
    @RequiresPermission(anyOf = {
            Manifest.permission.INSTALL_PACKAGES,
            Manifest.permission.REQUEST_INSTALL_PACKAGES})
    @SystemApi
    public void requestUnarchive(@NonNull String packageName)
            throws NameNotFoundException {
        try {
            mService.requestUnarchive(packageName, mContext.getPackageName(), mContext.getUser());
        } catch (ParcelableException e) {
            e.maybeRethrow(NameNotFoundException.class);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
}
Loading