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

Commit 035820cb authored by Paul Duffin's avatar Paul Duffin
Browse files

Insert org.apache.http.legacy at the start of the shared library list

Ensure consistent behaviour depending on whether OAHL is on the
bootclasspath or not.

When OAHL is on the bootclasspath the search order is (where ... is the
other libraries on the bootclasspath):
   OAHL
   ...
   shared libraries
   optional shared libraries
   APK

Prior to this change the OAHL was added to the end of the shared
library list which meant the search order (when OAHL is not on the
bootclasspath) would be:
   ...
   shared libraries
   OAHL
   optional shared libraries
   APK

After this change the order will be:
   ...
   OAHL
   shared libraries
   optional shared libraries
   APK

The slight difference at the beginning is not an issue because there are
no conflicting resources or class files between OAHL and the other boot
libraries.

Bug: 65552462
Bug: 18027885
Test: build, flash, check systrace when starting GoogleDialer
Change-Id: Ifcb4d50c13e35eebac4d18f8f0f10dd0734e8896
parent 0c3ad040
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.content.pm;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.pm.PackageParser.Package;
import android.os.Build;

@@ -56,7 +58,7 @@ public class PackageBackwardCompatibility {
            boolean apacheHttpLegacyPresent = isLibraryPresent(
                    usesLibraries, usesOptionalLibraries, APACHE_HTTP_LEGACY);
            if (!apacheHttpLegacyPresent) {
                usesLibraries = ArrayUtils.add(usesLibraries, APACHE_HTTP_LEGACY);
                usesLibraries = prefix(usesLibraries, APACHE_HTTP_LEGACY);
            }
        }

@@ -86,4 +88,12 @@ public class PackageBackwardCompatibility {
        return ArrayUtils.contains(usesLibraries, apacheHttpLegacy)
                || ArrayUtils.contains(usesOptionalLibraries, apacheHttpLegacy);
    }

    private static @NonNull <T> ArrayList<T> prefix(@Nullable ArrayList<T> cur, T val) {
        if (cur == null) {
            cur = new ArrayList<>();
        }
        cur.add(0, val);
        return cur;
    }
}
+14 −0
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@ public class PackageBackwardCompatibilityTest {

    private static final String ANDROID_TEST_MOCK = "android.test.mock";

    private static final String OTHER_LIBRARY = "other.library";

    private Package mPackage;

    private static ArrayList<String> arrayList(String... strings) {
@@ -77,6 +79,18 @@ public class PackageBackwardCompatibilityTest {
        assertNull("usesOptionalLibraries not updated correctly", mPackage.usesOptionalLibraries);
    }

    @Test
    public void targeted_at_O_not_empty_usesLibraries() {
        mPackage.applicationInfo.targetSdkVersion = Build.VERSION_CODES.O;
        mPackage.usesLibraries = arrayList(OTHER_LIBRARY);
        PackageBackwardCompatibility.modifySharedLibraries(mPackage);
        // The org.apache.http.legacy jar should be added at the start of the list.
        assertEquals("usesLibraries not updated correctly",
                arrayList(ORG_APACHE_HTTP_LEGACY, OTHER_LIBRARY),
                mPackage.usesLibraries);
        assertNull("usesOptionalLibraries not updated correctly", mPackage.usesOptionalLibraries);
    }

    @Test
    public void targeted_at_O_org_apache_http_legacy_in_usesLibraries() {
        mPackage.applicationInfo.targetSdkVersion = Build.VERSION_CODES.O;