Addresses unresolved comments for silent updates
Bug: 182487678
Test: atest CtsSilentUpdateHostTestCases
Change-Id: I2019213a8b45c23ba2c519a2457aae45081616f9
diff --git a/core/java/android/content/pm/PackageInstaller.java b/core/java/android/content/pm/PackageInstaller.java
index caedd70..b389fd6d 100644
--- a/core/java/android/content/pm/PackageInstaller.java
+++ b/core/java/android/content/pm/PackageInstaller.java
@@ -1566,7 +1566,7 @@
/** {@hide} */
public boolean forceQueryableOverride;
/** {@hide} */
- public Boolean requireUserAction;
+ public int requireUserAction = SessionInfo.USER_ACTION_UNSPECIFIED;
/**
* Construct parameters for a new package install session.
@@ -1609,12 +1609,7 @@
dataLoaderParams = new DataLoaderParams(dataLoaderParamsParcel);
}
rollbackDataPolicy = source.readInt();
- int requireUserActionInt = source.readInt();
- requireUserAction = requireUserActionInt == 0
- ? Boolean.FALSE
- : requireUserActionInt == 1
- ? Boolean.TRUE : null;
-
+ requireUserAction = source.readInt();
}
/** {@hide} */
@@ -2045,31 +2040,34 @@
* {@link android.Manifest.permission#REQUEST_INSTALL_PACKAGES android.permission
* #REQUEST_INSTALL_PACKAGES} permission, and {@code false} otherwise. When {@code true},
* installers will receive a {@link #STATUS_PENDING_USER_ACTION} callback once the
- * session is committed, indicating that the user is required for the install to proceed.
+ * session is committed, indicating that user action is required for the install to proceed.
* <p>
- * For installers using the {@link android.Manifest.permission#REQUEST_INSTALL_PACKAGES
- * android.permission.REQUEST_INSTALL_PACKAGES} permission, user action will not be
- * required when the following conditions are met:
+ * For installers that have been granted the
+ * {@link android.Manifest.permission#REQUEST_INSTALL_PACKAGES android.permission
+ * .REQUEST_INSTALL_PACKAGES} permission, user action will not be required when all of
+ * the following conditions are met:
*
* <ul>
* <li>{@code requireUserAction} is set to {@code false}.</li>
- * <li>The being installed targets {@link android.os.Build.VERSION_CODES#Q API 29} or
- * higher.</li>
+ * <li>The app being installed targets {@link android.os.Build.VERSION_CODES#Q API 29}
+ * or higher.</li>
* <li>The installer is the {@link InstallSourceInfo#getInstallingPackageName()
* installer of record} of an existing version of the app (i.e.: this install session
- * is an app update or the installer is updating itself).</li>
+ * is an app update) or the installer is updating itself.</li>
* <li>The installer declares the
* {@link android.Manifest.permission#UPDATE_PACKAGES_WITHOUT_USER_ACTION android
* .permission.UPDATE_PACKAGES_WITHOUT_USER_ACTION} permission.</li>
* </ul>
* <p>
* Note: The target API level requirement will advance in future Android versions.
- * Session owners should always be prepared to handle {@link #STATUS_PENDING_USER_ACTION}
+ * Session owners should always be prepared to handle {@link #STATUS_PENDING_USER_ACTION}.
*
* @param requireUserAction whether user action should be required.
*/
public void setRequireUserAction(boolean requireUserAction) {
- this.requireUserAction = requireUserAction;
+ this.requireUserAction = requireUserAction
+ ? SessionInfo.USER_ACTION_REQUIRED
+ : SessionInfo.USER_ACTION_NOT_REQUIRED;
}
/**
@@ -2102,7 +2100,7 @@
pw.printPair("isMultiPackage", isMultiPackage);
pw.printPair("isStaged", isStaged);
pw.printPair("forceQueryable", forceQueryableOverride);
- pw.printPair("requireUserAction", requireUserAction);
+ pw.printPair("requireUserAction", SessionInfo.userActionToString(requireUserAction));
pw.printPair("requiredInstalledVersionCode", requiredInstalledVersionCode);
pw.printPair("dataLoaderParams", dataLoaderParams);
pw.printPair("rollbackDataPolicy", rollbackDataPolicy);
@@ -2144,10 +2142,7 @@
dest.writeParcelable(null, flags);
}
dest.writeInt(rollbackDataPolicy);
- dest.writeInt(requireUserAction == Boolean.TRUE
- ? 1
- : requireUserAction == Boolean.FALSE
- ? 0 : 2);
+ dest.writeInt(requireUserAction);
}
public static final Parcelable.Creator<SessionParams>
@@ -2224,7 +2219,7 @@
public @interface UserActionRequirement {}
/**
- * The installer did not calling {@link SessionParams#setRequireUserAction(boolean)} to
+ * The installer did not call {@link SessionParams#setRequireUserAction(boolean)} to
* specify whether user action should be required for the install.
*/
public static final int USER_ACTION_UNSPECIFIED = 0;
@@ -2239,6 +2234,17 @@
*/
public static final int USER_ACTION_NOT_REQUIRED = 2;
+ private static String userActionToString(int requireUserAction) {
+ switch(requireUserAction) {
+ case SessionInfo.USER_ACTION_REQUIRED:
+ return "REQUIRED";
+ case SessionInfo.USER_ACTION_NOT_REQUIRED:
+ return "NOT_REQUIRED";
+ default:
+ return "UNSPECIFIED";
+ }
+ }
+
/** {@hide} */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
public int sessionId;
@@ -2331,7 +2337,7 @@
public int rollbackDataPolicy;
/** {@hide} */
- public Boolean requireUserAction;
+ public int requireUserAction;
/** {@hide} */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
@@ -2382,11 +2388,7 @@
isCommitted = source.readBoolean();
rollbackDataPolicy = source.readInt();
createdMillis = source.readLong();
- int requireUserActionInt = source.readInt();
- requireUserAction = requireUserActionInt == 0
- ? Boolean.FALSE
- : requireUserActionInt == 1
- ? Boolean.TRUE : null;
+ requireUserAction = source.readInt();
}
/**
@@ -2898,11 +2900,7 @@
*/
@UserActionRequirement
public int getRequireUserAction() {
- return requireUserAction == null
- ? USER_ACTION_UNSPECIFIED
- : requireUserAction == Boolean.TRUE
- ? USER_ACTION_REQUIRED
- : USER_ACTION_NOT_REQUIRED;
+ return requireUserAction;
}
@Override
@@ -2950,10 +2948,7 @@
dest.writeBoolean(isCommitted);
dest.writeInt(rollbackDataPolicy);
dest.writeLong(createdMillis);
- dest.writeInt(requireUserAction == Boolean.TRUE
- ? 1
- : requireUserAction == Boolean.FALSE
- ? 0 : 2);
+ dest.writeInt(requireUserAction);
}
public static final Parcelable.Creator<SessionInfo>
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index be306e0..c0a3e81 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -5688,13 +5688,9 @@
<permission android:name="android.permission.SET_CLIP_SOURCE"
android:protectionLevel="signature|recents" />
- <!-- Allows an application to request installs that update existing packages do so without
- user action via
- {@link android.content.pm.PackageInstaller.SessionParams#setRequireUserAction(boolean)}.
- This permission only grants the ability to make the request and is not a guarantee that the
- request will be honored. In order to execute the install, the caller must also have the
- "android.permission.REQUEST_INSTALL_PACKAGES" or "android.permission.INSTALL_PACKAGES"
- permissions.
+ <!-- Allows an application to indicate via
+ {@link android.content.pm.PackageInstaller.SessionParams#setRequireUserAction(boolean)}
+ that user action should not be required for an app update.
<p>Protection level: normal
-->
<permission android:name="android.permission.UPDATE_PACKAGES_WITHOUT_USER_ACTION"
diff --git a/services/core/java/com/android/server/pm/PackageInstallerSession.java b/services/core/java/com/android/server/pm/PackageInstallerSession.java
index 2e6c57c..671fccf 100644
--- a/services/core/java/com/android/server/pm/PackageInstallerSession.java
+++ b/services/core/java/com/android/server/pm/PackageInstallerSession.java
@@ -927,7 +927,7 @@
final boolean forcePermissionPrompt =
(params.installFlags & PackageManager.INSTALL_FORCE_PERMISSION_PROMPT) != 0
- || params.requireUserAction == Boolean.TRUE;
+ || params.requireUserAction == SessionInfo.USER_ACTION_REQUIRED;
if (forcePermissionPrompt) {
return USER_ACTION_REQUIRED;
}
@@ -976,7 +976,7 @@
return USER_ACTION_REQUIRED;
}
- if (params.requireUserAction == Boolean.FALSE
+ if (params.requireUserAction == SessionInfo.USER_ACTION_NOT_REQUIRED
&& isUpdateWithoutUserActionPermissionGranted
&& (isInstallerOfRecord || isSelfUpdate)) {
return USER_ACTION_PENDING_APK_PARSING;