| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.content.pm; |
| 18 |
|
| 19 |
import static android.app.AppOpsManager.MODE_ALLOWED; |
| 20 |
import static android.app.AppOpsManager.MODE_DEFAULT; |
| 21 |
import static android.app.AppOpsManager.MODE_IGNORED; |
| 22 |
import static android.content.pm.Checksum.TYPE_PARTIAL_MERKLE_ROOT_1M_SHA256; |
| 23 |
import static android.content.pm.Checksum.TYPE_PARTIAL_MERKLE_ROOT_1M_SHA512; |
| 24 |
import static android.content.pm.Checksum.TYPE_WHOLE_MD5; |
| 25 |
import static android.content.pm.Checksum.TYPE_WHOLE_MERKLE_ROOT_4K_SHA256; |
| 26 |
import static android.content.pm.Checksum.TYPE_WHOLE_SHA1; |
| 27 |
import static android.content.pm.Checksum.TYPE_WHOLE_SHA256; |
| 28 |
import static android.content.pm.Checksum.TYPE_WHOLE_SHA512; |
| 29 |
|
| 30 |
import android.Manifest; |
| 31 |
import android.annotation.CallbackExecutor; |
| 32 |
import android.annotation.CurrentTimeMillisLong; |
| 33 |
import android.annotation.IntDef; |
| 34 |
import android.annotation.NonNull; |
| 35 |
import android.annotation.Nullable; |
| 36 |
import android.annotation.RequiresPermission; |
| 37 |
import android.annotation.SdkConstant; |
| 38 |
import android.annotation.SdkConstant.SdkConstantType; |
| 39 |
import android.annotation.SystemApi; |
| 40 |
import android.annotation.TestApi; |
| 41 |
import android.app.ActivityManager; |
| 42 |
import android.app.AppGlobals; |
| 43 |
import android.compat.annotation.UnsupportedAppUsage; |
| 44 |
import android.content.Intent; |
| 45 |
import android.content.IntentSender; |
| 46 |
import android.content.pm.PackageManager.DeleteFlags; |
| 47 |
import android.content.pm.PackageManager.InstallReason; |
| 48 |
import android.content.pm.PackageManager.InstallScenario; |
| 49 |
import android.graphics.Bitmap; |
| 50 |
import android.net.Uri; |
| 51 |
import android.os.Build; |
| 52 |
import android.os.FileBridge; |
| 53 |
import android.os.Handler; |
| 54 |
import android.os.HandlerExecutor; |
| 55 |
import android.os.Parcel; |
| 56 |
import android.os.ParcelFileDescriptor; |
| 57 |
import android.os.Parcelable; |
| 58 |
import android.os.ParcelableException; |
| 59 |
import android.os.RemoteException; |
| 60 |
import android.os.SystemProperties; |
| 61 |
import android.os.UserHandle; |
| 62 |
import android.system.ErrnoException; |
| 63 |
import android.system.Os; |
| 64 |
import android.text.TextUtils; |
| 65 |
import android.util.ArraySet; |
| 66 |
import android.util.ExceptionUtils; |
| 67 |
|
| 68 |
import com.android.internal.util.IndentingPrintWriter; |
| 69 |
import com.android.internal.util.Preconditions; |
| 70 |
import com.android.internal.util.function.pooled.PooledLambda; |
| 71 |
|
| 72 |
import java.io.Closeable; |
| 73 |
import java.io.FileNotFoundException; |
| 74 |
import java.io.IOException; |
| 75 |
import java.io.InputStream; |
| 76 |
import java.io.OutputStream; |
| 77 |
import java.lang.annotation.Retention; |
| 78 |
import java.lang.annotation.RetentionPolicy; |
| 79 |
import java.security.MessageDigest; |
| 80 |
import java.security.cert.Certificate; |
| 81 |
import java.security.cert.CertificateEncodingException; |
| 82 |
import java.security.cert.X509Certificate; |
| 83 |
import java.util.ArrayList; |
| 84 |
import java.util.Collections; |
| 85 |
import java.util.Iterator; |
| 86 |
import java.util.List; |
| 87 |
import java.util.Objects; |
| 88 |
import java.util.Set; |
| 89 |
import java.util.concurrent.Executor; |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
public class PackageInstaller { |
| 125 |
private static final String TAG = "PackageInstaller"; |
| 126 |
|
| 127 |
|
| 128 |
public static final boolean ENABLE_REVOCABLE_FD = |
| 129 |
SystemProperties.getBoolean("fw.revocable_fd", false); |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 145 |
public static final String ACTION_SESSION_DETAILS = "android.content.pm.action.SESSION_DETAILS"; |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 156 |
public static final String ACTION_SESSION_COMMITTED = |
| 157 |
"android.content.pm.action.SESSION_COMMITTED"; |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 165 |
public static final String ACTION_SESSION_UPDATED = |
| 166 |
"android.content.pm.action.SESSION_UPDATED"; |
| 167 |
|
| 168 |
|
| 169 |
public static final String ACTION_CONFIRM_INSTALL = "android.content.pm.action.CONFIRM_INSTALL"; |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
public static final String EXTRA_SESSION_ID = "android.content.pm.extra.SESSION_ID"; |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
public static final String EXTRA_SESSION = "android.content.pm.extra.SESSION"; |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
public static final String EXTRA_PACKAGE_NAME = "android.content.pm.extra.PACKAGE_NAME"; |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
public static final String EXTRA_STATUS = "android.content.pm.extra.STATUS"; |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
public static final String EXTRA_STATUS_MESSAGE = "android.content.pm.extra.STATUS_MESSAGE"; |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
public static final String |
| 222 |
EXTRA_OTHER_PACKAGE_NAME = "android.content.pm.extra.OTHER_PACKAGE_NAME"; |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
public static final String EXTRA_STORAGE_PATH = "android.content.pm.extra.STORAGE_PATH"; |
| 230 |
|
| 231 |
|
| 232 |
@Deprecated |
| 233 |
public static final String EXTRA_PACKAGE_NAMES = "android.content.pm.extra.PACKAGE_NAMES"; |
| 234 |
|
| 235 |
|
| 236 |
public static final String EXTRA_LEGACY_STATUS = "android.content.pm.extra.LEGACY_STATUS"; |
| 237 |
|
| 238 |
public static final String EXTRA_LEGACY_BUNDLE = "android.content.pm.extra.LEGACY_BUNDLE"; |
| 239 |
|
| 240 |
public static final String EXTRA_CALLBACK = "android.content.pm.extra.CALLBACK"; |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
@SystemApi |
| 253 |
public static final String EXTRA_DATA_LOADER_TYPE = "android.content.pm.extra.DATA_LOADER_TYPE"; |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
public static final int STATUS_PENDING_STREAMING = -2; |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
public static final int STATUS_PENDING_USER_ACTION = -1; |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
public static final int STATUS_SUCCESS = 0; |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
public static final int STATUS_FAILURE = 1; |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
public static final int STATUS_FAILURE_BLOCKED = 2; |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
public static final int STATUS_FAILURE_ABORTED = 3; |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
public static final int STATUS_FAILURE_INVALID = 4; |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
public static final int STATUS_FAILURE_CONFLICT = 5; |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
public static final int STATUS_FAILURE_STORAGE = 6; |
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
public static final int STATUS_FAILURE_INCOMPATIBLE = 7; |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
@SystemApi |
| 366 |
public static final int DATA_LOADER_TYPE_NONE = DataLoaderType.NONE; |
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
@SystemApi |
| 375 |
public static final int DATA_LOADER_TYPE_STREAMING = DataLoaderType.STREAMING; |
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
@SystemApi |
| 384 |
public static final int DATA_LOADER_TYPE_INCREMENTAL = DataLoaderType.INCREMENTAL; |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
@SystemApi |
| 393 |
public static final int LOCATION_DATA_APP = InstallationFileLocation.DATA_APP; |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
@SystemApi |
| 401 |
public static final int LOCATION_MEDIA_OBB = InstallationFileLocation.MEDIA_OBB; |
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
@SystemApi |
| 411 |
public static final int LOCATION_MEDIA_DATA = InstallationFileLocation.MEDIA_DATA; |
| 412 |
|
| 413 |
|
| 414 |
@IntDef(prefix = { "LOCATION_" }, value = { |
| 415 |
LOCATION_DATA_APP, |
| 416 |
LOCATION_MEDIA_OBB, |
| 417 |
LOCATION_MEDIA_DATA}) |
| 418 |
@Retention(RetentionPolicy.SOURCE) |
| 419 |
public @interface FileLocation{} |
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
public static final int PACKAGE_SOURCE_UNSPECIFIED = 0; |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
public static final int PACKAGE_SOURCE_OTHER = 1; |
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
public static final int PACKAGE_SOURCE_STORE = 2; |
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
public static final int PACKAGE_SOURCE_LOCAL_FILE = 3; |
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
public static final int PACKAGE_SOURCE_DOWNLOADED_FILE = 4; |
| 451 |
|
| 452 |
|
| 453 |
@IntDef(prefix = { "PACKAGE_SOURCE_" }, value = { |
| 454 |
PACKAGE_SOURCE_UNSPECIFIED, |
| 455 |
PACKAGE_SOURCE_STORE, |
| 456 |
PACKAGE_SOURCE_LOCAL_FILE, |
| 457 |
PACKAGE_SOURCE_DOWNLOADED_FILE, |
| 458 |
PACKAGE_SOURCE_OTHER |
| 459 |
}) |
| 460 |
@Retention(RetentionPolicy.SOURCE) |
| 461 |
@interface PackageSourceType{} |
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
private static final int DEFAULT_CHECKSUMS = |
| 466 |
TYPE_WHOLE_MERKLE_ROOT_4K_SHA256 | TYPE_WHOLE_MD5 | TYPE_WHOLE_SHA1 | TYPE_WHOLE_SHA256 |
| 467 |
| TYPE_WHOLE_SHA512 | TYPE_PARTIAL_MERKLE_ROOT_1M_SHA256 |
| 468 |
| TYPE_PARTIAL_MERKLE_ROOT_1M_SHA512; |
| 469 |
|
| 470 |
private final IPackageInstaller mInstaller; |
| 471 |
private final int mUserId; |
| 472 |
private final String mInstallerPackageName; |
| 473 |
private final String mAttributionTag; |
| 474 |
|
| 475 |
private final ArrayList<SessionCallbackDelegate> mDelegates = new ArrayList<>(); |
| 476 |
|
| 477 |
|
| 478 |
public PackageInstaller(IPackageInstaller installer, |
| 479 |
String installerPackageName, String installerAttributionTag, int userId) { |
| 480 |
mInstaller = installer; |
| 481 |
mInstallerPackageName = installerPackageName; |
| 482 |
mAttributionTag = installerAttributionTag; |
| 483 |
mUserId = userId; |
| 484 |
} |
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
public int createSession(@NonNull SessionParams params) throws IOException { |
| 505 |
try { |
| 506 |
return mInstaller.createSession(params, mInstallerPackageName, mAttributionTag, |
| 507 |
mUserId); |
| 508 |
} catch (RuntimeException e) { |
| 509 |
ExceptionUtils.maybeUnwrapIOException(e); |
| 510 |
throw e; |
| 511 |
} catch (RemoteException e) { |
| 512 |
throw e.rethrowFromSystemServer(); |
| 513 |
} |
| 514 |
} |
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
public @NonNull Session openSession(int sessionId) throws IOException { |
| 526 |
try { |
| 527 |
try { |
| 528 |
return new Session(mInstaller.openSession(sessionId)); |
| 529 |
} catch (RemoteException e) { |
| 530 |
throw e.rethrowFromSystemServer(); |
| 531 |
} |
| 532 |
} catch (RuntimeException e) { |
| 533 |
ExceptionUtils.maybeUnwrapIOException(e); |
| 534 |
throw e; |
| 535 |
} |
| 536 |
} |
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
public void updateSessionAppIcon(int sessionId, @Nullable Bitmap appIcon) { |
| 547 |
try { |
| 548 |
mInstaller.updateSessionAppIcon(sessionId, appIcon); |
| 549 |
} catch (RemoteException e) { |
| 550 |
throw e.rethrowFromSystemServer(); |
| 551 |
} |
| 552 |
} |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
public void updateSessionAppLabel(int sessionId, @Nullable CharSequence appLabel) { |
| 562 |
try { |
| 563 |
final String val = (appLabel != null) ? appLabel.toString() : null; |
| 564 |
mInstaller.updateSessionAppLabel(sessionId, val); |
| 565 |
} catch (RemoteException e) { |
| 566 |
throw e.rethrowFromSystemServer(); |
| 567 |
} |
| 568 |
} |
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
public void abandonSession(int sessionId) { |
| 580 |
try { |
| 581 |
mInstaller.abandonSession(sessionId); |
| 582 |
} catch (RemoteException e) { |
| 583 |
throw e.rethrowFromSystemServer(); |
| 584 |
} |
| 585 |
} |
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
public @Nullable SessionInfo getSessionInfo(int sessionId) { |
| 596 |
try { |
| 597 |
return mInstaller.getSessionInfo(sessionId); |
| 598 |
} catch (RemoteException e) { |
| 599 |
throw e.rethrowFromSystemServer(); |
| 600 |
} |
| 601 |
} |
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
public @NonNull List<SessionInfo> getAllSessions() { |
| 610 |
try { |
| 611 |
return mInstaller.getAllSessions(mUserId).getList(); |
| 612 |
} catch (RemoteException e) { |
| 613 |
throw e.rethrowFromSystemServer(); |
| 614 |
} |
| 615 |
} |
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
public @NonNull List<SessionInfo> getMySessions() { |
| 621 |
try { |
| 622 |
return mInstaller.getMySessions(mInstallerPackageName, mUserId).getList(); |
| 623 |
} catch (RemoteException e) { |
| 624 |
throw e.rethrowFromSystemServer(); |
| 625 |
} |
| 626 |
} |
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
public @NonNull List<SessionInfo> getStagedSessions() { |
| 634 |
try { |
| 635 |
|
| 636 |
return mInstaller.getStagedSessions().getList(); |
| 637 |
} catch (RemoteException e) { |
| 638 |
throw e.rethrowFromSystemServer(); |
| 639 |
} |
| 640 |
} |
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
@Deprecated |
| 652 |
public @Nullable SessionInfo getActiveStagedSession() { |
| 653 |
List<SessionInfo> activeSessions = getActiveStagedSessions(); |
| 654 |
return activeSessions.isEmpty() ? null : activeSessions.get(0); |
| 655 |
} |
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
public @NonNull List<SessionInfo> getActiveStagedSessions() { |
| 664 |
final List<SessionInfo> activeStagedSessions = new ArrayList<>(); |
| 665 |
final List<SessionInfo> stagedSessions = getStagedSessions(); |
| 666 |
for (int i = 0; i < stagedSessions.size(); i++) { |
| 667 |
final SessionInfo sessionInfo = stagedSessions.get(i); |
| 668 |
if (sessionInfo.isStagedSessionActive()) { |
| 669 |
activeStagedSessions.add(sessionInfo); |
| 670 |
} |
| 671 |
} |
| 672 |
return activeStagedSessions; |
| 673 |
} |
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
@RequiresPermission(anyOf = { |
| 690 |
Manifest.permission.DELETE_PACKAGES, |
| 691 |
Manifest.permission.REQUEST_DELETE_PACKAGES}) |
| 692 |
public void uninstall(@NonNull String packageName, @NonNull IntentSender statusReceiver) { |
| 693 |
uninstall(packageName, 0 , statusReceiver); |
| 694 |
} |
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
public void uninstall(@NonNull String packageName, @DeleteFlags int flags, |
| 708 |
@NonNull IntentSender statusReceiver) { |
| 709 |
uninstall(new VersionedPackage(packageName, PackageManager.VERSION_CODE_HIGHEST), |
| 710 |
flags, statusReceiver); |
| 711 |
} |
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
@RequiresPermission(anyOf = { |
| 733 |
Manifest.permission.DELETE_PACKAGES, |
| 734 |
Manifest.permission.REQUEST_DELETE_PACKAGES}) |
| 735 |
public void uninstall(@NonNull VersionedPackage versionedPackage, |
| 736 |
@NonNull IntentSender statusReceiver) { |
| 737 |
uninstall(versionedPackage, 0 , statusReceiver); |
| 738 |
} |
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
@RequiresPermission(anyOf = { |
| 755 |
Manifest.permission.DELETE_PACKAGES, |
| 756 |
Manifest.permission.REQUEST_DELETE_PACKAGES}) |
| 757 |
public void uninstall(@NonNull VersionedPackage versionedPackage, @DeleteFlags int flags, |
| 758 |
@NonNull IntentSender statusReceiver) { |
| 759 |
Objects.requireNonNull(versionedPackage, "versionedPackage cannot be null"); |
| 760 |
try { |
| 761 |
mInstaller.uninstall(versionedPackage, mInstallerPackageName, |
| 762 |
flags, statusReceiver, mUserId); |
| 763 |
} catch (RemoteException e) { |
| 764 |
throw e.rethrowFromSystemServer(); |
| 765 |
} |
| 766 |
} |
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
@RequiresPermission(allOf = { |
| 781 |
Manifest.permission.INSTALL_PACKAGES, |
| 782 |
Manifest.permission.INSTALL_EXISTING_PACKAGES}) |
| 783 |
public void installExistingPackage(@NonNull String packageName, |
| 784 |
@InstallReason int installReason, |
| 785 |
@Nullable IntentSender statusReceiver) { |
| 786 |
Objects.requireNonNull(packageName, "packageName cannot be null"); |
| 787 |
try { |
| 788 |
mInstaller.installExistingPackage(packageName, |
| 789 |
PackageManager.INSTALL_ALL_WHITELIST_RESTRICTED_PERMISSIONS, installReason, |
| 790 |
statusReceiver, mUserId, null); |
| 791 |
} catch (RemoteException e) { |
| 792 |
throw e.rethrowFromSystemServer(); |
| 793 |
} |
| 794 |
} |
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
@RequiresPermission(Manifest.permission.DELETE_PACKAGES) |
| 804 |
public void uninstallExistingPackage(@NonNull String packageName, |
| 805 |
@Nullable IntentSender statusReceiver) { |
| 806 |
Objects.requireNonNull(packageName, "packageName cannot be null"); |
| 807 |
try { |
| 808 |
mInstaller.uninstallExistingPackage( |
| 809 |
new VersionedPackage(packageName, PackageManager.VERSION_CODE_HIGHEST), |
| 810 |
mInstallerPackageName, statusReceiver, mUserId); |
| 811 |
} catch (RemoteException e) { |
| 812 |
throw e.rethrowFromSystemServer(); |
| 813 |
} |
| 814 |
} |
| 815 |
|
| 816 |
|
| 817 |
@SystemApi |
| 818 |
@RequiresPermission(android.Manifest.permission.INSTALL_PACKAGES) |
| 819 |
public void setPermissionsResult(int sessionId, boolean accepted) { |
| 820 |
try { |
| 821 |
mInstaller.setPermissionsResult(sessionId, accepted); |
| 822 |
} catch (RemoteException e) { |
| 823 |
throw e.rethrowFromSystemServer(); |
| 824 |
} |
| 825 |
} |
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
public static abstract class SessionCallback { |
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
public abstract void onCreated(int sessionId); |
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
public abstract void onBadgingChanged(int sessionId); |
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
public abstract void onActiveChanged(int sessionId, boolean active); |
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
public abstract void onProgressChanged(int sessionId, float progress); |
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
public abstract void onFinished(int sessionId, boolean success); |
| 884 |
} |
| 885 |
|
| 886 |
|
| 887 |
static class SessionCallbackDelegate extends IPackageInstallerCallback.Stub { |
| 888 |
private static final int MSG_SESSION_CREATED = 1; |
| 889 |
private static final int MSG_SESSION_BADGING_CHANGED = 2; |
| 890 |
private static final int MSG_SESSION_ACTIVE_CHANGED = 3; |
| 891 |
private static final int MSG_SESSION_PROGRESS_CHANGED = 4; |
| 892 |
private static final int MSG_SESSION_FINISHED = 5; |
| 893 |
|
| 894 |
final SessionCallback mCallback; |
| 895 |
final Executor mExecutor; |
| 896 |
|
| 897 |
SessionCallbackDelegate(SessionCallback callback, Executor executor) { |
| 898 |
mCallback = callback; |
| 899 |
mExecutor = executor; |
| 900 |
} |
| 901 |
|
| 902 |
@Override |
| 903 |
public void onSessionCreated(int sessionId) { |
| 904 |
mExecutor.execute(PooledLambda.obtainRunnable(SessionCallback::onCreated, mCallback, |
| 905 |
sessionId).recycleOnUse()); |
| 906 |
} |
| 907 |
|
| 908 |
@Override |
| 909 |
public void onSessionBadgingChanged(int sessionId) { |
| 910 |
mExecutor.execute(PooledLambda.obtainRunnable(SessionCallback::onBadgingChanged, |
| 911 |
mCallback, sessionId).recycleOnUse()); |
| 912 |
} |
| 913 |
|
| 914 |
@Override |
| 915 |
public void onSessionActiveChanged(int sessionId, boolean active) { |
| 916 |
mExecutor.execute(PooledLambda.obtainRunnable(SessionCallback::onActiveChanged, |
| 917 |
mCallback, sessionId, active).recycleOnUse()); |
| 918 |
} |
| 919 |
|
| 920 |
@Override |
| 921 |
public void onSessionProgressChanged(int sessionId, float progress) { |
| 922 |
mExecutor.execute(PooledLambda.obtainRunnable(SessionCallback::onProgressChanged, |
| 923 |
mCallback, sessionId, progress).recycleOnUse()); |
| 924 |
} |
| 925 |
|
| 926 |
@Override |
| 927 |
public void onSessionFinished(int sessionId, boolean success) { |
| 928 |
mExecutor.execute(PooledLambda.obtainRunnable(SessionCallback::onFinished, |
| 929 |
mCallback, sessionId, success).recycleOnUse()); |
| 930 |
} |
| 931 |
} |
| 932 |
|
| 933 |
|
| 934 |
@Deprecated |
| 935 |
public void addSessionCallback(@NonNull SessionCallback callback) { |
| 936 |
registerSessionCallback(callback); |
| 937 |
} |
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
public void registerSessionCallback(@NonNull SessionCallback callback) { |
| 944 |
registerSessionCallback(callback, new Handler()); |
| 945 |
} |
| 946 |
|
| 947 |
|
| 948 |
@Deprecated |
| 949 |
public void addSessionCallback(@NonNull SessionCallback callback, @NonNull Handler handler) { |
| 950 |
registerSessionCallback(callback, handler); |
| 951 |
} |
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
public void registerSessionCallback(@NonNull SessionCallback callback, @NonNull Handler handler) { |
| 961 |
synchronized (mDelegates) { |
| 962 |
final SessionCallbackDelegate delegate = new SessionCallbackDelegate(callback, |
| 963 |
new HandlerExecutor(handler)); |
| 964 |
try { |
| 965 |
mInstaller.registerCallback(delegate, mUserId); |
| 966 |
} catch (RemoteException e) { |
| 967 |
throw e.rethrowFromSystemServer(); |
| 968 |
} |
| 969 |
mDelegates.add(delegate); |
| 970 |
} |
| 971 |
} |
| 972 |
|
| 973 |
|
| 974 |
@Deprecated |
| 975 |
public void removeSessionCallback(@NonNull SessionCallback callback) { |
| 976 |
unregisterSessionCallback(callback); |
| 977 |
} |
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
public void unregisterSessionCallback(@NonNull SessionCallback callback) { |
| 983 |
synchronized (mDelegates) { |
| 984 |
for (Iterator<SessionCallbackDelegate> i = mDelegates.iterator(); i.hasNext();) { |
| 985 |
final SessionCallbackDelegate delegate = i.next(); |
| 986 |
if (delegate.mCallback == callback) { |
| 987 |
try { |
| 988 |
mInstaller.unregisterCallback(delegate); |
| 989 |
} catch (RemoteException e) { |
| 990 |
throw e.rethrowFromSystemServer(); |
| 991 |
} |
| 992 |
i.remove(); |
| 993 |
} |
| 994 |
} |
| 995 |
} |
| 996 |
} |
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
public static class Session implements Closeable { |
| 1018 |
|
| 1019 |
protected final IPackageInstallerSession mSession; |
| 1020 |
|
| 1021 |
|
| 1022 |
public Session(IPackageInstallerSession session) { |
| 1023 |
mSession = session; |
| 1024 |
} |
| 1025 |
|
| 1026 |
|
| 1027 |
@Deprecated |
| 1028 |
public void setProgress(float progress) { |
| 1029 |
setStagingProgress(progress); |
| 1030 |
} |
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
public void setStagingProgress(float progress) { |
| 1042 |
try { |
| 1043 |
mSession.setClientProgress(progress); |
| 1044 |
} catch (RemoteException e) { |
| 1045 |
throw e.rethrowFromSystemServer(); |
| 1046 |
} |
| 1047 |
} |
| 1048 |
|
| 1049 |
|
| 1050 |
@UnsupportedAppUsage |
| 1051 |
public void addProgress(float progress) { |
| 1052 |
try { |
| 1053 |
mSession.addClientProgress(progress); |
| 1054 |
} catch (RemoteException e) { |
| 1055 |
throw e.rethrowFromSystemServer(); |
| 1056 |
} |
| 1057 |
} |
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
public @NonNull OutputStream openWrite(@NonNull String name, long offsetBytes, |
| 1090 |
long lengthBytes) throws IOException { |
| 1091 |
try { |
| 1092 |
if (ENABLE_REVOCABLE_FD) { |
| 1093 |
return new ParcelFileDescriptor.AutoCloseOutputStream( |
| 1094 |
mSession.openWrite(name, offsetBytes, lengthBytes)); |
| 1095 |
} else { |
| 1096 |
final ParcelFileDescriptor clientSocket = mSession.openWrite(name, |
| 1097 |
offsetBytes, lengthBytes); |
| 1098 |
return new FileBridge.FileBridgeOutputStream(clientSocket); |
| 1099 |
} |
| 1100 |
} catch (RuntimeException e) { |
| 1101 |
ExceptionUtils.maybeUnwrapIOException(e); |
| 1102 |
throw e; |
| 1103 |
} catch (RemoteException e) { |
| 1104 |
throw e.rethrowFromSystemServer(); |
| 1105 |
} |
| 1106 |
} |
| 1107 |
|
| 1108 |
|
| 1109 |
public void write(@NonNull String name, long offsetBytes, long lengthBytes, |
| 1110 |
@NonNull ParcelFileDescriptor fd) throws IOException { |
| 1111 |
try { |
| 1112 |
mSession.write(name, offsetBytes, lengthBytes, fd); |
| 1113 |
} catch (RuntimeException e) { |
| 1114 |
ExceptionUtils.maybeUnwrapIOException(e); |
| 1115 |
throw e; |
| 1116 |
} catch (RemoteException e) { |
| 1117 |
throw e.rethrowFromSystemServer(); |
| 1118 |
} |
| 1119 |
} |
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
public void stageViaHardLink(String target) throws IOException { |
| 1136 |
try { |
| 1137 |
mSession.stageViaHardLink(target); |
| 1138 |
} catch (RuntimeException e) { |
| 1139 |
ExceptionUtils.maybeUnwrapIOException(e); |
| 1140 |
throw e; |
| 1141 |
} catch (RemoteException e) { |
| 1142 |
throw e.rethrowFromSystemServer(); |
| 1143 |
} |
| 1144 |
} |
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
public void fsync(@NonNull OutputStream out) throws IOException { |
| 1152 |
if (ENABLE_REVOCABLE_FD) { |
| 1153 |
if (out instanceof ParcelFileDescriptor.AutoCloseOutputStream) { |
| 1154 |
try { |
| 1155 |
Os.fsync(((ParcelFileDescriptor.AutoCloseOutputStream) out).getFD()); |
| 1156 |
} catch (ErrnoException e) { |
| 1157 |
throw e.rethrowAsIOException(); |
| 1158 |
} |
| 1159 |
} else { |
| 1160 |
throw new IllegalArgumentException("Unrecognized stream"); |
| 1161 |
} |
| 1162 |
} else { |
| 1163 |
if (out instanceof FileBridge.FileBridgeOutputStream) { |
| 1164 |
((FileBridge.FileBridgeOutputStream) out).fsync(); |
| 1165 |
} else { |
| 1166 |
throw new IllegalArgumentException("Unrecognized stream"); |
| 1167 |
} |
| 1168 |
} |
| 1169 |
} |
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
public @NonNull String[] getNames() throws IOException { |
| 1181 |
try { |
| 1182 |
return mSession.getNames(); |
| 1183 |
} catch (RuntimeException e) { |
| 1184 |
ExceptionUtils.maybeUnwrapIOException(e); |
| 1185 |
throw e; |
| 1186 |
} catch (RemoteException e) { |
| 1187 |
throw e.rethrowFromSystemServer(); |
| 1188 |
} |
| 1189 |
} |
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
public @NonNull InputStream openRead(@NonNull String name) throws IOException { |
| 1203 |
try { |
| 1204 |
final ParcelFileDescriptor pfd = mSession.openRead(name); |
| 1205 |
return new ParcelFileDescriptor.AutoCloseInputStream(pfd); |
| 1206 |
} catch (RuntimeException e) { |
| 1207 |
ExceptionUtils.maybeUnwrapIOException(e); |
| 1208 |
throw e; |
| 1209 |
} catch (RemoteException e) { |
| 1210 |
throw e.rethrowFromSystemServer(); |
| 1211 |
} |
| 1212 |
} |
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
public void removeSplit(@NonNull String splitName) throws IOException { |
| 1225 |
try { |
| 1226 |
mSession.removeSplit(splitName); |
| 1227 |
} catch (RuntimeException e) { |
| 1228 |
ExceptionUtils.maybeUnwrapIOException(e); |
| 1229 |
throw e; |
| 1230 |
} catch (RemoteException e) { |
| 1231 |
throw e.rethrowFromSystemServer(); |
| 1232 |
} |
| 1233 |
} |
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
@SystemApi |
| 1240 |
@RequiresPermission(android.Manifest.permission.USE_INSTALLER_V2) |
| 1241 |
public @Nullable DataLoaderParams getDataLoaderParams() { |
| 1242 |
try { |
| 1243 |
DataLoaderParamsParcel data = mSession.getDataLoaderParams(); |
| 1244 |
if (data == null) { |
| 1245 |
return null; |
| 1246 |
} |
| 1247 |
return new DataLoaderParams(data); |
| 1248 |
} catch (RemoteException e) { |
| 1249 |
throw e.rethrowFromSystemServer(); |
| 1250 |
} |
| 1251 |
} |
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
@SystemApi |
| 1281 |
@RequiresPermission(android.Manifest.permission.USE_INSTALLER_V2) |
| 1282 |
public void addFile(@FileLocation int location, @NonNull String name, long lengthBytes, |
| 1283 |
@NonNull byte[] metadata, @Nullable byte[] signature) { |
| 1284 |
try { |
| 1285 |
mSession.addFile(location, name, lengthBytes, metadata, signature); |
| 1286 |
} catch (RemoteException e) { |
| 1287 |
throw e.rethrowFromSystemServer(); |
| 1288 |
} |
| 1289 |
} |
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
@SystemApi |
| 1305 |
@RequiresPermission(android.Manifest.permission.USE_INSTALLER_V2) |
| 1306 |
public void removeFile(@FileLocation int location, @NonNull String name) { |
| 1307 |
try { |
| 1308 |
mSession.removeFile(location, name); |
| 1309 |
} catch (RemoteException e) { |
| 1310 |
throw e.rethrowFromSystemServer(); |
| 1311 |
} |
| 1312 |
} |
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
|
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
@Deprecated |
| 1341 |
public void setChecksums(@NonNull String name, @NonNull List<Checksum> checksums, |
| 1342 |
@Nullable byte[] signature) throws IOException { |
| 1343 |
Objects.requireNonNull(name); |
| 1344 |
Objects.requireNonNull(checksums); |
| 1345 |
|
| 1346 |
try { |
| 1347 |
mSession.setChecksums(name, checksums.toArray(new Checksum[checksums.size()]), |
| 1348 |
signature); |
| 1349 |
} catch (RuntimeException e) { |
| 1350 |
ExceptionUtils.maybeUnwrapIOException(e); |
| 1351 |
throw e; |
| 1352 |
} catch (RemoteException e) { |
| 1353 |
throw e.rethrowFromSystemServer(); |
| 1354 |
} |
| 1355 |
} |
| 1356 |
|
| 1357 |
private static List<byte[]> encodeCertificates(List<Certificate> certs) throws |
| 1358 |
CertificateEncodingException { |
| 1359 |
if (certs == null) { |
| 1360 |
return null; |
| 1361 |
} |
| 1362 |
List<byte[]> result = new ArrayList<>(certs.size()); |
| 1363 |
for (Certificate cert : certs) { |
| 1364 |
if (!(cert instanceof X509Certificate)) { |
| 1365 |
throw new CertificateEncodingException("Only X509 certificates supported."); |
| 1366 |
} |
| 1367 |
result.add(cert.getEncoded()); |
| 1368 |
} |
| 1369 |
return result; |
| 1370 |
} |
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
public void requestChecksums(@NonNull String name, @Checksum.TypeMask int required, |
| 1407 |
@NonNull List<Certificate> trustedInstallers, |
| 1408 |
@NonNull @CallbackExecutor Executor executor, |
| 1409 |
@NonNull PackageManager.OnChecksumsReadyListener onChecksumsReadyListener) |
| 1410 |
throws CertificateEncodingException, FileNotFoundException { |
| 1411 |
Objects.requireNonNull(name); |
| 1412 |
Objects.requireNonNull(trustedInstallers); |
| 1413 |
Objects.requireNonNull(executor); |
| 1414 |
Objects.requireNonNull(onChecksumsReadyListener); |
| 1415 |
if (trustedInstallers == PackageManager.TRUST_ALL) { |
| 1416 |
trustedInstallers = null; |
| 1417 |
} else if (trustedInstallers == PackageManager.TRUST_NONE) { |
| 1418 |
trustedInstallers = Collections.emptyList(); |
| 1419 |
} else if (trustedInstallers.isEmpty()) { |
| 1420 |
throw new IllegalArgumentException( |
| 1421 |
"trustedInstallers has to be one of TRUST_ALL/TRUST_NONE or a non-empty " |
| 1422 |
+ "list of certificates."); |
| 1423 |
} |
| 1424 |
try { |
| 1425 |
IOnChecksumsReadyListener onChecksumsReadyListenerDelegate = |
| 1426 |
new IOnChecksumsReadyListener.Stub() { |
| 1427 |
@Override |
| 1428 |
public void onChecksumsReady(List<ApkChecksum> checksums) |
| 1429 |
throws RemoteException { |
| 1430 |
executor.execute( |
| 1431 |
() -> onChecksumsReadyListener.onChecksumsReady(checksums)); |
| 1432 |
} |
| 1433 |
}; |
| 1434 |
mSession.requestChecksums(name, DEFAULT_CHECKSUMS, required, |
| 1435 |
encodeCertificates(trustedInstallers), onChecksumsReadyListenerDelegate); |
| 1436 |
} catch (ParcelableException e) { |
| 1437 |
e.maybeRethrow(FileNotFoundException.class); |
| 1438 |
throw new RuntimeException(e); |
| 1439 |
} catch (RemoteException e) { |
| 1440 |
throw e.rethrowFromSystemServer(); |
| 1441 |
} |
| 1442 |
} |
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
public void commit(@NonNull IntentSender statusReceiver) { |
| 1466 |
try { |
| 1467 |
mSession.commit(statusReceiver, false); |
| 1468 |
} catch (RemoteException e) { |
| 1469 |
throw e.rethrowFromSystemServer(); |
| 1470 |
} |
| 1471 |
} |
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
@SystemApi |
| 1493 |
@RequiresPermission(android.Manifest.permission.INSTALL_PACKAGES) |
| 1494 |
public void commitTransferred(@NonNull IntentSender statusReceiver) { |
| 1495 |
try { |
| 1496 |
mSession.commit(statusReceiver, true); |
| 1497 |
} catch (RemoteException e) { |
| 1498 |
throw e.rethrowFromSystemServer(); |
| 1499 |
} |
| 1500 |
} |
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
public void transfer(@NonNull String packageName) |
| 1523 |
throws PackageManager.NameNotFoundException { |
| 1524 |
Preconditions.checkArgument(!TextUtils.isEmpty(packageName)); |
| 1525 |
|
| 1526 |
try { |
| 1527 |
mSession.transfer(packageName); |
| 1528 |
} catch (ParcelableException e) { |
| 1529 |
e.maybeRethrow(PackageManager.NameNotFoundException.class); |
| 1530 |
throw new RuntimeException(e); |
| 1531 |
} catch (RemoteException e) { |
| 1532 |
throw e.rethrowFromSystemServer(); |
| 1533 |
} |
| 1534 |
} |
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
@Override |
| 1541 |
public void close() { |
| 1542 |
try { |
| 1543 |
mSession.close(); |
| 1544 |
} catch (RemoteException e) { |
| 1545 |
throw e.rethrowFromSystemServer(); |
| 1546 |
} |
| 1547 |
} |
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
|
| 1556 |
|
| 1557 |
public void abandon() { |
| 1558 |
try { |
| 1559 |
mSession.abandon(); |
| 1560 |
} catch (RemoteException e) { |
| 1561 |
throw e.rethrowFromSystemServer(); |
| 1562 |
} |
| 1563 |
} |
| 1564 |
|
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
public boolean isMultiPackage() { |
| 1570 |
try { |
| 1571 |
return mSession.isMultiPackage(); |
| 1572 |
} catch (RemoteException e) { |
| 1573 |
throw e.rethrowFromSystemServer(); |
| 1574 |
} |
| 1575 |
} |
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
public boolean isStaged() { |
| 1581 |
try { |
| 1582 |
return mSession.isStaged(); |
| 1583 |
} catch (RemoteException e) { |
| 1584 |
throw e.rethrowFromSystemServer(); |
| 1585 |
} |
| 1586 |
} |
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
public int getInstallFlags() { |
| 1593 |
try { |
| 1594 |
return mSession.getInstallFlags(); |
| 1595 |
} catch (RemoteException e) { |
| 1596 |
throw e.rethrowFromSystemServer(); |
| 1597 |
} |
| 1598 |
} |
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
public int getParentSessionId() { |
| 1605 |
try { |
| 1606 |
return mSession.getParentSessionId(); |
| 1607 |
} catch (RemoteException e) { |
| 1608 |
throw e.rethrowFromSystemServer(); |
| 1609 |
} |
| 1610 |
} |
| 1611 |
|
| 1612 |
|
| 1613 |
|
| 1614 |
|
| 1615 |
|
| 1616 |
@NonNull |
| 1617 |
public int[] getChildSessionIds() { |
| 1618 |
try { |
| 1619 |
return mSession.getChildSessionIds(); |
| 1620 |
} catch (RemoteException e) { |
| 1621 |
throw e.rethrowFromSystemServer(); |
| 1622 |
} |
| 1623 |
} |
| 1624 |
|
| 1625 |
|
| 1626 |
|
| 1627 |
|
| 1628 |
|
| 1629 |
|
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
public void addChildSessionId(int sessionId) { |
| 1636 |
try { |
| 1637 |
mSession.addChildSessionId(sessionId); |
| 1638 |
} catch (RemoteException e) { |
| 1639 |
e.rethrowFromSystemServer(); |
| 1640 |
} |
| 1641 |
} |
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
public void removeChildSessionId(int sessionId) { |
| 1650 |
try { |
| 1651 |
mSession.removeChildSessionId(sessionId); |
| 1652 |
} catch (RemoteException e) { |
| 1653 |
e.rethrowFromSystemServer(); |
| 1654 |
} |
| 1655 |
} |
| 1656 |
} |
| 1657 |
|
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
public static class SessionParams implements Parcelable { |
| 1662 |
|
| 1663 |
|
| 1664 |
public static final int MODE_INVALID = -1; |
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
public static final int MODE_FULL_INSTALL = 1; |
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
public static final int MODE_INHERIT_EXISTING = 2; |
| 1682 |
|
| 1683 |
|
| 1684 |
|
| 1685 |
|
| 1686 |
public static final @NonNull Set<String> RESTRICTED_PERMISSIONS_ALL = new ArraySet<>(); |
| 1687 |
|
| 1688 |
|
| 1689 |
public static final int UID_UNKNOWN = -1; |
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
public static final int MAX_PACKAGE_NAME_LENGTH = 255; |
| 1697 |
|
| 1698 |
|
| 1699 |
@IntDef(prefix = {"USER_ACTION_"}, value = { |
| 1700 |
USER_ACTION_UNSPECIFIED, |
| 1701 |
USER_ACTION_REQUIRED, |
| 1702 |
USER_ACTION_NOT_REQUIRED |
| 1703 |
}) |
| 1704 |
@Retention(RetentionPolicy.SOURCE) |
| 1705 |
public @interface UserActionRequirement {} |
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
public static final int USER_ACTION_UNSPECIFIED = 0; |
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
|
| 1717 |
public static final int USER_ACTION_REQUIRED = 1; |
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
|
| 1722 |
|
| 1723 |
public static final int USER_ACTION_NOT_REQUIRED = 2; |
| 1724 |
|
| 1725 |
|
| 1726 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 1727 |
public int mode = MODE_INVALID; |
| 1728 |
|
| 1729 |
@UnsupportedAppUsage |
| 1730 |
public int installFlags = PackageManager.INSTALL_ALL_WHITELIST_RESTRICTED_PERMISSIONS; |
| 1731 |
|
| 1732 |
public int installLocation = PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY; |
| 1733 |
|
| 1734 |
public @InstallReason int installReason = PackageManager.INSTALL_REASON_UNKNOWN; |
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
public @InstallScenario int installScenario = PackageManager.INSTALL_SCENARIO_DEFAULT; |
| 1743 |
|
| 1744 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 1745 |
public long sizeBytes = -1; |
| 1746 |
|
| 1747 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 1748 |
public String appPackageName; |
| 1749 |
|
| 1750 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 1751 |
public Bitmap appIcon; |
| 1752 |
|
| 1753 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 1754 |
public String appLabel; |
| 1755 |
|
| 1756 |
public long appIconLastModified = -1; |
| 1757 |
|
| 1758 |
public Uri originatingUri; |
| 1759 |
|
| 1760 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 1761 |
public int originatingUid = UID_UNKNOWN; |
| 1762 |
|
| 1763 |
public Uri referrerUri; |
| 1764 |
|
| 1765 |
public String abiOverride; |
| 1766 |
|
| 1767 |
public String volumeUuid; |
| 1768 |
|
| 1769 |
public String[] grantedRuntimePermissions; |
| 1770 |
|
| 1771 |
public List<String> whitelistedRestrictedPermissions; |
| 1772 |
|
| 1773 |
public int autoRevokePermissionsMode = MODE_DEFAULT; |
| 1774 |
|
| 1775 |
public String installerPackageName; |
| 1776 |
|
| 1777 |
public boolean isMultiPackage; |
| 1778 |
|
| 1779 |
public int packageSource = PACKAGE_SOURCE_UNSPECIFIED; |
| 1780 |
|
| 1781 |
public boolean isStaged; |
| 1782 |
|
| 1783 |
public long requiredInstalledVersionCode = PackageManager.VERSION_CODE_HIGHEST; |
| 1784 |
|
| 1785 |
public DataLoaderParams dataLoaderParams; |
| 1786 |
|
| 1787 |
public int rollbackDataPolicy = PackageManager.ROLLBACK_DATA_POLICY_RESTORE; |
| 1788 |
|
| 1789 |
public boolean forceQueryableOverride; |
| 1790 |
|
| 1791 |
public int requireUserAction = USER_ACTION_UNSPECIFIED; |
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
public SessionParams(int mode) { |
| 1801 |
this.mode = mode; |
| 1802 |
} |
| 1803 |
|
| 1804 |
|
| 1805 |
public SessionParams(Parcel source) { |
| 1806 |
mode = source.readInt(); |
| 1807 |
installFlags = source.readInt(); |
| 1808 |
installLocation = source.readInt(); |
| 1809 |
installReason = source.readInt(); |
| 1810 |
installScenario = source.readInt(); |
| 1811 |
sizeBytes = source.readLong(); |
| 1812 |
appPackageName = source.readString(); |
| 1813 |
appIcon = source.readParcelable(null, android.graphics.Bitmap.class); |
| 1814 |
appLabel = source.readString(); |
| 1815 |
originatingUri = source.readParcelable(null, android.net.Uri.class); |
| 1816 |
originatingUid = source.readInt(); |
| 1817 |
referrerUri = source.readParcelable(null, android.net.Uri.class); |
| 1818 |
abiOverride = source.readString(); |
| 1819 |
volumeUuid = source.readString(); |
| 1820 |
grantedRuntimePermissions = source.readStringArray(); |
| 1821 |
whitelistedRestrictedPermissions = source.createStringArrayList(); |
| 1822 |
autoRevokePermissionsMode = source.readInt(); |
| 1823 |
installerPackageName = source.readString(); |
| 1824 |
isMultiPackage = source.readBoolean(); |
| 1825 |
isStaged = source.readBoolean(); |
| 1826 |
forceQueryableOverride = source.readBoolean(); |
| 1827 |
requiredInstalledVersionCode = source.readLong(); |
| 1828 |
DataLoaderParamsParcel dataLoaderParamsParcel = source.readParcelable( |
| 1829 |
DataLoaderParamsParcel.class.getClassLoader(), android.content.pm.DataLoaderParamsParcel.class); |
| 1830 |
if (dataLoaderParamsParcel != null) { |
| 1831 |
dataLoaderParams = new DataLoaderParams(dataLoaderParamsParcel); |
| 1832 |
} |
| 1833 |
rollbackDataPolicy = source.readInt(); |
| 1834 |
requireUserAction = source.readInt(); |
| 1835 |
packageSource = source.readInt(); |
| 1836 |
} |
| 1837 |
|
| 1838 |
|
| 1839 |
public SessionParams copy() { |
| 1840 |
SessionParams ret = new SessionParams(mode); |
| 1841 |
ret.installFlags = installFlags; |
| 1842 |
ret.installLocation = installLocation; |
| 1843 |
ret.installReason = installReason; |
| 1844 |
ret.installScenario = installScenario; |
| 1845 |
ret.sizeBytes = sizeBytes; |
| 1846 |
ret.appPackageName = appPackageName; |
| 1847 |
ret.appIcon = appIcon; |
| 1848 |
ret.appLabel = appLabel; |
| 1849 |
ret.originatingUri = originatingUri; |
| 1850 |
ret.originatingUid = originatingUid; |
| 1851 |
ret.referrerUri = referrerUri; |
| 1852 |
ret.abiOverride = abiOverride; |
| 1853 |
ret.volumeUuid = volumeUuid; |
| 1854 |
ret.grantedRuntimePermissions = grantedRuntimePermissions; |
| 1855 |
ret.whitelistedRestrictedPermissions = whitelistedRestrictedPermissions; |
| 1856 |
ret.autoRevokePermissionsMode = autoRevokePermissionsMode; |
| 1857 |
ret.installerPackageName = installerPackageName; |
| 1858 |
ret.isMultiPackage = isMultiPackage; |
| 1859 |
ret.isStaged = isStaged; |
| 1860 |
ret.forceQueryableOverride = forceQueryableOverride; |
| 1861 |
ret.requiredInstalledVersionCode = requiredInstalledVersionCode; |
| 1862 |
ret.dataLoaderParams = dataLoaderParams; |
| 1863 |
ret.rollbackDataPolicy = rollbackDataPolicy; |
| 1864 |
ret.requireUserAction = requireUserAction; |
| 1865 |
ret.packageSource = packageSource; |
| 1866 |
return ret; |
| 1867 |
} |
| 1868 |
|
| 1869 |
|
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
public boolean areHiddenOptionsSet() { |
| 1880 |
return (installFlags & (PackageManager.INSTALL_REQUEST_DOWNGRADE |
| 1881 |
| PackageManager.INSTALL_ALLOW_DOWNGRADE |
| 1882 |
| PackageManager.INSTALL_DONT_KILL_APP |
| 1883 |
| PackageManager.INSTALL_INSTANT_APP |
| 1884 |
| PackageManager.INSTALL_FULL_APP |
| 1885 |
| PackageManager.INSTALL_VIRTUAL_PRELOAD |
| 1886 |
| PackageManager.INSTALL_ALLOCATE_AGGRESSIVE)) != installFlags |
| 1887 |
|| abiOverride != null || volumeUuid != null; |
| 1888 |
} |
| 1889 |
|
| 1890 |
|
| 1891 |
|
| 1892 |
|
| 1893 |
|
| 1894 |
|
| 1895 |
public void setInstallLocation(int installLocation) { |
| 1896 |
this.installLocation = installLocation; |
| 1897 |
} |
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
|
| 1902 |
|
| 1903 |
|
| 1904 |
|
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
public void setSize(long sizeBytes) { |
| 1909 |
this.sizeBytes = sizeBytes; |
| 1910 |
} |
| 1911 |
|
| 1912 |
|
| 1913 |
|
| 1914 |
|
| 1915 |
|
| 1916 |
|
| 1917 |
|
| 1918 |
|
| 1919 |
|
| 1920 |
|
| 1921 |
public void setAppPackageName(@Nullable String appPackageName) { |
| 1922 |
this.appPackageName = appPackageName; |
| 1923 |
} |
| 1924 |
|
| 1925 |
|
| 1926 |
|
| 1927 |
|
| 1928 |
|
| 1929 |
|
| 1930 |
public void setAppIcon(@Nullable Bitmap appIcon) { |
| 1931 |
this.appIcon = appIcon; |
| 1932 |
} |
| 1933 |
|
| 1934 |
|
| 1935 |
|
| 1936 |
|
| 1937 |
|
| 1938 |
|
| 1939 |
public void setAppLabel(@Nullable CharSequence appLabel) { |
| 1940 |
this.appLabel = (appLabel != null) ? appLabel.toString() : null; |
| 1941 |
} |
| 1942 |
|
| 1943 |
|
| 1944 |
|
| 1945 |
|
| 1946 |
|
| 1947 |
|
| 1948 |
|
| 1949 |
public void setOriginatingUri(@Nullable Uri originatingUri) { |
| 1950 |
this.originatingUri = originatingUri; |
| 1951 |
} |
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
public void setOriginatingUid(int originatingUid) { |
| 1958 |
this.originatingUid = originatingUid; |
| 1959 |
} |
| 1960 |
|
| 1961 |
|
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
public void setReferrerUri(@Nullable Uri referrerUri) { |
| 1968 |
this.referrerUri = referrerUri; |
| 1969 |
} |
| 1970 |
|
| 1971 |
|
| 1972 |
|
| 1973 |
|
| 1974 |
|
| 1975 |
|
| 1976 |
|
| 1977 |
|
| 1978 |
|
| 1979 |
@SystemApi |
| 1980 |
@RequiresPermission(android.Manifest.permission.INSTALL_GRANT_RUNTIME_PERMISSIONS) |
| 1981 |
public void setGrantedRuntimePermissions(String[] permissions) { |
| 1982 |
installFlags |= PackageManager.INSTALL_GRANT_RUNTIME_PERMISSIONS; |
| 1983 |
this.grantedRuntimePermissions = permissions; |
| 1984 |
} |
| 1985 |
|
| 1986 |
|
| 1987 |
|
| 1988 |
|
| 1989 |
|
| 1990 |
|
| 1991 |
|
| 1992 |
|
| 1993 |
|
| 1994 |
|
| 1995 |
public void setPackageSource(@PackageSourceType int packageSource) { |
| 1996 |
this.packageSource = packageSource; |
| 1997 |
} |
| 1998 |
|
| 1999 |
|
| 2000 |
|
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 2012 |
|
| 2013 |
|
| 2014 |
|
| 2015 |
|
| 2016 |
|
| 2017 |
|
| 2018 |
|
| 2019 |
|
| 2020 |
|
| 2021 |
|
| 2022 |
|
| 2023 |
|
| 2024 |
|
| 2025 |
public void setWhitelistedRestrictedPermissions(@Nullable Set<String> permissions) { |
| 2026 |
if (permissions == RESTRICTED_PERMISSIONS_ALL) { |
| 2027 |
installFlags |= PackageManager.INSTALL_ALL_WHITELIST_RESTRICTED_PERMISSIONS; |
| 2028 |
whitelistedRestrictedPermissions = null; |
| 2029 |
} else { |
| 2030 |
installFlags &= ~PackageManager.INSTALL_ALL_WHITELIST_RESTRICTED_PERMISSIONS; |
| 2031 |
whitelistedRestrictedPermissions = (permissions != null) |
| 2032 |
? new ArrayList<>(permissions) : null; |
| 2033 |
} |
| 2034 |
} |
| 2035 |
|
| 2036 |
|
| 2037 |
|
| 2038 |
|
| 2039 |
|
| 2040 |
|
| 2041 |
|
| 2042 |
|
| 2043 |
|
| 2044 |
|
| 2045 |
|
| 2046 |
|
| 2047 |
|
| 2048 |
|
| 2049 |
|
| 2050 |
@Deprecated |
| 2051 |
public void setAutoRevokePermissionsMode(boolean shouldAutoRevoke) { |
| 2052 |
autoRevokePermissionsMode = shouldAutoRevoke ? MODE_ALLOWED : MODE_IGNORED; |
| 2053 |
} |
| 2054 |
|
| 2055 |
|
| 2056 |
|
| 2057 |
|
| 2058 |
|
| 2059 |
|
| 2060 |
|
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
@SystemApi |
| 2067 |
public void setEnableRollback(boolean enable) { |
| 2068 |
if (enable) { |
| 2069 |
installFlags |= PackageManager.INSTALL_ENABLE_ROLLBACK; |
| 2070 |
} else { |
| 2071 |
installFlags &= ~PackageManager.INSTALL_ENABLE_ROLLBACK; |
| 2072 |
} |
| 2073 |
rollbackDataPolicy = PackageManager.ROLLBACK_DATA_POLICY_RESTORE; |
| 2074 |
} |
| 2075 |
|
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
|
| 2080 |
|
| 2081 |
|
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
|
| 2087 |
|
| 2088 |
|
| 2089 |
|
| 2090 |
@SystemApi |
| 2091 |
public void setEnableRollback(boolean enable, |
| 2092 |
@PackageManager.RollbackDataPolicy int dataPolicy) { |
| 2093 |
if (enable) { |
| 2094 |
installFlags |= PackageManager.INSTALL_ENABLE_ROLLBACK; |
| 2095 |
} else { |
| 2096 |
installFlags &= ~PackageManager.INSTALL_ENABLE_ROLLBACK; |
| 2097 |
} |
| 2098 |
rollbackDataPolicy = dataPolicy; |
| 2099 |
} |
| 2100 |
|
| 2101 |
|
| 2102 |
|
| 2103 |
|
| 2104 |
|
| 2105 |
|
| 2106 |
@SystemApi |
| 2107 |
@Deprecated |
| 2108 |
public void setAllowDowngrade(boolean allowDowngrade) { |
| 2109 |
setRequestDowngrade(allowDowngrade); |
| 2110 |
} |
| 2111 |
|
| 2112 |
|
| 2113 |
@SystemApi |
| 2114 |
public void setRequestDowngrade(boolean requestDowngrade) { |
| 2115 |
if (requestDowngrade) { |
| 2116 |
installFlags |= PackageManager.INSTALL_REQUEST_DOWNGRADE; |
| 2117 |
} else { |
| 2118 |
installFlags &= ~PackageManager.INSTALL_REQUEST_DOWNGRADE; |
| 2119 |
} |
| 2120 |
} |
| 2121 |
|
| 2122 |
|
| 2123 |
|
| 2124 |
|
| 2125 |
|
| 2126 |
|
| 2127 |
|
| 2128 |
|
| 2129 |
|
| 2130 |
|
| 2131 |
public void setRequiredInstalledVersionCode(long versionCode) { |
| 2132 |
requiredInstalledVersionCode = versionCode; |
| 2133 |
} |
| 2134 |
|
| 2135 |
|
| 2136 |
public void setInstallFlagsForcePermissionPrompt() { |
| 2137 |
installFlags |= PackageManager.INSTALL_FORCE_PERMISSION_PROMPT; |
| 2138 |
} |
| 2139 |
|
| 2140 |
|
| 2141 |
@SystemApi |
| 2142 |
public void setDontKillApp(boolean dontKillApp) { |
| 2143 |
if (dontKillApp) { |
| 2144 |
installFlags |= PackageManager.INSTALL_DONT_KILL_APP; |
| 2145 |
} else { |
| 2146 |
installFlags &= ~PackageManager.INSTALL_DONT_KILL_APP; |
| 2147 |
} |
| 2148 |
} |
| 2149 |
|
| 2150 |
|
| 2151 |
@SystemApi |
| 2152 |
public void setInstallAsInstantApp(boolean isInstantApp) { |
| 2153 |
if (isInstantApp) { |
| 2154 |
installFlags |= PackageManager.INSTALL_INSTANT_APP; |
| 2155 |
installFlags &= ~PackageManager.INSTALL_FULL_APP; |
| 2156 |
} else { |
| 2157 |
installFlags &= ~PackageManager.INSTALL_INSTANT_APP; |
| 2158 |
installFlags |= PackageManager.INSTALL_FULL_APP; |
| 2159 |
} |
| 2160 |
} |
| 2161 |
|
| 2162 |
|
| 2163 |
|
| 2164 |
|
| 2165 |
|
| 2166 |
|
| 2167 |
@SystemApi |
| 2168 |
public void setInstallAsVirtualPreload() { |
| 2169 |
installFlags |= PackageManager.INSTALL_VIRTUAL_PRELOAD; |
| 2170 |
} |
| 2171 |
|
| 2172 |
|
| 2173 |
|
| 2174 |
|
| 2175 |
|
| 2176 |
|
| 2177 |
|
| 2178 |
|
| 2179 |
|
| 2180 |
|
| 2181 |
|
| 2182 |
|
| 2183 |
|
| 2184 |
public void setInstallReason(@InstallReason int installReason) { |
| 2185 |
this.installReason = installReason; |
| 2186 |
} |
| 2187 |
|
| 2188 |
|
| 2189 |
@SystemApi |
| 2190 |
@RequiresPermission(android.Manifest.permission.ALLOCATE_AGGRESSIVE) |
| 2191 |
public void setAllocateAggressive(boolean allocateAggressive) { |
| 2192 |
if (allocateAggressive) { |
| 2193 |
installFlags |= PackageManager.INSTALL_ALLOCATE_AGGRESSIVE; |
| 2194 |
} else { |
| 2195 |
installFlags &= ~PackageManager.INSTALL_ALLOCATE_AGGRESSIVE; |
| 2196 |
} |
| 2197 |
} |
| 2198 |
|
| 2199 |
|
| 2200 |
|
| 2201 |
|
| 2202 |
@TestApi |
| 2203 |
public void setInstallFlagAllowTest() { |
| 2204 |
installFlags |= PackageManager.INSTALL_ALLOW_TEST; |
| 2205 |
} |
| 2206 |
|
| 2207 |
|
| 2208 |
|
| 2209 |
|
| 2210 |
|
| 2211 |
|
| 2212 |
|
| 2213 |
|
| 2214 |
|
| 2215 |
@TestApi |
| 2216 |
public void setInstallerPackageName(@Nullable String installerPackageName) { |
| 2217 |
this.installerPackageName = installerPackageName; |
| 2218 |
} |
| 2219 |
|
| 2220 |
|
| 2221 |
|
| 2222 |
|
| 2223 |
|
| 2224 |
|
| 2225 |
|
| 2226 |
|
| 2227 |
|
| 2228 |
public void setMultiPackage() { |
| 2229 |
this.isMultiPackage = true; |
| 2230 |
} |
| 2231 |
|
| 2232 |
|
| 2233 |
|
| 2234 |
|
| 2235 |
|
| 2236 |
|
| 2237 |
|
| 2238 |
|
| 2239 |
|
| 2240 |
|
| 2241 |
|
| 2242 |
|
| 2243 |
|
| 2244 |
@SystemApi |
| 2245 |
@RequiresPermission(Manifest.permission.INSTALL_PACKAGES) |
| 2246 |
public void setStaged() { |
| 2247 |
this.isStaged = true; |
| 2248 |
} |
| 2249 |
|
| 2250 |
|
| 2251 |
|
| 2252 |
|
| 2253 |
|
| 2254 |
|
| 2255 |
@SystemApi |
| 2256 |
@RequiresPermission(Manifest.permission.INSTALL_PACKAGES) |
| 2257 |
public void setInstallAsApex() { |
| 2258 |
installFlags |= PackageManager.INSTALL_APEX; |
| 2259 |
} |
| 2260 |
|
| 2261 |
|
| 2262 |
public boolean getEnableRollback() { |
| 2263 |
return (installFlags & PackageManager.INSTALL_ENABLE_ROLLBACK) != 0; |
| 2264 |
} |
| 2265 |
|
| 2266 |
|
| 2267 |
|
| 2268 |
|
| 2269 |
|
| 2270 |
|
| 2271 |
|
| 2272 |
|
| 2273 |
|
| 2274 |
|
| 2275 |
@SystemApi |
| 2276 |
@RequiresPermission(allOf = { |
| 2277 |
Manifest.permission.INSTALL_PACKAGES, |
| 2278 |
Manifest.permission.USE_INSTALLER_V2}) |
| 2279 |
public void setDataLoaderParams(@NonNull DataLoaderParams dataLoaderParams) { |
| 2280 |
this.dataLoaderParams = dataLoaderParams; |
| 2281 |
} |
| 2282 |
|
| 2283 |
|
| 2284 |
|
| 2285 |
|
| 2286 |
|
| 2287 |
public void setForceQueryable() { |
| 2288 |
this.forceQueryableOverride = true; |
| 2289 |
} |
| 2290 |
|
| 2291 |
|
| 2292 |
|
| 2293 |
|
| 2294 |
|
| 2295 |
|
| 2296 |
|
| 2297 |
|
| 2298 |
|
| 2299 |
|
| 2300 |
|
| 2301 |
|
| 2302 |
|
| 2303 |
|
| 2304 |
|
| 2305 |
|
| 2306 |
|
| 2307 |
|
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
|
| 2312 |
|
| 2313 |
|
| 2314 |
|
| 2315 |
|
| 2316 |
|
| 2317 |
|
| 2318 |
|
| 2319 |
|
| 2320 |
|
| 2321 |
|
| 2322 |
|
| 2323 |
|
| 2324 |
|
| 2325 |
|
| 2326 |
|
| 2327 |
|
| 2328 |
|
| 2329 |
|
| 2330 |
|
| 2331 |
|
| 2332 |
public void setRequireUserAction( |
| 2333 |
@SessionParams.UserActionRequirement int requireUserAction) { |
| 2334 |
if (requireUserAction != USER_ACTION_UNSPECIFIED |
| 2335 |
&& requireUserAction != USER_ACTION_REQUIRED |
| 2336 |
&& requireUserAction != USER_ACTION_NOT_REQUIRED) { |
| 2337 |
throw new IllegalArgumentException("requireUserAction set as invalid value of " |
| 2338 |
+ requireUserAction + ", but must be one of [" |
| 2339 |
+ "USER_ACTION_UNSPECIFIED, USER_ACTION_REQUIRED, USER_ACTION_NOT_REQUIRED" |
| 2340 |
+ "]"); |
| 2341 |
} |
| 2342 |
this.requireUserAction = requireUserAction; |
| 2343 |
} |
| 2344 |
|
| 2345 |
|
| 2346 |
|
| 2347 |
|
| 2348 |
public void setInstallScenario(@InstallScenario int installScenario) { |
| 2349 |
this.installScenario = installScenario; |
| 2350 |
} |
| 2351 |
|
| 2352 |
|
| 2353 |
public void dump(IndentingPrintWriter pw) { |
| 2354 |
pw.printPair("mode", mode); |
| 2355 |
pw.printHexPair("installFlags", installFlags); |
| 2356 |
pw.printPair("installLocation", installLocation); |
| 2357 |
pw.printPair("installReason", installReason); |
| 2358 |
pw.printPair("installScenario", installScenario); |
| 2359 |
pw.printPair("sizeBytes", sizeBytes); |
| 2360 |
pw.printPair("appPackageName", appPackageName); |
| 2361 |
pw.printPair("appIcon", (appIcon != null)); |
| 2362 |
pw.printPair("appLabel", appLabel); |
| 2363 |
pw.printPair("originatingUri", originatingUri); |
| 2364 |
pw.printPair("originatingUid", originatingUid); |
| 2365 |
pw.printPair("referrerUri", referrerUri); |
| 2366 |
pw.printPair("abiOverride", abiOverride); |
| 2367 |
pw.printPair("volumeUuid", volumeUuid); |
| 2368 |
pw.printPair("grantedRuntimePermissions", grantedRuntimePermissions); |
| 2369 |
pw.printPair("packageSource", packageSource); |
| 2370 |
pw.printPair("whitelistedRestrictedPermissions", whitelistedRestrictedPermissions); |
| 2371 |
pw.printPair("autoRevokePermissions", autoRevokePermissionsMode); |
| 2372 |
pw.printPair("installerPackageName", installerPackageName); |
| 2373 |
pw.printPair("isMultiPackage", isMultiPackage); |
| 2374 |
pw.printPair("isStaged", isStaged); |
| 2375 |
pw.printPair("forceQueryable", forceQueryableOverride); |
| 2376 |
pw.printPair("requireUserAction", SessionInfo.userActionToString(requireUserAction)); |
| 2377 |
pw.printPair("requiredInstalledVersionCode", requiredInstalledVersionCode); |
| 2378 |
pw.printPair("dataLoaderParams", dataLoaderParams); |
| 2379 |
pw.printPair("rollbackDataPolicy", rollbackDataPolicy); |
| 2380 |
pw.println(); |
| 2381 |
} |
| 2382 |
|
| 2383 |
@Override |
| 2384 |
public int describeContents() { |
| 2385 |
return 0; |
| 2386 |
} |
| 2387 |
|
| 2388 |
@Override |
| 2389 |
public void writeToParcel(Parcel dest, int flags) { |
| 2390 |
dest.writeInt(mode); |
| 2391 |
dest.writeInt(installFlags); |
| 2392 |
dest.writeInt(installLocation); |
| 2393 |
dest.writeInt(installReason); |
| 2394 |
dest.writeInt(installScenario); |
| 2395 |
dest.writeLong(sizeBytes); |
| 2396 |
dest.writeString(appPackageName); |
| 2397 |
dest.writeParcelable(appIcon, flags); |
| 2398 |
dest.writeString(appLabel); |
| 2399 |
dest.writeParcelable(originatingUri, flags); |
| 2400 |
dest.writeInt(originatingUid); |
| 2401 |
dest.writeParcelable(referrerUri, flags); |
| 2402 |
dest.writeString(abiOverride); |
| 2403 |
dest.writeString(volumeUuid); |
| 2404 |
dest.writeStringArray(grantedRuntimePermissions); |
| 2405 |
dest.writeStringList(whitelistedRestrictedPermissions); |
| 2406 |
dest.writeInt(autoRevokePermissionsMode); |
| 2407 |
dest.writeString(installerPackageName); |
| 2408 |
dest.writeBoolean(isMultiPackage); |
| 2409 |
dest.writeBoolean(isStaged); |
| 2410 |
dest.writeBoolean(forceQueryableOverride); |
| 2411 |
dest.writeLong(requiredInstalledVersionCode); |
| 2412 |
if (dataLoaderParams != null) { |
| 2413 |
dest.writeParcelable(dataLoaderParams.getData(), flags); |
| 2414 |
} else { |
| 2415 |
dest.writeParcelable(null, flags); |
| 2416 |
} |
| 2417 |
dest.writeInt(rollbackDataPolicy); |
| 2418 |
dest.writeInt(requireUserAction); |
| 2419 |
dest.writeInt(packageSource); |
| 2420 |
} |
| 2421 |
|
| 2422 |
public static final Parcelable.Creator<SessionParams> |
| 2423 |
CREATOR = new Parcelable.Creator<SessionParams>() { |
| 2424 |
@Override |
| 2425 |
public SessionParams createFromParcel(Parcel p) { |
| 2426 |
return new SessionParams(p); |
| 2427 |
} |
| 2428 |
|
| 2429 |
@Override |
| 2430 |
public SessionParams[] newArray(int size) { |
| 2431 |
return new SessionParams[size]; |
| 2432 |
} |
| 2433 |
}; |
| 2434 |
} |
| 2435 |
|
| 2436 |
|
| 2437 |
|
| 2438 |
|
| 2439 |
public static class SessionInfo implements Parcelable { |
| 2440 |
|
| 2441 |
|
| 2442 |
|
| 2443 |
|
| 2444 |
public static final int INVALID_ID = -1; |
| 2445 |
|
| 2446 |
private static final int[] NO_SESSIONS = {}; |
| 2447 |
|
| 2448 |
|
| 2449 |
|
| 2450 |
|
| 2451 |
@Deprecated |
| 2452 |
public static final int STAGED_SESSION_NO_ERROR = 0; |
| 2453 |
|
| 2454 |
|
| 2455 |
|
| 2456 |
|
| 2457 |
@Deprecated |
| 2458 |
public static final int STAGED_SESSION_VERIFICATION_FAILED = 1; |
| 2459 |
|
| 2460 |
|
| 2461 |
|
| 2462 |
|
| 2463 |
@Deprecated |
| 2464 |
public static final int STAGED_SESSION_ACTIVATION_FAILED = 2; |
| 2465 |
|
| 2466 |
|
| 2467 |
|
| 2468 |
|
| 2469 |
@Deprecated |
| 2470 |
public static final int STAGED_SESSION_UNKNOWN = 3; |
| 2471 |
|
| 2472 |
|
| 2473 |
|
| 2474 |
|
| 2475 |
@Deprecated |
| 2476 |
public static final int STAGED_SESSION_CONFLICT = 4; |
| 2477 |
|
| 2478 |
|
| 2479 |
|
| 2480 |
|
| 2481 |
|
| 2482 |
public static final int SESSION_NO_ERROR = 0; |
| 2483 |
|
| 2484 |
|
| 2485 |
|
| 2486 |
|
| 2487 |
|
| 2488 |
public static final int SESSION_VERIFICATION_FAILED = 1; |
| 2489 |
|
| 2490 |
|
| 2491 |
|
| 2492 |
|
| 2493 |
|
| 2494 |
public static final int SESSION_ACTIVATION_FAILED = 2; |
| 2495 |
|
| 2496 |
|
| 2497 |
|
| 2498 |
|
| 2499 |
public static final int SESSION_UNKNOWN_ERROR = 3; |
| 2500 |
|
| 2501 |
|
| 2502 |
|
| 2503 |
|
| 2504 |
|
| 2505 |
public static final int SESSION_CONFLICT = 4; |
| 2506 |
|
| 2507 |
private static String userActionToString(int requireUserAction) { |
| 2508 |
switch(requireUserAction) { |
| 2509 |
case SessionParams.USER_ACTION_REQUIRED: |
| 2510 |
return "REQUIRED"; |
| 2511 |
case SessionParams.USER_ACTION_NOT_REQUIRED: |
| 2512 |
return "NOT_REQUIRED"; |
| 2513 |
default: |
| 2514 |
return "UNSPECIFIED"; |
| 2515 |
} |
| 2516 |
} |
| 2517 |
|
| 2518 |
|
| 2519 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 2520 |
public int sessionId; |
| 2521 |
|
| 2522 |
public int userId; |
| 2523 |
|
| 2524 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 2525 |
public String installerPackageName; |
| 2526 |
|
| 2527 |
public String installerAttributionTag; |
| 2528 |
|
| 2529 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 2530 |
public String resolvedBaseCodePath; |
| 2531 |
|
| 2532 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 2533 |
public float progress; |
| 2534 |
|
| 2535 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 2536 |
public boolean sealed; |
| 2537 |
|
| 2538 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 2539 |
public boolean active; |
| 2540 |
|
| 2541 |
|
| 2542 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 2543 |
public int mode; |
| 2544 |
|
| 2545 |
public @InstallReason int installReason; |
| 2546 |
|
| 2547 |
public @InstallScenario int installScenario; |
| 2548 |
|
| 2549 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 2550 |
public long sizeBytes; |
| 2551 |
|
| 2552 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 2553 |
public String appPackageName; |
| 2554 |
|
| 2555 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 2556 |
public Bitmap appIcon; |
| 2557 |
|
| 2558 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 2559 |
public CharSequence appLabel; |
| 2560 |
|
| 2561 |
|
| 2562 |
public int installLocation; |
| 2563 |
|
| 2564 |
public Uri originatingUri; |
| 2565 |
|
| 2566 |
public int originatingUid; |
| 2567 |
|
| 2568 |
public Uri referrerUri; |
| 2569 |
|
| 2570 |
public String[] grantedRuntimePermissions; |
| 2571 |
|
| 2572 |
public List<String> whitelistedRestrictedPermissions; |
| 2573 |
|
| 2574 |
public int autoRevokePermissionsMode = MODE_DEFAULT; |
| 2575 |
|
| 2576 |
public int installFlags; |
| 2577 |
|
| 2578 |
public boolean isMultiPackage; |
| 2579 |
|
| 2580 |
public boolean isStaged; |
| 2581 |
|
| 2582 |
public boolean forceQueryable; |
| 2583 |
|
| 2584 |
public int parentSessionId = INVALID_ID; |
| 2585 |
|
| 2586 |
public int[] childSessionIds = NO_SESSIONS; |
| 2587 |
|
| 2588 |
|
| 2589 |
public boolean isSessionApplied; |
| 2590 |
|
| 2591 |
public boolean isSessionReady; |
| 2592 |
|
| 2593 |
public boolean isSessionFailed; |
| 2594 |
private int mSessionErrorCode; |
| 2595 |
private String mSessionErrorMessage; |
| 2596 |
|
| 2597 |
|
| 2598 |
public boolean isCommitted; |
| 2599 |
|
| 2600 |
|
| 2601 |
public long createdMillis; |
| 2602 |
|
| 2603 |
|
| 2604 |
public long updatedMillis; |
| 2605 |
|
| 2606 |
|
| 2607 |
public int rollbackDataPolicy; |
| 2608 |
|
| 2609 |
|
| 2610 |
public int requireUserAction; |
| 2611 |
|
| 2612 |
|
| 2613 |
public int packageSource = PACKAGE_SOURCE_UNSPECIFIED; |
| 2614 |
|
| 2615 |
|
| 2616 |
public int installerUid; |
| 2617 |
|
| 2618 |
|
| 2619 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 2620 |
public SessionInfo() { |
| 2621 |
} |
| 2622 |
|
| 2623 |
|
| 2624 |
public SessionInfo(Parcel source) { |
| 2625 |
sessionId = source.readInt(); |
| 2626 |
userId = source.readInt(); |
| 2627 |
installerPackageName = source.readString(); |
| 2628 |
installerAttributionTag = source.readString(); |
| 2629 |
resolvedBaseCodePath = source.readString(); |
| 2630 |
progress = source.readFloat(); |
| 2631 |
sealed = source.readInt() != 0; |
| 2632 |
active = source.readInt() != 0; |
| 2633 |
|
| 2634 |
mode = source.readInt(); |
| 2635 |
installReason = source.readInt(); |
| 2636 |
installScenario = source.readInt(); |
| 2637 |
sizeBytes = source.readLong(); |
| 2638 |
appPackageName = source.readString(); |
| 2639 |
appIcon = source.readParcelable(null, android.graphics.Bitmap.class); |
| 2640 |
appLabel = source.readString(); |
| 2641 |
|
| 2642 |
installLocation = source.readInt(); |
| 2643 |
originatingUri = source.readParcelable(null, android.net.Uri.class); |
| 2644 |
originatingUid = source.readInt(); |
| 2645 |
referrerUri = source.readParcelable(null, android.net.Uri.class); |
| 2646 |
grantedRuntimePermissions = source.readStringArray(); |
| 2647 |
whitelistedRestrictedPermissions = source.createStringArrayList(); |
| 2648 |
autoRevokePermissionsMode = source.readInt(); |
| 2649 |
|
| 2650 |
installFlags = source.readInt(); |
| 2651 |
isMultiPackage = source.readBoolean(); |
| 2652 |
isStaged = source.readBoolean(); |
| 2653 |
forceQueryable = source.readBoolean(); |
| 2654 |
parentSessionId = source.readInt(); |
| 2655 |
childSessionIds = source.createIntArray(); |
| 2656 |
if (childSessionIds == null) { |
| 2657 |
childSessionIds = NO_SESSIONS; |
| 2658 |
} |
| 2659 |
isSessionApplied = source.readBoolean(); |
| 2660 |
isSessionReady = source.readBoolean(); |
| 2661 |
isSessionFailed = source.readBoolean(); |
| 2662 |
mSessionErrorCode = source.readInt(); |
| 2663 |
mSessionErrorMessage = source.readString(); |
| 2664 |
isCommitted = source.readBoolean(); |
| 2665 |
rollbackDataPolicy = source.readInt(); |
| 2666 |
createdMillis = source.readLong(); |
| 2667 |
requireUserAction = source.readInt(); |
| 2668 |
installerUid = source.readInt(); |
| 2669 |
packageSource = source.readInt(); |
| 2670 |
} |
| 2671 |
|
| 2672 |
|
| 2673 |
|
| 2674 |
|
| 2675 |
public int getSessionId() { |
| 2676 |
return sessionId; |
| 2677 |
} |
| 2678 |
|
| 2679 |
|
| 2680 |
|
| 2681 |
|
| 2682 |
public @NonNull UserHandle getUser() { |
| 2683 |
return new UserHandle(userId); |
| 2684 |
} |
| 2685 |
|
| 2686 |
|
| 2687 |
|
| 2688 |
|
| 2689 |
public @Nullable String getInstallerPackageName() { |
| 2690 |
return installerPackageName; |
| 2691 |
} |
| 2692 |
|
| 2693 |
|
| 2694 |
|
| 2695 |
|
| 2696 |
|
| 2697 |
public @Nullable String getInstallerAttributionTag() { |
| 2698 |
return installerAttributionTag; |
| 2699 |
} |
| 2700 |
|
| 2701 |
|
| 2702 |
|
| 2703 |
|
| 2704 |
|
| 2705 |
|
| 2706 |
|
| 2707 |
|
| 2708 |
|
| 2709 |
|
| 2710 |
public float getProgress() { |
| 2711 |
return progress; |
| 2712 |
} |
| 2713 |
|
| 2714 |
|
| 2715 |
|
| 2716 |
|
| 2717 |
|
| 2718 |
|
| 2719 |
|
| 2720 |
|
| 2721 |
|
| 2722 |
|
| 2723 |
|
| 2724 |
|
| 2725 |
|
| 2726 |
|
| 2727 |
public boolean isActive() { |
| 2728 |
return active; |
| 2729 |
} |
| 2730 |
|
| 2731 |
|
| 2732 |
|
| 2733 |
|
| 2734 |
|
| 2735 |
|
| 2736 |
|
| 2737 |
public boolean isSealed() { |
| 2738 |
return sealed; |
| 2739 |
} |
| 2740 |
|
| 2741 |
|
| 2742 |
|
| 2743 |
|
| 2744 |
|
| 2745 |
|
| 2746 |
public @InstallReason int getInstallReason() { |
| 2747 |
return installReason; |
| 2748 |
} |
| 2749 |
|
| 2750 |
|
| 2751 |
@Deprecated |
| 2752 |
public boolean isOpen() { |
| 2753 |
return isActive(); |
| 2754 |
} |
| 2755 |
|
| 2756 |
|
| 2757 |
|
| 2758 |
|
| 2759 |
|
| 2760 |
public @Nullable String getAppPackageName() { |
| 2761 |
return appPackageName; |
| 2762 |
} |
| 2763 |
|
| 2764 |
|
| 2765 |
|
| 2766 |
|
| 2767 |
|
| 2768 |
public @Nullable Bitmap getAppIcon() { |
| 2769 |
if (appIcon == null) { |
| 2770 |
|
| 2771 |
|
| 2772 |
try { |
| 2773 |
final SessionInfo info = AppGlobals.getPackageManager().getPackageInstaller() |
| 2774 |
.getSessionInfo(sessionId); |
| 2775 |
appIcon = (info != null) ? info.appIcon : null; |
| 2776 |
} catch (RemoteException e) { |
| 2777 |
throw e.rethrowFromSystemServer(); |
| 2778 |
} |
| 2779 |
} |
| 2780 |
return appIcon; |
| 2781 |
} |
| 2782 |
|
| 2783 |
|
| 2784 |
|
| 2785 |
|
| 2786 |
|
| 2787 |
public @Nullable CharSequence getAppLabel() { |
| 2788 |
return appLabel; |
| 2789 |
} |
| 2790 |
|
| 2791 |
|
| 2792 |
|
| 2793 |
|
| 2794 |
|
| 2795 |
|
| 2796 |
|
| 2797 |
|
| 2798 |
|
| 2799 |
|
| 2800 |
public @Nullable Intent createDetailsIntent() { |
| 2801 |
final Intent intent = new Intent(PackageInstaller.ACTION_SESSION_DETAILS); |
| 2802 |
intent.putExtra(PackageInstaller.EXTRA_SESSION_ID, sessionId); |
| 2803 |
intent.setPackage(installerPackageName); |
| 2804 |
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2805 |
return intent; |
| 2806 |
} |
| 2807 |
|
| 2808 |
|
| 2809 |
|
| 2810 |
|
| 2811 |
|
| 2812 |
|
| 2813 |
|
| 2814 |
public int getMode() { |
| 2815 |
return mode; |
| 2816 |
} |
| 2817 |
|
| 2818 |
|
| 2819 |
|
| 2820 |
|
| 2821 |
public int getInstallLocation() { |
| 2822 |
return installLocation; |
| 2823 |
} |
| 2824 |
|
| 2825 |
|
| 2826 |
|
| 2827 |
|
| 2828 |
|
| 2829 |
|
| 2830 |
public long getSize() { |
| 2831 |
return sizeBytes; |
| 2832 |
} |
| 2833 |
|
| 2834 |
|
| 2835 |
|
| 2836 |
|
| 2837 |
|
| 2838 |
public @Nullable Uri getOriginatingUri() { |
| 2839 |
return originatingUri; |
| 2840 |
} |
| 2841 |
|
| 2842 |
|
| 2843 |
|
| 2844 |
|
| 2845 |
public int getOriginatingUid() { |
| 2846 |
return originatingUid; |
| 2847 |
} |
| 2848 |
|
| 2849 |
|
| 2850 |
|
| 2851 |
|
| 2852 |
|
| 2853 |
public @Nullable Uri getReferrerUri() { |
| 2854 |
return referrerUri; |
| 2855 |
} |
| 2856 |
|
| 2857 |
|
| 2858 |
|
| 2859 |
|
| 2860 |
|
| 2861 |
|
| 2862 |
@SystemApi |
| 2863 |
public @Nullable String[] getGrantedRuntimePermissions() { |
| 2864 |
return grantedRuntimePermissions; |
| 2865 |
} |
| 2866 |
|
| 2867 |
|
| 2868 |
|
| 2869 |
|
| 2870 |
|
| 2871 |
|
| 2872 |
|
| 2873 |
|
| 2874 |
@SystemApi |
| 2875 |
public @NonNull Set<String> getWhitelistedRestrictedPermissions() { |
| 2876 |
if ((installFlags & PackageManager.INSTALL_ALL_WHITELIST_RESTRICTED_PERMISSIONS) != 0) { |
| 2877 |
return SessionParams.RESTRICTED_PERMISSIONS_ALL; |
| 2878 |
} |
| 2879 |
if (whitelistedRestrictedPermissions != null) { |
| 2880 |
return new ArraySet<>(whitelistedRestrictedPermissions); |
| 2881 |
} |
| 2882 |
return Collections.emptySet(); |
| 2883 |
} |
| 2884 |
|
| 2885 |
|
| 2886 |
|
| 2887 |
|
| 2888 |
|
| 2889 |
|
| 2890 |
|
| 2891 |
|
| 2892 |
|
| 2893 |
|
| 2894 |
|
| 2895 |
|
| 2896 |
|
| 2897 |
@SystemApi |
| 2898 |
public int getAutoRevokePermissionsMode() { |
| 2899 |
return autoRevokePermissionsMode; |
| 2900 |
} |
| 2901 |
|
| 2902 |
|
| 2903 |
|
| 2904 |
|
| 2905 |
|
| 2906 |
|
| 2907 |
|
| 2908 |
@SystemApi |
| 2909 |
@Deprecated |
| 2910 |
public boolean getAllowDowngrade() { |
| 2911 |
return getRequestDowngrade(); |
| 2912 |
} |
| 2913 |
|
| 2914 |
|
| 2915 |
|
| 2916 |
|
| 2917 |
|
| 2918 |
|
| 2919 |
@SystemApi |
| 2920 |
public boolean getRequestDowngrade() { |
| 2921 |
return (installFlags & PackageManager.INSTALL_REQUEST_DOWNGRADE) != 0; |
| 2922 |
} |
| 2923 |
|
| 2924 |
|
| 2925 |
|
| 2926 |
|
| 2927 |
|
| 2928 |
|
| 2929 |
@SystemApi |
| 2930 |
public boolean getDontKillApp() { |
| 2931 |
return (installFlags & PackageManager.INSTALL_DONT_KILL_APP) != 0; |
| 2932 |
} |
| 2933 |
|
| 2934 |
|
| 2935 |
|
| 2936 |
|
| 2937 |
|
| 2938 |
|
| 2939 |
|
| 2940 |
|
| 2941 |
|
| 2942 |
|
| 2943 |
|
| 2944 |
|
| 2945 |
|
| 2946 |
@SystemApi |
| 2947 |
public boolean getInstallAsInstantApp(boolean isInstantApp) { |
| 2948 |
return (installFlags & PackageManager.INSTALL_INSTANT_APP) != 0; |
| 2949 |
} |
| 2950 |
|
| 2951 |
|
| 2952 |
|
| 2953 |
|
| 2954 |
|
| 2955 |
|
| 2956 |
|
| 2957 |
|
| 2958 |
|
| 2959 |
|
| 2960 |
|
| 2961 |
|
| 2962 |
|
| 2963 |
@SystemApi |
| 2964 |
public boolean getInstallAsFullApp(boolean isInstantApp) { |
| 2965 |
return (installFlags & PackageManager.INSTALL_FULL_APP) != 0; |
| 2966 |
} |
| 2967 |
|
| 2968 |
|
| 2969 |
|
| 2970 |
|
| 2971 |
|
| 2972 |
|
| 2973 |
@SystemApi |
| 2974 |
public boolean getInstallAsVirtualPreload() { |
| 2975 |
return (installFlags & PackageManager.INSTALL_VIRTUAL_PRELOAD) != 0; |
| 2976 |
} |
| 2977 |
|
| 2978 |
|
| 2979 |
|
| 2980 |
|
| 2981 |
|
| 2982 |
|
| 2983 |
@SystemApi |
| 2984 |
public boolean getEnableRollback() { |
| 2985 |
return (installFlags & PackageManager.INSTALL_ENABLE_ROLLBACK) != 0; |
| 2986 |
} |
| 2987 |
|
| 2988 |
|
| 2989 |
|
| 2990 |
|
| 2991 |
|
| 2992 |
|
| 2993 |
@SystemApi |
| 2994 |
public boolean getAllocateAggressive() { |
| 2995 |
return (installFlags & PackageManager.INSTALL_ALLOCATE_AGGRESSIVE) != 0; |
| 2996 |
} |
| 2997 |
|
| 2998 |
|
| 2999 |
|
| 3000 |
@Deprecated |
| 3001 |
public @Nullable Intent getDetailsIntent() { |
| 3002 |
return createDetailsIntent(); |
| 3003 |
} |
| 3004 |
|
| 3005 |
|
| 3006 |
|
| 3007 |
|
| 3008 |
|
| 3009 |
public @PackageSourceType int getPackageSource() { |
| 3010 |
return packageSource; |
| 3011 |
} |
| 3012 |
|
| 3013 |
|
| 3014 |
|
| 3015 |
|
| 3016 |
|
| 3017 |
public boolean isMultiPackage() { |
| 3018 |
return isMultiPackage; |
| 3019 |
} |
| 3020 |
|
| 3021 |
|
| 3022 |
|
| 3023 |
|
| 3024 |
public boolean isStaged() { |
| 3025 |
return isStaged; |
| 3026 |
} |
| 3027 |
|
| 3028 |
|
| 3029 |
|
| 3030 |
|
| 3031 |
|
| 3032 |
|
| 3033 |
@SystemApi |
| 3034 |
@PackageManager.RollbackDataPolicy |
| 3035 |
public int getRollbackDataPolicy() { |
| 3036 |
return rollbackDataPolicy; |
| 3037 |
} |
| 3038 |
|
| 3039 |
|
| 3040 |
|
| 3041 |
|
| 3042 |
|
| 3043 |
public boolean isForceQueryable() { |
| 3044 |
return forceQueryable; |
| 3045 |
} |
| 3046 |
|
| 3047 |
|
| 3048 |
|
| 3049 |
|
| 3050 |
|
| 3051 |
|
| 3052 |
|
| 3053 |
|
| 3054 |
|
| 3055 |
|
| 3056 |
|
| 3057 |
|
| 3058 |
|
| 3059 |
|
| 3060 |
|
| 3061 |
|
| 3062 |
|
| 3063 |
|
| 3064 |
|
| 3065 |
public boolean isStagedSessionActive() { |
| 3066 |
return isStaged && isCommitted && !isSessionApplied && !isSessionFailed |
| 3067 |
&& !hasParentSessionId(); |
| 3068 |
} |
| 3069 |
|
| 3070 |
|
| 3071 |
|
| 3072 |
|
| 3073 |
|
| 3074 |
public int getParentSessionId() { |
| 3075 |
return parentSessionId; |
| 3076 |
} |
| 3077 |
|
| 3078 |
|
| 3079 |
|
| 3080 |
|
| 3081 |
public boolean hasParentSessionId() { |
| 3082 |
return parentSessionId != INVALID_ID; |
| 3083 |
} |
| 3084 |
|
| 3085 |
|
| 3086 |
|
| 3087 |
|
| 3088 |
|
| 3089 |
@NonNull |
| 3090 |
public int[] getChildSessionIds() { |
| 3091 |
return childSessionIds; |
| 3092 |
} |
| 3093 |
|
| 3094 |
private void checkSessionIsStaged() { |
| 3095 |
if (!isStaged) { |
| 3096 |
throw new IllegalStateException("Session is not marked as staged."); |
| 3097 |
} |
| 3098 |
} |
| 3099 |
|
| 3100 |
|
| 3101 |
|
| 3102 |
|
| 3103 |
|
| 3104 |
|
| 3105 |
public boolean isStagedSessionApplied() { |
| 3106 |
checkSessionIsStaged(); |
| 3107 |
return isSessionApplied; |
| 3108 |
} |
| 3109 |
|
| 3110 |
|
| 3111 |
|
| 3112 |
|
| 3113 |
|
| 3114 |
public boolean isStagedSessionReady() { |
| 3115 |
checkSessionIsStaged(); |
| 3116 |
return isSessionReady; |
| 3117 |
} |
| 3118 |
|
| 3119 |
|
| 3120 |
|
| 3121 |
|
| 3122 |
|
| 3123 |
public boolean isStagedSessionFailed() { |
| 3124 |
checkSessionIsStaged(); |
| 3125 |
return isSessionFailed; |
| 3126 |
} |
| 3127 |
|
| 3128 |
|
| 3129 |
|
| 3130 |
|
| 3131 |
|
| 3132 |
public int getStagedSessionErrorCode() { |
| 3133 |
checkSessionIsStaged(); |
| 3134 |
return mSessionErrorCode; |
| 3135 |
} |
| 3136 |
|
| 3137 |
|
| 3138 |
|
| 3139 |
|
| 3140 |
|
| 3141 |
public @NonNull String getStagedSessionErrorMessage() { |
| 3142 |
checkSessionIsStaged(); |
| 3143 |
return mSessionErrorMessage; |
| 3144 |
} |
| 3145 |
|
| 3146 |
|
| 3147 |
public void setSessionErrorCode(int errorCode, String errorMessage) { |
| 3148 |
mSessionErrorCode = errorCode; |
| 3149 |
mSessionErrorMessage = errorMessage; |
| 3150 |
} |
| 3151 |
|
| 3152 |
|
| 3153 |
|
| 3154 |
|
| 3155 |
|
| 3156 |
public boolean isCommitted() { |
| 3157 |
return isCommitted; |
| 3158 |
} |
| 3159 |
|
| 3160 |
|
| 3161 |
|
| 3162 |
|
| 3163 |
public long getCreatedMillis() { |
| 3164 |
return createdMillis; |
| 3165 |
} |
| 3166 |
|
| 3167 |
|
| 3168 |
|
| 3169 |
|
| 3170 |
|
| 3171 |
@CurrentTimeMillisLong |
| 3172 |
public long getUpdatedMillis() { |
| 3173 |
return updatedMillis; |
| 3174 |
} |
| 3175 |
|
| 3176 |
|
| 3177 |
|
| 3178 |
|
| 3179 |
|
| 3180 |
|
| 3181 |
|
| 3182 |
|
| 3183 |
|
| 3184 |
|
| 3185 |
|
| 3186 |
|
| 3187 |
@SessionParams.UserActionRequirement |
| 3188 |
public int getRequireUserAction() { |
| 3189 |
return requireUserAction; |
| 3190 |
} |
| 3191 |
|
| 3192 |
|
| 3193 |
|
| 3194 |
|
| 3195 |
|
| 3196 |
|
| 3197 |
public int getInstallerUid() { |
| 3198 |
return installerUid; |
| 3199 |
} |
| 3200 |
|
| 3201 |
@Override |
| 3202 |
public int describeContents() { |
| 3203 |
return 0; |
| 3204 |
} |
| 3205 |
|
| 3206 |
@Override |
| 3207 |
public void writeToParcel(Parcel dest, int flags) { |
| 3208 |
dest.writeInt(sessionId); |
| 3209 |
dest.writeInt(userId); |
| 3210 |
dest.writeString(installerPackageName); |
| 3211 |
dest.writeString(installerAttributionTag); |
| 3212 |
dest.writeString(resolvedBaseCodePath); |
| 3213 |
dest.writeFloat(progress); |
| 3214 |
dest.writeInt(sealed ? 1 : 0); |
| 3215 |
dest.writeInt(active ? 1 : 0); |
| 3216 |
|
| 3217 |
dest.writeInt(mode); |
| 3218 |
dest.writeInt(installReason); |
| 3219 |
dest.writeInt(installScenario); |
| 3220 |
dest.writeLong(sizeBytes); |
| 3221 |
dest.writeString(appPackageName); |
| 3222 |
dest.writeParcelable(appIcon, flags); |
| 3223 |
dest.writeString(appLabel != null ? appLabel.toString() : null); |
| 3224 |
|
| 3225 |
dest.writeInt(installLocation); |
| 3226 |
dest.writeParcelable(originatingUri, flags); |
| 3227 |
dest.writeInt(originatingUid); |
| 3228 |
dest.writeParcelable(referrerUri, flags); |
| 3229 |
dest.writeStringArray(grantedRuntimePermissions); |
| 3230 |
dest.writeStringList(whitelistedRestrictedPermissions); |
| 3231 |
dest.writeInt(autoRevokePermissionsMode); |
| 3232 |
dest.writeInt(installFlags); |
| 3233 |
dest.writeBoolean(isMultiPackage); |
| 3234 |
dest.writeBoolean(isStaged); |
| 3235 |
dest.writeBoolean(forceQueryable); |
| 3236 |
dest.writeInt(parentSessionId); |
| 3237 |
dest.writeIntArray(childSessionIds); |
| 3238 |
dest.writeBoolean(isSessionApplied); |
| 3239 |
dest.writeBoolean(isSessionReady); |
| 3240 |
dest.writeBoolean(isSessionFailed); |
| 3241 |
dest.writeInt(mSessionErrorCode); |
| 3242 |
dest.writeString(mSessionErrorMessage); |
| 3243 |
dest.writeBoolean(isCommitted); |
| 3244 |
dest.writeInt(rollbackDataPolicy); |
| 3245 |
dest.writeLong(createdMillis); |
| 3246 |
dest.writeInt(requireUserAction); |
| 3247 |
dest.writeInt(installerUid); |
| 3248 |
dest.writeInt(packageSource); |
| 3249 |
} |
| 3250 |
|
| 3251 |
public static final Parcelable.Creator<SessionInfo> |
| 3252 |
CREATOR = new Parcelable.Creator<SessionInfo>() { |
| 3253 |
@Override |
| 3254 |
public SessionInfo createFromParcel(Parcel p) { |
| 3255 |
return new SessionInfo(p); |
| 3256 |
} |
| 3257 |
|
| 3258 |
@Override |
| 3259 |
public SessionInfo[] newArray(int size) { |
| 3260 |
return new SessionInfo[size]; |
| 3261 |
} |
| 3262 |
}; |
| 3263 |
} |
| 3264 |
} |