blob: 62589ebb92fe7aac55fda2457a1cb6ad1a1814a9 [file] [log] [blame]
Calin Juravle1d0e83d2017-07-17 15:12:01 -07001/*
2 * Copyright (C) 2017 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
17package com.android.server.pm.dex;
18
19
20import static com.android.server.pm.PackageManagerServiceCompilerMapping.getCompilerFilterForReason;
21
Calin Juravle1d0e83d2017-07-17 15:12:01 -070022import static org.junit.Assert.assertEquals;
23import static org.junit.Assert.assertFalse;
24import static org.junit.Assert.assertTrue;
25
Brett Chabota26eda92018-07-23 13:08:30 -070026import androidx.test.filters.SmallTest;
27import androidx.test.runner.AndroidJUnit4;
28
Calin Juravle1d0e83d2017-07-17 15:12:01 -070029import com.android.server.pm.PackageManagerService;
30import com.android.server.pm.PackageManagerServiceCompilerMapping;
31
Brett Chabota26eda92018-07-23 13:08:30 -070032import org.junit.Test;
33import org.junit.runner.RunWith;
34
Calin Juravle1d0e83d2017-07-17 15:12:01 -070035@RunWith(AndroidJUnit4.class)
36@SmallTest
37public class DexoptOptionsTests {
38 private final static String mPackageName = "test.android.com";
39 private final static String mCompilerFilter =
40 PackageManagerServiceCompilerMapping.getDefaultCompilerFilter();
Calin Juravleb6f844d2017-07-17 15:23:21 -070041 private final static String mSplitName = "split-A.apk";
Calin Juravle1d0e83d2017-07-17 15:12:01 -070042
43 @Test
44 public void testCreateDexoptOptionsEmpty() {
45 DexoptOptions opt = new DexoptOptions(mPackageName, mCompilerFilter, /*flags*/ 0);
46 assertEquals(mPackageName, opt.getPackageName());
47 assertEquals(mCompilerFilter, opt.getCompilerFilter());
Calin Juravleb6f844d2017-07-17 15:23:21 -070048 assertEquals(null, opt.getSplitName());
Calin Juravle1d0e83d2017-07-17 15:12:01 -070049 assertFalse(opt.isBootComplete());
50 assertFalse(opt.isCheckForProfileUpdates());
51 assertFalse(opt.isDexoptOnlySecondaryDex());
52 assertFalse(opt.isDexoptOnlySharedDex());
53 assertFalse(opt.isDowngrade());
54 assertFalse(opt.isForce());
David Sehr2118ec42017-10-25 14:28:29 -070055 assertFalse(opt.isDexoptIdleBackgroundJob());
Calin Juravlecc651942018-02-01 17:20:51 +000056 assertFalse(opt.isDexoptInstallWithDexMetadata());
Calin Juravle1d0e83d2017-07-17 15:12:01 -070057 }
58
59 @Test
60 public void testCreateDexoptOptionsFull() {
61 int flags =
62 DexoptOptions.DEXOPT_FORCE |
63 DexoptOptions.DEXOPT_BOOT_COMPLETE |
64 DexoptOptions.DEXOPT_CHECK_FOR_PROFILES_UPDATES |
65 DexoptOptions.DEXOPT_ONLY_SECONDARY_DEX |
66 DexoptOptions.DEXOPT_ONLY_SHARED_DEX |
Calin Juravle3b74c412017-08-03 19:48:37 -070067 DexoptOptions.DEXOPT_DOWNGRADE |
David Sehr2118ec42017-10-25 14:28:29 -070068 DexoptOptions.DEXOPT_AS_SHARED_LIBRARY |
Calin Juravlecc651942018-02-01 17:20:51 +000069 DexoptOptions.DEXOPT_IDLE_BACKGROUND_JOB |
70 DexoptOptions.DEXOPT_INSTALL_WITH_DEX_METADATA_FILE;
Calin Juravle1d0e83d2017-07-17 15:12:01 -070071
72 DexoptOptions opt = new DexoptOptions(mPackageName, mCompilerFilter, flags);
73 assertEquals(mPackageName, opt.getPackageName());
74 assertEquals(mCompilerFilter, opt.getCompilerFilter());
Calin Juravleb6f844d2017-07-17 15:23:21 -070075 assertEquals(null, opt.getSplitName());
Calin Juravle1d0e83d2017-07-17 15:12:01 -070076 assertTrue(opt.isBootComplete());
77 assertTrue(opt.isCheckForProfileUpdates());
78 assertTrue(opt.isDexoptOnlySecondaryDex());
79 assertTrue(opt.isDexoptOnlySharedDex());
80 assertTrue(opt.isDowngrade());
81 assertTrue(opt.isForce());
Calin Juravle3b74c412017-08-03 19:48:37 -070082 assertTrue(opt.isDexoptAsSharedLibrary());
David Sehr2118ec42017-10-25 14:28:29 -070083 assertTrue(opt.isDexoptIdleBackgroundJob());
Calin Juravlecc651942018-02-01 17:20:51 +000084 assertTrue(opt.isDexoptInstallWithDexMetadata());
Calin Juravle1d0e83d2017-07-17 15:12:01 -070085 }
86
87 @Test
88 public void testCreateDexoptOptionsReason() {
89 int flags =
90 DexoptOptions.DEXOPT_FORCE |
91 DexoptOptions.DEXOPT_BOOT_COMPLETE |
92 DexoptOptions.DEXOPT_CHECK_FOR_PROFILES_UPDATES;
93
94 int[] reasons = new int[] {
95 PackageManagerService.REASON_FIRST_BOOT,
96 PackageManagerService.REASON_BOOT,
97 PackageManagerService.REASON_INSTALL,
98 PackageManagerService.REASON_BACKGROUND_DEXOPT,
99 PackageManagerService.REASON_AB_OTA,
Calin Juravle3b74c412017-08-03 19:48:37 -0700100 PackageManagerService.REASON_INACTIVE_PACKAGE_DOWNGRADE,};
Calin Juravle1d0e83d2017-07-17 15:12:01 -0700101
102 for (int reason : reasons) {
103 DexoptOptions opt = new DexoptOptions(mPackageName, reason, flags);
104 assertEquals(mPackageName, opt.getPackageName());
105 assertEquals(getCompilerFilterForReason(reason), opt.getCompilerFilter());
Calin Juravleb6f844d2017-07-17 15:23:21 -0700106 assertEquals(null, opt.getSplitName());
Calin Juravle1d0e83d2017-07-17 15:12:01 -0700107 assertTrue(opt.isBootComplete());
108 assertTrue(opt.isCheckForProfileUpdates());
109 assertFalse(opt.isDexoptOnlySecondaryDex());
110 assertFalse(opt.isDexoptOnlySharedDex());
111 assertFalse(opt.isDowngrade());
112 assertTrue(opt.isForce());
Calin Juravle3b74c412017-08-03 19:48:37 -0700113 assertFalse(opt.isDexoptAsSharedLibrary());
Calin Juravle1d0e83d2017-07-17 15:12:01 -0700114 }
115 }
116
117 @Test
Calin Juravleb6f844d2017-07-17 15:23:21 -0700118 public void testCreateDexoptOptionsSplit() {
119 int flags = DexoptOptions.DEXOPT_FORCE | DexoptOptions.DEXOPT_BOOT_COMPLETE;
120
Calin Juravle4bc8f4d2018-02-12 12:00:44 -0800121 DexoptOptions opt = new DexoptOptions(mPackageName, -1, mCompilerFilter, mSplitName, flags);
Calin Juravleb6f844d2017-07-17 15:23:21 -0700122 assertEquals(mPackageName, opt.getPackageName());
123 assertEquals(mCompilerFilter, opt.getCompilerFilter());
124 assertEquals(mSplitName, opt.getSplitName());
125 assertTrue(opt.isBootComplete());
126 assertFalse(opt.isCheckForProfileUpdates());
127 assertFalse(opt.isDexoptOnlySecondaryDex());
128 assertFalse(opt.isDexoptOnlySharedDex());
129 assertFalse(opt.isDowngrade());
130 assertTrue(opt.isForce());
Calin Juravle3b74c412017-08-03 19:48:37 -0700131 assertFalse(opt.isDexoptAsSharedLibrary());
Calin Juravleb6f844d2017-07-17 15:23:21 -0700132 }
133
134 @Test
Calin Juravle1d0e83d2017-07-17 15:12:01 -0700135 public void testCreateDexoptInvalid() {
136 boolean gotException = false;
137 try {
138 int invalidFlags = 999;
139 new DexoptOptions(mPackageName, mCompilerFilter, invalidFlags);
140 } catch (IllegalArgumentException ignore) {
141 gotException = true;
142 }
143
144 assertTrue(gotException);
145 }
David Sehr2118ec42017-10-25 14:28:29 -0700146}