Merge "Handle update-ownership tag"

This commit is contained in:
Jackal Guo
2023-01-05 23:54:04 +00:00
committed by Android (Google) Code Review
2 changed files with 77 additions and 0 deletions

View File

@@ -329,6 +329,8 @@ public class SystemConfig {
private final Set<String> mInstallConstraintsAllowlist = new ArraySet<>();
private String mModulesInstallerPackageName;
// Update ownership for system applications and the installers eligible to update them.
private final ArrayMap<String, String> mUpdateOwnersForSystemApps = new ArrayMap<>();
/**
* Map of system pre-defined, uniquely named actors; keys are namespace,
@@ -475,6 +477,13 @@ public class SystemConfig {
return mModulesInstallerPackageName;
}
/**
* Gets the update owner of the given package from "update-ownership" tags in sysconfig.
*/
public @Nullable String getSystemAppUpdateOwnerPackageName(@NonNull String packageName) {
return mUpdateOwnersForSystemApps.get(packageName);
}
public ArraySet<String> getAppDataIsolationWhitelistedApps() {
return mAppDataIsolationWhitelistedApps;
}
@@ -1405,6 +1414,22 @@ public class SystemConfig {
}
XmlUtils.skipCurrentTag(parser);
} break;
case "update-ownership": {
final String packageName = parser.getAttributeValue(null /* namespace */,
"package");
final String installerName = parser.getAttributeValue(null /* namespace */,
"installer");
if (TextUtils.isEmpty(packageName)) {
Slog.w(TAG, "<" + name + "> without valid package in " + permFile
+ " at " + parser.getPositionDescription());
} else if (TextUtils.isEmpty(installerName)) {
Slog.w(TAG, "<" + name + "> without valid installer in " + permFile
+ " at " + parser.getPositionDescription());
} else {
mUpdateOwnersForSystemApps.put(packageName, installerName);
}
XmlUtils.skipCurrentTag(parser);
} break;
default: {
Slog.w(TAG, "Tag " + name + " is unknown in "
+ permFile + " at " + parser.getPositionDescription());

View File

@@ -594,6 +594,58 @@ public class SystemConfigTest {
assertFooIsOnlySharedLibrary();
}
/**
* Tests that readPermissions works correctly for the tag: {@code update-ownership}.
*/
@Test
public void readPermissions_updateOwnership_successful() throws IOException {
final String contents =
"<config>\n"
+ " <update-ownership package=\"com.foo\" installer=\"com.bar\" />\n"
+ "</config>";
final File folder = createTempSubfolder("folder");
createTempFile(folder, "update_ownership.xml", contents);
readPermissions(folder, /* Grant all permission flags */ ~0);
assertThat(mSysConfig.getSystemAppUpdateOwnerPackageName("com.foo"))
.isEqualTo("com.bar");
}
/**
* Tests that readPermissions works correctly for the tag: {@code update-ownership}.
*/
@Test
public void readPermissions_updateOwnership_noPackage() throws IOException {
final String contents =
"<config>\n"
+ " <update-ownership />\n"
+ "</config>";
final File folder = createTempSubfolder("folder");
createTempFile(folder, "update_ownership.xml", contents);
readPermissions(folder, /* Grant all permission flags */ ~0);
assertThat(mSysConfig.getSystemAppUpdateOwnerPackageName("com.foo")).isNull();
}
/**
* Tests that readPermissions works correctly for the tag: {@code update-ownership}.
*/
@Test
public void readPermissions_updateOwnership_noInstaller() throws IOException {
final String contents =
"<config>\n"
+ " <update-ownership package=\"com.foo\" />\n"
+ "</config>";
final File folder = createTempSubfolder("folder");
createTempFile(folder, "update_ownership.xml", contents);
readPermissions(folder, /* Grant all permission flags */ ~0);
assertThat(mSysConfig.getSystemAppUpdateOwnerPackageName("com.foo")).isNull();
}
private void parseSharedLibraries(String contents) throws IOException {
File folder = createTempSubfolder("permissions_folder");
createTempFile(folder, "permissions.xml", contents);