• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 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.framework.tests;
18 
19 import com.android.ddmlib.Log;
20 import com.android.tradefed.config.Option;
21 import com.android.tradefed.config.Option.Importance;
22 import com.android.tradefed.device.DeviceNotAvailableException;
23 import com.android.tradefed.testtype.DeviceTestCase;
24 import com.android.tradefed.util.FileUtil;
25 
26 import java.io.File;
27 
28 /** Set of tests that verify host side install cases */
29 public class PackageManagerHostTests extends DeviceTestCase {
30 
31     private static final String ABI_PROPERTY = "ro.product.cpu.abi";
32     private static final String ARM64_V8A = "arm64-v8a";
33     private static final String ARMEABI_V7A = "armeabi-v7a";
34     private static final String LOG_TAG = "PackageManagerHostTests";
35     private PackageManagerHostTestUtils mPMHostUtils = null;
36 
37     // Various test files and their corresponding package names...
38 
39     // testPushAppPrivate constants
40     // these constants must match values defined in test-apps/SimpleTestApp
41     private static final String SIMPLE_APK = "SimpleTestApp.apk";
42     private static final String SIMPLE_PKG = "com.android.framework.simpletestapp";
43 
44     // Apk with install location set to auto
45     private static final String AUTO_LOC_APK = "AutoLocTestApp.apk";
46     private static final String AUTO_LOC_PKG = "com.android.framework.autoloctestapp";
47     // Apk with install location set to internalOnly
48     private static final String INTERNAL_LOC_APK = "InternalLocTestApp.apk";
49     private static final String INTERNAL_LOC_PKG = "com.android.framework.internalloctestapp";
50     // Apk with install location set to preferExternal
51     private static final String EXTERNAL_LOC_APK = "ExternalLocTestApp.apk";
52     private static final String EXTERNAL_LOC_PKG = "com.android.framework.externalloctestapp";
53     // Apk with install location set to auto (2 versions, for update testing)
54     @SuppressWarnings("unused")
55     private static final String AUTO_LOC_VERSION_V1_APK = "AutoLocVersionedTestApp_v1.apk";
56 
57     @SuppressWarnings("unused")
58     private static final String AUTO_LOC_VERSION_V2_APK = "AutoLocVersionedTestApp_v2.apk";
59 
60     @SuppressWarnings("unused")
61     private static final String AUTO_LOC_VERSION_PKG =
62             "com.android.framework.autolocversionedtestapp";
63     // Apk with install location set to preferExternal (2 versions, for update
64     // testing)
65     private static final String EXTERNAL_LOC_VERSION_V1_APK = "ExternalLocVersionedTestApp_v1.apk";
66     private static final String EXTERNAL_LOC_VERSION_V2_APK = "ExternalLocVersionedTestApp_v2.apk";
67     private static final String EXTERNAL_LOC_VERSION_PKG =
68             "com.android.framework.externallocversionedtestapp";
69     // Apk with install location set to auto (2 versions, for update testing)
70     private static final String NO_LOC_VERSION_V1_APK = "NoLocVersionedTestApp_v1.apk";
71     private static final String NO_LOC_VERSION_V2_APK = "NoLocVersionedTestApp_v2.apk";
72     private static final String NO_LOC_VERSION_PKG = "com.android.framework.nolocversionedtestapp";
73     // Apk with no install location set
74     private static final String NO_LOC_APK = "NoLocTestApp.apk";
75     private static final String NO_LOC_PKG = "com.android.framework.noloctestapp";
76     // Apk with 2 different versions - v1 is set to external, v2 has no location
77     // setting
78     private static final String UPDATE_EXTERNAL_LOC_V1_EXT_APK =
79             "UpdateExternalLocTestApp_v1_ext.apk";
80     private static final String UPDATE_EXTERNAL_LOC_V2_NONE_APK =
81             "UpdateExternalLocTestApp_v2_none.apk";
82     private static final String UPDATE_EXTERNAL_LOC_PKG =
83             "com.android.framework.updateexternalloctestapp";
84     // Apk with 2 different versions - v1 is set to external, v2 is set to
85     // internalOnly
86     private static final String UPDATE_EXT_TO_INT_LOC_V1_EXT_APK =
87             "UpdateExtToIntLocTestApp_v1_ext.apk";
88     private static final String UPDATE_EXT_TO_INT_LOC_V2_INT_APK =
89             "UpdateExtToIntLocTestApp_v2_int.apk";
90     private static final String UPDATE_EXT_TO_INT_LOC_PKG =
91             "com.android.framework.updateexttointloctestapp";
92     // Apk set to preferExternal, with Access Fine Location permissions set in
93     // its manifest
94     @SuppressWarnings("unused")
95     private static final String FL_PERMS_APK = "ExternalLocPermsFLTestApp.apk";
96 
97     @SuppressWarnings("unused")
98     private static final String FL_PERMS_PKG = "com.android.framework.externallocpermsfltestapp";
99     // Apk set to preferExternal, with all permissions set in manifest
100     private static final String ALL_PERMS_APK = "ExternalLocAllPermsTestApp.apk";
101     private static final String ALL_PERMS_PKG = "com.android.framework.externallocallpermstestapp";
102     // Apks with the same package name, but install location set to
103     // one of: Internal, External, Auto, or None
104     private static final String VERSATILE_LOC_PKG = "com.android.framework.versatiletestapp";
105     private static final String VERSATILE_LOC_INTERNAL_APK = "VersatileTestApp_Internal.apk";
106     private static final String VERSATILE_LOC_EXTERNAL_APK = "VersatileTestApp_External.apk";
107 
108     @SuppressWarnings("unused")
109     private static final String VERSATILE_LOC_AUTO_APK = "VersatileTestApp_Auto.apk";
110 
111     @SuppressWarnings("unused")
112     private static final String VERSATILE_LOC_NONE_APK = "VersatileTestApp_None.apk";
113     // Apks with shared UserID
114     private static final String SHARED_PERMS_APK = "ExternalSharedPermsTestApp.apk";
115     private static final String SHARED_PERMS_PKG =
116             "com.android.framework.externalsharedpermstestapp";
117     private static final String SHARED_PERMS_FL_APK = "ExternalSharedPermsFLTestApp.apk";
118     private static final String SHARED_PERMS_FL_PKG =
119             "com.android.framework.externalsharedpermsfltestapp";
120     private static final String SHARED_PERMS_BT_APK = "ExternalSharedPermsBTTestApp.apk";
121     private static final String SHARED_PERMS_BT_PKG =
122             "com.android.framework.externalsharedpermsbttestapp";
123     // Apk with shared UserID, but signed with a different cert (the media cert)
124     @SuppressWarnings("unused")
125     private static final String SHARED_PERMS_DIFF_KEY_APK = "ExternalSharedPermsDiffKeyTestApp.apk";
126 
127     @SuppressWarnings("unused")
128     private static final String SHARED_PERMS_DIFF_KEY_PKG =
129             "com.android.framework.externalsharedpermsdiffkeytestapp";
130 
131     // Shared uid apks
132     private static final String SHARED_UID_APK = "PMTest_Java.apk";
133     private static final String SHARED_UID_PKG = "com.framework.shareduid.java";
134     private static final String SHARED_UID_APK_32 = "PMTest_Java32.apk";
135     private static final String SHARED_UID_PKG_32 = "com.framework.shareduid.bit32";
136     private static final String SHARED_UID_APK_64 = "PMTest_Java64.apk";
137     private static final String SHARED_UID_PKG_64 = "com.framework.shareduid.bit64";
138     private static final String SHARED_UID_APK_DUAL = "PMTest_Java_dual.apk";
139     private static final String SHARED_UID_PKG_DUAL = "com.framework.shareduid.dual";
140 
141     // TODO: consider fetching these files from build server instead.
142     @Option(
143             name = "app-repository-path",
144             description = "path to the app repository containing large apks",
145             importance = Importance.IF_UNSET)
146     private File mAppRepositoryPath = null;
147 
148     @Override
setUp()149     protected void setUp() throws Exception {
150         super.setUp();
151         // ensure apk path has been set before test is run
152         assertNotNull("Missing --app-repository-path option", mAppRepositoryPath);
153 
154         // setup the PackageManager host tests utilities class, and get various
155         // paths we'll need...
156         mPMHostUtils = new PackageManagerHostTestUtils(getDevice());
157     }
158 
159     /**
160      * Get the absolute file system location of test app with given filename
161      *
162      * @param fileName the file name of the test app apk
163      * @return {@link String} of absolute file path
164      */
getTestAppFilePath(String fileName)165     public File getTestAppFilePath(String fileName) {
166         return FileUtil.getFileForPath(mAppRepositoryPath, fileName);
167     }
168 
169     /**
170      * Regression test to verify that pushing an apk to the private app directory doesn't install
171      * the app, and otherwise cause the system to blow up.
172      *
173      * <p>Assumes adb is running as root in device under test.
174      *
175      * @throws DeviceNotAvailableException
176      */
testPushAppPrivate()177     public void testPushAppPrivate() throws DeviceNotAvailableException {
178         Log.i(LOG_TAG, "testing pushing an apk to /data/app-private");
179         final String apkAppPrivatePath =
180                 PackageManagerHostTestUtils.getAppPrivatePath() + SIMPLE_APK;
181 
182         // cleanup test app just in case it was accidently installed
183         getDevice().uninstallPackage(SIMPLE_PKG);
184         getDevice().executeShellCommand("stop");
185         getDevice().pushFile(getTestAppFilePath(SIMPLE_APK), apkAppPrivatePath);
186 
187         // sanity check to make sure file is there
188         assertTrue(getDevice().doesFileExist(apkAppPrivatePath));
189         getDevice().executeShellCommand("start");
190 
191         mPMHostUtils.waitForPackageManager();
192 
193         // grep for package to make sure its not installed
194         assertFalse(mPMHostUtils.doesPackageExist(SIMPLE_PKG));
195         // TODO: Is the apk supposed to uninstall itself?
196         // ensure it has been deleted from app-private
197         // assertFalse(getDevice().doesFileExist(apkAppPrivatePath));
198     }
199 
200     /**
201      * Helper to do a standard install of an apk and verify it installed to the correct location.
202      *
203      * <p>Assumes adb is running as root in device under test.
204      *
205      * @param apkName the file name of the test app apk
206      * @param pkgName the package name of the test app apk
207      * @param expectedLocation the file name of the test app apk
208      * @throws DeviceNotAvailableException
209      */
doStandardInstall( String apkName, String pkgName, PackageManagerHostTestUtils.InstallLocation expectedLocation)210     private void doStandardInstall(
211             String apkName,
212             String pkgName,
213             PackageManagerHostTestUtils.InstallLocation expectedLocation)
214             throws DeviceNotAvailableException {
215 
216         if (expectedLocation == PackageManagerHostTestUtils.InstallLocation.DEVICE) {
217             mPMHostUtils.installAppAndVerifyExistsOnDevice(
218                     getTestAppFilePath(apkName), pkgName, false);
219         } else {
220             mPMHostUtils.installAppAndVerifyExistsOnSDCard(
221                     getTestAppFilePath(apkName), pkgName, false);
222         }
223     }
224 
225     /**
226      * Installs the Auto app and verifies it was installed at expected loc.
227      *
228      * <p>Assumes adb is running as root in device under test.
229      *
230      * @param expectedLocation the expected location of where the apk was installed
231      * @throws DeviceNotAvailableException
232      */
installAppAutoLoc(PackageManagerHostTestUtils.InstallLocation expectedLocation)233     public void installAppAutoLoc(PackageManagerHostTestUtils.InstallLocation expectedLocation)
234             throws DeviceNotAvailableException {
235         try {
236             // Auto app should go to storage with more free space when device has adopted storage
237             doStandardInstall(AUTO_LOC_APK, AUTO_LOC_PKG, expectedLocation);
238         }
239         // cleanup test app
240         finally {
241             mPMHostUtils.uninstallApp(AUTO_LOC_PKG);
242         }
243     }
244 
245     /**
246      * Regression test to verify that an app with its manifest set to installLocation=auto will
247      * install the app to the device
248      *
249      * <p>Assumes adb is running as root in device under test.
250      */
testInstallAppLocPrefIsAuto()251     public void testInstallAppLocPrefIsAuto() throws Exception {
252         Log.i(LOG_TAG, "Test app manifest installLocation=auto gets installed on device");
253         installAppAutoLoc(PackageManagerHostTestUtils.InstallLocation.DEVICE);
254     }
255 
256     /**
257      * Installs the Internal app and verifies it was installed at expected loc.
258      *
259      * <p>Assumes adb is running as root in device under test.
260      *
261      * @param expectedLocation the expected location of where the apk was installed
262      */
installAppInternalLoc(PackageManagerHostTestUtils.InstallLocation expectedLocation)263     public void installAppInternalLoc(PackageManagerHostTestUtils.InstallLocation expectedLocation)
264             throws Exception {
265         try {
266             doStandardInstall(INTERNAL_LOC_APK, INTERNAL_LOC_PKG, expectedLocation);
267         }
268         // cleanup test app
269         finally {
270             mPMHostUtils.uninstallApp(INTERNAL_LOC_PKG);
271         }
272     }
273 
274     /**
275      * Regression test to verify that an app with its manifest set to installLocation=internalOnly
276      * will install the app to the device when device's preference is auto.
277      *
278      * <p>Assumes adb is running as root in device under test.
279      */
testInstallAppLocPrefIsInternal()280     public void testInstallAppLocPrefIsInternal() throws Exception {
281         Log.i(LOG_TAG, "Test app manifest installLocation=internal gets installed on device");
282         installAppInternalLoc(PackageManagerHostTestUtils.InstallLocation.DEVICE);
283     }
284 
285     /**
286      * Regression test to verify that an app with its manifest set to installLocation=preferExternal
287      * will install the app to expected loc.
288      *
289      * <p>Assumes adb is running as root in device under test.
290      *
291      * @param expectedLocation the expected location of where the apk was installed
292      */
installAppExternalLoc(PackageManagerHostTestUtils.InstallLocation expectedLocation)293     public void installAppExternalLoc(PackageManagerHostTestUtils.InstallLocation expectedLocation)
294             throws Exception {
295         try {
296             doStandardInstall(EXTERNAL_LOC_APK, EXTERNAL_LOC_PKG, expectedLocation);
297         }
298         // cleanup test app
299         finally {
300             mPMHostUtils.uninstallApp(EXTERNAL_LOC_PKG);
301         }
302     }
303 
304     /**
305      * Regression test to verify that an app with its manifest set to installLocation=preferExternal
306      * will install the app to the appropriate external storage.
307      *
308      * <p>Assumes adb is running as root in device under test.
309      */
testInstallAppLocPrefIsExternal()310     public void testInstallAppLocPrefIsExternal() throws Exception {
311         Log.i(LOG_TAG, "Test installLocation=external gets installed on SD Card");
312         installAppExternalLoc(PackageManagerHostTestUtils.InstallLocation.SDCARD);
313     }
314 
315     /**
316      * Regression test to verify that an app without installLocation in its manifest will install
317      * the app to the device by default
318      *
319      * <p>Assumes adb is running as root in device under test.
320      */
testInstallAppNoLocPrefIsAuto()321     public void testInstallAppNoLocPrefIsAuto() throws Exception {
322         Log.i(LOG_TAG, "Test an app with no installLocation gets installed on device");
323         try {
324             mPMHostUtils.installAppAndVerifyExistsOnDevice(
325                     getTestAppFilePath(NO_LOC_APK), NO_LOC_PKG, false);
326         }
327         // cleanup test app
328         finally {
329             mPMHostUtils.uninstallApp(NO_LOC_PKG);
330         }
331     }
332 
333     /**
334      * Regression test to verify that an app with its installLocation set to internal that is
335      * forward-locked will get installed to the correct location.
336      *
337      * <p>Assumes adb is running as root in device under test.
338      */
testInstallFwdLockedAppInternal()339     public void testInstallFwdLockedAppInternal() throws Exception {
340         Log.i(LOG_TAG, "Test an app with installLoc set to Internal gets installed to app-private");
341 
342         try {
343             mPMHostUtils.installFwdLockedAppAndVerifyExists(
344                     getTestAppFilePath(INTERNAL_LOC_APK), INTERNAL_LOC_PKG, false);
345         }
346         // cleanup test app
347         finally {
348             mPMHostUtils.uninstallApp(INTERNAL_LOC_PKG);
349         }
350     }
351 
352     /**
353      * Regression test to verify that an app with its installLocation set to external that is
354      * forward-locked will get installed to the correct location.
355      *
356      * <p>Assumes adb is running as root in device under test.
357      */
testInstallFwdLockedAppExternal()358     public void testInstallFwdLockedAppExternal() throws Exception {
359         Log.i(LOG_TAG, "Test an app with installLoc set to Internal gets installed to app-private");
360 
361         try {
362             mPMHostUtils.installFwdLockedAppAndVerifyExists(
363                     getTestAppFilePath(EXTERNAL_LOC_APK), EXTERNAL_LOC_PKG, false);
364         }
365         // cleanup test app
366         finally {
367             mPMHostUtils.uninstallApp(EXTERNAL_LOC_PKG);
368         }
369     }
370 
371     /**
372      * Regression test to verify that an app with its installLocation set to external that is
373      * forward-locked will get installed to the correct location.
374      *
375      * <p>Assumes adb is running as root in device under test.
376      */
testInstallFwdLockedAppAuto()377     public void testInstallFwdLockedAppAuto() throws Exception {
378         Log.i(LOG_TAG, "Test an app with installLoc set to Auto gets installed to app-private");
379 
380         try {
381             mPMHostUtils.installFwdLockedAppAndVerifyExists(
382                     getTestAppFilePath(AUTO_LOC_APK), AUTO_LOC_PKG, false);
383         }
384         // cleanup test app
385         finally {
386             mPMHostUtils.uninstallApp(AUTO_LOC_PKG);
387         }
388     }
389 
390     /**
391      * Regression test to verify that an app with no installLocation set and is forward-locked
392      * installed will get installed to the correct location.
393      *
394      * <p>Assumes adb is running as root in device under test.
395      */
testInstallFwdLockedAppNone()396     public void testInstallFwdLockedAppNone() throws Exception {
397         Log.i(LOG_TAG, "Test an app with no installLoc set gets installed to app-private");
398 
399         try {
400             mPMHostUtils.installFwdLockedAppAndVerifyExists(
401                     getTestAppFilePath(NO_LOC_APK), NO_LOC_PKG, false);
402         }
403         // cleanup test app
404         finally {
405             mPMHostUtils.uninstallApp(NO_LOC_PKG);
406         }
407     }
408 
409     /**
410      * Regression test to verify that we can install an app onto the device, uninstall it, and
411      * reinstall it onto the SD card.
412      *
413      * <p>Assumes adb is running as root in device under test.
414      */
415     // TODO: This currently relies on the app's manifest to switch from device
416     // to
417     // SD card install locations. We might want to make Device's
418     // installPackage()
419     // accept a installLocation flag so we can install a package to the
420     // destination of our choosing.
testReinstallInternalToExternal()421     public void testReinstallInternalToExternal() throws Exception {
422         Log.i(LOG_TAG, "Test installing an app first to the device, then to the SD Card");
423 
424         try {
425             mPMHostUtils.installAppAndVerifyExistsOnDevice(
426                     getTestAppFilePath(VERSATILE_LOC_INTERNAL_APK), VERSATILE_LOC_PKG, false);
427             mPMHostUtils.uninstallApp(VERSATILE_LOC_PKG);
428             mPMHostUtils.installAppAndVerifyExistsOnSDCard(
429                     getTestAppFilePath(VERSATILE_LOC_EXTERNAL_APK), VERSATILE_LOC_PKG, false);
430         }
431         // cleanup test app
432         finally {
433             mPMHostUtils.uninstallApp(VERSATILE_LOC_PKG);
434         }
435     }
436 
437     /**
438      * Regression test to verify that we can install an app onto the SD Card, uninstall it, and
439      * reinstall it onto the device.
440      *
441      * <p>Assumes adb is running as root in device under test.
442      */
443     // TODO: This currently relies on the app's manifest to switch from device
444     // to
445     // SD card install locations. We might want to make Device's
446     // installPackage()
447     // accept a installLocation flag so we can install a package to the
448     // destination of our choosing.
testReinstallExternalToInternal()449     public void testReinstallExternalToInternal() throws Exception {
450         Log.i(LOG_TAG, "Test installing an app first to the SD Care, then to the device");
451 
452         try {
453             // install the app externally
454             mPMHostUtils.installAppAndVerifyExistsOnSDCard(
455                     getTestAppFilePath(VERSATILE_LOC_EXTERNAL_APK), VERSATILE_LOC_PKG, false);
456             mPMHostUtils.uninstallApp(VERSATILE_LOC_PKG);
457             // then replace the app with one marked for internalOnly
458             mPMHostUtils.installAppAndVerifyExistsOnDevice(
459                     getTestAppFilePath(VERSATILE_LOC_INTERNAL_APK), VERSATILE_LOC_PKG, false);
460         }
461         // cleanup test app
462         finally {
463             mPMHostUtils.uninstallApp(VERSATILE_LOC_PKG);
464         }
465     }
466 
467     /**
468      * Regression test to verify that updating an app on the SD card will install the update onto
469      * the SD card as well when location is set to external for both versions
470      *
471      * <p>Assumes adb is running as root in device under test.
472      */
testUpdateBothExternal()473     public void testUpdateBothExternal() throws Exception {
474         Log.i(LOG_TAG, "Test updating an app on the SD card stays on the SD card");
475 
476         try {
477             // install the app externally
478             mPMHostUtils.installAppAndVerifyExistsOnSDCard(
479                     getTestAppFilePath(EXTERNAL_LOC_VERSION_V1_APK),
480                     EXTERNAL_LOC_VERSION_PKG,
481                     false);
482             // now replace the app with one where the location is still set to
483             // preferExternal
484             mPMHostUtils.installAppAndVerifyExistsOnSDCard(
485                     getTestAppFilePath(EXTERNAL_LOC_VERSION_V2_APK),
486                     EXTERNAL_LOC_VERSION_PKG,
487                     true);
488         }
489         // cleanup test app
490         finally {
491             mPMHostUtils.uninstallApp(EXTERNAL_LOC_VERSION_PKG);
492         }
493     }
494 
495     /**
496      * Regression test to verify that updating an app on the SD card will install the update onto
497      * the SD card as well when location is not explicitly set in the updated apps' manifest file.
498      *
499      * <p>Assumes adb is running as root in device under test.
500      */
testUpdateToSDCard()501     public void testUpdateToSDCard() throws Exception {
502         Log.i(LOG_TAG, "Test updating an app on the SD card stays on the SD card");
503 
504         try {
505             // install the app externally
506             mPMHostUtils.installAppAndVerifyExistsOnSDCard(
507                     getTestAppFilePath(UPDATE_EXTERNAL_LOC_V1_EXT_APK),
508                     UPDATE_EXTERNAL_LOC_PKG,
509                     false);
510             // now replace the app with one where the location is blank (app
511             // should stay external)
512             mPMHostUtils.installAppAndVerifyExistsOnSDCard(
513                     getTestAppFilePath(UPDATE_EXTERNAL_LOC_V2_NONE_APK),
514                     UPDATE_EXTERNAL_LOC_PKG,
515                     true);
516         }
517         // cleanup test app
518         finally {
519             mPMHostUtils.uninstallApp(UPDATE_EXTERNAL_LOC_PKG);
520         }
521     }
522 
523     /**
524      * Regression test to verify that updating an app on the SD card will install the update onto
525      * the device if the manifest has changed to installLocation=internalOnly
526      *
527      * <p>Assumes adb is running as root in device under test.
528      */
testUpdateSDCardToDevice()529     public void testUpdateSDCardToDevice() throws Exception {
530         Log.i(LOG_TAG, "Test updating an app on the SD card to the Device through manifest change");
531 
532         try {
533             // install the app externally
534             mPMHostUtils.installAppAndVerifyExistsOnSDCard(
535                     getTestAppFilePath(UPDATE_EXT_TO_INT_LOC_V1_EXT_APK),
536                     UPDATE_EXT_TO_INT_LOC_PKG,
537                     false);
538             // now replace the app with an update marked for
539             // internalOnly...(should move internal)
540             mPMHostUtils.installAppAndVerifyExistsOnDevice(
541                     getTestAppFilePath(UPDATE_EXT_TO_INT_LOC_V2_INT_APK),
542                     UPDATE_EXT_TO_INT_LOC_PKG,
543                     true);
544         }
545         // cleanup test app
546         finally {
547             mPMHostUtils.uninstallApp(UPDATE_EXT_TO_INT_LOC_PKG);
548         }
549     }
550 
551     /**
552      * Regression test to verify that installing and updating a forward-locked app will install the
553      * update onto the device's forward-locked location
554      *
555      * <p>Assumes adb is running as root in device under test.
556      */
testInstallAndUpdateExternalLocForwardLockedApp()557     public void testInstallAndUpdateExternalLocForwardLockedApp() throws Exception {
558         Log.i(LOG_TAG, "Test updating a forward-locked app marked preferExternal");
559 
560         try {
561             // first try to install the forward-locked app externally
562             mPMHostUtils.installFwdLockedAppAndVerifyExists(
563                     getTestAppFilePath(EXTERNAL_LOC_VERSION_V1_APK),
564                     EXTERNAL_LOC_VERSION_PKG,
565                     false);
566             // now replace the app with an update marked for internalOnly and as
567             // forward locked
568             mPMHostUtils.installFwdLockedAppAndVerifyExists(
569                     getTestAppFilePath(EXTERNAL_LOC_VERSION_V2_APK),
570                     EXTERNAL_LOC_VERSION_PKG,
571                     true);
572         }
573         // cleanup test app
574         finally {
575             mPMHostUtils.uninstallApp(EXTERNAL_LOC_VERSION_PKG);
576         }
577     }
578 
579     /**
580      * Regression test to verify that updating a forward-locked app will install the update onto the
581      * device's forward-locked location
582      *
583      * <p>Assumes adb is running as root in device under test.
584      */
testInstallAndUpdateNoLocForwardLockedApp()585     public void testInstallAndUpdateNoLocForwardLockedApp() throws Exception {
586         Log.i(LOG_TAG, "Test updating a forward-locked app with no installLocation pref set");
587 
588         try {
589             // install the app
590             mPMHostUtils.installFwdLockedAppAndVerifyExists(
591                     getTestAppFilePath(NO_LOC_VERSION_V1_APK), NO_LOC_VERSION_PKG, false);
592             // now replace the app with an update marked for internalOnly...
593             mPMHostUtils.installFwdLockedAppAndVerifyExists(
594                     getTestAppFilePath(NO_LOC_VERSION_V2_APK), NO_LOC_VERSION_PKG, true);
595         }
596         // cleanup test app
597         finally {
598             mPMHostUtils.uninstallApp(NO_LOC_VERSION_PKG);
599         }
600     }
601 
602     /**
603      * Regression test to verify that an app with all permissions set can be installed on SD card
604      * and then launched without crashing.
605      *
606      * <p>Assumes adb is running as root in device under test.
607      */
testInstallAndLaunchAllPermsAppOnSD()608     public void testInstallAndLaunchAllPermsAppOnSD() throws Exception {
609         Log.i(LOG_TAG, "Test launching an app with all perms set, installed on SD card");
610 
611         try {
612             // install the app
613             mPMHostUtils.installAppAndVerifyExistsOnSDCard(
614                     getTestAppFilePath(ALL_PERMS_APK), ALL_PERMS_PKG, false);
615             boolean testsPassed = mPMHostUtils.runDeviceTestsDidAllTestsPass(ALL_PERMS_PKG);
616             assert (testsPassed);
617         }
618         // cleanup test app
619         finally {
620             mPMHostUtils.uninstallApp(ALL_PERMS_PKG);
621         }
622     }
623 
624     /**
625      * Regression test to verify that an app with ACCESS_FINE_LOCATION (GPS) permissions can run
626      * without permissions errors.
627      *
628      * <p>Assumes adb is running as root in device under test.
629      */
testInstallAndLaunchFLPermsAppOnSD()630     public void testInstallAndLaunchFLPermsAppOnSD() throws Exception {
631         Log.i(LOG_TAG, "Test launching an app with location perms set, installed on SD card");
632 
633         try {
634             // install the app and verify we can launch it without permissions
635             // errors
636             mPMHostUtils.installAppAndVerifyExistsOnSDCard(
637                     getTestAppFilePath(SHARED_PERMS_FL_APK), SHARED_PERMS_FL_PKG, false);
638             boolean testsPassed = mPMHostUtils.runDeviceTestsDidAllTestsPass(SHARED_PERMS_FL_PKG);
639             assert (testsPassed);
640         }
641         // cleanup test app
642         finally {
643             mPMHostUtils.uninstallApp(SHARED_PERMS_FL_PKG);
644         }
645     }
646 
647     /**
648      * Regression test to verify that an app with BLUE_TOOTH permissions can run without permissions
649      * errors.
650      *
651      * <p>Assumes adb is running as root in device under test.
652      */
testInstallAndLaunchBTPermsAppOnSD()653     public void testInstallAndLaunchBTPermsAppOnSD() throws Exception {
654         Log.i(LOG_TAG, "Test launching an app with bluetooth perms set, installed on SD card");
655 
656         try {
657             // install the app and verify we can launch it without permissions
658             // errors
659             mPMHostUtils.installAppAndVerifyExistsOnSDCard(
660                     getTestAppFilePath(SHARED_PERMS_BT_APK), SHARED_PERMS_BT_PKG, false);
661             boolean testsPassed = mPMHostUtils.runDeviceTestsDidAllTestsPass(SHARED_PERMS_BT_PKG);
662             assert (testsPassed);
663         }
664         // cleanup test app
665         finally {
666             mPMHostUtils.uninstallApp(SHARED_PERMS_BT_PKG);
667         }
668     }
669 
670     /**
671      * Regression test to verify that a shared app with no explicit permissions throws a
672      * SecurityException when launched if its other shared apps are not installed.
673      *
674      * <p>Assumes adb is running as root in device under test.
675      */
testInstallAndLaunchSharedPermsAppOnSD_NoPerms()676     public void testInstallAndLaunchSharedPermsAppOnSD_NoPerms() throws Exception {
677         Log.i(LOG_TAG, "Test launching an app with no explicit perms set, installed on SD card");
678 
679         try {
680             // Make sure the 2 shared apps with needed permissions are not
681             // installed...
682             mPMHostUtils.uninstallApp(SHARED_PERMS_FL_PKG);
683             mPMHostUtils.uninstallApp(SHARED_PERMS_BT_PKG);
684 
685             // now install the app and see if when we launch it we get a
686             // permissions error
687             mPMHostUtils.installAppAndVerifyExistsOnSDCard(
688                     getTestAppFilePath(SHARED_PERMS_APK), SHARED_PERMS_PKG, false);
689 
690             boolean testsPassed = mPMHostUtils.runDeviceTestsDidAllTestsPass(SHARED_PERMS_PKG);
691             assertEquals("Shared perms app should fail to run", false, testsPassed);
692         }
693         // cleanup test app
694         finally {
695             mPMHostUtils.uninstallApp(SHARED_PERMS_PKG);
696         }
697     }
698 
699     /**
700      * Regression test to verify that a shared app with no explicit permissions can run if its other
701      * shared apps are installed.
702      *
703      * <p>Assumes adb is running as root in device under test.
704      */
testInstallAndLaunchSharedPermsAppOnSD_GrantedPerms()705     public void testInstallAndLaunchSharedPermsAppOnSD_GrantedPerms() throws Exception {
706         Log.i(LOG_TAG, "Test launching an app with no explicit perms set, installed on SD card");
707 
708         try {
709             // install the 2 shared apps with needed permissions first
710             mPMHostUtils.installAppAndVerifyExistsOnSDCard(
711                     getTestAppFilePath(SHARED_PERMS_FL_APK), SHARED_PERMS_FL_PKG, false);
712             mPMHostUtils.installAppAndVerifyExistsOnSDCard(
713                     getTestAppFilePath(SHARED_PERMS_BT_APK), SHARED_PERMS_BT_PKG, false);
714 
715             // now install the test app and see if we can launch it without
716             // errors
717             mPMHostUtils.installAppAndVerifyExistsOnSDCard(
718                     getTestAppFilePath(SHARED_PERMS_APK), SHARED_PERMS_PKG, false);
719             boolean testsPassed = mPMHostUtils.runDeviceTestsDidAllTestsPass(SHARED_PERMS_PKG);
720             assert (testsPassed);
721         }
722         // cleanup test app
723         finally {
724             mPMHostUtils.uninstallApp(SHARED_PERMS_PKG);
725             mPMHostUtils.uninstallApp(SHARED_PERMS_BT_PKG);
726             mPMHostUtils.uninstallApp(SHARED_PERMS_FL_PKG);
727         }
728     }
729 
730     /**
731      * Regression test to verify that an app with ACCESS_FINE_LOCATION (GPS) permissions can run
732      * without permissions errors even after a reboot
733      *
734      * <p>Assumes adb is running as root in device under test.
735      */
testInstallAndLaunchFLPermsAppOnSD_Reboot()736     public void testInstallAndLaunchFLPermsAppOnSD_Reboot() throws Exception {
737         Log.i(LOG_TAG, "Test launching an app with location perms set, installed on SD card");
738 
739         try {
740             // install the app and verify we can launch it without permissions
741             // errors
742             mPMHostUtils.installAppAndVerifyExistsOnSDCard(
743                     getTestAppFilePath(SHARED_PERMS_FL_APK), SHARED_PERMS_FL_PKG, false);
744             boolean testsPassed = mPMHostUtils.runDeviceTestsDidAllTestsPass(SHARED_PERMS_FL_PKG);
745             assert (testsPassed);
746 
747             getDevice().reboot();
748 
749             testsPassed = mPMHostUtils.runDeviceTestsDidAllTestsPass(SHARED_PERMS_FL_PKG);
750             assert (testsPassed);
751         }
752         // cleanup test app
753         finally {
754             mPMHostUtils.uninstallApp(SHARED_PERMS_FL_PKG);
755         }
756     }
757 
758     /**
759      * Regression test to verify that a shared app with no explicit permissions can run if its other
760      * shared apps are installed, even after a reboot.
761      *
762      * <p>Assumes adb is running as root in device under test.
763      */
testInstallAndLaunchSharedPermsAppOnSD_Reboot()764     public void testInstallAndLaunchSharedPermsAppOnSD_Reboot() throws Exception {
765         Log.i(LOG_TAG, "Test launching an app on SD, with no explicit perms set after reboot");
766 
767         try {
768             // install the 2 shared apps with needed permissions first
769             mPMHostUtils.installAppAndVerifyExistsOnSDCard(
770                     getTestAppFilePath(SHARED_PERMS_FL_APK), SHARED_PERMS_FL_PKG, false);
771             mPMHostUtils.installAppAndVerifyExistsOnSDCard(
772                     getTestAppFilePath(SHARED_PERMS_BT_APK), SHARED_PERMS_BT_PKG, false);
773 
774             // now install the test app and see if we can launch it without
775             // errors
776             mPMHostUtils.installAppAndVerifyExistsOnSDCard(
777                     getTestAppFilePath(SHARED_PERMS_APK), SHARED_PERMS_PKG, false);
778             boolean testsPassed = mPMHostUtils.runDeviceTestsDidAllTestsPass(SHARED_PERMS_PKG);
779             assert (testsPassed);
780 
781             // reboot
782             getDevice().reboot();
783 
784             // Verify we can still launch the app
785             testsPassed = mPMHostUtils.runDeviceTestsDidAllTestsPass(SHARED_PERMS_PKG);
786             assert (testsPassed);
787         }
788         // cleanup test app
789         finally {
790             mPMHostUtils.uninstallApp(SHARED_PERMS_PKG);
791             mPMHostUtils.uninstallApp(SHARED_PERMS_BT_PKG);
792             mPMHostUtils.uninstallApp(SHARED_PERMS_FL_PKG);
793         }
794     }
795 
testInstallApk32bit()796     public void testInstallApk32bit() throws DeviceNotAvailableException {
797         try {
798             mPMHostUtils.installFile(getTestAppFilePath(SHARED_UID_APK_32), true);
799             assertEquals(ARMEABI_V7A, mPMHostUtils.getAbi(SHARED_UID_PKG_32));
800         } finally {
801             mPMHostUtils.uninstallApp(SHARED_UID_PKG_32);
802         }
803     }
804 
testInstallApk64bit()805     public void testInstallApk64bit() throws DeviceNotAvailableException {
806         try {
807             if (!ARM64_V8A.equals(getDevice().getProperty(ABI_PROPERTY))) {
808                 return;
809             }
810             mPMHostUtils.installFile(getTestAppFilePath(SHARED_UID_APK_64), true);
811             assertEquals(ARM64_V8A, mPMHostUtils.getAbi(SHARED_UID_PKG_64));
812         } finally {
813             mPMHostUtils.uninstallApp(SHARED_UID_PKG_64);
814         }
815     }
816 
testInstallApkDualAbi()817     public void testInstallApkDualAbi() throws DeviceNotAvailableException {
818         try {
819             mPMHostUtils.installFile(getTestAppFilePath(SHARED_UID_APK_DUAL), true);
820             assertEquals(
821                     getDevice().getProperty(ABI_PROPERTY),
822                     mPMHostUtils.getAbi(SHARED_UID_PKG_DUAL));
823         } finally {
824             mPMHostUtils.uninstallApp(SHARED_UID_PKG_DUAL);
825         }
826     }
827 
testInstallSharedUid32()828     public void testInstallSharedUid32() throws DeviceNotAvailableException {
829         try {
830             if (!ARMEABI_V7A.equals(getDevice().getProperty(ABI_PROPERTY))) {
831                 return;
832             }
833             mPMHostUtils.installFile(getTestAppFilePath(SHARED_UID_APK), true);
834             mPMHostUtils.installFile(getTestAppFilePath(SHARED_UID_APK_32), true);
835             assertEquals(
836                     mPMHostUtils.getUid(SHARED_UID_PKG), mPMHostUtils.getUid(SHARED_UID_PKG_32));
837         } finally {
838             mPMHostUtils.uninstallApp(SHARED_UID_PKG);
839             mPMHostUtils.uninstallApp(SHARED_UID_PKG_32);
840         }
841     }
842 
testInstallSharedUid64()843     public void testInstallSharedUid64() throws DeviceNotAvailableException {
844         try {
845             if (!ARM64_V8A.equals(getDevice().getProperty(ABI_PROPERTY))) {
846                 return;
847             }
848             mPMHostUtils.installFile(getTestAppFilePath(SHARED_UID_APK), true);
849             mPMHostUtils.installFile(getTestAppFilePath(SHARED_UID_APK_64), true);
850             assertEquals(
851                     mPMHostUtils.getUid(SHARED_UID_PKG), mPMHostUtils.getUid(SHARED_UID_PKG_64));
852         } finally {
853             mPMHostUtils.uninstallApp(SHARED_UID_PKG);
854             mPMHostUtils.uninstallApp(SHARED_UID_PKG_64);
855         }
856     }
857 
testInstallSharedUidDual64()858     public void testInstallSharedUidDual64() throws DeviceNotAvailableException {
859         try {
860             if (!ARM64_V8A.equals(getDevice().getProperty(ABI_PROPERTY))) {
861                 return;
862             }
863             mPMHostUtils.installFile(getTestAppFilePath(SHARED_UID_APK_DUAL), true);
864             mPMHostUtils.installFile(getTestAppFilePath(SHARED_UID_APK_64), true);
865             assertEquals(
866                     mPMHostUtils.getUid(SHARED_UID_PKG_DUAL),
867                     mPMHostUtils.getUid(SHARED_UID_PKG_64));
868         } finally {
869             mPMHostUtils.uninstallApp(SHARED_UID_PKG_DUAL);
870             mPMHostUtils.uninstallApp(SHARED_UID_PKG_64);
871         }
872     }
873 
testInstallSharedUidDual32()874     public void testInstallSharedUidDual32() throws DeviceNotAvailableException {
875         try {
876             if (!ARMEABI_V7A.equals(getDevice().getProperty(ABI_PROPERTY))) {
877                 return;
878             }
879             mPMHostUtils.installFile(getTestAppFilePath(SHARED_UID_APK_DUAL), true);
880             mPMHostUtils.installFile(getTestAppFilePath(SHARED_UID_APK_32), true);
881             assertEquals(
882                     mPMHostUtils.getUid(SHARED_UID_PKG_DUAL),
883                     mPMHostUtils.getUid(SHARED_UID_PKG_32));
884         } finally {
885             mPMHostUtils.uninstallApp(SHARED_UID_PKG_DUAL);
886             mPMHostUtils.uninstallApp(SHARED_UID_PKG_32);
887         }
888     }
889 
testInstallSharedUidJavaDual()890     public void testInstallSharedUidJavaDual() throws DeviceNotAvailableException {
891         try {
892             mPMHostUtils.installFile(getTestAppFilePath(SHARED_UID_APK_DUAL), true);
893             mPMHostUtils.installFile(getTestAppFilePath(SHARED_UID_APK), true);
894             assertEquals(
895                     mPMHostUtils.getUid(SHARED_UID_PKG_DUAL), mPMHostUtils.getUid(SHARED_UID_PKG));
896         } finally {
897             mPMHostUtils.uninstallApp(SHARED_UID_PKG_DUAL);
898             mPMHostUtils.uninstallApp(SHARED_UID_PKG);
899         }
900     }
901 }
902