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

Commit 26c9531a authored by Dario Freni's avatar Dario Freni Committed by android-build-merger
Browse files

Merge changes from topic "apks_in_apex" am: a8ce56e2

am: 62637979

Change-Id: If7e4d5408af91a6c0976568c9625622b4432a71c
parents 61177ace 62637979
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -22,11 +22,11 @@ import android.os.SystemProperties;
import android.text.TextUtils;
import android.util.ArraySet;

import dalvik.system.VMRuntime;

import java.util.ArrayList;
import java.util.List;

import dalvik.system.VMRuntime;

/**
 * Provides various methods for obtaining and converting of instruction sets.
 *
@@ -113,12 +113,15 @@ public class InstructionSets {
        return allInstructionSets;
    }

    public static String getPrimaryInstructionSet(ApplicationInfo info) {
        if (info.primaryCpuAbi == null) {
    /**
     * Calculates the primary instruction set based on the computed Abis of a given package.
     */
    public static String getPrimaryInstructionSet(PackageAbiHelper.Abis abis) {
        if (abis.primary == null) {
            return getPreferredInstructionSet();
        }

        return VMRuntime.getInstructionSet(info.primaryCpuAbi);
        return VMRuntime.getInstructionSet(abis.primary);
    }

}
+135 −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 android.util.Pair;

import com.android.internal.annotations.VisibleForTesting;

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

@VisibleForTesting
interface PackageAbiHelper {
    /**
     * Derive and get the location of native libraries for the given package,
     * which varies depending on where and how the package was installed.
     */
    NativeLibraryPaths getNativeLibraryPaths(
            PackageParser.Package pkg, File appLib32InstallDir);

    /**
     * Calculate the abis 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.
     */
    Abis getBundledAppAbis(PackageParser.Package pkg);

    /**
     * Derive the ABI of a non-system package located at {@code pkg}. This information
     * is derived purely on the basis of the contents of {@code pkg} and {@code cpuAbiOverride}.
     *
     * If {@code extractLibs} is true, native libraries are extracted from the app if required.
     */
    Pair<Abis, NativeLibraryPaths> derivePackageAbi(
            PackageParser.Package pkg, String cpuAbiOverride, boolean extractLibs)
            throws PackageManagerException;

    /**
     * Calculates adjusted 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 scannedPackage} 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.
     *
     * @return the calculated primary abi that should be set for all non-specified packages
     *         belonging to the shared user.
     */
    @Nullable
    String getAdjustedAbiForSharedUser(
            Set<PackageSetting> packagesForUser, PackageParser.Package scannedPackage);

    /**
     * The native library paths and related properties that should be set on a
     * {@link android.content.pm.PackageParser.Package}.
     */
    final class NativeLibraryPaths {
        public final String nativeLibraryRootDir;
        public final boolean nativeLibraryRootRequiresIsa;
        public final String nativeLibraryDir;
        public final String secondaryNativeLibraryDir;

        @VisibleForTesting
        NativeLibraryPaths(String nativeLibraryRootDir,
                boolean nativeLibraryRootRequiresIsa, String nativeLibraryDir,
                String secondaryNativeLibraryDir) {
            this.nativeLibraryRootDir = nativeLibraryRootDir;
            this.nativeLibraryRootRequiresIsa = nativeLibraryRootRequiresIsa;
            this.nativeLibraryDir = nativeLibraryDir;
            this.secondaryNativeLibraryDir = secondaryNativeLibraryDir;
        }

        public void applyTo(PackageParser.Package pkg) {
            pkg.applicationInfo.nativeLibraryRootDir = nativeLibraryRootDir;
            pkg.applicationInfo.nativeLibraryRootRequiresIsa = nativeLibraryRootRequiresIsa;
            pkg.applicationInfo.nativeLibraryDir = nativeLibraryDir;
            pkg.applicationInfo.secondaryNativeLibraryDir = secondaryNativeLibraryDir;
        }
    }

    /**
     * The primary and secondary ABIs that should be set on a package and its package setting.
     */
    final class Abis {
        public final String primary;
        public final String secondary;

        @VisibleForTesting
        Abis(String primary, String secondary) {
            this.primary = primary;
            this.secondary = secondary;
        }

        Abis(PackageParser.Package pkg) {
            this(pkg.applicationInfo.primaryCpuAbi, pkg.applicationInfo.secondaryCpuAbi);
        }

        public void applyTo(PackageParser.Package pkg) {
            pkg.applicationInfo.primaryCpuAbi = primary;
            pkg.applicationInfo.secondaryCpuAbi = secondary;
        }
        public void applyTo(PackageSetting pkgSetting) {
            // pkgSetting might be null during rescan following uninstall of updates
            // to a bundled app, so accommodate that possibility.  The settings in
            // that case will be established later from the parsed package.
            //
            // If the settings aren't null, sync them up with what we've derived.
            if (pkgSetting != null) {
                pkgSetting.primaryCpuAbiString = primary;
                pkgSetting.secondaryCpuAbiString = secondary;
            }
        }
    }
}
+528 −0

File added.

Preview size limit exceeded, changes collapsed.

+132 −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;
    }
Loading