Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2e124501 authored by Jackal Guo's avatar Jackal Guo
Browse files

Handle update-ownership tag

For update ownership enforcement, using the config to enable the
enforcement for the system apps.

A config is expected to have "update-ownership" tags per package:
```
<config>
    <update-ownership package="foo" installer="bar" />
</config>
```

Bug: 244413073
Test: atest FrameworksServicesTests:SystemConfigTest
Change-Id: I38e996eb885a130f72f656b27731d9f31b16b366
parent df5a4fe7
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -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());
+52 −0
Original line number Diff line number Diff line
@@ -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);