• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.server.pm.dex;
18 
19 import static com.android.server.pm.InstructionSets.getAppDexInstructionSets;
20 
21 import android.annotation.NonNull;
22 
23 import com.android.server.pm.PackageDexOptimizer;
24 import com.android.server.pm.parsing.pkg.AndroidPackageUtils;
25 import com.android.server.pm.pkg.AndroidPackage;
26 import com.android.server.pm.pkg.PackageState;
27 
28 import java.io.File;
29 import java.util.Arrays;
30 
31 /**
32  * Utility class to interface between PM and ART tooling (e.g. DexManager).
33  */
34 public final class ArtUtils {
ArtUtils()35     private ArtUtils() {
36     }
37 
38     /**
39      * Create the ART-representation of package info.
40      */
createArtPackageInfo( AndroidPackage pkg, PackageState packageState)41     public static ArtPackageInfo createArtPackageInfo(
42             AndroidPackage pkg, PackageState packageState) {
43         return new ArtPackageInfo(
44                 pkg.getPackageName(),
45                 Arrays.asList(getAppDexInstructionSets(packageState.getPrimaryCpuAbi(),
46                         packageState.getSecondaryCpuAbi())),
47                 AndroidPackageUtils.getAllCodePaths(pkg),
48                 getOatDir(pkg, packageState));
49     }
50 
getOatDir(AndroidPackage pkg, @NonNull PackageState packageState)51     private static String getOatDir(AndroidPackage pkg, @NonNull PackageState packageState) {
52         if (!AndroidPackageUtils.canHaveOatDir(packageState, pkg)) {
53             return null;
54         }
55         File codePath = new File(pkg.getPath());
56         if (codePath.isDirectory()) {
57             return PackageDexOptimizer.getOatDir(codePath).getAbsolutePath();
58         }
59         return null;
60     }
61 
62 }
63