1 /*
2  * Copyright (C) 2019 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;
18 
19 import static android.content.pm.SharedLibraryInfo.TYPE_DYNAMIC;
20 import static android.content.pm.SharedLibraryInfo.TYPE_STATIC;
21 import static android.content.pm.SharedLibraryInfo.VERSION_UNDEFINED;
22 
23 import static com.android.server.pm.PackageManagerService.SCAN_AS_FULL_APP;
24 import static com.android.server.pm.PackageManagerService.SCAN_AS_INSTANT_APP;
25 import static com.android.server.pm.PackageManagerService.SCAN_FIRST_BOOT_OR_UPGRADE;
26 import static com.android.server.pm.PackageManagerService.SCAN_NEW_INSTALL;
27 
28 import static org.hamcrest.MatcherAssert.assertThat;
29 import static org.hamcrest.Matchers.empty;
30 import static org.hamcrest.Matchers.hasItems;
31 import static org.hamcrest.Matchers.nullValue;
32 import static org.hamcrest.collection.IsArrayContainingInOrder.arrayContaining;
33 import static org.hamcrest.core.Is.is;
34 import static org.junit.Assert.assertNotSame;
35 import static org.mockito.ArgumentMatchers.any;
36 import static org.mockito.ArgumentMatchers.anyBoolean;
37 import static org.mockito.ArgumentMatchers.nullable;
38 import static org.mockito.Mockito.when;
39 
40 import android.Manifest;
41 import android.content.pm.ApplicationInfo;
42 import android.content.pm.PackageInfo;
43 import android.content.pm.PackageParser;
44 import android.content.pm.SharedLibraryInfo;
45 import android.os.Environment;
46 import android.os.UserHandle;
47 import android.os.UserManagerInternal;
48 import android.platform.test.annotations.Presubmit;
49 import android.util.Pair;
50 
51 import org.hamcrest.BaseMatcher;
52 import org.hamcrest.Description;
53 import org.hamcrest.Matcher;
54 import org.junit.Before;
55 import org.junit.Test;
56 import org.junit.runner.RunWith;
57 import org.mockito.Mock;
58 import org.mockito.junit.MockitoJUnitRunner;
59 
60 import java.io.File;
61 
62 @RunWith(MockitoJUnitRunner.class)
63 @Presubmit
64 // TODO: shared user tests
65 public class ScanTests {
66 
67     private static final String DUMMY_PACKAGE_NAME = "some.app.to.test";
68 
69     @Mock
70     PackageAbiHelper mMockPackageAbiHelper;
71     @Mock
72     UserManagerInternal mMockUserManager;
73 
74     @Before
setupDefaultUser()75     public void setupDefaultUser() {
76         when(mMockUserManager.getUserIds()).thenReturn(new int[]{0});
77     }
78 
79     @Before
setupDefaultAbiBehavior()80     public void setupDefaultAbiBehavior() throws Exception {
81         when(mMockPackageAbiHelper.derivePackageAbi(
82                 any(PackageParser.Package.class), nullable(String.class), anyBoolean()))
83                 .thenReturn(new Pair<>(
84                         new PackageAbiHelper.Abis("derivedPrimary", "derivedSecondary"),
85                         new PackageAbiHelper.NativeLibraryPaths(
86                                 "derivedRootDir", true, "derivedNativeDir", "derivedNativeDir2")));
87         when(mMockPackageAbiHelper.getNativeLibraryPaths(
88                 any(PackageParser.Package.class), any(File.class)))
89                 .thenReturn(new PackageAbiHelper.NativeLibraryPaths(
90                         "getRootDir", true, "getNativeDir", "getNativeDir2"
91                 ));
92         when(mMockPackageAbiHelper.getBundledAppAbis(
93                 any(PackageParser.Package.class)))
94                 .thenReturn(new PackageAbiHelper.Abis("bundledPrimary", "bundledSecondary"));
95     }
96 
97     @Test
newInstallSimpleAllNominal()98     public void newInstallSimpleAllNominal() throws Exception {
99         final PackageManagerService.ScanRequest scanRequest =
100                 createBasicScanRequestBuilder(createBasicPackage(DUMMY_PACKAGE_NAME).build())
101                         .addScanFlag(PackageManagerService.SCAN_NEW_INSTALL)
102                         .addScanFlag(PackageManagerService.SCAN_AS_FULL_APP)
103                         .build();
104 
105         final PackageManagerService.ScanResult scanResult = executeScan(scanRequest);
106 
107         assertBasicPackageScanResult(scanResult, DUMMY_PACKAGE_NAME, false /*isInstant*/);
108         assertThat(scanResult.existingSettingCopied, is(false));
109         assertPathsNotDerived(scanResult);
110     }
111 
112     @Test
newInstallForAllUsers()113     public void newInstallForAllUsers() throws Exception {
114         final int[] userIds = {0, 10, 11};
115         when(mMockUserManager.getUserIds()).thenReturn(userIds);
116 
117         final PackageManagerService.ScanRequest scanRequest =
118                 createBasicScanRequestBuilder(createBasicPackage(DUMMY_PACKAGE_NAME).build())
119                         .setRealPkgName(null)
120                         .addScanFlag(PackageManagerService.SCAN_NEW_INSTALL)
121                         .addScanFlag(PackageManagerService.SCAN_AS_FULL_APP)
122                         .build();
123         final PackageManagerService.ScanResult scanResult = executeScan(scanRequest);
124 
125         for (int uid : userIds) {
126             assertThat(scanResult.pkgSetting.readUserState(uid).installed, is(true));
127         }
128     }
129 
130     @Test
installRealPackageName()131     public void installRealPackageName() throws Exception {
132         final PackageManagerService.ScanRequest scanRequest =
133                 createBasicScanRequestBuilder(createBasicPackage(DUMMY_PACKAGE_NAME).build())
134                         .setRealPkgName("com.package.real")
135                         .build();
136 
137         final PackageManagerService.ScanResult scanResult = executeScan(scanRequest);
138 
139         assertThat(scanResult.pkgSetting.realName, is("com.package.real"));
140 
141         final PackageManagerService.ScanRequest scanRequestNoRealPkg =
142                 createBasicScanRequestBuilder(
143                         createBasicPackage(DUMMY_PACKAGE_NAME)
144                                 .setRealPackageName("com.package.real").build())
145                         .build();
146 
147         final PackageManagerService.ScanResult scanResultNoReal = executeScan(scanRequestNoRealPkg);
148         assertThat(scanResultNoReal.pkgSetting.realName, nullValue());
149     }
150 
151     @Test
updateSimpleNominal()152     public void updateSimpleNominal() throws Exception {
153         when(mMockUserManager.getUserIds()).thenReturn(new int[]{0});
154 
155         final PackageSetting pkgSetting = createBasicPackageSettingBuilder(DUMMY_PACKAGE_NAME)
156                 .setPrimaryCpuAbiString("primaryCpuAbi")
157                 .setSecondaryCpuAbiString("secondaryCpuAbi")
158                 .build();
159         final PackageManagerService.ScanRequest scanRequest =
160                 createBasicScanRequestBuilder(createBasicPackage(DUMMY_PACKAGE_NAME).build())
161                         .addScanFlag(PackageManagerService.SCAN_AS_FULL_APP)
162                         .setPkgSetting(pkgSetting)
163                         .build();
164 
165 
166         final PackageManagerService.ScanResult scanResult = executeScan(scanRequest);
167 
168         assertThat(scanResult.existingSettingCopied, is(true));
169 
170         // ensure we don't overwrite the existing pkgSetting, in case something post-scan fails
171         assertNotSame(pkgSetting, scanResult.pkgSetting);
172 
173         assertBasicPackageScanResult(scanResult, DUMMY_PACKAGE_NAME, false /*isInstant*/);
174 
175         assertThat(scanResult.pkgSetting.primaryCpuAbiString, is("primaryCpuAbi"));
176         assertThat(scanResult.pkgSetting.secondaryCpuAbiString, is("secondaryCpuAbi"));
177         assertThat(scanResult.pkgSetting.cpuAbiOverrideString, nullValue());
178 
179         assertPathsNotDerived(scanResult);
180     }
181 
182     @Test
updateInstantSimpleNominal()183     public void updateInstantSimpleNominal() throws Exception {
184         when(mMockUserManager.getUserIds()).thenReturn(new int[]{0});
185 
186         final PackageSetting existingPkgSetting =
187                 createBasicPackageSettingBuilder(DUMMY_PACKAGE_NAME)
188                         .setInstantAppUserState(0, true)
189                         .build();
190 
191         final PackageManagerService.ScanRequest scanRequest =
192                 createBasicScanRequestBuilder(createBasicPackage(DUMMY_PACKAGE_NAME).build())
193                         .setPkgSetting(existingPkgSetting)
194                         .build();
195 
196 
197         final PackageManagerService.ScanResult scanResult = executeScan(scanRequest);
198 
199         assertBasicPackageScanResult(scanResult, DUMMY_PACKAGE_NAME, true /*isInstant*/);
200     }
201 
202     @Test
installStaticSharedLibrary()203     public void installStaticSharedLibrary() throws Exception {
204         final PackageParser.Package pkg = createBasicPackage("static.lib.pkg.123")
205                 .setStaticSharedLib("static.lib", 123L)
206                 .setManifestPackageName("static.lib.pkg")
207                 .setVersionCodeMajor(1)
208                 .setVersionCode(234)
209                 .setBaseCodePath("/some/path.apk")
210                 .addSplitCodePath("/some/other/path.apk")
211                 .build();
212 
213         final PackageManagerService.ScanRequest scanRequest = new ScanRequestBuilder(
214                 pkg).setUser(UserHandle.of(0)).build();
215 
216 
217         final PackageManagerService.ScanResult scanResult = executeScan(scanRequest);
218 
219         assertThat(scanResult.staticSharedLibraryInfo.getPackageName(), is("static.lib.pkg.123"));
220         assertThat(scanResult.staticSharedLibraryInfo.getName(), is("static.lib"));
221         assertThat(scanResult.staticSharedLibraryInfo.getLongVersion(), is(123L));
222         assertThat(scanResult.staticSharedLibraryInfo.getType(), is(TYPE_STATIC));
223         assertThat(scanResult.staticSharedLibraryInfo.getDeclaringPackage().getPackageName(),
224                 is("static.lib.pkg"));
225         assertThat(scanResult.staticSharedLibraryInfo.getDeclaringPackage().getLongVersionCode(),
226                 is(pkg.getLongVersionCode()));
227         assertThat(scanResult.staticSharedLibraryInfo.getAllCodePaths(),
228                 hasItems("/some/path.apk", "/some/other/path.apk"));
229         assertThat(scanResult.staticSharedLibraryInfo.getDependencies(), nullValue());
230         assertThat(scanResult.staticSharedLibraryInfo.getDependentPackages(), empty());
231     }
232 
233     @Test
installDynamicLibraries()234     public void installDynamicLibraries() throws Exception {
235         final PackageParser.Package pkg = createBasicPackage("dynamic.lib.pkg")
236                 .setManifestPackageName("dynamic.lib.pkg")
237                 .addLibraryName("liba")
238                 .addLibraryName("libb")
239                 .setVersionCodeMajor(1)
240                 .setVersionCode(234)
241                 .setBaseCodePath("/some/path.apk")
242                 .addSplitCodePath("/some/other/path.apk")
243                 .build();
244 
245         final PackageManagerService.ScanRequest scanRequest =
246                 new ScanRequestBuilder(pkg).setUser(UserHandle.of(0)).build();
247 
248 
249         final PackageManagerService.ScanResult scanResult = executeScan(scanRequest);
250 
251         final SharedLibraryInfo dynamicLib0 = scanResult.dynamicSharedLibraryInfos.get(0);
252         assertThat(dynamicLib0.getPackageName(), is("dynamic.lib.pkg"));
253         assertThat(dynamicLib0.getName(), is("liba"));
254         assertThat(dynamicLib0.getLongVersion(), is((long) VERSION_UNDEFINED));
255         assertThat(dynamicLib0.getType(), is(TYPE_DYNAMIC));
256         assertThat(dynamicLib0.getDeclaringPackage().getPackageName(), is("dynamic.lib.pkg"));
257         assertThat(dynamicLib0.getDeclaringPackage().getLongVersionCode(),
258                 is(pkg.getLongVersionCode()));
259         assertThat(dynamicLib0.getAllCodePaths(),
260                 hasItems("/some/path.apk", "/some/other/path.apk"));
261         assertThat(dynamicLib0.getDependencies(), nullValue());
262         assertThat(dynamicLib0.getDependentPackages(), empty());
263 
264         final SharedLibraryInfo dynamicLib1 = scanResult.dynamicSharedLibraryInfos.get(1);
265         assertThat(dynamicLib1.getPackageName(), is("dynamic.lib.pkg"));
266         assertThat(dynamicLib1.getName(), is("libb"));
267         assertThat(dynamicLib1.getLongVersion(), is((long) VERSION_UNDEFINED));
268         assertThat(dynamicLib1.getType(), is(TYPE_DYNAMIC));
269         assertThat(dynamicLib1.getDeclaringPackage().getPackageName(), is("dynamic.lib.pkg"));
270         assertThat(dynamicLib1.getDeclaringPackage().getLongVersionCode(),
271                 is(pkg.getLongVersionCode()));
272         assertThat(dynamicLib1.getAllCodePaths(),
273                 hasItems("/some/path.apk", "/some/other/path.apk"));
274         assertThat(dynamicLib1.getDependencies(), nullValue());
275         assertThat(dynamicLib1.getDependentPackages(), empty());
276     }
277 
278     @Test
volumeUuidChangesOnUpdate()279     public void volumeUuidChangesOnUpdate() throws Exception {
280         final PackageSetting pkgSetting =
281                 createBasicPackageSettingBuilder(DUMMY_PACKAGE_NAME)
282                         .setVolumeUuid("someUuid")
283                         .build();
284 
285         final PackageParser.Package basicPackage = createBasicPackage(DUMMY_PACKAGE_NAME)
286                 .setApplicationInfoVolumeUuid("someNewUuid")
287                 .build();
288 
289 
290         final PackageManagerService.ScanResult scanResult = executeScan(
291                 new ScanRequestBuilder(basicPackage).setPkgSetting(pkgSetting).build());
292 
293         assertThat(scanResult.pkgSetting.volumeUuid, is("someNewUuid"));
294     }
295 
296     @Test
scanFirstBoot_derivesAbis()297     public void scanFirstBoot_derivesAbis() throws Exception {
298         final PackageSetting pkgSetting =
299                 createBasicPackageSettingBuilder(DUMMY_PACKAGE_NAME).build();
300 
301         final PackageParser.Package basicPackage =
302                 createBasicPackage(DUMMY_PACKAGE_NAME)
303                         .setCpuAbiOVerride("testOverride")
304                         .build();
305 
306 
307         final PackageManagerService.ScanResult scanResult = executeScan(new ScanRequestBuilder(
308                 basicPackage)
309                 .setPkgSetting(pkgSetting)
310                 .addScanFlag(SCAN_FIRST_BOOT_OR_UPGRADE)
311                 .build());
312 
313         assertAbiAndPathssDerived(scanResult);
314     }
315 
316     @Test
scanWithOriginalPkgSetting_packageNameChanges()317     public void scanWithOriginalPkgSetting_packageNameChanges() throws Exception {
318         final PackageSetting originalPkgSetting =
319                 createBasicPackageSettingBuilder("original.package").build();
320 
321         final PackageParser.Package basicPackage =
322                 createBasicPackage(DUMMY_PACKAGE_NAME)
323                         .build();
324 
325 
326         final PackageManagerService.ScanResult result =
327                 executeScan(new ScanRequestBuilder(basicPackage)
328                         .setOriginalPkgSetting(originalPkgSetting)
329                         .build());
330 
331         assertThat(result.request.pkg.packageName, is("original.package"));
332     }
333 
334     @Test
updateInstant_changeToFull()335     public void updateInstant_changeToFull() throws Exception {
336         when(mMockUserManager.getUserIds()).thenReturn(new int[]{0});
337 
338         final PackageSetting existingPkgSetting =
339                 createBasicPackageSettingBuilder(DUMMY_PACKAGE_NAME)
340                         .setInstantAppUserState(0, true)
341                         .build();
342 
343         final PackageManagerService.ScanRequest scanRequest =
344                 createBasicScanRequestBuilder(createBasicPackage(DUMMY_PACKAGE_NAME).build())
345                         .setPkgSetting(existingPkgSetting)
346                         .addScanFlag(SCAN_AS_FULL_APP)
347                         .build();
348 
349 
350         final PackageManagerService.ScanResult scanResult = executeScan(scanRequest);
351 
352         assertBasicPackageScanResult(scanResult, DUMMY_PACKAGE_NAME, false /*isInstant*/);
353     }
354 
355     @Test
updateFull_changeToInstant()356     public void updateFull_changeToInstant() throws Exception {
357         when(mMockUserManager.getUserIds()).thenReturn(new int[]{0});
358 
359         final PackageSetting existingPkgSetting =
360                 createBasicPackageSettingBuilder(DUMMY_PACKAGE_NAME)
361                         .setInstantAppUserState(0, false)
362                         .build();
363 
364         final PackageManagerService.ScanRequest scanRequest =
365                 createBasicScanRequestBuilder(createBasicPackage(DUMMY_PACKAGE_NAME).build())
366                         .setPkgSetting(existingPkgSetting)
367                         .addScanFlag(SCAN_AS_INSTANT_APP)
368                         .build();
369 
370 
371         final PackageManagerService.ScanResult scanResult = executeScan(scanRequest);
372 
373         assertBasicPackageScanResult(scanResult, DUMMY_PACKAGE_NAME, true /*isInstant*/);
374     }
375 
376     @Test
updateSystemApp_applicationInfoFlagSet()377     public void updateSystemApp_applicationInfoFlagSet() throws Exception {
378         final PackageSetting existingPkgSetting =
379                 createBasicPackageSettingBuilder(DUMMY_PACKAGE_NAME)
380                         .setPkgFlags(ApplicationInfo.FLAG_SYSTEM)
381                         .build();
382 
383         final PackageManagerService.ScanRequest scanRequest =
384                 createBasicScanRequestBuilder(createBasicPackage(DUMMY_PACKAGE_NAME).build())
385                         .setPkgSetting(existingPkgSetting)
386                         .setDisabledPkgSetting(existingPkgSetting)
387                         .addScanFlag(SCAN_NEW_INSTALL)
388                         .build();
389 
390         final PackageManagerService.ScanResult scanResult = executeScan(scanRequest);
391 
392         assertThat(scanResult.request.pkg.applicationInfo.flags,
393                 hasFlag(ApplicationInfo.FLAG_UPDATED_SYSTEM_APP));
394     }
395 
396     @Test
factoryTestFlagSet()397     public void factoryTestFlagSet() throws Exception {
398         final PackageParser.Package basicPackage = createBasicPackage(DUMMY_PACKAGE_NAME)
399                 .addPermissionRequest(Manifest.permission.FACTORY_TEST)
400                 .build();
401 
402         final PackageManagerService.ScanResult scanResult = PackageManagerService.scanPackageOnlyLI(
403                 createBasicScanRequestBuilder(basicPackage).build(),
404                 new PackageManagerService.Injector(mMockUserManager, mMockPackageAbiHelper),
405                 true /*isUnderFactoryTest*/,
406                 System.currentTimeMillis());
407 
408         assertThat(scanResult.request.pkg.applicationInfo.flags,
409                 hasFlag(ApplicationInfo.FLAG_FACTORY_TEST));
410     }
411 
412     @Test
scanSystemApp_isOrphanedTrue()413     public void scanSystemApp_isOrphanedTrue() throws Exception {
414         final PackageParser.Package pkg = createBasicPackage(DUMMY_PACKAGE_NAME)
415                 .addApplicationInfoFlag(ApplicationInfo.FLAG_SYSTEM)
416                 .build();
417 
418         final PackageManagerService.ScanRequest scanRequest =
419                 createBasicScanRequestBuilder(pkg)
420                         .build();
421 
422         final PackageManagerService.ScanResult scanResult = executeScan(scanRequest);
423 
424         assertThat(scanResult.pkgSetting.isOrphaned, is(true));
425     }
426 
hasFlag(final int flag)427     private static Matcher<Integer> hasFlag(final int flag) {
428         return new BaseMatcher<Integer>() {
429             @Override public void describeTo(Description description) {
430                 description.appendText("flags ");
431             }
432 
433             @Override public boolean matches(Object item) {
434                 return ((int) item & flag) != 0;
435             }
436 
437             @Override
438             public void describeMismatch(Object item, Description mismatchDescription) {
439                 mismatchDescription
440                         .appendValue(item)
441                         .appendText(" does not contain flag ")
442                         .appendValue(flag);
443             }
444         };
445     }
446 
447     private PackageManagerService.ScanResult executeScan(
448             PackageManagerService.ScanRequest scanRequest) throws PackageManagerException {
449         return PackageManagerService.scanPackageOnlyLI(
450                 scanRequest,
451                 new PackageManagerService.Injector(mMockUserManager, mMockPackageAbiHelper),
452                 false /*isUnderFactoryTest*/,
453                 System.currentTimeMillis());
454     }
455 
456     private static String createResourcePath(String packageName) {
457         return "/data/app/" + packageName + "-randompath/base.apk";
458     }
459 
460     private static String createCodePath(String packageName) {
461         return "/data/app/" + packageName + "-randompath";
462     }
463 
464     private static PackageSettingBuilder createBasicPackageSettingBuilder(String packageName) {
465         return new PackageSettingBuilder()
466                 .setName(packageName)
467                 .setCodePath(createCodePath(packageName))
468                 .setResourcePath(createResourcePath(packageName));
469     }
470 
471     private static ScanRequestBuilder createBasicScanRequestBuilder(PackageParser.Package pkg) {
472         return new ScanRequestBuilder(pkg)
473                 .setUser(UserHandle.of(0));
474     }
475 
476 
477     private static PackageBuilder createBasicPackage(String packageName) {
478         return new PackageBuilder(packageName)
479                 .setCodePath("/data/tmp/randompath")
480                 .setApplicationInfoCodePath(createCodePath(packageName))
481                 .setApplicationInfoResourcePath(createResourcePath(packageName))
482                 .setApplicationInfoVolumeUuid("volumeUuid")
483                 .setBaseCodePath("/data/tmp/randompath/base.apk")
484                 .addUsesStaticLibrary("some.static.library", 234L)
485                 .addUsesStaticLibrary("some.other.static.library", 456L)
486                 .setApplicationInfoNativeLibraryRootDir("/data/tmp/randompath/base.apk:/lib")
487                 .setVersionCodeMajor(1)
488                 .setVersionCode(2345);
489     }
490 
491     private static void assertBasicPackageScanResult(
492             PackageManagerService.ScanResult scanResult, String packageName, boolean isInstant) {
493         assertThat(scanResult.success, is(true));
494 
495         final PackageSetting pkgSetting = scanResult.pkgSetting;
496         assertBasicPackageSetting(scanResult, packageName, isInstant, pkgSetting);
497 
498         final ApplicationInfo applicationInfo = pkgSetting.pkg.applicationInfo;
499         assertBasicApplicationInfo(scanResult, applicationInfo);
500 
501     }
502 
503     private static void assertBasicPackageSetting(PackageManagerService.ScanResult scanResult,
504             String packageName, boolean isInstant, PackageSetting pkgSetting) {
505         assertThat(pkgSetting.pkg.packageName, is(packageName));
506         assertThat(pkgSetting.getInstantApp(0), is(isInstant));
507         assertThat(pkgSetting.usesStaticLibraries,
508                 arrayContaining("some.static.library", "some.other.static.library"));
509         assertThat(pkgSetting.usesStaticLibrariesVersions, is(new long[]{234L, 456L}));
510         assertThat(pkgSetting.pkg, is(scanResult.request.pkg));
511         assertThat(pkgSetting.pkg.mExtras, is(pkgSetting));
512         assertThat(pkgSetting.codePath, is(new File(createCodePath(packageName))));
513         assertThat(pkgSetting.resourcePath, is(new File(createResourcePath(packageName))));
514         assertThat(pkgSetting.versionCode, is(PackageInfo.composeLongVersionCode(1, 2345)));
515     }
516 
517     private static void assertBasicApplicationInfo(PackageManagerService.ScanResult scanResult,
518             ApplicationInfo applicationInfo) {
519         assertThat(applicationInfo.processName, is(scanResult.request.pkg.packageName));
520 
521         final int uid = applicationInfo.uid;
522         assertThat(UserHandle.getUserId(uid), is(UserHandle.USER_SYSTEM));
523 
524         final String calculatedCredentialId = Environment.getDataUserCePackageDirectory(
525                 applicationInfo.volumeUuid, UserHandle.USER_SYSTEM,
526                 scanResult.request.pkg.packageName).getAbsolutePath();
527         assertThat(applicationInfo.credentialProtectedDataDir, is(calculatedCredentialId));
528         assertThat(applicationInfo.dataDir, is(applicationInfo.credentialProtectedDataDir));
529     }
530 
531     private static void assertAbiAndPathssDerived(PackageManagerService.ScanResult scanResult) {
532         final ApplicationInfo applicationInfo = scanResult.pkgSetting.pkg.applicationInfo;
533         assertThat(applicationInfo.primaryCpuAbi, is("derivedPrimary"));
534         assertThat(applicationInfo.secondaryCpuAbi, is("derivedSecondary"));
535 
536         assertThat(applicationInfo.nativeLibraryRootDir, is("derivedRootDir"));
537         assertThat(scanResult.pkgSetting.legacyNativeLibraryPathString, is("derivedRootDir"));
538         assertThat(applicationInfo.nativeLibraryRootRequiresIsa, is(true));
539         assertThat(applicationInfo.nativeLibraryDir, is("derivedNativeDir"));
540         assertThat(applicationInfo.secondaryNativeLibraryDir, is("derivedNativeDir2"));
541     }
542 
543     private static void assertPathsNotDerived(PackageManagerService.ScanResult scanResult) {
544         final ApplicationInfo applicationInfo = scanResult.pkgSetting.pkg.applicationInfo;
545         assertThat(applicationInfo.nativeLibraryRootDir, is("getRootDir"));
546         assertThat(scanResult.pkgSetting.legacyNativeLibraryPathString, is("getRootDir"));
547         assertThat(applicationInfo.nativeLibraryRootRequiresIsa, is(true));
548         assertThat(applicationInfo.nativeLibraryDir, is("getNativeDir"));
549         assertThat(applicationInfo.secondaryNativeLibraryDir, is("getNativeDir2"));
550     }
551 }
552