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

Commit 2f653107 authored by Rhed Jao's avatar Rhed Jao
Browse files

Ignore prebuilt shared library if it doesn't exist on device

Bug: 191232777
Test: atest PackageManagerTest
Test: atest SystemConfigTest
Change-Id: I756e2c909af6ad0dcf8f1857ba398cfe07862b29
parent 0ee1df68
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -870,7 +870,8 @@ public class SystemConfig {
                                boolean allowedMinSdk = minDeviceSdk <= Build.VERSION.SDK_INT;
                                boolean allowedMaxSdk =
                                        maxDeviceSdk == 0 || maxDeviceSdk >= Build.VERSION.SDK_INT;
                                if (allowedMinSdk && allowedMaxSdk) {
                                final boolean exists = new File(lfile).exists();
                                if (allowedMinSdk && allowedMaxSdk && exists) {
                                    int bcpSince = XmlUtils.readIntAttribute(parser,
                                            "on-bootclasspath-since", 0);
                                    int bcpBefore = XmlUtils.readIntAttribute(parser,
@@ -880,6 +881,19 @@ public class SystemConfig {
                                                    ? new String[0] : ldependency.split(":"),
                                            bcpSince, bcpBefore);
                                    mSharedLibraries.put(lname, entry);
                                } else {
                                    final StringBuilder msg = new StringBuilder(
                                            "Ignore shared library ").append(lname).append(":");
                                    if (!allowedMinSdk) {
                                        msg.append(" min-device-sdk=").append(minDeviceSdk);
                                    }
                                    if (!allowedMaxSdk) {
                                        msg.append(" max-device-sdk=").append(maxDeviceSdk);
                                    }
                                    if (!exists) {
                                        msg.append(" ").append(lfile).append(" does not exist");
                                    }
                                    Slog.i(TAG, msg.toString());
                                }
                            }
                        } else {
+14 −11
Original line number Diff line number Diff line
@@ -62,12 +62,15 @@ public class SystemConfigTest {
    private static final String LOG_TAG = "SystemConfigTest";

    private SystemConfig mSysConfig;
    private File mFooJar;

    @Rule public TemporaryFolder mTemporaryFolder = new TemporaryFolder();

    @Before
    public void setUp() throws Exception {
        mSysConfig = new SystemConfigTestClass();
        mFooJar = createTempFile(
                mTemporaryFolder.getRoot().getCanonicalFile(), "foo.jar", "JAR");
    }

    /**
@@ -340,7 +343,7 @@ public class SystemConfigTest {
                "<permissions>\n"
                + "    <library \n"
                + "        name=\"foo\"\n"
                + "        file=\"foo.jar\"\n"
                + "        file=\"" + mFooJar + "\"\n"
                + "        on-bootclasspath-before=\"10\"\n"
                + "        on-bootclasspath-since=\"20\"\n"
                + "     />\n\n"
@@ -362,7 +365,7 @@ public class SystemConfigTest {
                "<permissions>\n"
                        + "    <updatable-library \n"
                        + "        name=\"foo\"\n"
                        + "        file=\"foo.jar\"\n"
                        + "        file=\"" + mFooJar + "\"\n"
                        + "        on-bootclasspath-before=\"10\"\n"
                        + "        on-bootclasspath-since=\"20\"\n"
                        + "     />\n\n"
@@ -384,7 +387,7 @@ public class SystemConfigTest {
                "<permissions>\n"
                + "    <library \n"
                + "        name=\"foo\"\n"
                + "        file=\"foo.jar\"\n"
                + "        file=\"" + mFooJar + "\"\n"
                + "        min-device-sdk=\"30\"\n"
                + "     />\n\n"
                + " </permissions>";
@@ -402,7 +405,7 @@ public class SystemConfigTest {
                "<permissions>\n"
                + "    <library \n"
                + "        name=\"foo\"\n"
                + "        file=\"foo.jar\"\n"
                + "        file=\"" + mFooJar + "\"\n"
                + "        min-device-sdk=\"" + Build.VERSION.SDK_INT + "\"\n"
                + "     />\n\n"
                + " </permissions>";
@@ -420,7 +423,7 @@ public class SystemConfigTest {
                "<permissions>\n"
                + "    <library \n"
                + "        name=\"foo\"\n"
                + "        file=\"foo.jar\"\n"
                + "        file=\"" + mFooJar + "\"\n"
                + "        min-device-sdk=\"" + (Build.VERSION.SDK_INT + 1) + "\"\n"
                + "     />\n\n"
                + " </permissions>";
@@ -438,7 +441,7 @@ public class SystemConfigTest {
                "<permissions>\n"
                + "    <library \n"
                + "        name=\"foo\"\n"
                + "        file=\"foo.jar\"\n"
                + "        file=\"" + mFooJar + "\"\n"
                + "        max-device-sdk=\"30\"\n"
                + "     />\n\n"
                + " </permissions>";
@@ -456,7 +459,7 @@ public class SystemConfigTest {
                "<permissions>\n"
                + "    <library \n"
                + "        name=\"foo\"\n"
                + "        file=\"foo.jar\"\n"
                + "        file=\"" + mFooJar + "\"\n"
                + "        max-device-sdk=\"" + Build.VERSION.SDK_INT + "\"\n"
                + "     />\n\n"
                + " </permissions>";
@@ -474,7 +477,7 @@ public class SystemConfigTest {
                "<permissions>\n"
                + "    <library \n"
                + "        name=\"foo\"\n"
                + "        file=\"foo.jar\"\n"
                + "        file=\"" + mFooJar + "\"\n"
                + "        max-device-sdk=\"" + (Build.VERSION.SDK_INT + 1) + "\"\n"
                + "     />\n\n"
                + " </permissions>";
@@ -507,7 +510,7 @@ public class SystemConfigTest {
     * @param folder   pre-existing subdirectory of mTemporaryFolder to put the file
     * @param fileName name of the file (e.g. filename.xml) to create
     * @param contents contents to write to the file
     * @return the folder containing the newly created file (not the file itself!)
     * @return the newly created file
     */
    private File createTempFile(File folder, String fileName, String contents)
            throws IOException {
@@ -523,13 +526,13 @@ public class SystemConfigTest {
            Log.d(LOG_TAG, input.nextLine());
        }

        return folder;
        return file;
    }

    private void assertFooIsOnlySharedLibrary() {
        assertThat(mSysConfig.getSharedLibraries().size()).isEqualTo(1);
        SystemConfig.SharedLibraryEntry entry = mSysConfig.getSharedLibraries().get("foo");
        assertThat(entry.name).isEqualTo("foo");
        assertThat(entry.filename).isEqualTo("foo.jar");
        assertThat(entry.filename).isEqualTo(mFooJar.toString());
    }
}