Add a switch for pre-approval request

In case we decide not to provide pre-approval request to installer
for some reason (e.g., feature off), we need a way to disable this,
and let callers know the typical flow will be needed instead.

Bug: 242677131
Test: atest CtsPackageInstallTestCases:PreapprovalInstallTest
Change-Id: I42dead8044597238588dcf55ddd7d617ac21f671
This commit is contained in:
Jackal Guo
2022-10-04 11:16:56 +08:00
parent a44cf8829d
commit 1d1eb8e621
3 changed files with 35 additions and 0 deletions

View File

@@ -2205,6 +2205,13 @@ public abstract class PackageManager {
*/
public static final int INSTALL_ACTIVATION_FAILED = -128;
/**
* Installation failed return code: requesting user pre-approval is currently unavailable.
*
* @hide
*/
public static final int INSTALL_FAILED_PRE_APPROVAL_NOT_AVAILABLE = -129;
/** @hide */
@IntDef(flag = true, prefix = { "DELETE_" }, value = {
DELETE_KEEP_DATA,
@@ -9635,6 +9642,7 @@ public abstract class PackageManager {
case INSTALL_FAILED_NO_MATCHING_ABIS: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
case INSTALL_FAILED_ABORTED: return PackageInstaller.STATUS_FAILURE_ABORTED;
case INSTALL_FAILED_MISSING_SPLIT: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
case INSTALL_FAILED_PRE_APPROVAL_NOT_AVAILABLE: return PackageInstaller.STATUS_FAILURE_BLOCKED;
default: return PackageInstaller.STATUS_FAILURE;
}
}

View File

@@ -29,6 +29,7 @@ import static android.content.pm.PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
import static android.content.pm.PackageManager.INSTALL_FAILED_INVALID_APK;
import static android.content.pm.PackageManager.INSTALL_FAILED_MEDIA_UNAVAILABLE;
import static android.content.pm.PackageManager.INSTALL_FAILED_MISSING_SPLIT;
import static android.content.pm.PackageManager.INSTALL_FAILED_PRE_APPROVAL_NOT_AVAILABLE;
import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
import static android.content.pm.PackageManager.INSTALL_STAGED;
import static android.content.pm.PackageManager.INSTALL_SUCCEEDED;
@@ -4243,6 +4244,13 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
public void requestUserPreapproval(@NonNull PreapprovalDetails details,
@NonNull IntentSender statusReceiver) {
validatePreapprovalRequest(details, statusReceiver);
if (!mPm.isPreapprovalRequestAvailable()) {
sendUpdateToRemoteStatusReceiver(INSTALL_FAILED_PRE_APPROVAL_NOT_AVAILABLE,
"Request user pre-approval is currently not available.", null /* extras */);
return;
}
dispatchPreapprovalRequest();
}

View File

@@ -494,6 +494,15 @@ public class PackageManagerService implements PackageSender, TestUtilityService
*/
private static final String PROPERTY_KNOWN_DIGESTERS_LIST = "known_digesters_list";
/**
* Whether of not requesting the approval before committing sessions is available.
*
* Flag type: {@code boolean}
* Namespace: NAMESPACE_PACKAGE_MANAGER_SERVICE
*/
private static final String PROPERTY_IS_PRE_APPROVAL_REQUEST_AVAILABLE =
"is_preapproval_available";
/**
* The default response for package verification timeout.
*
@@ -6889,6 +6898,16 @@ public class PackageManagerService implements PackageSender, TestUtilityService
}
}
static boolean isPreapprovalRequestAvailable() {
final long token = Binder.clearCallingIdentity();
try {
return DeviceConfig.getBoolean(NAMESPACE_PACKAGE_MANAGER_SERVICE,
PROPERTY_IS_PRE_APPROVAL_REQUEST_AVAILABLE, true /* defaultValue */);
} finally {
Binder.restoreCallingIdentity(token);
}
}
/**
* Returns the array containing per-uid timeout configuration.
* This is derived from DeviceConfig flags.