Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.content.pm; |
| 18 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 19 | import android.Manifest; |
Dario Freni | 71eee5e | 2018-12-06 15:47:16 +0000 | [diff] [blame] | 20 | import android.annotation.IntDef; |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 21 | import android.annotation.NonNull; |
| 22 | import android.annotation.Nullable; |
Svet Ganov | 7121e18 | 2015-07-13 22:38:12 -0700 | [diff] [blame] | 23 | import android.annotation.RequiresPermission; |
Jeff Sharkey | 1cb2d0d | 2014-07-30 16:45:01 -0700 | [diff] [blame] | 24 | import android.annotation.SdkConstant; |
| 25 | import android.annotation.SdkConstant.SdkConstantType; |
Svet Ganov | 7121e18 | 2015-07-13 22:38:12 -0700 | [diff] [blame] | 26 | import android.annotation.SystemApi; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 27 | import android.annotation.UnsupportedAppUsage; |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 28 | import android.app.ActivityManager; |
Jeff Sharkey | da1247a | 2017-06-08 14:13:29 -0600 | [diff] [blame] | 29 | import android.app.AppGlobals; |
Jeff Sharkey | fbd0e9f | 2014-08-06 16:34:34 -0700 | [diff] [blame] | 30 | import android.content.Intent; |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 31 | import android.content.IntentSender; |
Todd Kennedy | cda831f | 2017-05-16 10:54:33 -0700 | [diff] [blame] | 32 | import android.content.pm.PackageManager.DeleteFlags; |
Bartosz Fabianowski | 40a0062 | 2017-04-18 14:39:23 +0200 | [diff] [blame] | 33 | import android.content.pm.PackageManager.InstallReason; |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 34 | import android.graphics.Bitmap; |
| 35 | import android.net.Uri; |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 36 | import android.os.Build; |
Jeff Sharkey | 78cc340 | 2014-05-22 10:52:49 -0700 | [diff] [blame] | 37 | import android.os.FileBridge; |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 38 | import android.os.Handler; |
| 39 | import android.os.Looper; |
| 40 | import android.os.Message; |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 41 | import android.os.Parcel; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 42 | import android.os.ParcelFileDescriptor; |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 43 | import android.os.Parcelable; |
Philip P. Moltmann | 7460c59 | 2017-08-08 20:07:11 +0000 | [diff] [blame] | 44 | import android.os.ParcelableException; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 45 | import android.os.RemoteException; |
Jeff Sharkey | 02d4e34 | 2017-03-10 21:53:48 -0700 | [diff] [blame] | 46 | import android.os.SystemProperties; |
| 47 | import android.system.ErrnoException; |
| 48 | import android.system.Os; |
Jeff Sharkey | a103114 | 2014-07-12 18:09:46 -0700 | [diff] [blame] | 49 | import android.util.ExceptionUtils; |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 50 | |
| 51 | import com.android.internal.util.IndentingPrintWriter; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 52 | import com.android.internal.util.Preconditions; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 53 | |
Jeff Sharkey | ec55ef0 | 2014-07-08 11:28:00 -0700 | [diff] [blame] | 54 | import java.io.Closeable; |
Jeff Sharkey | a103114 | 2014-07-12 18:09:46 -0700 | [diff] [blame] | 55 | import java.io.IOException; |
Jeff Sharkey | 1cb2d0d | 2014-07-30 16:45:01 -0700 | [diff] [blame] | 56 | import java.io.InputStream; |
Jeff Sharkey | 78cc340 | 2014-05-22 10:52:49 -0700 | [diff] [blame] | 57 | import java.io.OutputStream; |
Dario Freni | 71eee5e | 2018-12-06 15:47:16 +0000 | [diff] [blame] | 58 | import java.lang.annotation.Retention; |
| 59 | import java.lang.annotation.RetentionPolicy; |
Jeff Sharkey | 1cb2d0d | 2014-07-30 16:45:01 -0700 | [diff] [blame] | 60 | import java.security.MessageDigest; |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 61 | import java.util.ArrayList; |
| 62 | import java.util.Iterator; |
Jeff Sharkey | bb58067 | 2014-07-10 12:10:25 -0700 | [diff] [blame] | 63 | import java.util.List; |
Jeff Sharkey | 78cc340 | 2014-05-22 10:52:49 -0700 | [diff] [blame] | 64 | |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 65 | /** |
| 66 | * Offers the ability to install, upgrade, and remove applications on the |
| 67 | * device. This includes support for apps packaged either as a single |
| 68 | * "monolithic" APK, or apps packaged as multiple "split" APKs. |
| 69 | * <p> |
| 70 | * An app is delivered for installation through a |
| 71 | * {@link PackageInstaller.Session}, which any app can create. Once the session |
| 72 | * is created, the installer can stream one or more APKs into place until it |
| 73 | * decides to either commit or destroy the session. Committing may require user |
Rubin Xu | fd4a3b44 | 2018-12-05 16:03:27 +0000 | [diff] [blame] | 74 | * intervention to complete the installation, unless the caller falls into one of the |
| 75 | * following categories, in which case the installation will complete automatically. |
| 76 | * <ul> |
| 77 | * <li>the device owner |
| 78 | * <li>the affiliated profile owner |
| 79 | * <li>the device owner delegated app with |
| 80 | * {@link android.app.admin.DevicePolicyManager#DELEGATION_PACKAGE_INSTALLATION} |
| 81 | * </ul> |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 82 | * <p> |
| 83 | * Sessions can install brand new apps, upgrade existing apps, or add new splits |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 84 | * into an existing app. |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 85 | * <p> |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 86 | * Apps packaged as multiple split APKs always consist of a single "base" APK |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 87 | * (with a {@code null} split name) and zero or more "split" APKs (with unique |
| 88 | * split names). Any subset of these APKs can be installed together, as long as |
| 89 | * the following constraints are met: |
| 90 | * <ul> |
| 91 | * <li>All APKs must have the exact same package name, version code, and signing |
| 92 | * certificates. |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 93 | * <li>All APKs must have unique split names. |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 94 | * <li>All installations must contain a single base APK. |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 95 | * </ul> |
Peter Visontay | f702fd4 | 2017-11-17 14:00:47 +0000 | [diff] [blame] | 96 | * <p> |
| 97 | * The ApiDemos project contains examples of using this API: |
| 98 | * <code>ApiDemos/src/com/example/android/apis/content/InstallApk*.java</code>. |
Ricky Wai | c5ea08b | 2018-09-05 20:55:11 +0100 | [diff] [blame] | 99 | * <p> |
| 100 | * On Android Q or above, an app installed notification will be posted |
| 101 | * by system after a new app is installed. |
| 102 | * To customize installer's notification icon, you should declare the following in the manifest |
| 103 | * <application> as follows: </p> |
| 104 | * <pre> |
| 105 | * <meta-data android:name="com.android.packageinstaller.notification.smallIcon" |
| 106 | * android:resource="@drawable/installer_notification_icon"/> |
| 107 | * </pre> |
| 108 | * <pre> |
| 109 | * <meta-data android:name="com.android.packageinstaller.notification.color" |
| 110 | * android:resource="@color/installer_notification_color"/> |
| 111 | * </pre> |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 112 | */ |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 113 | public class PackageInstaller { |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 114 | private static final String TAG = "PackageInstaller"; |
| 115 | |
Jeff Sharkey | 02d4e34 | 2017-03-10 21:53:48 -0700 | [diff] [blame] | 116 | /** {@hide} */ |
| 117 | public static final boolean ENABLE_REVOCABLE_FD = |
| 118 | SystemProperties.getBoolean("fw.revocable_fd", false); |
| 119 | |
Jeff Sharkey | 1cb2d0d | 2014-07-30 16:45:01 -0700 | [diff] [blame] | 120 | /** |
| 121 | * Activity Action: Show details about a particular install session. This |
| 122 | * may surface actions such as pause, resume, or cancel. |
| 123 | * <p> |
| 124 | * This should always be scoped to the installer package that owns the |
Jeff Sharkey | de74231 | 2014-09-15 14:04:56 -0700 | [diff] [blame] | 125 | * session. Clients should use {@link SessionInfo#createDetailsIntent()} to |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 126 | * build this intent correctly. |
Jeff Sharkey | 1cb2d0d | 2014-07-30 16:45:01 -0700 | [diff] [blame] | 127 | * <p> |
| 128 | * In some cases, a matching Activity may not exist, so ensure you safeguard |
| 129 | * against this. |
Jeff Sharkey | 941a8ba | 2014-08-20 16:26:32 -0700 | [diff] [blame] | 130 | * <p> |
| 131 | * The session to show details for is defined in {@link #EXTRA_SESSION_ID}. |
Jeff Sharkey | 1cb2d0d | 2014-07-30 16:45:01 -0700 | [diff] [blame] | 132 | */ |
| 133 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 134 | public static final String ACTION_SESSION_DETAILS = "android.content.pm.action.SESSION_DETAILS"; |
| 135 | |
Sunny Goyal | 6d7cb23 | 2017-01-30 10:43:18 -0800 | [diff] [blame] | 136 | /** |
| 137 | * Broadcast Action: Explicit broadcast sent to the last known default launcher when a session |
| 138 | * for a new install is committed. For managed profile, this is sent to the default launcher |
| 139 | * of the primary profile. |
| 140 | * <p> |
| 141 | * The associated session is defined in {@link #EXTRA_SESSION} and the user for which this |
| 142 | * session was created in {@link Intent#EXTRA_USER}. |
| 143 | */ |
| 144 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 145 | public static final String ACTION_SESSION_COMMITTED = |
| 146 | "android.content.pm.action.SESSION_COMMITTED"; |
| 147 | |
Dario Freni | e487ea2 | 2018-12-12 15:41:59 +0000 | [diff] [blame] | 148 | /** |
| 149 | * Broadcast Action: Send information about a staged install session when its state is updated. |
| 150 | * <p> |
| 151 | * The associated session information is defined in {@link #EXTRA_SESSION}. |
| 152 | */ |
| 153 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 154 | public static final String ACTION_SESSION_UPDATED = |
| 155 | "android.content.pm.action.SESSION_UPDATED"; |
| 156 | |
Jeff Sharkey | 7328a1b | 2014-08-07 14:01:43 -0700 | [diff] [blame] | 157 | /** {@hide} */ |
Philip P. Moltmann | e8fe3cb | 2018-07-23 14:27:11 -0700 | [diff] [blame] | 158 | public static final String ACTION_CONFIRM_INSTALL = "android.content.pm.action.CONFIRM_INSTALL"; |
Jeff Sharkey | 7328a1b | 2014-08-07 14:01:43 -0700 | [diff] [blame] | 159 | |
Jeff Sharkey | 1cb2d0d | 2014-07-30 16:45:01 -0700 | [diff] [blame] | 160 | /** |
Jeff Sharkey | 941a8ba | 2014-08-20 16:26:32 -0700 | [diff] [blame] | 161 | * An integer session ID that an operation is working with. |
Jeff Sharkey | 1cb2d0d | 2014-07-30 16:45:01 -0700 | [diff] [blame] | 162 | * |
Jeff Sharkey | 941a8ba | 2014-08-20 16:26:32 -0700 | [diff] [blame] | 163 | * @see Intent#getIntExtra(String, int) |
Jeff Sharkey | 1cb2d0d | 2014-07-30 16:45:01 -0700 | [diff] [blame] | 164 | */ |
| 165 | public static final String EXTRA_SESSION_ID = "android.content.pm.extra.SESSION_ID"; |
| 166 | |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 167 | /** |
Sunny Goyal | 6d7cb23 | 2017-01-30 10:43:18 -0800 | [diff] [blame] | 168 | * {@link SessionInfo} that an operation is working with. |
| 169 | * |
| 170 | * @see Intent#getParcelableExtra(String) |
| 171 | */ |
| 172 | public static final String EXTRA_SESSION = "android.content.pm.extra.SESSION"; |
| 173 | |
| 174 | /** |
Jeff Sharkey | 941a8ba | 2014-08-20 16:26:32 -0700 | [diff] [blame] | 175 | * Package name that an operation is working with. |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 176 | * |
Jeff Sharkey | bb7b7be | 2014-08-19 16:18:28 -0700 | [diff] [blame] | 177 | * @see Intent#getStringExtra(String) |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 178 | */ |
Jeff Sharkey | bb7b7be | 2014-08-19 16:18:28 -0700 | [diff] [blame] | 179 | public static final String EXTRA_PACKAGE_NAME = "android.content.pm.extra.PACKAGE_NAME"; |
| 180 | |
Jeff Sharkey | 941a8ba | 2014-08-20 16:26:32 -0700 | [diff] [blame] | 181 | /** |
| 182 | * Current status of an operation. Will be one of |
| 183 | * {@link #STATUS_PENDING_USER_ACTION}, {@link #STATUS_SUCCESS}, |
| 184 | * {@link #STATUS_FAILURE}, {@link #STATUS_FAILURE_ABORTED}, |
| 185 | * {@link #STATUS_FAILURE_BLOCKED}, {@link #STATUS_FAILURE_CONFLICT}, |
| 186 | * {@link #STATUS_FAILURE_INCOMPATIBLE}, {@link #STATUS_FAILURE_INVALID}, or |
| 187 | * {@link #STATUS_FAILURE_STORAGE}. |
| 188 | * <p> |
| 189 | * More information about a status may be available through additional |
| 190 | * extras; see the individual status documentation for details. |
| 191 | * |
| 192 | * @see Intent#getIntExtra(String, int) |
| 193 | */ |
| 194 | public static final String EXTRA_STATUS = "android.content.pm.extra.STATUS"; |
| 195 | |
| 196 | /** |
| 197 | * Detailed string representation of the status, including raw details that |
| 198 | * are useful for debugging. |
| 199 | * |
| 200 | * @see Intent#getStringExtra(String) |
| 201 | */ |
| 202 | public static final String EXTRA_STATUS_MESSAGE = "android.content.pm.extra.STATUS_MESSAGE"; |
| 203 | |
| 204 | /** |
| 205 | * Another package name relevant to a status. This is typically the package |
| 206 | * responsible for causing an operation failure. |
| 207 | * |
| 208 | * @see Intent#getStringExtra(String) |
| 209 | */ |
| 210 | public static final String |
| 211 | EXTRA_OTHER_PACKAGE_NAME = "android.content.pm.extra.OTHER_PACKAGE_NAME"; |
| 212 | |
| 213 | /** |
| 214 | * Storage path relevant to a status. |
| 215 | * |
| 216 | * @see Intent#getStringExtra(String) |
| 217 | */ |
| 218 | public static final String EXTRA_STORAGE_PATH = "android.content.pm.extra.STORAGE_PATH"; |
| 219 | |
Jeff Sharkey | bb7b7be | 2014-08-19 16:18:28 -0700 | [diff] [blame] | 220 | /** {@hide} */ |
| 221 | @Deprecated |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 222 | public static final String EXTRA_PACKAGE_NAMES = "android.content.pm.extra.PACKAGE_NAMES"; |
| 223 | |
| 224 | /** {@hide} */ |
| 225 | public static final String EXTRA_LEGACY_STATUS = "android.content.pm.extra.LEGACY_STATUS"; |
| 226 | /** {@hide} */ |
| 227 | public static final String EXTRA_LEGACY_BUNDLE = "android.content.pm.extra.LEGACY_BUNDLE"; |
Jeff Sharkey | f060095 | 2014-08-07 17:31:53 -0700 | [diff] [blame] | 228 | /** {@hide} */ |
| 229 | public static final String EXTRA_CALLBACK = "android.content.pm.extra.CALLBACK"; |
| 230 | |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 231 | /** |
| 232 | * User action is currently required to proceed. You can launch the intent |
| 233 | * activity described by {@link Intent#EXTRA_INTENT} to involve the user and |
| 234 | * continue. |
| 235 | * <p> |
| 236 | * You may choose to immediately launch the intent if the user is actively |
| 237 | * using your app. Otherwise, you should use a notification to guide the |
| 238 | * user back into your app before launching. |
| 239 | * |
| 240 | * @see Intent#getParcelableExtra(String) |
| 241 | */ |
Jeff Sharkey | 742e790 | 2014-08-16 19:09:13 -0700 | [diff] [blame] | 242 | public static final int STATUS_PENDING_USER_ACTION = -1; |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 243 | |
| 244 | /** |
| 245 | * The operation succeeded. |
| 246 | */ |
| 247 | public static final int STATUS_SUCCESS = 0; |
| 248 | |
| 249 | /** |
| 250 | * The operation failed in a generic way. The system will always try to |
| 251 | * provide a more specific failure reason, but in some rare cases this may |
| 252 | * be delivered. |
| 253 | * |
| 254 | * @see #EXTRA_STATUS_MESSAGE |
| 255 | */ |
| 256 | public static final int STATUS_FAILURE = 1; |
| 257 | |
| 258 | /** |
| 259 | * The operation failed because it was blocked. For example, a device policy |
| 260 | * may be blocking the operation, a package verifier may have blocked the |
| 261 | * operation, or the app may be required for core system operation. |
Jeff Sharkey | 941a8ba | 2014-08-20 16:26:32 -0700 | [diff] [blame] | 262 | * <p> |
| 263 | * The result may also contain {@link #EXTRA_OTHER_PACKAGE_NAME} with the |
| 264 | * specific package blocking the install. |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 265 | * |
| 266 | * @see #EXTRA_STATUS_MESSAGE |
Jeff Sharkey | 941a8ba | 2014-08-20 16:26:32 -0700 | [diff] [blame] | 267 | * @see #EXTRA_OTHER_PACKAGE_NAME |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 268 | */ |
Jeff Sharkey | 742e790 | 2014-08-16 19:09:13 -0700 | [diff] [blame] | 269 | public static final int STATUS_FAILURE_BLOCKED = 2; |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 270 | |
| 271 | /** |
| 272 | * The operation failed because it was actively aborted. For example, the |
| 273 | * user actively declined requested permissions, or the session was |
| 274 | * abandoned. |
| 275 | * |
| 276 | * @see #EXTRA_STATUS_MESSAGE |
| 277 | */ |
Jeff Sharkey | 742e790 | 2014-08-16 19:09:13 -0700 | [diff] [blame] | 278 | public static final int STATUS_FAILURE_ABORTED = 3; |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 279 | |
| 280 | /** |
| 281 | * The operation failed because one or more of the APKs was invalid. For |
| 282 | * example, they might be malformed, corrupt, incorrectly signed, |
| 283 | * mismatched, etc. |
| 284 | * |
| 285 | * @see #EXTRA_STATUS_MESSAGE |
| 286 | */ |
Jeff Sharkey | 742e790 | 2014-08-16 19:09:13 -0700 | [diff] [blame] | 287 | public static final int STATUS_FAILURE_INVALID = 4; |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 288 | |
| 289 | /** |
| 290 | * The operation failed because it conflicts (or is inconsistent with) with |
| 291 | * another package already installed on the device. For example, an existing |
| 292 | * permission, incompatible certificates, etc. The user may be able to |
| 293 | * uninstall another app to fix the issue. |
| 294 | * <p> |
Jeff Sharkey | 941a8ba | 2014-08-20 16:26:32 -0700 | [diff] [blame] | 295 | * The result may also contain {@link #EXTRA_OTHER_PACKAGE_NAME} with the |
Jeff Sharkey | bb7b7be | 2014-08-19 16:18:28 -0700 | [diff] [blame] | 296 | * specific package identified as the cause of the conflict. |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 297 | * |
| 298 | * @see #EXTRA_STATUS_MESSAGE |
Jeff Sharkey | 941a8ba | 2014-08-20 16:26:32 -0700 | [diff] [blame] | 299 | * @see #EXTRA_OTHER_PACKAGE_NAME |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 300 | */ |
Jeff Sharkey | 742e790 | 2014-08-16 19:09:13 -0700 | [diff] [blame] | 301 | public static final int STATUS_FAILURE_CONFLICT = 5; |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 302 | |
| 303 | /** |
| 304 | * The operation failed because of storage issues. For example, the device |
| 305 | * may be running low on space, or external media may be unavailable. The |
| 306 | * user may be able to help free space or insert different external media. |
Jeff Sharkey | 941a8ba | 2014-08-20 16:26:32 -0700 | [diff] [blame] | 307 | * <p> |
| 308 | * The result may also contain {@link #EXTRA_STORAGE_PATH} with the path to |
| 309 | * the storage device that caused the failure. |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 310 | * |
| 311 | * @see #EXTRA_STATUS_MESSAGE |
Jeff Sharkey | 941a8ba | 2014-08-20 16:26:32 -0700 | [diff] [blame] | 312 | * @see #EXTRA_STORAGE_PATH |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 313 | */ |
Jeff Sharkey | 742e790 | 2014-08-16 19:09:13 -0700 | [diff] [blame] | 314 | public static final int STATUS_FAILURE_STORAGE = 6; |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 315 | |
| 316 | /** |
| 317 | * The operation failed because it is fundamentally incompatible with this |
| 318 | * device. For example, the app may require a hardware feature that doesn't |
| 319 | * exist, it may be missing native code for the ABIs supported by the |
| 320 | * device, or it requires a newer SDK version, etc. |
| 321 | * |
| 322 | * @see #EXTRA_STATUS_MESSAGE |
| 323 | */ |
Jeff Sharkey | 742e790 | 2014-08-16 19:09:13 -0700 | [diff] [blame] | 324 | public static final int STATUS_FAILURE_INCOMPATIBLE = 7; |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 325 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 326 | private final IPackageInstaller mInstaller; |
| 327 | private final int mUserId; |
| 328 | private final String mInstallerPackageName; |
| 329 | |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 330 | private final ArrayList<SessionCallbackDelegate> mDelegates = new ArrayList<>(); |
| 331 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 332 | /** {@hide} */ |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 333 | public PackageInstaller(IPackageInstaller installer, |
Jeff Sharkey | ec55ef0 | 2014-07-08 11:28:00 -0700 | [diff] [blame] | 334 | String installerPackageName, int userId) { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 335 | mInstaller = installer; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 336 | mInstallerPackageName = installerPackageName; |
Jeff Sharkey | ec55ef0 | 2014-07-08 11:28:00 -0700 | [diff] [blame] | 337 | mUserId = userId; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 340 | /** |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 341 | * Create a new session using the given parameters, returning a unique ID |
| 342 | * that represents the session. Once created, the session can be opened |
| 343 | * multiple times across multiple device boots. |
| 344 | * <p> |
| 345 | * The system may automatically destroy sessions that have not been |
| 346 | * finalized (either committed or abandoned) within a reasonable period of |
| 347 | * time, typically on the order of a day. |
| 348 | * |
| 349 | * @throws IOException if parameters were unsatisfiable, such as lack of |
| 350 | * disk space or unavailable media. |
Jeff Sharkey | 77d218e | 2014-09-06 12:20:37 -0700 | [diff] [blame] | 351 | * @throws SecurityException when installation services are unavailable, |
| 352 | * such as when called from a restricted user. |
| 353 | * @throws IllegalArgumentException when {@link SessionParams} is invalid. |
Jeff Sharkey | f174c6e | 2014-08-05 10:42:27 -0700 | [diff] [blame] | 354 | * @return positive, non-zero unique ID that represents the created session. |
| 355 | * This ID remains consistent across device reboots until the |
| 356 | * session is finalized. IDs are not reused during a given boot. |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 357 | */ |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 358 | public int createSession(@NonNull SessionParams params) throws IOException { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 359 | try { |
Philip P. Moltmann | 79c238a | 2017-12-13 15:59:07 -0800 | [diff] [blame] | 360 | final String installerPackage; |
| 361 | if (params.installerPackageName == null) { |
| 362 | installerPackage = mInstallerPackageName; |
| 363 | } else { |
| 364 | installerPackage = params.installerPackageName; |
| 365 | } |
| 366 | |
| 367 | return mInstaller.createSession(params, installerPackage, mUserId); |
Jeff Sharkey | a103114 | 2014-07-12 18:09:46 -0700 | [diff] [blame] | 368 | } catch (RuntimeException e) { |
| 369 | ExceptionUtils.maybeUnwrapIOException(e); |
| 370 | throw e; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 371 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 372 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 373 | } |
| 374 | } |
| 375 | |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 376 | /** |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 377 | * Open an existing session to actively perform work. To succeed, the caller |
| 378 | * must be the owner of the install session. |
Jeff Sharkey | 77d218e | 2014-09-06 12:20:37 -0700 | [diff] [blame] | 379 | * |
| 380 | * @throws IOException if parameters were unsatisfiable, such as lack of |
| 381 | * disk space or unavailable media. |
| 382 | * @throws SecurityException when the caller does not own the session, or |
| 383 | * the session is invalid. |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 384 | */ |
Jeff Sharkey | bc7bce3 | 2014-09-05 15:53:05 -0700 | [diff] [blame] | 385 | public @NonNull Session openSession(int sessionId) throws IOException { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 386 | try { |
Patrick Baumann | 0aff9b1 | 2018-11-08 14:05:08 +0000 | [diff] [blame] | 387 | try { |
| 388 | return new Session(mInstaller.openSession(sessionId)); |
| 389 | } catch (RemoteException e) { |
| 390 | throw e.rethrowFromSystemServer(); |
| 391 | } |
Jeff Sharkey | bc7bce3 | 2014-09-05 15:53:05 -0700 | [diff] [blame] | 392 | } catch (RuntimeException e) { |
| 393 | ExceptionUtils.maybeUnwrapIOException(e); |
| 394 | throw e; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 395 | } |
| 396 | } |
| 397 | |
Jeff Sharkey | ec9bad2 | 2014-09-05 09:45:20 -0700 | [diff] [blame] | 398 | /** |
| 399 | * Update the icon representing the app being installed in a specific |
| 400 | * session. This should be roughly |
| 401 | * {@link ActivityManager#getLauncherLargeIconSize()} in both dimensions. |
Jeff Sharkey | 77d218e | 2014-09-06 12:20:37 -0700 | [diff] [blame] | 402 | * |
| 403 | * @throws SecurityException when the caller does not own the session, or |
| 404 | * the session is invalid. |
Jeff Sharkey | ec9bad2 | 2014-09-05 09:45:20 -0700 | [diff] [blame] | 405 | */ |
| 406 | public void updateSessionAppIcon(int sessionId, @Nullable Bitmap appIcon) { |
| 407 | try { |
| 408 | mInstaller.updateSessionAppIcon(sessionId, appIcon); |
| 409 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 410 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | ec9bad2 | 2014-09-05 09:45:20 -0700 | [diff] [blame] | 411 | } |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * Update the label representing the app being installed in a specific |
| 416 | * session. |
Jeff Sharkey | 77d218e | 2014-09-06 12:20:37 -0700 | [diff] [blame] | 417 | * |
| 418 | * @throws SecurityException when the caller does not own the session, or |
| 419 | * the session is invalid. |
Jeff Sharkey | ec9bad2 | 2014-09-05 09:45:20 -0700 | [diff] [blame] | 420 | */ |
| 421 | public void updateSessionAppLabel(int sessionId, @Nullable CharSequence appLabel) { |
| 422 | try { |
| 423 | final String val = (appLabel != null) ? appLabel.toString() : null; |
| 424 | mInstaller.updateSessionAppLabel(sessionId, val); |
| 425 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 426 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | ec9bad2 | 2014-09-05 09:45:20 -0700 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | |
Jeff Sharkey | 77d218e | 2014-09-06 12:20:37 -0700 | [diff] [blame] | 430 | /** |
| 431 | * Completely abandon the given session, destroying all staged data and |
| 432 | * rendering it invalid. Abandoned sessions will be reported to |
| 433 | * {@link SessionCallback} listeners as failures. This is equivalent to |
| 434 | * opening the session and calling {@link Session#abandon()}. |
| 435 | * |
| 436 | * @throws SecurityException when the caller does not own the session, or |
| 437 | * the session is invalid. |
| 438 | */ |
Jeff Sharkey | 381d94b | 2014-08-24 14:45:56 -0700 | [diff] [blame] | 439 | public void abandonSession(int sessionId) { |
| 440 | try { |
| 441 | mInstaller.abandonSession(sessionId); |
| 442 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 443 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 381d94b | 2014-08-24 14:45:56 -0700 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 447 | /** |
Jeff Sharkey | 77d218e | 2014-09-06 12:20:37 -0700 | [diff] [blame] | 448 | * Return details for a specific session. No special permissions are |
| 449 | * required to retrieve these details. |
| 450 | * |
| 451 | * @return details for the requested session, or {@code null} if the session |
| 452 | * does not exist. |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 453 | */ |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 454 | public @Nullable SessionInfo getSessionInfo(int sessionId) { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 455 | try { |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 456 | return mInstaller.getSessionInfo(sessionId); |
| 457 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 458 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | |
| 462 | /** |
Jeff Sharkey | 77d218e | 2014-09-06 12:20:37 -0700 | [diff] [blame] | 463 | * Return list of all known install sessions, regardless of the installer. |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 464 | */ |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 465 | public @NonNull List<SessionInfo> getAllSessions() { |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 466 | try { |
Jeff Sharkey | 97d47ed | 2014-10-15 09:19:47 -0700 | [diff] [blame] | 467 | return mInstaller.getAllSessions(mUserId).getList(); |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 468 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 469 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 470 | } |
| 471 | } |
| 472 | |
| 473 | /** |
Jeff Sharkey | 77d218e | 2014-09-06 12:20:37 -0700 | [diff] [blame] | 474 | * Return list of all known install sessions owned by the calling app. |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 475 | */ |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 476 | public @NonNull List<SessionInfo> getMySessions() { |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 477 | try { |
Jeff Sharkey | 97d47ed | 2014-10-15 09:19:47 -0700 | [diff] [blame] | 478 | return mInstaller.getMySessions(mInstallerPackageName, mUserId).getList(); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 479 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 480 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 481 | } |
| 482 | } |
| 483 | |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 484 | /** |
Dario Freni | aac4ba4 | 2018-12-06 15:47:16 +0000 | [diff] [blame] | 485 | * Return list of all staged install sessions. |
| 486 | */ |
| 487 | public @NonNull List<SessionInfo> getStagedSessions() { |
| 488 | try { |
| 489 | // TODO: limit this to the mUserId? |
| 490 | return mInstaller.getStagedSessions().getList(); |
| 491 | } catch (RemoteException e) { |
| 492 | throw e.rethrowFromSystemServer(); |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | /** |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 497 | * Uninstall the given package, removing it completely from the device. This |
Tony Mak | 366ee62 | 2018-02-12 17:52:34 +0000 | [diff] [blame] | 498 | * method is available to: |
| 499 | * <ul> |
| 500 | * <li>the current "installer of record" for the package |
| 501 | * <li>the device owner |
| 502 | * <li>the affiliated profile owner |
Rubin Xu | fd4a3b44 | 2018-12-05 16:03:27 +0000 | [diff] [blame] | 503 | * <li>the device owner delegated app with |
| 504 | * {@link android.app.admin.DevicePolicyManager#DELEGATION_PACKAGE_INSTALLATION} |
Tony Mak | 366ee62 | 2018-02-12 17:52:34 +0000 | [diff] [blame] | 505 | * </ul> |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 506 | * |
| 507 | * @param packageName The package to uninstall. |
| 508 | * @param statusReceiver Where to deliver the result. |
Tony Mak | 366ee62 | 2018-02-12 17:52:34 +0000 | [diff] [blame] | 509 | * |
| 510 | * @see android.app.admin.DevicePolicyManager |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 511 | */ |
Philip P. Moltmann | d9bb39a | 2017-09-05 12:41:15 -0700 | [diff] [blame] | 512 | @RequiresPermission(anyOf = { |
| 513 | Manifest.permission.DELETE_PACKAGES, |
| 514 | Manifest.permission.REQUEST_DELETE_PACKAGES}) |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 515 | public void uninstall(@NonNull String packageName, @NonNull IntentSender statusReceiver) { |
Todd Kennedy | cda831f | 2017-05-16 10:54:33 -0700 | [diff] [blame] | 516 | uninstall(packageName, 0 /*flags*/, statusReceiver); |
| 517 | } |
| 518 | |
| 519 | /** |
| 520 | * Uninstall the given package, removing it completely from the device. This |
| 521 | * method is only available to the current "installer of record" for the |
| 522 | * package. |
| 523 | * |
| 524 | * @param packageName The package to uninstall. |
| 525 | * @param flags Flags for uninstall. |
| 526 | * @param statusReceiver Where to deliver the result. |
| 527 | * |
| 528 | * @hide |
| 529 | */ |
| 530 | public void uninstall(@NonNull String packageName, @DeleteFlags int flags, |
| 531 | @NonNull IntentSender statusReceiver) { |
| 532 | uninstall(new VersionedPackage(packageName, PackageManager.VERSION_CODE_HIGHEST), |
| 533 | flags, statusReceiver); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | /** |
| 537 | * Uninstall the given package with a specific version code, removing it |
Tony Mak | 366ee62 | 2018-02-12 17:52:34 +0000 | [diff] [blame] | 538 | * completely from the device. If the version code of the package |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 539 | * does not match the one passed in the versioned package argument this |
| 540 | * method is a no-op. Use {@link PackageManager#VERSION_CODE_HIGHEST} to |
| 541 | * uninstall the latest version of the package. |
Tony Mak | 366ee62 | 2018-02-12 17:52:34 +0000 | [diff] [blame] | 542 | * <p> |
| 543 | * This method is available to: |
| 544 | * <ul> |
| 545 | * <li>the current "installer of record" for the package |
| 546 | * <li>the device owner |
| 547 | * <li>the affiliated profile owner |
| 548 | * </ul> |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 549 | * |
| 550 | * @param versionedPackage The versioned package to uninstall. |
| 551 | * @param statusReceiver Where to deliver the result. |
Tony Mak | 366ee62 | 2018-02-12 17:52:34 +0000 | [diff] [blame] | 552 | * |
| 553 | * @see android.app.admin.DevicePolicyManager |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 554 | */ |
Philip P. Moltmann | d9bb39a | 2017-09-05 12:41:15 -0700 | [diff] [blame] | 555 | @RequiresPermission(anyOf = { |
| 556 | Manifest.permission.DELETE_PACKAGES, |
| 557 | Manifest.permission.REQUEST_DELETE_PACKAGES}) |
Todd Kennedy | cda831f | 2017-05-16 10:54:33 -0700 | [diff] [blame] | 558 | public void uninstall(@NonNull VersionedPackage versionedPackage, |
| 559 | @NonNull IntentSender statusReceiver) { |
| 560 | uninstall(versionedPackage, 0 /*flags*/, statusReceiver); |
| 561 | } |
| 562 | |
| 563 | /** |
| 564 | * Uninstall the given package with a specific version code, removing it |
| 565 | * completely from the device. This method is only available to the current |
| 566 | * "installer of record" for the package. If the version code of the package |
| 567 | * does not match the one passed in the versioned package argument this |
| 568 | * method is a no-op. Use {@link PackageManager#VERSION_CODE_HIGHEST} to |
| 569 | * uninstall the latest version of the package. |
| 570 | * |
| 571 | * @param versionedPackage The versioned package to uninstall. |
| 572 | * @param flags Flags for uninstall. |
| 573 | * @param statusReceiver Where to deliver the result. |
| 574 | * |
| 575 | * @hide |
| 576 | */ |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 577 | @RequiresPermission(anyOf = { |
| 578 | Manifest.permission.DELETE_PACKAGES, |
| 579 | Manifest.permission.REQUEST_DELETE_PACKAGES}) |
Todd Kennedy | cda831f | 2017-05-16 10:54:33 -0700 | [diff] [blame] | 580 | public void uninstall(@NonNull VersionedPackage versionedPackage, @DeleteFlags int flags, |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 581 | @NonNull IntentSender statusReceiver) { |
| 582 | Preconditions.checkNotNull(versionedPackage, "versionedPackage cannot be null"); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 583 | try { |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 584 | mInstaller.uninstall(versionedPackage, mInstallerPackageName, |
Todd Kennedy | cda831f | 2017-05-16 10:54:33 -0700 | [diff] [blame] | 585 | flags, statusReceiver, mUserId); |
Jeff Sharkey | bb58067 | 2014-07-10 12:10:25 -0700 | [diff] [blame] | 586 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 587 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | bb58067 | 2014-07-10 12:10:25 -0700 | [diff] [blame] | 588 | } |
| 589 | } |
| 590 | |
Jeff Sharkey | 7328a1b | 2014-08-07 14:01:43 -0700 | [diff] [blame] | 591 | /** {@hide} */ |
Todd Kennedy | 04cc191 | 2017-03-03 13:05:12 -0800 | [diff] [blame] | 592 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 593 | @RequiresPermission(android.Manifest.permission.INSTALL_PACKAGES) |
Jeff Sharkey | 7328a1b | 2014-08-07 14:01:43 -0700 | [diff] [blame] | 594 | public void setPermissionsResult(int sessionId, boolean accepted) { |
| 595 | try { |
| 596 | mInstaller.setPermissionsResult(sessionId, accepted); |
| 597 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 598 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 7328a1b | 2014-08-07 14:01:43 -0700 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 602 | /** |
| 603 | * Events for observing session lifecycle. |
Jeff Sharkey | 1cb2d0d | 2014-07-30 16:45:01 -0700 | [diff] [blame] | 604 | * <p> |
| 605 | * A typical session lifecycle looks like this: |
| 606 | * <ul> |
| 607 | * <li>An installer creates a session to indicate pending app delivery. All |
| 608 | * install details are available at this point. |
| 609 | * <li>The installer opens the session to deliver APK data. Note that a |
| 610 | * session may be opened and closed multiple times as network connectivity |
| 611 | * changes. The installer may deliver periodic progress updates. |
| 612 | * <li>The installer commits or abandons the session, resulting in the |
| 613 | * session being finished. |
| 614 | * </ul> |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 615 | */ |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 616 | public static abstract class SessionCallback { |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 617 | /** |
Jeff Sharkey | 1cb2d0d | 2014-07-30 16:45:01 -0700 | [diff] [blame] | 618 | * New session has been created. Details about the session can be |
| 619 | * obtained from {@link PackageInstaller#getSessionInfo(int)}. |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 620 | */ |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 621 | public abstract void onCreated(int sessionId); |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 622 | |
| 623 | /** |
Jeff Sharkey | ec9bad2 | 2014-09-05 09:45:20 -0700 | [diff] [blame] | 624 | * Badging details for an existing session has changed. For example, the |
| 625 | * app icon or label has been updated. |
| 626 | */ |
| 627 | public abstract void onBadgingChanged(int sessionId); |
| 628 | |
| 629 | /** |
Jeff Sharkey | bc7bce3 | 2014-09-05 15:53:05 -0700 | [diff] [blame] | 630 | * Active state for session has been changed. |
| 631 | * <p> |
| 632 | * A session is considered active whenever there is ongoing forward |
| 633 | * progress being made, such as the installer holding an open |
| 634 | * {@link Session} instance while streaming data into place, or the |
| 635 | * system optimizing code as the result of |
| 636 | * {@link Session#commit(IntentSender)}. |
| 637 | * <p> |
| 638 | * If the installer closes the {@link Session} without committing, the |
| 639 | * session is considered inactive until the installer opens the session |
| 640 | * again. |
Jeff Sharkey | 1cb2d0d | 2014-07-30 16:45:01 -0700 | [diff] [blame] | 641 | */ |
Jeff Sharkey | bc7bce3 | 2014-09-05 15:53:05 -0700 | [diff] [blame] | 642 | public abstract void onActiveChanged(int sessionId, boolean active); |
Jeff Sharkey | 1cb2d0d | 2014-07-30 16:45:01 -0700 | [diff] [blame] | 643 | |
| 644 | /** |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 645 | * Progress for given session has been updated. |
| 646 | * <p> |
| 647 | * Note that this progress may not directly correspond to the value |
Jeff Sharkey | bc7bce3 | 2014-09-05 15:53:05 -0700 | [diff] [blame] | 648 | * reported by |
| 649 | * {@link PackageInstaller.Session#setStagingProgress(float)}, as the |
| 650 | * system may carve out a portion of the overall progress to represent |
| 651 | * its own internal installation work. |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 652 | */ |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 653 | public abstract void onProgressChanged(int sessionId, float progress); |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 654 | |
| 655 | /** |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 656 | * Session has completely finished, either with success or failure. |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 657 | */ |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 658 | public abstract void onFinished(int sessionId, boolean success); |
Jeff Sharkey | bb58067 | 2014-07-10 12:10:25 -0700 | [diff] [blame] | 659 | } |
| 660 | |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 661 | /** {@hide} */ |
| 662 | private static class SessionCallbackDelegate extends IPackageInstallerCallback.Stub implements |
| 663 | Handler.Callback { |
| 664 | private static final int MSG_SESSION_CREATED = 1; |
Jeff Sharkey | ec9bad2 | 2014-09-05 09:45:20 -0700 | [diff] [blame] | 665 | private static final int MSG_SESSION_BADGING_CHANGED = 2; |
Jeff Sharkey | bc7bce3 | 2014-09-05 15:53:05 -0700 | [diff] [blame] | 666 | private static final int MSG_SESSION_ACTIVE_CHANGED = 3; |
Jeff Sharkey | ec9bad2 | 2014-09-05 09:45:20 -0700 | [diff] [blame] | 667 | private static final int MSG_SESSION_PROGRESS_CHANGED = 4; |
Jeff Sharkey | bc7bce3 | 2014-09-05 15:53:05 -0700 | [diff] [blame] | 668 | private static final int MSG_SESSION_FINISHED = 5; |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 669 | |
| 670 | final SessionCallback mCallback; |
| 671 | final Handler mHandler; |
| 672 | |
| 673 | public SessionCallbackDelegate(SessionCallback callback, Looper looper) { |
| 674 | mCallback = callback; |
| 675 | mHandler = new Handler(looper, this); |
| 676 | } |
| 677 | |
| 678 | @Override |
| 679 | public boolean handleMessage(Message msg) { |
Jeff Sharkey | bc7bce3 | 2014-09-05 15:53:05 -0700 | [diff] [blame] | 680 | final int sessionId = msg.arg1; |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 681 | switch (msg.what) { |
| 682 | case MSG_SESSION_CREATED: |
Jeff Sharkey | bc7bce3 | 2014-09-05 15:53:05 -0700 | [diff] [blame] | 683 | mCallback.onCreated(sessionId); |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 684 | return true; |
Jeff Sharkey | ec9bad2 | 2014-09-05 09:45:20 -0700 | [diff] [blame] | 685 | case MSG_SESSION_BADGING_CHANGED: |
Jeff Sharkey | bc7bce3 | 2014-09-05 15:53:05 -0700 | [diff] [blame] | 686 | mCallback.onBadgingChanged(sessionId); |
Jeff Sharkey | ec9bad2 | 2014-09-05 09:45:20 -0700 | [diff] [blame] | 687 | return true; |
Jeff Sharkey | bc7bce3 | 2014-09-05 15:53:05 -0700 | [diff] [blame] | 688 | case MSG_SESSION_ACTIVE_CHANGED: |
| 689 | final boolean active = msg.arg2 != 0; |
| 690 | mCallback.onActiveChanged(sessionId, active); |
Jeff Sharkey | 1cb2d0d | 2014-07-30 16:45:01 -0700 | [diff] [blame] | 691 | return true; |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 692 | case MSG_SESSION_PROGRESS_CHANGED: |
Jeff Sharkey | bc7bce3 | 2014-09-05 15:53:05 -0700 | [diff] [blame] | 693 | mCallback.onProgressChanged(sessionId, (float) msg.obj); |
Jeff Sharkey | 1cb2d0d | 2014-07-30 16:45:01 -0700 | [diff] [blame] | 694 | return true; |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 695 | case MSG_SESSION_FINISHED: |
Jeff Sharkey | bc7bce3 | 2014-09-05 15:53:05 -0700 | [diff] [blame] | 696 | mCallback.onFinished(sessionId, msg.arg2 != 0); |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 697 | return true; |
| 698 | } |
| 699 | return false; |
| 700 | } |
| 701 | |
| 702 | @Override |
| 703 | public void onSessionCreated(int sessionId) { |
| 704 | mHandler.obtainMessage(MSG_SESSION_CREATED, sessionId, 0).sendToTarget(); |
| 705 | } |
| 706 | |
| 707 | @Override |
Jeff Sharkey | ec9bad2 | 2014-09-05 09:45:20 -0700 | [diff] [blame] | 708 | public void onSessionBadgingChanged(int sessionId) { |
| 709 | mHandler.obtainMessage(MSG_SESSION_BADGING_CHANGED, sessionId, 0).sendToTarget(); |
| 710 | } |
| 711 | |
| 712 | @Override |
Jeff Sharkey | bc7bce3 | 2014-09-05 15:53:05 -0700 | [diff] [blame] | 713 | public void onSessionActiveChanged(int sessionId, boolean active) { |
| 714 | mHandler.obtainMessage(MSG_SESSION_ACTIVE_CHANGED, sessionId, active ? 1 : 0) |
| 715 | .sendToTarget(); |
Jeff Sharkey | 1cb2d0d | 2014-07-30 16:45:01 -0700 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | @Override |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 719 | public void onSessionProgressChanged(int sessionId, float progress) { |
| 720 | mHandler.obtainMessage(MSG_SESSION_PROGRESS_CHANGED, sessionId, 0, progress) |
| 721 | .sendToTarget(); |
| 722 | } |
| 723 | |
| 724 | @Override |
| 725 | public void onSessionFinished(int sessionId, boolean success) { |
| 726 | mHandler.obtainMessage(MSG_SESSION_FINISHED, sessionId, success ? 1 : 0) |
| 727 | .sendToTarget(); |
Jeff Sharkey | bb58067 | 2014-07-10 12:10:25 -0700 | [diff] [blame] | 728 | } |
| 729 | } |
| 730 | |
Jeff Sharkey | ec9bad2 | 2014-09-05 09:45:20 -0700 | [diff] [blame] | 731 | /** {@hide} */ |
| 732 | @Deprecated |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 733 | public void addSessionCallback(@NonNull SessionCallback callback) { |
Jeff Sharkey | ec9bad2 | 2014-09-05 09:45:20 -0700 | [diff] [blame] | 734 | registerSessionCallback(callback); |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | /** |
Jeff Sharkey | 77d218e | 2014-09-06 12:20:37 -0700 | [diff] [blame] | 738 | * Register to watch for session lifecycle events. No special permissions |
| 739 | * are required to watch for these events. |
Jeff Sharkey | ec9bad2 | 2014-09-05 09:45:20 -0700 | [diff] [blame] | 740 | */ |
| 741 | public void registerSessionCallback(@NonNull SessionCallback callback) { |
| 742 | registerSessionCallback(callback, new Handler()); |
| 743 | } |
| 744 | |
| 745 | /** {@hide} */ |
| 746 | @Deprecated |
| 747 | public void addSessionCallback(@NonNull SessionCallback callback, @NonNull Handler handler) { |
| 748 | registerSessionCallback(callback, handler); |
| 749 | } |
| 750 | |
| 751 | /** |
Jeff Sharkey | 77d218e | 2014-09-06 12:20:37 -0700 | [diff] [blame] | 752 | * Register to watch for session lifecycle events. No special permissions |
| 753 | * are required to watch for these events. |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 754 | * |
| 755 | * @param handler to dispatch callback events through, otherwise uses |
| 756 | * calling thread. |
| 757 | */ |
Jeff Sharkey | ec9bad2 | 2014-09-05 09:45:20 -0700 | [diff] [blame] | 758 | public void registerSessionCallback(@NonNull SessionCallback callback, @NonNull Handler handler) { |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 759 | synchronized (mDelegates) { |
| 760 | final SessionCallbackDelegate delegate = new SessionCallbackDelegate(callback, |
| 761 | handler.getLooper()); |
| 762 | try { |
| 763 | mInstaller.registerCallback(delegate, mUserId); |
| 764 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 765 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 766 | } |
| 767 | mDelegates.add(delegate); |
| 768 | } |
| 769 | } |
| 770 | |
Jeff Sharkey | ec9bad2 | 2014-09-05 09:45:20 -0700 | [diff] [blame] | 771 | /** {@hide} */ |
| 772 | @Deprecated |
| 773 | public void removeSessionCallback(@NonNull SessionCallback callback) { |
| 774 | unregisterSessionCallback(callback); |
| 775 | } |
| 776 | |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 777 | /** |
Jeff Sharkey | 77d218e | 2014-09-06 12:20:37 -0700 | [diff] [blame] | 778 | * Unregister a previously registered callback. |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 779 | */ |
Jeff Sharkey | ec9bad2 | 2014-09-05 09:45:20 -0700 | [diff] [blame] | 780 | public void unregisterSessionCallback(@NonNull SessionCallback callback) { |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 781 | synchronized (mDelegates) { |
| 782 | for (Iterator<SessionCallbackDelegate> i = mDelegates.iterator(); i.hasNext();) { |
| 783 | final SessionCallbackDelegate delegate = i.next(); |
| 784 | if (delegate.mCallback == callback) { |
| 785 | try { |
| 786 | mInstaller.unregisterCallback(delegate); |
| 787 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 788 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 789 | } |
| 790 | i.remove(); |
| 791 | } |
| 792 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 793 | } |
| 794 | } |
| 795 | |
| 796 | /** |
| 797 | * An installation that is being actively staged. For an install to succeed, |
| 798 | * all existing and new packages must have identical package names, version |
| 799 | * codes, and signing certificates. |
| 800 | * <p> |
| 801 | * A session may contain any number of split packages. If the application |
| 802 | * does not yet exist, this session must include a base package. |
| 803 | * <p> |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 804 | * If an APK included in this session is already defined by the existing |
| 805 | * installation (for example, the same split name), the APK in this session |
| 806 | * will replace the existing APK. |
Patrick Baumann | 0aff9b1 | 2018-11-08 14:05:08 +0000 | [diff] [blame] | 807 | * <p> |
| 808 | * In such a case that multiple packages need to be commited simultaneously, |
| 809 | * multiple sessions can be referenced by a single multi-package session. |
| 810 | * This session is created with no package name and calling |
| 811 | * {@link SessionParams#setMultiPackage()} with {@code true}. The |
| 812 | * individual session IDs can be added with {@link #addChildSessionId(int)} |
| 813 | * and commit of the multi-package session will result in all child sessions |
| 814 | * being committed atomically. |
Dario Freni | aac4ba4 | 2018-12-06 15:47:16 +0000 | [diff] [blame] | 815 | * <p> |
| 816 | * If a package requires to be installed only at reboot, the session should |
| 817 | * be marked as a staged session by calling {@link SessionParams#setStaged()} |
| 818 | * with {@code true}. This can also apply to a multi-package session, in |
| 819 | * which case all the packages in the session will be applied at reboot. |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 820 | */ |
Jeff Sharkey | ec55ef0 | 2014-07-08 11:28:00 -0700 | [diff] [blame] | 821 | public static class Session implements Closeable { |
Patrick Baumann | 0aff9b1 | 2018-11-08 14:05:08 +0000 | [diff] [blame] | 822 | /** {@hide} */ |
| 823 | protected final IPackageInstallerSession mSession; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 824 | |
| 825 | /** {@hide} */ |
| 826 | public Session(IPackageInstallerSession session) { |
| 827 | mSession = session; |
| 828 | } |
| 829 | |
Jeff Sharkey | bc7bce3 | 2014-09-05 15:53:05 -0700 | [diff] [blame] | 830 | /** {@hide} */ |
| 831 | @Deprecated |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 832 | public void setProgress(float progress) { |
Jeff Sharkey | bc7bce3 | 2014-09-05 15:53:05 -0700 | [diff] [blame] | 833 | setStagingProgress(progress); |
| 834 | } |
| 835 | |
| 836 | /** |
| 837 | * Set current progress of staging this session. Valid values are |
| 838 | * anywhere between 0 and 1. |
| 839 | * <p> |
| 840 | * Note that this progress may not directly correspond to the value |
| 841 | * reported by {@link SessionCallback#onProgressChanged(int, float)}, as |
| 842 | * the system may carve out a portion of the overall progress to |
| 843 | * represent its own internal installation work. |
| 844 | */ |
| 845 | public void setStagingProgress(float progress) { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 846 | try { |
Jeff Sharkey | a103114 | 2014-07-12 18:09:46 -0700 | [diff] [blame] | 847 | mSession.setClientProgress(progress); |
| 848 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 849 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | a103114 | 2014-07-12 18:09:46 -0700 | [diff] [blame] | 850 | } |
| 851 | } |
| 852 | |
| 853 | /** {@hide} */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 854 | @UnsupportedAppUsage |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 855 | public void addProgress(float progress) { |
Jeff Sharkey | a103114 | 2014-07-12 18:09:46 -0700 | [diff] [blame] | 856 | try { |
| 857 | mSession.addClientProgress(progress); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 858 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 859 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 860 | } |
| 861 | } |
| 862 | |
Jeff Sharkey | 78cc340 | 2014-05-22 10:52:49 -0700 | [diff] [blame] | 863 | /** |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 864 | * Open a stream to write an APK file into the session. |
| 865 | * <p> |
| 866 | * The returned stream will start writing data at the requested offset |
| 867 | * in the underlying file, which can be used to resume a partially |
| 868 | * written file. If a valid file length is specified, the system will |
| 869 | * preallocate the underlying disk space to optimize placement on disk. |
| 870 | * It's strongly recommended to provide a valid file length when known. |
| 871 | * <p> |
| 872 | * You can write data into the returned stream, optionally call |
| 873 | * {@link #fsync(OutputStream)} as needed to ensure bytes have been |
| 874 | * persisted to disk, and then close when finished. All streams must be |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 875 | * closed before calling {@link #commit(IntentSender)}. |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 876 | * |
| 877 | * @param name arbitrary, unique name of your choosing to identify the |
| 878 | * APK being written. You can open a file again for |
| 879 | * additional writes (such as after a reboot) by using the |
| 880 | * same name. This name is only meaningful within the context |
| 881 | * of a single install session. |
| 882 | * @param offsetBytes offset into the file to begin writing at, or 0 to |
| 883 | * start at the beginning of the file. |
| 884 | * @param lengthBytes total size of the file being written, used to |
| 885 | * preallocate the underlying disk space, or -1 if unknown. |
Jeff Sharkey | 77d218e | 2014-09-06 12:20:37 -0700 | [diff] [blame] | 886 | * The system may clear various caches as needed to allocate |
| 887 | * this space. |
| 888 | * @throws IOException if trouble opening the file for writing, such as |
| 889 | * lack of disk space or unavailable media. |
| 890 | * @throws SecurityException if called after the session has been |
Philip P. Moltmann | 7460c59 | 2017-08-08 20:07:11 +0000 | [diff] [blame] | 891 | * sealed or abandoned |
Jeff Sharkey | 78cc340 | 2014-05-22 10:52:49 -0700 | [diff] [blame] | 892 | */ |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 893 | public @NonNull OutputStream openWrite(@NonNull String name, long offsetBytes, |
| 894 | long lengthBytes) throws IOException { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 895 | try { |
Jeff Sharkey | 02d4e34 | 2017-03-10 21:53:48 -0700 | [diff] [blame] | 896 | if (ENABLE_REVOCABLE_FD) { |
| 897 | return new ParcelFileDescriptor.AutoCloseOutputStream( |
| 898 | mSession.openWrite(name, offsetBytes, lengthBytes)); |
| 899 | } else { |
| 900 | final ParcelFileDescriptor clientSocket = mSession.openWrite(name, |
| 901 | offsetBytes, lengthBytes); |
| 902 | return new FileBridge.FileBridgeOutputStream(clientSocket); |
| 903 | } |
Jeff Sharkey | a103114 | 2014-07-12 18:09:46 -0700 | [diff] [blame] | 904 | } catch (RuntimeException e) { |
| 905 | ExceptionUtils.maybeUnwrapIOException(e); |
| 906 | throw e; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 907 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 908 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 909 | } |
Jeff Sharkey | 0451de6 | 2018-02-02 11:27:21 -0700 | [diff] [blame] | 910 | } |
Jeff Sharkey | 02d4e34 | 2017-03-10 21:53:48 -0700 | [diff] [blame] | 911 | |
Jeff Sharkey | 0451de6 | 2018-02-02 11:27:21 -0700 | [diff] [blame] | 912 | /** {@hide} */ |
| 913 | public void write(@NonNull String name, long offsetBytes, long lengthBytes, |
| 914 | @NonNull ParcelFileDescriptor fd) throws IOException { |
| 915 | try { |
| 916 | mSession.write(name, offsetBytes, lengthBytes, fd); |
| 917 | } catch (RuntimeException e) { |
| 918 | ExceptionUtils.maybeUnwrapIOException(e); |
| 919 | throw e; |
| 920 | } catch (RemoteException e) { |
| 921 | throw e.rethrowFromSystemServer(); |
| 922 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 923 | } |
| 924 | |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 925 | /** |
| 926 | * Ensure that any outstanding data for given stream has been committed |
| 927 | * to disk. This is only valid for streams returned from |
| 928 | * {@link #openWrite(String, long, long)}. |
| 929 | */ |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 930 | public void fsync(@NonNull OutputStream out) throws IOException { |
Jeff Sharkey | 02d4e34 | 2017-03-10 21:53:48 -0700 | [diff] [blame] | 931 | if (ENABLE_REVOCABLE_FD) { |
| 932 | if (out instanceof ParcelFileDescriptor.AutoCloseOutputStream) { |
| 933 | try { |
| 934 | Os.fsync(((ParcelFileDescriptor.AutoCloseOutputStream) out).getFD()); |
| 935 | } catch (ErrnoException e) { |
| 936 | throw e.rethrowAsIOException(); |
| 937 | } |
| 938 | } else { |
| 939 | throw new IllegalArgumentException("Unrecognized stream"); |
| 940 | } |
Jeff Sharkey | a103114 | 2014-07-12 18:09:46 -0700 | [diff] [blame] | 941 | } else { |
Jeff Sharkey | 02d4e34 | 2017-03-10 21:53:48 -0700 | [diff] [blame] | 942 | if (out instanceof FileBridge.FileBridgeOutputStream) { |
| 943 | ((FileBridge.FileBridgeOutputStream) out).fsync(); |
| 944 | } else { |
| 945 | throw new IllegalArgumentException("Unrecognized stream"); |
| 946 | } |
Jeff Sharkey | a103114 | 2014-07-12 18:09:46 -0700 | [diff] [blame] | 947 | } |
| 948 | } |
| 949 | |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 950 | /** |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 951 | * Return all APK names contained in this session. |
Jeff Sharkey | 1cb2d0d | 2014-07-30 16:45:01 -0700 | [diff] [blame] | 952 | * <p> |
| 953 | * This returns all names which have been previously written through |
| 954 | * {@link #openWrite(String, long, long)} as part of this session. |
Jeff Sharkey | 77d218e | 2014-09-06 12:20:37 -0700 | [diff] [blame] | 955 | * |
| 956 | * @throws SecurityException if called after the session has been |
| 957 | * committed or abandoned. |
Jeff Sharkey | 1cb2d0d | 2014-07-30 16:45:01 -0700 | [diff] [blame] | 958 | */ |
Jeff Sharkey | 742e790 | 2014-08-16 19:09:13 -0700 | [diff] [blame] | 959 | public @NonNull String[] getNames() throws IOException { |
Jeff Sharkey | 1cb2d0d | 2014-07-30 16:45:01 -0700 | [diff] [blame] | 960 | try { |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 961 | return mSession.getNames(); |
Jeff Sharkey | 742e790 | 2014-08-16 19:09:13 -0700 | [diff] [blame] | 962 | } catch (RuntimeException e) { |
| 963 | ExceptionUtils.maybeUnwrapIOException(e); |
| 964 | throw e; |
Jeff Sharkey | 1cb2d0d | 2014-07-30 16:45:01 -0700 | [diff] [blame] | 965 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 966 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 1cb2d0d | 2014-07-30 16:45:01 -0700 | [diff] [blame] | 967 | } |
| 968 | } |
| 969 | |
| 970 | /** |
| 971 | * Open a stream to read an APK file from the session. |
| 972 | * <p> |
| 973 | * This is only valid for names which have been previously written |
| 974 | * through {@link #openWrite(String, long, long)} as part of this |
| 975 | * session. For example, this stream may be used to calculate a |
| 976 | * {@link MessageDigest} of a written APK before committing. |
Jeff Sharkey | 77d218e | 2014-09-06 12:20:37 -0700 | [diff] [blame] | 977 | * |
| 978 | * @throws SecurityException if called after the session has been |
| 979 | * committed or abandoned. |
Jeff Sharkey | 1cb2d0d | 2014-07-30 16:45:01 -0700 | [diff] [blame] | 980 | */ |
| 981 | public @NonNull InputStream openRead(@NonNull String name) throws IOException { |
| 982 | try { |
| 983 | final ParcelFileDescriptor pfd = mSession.openRead(name); |
| 984 | return new ParcelFileDescriptor.AutoCloseInputStream(pfd); |
| 985 | } catch (RuntimeException e) { |
| 986 | ExceptionUtils.maybeUnwrapIOException(e); |
| 987 | throw e; |
| 988 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 989 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 1cb2d0d | 2014-07-30 16:45:01 -0700 | [diff] [blame] | 990 | } |
| 991 | } |
| 992 | |
| 993 | /** |
Todd Kennedy | eb9b053 | 2016-03-08 10:10:54 -0800 | [diff] [blame] | 994 | * Removes a split. |
| 995 | * <p> |
| 996 | * Split removals occur prior to adding new APKs. If upgrading a feature |
| 997 | * split, it is not expected nor desirable to remove the split prior to |
| 998 | * upgrading. |
| 999 | * <p> |
| 1000 | * When split removal is bundled with new APKs, the packageName must be |
| 1001 | * identical. |
| 1002 | */ |
| 1003 | public void removeSplit(@NonNull String splitName) throws IOException { |
| 1004 | try { |
| 1005 | mSession.removeSplit(splitName); |
| 1006 | } catch (RuntimeException e) { |
| 1007 | ExceptionUtils.maybeUnwrapIOException(e); |
| 1008 | throw e; |
| 1009 | } catch (RemoteException e) { |
| 1010 | throw e.rethrowFromSystemServer(); |
| 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | /** |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 1015 | * Attempt to commit everything staged in this session. This may require |
| 1016 | * user intervention, and so it may not happen immediately. The final |
| 1017 | * result of the commit will be reported through the given callback. |
| 1018 | * <p> |
Todd Kennedy | 04cc191 | 2017-03-03 13:05:12 -0800 | [diff] [blame] | 1019 | * Once this method is called, the session is sealed and no additional |
| 1020 | * mutations may be performed on the session. If the device reboots |
| 1021 | * before the session has been finalized, you may commit the session again. |
Tony Mak | 366ee62 | 2018-02-12 17:52:34 +0000 | [diff] [blame] | 1022 | * <p> |
| 1023 | * If the installer is the device owner or the affiliated profile owner, there will be no |
| 1024 | * user intervention. |
Jeff Sharkey | 77d218e | 2014-09-06 12:20:37 -0700 | [diff] [blame] | 1025 | * |
Philip P. Moltmann | 2fe7dee | 2018-09-14 08:45:42 -0700 | [diff] [blame] | 1026 | * @param statusReceiver Called when the state of the session changes. Intents |
| 1027 | * sent to this receiver contain {@link #EXTRA_STATUS}. Refer to the |
| 1028 | * individual status codes on how to handle them. |
| 1029 | * |
Jeff Sharkey | 77d218e | 2014-09-06 12:20:37 -0700 | [diff] [blame] | 1030 | * @throws SecurityException if streams opened through |
| 1031 | * {@link #openWrite(String, long, long)} are still open. |
Tony Mak | 366ee62 | 2018-02-12 17:52:34 +0000 | [diff] [blame] | 1032 | * |
| 1033 | * @see android.app.admin.DevicePolicyManager |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 1034 | */ |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1035 | public void commit(@NonNull IntentSender statusReceiver) { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1036 | try { |
Philip P. Moltmann | 7460c59 | 2017-08-08 20:07:11 +0000 | [diff] [blame] | 1037 | mSession.commit(statusReceiver, false); |
| 1038 | } catch (RemoteException e) { |
| 1039 | throw e.rethrowFromSystemServer(); |
| 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | /** |
| 1044 | * Attempt to commit a session that has been {@link #transfer(String) transferred}. |
| 1045 | * |
| 1046 | * <p>If the device reboots before the session has been finalized, you may commit the |
| 1047 | * session again. |
| 1048 | * |
| 1049 | * <p>The caller of this method is responsible to ensure the safety of the session. As the |
| 1050 | * session was created by another - usually less trusted - app, it is paramount that before |
| 1051 | * committing <u>all</u> public and system {@link SessionInfo properties of the session} |
| 1052 | * and <u>all</u> {@link #openRead(String) APKs} are verified by the caller. It might happen |
| 1053 | * that new properties are added to the session with a new API revision. In this case the |
| 1054 | * callers need to be updated. |
| 1055 | * |
Philip P. Moltmann | 2fe7dee | 2018-09-14 08:45:42 -0700 | [diff] [blame] | 1056 | * @param statusReceiver Called when the state of the session changes. Intents |
| 1057 | * sent to this receiver contain {@link #EXTRA_STATUS}. Refer to the |
| 1058 | * individual status codes on how to handle them. |
Philip P. Moltmann | 7460c59 | 2017-08-08 20:07:11 +0000 | [diff] [blame] | 1059 | * |
| 1060 | * @hide |
| 1061 | */ |
| 1062 | @SystemApi |
| 1063 | @RequiresPermission(android.Manifest.permission.INSTALL_PACKAGES) |
| 1064 | public void commitTransferred(@NonNull IntentSender statusReceiver) { |
| 1065 | try { |
| 1066 | mSession.commit(statusReceiver, true); |
| 1067 | } catch (RemoteException e) { |
| 1068 | throw e.rethrowFromSystemServer(); |
| 1069 | } |
| 1070 | } |
| 1071 | |
| 1072 | /** |
| 1073 | * Transfer the session to a new owner. |
| 1074 | * <p> |
| 1075 | * Only sessions that update the installing app can be transferred. |
| 1076 | * <p> |
| 1077 | * After the transfer to a package with a different uid all method calls on the session |
| 1078 | * will cause {@link SecurityException}s. |
| 1079 | * <p> |
| 1080 | * Once this method is called, the session is sealed and no additional mutations beside |
| 1081 | * committing it may be performed on the session. |
| 1082 | * |
| 1083 | * @param packageName The package of the new owner. Needs to hold the INSTALL_PACKAGES |
| 1084 | * permission. |
| 1085 | * |
| 1086 | * @throws PackageManager.NameNotFoundException if the new owner could not be found. |
| 1087 | * @throws SecurityException if called after the session has been committed or abandoned. |
| 1088 | * @throws SecurityException if the session does not update the original installer |
| 1089 | * @throws SecurityException if streams opened through |
| 1090 | * {@link #openWrite(String, long, long) are still open. |
| 1091 | */ |
| 1092 | public void transfer(@NonNull String packageName) |
| 1093 | throws PackageManager.NameNotFoundException { |
| 1094 | Preconditions.checkNotNull(packageName); |
| 1095 | |
| 1096 | try { |
| 1097 | mSession.transfer(packageName); |
| 1098 | } catch (ParcelableException e) { |
| 1099 | e.maybeRethrow(PackageManager.NameNotFoundException.class); |
| 1100 | throw new RuntimeException(e); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1101 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1102 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1103 | } |
| 1104 | } |
| 1105 | |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 1106 | /** |
| 1107 | * Release this session object. You can open the session again if it |
| 1108 | * hasn't been finalized. |
| 1109 | */ |
Jeff Sharkey | ec55ef0 | 2014-07-08 11:28:00 -0700 | [diff] [blame] | 1110 | @Override |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1111 | public void close() { |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 1112 | try { |
| 1113 | mSession.close(); |
| 1114 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1115 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 1116 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1117 | } |
| 1118 | |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 1119 | /** |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 1120 | * Completely abandon this session, destroying all staged data and |
Jeff Sharkey | 77d218e | 2014-09-06 12:20:37 -0700 | [diff] [blame] | 1121 | * rendering it invalid. Abandoned sessions will be reported to |
| 1122 | * {@link SessionCallback} listeners as failures. This is equivalent to |
| 1123 | * opening the session and calling {@link Session#abandon()}. |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 1124 | */ |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 1125 | public void abandon() { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1126 | try { |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 1127 | mSession.abandon(); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1128 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1129 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1130 | } |
| 1131 | } |
Patrick Baumann | 0aff9b1 | 2018-11-08 14:05:08 +0000 | [diff] [blame] | 1132 | |
| 1133 | /** |
| 1134 | * @return {@code true} if this session will commit more than one package when it is |
| 1135 | * committed. |
| 1136 | */ |
| 1137 | public boolean isMultiPackage() { |
| 1138 | try { |
| 1139 | return mSession.isMultiPackage(); |
| 1140 | } catch (RemoteException e) { |
| 1141 | throw e.rethrowFromSystemServer(); |
| 1142 | } |
| 1143 | } |
| 1144 | |
| 1145 | /** |
Dario Freni | aac4ba4 | 2018-12-06 15:47:16 +0000 | [diff] [blame] | 1146 | * @return {@code true} if this session will be staged and applied at next reboot. |
| 1147 | */ |
| 1148 | public boolean isStaged() { |
| 1149 | try { |
| 1150 | return mSession.isStaged(); |
| 1151 | } catch (RemoteException e) { |
| 1152 | throw e.rethrowFromSystemServer(); |
| 1153 | } |
| 1154 | } |
| 1155 | |
| 1156 | /** |
Patrick Baumann | 0aff9b1 | 2018-11-08 14:05:08 +0000 | [diff] [blame] | 1157 | * @return the session ID of the multi-package session that this belongs to or |
| 1158 | * {@link SessionInfo#INVALID_ID} if it does not belong to a multi-package session. |
| 1159 | */ |
| 1160 | public int getParentSessionId() { |
| 1161 | try { |
| 1162 | return mSession.getParentSessionId(); |
| 1163 | } catch (RemoteException e) { |
| 1164 | throw e.rethrowFromSystemServer(); |
| 1165 | } |
| 1166 | } |
| 1167 | |
| 1168 | /** |
| 1169 | * @return the set of session IDs that will be committed atomically when this session is |
| 1170 | * committed if this is a multi-package session or null if none exist. |
| 1171 | */ |
| 1172 | @NonNull |
| 1173 | public int[] getChildSessionIds() { |
| 1174 | try { |
| 1175 | return mSession.getChildSessionIds(); |
| 1176 | } catch (RemoteException e) { |
| 1177 | throw e.rethrowFromSystemServer(); |
| 1178 | } |
| 1179 | } |
| 1180 | |
| 1181 | /** |
| 1182 | * Adds a session ID to the set of sessions that will be committed atomically |
| 1183 | * when this session is committed. |
| 1184 | * |
| 1185 | * @param sessionId the session ID to add to this multi-package session. |
| 1186 | */ |
| 1187 | public void addChildSessionId(int sessionId) { |
| 1188 | try { |
| 1189 | mSession.addChildSessionId(sessionId); |
| 1190 | } catch (RemoteException e) { |
| 1191 | throw e.rethrowFromSystemServer(); |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | /** |
| 1196 | * Removes a session ID from the set of sessions that will be committed |
| 1197 | * atomically when this session is committed. |
| 1198 | * |
| 1199 | * @param sessionId the session ID to remove from this multi-package session. |
| 1200 | */ |
| 1201 | public void removeChildSessionId(int sessionId) { |
| 1202 | try { |
| 1203 | mSession.removeChildSessionId(sessionId); |
| 1204 | } catch (RemoteException e) { |
| 1205 | throw e.rethrowFromSystemServer(); |
| 1206 | } |
| 1207 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1208 | } |
Jeff Sharkey | bb58067 | 2014-07-10 12:10:25 -0700 | [diff] [blame] | 1209 | |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 1210 | /** |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1211 | * Parameters for creating a new {@link PackageInstaller.Session}. |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 1212 | */ |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1213 | public static class SessionParams implements Parcelable { |
| 1214 | |
| 1215 | /** {@hide} */ |
| 1216 | public static final int MODE_INVALID = -1; |
Jeff Sharkey | f060095 | 2014-08-07 17:31:53 -0700 | [diff] [blame] | 1217 | |
| 1218 | /** |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1219 | * Mode for an install session whose staged APKs should fully replace any |
| 1220 | * existing APKs for the target app. |
Jeff Sharkey | f060095 | 2014-08-07 17:31:53 -0700 | [diff] [blame] | 1221 | */ |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1222 | public static final int MODE_FULL_INSTALL = 1; |
Jeff Sharkey | f060095 | 2014-08-07 17:31:53 -0700 | [diff] [blame] | 1223 | |
| 1224 | /** |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1225 | * Mode for an install session that should inherit any existing APKs for the |
| 1226 | * target app, unless they have been explicitly overridden (based on split |
| 1227 | * name) by the session. For example, this can be used to add one or more |
| 1228 | * split APKs to an existing installation. |
Jeff Sharkey | fbd0e9f | 2014-08-06 16:34:34 -0700 | [diff] [blame] | 1229 | * <p> |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1230 | * If there are no existing APKs for the target app, this behaves like |
| 1231 | * {@link #MODE_FULL_INSTALL}. |
Jeff Sharkey | fbd0e9f | 2014-08-06 16:34:34 -0700 | [diff] [blame] | 1232 | */ |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1233 | public static final int MODE_INHERIT_EXISTING = 2; |
Jeff Sharkey | fbd0e9f | 2014-08-06 16:34:34 -0700 | [diff] [blame] | 1234 | |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1235 | /** {@hide} */ |
Todd Kennedy | a1d12cf | 2015-09-29 15:43:00 -0700 | [diff] [blame] | 1236 | public static final int UID_UNKNOWN = -1; |
| 1237 | |
| 1238 | /** {@hide} */ |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 1239 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1240 | public int mode = MODE_INVALID; |
| 1241 | /** {@hide} */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 1242 | @UnsupportedAppUsage |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1243 | public int installFlags; |
| 1244 | /** {@hide} */ |
| 1245 | public int installLocation = PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY; |
| 1246 | /** {@hide} */ |
Bartosz Fabianowski | 40a0062 | 2017-04-18 14:39:23 +0200 | [diff] [blame] | 1247 | public @InstallReason int installReason = PackageManager.INSTALL_REASON_UNKNOWN; |
Bartosz Fabianowski | a34f53f | 2017-01-11 18:08:47 +0100 | [diff] [blame] | 1248 | /** {@hide} */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 1249 | @UnsupportedAppUsage |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1250 | public long sizeBytes = -1; |
| 1251 | /** {@hide} */ |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 1252 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1253 | public String appPackageName; |
| 1254 | /** {@hide} */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 1255 | @UnsupportedAppUsage |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1256 | public Bitmap appIcon; |
| 1257 | /** {@hide} */ |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 1258 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1259 | public String appLabel; |
| 1260 | /** {@hide} */ |
Jeff Sharkey | 02bd784 | 2014-10-06 15:14:27 -0700 | [diff] [blame] | 1261 | public long appIconLastModified = -1; |
| 1262 | /** {@hide} */ |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1263 | public Uri originatingUri; |
| 1264 | /** {@hide} */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 1265 | @UnsupportedAppUsage |
Todd Kennedy | a1d12cf | 2015-09-29 15:43:00 -0700 | [diff] [blame] | 1266 | public int originatingUid = UID_UNKNOWN; |
| 1267 | /** {@hide} */ |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1268 | public Uri referrerUri; |
| 1269 | /** {@hide} */ |
| 1270 | public String abiOverride; |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 1271 | /** {@hide} */ |
| 1272 | public String volumeUuid; |
Svet Ganov | 7121e18 | 2015-07-13 22:38:12 -0700 | [diff] [blame] | 1273 | /** {@hide} */ |
| 1274 | public String[] grantedRuntimePermissions; |
Philip P. Moltmann | 79c238a | 2017-12-13 15:59:07 -0800 | [diff] [blame] | 1275 | /** {@hide} */ |
| 1276 | public String installerPackageName; |
Patrick Baumann | 0aff9b1 | 2018-11-08 14:05:08 +0000 | [diff] [blame] | 1277 | /** {@hide} */ |
| 1278 | public boolean isMultiPackage; |
Dario Freni | aac4ba4 | 2018-12-06 15:47:16 +0000 | [diff] [blame] | 1279 | /** {@hide} */ |
| 1280 | public boolean isStaged; |
Jeff Sharkey | bb58067 | 2014-07-10 12:10:25 -0700 | [diff] [blame] | 1281 | |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1282 | /** |
| 1283 | * Construct parameters for a new package install session. |
| 1284 | * |
| 1285 | * @param mode one of {@link #MODE_FULL_INSTALL} or |
| 1286 | * {@link #MODE_INHERIT_EXISTING} describing how the session |
| 1287 | * should interact with an existing app. |
| 1288 | */ |
| 1289 | public SessionParams(int mode) { |
| 1290 | this.mode = mode; |
| 1291 | } |
Jeff Sharkey | bb58067 | 2014-07-10 12:10:25 -0700 | [diff] [blame] | 1292 | |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1293 | /** {@hide} */ |
| 1294 | public SessionParams(Parcel source) { |
| 1295 | mode = source.readInt(); |
| 1296 | installFlags = source.readInt(); |
| 1297 | installLocation = source.readInt(); |
Bartosz Fabianowski | a34f53f | 2017-01-11 18:08:47 +0100 | [diff] [blame] | 1298 | installReason = source.readInt(); |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1299 | sizeBytes = source.readLong(); |
| 1300 | appPackageName = source.readString(); |
| 1301 | appIcon = source.readParcelable(null); |
| 1302 | appLabel = source.readString(); |
| 1303 | originatingUri = source.readParcelable(null); |
Todd Kennedy | a1d12cf | 2015-09-29 15:43:00 -0700 | [diff] [blame] | 1304 | originatingUid = source.readInt(); |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1305 | referrerUri = source.readParcelable(null); |
| 1306 | abiOverride = source.readString(); |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 1307 | volumeUuid = source.readString(); |
Svet Ganov | 7121e18 | 2015-07-13 22:38:12 -0700 | [diff] [blame] | 1308 | grantedRuntimePermissions = source.readStringArray(); |
Philip P. Moltmann | 79c238a | 2017-12-13 15:59:07 -0800 | [diff] [blame] | 1309 | installerPackageName = source.readString(); |
Patrick Baumann | 0aff9b1 | 2018-11-08 14:05:08 +0000 | [diff] [blame] | 1310 | isMultiPackage = source.readBoolean(); |
Dario Freni | aac4ba4 | 2018-12-06 15:47:16 +0000 | [diff] [blame] | 1311 | isStaged = source.readBoolean(); |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | /** |
Philip P. Moltmann | 7460c59 | 2017-08-08 20:07:11 +0000 | [diff] [blame] | 1315 | * Check if there are hidden options set. |
| 1316 | * |
| 1317 | * <p>Hidden options are those options that cannot be verified via public or system-api |
| 1318 | * methods on {@link SessionInfo}. |
| 1319 | * |
| 1320 | * @return {@code true} if any hidden option is set. |
| 1321 | * |
| 1322 | * @hide |
| 1323 | */ |
| 1324 | public boolean areHiddenOptionsSet() { |
| 1325 | return (installFlags & (PackageManager.INSTALL_ALLOW_DOWNGRADE |
| 1326 | | PackageManager.INSTALL_DONT_KILL_APP |
| 1327 | | PackageManager.INSTALL_INSTANT_APP |
| 1328 | | PackageManager.INSTALL_FULL_APP |
| 1329 | | PackageManager.INSTALL_VIRTUAL_PRELOAD |
| 1330 | | PackageManager.INSTALL_ALLOCATE_AGGRESSIVE)) != installFlags |
| 1331 | || abiOverride != null || volumeUuid != null; |
| 1332 | } |
| 1333 | |
| 1334 | /** |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1335 | * Provide value of {@link PackageInfo#installLocation}, which may be used |
| 1336 | * to determine where the app will be staged. Defaults to |
| 1337 | * {@link PackageInfo#INSTALL_LOCATION_INTERNAL_ONLY}. |
| 1338 | */ |
| 1339 | public void setInstallLocation(int installLocation) { |
| 1340 | this.installLocation = installLocation; |
| 1341 | } |
| 1342 | |
| 1343 | /** |
| 1344 | * Optionally indicate the total size (in bytes) of all APKs that will be |
| 1345 | * delivered in this session. The system may use this to ensure enough disk |
| 1346 | * space exists before proceeding, or to estimate container size for |
| 1347 | * installations living on external storage. |
| 1348 | * |
| 1349 | * @see PackageInfo#INSTALL_LOCATION_AUTO |
| 1350 | * @see PackageInfo#INSTALL_LOCATION_PREFER_EXTERNAL |
| 1351 | */ |
| 1352 | public void setSize(long sizeBytes) { |
| 1353 | this.sizeBytes = sizeBytes; |
| 1354 | } |
| 1355 | |
| 1356 | /** |
| 1357 | * Optionally set the package name of the app being installed. It's strongly |
| 1358 | * recommended that you provide this value when known, so that observers can |
| 1359 | * communicate installing apps to users. |
| 1360 | * <p> |
| 1361 | * If the APKs staged in the session aren't consistent with this package |
| 1362 | * name, the install will fail. Regardless of this value, all APKs in the |
| 1363 | * app must have the same package name. |
| 1364 | */ |
| 1365 | public void setAppPackageName(@Nullable String appPackageName) { |
| 1366 | this.appPackageName = appPackageName; |
| 1367 | } |
| 1368 | |
| 1369 | /** |
| 1370 | * Optionally set an icon representing the app being installed. This should |
| 1371 | * be roughly {@link ActivityManager#getLauncherLargeIconSize()} in both |
| 1372 | * dimensions. |
| 1373 | */ |
| 1374 | public void setAppIcon(@Nullable Bitmap appIcon) { |
| 1375 | this.appIcon = appIcon; |
| 1376 | } |
| 1377 | |
| 1378 | /** |
| 1379 | * Optionally set a label representing the app being installed. |
| 1380 | */ |
| 1381 | public void setAppLabel(@Nullable CharSequence appLabel) { |
| 1382 | this.appLabel = (appLabel != null) ? appLabel.toString() : null; |
| 1383 | } |
| 1384 | |
| 1385 | /** |
Todd Kennedy | 1ed6b87 | 2016-03-10 10:07:00 -0800 | [diff] [blame] | 1386 | * Optionally set the URI where this package was downloaded from. This is |
| 1387 | * informational and may be used as a signal for anti-malware purposes. |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1388 | * |
| 1389 | * @see Intent#EXTRA_ORIGINATING_URI |
| 1390 | */ |
| 1391 | public void setOriginatingUri(@Nullable Uri originatingUri) { |
| 1392 | this.originatingUri = originatingUri; |
| 1393 | } |
| 1394 | |
| 1395 | /** |
Nikolas Bravo | 6283100 | 2017-11-07 21:07:15 +0000 | [diff] [blame] | 1396 | * Sets the UID that initiated the package installation. This is informational |
Todd Kennedy | 1ed6b87 | 2016-03-10 10:07:00 -0800 | [diff] [blame] | 1397 | * and may be used as a signal for anti-malware purposes. |
Todd Kennedy | a1d12cf | 2015-09-29 15:43:00 -0700 | [diff] [blame] | 1398 | */ |
| 1399 | public void setOriginatingUid(int originatingUid) { |
| 1400 | this.originatingUid = originatingUid; |
| 1401 | } |
| 1402 | |
| 1403 | /** |
Todd Kennedy | 1ed6b87 | 2016-03-10 10:07:00 -0800 | [diff] [blame] | 1404 | * Optionally set the URI that referred you to install this package. This is |
| 1405 | * informational and may be used as a signal for anti-malware purposes. |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1406 | * |
| 1407 | * @see Intent#EXTRA_REFERRER |
| 1408 | */ |
| 1409 | public void setReferrerUri(@Nullable Uri referrerUri) { |
| 1410 | this.referrerUri = referrerUri; |
| 1411 | } |
| 1412 | |
Svet Ganov | 7121e18 | 2015-07-13 22:38:12 -0700 | [diff] [blame] | 1413 | /** |
| 1414 | * Sets which runtime permissions to be granted to the package at installation. |
Svet Ganov | 7121e18 | 2015-07-13 22:38:12 -0700 | [diff] [blame] | 1415 | * |
| 1416 | * @param permissions The permissions to grant or null to grant all runtime |
| 1417 | * permissions. |
| 1418 | * |
| 1419 | * @hide |
| 1420 | */ |
| 1421 | @SystemApi |
| 1422 | @RequiresPermission(android.Manifest.permission.INSTALL_GRANT_RUNTIME_PERMISSIONS) |
| 1423 | public void setGrantedRuntimePermissions(String[] permissions) { |
| 1424 | installFlags |= PackageManager.INSTALL_GRANT_RUNTIME_PERMISSIONS; |
| 1425 | this.grantedRuntimePermissions = permissions; |
| 1426 | } |
| 1427 | |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 1428 | /** |
| 1429 | * Request that rollbacks be enabled for the given upgrade. |
Richard Uhler | c739c8c | 2018-12-12 11:03:34 +0000 | [diff] [blame] | 1430 | * @hide |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 1431 | */ |
Richard Uhler | c739c8c | 2018-12-12 11:03:34 +0000 | [diff] [blame] | 1432 | @SystemApi |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 1433 | public void setEnableRollback() { |
| 1434 | installFlags |= PackageManager.INSTALL_ENABLE_ROLLBACK; |
| 1435 | } |
| 1436 | |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1437 | /** {@hide} */ |
Todd Kennedy | c84d1ab | 2016-03-11 11:37:17 -0800 | [diff] [blame] | 1438 | @SystemApi |
Todd Kennedy | 948b702 | 2016-03-14 14:29:52 -0700 | [diff] [blame] | 1439 | public void setAllowDowngrade(boolean allowDowngrade) { |
| 1440 | if (allowDowngrade) { |
| 1441 | installFlags |= PackageManager.INSTALL_ALLOW_DOWNGRADE; |
| 1442 | } else { |
| 1443 | installFlags &= ~PackageManager.INSTALL_ALLOW_DOWNGRADE; |
| 1444 | } |
Todd Kennedy | c84d1ab | 2016-03-11 11:37:17 -0800 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | /** {@hide} */ |
Todd Kennedy | a1d12cf | 2015-09-29 15:43:00 -0700 | [diff] [blame] | 1448 | public void setInstallFlagsForcePermissionPrompt() { |
| 1449 | installFlags |= PackageManager.INSTALL_FORCE_PERMISSION_PROMPT; |
| 1450 | } |
| 1451 | |
| 1452 | /** {@hide} */ |
Todd Kennedy | 24ca5c6 | 2016-03-16 15:42:01 -0700 | [diff] [blame] | 1453 | @SystemApi |
| 1454 | public void setDontKillApp(boolean dontKillApp) { |
| 1455 | if (dontKillApp) { |
| 1456 | installFlags |= PackageManager.INSTALL_DONT_KILL_APP; |
| 1457 | } else { |
| 1458 | installFlags &= ~PackageManager.INSTALL_DONT_KILL_APP; |
| 1459 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | /** {@hide} */ |
Todd Kennedy | b771768 | 2016-11-30 15:41:21 -0800 | [diff] [blame] | 1463 | @SystemApi |
| 1464 | public void setInstallAsInstantApp(boolean isInstantApp) { |
| 1465 | if (isInstantApp) { |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 1466 | installFlags |= PackageManager.INSTALL_INSTANT_APP; |
| 1467 | installFlags &= ~PackageManager.INSTALL_FULL_APP; |
Todd Kennedy | b771768 | 2016-11-30 15:41:21 -0800 | [diff] [blame] | 1468 | } else { |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 1469 | installFlags &= ~PackageManager.INSTALL_INSTANT_APP; |
| 1470 | installFlags |= PackageManager.INSTALL_FULL_APP; |
Todd Kennedy | b771768 | 2016-11-30 15:41:21 -0800 | [diff] [blame] | 1471 | } |
| 1472 | } |
| 1473 | |
Bartosz Fabianowski | 40a0062 | 2017-04-18 14:39:23 +0200 | [diff] [blame] | 1474 | /** |
Todd Kennedy | 78a7250 | 2017-07-19 12:49:30 -0700 | [diff] [blame] | 1475 | * Sets the install as a virtual preload. Will only have effect when called |
| 1476 | * by the verifier. |
| 1477 | * {@hide} |
| 1478 | */ |
| 1479 | @SystemApi |
| 1480 | public void setInstallAsVirtualPreload() { |
| 1481 | installFlags |= PackageManager.INSTALL_VIRTUAL_PRELOAD; |
| 1482 | } |
| 1483 | |
| 1484 | /** |
Bartosz Fabianowski | 40a0062 | 2017-04-18 14:39:23 +0200 | [diff] [blame] | 1485 | * Set the reason for installing this package. |
Todd Kennedy | 5fdbabb | 2018-03-07 15:59:41 -0800 | [diff] [blame] | 1486 | * <p> |
| 1487 | * The install reason should be a pre-defined integer. The behavior is |
| 1488 | * undefined if other values are used. |
| 1489 | * |
Aurimas Liutikas | 7f69533 | 2018-05-31 21:07:32 -0700 | [diff] [blame] | 1490 | * @see PackageManager#INSTALL_REASON_UNKNOWN |
| 1491 | * @see PackageManager#INSTALL_REASON_POLICY |
| 1492 | * @see PackageManager#INSTALL_REASON_DEVICE_RESTORE |
| 1493 | * @see PackageManager#INSTALL_REASON_DEVICE_SETUP |
Todd Kennedy | 5fdbabb | 2018-03-07 15:59:41 -0800 | [diff] [blame] | 1494 | * @see PackageManager#INSTALL_REASON_USER |
Bartosz Fabianowski | 40a0062 | 2017-04-18 14:39:23 +0200 | [diff] [blame] | 1495 | */ |
| 1496 | public void setInstallReason(@InstallReason int installReason) { |
Bartosz Fabianowski | a34f53f | 2017-01-11 18:08:47 +0100 | [diff] [blame] | 1497 | this.installReason = installReason; |
| 1498 | } |
| 1499 | |
Todd Kennedy | b771768 | 2016-11-30 15:41:21 -0800 | [diff] [blame] | 1500 | /** {@hide} */ |
Jeff Sharkey | 683bcd3 | 2017-03-18 17:54:51 -0600 | [diff] [blame] | 1501 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1502 | @RequiresPermission(android.Manifest.permission.ALLOCATE_AGGRESSIVE) |
Jeff Sharkey | 683bcd3 | 2017-03-18 17:54:51 -0600 | [diff] [blame] | 1503 | public void setAllocateAggressive(boolean allocateAggressive) { |
| 1504 | if (allocateAggressive) { |
| 1505 | installFlags |= PackageManager.INSTALL_ALLOCATE_AGGRESSIVE; |
| 1506 | } else { |
| 1507 | installFlags &= ~PackageManager.INSTALL_ALLOCATE_AGGRESSIVE; |
| 1508 | } |
| 1509 | } |
| 1510 | |
Philip P. Moltmann | 79c238a | 2017-12-13 15:59:07 -0800 | [diff] [blame] | 1511 | /** |
| 1512 | * Set the installer package for the app. |
| 1513 | * |
| 1514 | * By default this is the app that created the {@link PackageInstaller} object. |
| 1515 | * |
| 1516 | * @param installerPackageName name of the installer package |
| 1517 | * {@hide} |
| 1518 | */ |
| 1519 | public void setInstallerPackageName(String installerPackageName) { |
| 1520 | this.installerPackageName = installerPackageName; |
| 1521 | } |
| 1522 | |
Patrick Baumann | 0aff9b1 | 2018-11-08 14:05:08 +0000 | [diff] [blame] | 1523 | /** |
| 1524 | * Set this session to be the parent of a multi-package install. |
| 1525 | * |
| 1526 | * A multi-package install session contains no APKs and only references other install |
| 1527 | * sessions via ID. When a multi-package session is committed, all of its children |
| 1528 | * are committed to the system in an atomic manner. If any children fail to install, |
| 1529 | * all of them do, including the multi-package session. |
| 1530 | */ |
| 1531 | public void setMultiPackage() { |
| 1532 | this.isMultiPackage = true; |
| 1533 | } |
| 1534 | |
Dario Freni | aac4ba4 | 2018-12-06 15:47:16 +0000 | [diff] [blame] | 1535 | /** |
| 1536 | * Set this session to be staged to be installed at reboot. |
| 1537 | * |
| 1538 | * Staged sessions are scheduled to be installed at next reboot. Staged sessions can also be |
| 1539 | * multi-package. In that case, if any of the children sessions fail to install at reboot, |
| 1540 | * all the other children sessions are aborted as well. |
| 1541 | */ |
| 1542 | public void setStaged() { |
| 1543 | this.isStaged = true; |
| 1544 | } |
| 1545 | |
Dario Freni | 3fa46d8 | 2019-01-23 19:31:47 +0000 | [diff] [blame] | 1546 | /** |
| 1547 | * Set this session to be installing an APEX package. |
| 1548 | */ |
| 1549 | public void setInstallAsApex() { |
| 1550 | installFlags |= PackageManager.INSTALL_APEX; |
| 1551 | } |
| 1552 | |
Jeff Sharkey | 683bcd3 | 2017-03-18 17:54:51 -0600 | [diff] [blame] | 1553 | /** {@hide} */ |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1554 | public void dump(IndentingPrintWriter pw) { |
| 1555 | pw.printPair("mode", mode); |
| 1556 | pw.printHexPair("installFlags", installFlags); |
| 1557 | pw.printPair("installLocation", installLocation); |
| 1558 | pw.printPair("sizeBytes", sizeBytes); |
| 1559 | pw.printPair("appPackageName", appPackageName); |
| 1560 | pw.printPair("appIcon", (appIcon != null)); |
| 1561 | pw.printPair("appLabel", appLabel); |
| 1562 | pw.printPair("originatingUri", originatingUri); |
Todd Kennedy | a1d12cf | 2015-09-29 15:43:00 -0700 | [diff] [blame] | 1563 | pw.printPair("originatingUid", originatingUid); |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1564 | pw.printPair("referrerUri", referrerUri); |
| 1565 | pw.printPair("abiOverride", abiOverride); |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 1566 | pw.printPair("volumeUuid", volumeUuid); |
Svet Ganov | 7121e18 | 2015-07-13 22:38:12 -0700 | [diff] [blame] | 1567 | pw.printPair("grantedRuntimePermissions", grantedRuntimePermissions); |
Philip P. Moltmann | 79c238a | 2017-12-13 15:59:07 -0800 | [diff] [blame] | 1568 | pw.printPair("installerPackageName", installerPackageName); |
Patrick Baumann | 0aff9b1 | 2018-11-08 14:05:08 +0000 | [diff] [blame] | 1569 | pw.printPair("isMultiPackage", isMultiPackage); |
Dario Freni | aac4ba4 | 2018-12-06 15:47:16 +0000 | [diff] [blame] | 1570 | pw.printPair("isStaged", isStaged); |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1571 | pw.println(); |
Jeff Sharkey | bb58067 | 2014-07-10 12:10:25 -0700 | [diff] [blame] | 1572 | } |
| 1573 | |
| 1574 | @Override |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1575 | public int describeContents() { |
| 1576 | return 0; |
Jeff Sharkey | fbd0e9f | 2014-08-06 16:34:34 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | @Override |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1580 | public void writeToParcel(Parcel dest, int flags) { |
| 1581 | dest.writeInt(mode); |
| 1582 | dest.writeInt(installFlags); |
| 1583 | dest.writeInt(installLocation); |
Bartosz Fabianowski | a34f53f | 2017-01-11 18:08:47 +0100 | [diff] [blame] | 1584 | dest.writeInt(installReason); |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1585 | dest.writeLong(sizeBytes); |
| 1586 | dest.writeString(appPackageName); |
| 1587 | dest.writeParcelable(appIcon, flags); |
| 1588 | dest.writeString(appLabel); |
| 1589 | dest.writeParcelable(originatingUri, flags); |
Todd Kennedy | a1d12cf | 2015-09-29 15:43:00 -0700 | [diff] [blame] | 1590 | dest.writeInt(originatingUid); |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1591 | dest.writeParcelable(referrerUri, flags); |
| 1592 | dest.writeString(abiOverride); |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 1593 | dest.writeString(volumeUuid); |
Svet Ganov | 7121e18 | 2015-07-13 22:38:12 -0700 | [diff] [blame] | 1594 | dest.writeStringArray(grantedRuntimePermissions); |
Philip P. Moltmann | 79c238a | 2017-12-13 15:59:07 -0800 | [diff] [blame] | 1595 | dest.writeString(installerPackageName); |
Patrick Baumann | 0aff9b1 | 2018-11-08 14:05:08 +0000 | [diff] [blame] | 1596 | dest.writeBoolean(isMultiPackage); |
Dario Freni | aac4ba4 | 2018-12-06 15:47:16 +0000 | [diff] [blame] | 1597 | dest.writeBoolean(isStaged); |
Jeff Sharkey | bb58067 | 2014-07-10 12:10:25 -0700 | [diff] [blame] | 1598 | } |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1599 | |
| 1600 | public static final Parcelable.Creator<SessionParams> |
| 1601 | CREATOR = new Parcelable.Creator<SessionParams>() { |
| 1602 | @Override |
| 1603 | public SessionParams createFromParcel(Parcel p) { |
| 1604 | return new SessionParams(p); |
| 1605 | } |
| 1606 | |
| 1607 | @Override |
| 1608 | public SessionParams[] newArray(int size) { |
| 1609 | return new SessionParams[size]; |
| 1610 | } |
| 1611 | }; |
Jeff Sharkey | bb58067 | 2014-07-10 12:10:25 -0700 | [diff] [blame] | 1612 | } |
| 1613 | |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 1614 | /** |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1615 | * Details for an active install session. |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 1616 | */ |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1617 | public static class SessionInfo implements Parcelable { |
| 1618 | |
Patrick Baumann | 0aff9b1 | 2018-11-08 14:05:08 +0000 | [diff] [blame] | 1619 | /** |
| 1620 | * A session ID that does not exist or is invalid. |
| 1621 | */ |
| 1622 | public static final int INVALID_ID = -1; |
| 1623 | /** {@hide} */ |
| 1624 | private static final int[] NO_SESSIONS = {}; |
Dario Freni | 71eee5e | 2018-12-06 15:47:16 +0000 | [diff] [blame] | 1625 | |
| 1626 | /** @hide */ |
| 1627 | @IntDef(value = {NO_ERROR, VERIFICATION_FAILED, ACTIVATION_FAILED}) |
| 1628 | @Retention(RetentionPolicy.SOURCE) |
| 1629 | public @interface StagedSessionErrorCode{} |
| 1630 | /** |
| 1631 | * Constant indicating that no error occurred during the preparation or the activation of |
| 1632 | * this staged session. |
| 1633 | */ |
| 1634 | public static final int NO_ERROR = 0; |
| 1635 | |
| 1636 | /** |
| 1637 | * Constant indicating that an error occurred during the verification phase (pre-reboot) of |
| 1638 | * this staged session. |
| 1639 | */ |
| 1640 | public static final int VERIFICATION_FAILED = 1; |
| 1641 | |
| 1642 | /** |
| 1643 | * Constant indicating that an error occurred during the activation phase (post-reboot) of |
| 1644 | * this staged session. |
| 1645 | */ |
| 1646 | public static final int ACTIVATION_FAILED = 2; |
| 1647 | |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1648 | /** {@hide} */ |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 1649 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1650 | public int sessionId; |
| 1651 | /** {@hide} */ |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 1652 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1653 | public String installerPackageName; |
| 1654 | /** {@hide} */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 1655 | @UnsupportedAppUsage |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1656 | public String resolvedBaseCodePath; |
| 1657 | /** {@hide} */ |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 1658 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1659 | public float progress; |
| 1660 | /** {@hide} */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 1661 | @UnsupportedAppUsage |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1662 | public boolean sealed; |
| 1663 | /** {@hide} */ |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 1664 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Jeff Sharkey | bc7bce3 | 2014-09-05 15:53:05 -0700 | [diff] [blame] | 1665 | public boolean active; |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1666 | |
| 1667 | /** {@hide} */ |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 1668 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1669 | public int mode; |
| 1670 | /** {@hide} */ |
Bartosz Fabianowski | 40a0062 | 2017-04-18 14:39:23 +0200 | [diff] [blame] | 1671 | public @InstallReason int installReason; |
Sunny Goyal | 6d7cb23 | 2017-01-30 10:43:18 -0800 | [diff] [blame] | 1672 | /** {@hide} */ |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 1673 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1674 | public long sizeBytes; |
| 1675 | /** {@hide} */ |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 1676 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1677 | public String appPackageName; |
| 1678 | /** {@hide} */ |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 1679 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1680 | public Bitmap appIcon; |
| 1681 | /** {@hide} */ |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 1682 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1683 | public CharSequence appLabel; |
| 1684 | |
| 1685 | /** {@hide} */ |
Philip P. Moltmann | 7460c59 | 2017-08-08 20:07:11 +0000 | [diff] [blame] | 1686 | public int installLocation; |
| 1687 | /** {@hide} */ |
| 1688 | public Uri originatingUri; |
| 1689 | /** {@hide} */ |
| 1690 | public int originatingUid; |
| 1691 | /** {@hide} */ |
| 1692 | public Uri referrerUri; |
| 1693 | /** {@hide} */ |
| 1694 | public String[] grantedRuntimePermissions; |
| 1695 | /** {@hide} */ |
| 1696 | public int installFlags; |
Patrick Baumann | 0aff9b1 | 2018-11-08 14:05:08 +0000 | [diff] [blame] | 1697 | /** {@hide} */ |
| 1698 | public boolean isMultiPackage; |
| 1699 | /** {@hide} */ |
Dario Freni | aac4ba4 | 2018-12-06 15:47:16 +0000 | [diff] [blame] | 1700 | public boolean isStaged; |
| 1701 | /** {@hide} */ |
Patrick Baumann | 0aff9b1 | 2018-11-08 14:05:08 +0000 | [diff] [blame] | 1702 | public int parentSessionId = INVALID_ID; |
| 1703 | /** {@hide} */ |
| 1704 | public int[] childSessionIds = NO_SESSIONS; |
Philip P. Moltmann | 7460c59 | 2017-08-08 20:07:11 +0000 | [diff] [blame] | 1705 | |
| 1706 | /** {@hide} */ |
Dario Freni | 71eee5e | 2018-12-06 15:47:16 +0000 | [diff] [blame] | 1707 | public boolean isSessionApplied; |
| 1708 | /** {@hide} */ |
| 1709 | public boolean isSessionReady; |
| 1710 | /** {@hide} */ |
| 1711 | public boolean isSessionFailed; |
| 1712 | private int mStagedSessionErrorCode; |
Dario Freni | 275b4ab | 2019-01-25 09:55:16 +0000 | [diff] [blame] | 1713 | private String mStagedSessionErrorMessage; |
Dario Freni | 71eee5e | 2018-12-06 15:47:16 +0000 | [diff] [blame] | 1714 | |
| 1715 | /** {@hide} */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 1716 | @UnsupportedAppUsage |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1717 | public SessionInfo() { |
| 1718 | } |
| 1719 | |
| 1720 | /** {@hide} */ |
| 1721 | public SessionInfo(Parcel source) { |
| 1722 | sessionId = source.readInt(); |
| 1723 | installerPackageName = source.readString(); |
| 1724 | resolvedBaseCodePath = source.readString(); |
| 1725 | progress = source.readFloat(); |
| 1726 | sealed = source.readInt() != 0; |
Jeff Sharkey | bc7bce3 | 2014-09-05 15:53:05 -0700 | [diff] [blame] | 1727 | active = source.readInt() != 0; |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1728 | |
| 1729 | mode = source.readInt(); |
Sunny Goyal | 6d7cb23 | 2017-01-30 10:43:18 -0800 | [diff] [blame] | 1730 | installReason = source.readInt(); |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1731 | sizeBytes = source.readLong(); |
| 1732 | appPackageName = source.readString(); |
| 1733 | appIcon = source.readParcelable(null); |
| 1734 | appLabel = source.readString(); |
Philip P. Moltmann | 7460c59 | 2017-08-08 20:07:11 +0000 | [diff] [blame] | 1735 | |
| 1736 | installLocation = source.readInt(); |
| 1737 | originatingUri = source.readParcelable(null); |
| 1738 | originatingUid = source.readInt(); |
| 1739 | referrerUri = source.readParcelable(null); |
| 1740 | grantedRuntimePermissions = source.readStringArray(); |
| 1741 | installFlags = source.readInt(); |
Patrick Baumann | 0aff9b1 | 2018-11-08 14:05:08 +0000 | [diff] [blame] | 1742 | isMultiPackage = source.readBoolean(); |
Dario Freni | aac4ba4 | 2018-12-06 15:47:16 +0000 | [diff] [blame] | 1743 | isStaged = source.readBoolean(); |
Patrick Baumann | 0aff9b1 | 2018-11-08 14:05:08 +0000 | [diff] [blame] | 1744 | parentSessionId = source.readInt(); |
| 1745 | childSessionIds = source.createIntArray(); |
| 1746 | if (childSessionIds == null) { |
| 1747 | childSessionIds = NO_SESSIONS; |
| 1748 | } |
Dario Freni | 71eee5e | 2018-12-06 15:47:16 +0000 | [diff] [blame] | 1749 | isSessionApplied = source.readBoolean(); |
| 1750 | isSessionReady = source.readBoolean(); |
| 1751 | isSessionFailed = source.readBoolean(); |
| 1752 | mStagedSessionErrorCode = source.readInt(); |
Dario Freni | 275b4ab | 2019-01-25 09:55:16 +0000 | [diff] [blame] | 1753 | mStagedSessionErrorMessage = source.readString(); |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1754 | } |
Jeff Sharkey | bb58067 | 2014-07-10 12:10:25 -0700 | [diff] [blame] | 1755 | |
| 1756 | /** |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1757 | * Return the ID for this session. |
Jeff Sharkey | bb58067 | 2014-07-10 12:10:25 -0700 | [diff] [blame] | 1758 | */ |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1759 | public int getSessionId() { |
| 1760 | return sessionId; |
| 1761 | } |
Jeff Sharkey | bb58067 | 2014-07-10 12:10:25 -0700 | [diff] [blame] | 1762 | |
| 1763 | /** |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1764 | * Return the package name of the app that owns this session. |
| 1765 | */ |
| 1766 | public @Nullable String getInstallerPackageName() { |
| 1767 | return installerPackageName; |
| 1768 | } |
| 1769 | |
| 1770 | /** |
| 1771 | * Return current overall progress of this session, between 0 and 1. |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 1772 | * <p> |
Jeff Sharkey | bc7bce3 | 2014-09-05 15:53:05 -0700 | [diff] [blame] | 1773 | * Note that this progress may not directly correspond to the value |
| 1774 | * reported by |
| 1775 | * {@link PackageInstaller.Session#setStagingProgress(float)}, as the |
| 1776 | * system may carve out a portion of the overall progress to represent |
| 1777 | * its own internal installation work. |
Jeff Sharkey | bb58067 | 2014-07-10 12:10:25 -0700 | [diff] [blame] | 1778 | */ |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1779 | public float getProgress() { |
| 1780 | return progress; |
| 1781 | } |
Jeff Sharkey | bb58067 | 2014-07-10 12:10:25 -0700 | [diff] [blame] | 1782 | |
| 1783 | /** |
Jeff Sharkey | bc7bce3 | 2014-09-05 15:53:05 -0700 | [diff] [blame] | 1784 | * Return if this session is currently active. |
| 1785 | * <p> |
| 1786 | * A session is considered active whenever there is ongoing forward |
| 1787 | * progress being made, such as the installer holding an open |
| 1788 | * {@link Session} instance while streaming data into place, or the |
| 1789 | * system optimizing code as the result of |
| 1790 | * {@link Session#commit(IntentSender)}. |
| 1791 | * <p> |
| 1792 | * If the installer closes the {@link Session} without committing, the |
| 1793 | * session is considered inactive until the installer opens the session |
| 1794 | * again. |
Jeff Sharkey | bb58067 | 2014-07-10 12:10:25 -0700 | [diff] [blame] | 1795 | */ |
Jeff Sharkey | bc7bce3 | 2014-09-05 15:53:05 -0700 | [diff] [blame] | 1796 | public boolean isActive() { |
| 1797 | return active; |
| 1798 | } |
| 1799 | |
Sunny Goyal | 6d7cb23 | 2017-01-30 10:43:18 -0800 | [diff] [blame] | 1800 | /** |
Todd Kennedy | 04cc191 | 2017-03-03 13:05:12 -0800 | [diff] [blame] | 1801 | * Return if this session is sealed. |
| 1802 | * <p> |
| 1803 | * Once sealed, no further changes may be made to the session. A session |
| 1804 | * is sealed the moment {@link Session#commit(IntentSender)} is called. |
| 1805 | */ |
| 1806 | public boolean isSealed() { |
| 1807 | return sealed; |
| 1808 | } |
| 1809 | |
| 1810 | /** |
Sunny Goyal | 6d7cb23 | 2017-01-30 10:43:18 -0800 | [diff] [blame] | 1811 | * Return the reason for installing this package. |
| 1812 | * |
Bartosz Fabianowski | 40a0062 | 2017-04-18 14:39:23 +0200 | [diff] [blame] | 1813 | * @return The install reason. |
Sunny Goyal | 6d7cb23 | 2017-01-30 10:43:18 -0800 | [diff] [blame] | 1814 | */ |
Bartosz Fabianowski | 40a0062 | 2017-04-18 14:39:23 +0200 | [diff] [blame] | 1815 | public @InstallReason int getInstallReason() { |
Sunny Goyal | 6d7cb23 | 2017-01-30 10:43:18 -0800 | [diff] [blame] | 1816 | return installReason; |
| 1817 | } |
| 1818 | |
Jeff Sharkey | bc7bce3 | 2014-09-05 15:53:05 -0700 | [diff] [blame] | 1819 | /** {@hide} */ |
| 1820 | @Deprecated |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1821 | public boolean isOpen() { |
Jeff Sharkey | bc7bce3 | 2014-09-05 15:53:05 -0700 | [diff] [blame] | 1822 | return isActive(); |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1823 | } |
Jeff Sharkey | bb58067 | 2014-07-10 12:10:25 -0700 | [diff] [blame] | 1824 | |
| 1825 | /** |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1826 | * Return the package name this session is working with. May be {@code null} |
| 1827 | * if unknown. |
Jeff Sharkey | bb58067 | 2014-07-10 12:10:25 -0700 | [diff] [blame] | 1828 | */ |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1829 | public @Nullable String getAppPackageName() { |
| 1830 | return appPackageName; |
| 1831 | } |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 1832 | |
Jeff Sharkey | 7328a1b | 2014-08-07 14:01:43 -0700 | [diff] [blame] | 1833 | /** |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1834 | * Return an icon representing the app being installed. May be {@code null} |
| 1835 | * if unavailable. |
| 1836 | */ |
| 1837 | public @Nullable Bitmap getAppIcon() { |
Jeff Sharkey | da1247a | 2017-06-08 14:13:29 -0600 | [diff] [blame] | 1838 | if (appIcon == null) { |
| 1839 | // Icon may have been omitted for calls that return bulk session |
| 1840 | // lists, so try fetching the specific icon. |
| 1841 | try { |
Jeff Sharkey | d1dd2c6 | 2017-08-02 09:28:53 -0600 | [diff] [blame] | 1842 | final SessionInfo info = AppGlobals.getPackageManager().getPackageInstaller() |
| 1843 | .getSessionInfo(sessionId); |
| 1844 | appIcon = (info != null) ? info.appIcon : null; |
Jeff Sharkey | da1247a | 2017-06-08 14:13:29 -0600 | [diff] [blame] | 1845 | } catch (RemoteException e) { |
| 1846 | throw e.rethrowFromSystemServer(); |
| 1847 | } |
| 1848 | } |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1849 | return appIcon; |
| 1850 | } |
| 1851 | |
| 1852 | /** |
| 1853 | * Return a label representing the app being installed. May be {@code null} |
| 1854 | * if unavailable. |
| 1855 | */ |
| 1856 | public @Nullable CharSequence getAppLabel() { |
| 1857 | return appLabel; |
| 1858 | } |
| 1859 | |
| 1860 | /** |
| 1861 | * Return an Intent that can be started to view details about this install |
| 1862 | * session. This may surface actions such as pause, resume, or cancel. |
| 1863 | * <p> |
| 1864 | * In some cases, a matching Activity may not exist, so ensure you safeguard |
| 1865 | * against this. |
Jeff Sharkey | 7328a1b | 2014-08-07 14:01:43 -0700 | [diff] [blame] | 1866 | * |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1867 | * @see PackageInstaller#ACTION_SESSION_DETAILS |
Jeff Sharkey | 7328a1b | 2014-08-07 14:01:43 -0700 | [diff] [blame] | 1868 | */ |
Jeff Sharkey | de74231 | 2014-09-15 14:04:56 -0700 | [diff] [blame] | 1869 | public @Nullable Intent createDetailsIntent() { |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 1870 | final Intent intent = new Intent(PackageInstaller.ACTION_SESSION_DETAILS); |
| 1871 | intent.putExtra(PackageInstaller.EXTRA_SESSION_ID, sessionId); |
| 1872 | intent.setPackage(installerPackageName); |
| 1873 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1874 | return intent; |
Jeff Sharkey | bb58067 | 2014-07-10 12:10:25 -0700 | [diff] [blame] | 1875 | } |
| 1876 | |
Philip P. Moltmann | 7460c59 | 2017-08-08 20:07:11 +0000 | [diff] [blame] | 1877 | /** |
| 1878 | * Get the mode of the session as set in the constructor of the {@link SessionParams}. |
| 1879 | * |
| 1880 | * @return One of {@link SessionParams#MODE_FULL_INSTALL} |
| 1881 | * or {@link SessionParams#MODE_INHERIT_EXISTING} |
| 1882 | */ |
| 1883 | public int getMode() { |
| 1884 | return mode; |
| 1885 | } |
| 1886 | |
| 1887 | /** |
| 1888 | * Get the value set in {@link SessionParams#setInstallLocation(int)}. |
| 1889 | */ |
| 1890 | public int getInstallLocation() { |
| 1891 | return installLocation; |
| 1892 | } |
| 1893 | |
| 1894 | /** |
| 1895 | * Get the value as set in {@link SessionParams#setSize(long)}. |
| 1896 | * |
| 1897 | * <p>The value is a hint and does not have to match the actual size. |
| 1898 | */ |
| 1899 | public long getSize() { |
| 1900 | return sizeBytes; |
| 1901 | } |
| 1902 | |
| 1903 | /** |
| 1904 | * Get the value set in {@link SessionParams#setOriginatingUri(Uri)}. |
| 1905 | */ |
| 1906 | public @Nullable Uri getOriginatingUri() { |
| 1907 | return originatingUri; |
| 1908 | } |
| 1909 | |
| 1910 | /** |
| 1911 | * Get the value set in {@link SessionParams#setOriginatingUid(int)}. |
| 1912 | */ |
| 1913 | public int getOriginatingUid() { |
| 1914 | return originatingUid; |
| 1915 | } |
| 1916 | |
| 1917 | /** |
| 1918 | * Get the value set in {@link SessionParams#setReferrerUri(Uri)} |
| 1919 | */ |
| 1920 | public @Nullable Uri getReferrerUri() { |
| 1921 | return referrerUri; |
| 1922 | } |
| 1923 | |
| 1924 | /** |
| 1925 | * Get the value set in {@link SessionParams#setGrantedRuntimePermissions(String[])}. |
| 1926 | * |
| 1927 | * @hide |
| 1928 | */ |
| 1929 | @SystemApi |
| 1930 | public @Nullable String[] getGrantedRuntimePermissions() { |
| 1931 | return grantedRuntimePermissions; |
| 1932 | } |
| 1933 | |
| 1934 | /** |
| 1935 | * Get the value set in {@link SessionParams#setAllowDowngrade(boolean)}. |
| 1936 | * |
| 1937 | * @hide |
| 1938 | */ |
| 1939 | @SystemApi |
| 1940 | public boolean getAllowDowngrade() { |
| 1941 | return (installFlags & PackageManager.INSTALL_ALLOW_DOWNGRADE) != 0; |
| 1942 | } |
| 1943 | |
| 1944 | /** |
| 1945 | * Get the value set in {@link SessionParams#setDontKillApp(boolean)}. |
| 1946 | * |
| 1947 | * @hide |
| 1948 | */ |
| 1949 | @SystemApi |
| 1950 | public boolean getDontKillApp() { |
| 1951 | return (installFlags & PackageManager.INSTALL_DONT_KILL_APP) != 0; |
| 1952 | } |
| 1953 | |
| 1954 | /** |
| 1955 | * If {@link SessionParams#setInstallAsInstantApp(boolean)} was called with {@code true}, |
| 1956 | * return true. If it was called with {@code false} or if it was not called return false. |
| 1957 | * |
| 1958 | * @hide |
| 1959 | * |
| 1960 | * @see #getInstallAsFullApp |
| 1961 | */ |
| 1962 | @SystemApi |
| 1963 | public boolean getInstallAsInstantApp(boolean isInstantApp) { |
| 1964 | return (installFlags & PackageManager.INSTALL_INSTANT_APP) != 0; |
| 1965 | } |
| 1966 | |
| 1967 | /** |
| 1968 | * If {@link SessionParams#setInstallAsInstantApp(boolean)} was called with {@code false}, |
| 1969 | * return true. If it was called with {@code true} or if it was not called return false. |
| 1970 | * |
| 1971 | * @hide |
| 1972 | * |
| 1973 | * @see #getInstallAsInstantApp |
| 1974 | */ |
| 1975 | @SystemApi |
| 1976 | public boolean getInstallAsFullApp(boolean isInstantApp) { |
| 1977 | return (installFlags & PackageManager.INSTALL_FULL_APP) != 0; |
| 1978 | } |
| 1979 | |
| 1980 | /** |
| 1981 | * Get if {@link SessionParams#setInstallAsVirtualPreload()} was called. |
| 1982 | * |
| 1983 | * @hide |
| 1984 | */ |
| 1985 | @SystemApi |
| 1986 | public boolean getInstallAsVirtualPreload() { |
| 1987 | return (installFlags & PackageManager.INSTALL_VIRTUAL_PRELOAD) != 0; |
| 1988 | } |
| 1989 | |
| 1990 | /** |
| 1991 | * Get the value set in {@link SessionParams#setAllocateAggressive(boolean)}. |
| 1992 | * |
| 1993 | * @hide |
| 1994 | */ |
| 1995 | @SystemApi |
| 1996 | public boolean getAllocateAggressive() { |
| 1997 | return (installFlags & PackageManager.INSTALL_ALLOCATE_AGGRESSIVE) != 0; |
| 1998 | } |
| 1999 | |
| 2000 | |
Jeff Sharkey | de74231 | 2014-09-15 14:04:56 -0700 | [diff] [blame] | 2001 | /** {@hide} */ |
| 2002 | @Deprecated |
| 2003 | public @Nullable Intent getDetailsIntent() { |
| 2004 | return createDetailsIntent(); |
| 2005 | } |
| 2006 | |
Patrick Baumann | 0aff9b1 | 2018-11-08 14:05:08 +0000 | [diff] [blame] | 2007 | /** |
| 2008 | * Returns true if this session is a multi-package session containing references to other |
| 2009 | * sessions. |
| 2010 | */ |
| 2011 | public boolean isMultiPackage() { |
| 2012 | return isMultiPackage; |
| 2013 | } |
| 2014 | |
| 2015 | /** |
Dario Freni | aac4ba4 | 2018-12-06 15:47:16 +0000 | [diff] [blame] | 2016 | * Returns true if this session is a staged session which will be applied at next reboot. |
| 2017 | */ |
| 2018 | public boolean isStaged() { |
| 2019 | return isStaged; |
| 2020 | } |
| 2021 | |
| 2022 | /** |
Patrick Baumann | 0aff9b1 | 2018-11-08 14:05:08 +0000 | [diff] [blame] | 2023 | * Returns the parent multi-package session ID if this session belongs to one, |
| 2024 | * {@link #INVALID_ID} otherwise. |
| 2025 | */ |
| 2026 | public int getParentSessionId() { |
| 2027 | return parentSessionId; |
| 2028 | } |
| 2029 | |
| 2030 | /** |
| 2031 | * Returns the set of session IDs that will be committed when this session is commited if |
| 2032 | * this session is a multi-package session. |
| 2033 | */ |
| 2034 | public int[] getChildSessionIds() { |
| 2035 | return childSessionIds; |
| 2036 | } |
| 2037 | |
Dario Freni | 71eee5e | 2018-12-06 15:47:16 +0000 | [diff] [blame] | 2038 | /** |
| 2039 | * Whether the staged session has been applied successfully, meaning that all of its |
| 2040 | * packages have been activated and no further action is required. |
| 2041 | * Only meaningful if {@code isStaged} is true. |
| 2042 | */ |
| 2043 | public boolean isSessionApplied() { |
| 2044 | return isSessionApplied; |
| 2045 | } |
| 2046 | |
| 2047 | /** |
| 2048 | * Whether the staged session is ready to be applied at next reboot. Only meaningful if |
| 2049 | * {@code isStaged} is true. |
| 2050 | */ |
| 2051 | public boolean isSessionReady() { |
| 2052 | return isSessionReady; |
| 2053 | } |
| 2054 | |
| 2055 | /** |
| 2056 | * Whether something went wrong and the staged session is declared as failed, meaning that |
| 2057 | * it will be ignored at next reboot. Only meaningful if {@code isStaged} is true. |
| 2058 | */ |
| 2059 | public boolean isSessionFailed() { |
| 2060 | return isSessionFailed; |
| 2061 | } |
| 2062 | |
| 2063 | /** |
| 2064 | * If something went wrong with a staged session, clients can check this error code to |
| 2065 | * understand which kind of failure happened. Only meaningful if {@code isStaged} is true. |
| 2066 | */ |
| 2067 | public int getStagedSessionErrorCode() { |
| 2068 | return mStagedSessionErrorCode; |
| 2069 | } |
| 2070 | |
Dario Freni | 275b4ab | 2019-01-25 09:55:16 +0000 | [diff] [blame] | 2071 | /** |
| 2072 | * Text description of the error code returned by {@code getStagedSessionErrorCode}, or |
| 2073 | * empty string if no error was encountered. |
| 2074 | */ |
| 2075 | public String getStagedSessionErrorMessage() { |
| 2076 | return mStagedSessionErrorMessage; |
| 2077 | } |
| 2078 | |
Dario Freni | 71eee5e | 2018-12-06 15:47:16 +0000 | [diff] [blame] | 2079 | /** {@hide} */ |
Dario Freni | 275b4ab | 2019-01-25 09:55:16 +0000 | [diff] [blame] | 2080 | public void setStagedSessionErrorCode(@StagedSessionErrorCode int errorCode, |
| 2081 | String errorMessage) { |
Dario Freni | 71eee5e | 2018-12-06 15:47:16 +0000 | [diff] [blame] | 2082 | mStagedSessionErrorCode = errorCode; |
Dario Freni | 275b4ab | 2019-01-25 09:55:16 +0000 | [diff] [blame] | 2083 | mStagedSessionErrorMessage = errorMessage; |
Dario Freni | 71eee5e | 2018-12-06 15:47:16 +0000 | [diff] [blame] | 2084 | } |
| 2085 | |
Jeff Sharkey | bb58067 | 2014-07-10 12:10:25 -0700 | [diff] [blame] | 2086 | @Override |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 2087 | public int describeContents() { |
| 2088 | return 0; |
Jeff Sharkey | fbd0e9f | 2014-08-06 16:34:34 -0700 | [diff] [blame] | 2089 | } |
| 2090 | |
| 2091 | @Override |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 2092 | public void writeToParcel(Parcel dest, int flags) { |
| 2093 | dest.writeInt(sessionId); |
| 2094 | dest.writeString(installerPackageName); |
| 2095 | dest.writeString(resolvedBaseCodePath); |
| 2096 | dest.writeFloat(progress); |
| 2097 | dest.writeInt(sealed ? 1 : 0); |
Jeff Sharkey | bc7bce3 | 2014-09-05 15:53:05 -0700 | [diff] [blame] | 2098 | dest.writeInt(active ? 1 : 0); |
Jeff Sharkey | bb58067 | 2014-07-10 12:10:25 -0700 | [diff] [blame] | 2099 | |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 2100 | dest.writeInt(mode); |
Sunny Goyal | 6d7cb23 | 2017-01-30 10:43:18 -0800 | [diff] [blame] | 2101 | dest.writeInt(installReason); |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 2102 | dest.writeLong(sizeBytes); |
| 2103 | dest.writeString(appPackageName); |
| 2104 | dest.writeParcelable(appIcon, flags); |
| 2105 | dest.writeString(appLabel != null ? appLabel.toString() : null); |
Philip P. Moltmann | 7460c59 | 2017-08-08 20:07:11 +0000 | [diff] [blame] | 2106 | |
| 2107 | dest.writeInt(installLocation); |
| 2108 | dest.writeParcelable(originatingUri, flags); |
| 2109 | dest.writeInt(originatingUid); |
| 2110 | dest.writeParcelable(referrerUri, flags); |
| 2111 | dest.writeStringArray(grantedRuntimePermissions); |
| 2112 | dest.writeInt(installFlags); |
Patrick Baumann | 0aff9b1 | 2018-11-08 14:05:08 +0000 | [diff] [blame] | 2113 | dest.writeBoolean(isMultiPackage); |
Dario Freni | aac4ba4 | 2018-12-06 15:47:16 +0000 | [diff] [blame] | 2114 | dest.writeBoolean(isStaged); |
Patrick Baumann | 0aff9b1 | 2018-11-08 14:05:08 +0000 | [diff] [blame] | 2115 | dest.writeInt(parentSessionId); |
| 2116 | dest.writeIntArray(childSessionIds); |
Dario Freni | 71eee5e | 2018-12-06 15:47:16 +0000 | [diff] [blame] | 2117 | dest.writeBoolean(isSessionApplied); |
| 2118 | dest.writeBoolean(isSessionReady); |
| 2119 | dest.writeBoolean(isSessionFailed); |
| 2120 | dest.writeInt(mStagedSessionErrorCode); |
Dario Freni | 275b4ab | 2019-01-25 09:55:16 +0000 | [diff] [blame] | 2121 | dest.writeString(mStagedSessionErrorMessage); |
Jeff Sharkey | bb58067 | 2014-07-10 12:10:25 -0700 | [diff] [blame] | 2122 | } |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 2123 | |
| 2124 | public static final Parcelable.Creator<SessionInfo> |
| 2125 | CREATOR = new Parcelable.Creator<SessionInfo>() { |
| 2126 | @Override |
| 2127 | public SessionInfo createFromParcel(Parcel p) { |
| 2128 | return new SessionInfo(p); |
| 2129 | } |
| 2130 | |
| 2131 | @Override |
| 2132 | public SessionInfo[] newArray(int size) { |
| 2133 | return new SessionInfo[size]; |
| 2134 | } |
| 2135 | }; |
Jeff Sharkey | bb58067 | 2014-07-10 12:10:25 -0700 | [diff] [blame] | 2136 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 2137 | } |