Mark all installations using PMSC as "ADB".

This will allow tests to disable verification on case-by-case basis.

Bug: 224017187
Bug: 220086205
Test: atest PackageManagerShellCommandTest ResourcesHardeningTest PackageManagerShellCommandIncrementalTest ChecksumsTest
Change-Id: Ie0e77f1cbc52b7fe56e00e8b0b36f47b2422391b
This commit is contained in:
Alex Buynytskyy
2022-03-19 14:12:41 -07:00
parent 5593d1dd5d
commit a3a7732e89
4 changed files with 51 additions and 27 deletions

View File

@@ -640,7 +640,8 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
&& params.installerPackageName.length() < SessionParams.MAX_PACKAGE_NAME_LENGTH)
? params.installerPackageName : installerPackageName;
if ((callingUid == Process.SHELL_UID) || (callingUid == Process.ROOT_UID)) {
if ((callingUid == Process.SHELL_UID) || (callingUid == Process.ROOT_UID)
|| PackageInstallerSession.isSystemDataLoaderInstallation(params)) {
params.installFlags |= PackageManager.INSTALL_FROM_ADB;
// adb installs can override the installingPackageName, but not the
// initiatingPackageName
@@ -666,8 +667,7 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
&& !mPm.isCallerVerifier(snapshot, callingUid)) {
params.installFlags &= ~PackageManager.INSTALL_VIRTUAL_PRELOAD;
}
if (mContext.checkCallingOrSelfPermission(
Manifest.permission.INSTALL_TEST_ONLY_PACKAGE)
if (mContext.checkCallingOrSelfPermission(Manifest.permission.INSTALL_TEST_ONLY_PACKAGE)
!= PackageManager.PERMISSION_GRANTED) {
params.installFlags &= ~PackageManager.INSTALL_ALLOW_TEST;
}

View File

@@ -29,7 +29,6 @@ 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_FROM_ADB;
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;
@@ -705,6 +704,18 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
}
};
static boolean isDataLoaderInstallation(SessionParams params) {
return params.dataLoaderParams != null;
}
static boolean isSystemDataLoaderInstallation(SessionParams params) {
if (!isDataLoaderInstallation(params)) {
return false;
}
return SYSTEM_DATA_LOADER_PACKAGE.equals(
params.dataLoaderParams.getComponentName().getPackageName());
}
private final Handler.Callback mHandlerCallback = new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
@@ -744,7 +755,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
};
private boolean isDataLoaderInstallation() {
return params.dataLoaderParams != null;
return isDataLoaderInstallation(this.params);
}
private boolean isStreamingInstallation() {
@@ -756,11 +767,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
}
private boolean isSystemDataLoaderInstallation() {
if (!isDataLoaderInstallation()) {
return false;
}
return SYSTEM_DATA_LOADER_PACKAGE.equals(
this.params.dataLoaderParams.getComponentName().getPackageName());
return isSystemDataLoaderInstallation(this.params);
}
/**
@@ -957,17 +964,12 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
"DataLoader installation of APEX modules is not allowed.");
}
if (isSystemDataLoaderInstallation()) {
if (mContext.checkCallingOrSelfPermission(
Manifest.permission.USE_SYSTEM_DATA_LOADERS)
!= PackageManager.PERMISSION_GRANTED) {
throw new SecurityException("You need the "
+ "com.android.permission.USE_SYSTEM_DATA_LOADERS permission "
+ "to use system data loaders");
}
// All installations using system dataloaders marked as ADB.
this.params.installFlags |= INSTALL_FROM_ADB;
if (isSystemDataLoaderInstallation() && mContext.checkCallingOrSelfPermission(
Manifest.permission.USE_SYSTEM_DATA_LOADERS)
!= PackageManager.PERMISSION_GRANTED) {
throw new SecurityException("You need the "
+ "com.android.permission.USE_SYSTEM_DATA_LOADERS permission "
+ "to use system data loaders");
}
}
@@ -1264,13 +1266,21 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
return;
}
final String initiatingPackageName = getInstallSource().initiatingPackageName;
final String installerPackageName;
if (!TextUtils.isEmpty(getInstallSource().initiatingPackageName)) {
installerPackageName = getInstallSource().initiatingPackageName;
} else {
installerPackageName = getInstallSource().installerPackageName;
}
if (TextUtils.isEmpty(installerPackageName)) {
throw new IllegalStateException("Installer package is empty.");
}
final AppOpsManager appOps = mContext.getSystemService(AppOpsManager.class);
appOps.checkPackage(Binder.getCallingUid(), initiatingPackageName);
appOps.checkPackage(Binder.getCallingUid(), installerPackageName);
final PackageManagerInternal pmi = LocalServices.getService(PackageManagerInternal.class);
final AndroidPackage callingInstaller = pmi.getPackage(initiatingPackageName);
final AndroidPackage callingInstaller = pmi.getPackage(installerPackageName);
if (callingInstaller == null) {
throw new IllegalStateException("Can't obtain calling installer's package.");
}

View File

@@ -1254,9 +1254,18 @@ public class PackageManagerService implements PackageSender, TestUtilityService
if (applicationInfo == null) {
throw new ParcelableException(new PackageManager.NameNotFoundException(packageName));
}
final InstallSourceInfo installSourceInfo = snapshot.getInstallSourceInfo(packageName);
final String installerPackageName =
installSourceInfo != null ? installSourceInfo.getInitiatingPackageName() : null;
final String installerPackageName;
if (installSourceInfo != null) {
if (!TextUtils.isEmpty(installSourceInfo.getInitiatingPackageName())) {
installerPackageName = installSourceInfo.getInitiatingPackageName();
} else {
installerPackageName = installSourceInfo.getInstallingPackageName();
}
} else {
installerPackageName = null;
}
List<Pair<String, File>> filesToChecksum = new ArrayList<>();

View File

@@ -111,6 +111,11 @@ static bool getAlwaysEnableReadTimeoutsForSystemDataLoaders() {
true);
}
static bool getEnableReadTimeoutsAfterInstall() {
return android::base::GetBoolProperty("debug.incremental.enable_read_timeouts_after_install",
true);
}
static bool getEnforceReadLogsMaxIntervalForSystemDataLoaders() {
return android::base::GetBoolProperty("debug.incremental.enforce_readlogs_max_interval_for_"
"system_dataloaders",
@@ -853,7 +858,7 @@ void IncrementalService::onInstallationComplete(StorageId storage) {
// Always enable long read timeouts after installation is complete.
std::unique_lock l(ifs->lock);
ifs->setReadTimeoutsRequested(true);
ifs->setReadTimeoutsRequested(getEnableReadTimeoutsAfterInstall());
applyStorageParamsLocked(*ifs);
}