• 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.PackageSetting;
25 import com.android.server.pm.parsing.pkg.AndroidPackage;
26 import com.android.server.pm.parsing.pkg.AndroidPackageUtils;
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, PackageSetting pkgSetting)41     public static ArtPackageInfo createArtPackageInfo(
42             AndroidPackage pkg, PackageSetting pkgSetting) {
43         return new ArtPackageInfo(
44                 pkg.getPackageName(),
45                 Arrays.asList(getAppDexInstructionSets(
46                         AndroidPackageUtils.getPrimaryCpuAbi(pkg, pkgSetting),
47                         AndroidPackageUtils.getSecondaryCpuAbi(pkg, pkgSetting))),
48                 AndroidPackageUtils.getAllCodePaths(pkg),
49                 getOatDir(pkg, pkgSetting));
50     }
51 
getOatDir(AndroidPackage pkg, @NonNull PackageSetting pkgSetting)52     private static String getOatDir(AndroidPackage pkg, @NonNull PackageSetting pkgSetting) {
53         if (!AndroidPackageUtils.canHaveOatDir(pkg,
54                 pkgSetting.getPkgState().isUpdatedSystemApp())) {
55             return null;
56         }
57         File codePath = new File(pkg.getPath());
58         if (codePath.isDirectory()) {
59             return PackageDexOptimizer.getOatDir(codePath).getAbsolutePath();
60         }
61         return null;
62     }
63 
64 }
65