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

Commit 33eacc6c authored by Winson's avatar Winson
Browse files

ParsingPackage/ParsedPackage test code migration

Part of the Parsing/ParsedPackage split into core/server.

Moves core tests that are should now be in services,
and cleans up/migrates test code. Import changes, moving
classes into the server, and general small cleanup.

This is the final commit in the Parsing/ParsedPackage split.

Bug: 135203078

Test: enumerated in first commit of change ID
		Ib4fe51d729a56bfb0ea1316e577358ba0dfceccf

Change-Id: I694da372feda070815e05b450807a18d71ec9b9d
parent 5e0a1d5c
Loading
Loading
Loading
Loading
+0 −8
Original line number Original line Diff line number Diff line
@@ -83,21 +83,13 @@ java_genrule {
        ":FrameworksCoreTests_install_bad_dex",
        ":FrameworksCoreTests_install_bad_dex",
        ":FrameworksCoreTests_install_complete_package_info",
        ":FrameworksCoreTests_install_complete_package_info",
        ":FrameworksCoreTests_install_decl_perm",
        ":FrameworksCoreTests_install_decl_perm",
        ":FrameworksCoreTests_install_intent_filters",
        ":FrameworksCoreTests_install_jni_lib_open_from_apk",
        ":FrameworksCoreTests_install_jni_lib_open_from_apk",
        ":FrameworksCoreTests_install_loc_auto",
        ":FrameworksCoreTests_install_loc_auto",
        ":FrameworksCoreTests_install_loc_internal",
        ":FrameworksCoreTests_install_loc_internal",
        ":FrameworksCoreTests_install_loc_sdcard",
        ":FrameworksCoreTests_install_loc_sdcard",
        ":FrameworksCoreTests_install_loc_unspecified",
        ":FrameworksCoreTests_install_loc_unspecified",
        ":FrameworksCoreTests_install_split_base",
        ":FrameworksCoreTests_install_split_feature_a",
        ":FrameworksCoreTests_install_use_perm_good",
        ":FrameworksCoreTests_install_use_perm_good",
        ":FrameworksCoreTests_install_uses_feature",
        ":FrameworksCoreTests_install_uses_feature",
        ":FrameworksCoreTests_install_uses_sdk_0",
        ":FrameworksCoreTests_install_uses_sdk_q0",
        ":FrameworksCoreTests_install_uses_sdk_r",
        ":FrameworksCoreTests_install_uses_sdk_r0",
        ":FrameworksCoreTests_install_uses_sdk_r5",
        ":FrameworksCoreTests_install_verifier_bad",
        ":FrameworksCoreTests_install_verifier_bad",
        ":FrameworksCoreTests_install_verifier_good",
        ":FrameworksCoreTests_install_verifier_good",
        ":FrameworksCoreTests_keyset_permdef_sa_unone",
        ":FrameworksCoreTests_keyset_permdef_sa_unone",
+1 −1
Original line number Original line Diff line number Diff line
/*
/*
 * Copyright (C) 2019 The Android Open Source Project
 * Copyright (C) 2020 The Android Open Source Project
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * you may not use this file except in compliance with the License.
+1 −1
Original line number Original line Diff line number Diff line
/*
/*
 * Copyright (C) 2019 The Android Open Source Project
 * Copyright (C) 2020 The Android Open Source Project
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * you may not use this file except in compliance with the License.
+1 −1
Original line number Original line Diff line number Diff line
/*
/*
 * Copyright (C) 2019 The Android Open Source Project
 * Copyright (C) 2020 The Android Open Source Project
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * you may not use this file except in compliance with the License.
+18 −34
Original line number Original line Diff line number Diff line
/*
/*
 * Copyright (C) 2019 The Android Open Source Project
 * Copyright (C) 2020 The Android Open Source Project
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ import static com.android.server.pm.parsing.library.SharedLibraryNames.ANDROID_T
import static com.android.server.pm.parsing.library.SharedLibraryNames.ANDROID_TEST_RUNNER;
import static com.android.server.pm.parsing.library.SharedLibraryNames.ANDROID_TEST_RUNNER;
import static com.android.server.pm.parsing.library.SharedLibraryNames.ORG_APACHE_HTTP_LEGACY;
import static com.android.server.pm.parsing.library.SharedLibraryNames.ORG_APACHE_HTTP_LEGACY;


import android.content.pm.PackageParser;
import android.util.Log;
import android.util.Log;


import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
@@ -28,7 +29,6 @@ import com.android.server.pm.parsing.pkg.ParsedPackage;


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
import java.util.function.Supplier;


/**
/**
 * Modifies {@link ParsedPackage} in order to maintain backwards compatibility.
 * Modifies {@link ParsedPackage} in order to maintain backwards compatibility.
@@ -55,13 +55,7 @@ public class PackageBackwardCompatibility extends PackageSharedLibraryUpdater {
        // android.test.mock.
        // android.test.mock.
        packageUpdaters.add(new AndroidTestRunnerSplitUpdater());
        packageUpdaters.add(new AndroidTestRunnerSplitUpdater());


        // Attempt to load and add the optional updater that will only be available when
        boolean bootClassPathContainsATB = !addUpdaterForAndroidTestBase(packageUpdaters);
        // REMOVE_ATB_FROM_BCP=true. If that could not be found then add the default updater that
        // will remove any references to org.apache.http.library from the package so that it does
        // not try and load the library when it is on the bootclasspath.
        boolean bootClassPathContainsATB = !addOptionalUpdater(packageUpdaters,
                "android.content.pm.parsing.library.AndroidTestBaseUpdater",
                RemoveUnnecessaryAndroidTestBaseLibrary::new);


        PackageSharedLibraryUpdater[] updaterArray = packageUpdaters
        PackageSharedLibraryUpdater[] updaterArray = packageUpdaters
                .toArray(new PackageSharedLibraryUpdater[0]);
                .toArray(new PackageSharedLibraryUpdater[0]);
@@ -70,41 +64,31 @@ public class PackageBackwardCompatibility extends PackageSharedLibraryUpdater {
    }
    }


    /**
    /**
     * Add an optional {@link PackageSharedLibraryUpdater} instance to the list, if it could not be
     * Attempt to load and add the optional updater that will only be available when
     * found then add a default instance instead.
     * REMOVE_ATB_FROM_BCP=true. If that could not be found then add the default updater that
     * will remove any references to org.apache.http.library from the package so that
     * it does not try and load the library when it is on the bootclasspath.
     *
     *
     * @param packageUpdaters the list to update.
     * TODO:(b/135203078): Find a better way to do this.
     * @param className the name of the optional class.
     * @param defaultUpdater the supplier of the default instance.
     * @return true if the optional updater was added false otherwise.
     */
     */
    private static boolean addOptionalUpdater(List<PackageSharedLibraryUpdater> packageUpdaters,
    private static boolean addUpdaterForAndroidTestBase(
            String className, Supplier<PackageSharedLibraryUpdater> defaultUpdater) {
            List<PackageSharedLibraryUpdater> packageUpdaters) {
        Class<? extends PackageSharedLibraryUpdater> clazz;
        boolean hasClass = false;
        String className = "android.content.pm.AndroidTestBaseUpdater";
        try {
        try {
            clazz = (PackageBackwardCompatibility.class.getClassLoader()
            Class clazz = (PackageParser.class.getClassLoader().loadClass(className));
                    .loadClass(className)
            hasClass = clazz != null;
                    .asSubclass(PackageSharedLibraryUpdater.class));
            Log.i(TAG, "Loaded " + className);
            Log.i(TAG, "Loaded " + className);
        } catch (ClassNotFoundException e) {
        } catch (ClassNotFoundException e) {
            Log.i(TAG, "Could not find " + className + ", ignoring");
            Log.i(TAG, "Could not find " + className + ", ignoring");
            clazz = null;
        }
        }


        boolean usedOptional = false;
        if (hasClass) {
        PackageSharedLibraryUpdater updater;
            packageUpdaters.add(new AndroidTestBaseUpdater());
        if (clazz == null) {
            updater = defaultUpdater.get();
        } else {
        } else {
            try {
            packageUpdaters.add(new RemoveUnnecessaryAndroidTestBaseLibrary());
                updater = clazz.getConstructor().newInstance();
                usedOptional = true;
            } catch (ReflectiveOperationException e) {
                throw new IllegalStateException("Could not create instance of " + className, e);
            }
        }
        }
        packageUpdaters.add(updater);
        return hasClass;
        return usedOptional;
    }
    }


    @VisibleForTesting
    @VisibleForTesting
Loading