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

Commit f62817e8 authored by Patrick Baumann's avatar Patrick Baumann Committed by Bill Lin
Browse files

Adds scan unit tests

This change adds much needed unit tests to the scanPackageOnlyLI method
in PackageManagerService. As part of the change, the abi-deriving /
parsing code that is heavily device state dependant has been extracted
into an interface that can be mocked.

Test: atest ScanTests
Bug: 137881067
Bug: 137961986
Exempt-From-Owner-Approval: Already approved in
https://googleplex-android-review.git.corp.google.com/c/platform/frameworks/base/+/7844466

Change-Id: If99330c63658ff21c799712f99c9bb5eba35b960
Merged-In: Ib0b17bffa02570451bd2ad6a649791832c9edd65
parent 337df70e
Loading
Loading
Loading
Loading
+85 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.pm;

import android.annotation.Nullable;
import android.content.pm.PackageParser;

import com.android.internal.annotations.VisibleForTesting;

import java.io.File;
import java.util.List;
import java.util.Set;

@VisibleForTesting
interface PackageAbiHelper {
    /**
     * Derive and set the location of native libraries for the given package,
     * which varies depending on where and how the package was installed.
     *
     * WARNING: This API enables modifying of the package.
     * TODO(b/137881067): Modify so that caller is responsible for setting pkg fields as necessary
     */
    void setNativeLibraryPaths(PackageParser.Package pkg, File appLib32InstallDir);

    /**
     * Calculate the abis and roots for a bundled app. These can uniquely
     * be determined from the contents of the system partition, i.e whether
     * it contains 64 or 32 bit shared libraries etc. We do not validate any
     * of this information, and instead assume that the system was built
     * sensibly.
     *
     * WARNING: This API enables modifying of the package.
     * TODO(b/137881067): Modify so that caller is responsible for setting pkg fields as necessary
     */
    void setBundledAppAbisAndRoots(PackageParser.Package pkg,
            PackageSetting pkgSetting);

    /**
     * Derive the ABI of a non-system package located at {@code scanFile}. This information
     * is derived purely on the basis of the contents of {@code scanFile} and
     * {@code cpuAbiOverride}.
     *
     * If {@code extractLibs} is true, native libraries are extracted from the app if required.
     *
     * WARNING: This API enables modifying of the package.
     * TODO(b/137881067): Modify so that caller is responsible for setting pkg fields as necessary
     */
    void derivePackageAbi(PackageParser.Package pkg, String cpuAbiOverride,
            boolean extractLibs)
            throws PackageManagerException;

    /**
     * Adjusts ABIs for a set of packages belonging to a shared user so that they all match.
     * i.e, so that all packages can be run inside a single process if required.
     *
     * Optionally, callers can pass in a parsed package via {@code newPackage} in which case
     * this function will either try and make the ABI for all packages in
     * {@code packagesForUser} match {@code scannedPackage} or will update the ABI of
     * {@code scannedPackage} to match the ABI selected for {@code packagesForUser}. This
     * variant is used when installing or updating a package that belongs to a shared user.
     *
     * NOTE: We currently only match for the primary CPU abi string. Matching the secondary
     * adds unnecessary complexity.
     *
     * WARNING: This API enables modifying of the package.
     * TODO(b/137881067): Modify so that caller is responsible for setting pkg fields as necessary
     */
    @Nullable
    List<String> adjustCpuAbisForSharedUser(
            Set<PackageSetting> packagesForUser, PackageParser.Package scannedPackage);
}
+542 −0

File added.

Preview size limit exceeded, changes collapsed.

+70 −521

File changed.

Preview size limit exceeded, changes collapsed.

+14 −1
Original line number Diff line number Diff line
@@ -270,7 +270,8 @@ public abstract class PackageSettingBase extends SettingBase {
        updateAvailable = orig.updateAvailable;
    }

    private PackageUserState modifyUserState(int userId) {
    @VisibleForTesting
    PackageUserState modifyUserState(int userId) {
        PackageUserState state = mUserState.get(userId);
        if (state == null) {
            state = new PackageUserState();
@@ -463,6 +464,18 @@ public abstract class PackageSettingBase extends SettingBase {
        state.harmfulAppWarning = harmfulAppWarning;
    }

    void setUserState(int userId, PackageUserState otherState) {
        setUserState(userId, otherState.ceDataInode, otherState.enabled, otherState.installed,
                otherState.stopped, otherState.notLaunched, otherState.hidden,
                otherState.distractionFlags, otherState.suspended, otherState.suspendingPackage,
                otherState.dialogInfo, otherState.suspendedAppExtras,
                otherState.suspendedLauncherExtras, otherState.instantApp,
                otherState.virtualPreload, otherState.lastDisableAppCaller,
                otherState.enabledComponents, otherState.disabledComponents,
                otherState.domainVerificationStatus, otherState.appLinkGeneration,
                otherState.installReason, otherState.harmfulAppWarning);
    }

    ArraySet<String> getEnabledComponents(int userId) {
        return readUserState(userId).enabledComponents;
    }
+14 −0
Original line number Diff line number Diff line
@@ -8,6 +8,20 @@
    },
    {
      "name": "CtsCompilationTestCases"
    },
    {
      "name": "FrameworksServicesTests",
      "options": [
        {
          "include-filter": "com.android.server.pm."
        },
        {
          "include-annotation": "android.platform.test.annotations.Presubmit"
        },
        {
          "exclude-annotation": "androidx.test.filters.FlakyTest"
        }
      ]
    }
  ],
  "imports": [
Loading