Fix appMetadataFilePath when restoring system app

When restoring a disabled system app the appMetadataFilePath field was
not being copied over from the disabled PackageSetting to the new
PackageSetting. This is now copied over in enableSystemPackageLPw.

The appMetadataFilePath was also being set in commitPackageSettings
which is shared code path for both installs and restores. This was
causing the appMetadataFilePath to be set to null when restoring. Moved
the relevant code instead to commitPackagesLocked so that it only sets
for installs and not restores.

Also added GET_APP_METADATA permission check to guard the
get-app-metadata adb command.

Bug: 281589646
Test: Manual
Test: atest android.packageinstaller.install.cts.InstallAppMetadataTest
Change-Id: I69b90d61b1f53f8eaefc2adf719eca99f77e81ea
This commit is contained in:
William Loh
2023-05-10 11:07:02 -07:00
parent c0d1de114f
commit 32e9cd9b54
3 changed files with 12 additions and 7 deletions

View File

@@ -499,13 +499,6 @@ final class InstallPackageHelper {
mPm.setUpCustomResolverActivity(pkg, pkgSetting);
}
File appMetadataFile = new File(pkgSetting.getPath(), APP_METADATA_FILE_NAME);
if (appMetadataFile.exists()) {
pkgSetting.setAppMetadataFilePath(appMetadataFile.getAbsolutePath());
} else {
pkgSetting.setAppMetadataFilePath(null);
}
if (pkg.getPackageName().equals("android")) {
mPm.setPlatformPackage(pkg, pkgSetting);
}
@@ -2170,6 +2163,13 @@ final class InstallPackageHelper {
installRequest.setNewUsers(
ps.queryInstalledUsers(mPm.mUserManager.getUserIds(), true));
ps.setUpdateAvailable(false /*updateAvailable*/);
File appMetadataFile = new File(ps.getPath(), APP_METADATA_FILE_NAME);
if (appMetadataFile.exists()) {
ps.setAppMetadataFilePath(appMetadataFile.getAbsolutePath());
} else {
ps.setAppMetadataFilePath(null);
}
}
if (installRequest.getReturnCode() == PackageManager.INSTALL_SUCCEEDED) {
mPm.updateSequenceNumberLP(ps, installRequest.getNewUsers());

View File

@@ -16,6 +16,7 @@
package com.android.server.pm;
import static android.Manifest.permission.GET_APP_METADATA;
import static android.content.pm.PackageInstaller.LOCATION_DATA_APP;
import static android.content.pm.PackageManager.FLAG_PERMISSION_REVIEW_REQUIRED;
import static android.content.pm.PackageManager.FLAG_PERMISSION_REVOKED_COMPAT;
@@ -3576,6 +3577,7 @@ class PackageManagerShellCommand extends ShellCommand {
}
private int runGetAppMetadata() {
mContext.enforceCallingOrSelfPermission(GET_APP_METADATA, "getAppMetadataFd");
final PrintWriter pw = getOutPrintWriter();
String pkgName = getNextArgRequired();
ParcelFileDescriptor pfd = null;

View File

@@ -921,6 +921,7 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
p.getUsesStaticLibraries(), p.getUsesStaticLibrariesVersions(), p.getMimeGroups(),
mDomainVerificationManager.generateNewId());
if (ret != null) {
ret.setAppMetadataFilePath(p.getAppMetadataFilePath());
ret.getPkgState().setUpdatedSystemApp(false);
}
mDisabledSysPackages.remove(name);
@@ -3700,6 +3701,8 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
ps.setSharedUserAppId(sharedUserAppId);
}
ps.setAppMetadataFilePath(parser.getAttributeValue(null, "appMetadataFilePath"));
int outerDepth = parser.getDepth();
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT