Add strict mode feature flag for low target sdk
Use the new MinInstallableTargetSdk__install_block_strict_mode_enabled feature flag to no longer give exemptions to install blocks when strict mode is enabled for: 1) All installs from adb 2) Any install where the installer package name is null (not installed from a store) Bug: 237321649 Test: adb shell device_config put package_manager_service MinInstallableTargetSdk__install_block_strict_mode_enabled true Test: adb shell device_config put package_manager_service MinInstallableTargetSdk__strict_mode_target_sdk 23 Test: adb install ~/install_target_sdk_22.apk (install blocked) Test: adb install --bypass-low-target-sdk-block ~/install_target_sdk_22.apk (install successful) Test: adb shell device_config put package_manager_service MinInstallableTargetSdk__install_block_strict_mode_enabled false Test: adb install ~/install_target_sdk_22.apk (install successful) Change-Id: Ie6d44b5f16bf7dd35d3c75f51a9c94fd4ef9dcb6
This commit is contained in:
@@ -1083,19 +1083,32 @@ final class InstallPackageHelper {
|
|||||||
"MinInstallableTargetSdk__min_installable_target_sdk",
|
"MinInstallableTargetSdk__min_installable_target_sdk",
|
||||||
0);
|
0);
|
||||||
|
|
||||||
|
// Determine if enforcement is in strict mode
|
||||||
|
boolean strictMode = false;
|
||||||
|
if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PACKAGE_MANAGER_SERVICE,
|
||||||
|
"MinInstallableTargetSdk__install_block_strict_mode_enabled",
|
||||||
|
false)) {
|
||||||
|
if (parsedPackage.getTargetSdkVersion()
|
||||||
|
< DeviceConfig.getInt(DeviceConfig.NAMESPACE_PACKAGE_MANAGER_SERVICE,
|
||||||
|
"MinInstallableTargetSdk__strict_mode_target_sdk",
|
||||||
|
0)) {
|
||||||
|
strictMode = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Skip enforcement when the bypass flag is set
|
// Skip enforcement when the bypass flag is set
|
||||||
boolean bypassLowTargetSdkBlock =
|
boolean bypassLowTargetSdkBlock =
|
||||||
((installFlags & PackageManager.INSTALL_BYPASS_LOW_TARGET_SDK_BLOCK) != 0);
|
((installFlags & PackageManager.INSTALL_BYPASS_LOW_TARGET_SDK_BLOCK) != 0);
|
||||||
|
|
||||||
// Skip enforcement for tests that were installed from adb
|
// Skip enforcement for tests that were installed from adb
|
||||||
if (!bypassLowTargetSdkBlock
|
if (!strictMode && !bypassLowTargetSdkBlock
|
||||||
&& ((installFlags & PackageManager.INSTALL_FROM_ADB) != 0)) {
|
&& ((installFlags & PackageManager.INSTALL_FROM_ADB) != 0)) {
|
||||||
bypassLowTargetSdkBlock = true;
|
bypassLowTargetSdkBlock = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip enforcement if the installer package name is not set
|
// Skip enforcement if the installer package name is not set
|
||||||
// (e.g. "pm install" from shell)
|
// (e.g. "pm install" from shell)
|
||||||
if (!bypassLowTargetSdkBlock) {
|
if (!strictMode && !bypassLowTargetSdkBlock) {
|
||||||
if (request.getInstallerPackageName() == null) {
|
if (request.getInstallerPackageName() == null) {
|
||||||
bypassLowTargetSdkBlock = true;
|
bypassLowTargetSdkBlock = true;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user