blob: 1b797d5a40abc5a0247fdc280ecf7efe221d5860 [file] [log] [blame]
Brett Chabotcb2003a2010-02-17 11:18:16 -08001/*
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
17package android.content.pm;
18
Neal Nguyen7cbb92d2010-03-22 13:14:25 -070019import com.android.ddmlib.IDevice;
Brett Chabotcb2003a2010-02-17 11:18:16 -080020import com.android.ddmlib.IShellOutputReceiver;
21import com.android.ddmlib.Log;
22import com.android.ddmlib.MultiLineReceiver;
23import com.android.ddmlib.SyncService;
24import com.android.ddmlib.SyncService.ISyncProgressMonitor;
25import com.android.ddmlib.SyncService.SyncResult;
26import com.android.hosttest.DeviceTestCase;
27import com.android.hosttest.DeviceTestSuite;
28
29import java.io.File;
30import java.io.IOException;
31
32import junit.framework.Test;
33
34/**
35 * Set of tests that verify host side install cases
36 */
37public class PackageManagerHostTests extends DeviceTestCase {
38
Neal Nguyen7cbb92d2010-03-22 13:14:25 -070039 private static final String LOG_TAG = "PackageManagerHostTests";
Neal Nguyen70df9ba2010-03-24 19:15:31 -070040 private PackageManagerHostTestUtils mPMHostUtils = null;
Neal Nguyen7cbb92d2010-03-22 13:14:25 -070041
Neal Nguyen70df9ba2010-03-24 19:15:31 -070042 private String appPrivatePath = null;
43 private String deviceAppPath = null;
44 private String sdcardAppPath = null;
Neal Nguyen7cbb92d2010-03-22 13:14:25 -070045
46 // Various test files and their corresponding package names...
47
Brett Chabotcb2003a2010-02-17 11:18:16 -080048 // testPushAppPrivate constants
49 // these constants must match values defined in test-apps/SimpleTestApp
50 private static final String SIMPLE_APK = "SimpleTestApp.apk";
51 private static final String SIMPLE_PKG = "com.android.framework.simpletestapp";
Brett Chabotcb2003a2010-02-17 11:18:16 -080052
Neal Nguyen7cbb92d2010-03-22 13:14:25 -070053 // Apk with install location set to auto
54 private static final String AUTO_LOC_APK = "AutoLocTestApp.apk";
55 private static final String AUTO_LOC_PKG = "com.android.framework.autoloctestapp";
56 // Apk with install location set to internalOnly
57 private static final String INTERNAL_LOC_APK = "InternalLocTestApp.apk";
58 private static final String INTERNAL_LOC_PKG = "com.android.framework.internalloctestapp";
59 // Apk with install location set to preferExternal
60 private static final String EXTERNAL_LOC_APK = "ExternalLocTestApp.apk";
61 private static final String EXTERNAL_LOC_PKG = "com.android.framework.externalloctestapp";
Neal Nguyenb1fb5c32010-03-31 16:45:01 -070062 // Apk with install location set to auto (2 versions, for update testing)
63 private static final String AUTO_LOC_VERSION_V1_APK = "AutoLocVersionedTestApp_v1.apk";
64 private static final String AUTO_LOC_VERSION_V2_APK = "AutoLocVersionedTestApp_v2.apk";
65 private static final String AUTO_LOC_VERSION_PKG =
66 "com.android.framework.autolocversionedtestapp";
67 // Apk with install location set to preferExternal (2 versions, for update testing)
68 private static final String EXTERNAL_LOC_VERSION_V1_APK = "ExternalLocVersionedTestApp_v1.apk";
69 private static final String EXTERNAL_LOC_VERSION_V2_APK = "ExternalLocVersionedTestApp_v2.apk";
70 private static final String EXTERNAL_LOC_VERSION_PKG =
71 "com.android.framework.externallocversionedtestapp";
72 // Apk with install location set to auto (2 versions, for update testing)
73 private static final String NO_LOC_VERSION_V1_APK = "NoLocVersionedTestApp_v1.apk";
74 private static final String NO_LOC_VERSION_V2_APK = "NoLocVersionedTestApp_v2.apk";
75 private static final String NO_LOC_VERSION_PKG =
76 "com.android.framework.nolocversionedtestapp";
Neal Nguyen7cbb92d2010-03-22 13:14:25 -070077 // Apk with no install location set
78 private static final String NO_LOC_APK = "NoLocTestApp.apk";
79 private static final String NO_LOC_PKG = "com.android.framework.noloctestapp";
80 // Apk with 2 different versions - v1 is set to external, v2 has no location setting
81 private static final String UPDATE_EXTERNAL_LOC_V1_EXT_APK
82 = "UpdateExternalLocTestApp_v1_ext.apk";
83 private static final String UPDATE_EXTERNAL_LOC_V2_NONE_APK
84 = "UpdateExternalLocTestApp_v2_none.apk";
85 private static final String UPDATE_EXTERNAL_LOC_PKG
86 = "com.android.framework.updateexternalloctestapp";
87 // Apk with 2 different versions - v1 is set to external, v2 is set to internalOnly
88 private static final String UPDATE_EXT_TO_INT_LOC_V1_EXT_APK
89 = "UpdateExtToIntLocTestApp_v1_ext.apk";
90 private static final String UPDATE_EXT_TO_INT_LOC_V2_INT_APK
91 = "UpdateExtToIntLocTestApp_v2_int.apk";
92 private static final String UPDATE_EXT_TO_INT_LOC_PKG
93 = "com.android.framework.updateexttointloctestapp";
Neal Nguyenb1fb5c32010-03-31 16:45:01 -070094 // Apk set to preferExternal, with Access Fine Location permissions set in its manifest
95 private static final String FL_PERMS_APK = "ExternalLocPermsFLTestApp.apk";
96 private static final String FL_PERMS_PKG = "com.android.framework.externallocpermsfltestapp";
97 // Apk set to preferExternal, with all permissions set in manifest
98 private static final String ALL_PERMS_APK = "ExternalLocAllPermsTestApp.apk";
99 private static final String ALL_PERMS_PKG = "com.android.framework.externallocallpermstestapp";
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700100 // Apks with the same package name, but install location set to
101 // one of: Internal, External, Auto, or None
102 private static final String VERSATILE_LOC_PKG = "com.android.framework.versatiletestapp";
103 private static final String VERSATILE_LOC_INTERNAL_APK = "VersatileTestApp_Internal.apk";
104 private static final String VERSATILE_LOC_EXTERNAL_APK = "VersatileTestApp_External.apk";
105 private static final String VERSATILE_LOC_AUTO_APK = "VersatileTestApp_Auto.apk";
106 private static final String VERSATILE_LOC_NONE_APK = "VersatileTestApp_None.apk";
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700107 // Apks with shared UserID
108 private static final String SHARED_PERMS_APK = "ExternalSharedPermsTestApp.apk";
109 private static final String SHARED_PERMS_PKG
110 = "com.android.framework.externalsharedpermstestapp";
111 private static final String SHARED_PERMS_FL_APK = "ExternalSharedPermsFLTestApp.apk";
112 private static final String SHARED_PERMS_FL_PKG
113 = "com.android.framework.externalsharedpermsfltestapp";
114 private static final String SHARED_PERMS_BT_APK = "ExternalSharedPermsBTTestApp.apk";
115 private static final String SHARED_PERMS_BT_PKG
116 = "com.android.framework.externalsharedpermsbttestapp";
117 // Apk with shared UserID, but signed with a different cert (the media cert)
118 private static final String SHARED_PERMS_DIFF_KEY_APK = "ExternalSharedPermsDiffKeyTestApp.apk";
119 private static final String SHARED_PERMS_DIFF_KEY_PKG
120 = "com.android.framework.externalsharedpermsdiffkeytestapp";
Brett Chabotcb2003a2010-02-17 11:18:16 -0800121
122 @Override
123 protected void setUp() throws Exception {
124 super.setUp();
125 // ensure apk path has been set before test is run
126 assertNotNull(getTestAppPath());
Neal Nguyen70df9ba2010-03-24 19:15:31 -0700127
128 // setup the PackageManager host tests utilities class, and get various paths we'll need...
129 mPMHostUtils = new PackageManagerHostTestUtils(getDevice());
130 appPrivatePath = mPMHostUtils.getAppPrivatePath();
131 deviceAppPath = mPMHostUtils.getDeviceAppPath();
132 sdcardAppPath = mPMHostUtils.getSDCardAppPath();
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700133
134 // Ensure the default is set to let the system decide where to install apps
135 // (It's ok for individual tests to override and change this during their test, but should
136 // reset it back when they're done)
137 mPMHostUtils.setDevicePreferredInstallLocation(
138 PackageManagerHostTestUtils.InstallLocPreference.AUTO);
Neal Nguyen70df9ba2010-03-24 19:15:31 -0700139 }
140
141 /**
142 * Get the absolute file system location of test app with given filename
143 * @param fileName the file name of the test app apk
144 * @return {@link String} of absolute file path
145 */
146 public String getTestAppFilePath(String fileName) {
147 return String.format("%s%s%s", getTestAppPath(), File.separator, fileName);
148 }
149
150 public static Test suite() {
151 return new DeviceTestSuite(PackageManagerHostTests.class);
Brett Chabotcb2003a2010-02-17 11:18:16 -0800152 }
153
154 /**
155 * Regression test to verify that pushing an apk to the private app directory doesn't install
156 * the app, and otherwise cause the system to blow up.
157 * <p/>
158 * Assumes adb is running as root in device under test.
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700159 * @throws IOException if adb shell command failed
160 * @throws InterruptedException if the thread was interrupted
Brett Chabotcb2003a2010-02-17 11:18:16 -0800161 */
162 public void testPushAppPrivate() throws IOException, InterruptedException {
163 Log.i(LOG_TAG, "testing pushing an apk to /data/app-private");
Neal Nguyen70df9ba2010-03-24 19:15:31 -0700164 final String apkAppPrivatePath = appPrivatePath + SIMPLE_APK;
Brett Chabotcb2003a2010-02-17 11:18:16 -0800165
166 // cleanup test app just in case it was accidently installed
167 getDevice().uninstallPackage(SIMPLE_PKG);
Neal Nguyen70df9ba2010-03-24 19:15:31 -0700168 mPMHostUtils.executeShellCommand("stop");
169 mPMHostUtils.pushFile(getTestAppFilePath(SIMPLE_APK), apkAppPrivatePath);
Brett Chabotcb2003a2010-02-17 11:18:16 -0800170
Neal Nguyen70df9ba2010-03-24 19:15:31 -0700171 // sanity check to make sure file is there
172 assertTrue(mPMHostUtils.doesRemoteFileExist(apkAppPrivatePath));
173 mPMHostUtils.executeShellCommand("start");
174
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700175 mPMHostUtils.waitForPackageManager();
Brett Chabotcb2003a2010-02-17 11:18:16 -0800176
177 // grep for package to make sure its not installed
Neal Nguyen70df9ba2010-03-24 19:15:31 -0700178 assertFalse(mPMHostUtils.doesPackageExist(SIMPLE_PKG));
Brett Chabotcb2003a2010-02-17 11:18:16 -0800179 // ensure it has been deleted from app-private
Neal Nguyen70df9ba2010-03-24 19:15:31 -0700180 assertFalse(mPMHostUtils.doesRemoteFileExist(apkAppPrivatePath));
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700181 }
182
183 /**
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700184 * Helper to do a standard install of an apk and verify it installed to the correct location.
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700185 * <p/>
186 * Assumes adb is running as root in device under test.
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700187 * @param apkName the file name of the test app apk
188 * @param pkgName the package name of the test app apk
189 * @param expectedLocation the file name of the test app apk
190 * @throws IOException if adb shell command failed
191 * @throws InterruptedException if the thread was interrupted
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700192 */
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700193 private void doStandardInstall(String apkName, String pkgName,
194 PackageManagerHostTestUtils.InstallLocation expectedLocation)
195 throws IOException, InterruptedException {
196
197 if (expectedLocation == PackageManagerHostTestUtils.InstallLocation.DEVICE) {
198 mPMHostUtils.installAppAndVerifyExistsOnDevice(
199 getTestAppFilePath(apkName), pkgName, false);
200 }
201 else {
202 mPMHostUtils.installAppAndVerifyExistsOnSDCard(
203 getTestAppFilePath(apkName), pkgName, false);
204 }
205 }
206
207 /**
208 * Installs the Auto app using the preferred device install location specified,
209 * and verifies it was installed on the device.
210 * <p/>
211 * Assumes adb is running as root in device under test.
212 * @param preference the device's preferred location of where to install apps
213 * @param expectedLocation the expected location of where the apk was installed
214 * @throws IOException if adb shell command failed
215 * @throws InterruptedException if the thread was interrupted
216 */
217 public void installAppAutoLoc(PackageManagerHostTestUtils.InstallLocPreference preference,
218 PackageManagerHostTestUtils.InstallLocation expectedLocation)
219 throws IOException, InterruptedException {
220
221 PackageManagerHostTestUtils.InstallLocPreference savedPref =
222 PackageManagerHostTestUtils.InstallLocPreference.AUTO;
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700223
224 try {
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700225 savedPref = mPMHostUtils.getDevicePreferredInstallLocation();
226 mPMHostUtils.setDevicePreferredInstallLocation(preference);
227
228 doStandardInstall(AUTO_LOC_APK, AUTO_LOC_PKG, expectedLocation);
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700229 }
230 // cleanup test app
231 finally {
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700232 mPMHostUtils.setDevicePreferredInstallLocation(savedPref);
Neal Nguyen70df9ba2010-03-24 19:15:31 -0700233 mPMHostUtils.uninstallApp(AUTO_LOC_PKG);
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700234 }
235 }
236
237 /**
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700238 * Regression test to verify that an app with its manifest set to installLocation=auto
239 * will install the app to the device when device's preference is auto.
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700240 * <p/>
241 * Assumes adb is running as root in device under test.
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700242 * @throws IOException if adb shell command failed
243 * @throws InterruptedException if the thread was interrupted
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700244 */
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700245 public void testInstallAppAutoLocPrefIsAuto() throws IOException, InterruptedException {
246 Log.i(LOG_TAG, "Test installLocation=auto, prefer=auto gets installed on device");
247 installAppAutoLoc(PackageManagerHostTestUtils.InstallLocPreference.AUTO,
248 PackageManagerHostTestUtils.InstallLocation.DEVICE);
249 }
250
251 /**
252 * Regression test to verify that an app with its manifest set to installLocation=auto
253 * will install the app to the device when device's preference is internal.
254 * <p/>
255 * Assumes adb is running as root in device under test.
256 * @throws IOException if adb shell command failed
257 * @throws InterruptedException if the thread was interrupted
258 */
259 public void testInstallAppAutoLocPrefIsInternal() throws IOException, InterruptedException {
260 Log.i(LOG_TAG, "Test installLocation=auto, prefer=internal gets installed on device");
261 installAppAutoLoc(PackageManagerHostTestUtils.InstallLocPreference.INTERNAL,
262 PackageManagerHostTestUtils.InstallLocation.DEVICE);
263 }
264
265 /**
266 * Regression test to verify that an app with its manifest set to installLocation=auto
267 * will install the app to the SD card when device's preference is external.
268 * <p/>
269 * Assumes adb is running as root in device under test.
270 * @throws IOException if adb shell command failed
271 * @throws InterruptedException if the thread was interrupted
272 */
273 public void testInstallAppAutoLocPrefIsExternal() throws IOException, InterruptedException {
274 Log.i(LOG_TAG, "Test installLocation=auto, prefer=external gets installed on device");
275 installAppAutoLoc(PackageManagerHostTestUtils.InstallLocPreference.EXTERNAL,
276 PackageManagerHostTestUtils.InstallLocation.DEVICE);
277 }
278
279 /**
280 * Installs the Internal app using the preferred device install location specified,
281 * and verifies it was installed to the location expected.
282 * <p/>
283 * Assumes adb is running as root in device under test.
284 * @param preference the device's preferred location of where to install apps
285 * @param expectedLocation the expected location of where the apk was installed
286 * @throws IOException if adb shell command failed
287 * @throws InterruptedException if the thread was interrupted
288 */
289 public void installAppInternalLoc(PackageManagerHostTestUtils.InstallLocPreference preference,
290 PackageManagerHostTestUtils.InstallLocation expectedLocation)
291 throws IOException, InterruptedException {
292
293 PackageManagerHostTestUtils.InstallLocPreference savedPref =
294 PackageManagerHostTestUtils.InstallLocPreference.AUTO;
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700295
296 try {
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700297 savedPref = mPMHostUtils.getDevicePreferredInstallLocation();
298 mPMHostUtils.setDevicePreferredInstallLocation(preference);
299
300 doStandardInstall(INTERNAL_LOC_APK, INTERNAL_LOC_PKG, expectedLocation);
301 }
302 // cleanup test app
303 finally {
304 mPMHostUtils.setDevicePreferredInstallLocation(savedPref);
305 mPMHostUtils.uninstallApp(INTERNAL_LOC_PKG);
306 }
307 }
308
309 /**
310 * Regression test to verify that an app with its manifest set to installLocation=internalOnly
311 * will install the app to the device when device's preference is auto.
312 * <p/>
313 * Assumes adb is running as root in device under test.
314 * @throws IOException if adb shell command failed
315 * @throws InterruptedException if the thread was interrupted
316 */
317 public void testInstallAppInternalLocPrefIsAuto() throws IOException, InterruptedException {
318 Log.i(LOG_TAG, "Test installLocation=internal, prefer=auto gets installed on device");
319 installAppInternalLoc(PackageManagerHostTestUtils.InstallLocPreference.AUTO,
320 PackageManagerHostTestUtils.InstallLocation.DEVICE);
321 }
322
323 /**
324 * Regression test to verify that an app with its manifest set to installLocation=internalOnly
325 * will install the app to the device when device's preference is internal.
326 * <p/>
327 * Assumes adb is running as root in device under test.
328 * @throws IOException if adb shell command failed
329 * @throws InterruptedException if the thread was interrupted
330 */
331 public void testInstallAppInternalLocPrefIsInternal() throws IOException, InterruptedException {
332 Log.i(LOG_TAG, "Test installLocation=internal, prefer=internal is installed on device");
333 installAppInternalLoc(PackageManagerHostTestUtils.InstallLocPreference.INTERNAL,
334 PackageManagerHostTestUtils.InstallLocation.DEVICE);
335 }
336
337 /**
338 * Regression test to verify that an app with its manifest set to installLocation=internalOnly
339 * will install the app to the device when device's preference is external.
340 * <p/>
341 * Assumes adb is running as root in device under test.
342 * @throws IOException if adb shell command failed
343 * @throws InterruptedException if the thread was interrupted
344 */
345 public void testInstallAppInternalLocPrefIsExternal() throws IOException, InterruptedException {
346 Log.i(LOG_TAG, "Test installLocation=internal, prefer=external is installed on device");
347 installAppInternalLoc(PackageManagerHostTestUtils.InstallLocPreference.EXTERNAL,
348 PackageManagerHostTestUtils.InstallLocation.DEVICE);
349 }
350
351 /**
352 * Regression test to verify that an app with its manifest set to installLocation=preferExternal
353 * will install the app to the SD card.
354 * <p/>
355 * Assumes adb is running as root in device under test.
356 * @param preference the device's preferred location of where to install apps
357 * @param expectedLocation the expected location of where the apk was installed
358 * @throws IOException if adb shell command failed
359 * @throws InterruptedException if the thread was interrupted
360 */
361 public void installAppExternalLoc(PackageManagerHostTestUtils.InstallLocPreference preference,
362 PackageManagerHostTestUtils.InstallLocation expectedLocation)
363 throws IOException, InterruptedException {
364
365 PackageManagerHostTestUtils.InstallLocPreference savedPref =
366 PackageManagerHostTestUtils.InstallLocPreference.AUTO;
367
368 try {
369 savedPref = mPMHostUtils.getDevicePreferredInstallLocation();
370 mPMHostUtils.setDevicePreferredInstallLocation(preference);
371
372 doStandardInstall(EXTERNAL_LOC_APK, EXTERNAL_LOC_PKG, expectedLocation);
373
374 }
375 // cleanup test app
376 finally {
377 mPMHostUtils.setDevicePreferredInstallLocation(savedPref);
378 mPMHostUtils.uninstallApp(EXTERNAL_LOC_PKG);
379 }
380 }
381
382 /**
383 * Regression test to verify that an app with its manifest set to installLocation=preferExternal
384 * will install the app to the device when device's preference is auto.
385 * <p/>
386 * Assumes adb is running as root in device under test.
387 * @throws IOException if adb shell command failed
388 * @throws InterruptedException if the thread was interrupted
389 */
390 public void testInstallAppExternalLocPrefIsAuto() throws IOException, InterruptedException {
391 Log.i(LOG_TAG, "Test installLocation=external, pref=auto gets installed on SD Card");
392 installAppExternalLoc(PackageManagerHostTestUtils.InstallLocPreference.AUTO,
393 PackageManagerHostTestUtils.InstallLocation.SDCARD);
394 }
395
396 /**
397 * Regression test to verify that an app with its manifest set to installLocation=preferExternal
398 * will install the app to the device when device's preference is internal.
399 * <p/>
400 * Assumes adb is running as root in device under test.
401 * @throws IOException if adb shell command failed
402 * @throws InterruptedException if the thread was interrupted
403 */
404 public void testInstallAppExternalLocPrefIsInternal() throws IOException, InterruptedException {
405 Log.i(LOG_TAG, "Test installLocation=external, pref=internal gets installed on SD Card");
406 installAppExternalLoc(PackageManagerHostTestUtils.InstallLocPreference.INTERNAL,
407 PackageManagerHostTestUtils.InstallLocation.SDCARD);
408 }
409
410 /**
411 * Regression test to verify that an app with its manifest set to installLocation=preferExternal
412 * will install the app to the device when device's preference is external.
413 * <p/>
414 * Assumes adb is running as root in device under test.
415 * @throws IOException if adb shell command failed
416 * @throws InterruptedException if the thread was interrupted
417 */
418 public void testInstallAppExternalLocPrefIsExternal() throws IOException, InterruptedException {
419 Log.i(LOG_TAG, "Test installLocation=external, pref=external gets installed on SD Card");
420 installAppExternalLoc(PackageManagerHostTestUtils.InstallLocPreference.EXTERNAL,
421 PackageManagerHostTestUtils.InstallLocation.SDCARD);
422 }
423
424 /**
425 * Regression test to verify that an app without installLocation in its manifest
426 * will install the app to the device by default when the system default pref is to let the
427 * system decide.
428 * <p/>
429 * Assumes adb is running as root in device under test.
430 * @throws IOException if adb shell command failed
431 * @throws InterruptedException if the thread was interrupted
432 */
433 public void testInstallAppNoLocPrefIsAuto() throws IOException, InterruptedException {
434 Log.i(LOG_TAG, "Test an app with no installLocation gets installed on device");
435
436 PackageManagerHostTestUtils.InstallLocPreference savedPref =
437 PackageManagerHostTestUtils.InstallLocPreference.AUTO;
438
439 try {
440 savedPref = mPMHostUtils.getDevicePreferredInstallLocation();
441 mPMHostUtils.setDevicePreferredInstallLocation(
442 PackageManagerHostTestUtils.InstallLocPreference.AUTO);
Neal Nguyen70df9ba2010-03-24 19:15:31 -0700443 mPMHostUtils.installAppAndVerifyExistsOnDevice(
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700444 getTestAppFilePath(NO_LOC_APK), NO_LOC_PKG, false);
445 }
446 // cleanup test app
447 finally {
448 mPMHostUtils.setDevicePreferredInstallLocation(savedPref);
449 mPMHostUtils.uninstallApp(NO_LOC_PKG);
450 }
451 }
452
453 /**
454 * Regression test to verify that an app without installLocation in its manifest
455 * will install the app to the device by default when the system default pref is to install
456 * external.
457 * <p/>
458 * Assumes adb is running as root in device under test.
459 * @throws IOException if adb shell command failed
460 * @throws InterruptedException if the thread was interrupted
461 */
462 public void testInstallAppNoLocPrefIsExternal() throws IOException, InterruptedException {
463 Log.i(LOG_TAG, "Test an app with no installLocation gets installed on SD card");
464
465 PackageManagerHostTestUtils.InstallLocPreference savedPref =
466 PackageManagerHostTestUtils.InstallLocPreference.AUTO;
467
468 try {
469 savedPref = mPMHostUtils.getDevicePreferredInstallLocation();
470 mPMHostUtils.setDevicePreferredInstallLocation(
471 PackageManagerHostTestUtils.InstallLocPreference.EXTERNAL);
472 mPMHostUtils.installAppAndVerifyExistsOnSDCard(
473 getTestAppFilePath(NO_LOC_APK), NO_LOC_PKG, false);
474 }
475 // cleanup test app
476 finally {
477 mPMHostUtils.setDevicePreferredInstallLocation(savedPref);
478 mPMHostUtils.uninstallApp(NO_LOC_PKG);
479 }
480 }
481
482 /**
483 * Regression test to verify that an app without installLocation in its manifest
484 * will install the app to the device by default when the system default pref is to install
485 * internal.
486 * <p/>
487 * Assumes adb is running as root in device under test.
488 * @throws IOException if adb shell command failed
489 * @throws InterruptedException if the thread was interrupted
490 */
491 public void testInstallAppNoLocPrefIsInternal() throws IOException, InterruptedException {
492 Log.i(LOG_TAG, "Test an app with no installLocation gets installed on device");
493
494 PackageManagerHostTestUtils.InstallLocPreference savedPref =
495 PackageManagerHostTestUtils.InstallLocPreference.AUTO;
496
497 try {
498 savedPref = mPMHostUtils.getDevicePreferredInstallLocation();
499 mPMHostUtils.setDevicePreferredInstallLocation(
500 PackageManagerHostTestUtils.InstallLocPreference.INTERNAL);
501 mPMHostUtils.installAppAndVerifyExistsOnDevice(
502 getTestAppFilePath(NO_LOC_APK), NO_LOC_PKG, false);
503 }
504 // cleanup test app
505 finally {
506 mPMHostUtils.setDevicePreferredInstallLocation(savedPref);
507 mPMHostUtils.uninstallApp(NO_LOC_PKG);
508 }
509 }
510
511 /**
512 * Regression test to verify that an app with its installLocation set to internal that is
513 * forward-locked will get installed to the correct location.
514 * <p/>
515 * Assumes adb is running as root in device under test.
516 * @throws IOException if adb shell command failed
517 * @throws InterruptedException if the thread was interrupted
518 */
519 public void testInstallFwdLockedAppInternal() throws IOException, InterruptedException {
520 Log.i(LOG_TAG, "Test an app with installLoc set to Internal gets installed to app-private");
521
522 try {
523 mPMHostUtils.installFwdLockedAppAndVerifyExists(
Neal Nguyen70df9ba2010-03-24 19:15:31 -0700524 getTestAppFilePath(INTERNAL_LOC_APK), INTERNAL_LOC_PKG, false);
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700525 }
526 // cleanup test app
527 finally {
Neal Nguyen70df9ba2010-03-24 19:15:31 -0700528 mPMHostUtils.uninstallApp(INTERNAL_LOC_PKG);
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700529 }
530 }
531
532 /**
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700533 * Regression test to verify that an app with its installLocation set to external that is
534 * forward-locked will get installed to the correct location.
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700535 * <p/>
536 * Assumes adb is running as root in device under test.
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700537 * @throws IOException if adb shell command failed
538 * @throws InterruptedException if the thread was interrupted
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700539 */
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700540 public void testInstallFwdLockedAppExternal() throws IOException, InterruptedException {
541 Log.i(LOG_TAG, "Test an app with installLoc set to Internal gets installed to app-private");
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700542
543 try {
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700544 mPMHostUtils.installFwdLockedAppAndVerifyExists(
545 getTestAppFilePath(INTERNAL_LOC_APK), INTERNAL_LOC_PKG, false);
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700546 }
547 // cleanup test app
548 finally {
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700549 mPMHostUtils.uninstallApp(INTERNAL_LOC_PKG);
550 }
551 }
552
553 /**
554 * Regression test to verify that an app with its installLocation set to external that is
555 * forward-locked will get installed to the correct location.
556 * <p/>
557 * Assumes adb is running as root in device under test.
558 * @throws IOException if adb shell command failed
559 * @throws InterruptedException if the thread was interrupted
560 */
561 public void testInstallFwdLockedAppAuto() throws IOException, InterruptedException {
562 Log.i(LOG_TAG, "Test an app with installLoc set to Auto gets installed to app-private");
563
564 try {
565 mPMHostUtils.installFwdLockedAppAndVerifyExists(
566 getTestAppFilePath(AUTO_LOC_APK), AUTO_LOC_PKG, false);
567 }
568 // cleanup test app
569 finally {
570 mPMHostUtils.uninstallApp(AUTO_LOC_PKG);
571 }
572 }
573
574 /**
575 * Regression test to verify that an app with no installLocation set and is
576 * forward-locked installed will get installed to the correct location.
577 * <p/>
578 * Assumes adb is running as root in device under test.
579 * @throws IOException if adb shell command failed
580 * @throws InterruptedException if the thread was interrupted
581 */
582 public void testInstallFwdLockedAppNone() throws IOException, InterruptedException {
583 Log.i(LOG_TAG, "Test an app with no installLoc set gets installed to app-private");
584
585 try {
586 mPMHostUtils.installFwdLockedAppAndVerifyExists(
587 getTestAppFilePath(NO_LOC_APK), NO_LOC_PKG, false);
588 }
589 // cleanup test app
590 finally {
591 mPMHostUtils.uninstallApp(NO_LOC_PKG);
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700592 }
593 }
594
595 /**
596 * Regression test to verify that we can install an app onto the device,
597 * uninstall it, and reinstall it onto the SD card.
598 * <p/>
599 * Assumes adb is running as root in device under test.
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700600 * @throws IOException if adb shell command failed
601 * @throws InterruptedException if the thread was interrupted
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700602 */
603 // TODO: This currently relies on the app's manifest to switch from device to
604 // SD card install locations. We might want to make Device's installPackage()
605 // accept a installLocation flag so we can install a package to the
606 // destination of our choosing.
607 public void testReinstallInternalToExternal() throws IOException, InterruptedException {
608 Log.i(LOG_TAG, "Test installing an app first to the device, then to the SD Card");
609
610 try {
Neal Nguyen70df9ba2010-03-24 19:15:31 -0700611 mPMHostUtils.installAppAndVerifyExistsOnDevice(
612 getTestAppFilePath(VERSATILE_LOC_INTERNAL_APK), VERSATILE_LOC_PKG, false);
613 mPMHostUtils.uninstallApp(VERSATILE_LOC_PKG);
614 mPMHostUtils.installAppAndVerifyExistsOnSDCard(
615 getTestAppFilePath(VERSATILE_LOC_EXTERNAL_APK), VERSATILE_LOC_PKG, false);
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700616 }
617 // cleanup test app
618 finally {
Neal Nguyen70df9ba2010-03-24 19:15:31 -0700619 mPMHostUtils.uninstallApp(VERSATILE_LOC_PKG);
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700620 }
621 }
622
623 /**
624 * Regression test to verify that we can install an app onto the SD Card,
625 * uninstall it, and reinstall it onto the device.
626 * <p/>
627 * Assumes adb is running as root in device under test.
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700628 * @throws IOException if adb shell command failed
629 * @throws InterruptedException if the thread was interrupted
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700630 */
631 // TODO: This currently relies on the app's manifest to switch from device to
632 // SD card install locations. We might want to make Device's installPackage()
633 // accept a installLocation flag so we can install a package to the
634 // destination of our choosing.
635 public void testReinstallExternalToInternal() throws IOException, InterruptedException {
636 Log.i(LOG_TAG, "Test installing an app first to the SD Care, then to the device");
637
638 try {
639 // install the app externally
Neal Nguyen70df9ba2010-03-24 19:15:31 -0700640 mPMHostUtils.installAppAndVerifyExistsOnSDCard(
641 getTestAppFilePath(VERSATILE_LOC_EXTERNAL_APK), VERSATILE_LOC_PKG, false);
642 mPMHostUtils.uninstallApp(VERSATILE_LOC_PKG);
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700643 // then replace the app with one marked for internalOnly
Neal Nguyen70df9ba2010-03-24 19:15:31 -0700644 mPMHostUtils.installAppAndVerifyExistsOnDevice(
645 getTestAppFilePath(VERSATILE_LOC_INTERNAL_APK), VERSATILE_LOC_PKG, false);
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700646 }
647 // cleanup test app
648 finally {
Neal Nguyen70df9ba2010-03-24 19:15:31 -0700649 mPMHostUtils.uninstallApp(VERSATILE_LOC_PKG);
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700650 }
651 }
652
653 /**
654 * Regression test to verify that updating an app on the SD card will install
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700655 * the update onto the SD card as well when location is set to external for both versions
656 * <p/>
657 * Assumes adb is running as root in device under test.
658 * @throws IOException if adb shell command failed
659 * @throws InterruptedException if the thread was interrupted
660 */
661 public void testUpdateBothExternal() throws IOException, InterruptedException {
662 Log.i(LOG_TAG, "Test updating an app on the SD card stays on the SD card");
663
664 try {
665 // install the app externally
666 mPMHostUtils.installAppAndVerifyExistsOnSDCard(getTestAppFilePath(
667 EXTERNAL_LOC_VERSION_V1_APK), EXTERNAL_LOC_VERSION_PKG, false);
668 // now replace the app with one where the location is still set to preferExternal
669 mPMHostUtils.installAppAndVerifyExistsOnSDCard(getTestAppFilePath(
670 EXTERNAL_LOC_VERSION_V2_APK), EXTERNAL_LOC_VERSION_PKG, true);
671 }
672 // cleanup test app
673 finally {
674 mPMHostUtils.uninstallApp(EXTERNAL_LOC_VERSION_PKG);
675 }
676 }
677
678 /**
679 * Regression test to verify that updating an app on the SD card will install
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700680 * the update onto the SD card as well when location is not explicitly set in the
681 * updated apps' manifest file.
682 * <p/>
683 * Assumes adb is running as root in device under test.
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700684 * @throws IOException if adb shell command failed
685 * @throws InterruptedException if the thread was interrupted
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700686 */
687 public void testUpdateToSDCard() throws IOException, InterruptedException {
688 Log.i(LOG_TAG, "Test updating an app on the SD card stays on the SD card");
689
690 try {
691 // install the app externally
Neal Nguyen70df9ba2010-03-24 19:15:31 -0700692 mPMHostUtils.installAppAndVerifyExistsOnSDCard(getTestAppFilePath(
693 UPDATE_EXTERNAL_LOC_V1_EXT_APK), UPDATE_EXTERNAL_LOC_PKG, false);
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700694 // now replace the app with one where the location is blank (app should stay external)
Neal Nguyen70df9ba2010-03-24 19:15:31 -0700695 mPMHostUtils.installAppAndVerifyExistsOnSDCard(getTestAppFilePath(
696 UPDATE_EXTERNAL_LOC_V2_NONE_APK), UPDATE_EXTERNAL_LOC_PKG, true);
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700697 }
698 // cleanup test app
699 finally {
Neal Nguyen70df9ba2010-03-24 19:15:31 -0700700 mPMHostUtils.uninstallApp(UPDATE_EXTERNAL_LOC_PKG);
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700701 }
702 }
703
704 /**
705 * Regression test to verify that updating an app on the SD card will install
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700706 * the update onto the device if the manifest has changed to installLocation=internalOnly
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700707 * <p/>
708 * Assumes adb is running as root in device under test.
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700709 * @throws IOException if adb shell command failed
710 * @throws InterruptedException if the thread was interrupted
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700711 */
712 public void testUpdateSDCardToDevice() throws IOException, InterruptedException {
713 Log.i(LOG_TAG, "Test updating an app on the SD card to the Device through manifest change");
714
715 try {
716 // install the app externally
Neal Nguyen70df9ba2010-03-24 19:15:31 -0700717 mPMHostUtils.installAppAndVerifyExistsOnSDCard(getTestAppFilePath(
718 UPDATE_EXT_TO_INT_LOC_V1_EXT_APK), UPDATE_EXT_TO_INT_LOC_PKG, false);
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700719 // now replace the app with an update marked for internalOnly...(should move internal)
Neal Nguyen70df9ba2010-03-24 19:15:31 -0700720 mPMHostUtils.installAppAndVerifyExistsOnDevice(getTestAppFilePath(
721 UPDATE_EXT_TO_INT_LOC_V2_INT_APK), UPDATE_EXT_TO_INT_LOC_PKG, true);
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700722 }
723 // cleanup test app
724 finally {
Neal Nguyen70df9ba2010-03-24 19:15:31 -0700725 mPMHostUtils.uninstallApp(UPDATE_EXT_TO_INT_LOC_PKG);
Neal Nguyen7cbb92d2010-03-22 13:14:25 -0700726 }
727 }
Neal Nguyenb1fb5c32010-03-31 16:45:01 -0700728
729 /**
730 * Regression test to verify that installing and updating a forward-locked app will install
731 * the update onto the device's forward-locked location
732 * <p/>
733 * Assumes adb is running as root in device under test.
734 * @throws IOException if adb shell command failed
735 * @throws InterruptedException if the thread was interrupted
736 */
737 public void testInstallAndUpdateExternalLocForwardLockedApp()
738 throws IOException, InterruptedException {
739 Log.i(LOG_TAG, "Test updating a forward-locked app marked preferExternal");
740
741 try {
742 // first try to install the forward-locked app externally
743 mPMHostUtils.installFwdLockedAppAndVerifyExists(getTestAppFilePath(
744 EXTERNAL_LOC_VERSION_V1_APK), EXTERNAL_LOC_VERSION_PKG, false);
745 // now replace the app with an update marked for internalOnly and as forward locked
746 mPMHostUtils.installFwdLockedAppAndVerifyExists(getTestAppFilePath(
747 EXTERNAL_LOC_VERSION_V2_APK), EXTERNAL_LOC_VERSION_PKG, true);
748 }
749 // cleanup test app
750 finally {
751 mPMHostUtils.uninstallApp(EXTERNAL_LOC_VERSION_PKG);
752 }
753 }
754
755 /**
756 * Regression test to verify that updating a forward-locked app will install
757 * the update onto the device's forward-locked location
758 * <p/>
759 * Assumes adb is running as root in device under test.
760 * @throws IOException if adb shell command failed
761 * @throws InterruptedException if the thread was interrupted
762 */
763 public void testInstallAndUpdateNoLocForwardLockedApp()
764 throws IOException, InterruptedException {
765 Log.i(LOG_TAG, "Test updating a forward-locked app with no installLocation pref set");
766
767 try {
768 // install the app
769 mPMHostUtils.installFwdLockedAppAndVerifyExists(getTestAppFilePath(
770 NO_LOC_VERSION_V1_APK), NO_LOC_VERSION_PKG, false);
771 // now replace the app with an update marked for internalOnly...
772 mPMHostUtils.installFwdLockedAppAndVerifyExists(getTestAppFilePath(
773 NO_LOC_VERSION_V2_APK), NO_LOC_VERSION_PKG, true);
774 }
775 // cleanup test app
776 finally {
777 mPMHostUtils.uninstallApp(NO_LOC_VERSION_PKG);
778 }
779 }
780
781 /**
782 * Regression test to verify that an app with all permissions set can be installed on SD card
783 * and then launched without crashing.
784 * <p/>
785 * Assumes adb is running as root in device under test.
786 * @throws IOException if adb shell command failed
787 * @throws InterruptedException if the thread was interrupted
788 */
789 public void testInstallAndLaunchAllPermsAppOnSD()
790 throws IOException, InterruptedException {
791 Log.i(LOG_TAG, "Test launching an app with all perms set, installed on SD card");
792
793 try {
794 // install the app
795 mPMHostUtils.installAppAndVerifyExistsOnSDCard(getTestAppFilePath(
796 ALL_PERMS_APK), ALL_PERMS_PKG, false);
797 boolean testsPassed = mPMHostUtils.runDeviceTestsDidAllTestsPass(ALL_PERMS_PKG);
798 assert(testsPassed);
799 }
800 // cleanup test app
801 finally {
802 mPMHostUtils.uninstallApp(ALL_PERMS_PKG);
803 }
804 }
805
806 /**
807 * Regression test to verify that an app with ACCESS_FINE_LOCATION (GPS) permissions can
808 * run without permissions errors.
809 * <p/>
810 * Assumes adb is running as root in device under test.
811 * @throws IOException if adb shell command failed
812 * @throws InterruptedException if the thread was interrupted
813 */
814 public void testInstallAndLaunchFLPermsAppOnSD()
815 throws IOException, InterruptedException {
816 Log.i(LOG_TAG, "Test launching an app with location perms set, installed on SD card");
817
818 try {
819 // install the app and verify we can launch it without permissions errors
820 mPMHostUtils.installAppAndVerifyExistsOnSDCard(getTestAppFilePath(
821 SHARED_PERMS_FL_APK), SHARED_PERMS_FL_PKG, false);
822 boolean testsPassed = mPMHostUtils.runDeviceTestsDidAllTestsPass(SHARED_PERMS_FL_PKG);
823 assert(testsPassed);
824 }
825 // cleanup test app
826 finally {
827 mPMHostUtils.uninstallApp(SHARED_PERMS_FL_PKG);
828 }
829 }
830
831 /**
832 * Regression test to verify that an app with BLUE_TOOTH permissions can
833 * run without permissions errors.
834 * <p/>
835 * Assumes adb is running as root in device under test.
836 * @throws IOException if adb shell command failed
837 * @throws InterruptedException if the thread was interrupted
838 */
839 public void testInstallAndLaunchBTPermsAppOnSD()
840 throws IOException, InterruptedException {
841 Log.i(LOG_TAG, "Test launching an app with bluetooth perms set, installed on SD card");
842
843 try {
844 // install the app and verify we can launch it without permissions errors
845 mPMHostUtils.installAppAndVerifyExistsOnSDCard(getTestAppFilePath(
846 SHARED_PERMS_BT_APK), SHARED_PERMS_BT_PKG, false);
847 boolean testsPassed = mPMHostUtils.runDeviceTestsDidAllTestsPass(SHARED_PERMS_BT_PKG);
848 assert(testsPassed);
849 }
850 // cleanup test app
851 finally {
852 mPMHostUtils.uninstallApp(SHARED_PERMS_BT_PKG);
853 }
854 }
855
856 /**
857 * Regression test to verify that a shared app with no explicit permissions throws a
858 * SecurityException when launched if its other shared apps are not installed.
859 * <p/>
860 * Assumes adb is running as root in device under test.
861 * @throws IOException if adb shell command failed
862 * @throws InterruptedException if the thread was interrupted
863 */
864 public void testInstallAndLaunchSharedPermsAppOnSD_NoPerms()
865 throws IOException, InterruptedException {
866 Log.i(LOG_TAG, "Test launching an app with no explicit perms set, installed on SD card");
867
868 try {
869 // Make sure the 2 shared apps with needed permissions are not installed...
870 mPMHostUtils.uninstallApp(SHARED_PERMS_FL_PKG);
871 mPMHostUtils.uninstallApp(SHARED_PERMS_BT_PKG);
872
873 // now install the app and see if when we launch it we get a permissions error
874 mPMHostUtils.installAppAndVerifyExistsOnSDCard(getTestAppFilePath(
875 SHARED_PERMS_APK), SHARED_PERMS_PKG, false);
876
877 boolean testsPassed = mPMHostUtils.runDeviceTestsDidAllTestsPass(SHARED_PERMS_PKG);
878 assertEquals("Shared perms app should fail to run", false, testsPassed);
879 }
880 // cleanup test app
881 finally {
882 mPMHostUtils.uninstallApp(SHARED_PERMS_PKG);
883 }
884 }
885
886 /**
887 * Regression test to verify that a shared app with no explicit permissions can run if its other
888 * shared apps are installed.
889 * <p/>
890 * Assumes adb is running as root in device under test.
891 * @throws IOException if adb shell command failed
892 * @throws InterruptedException if the thread was interrupted
893 */
894 public void testInstallAndLaunchSharedPermsAppOnSD_GrantedPerms()
895 throws IOException, InterruptedException {
896 Log.i(LOG_TAG, "Test launching an app with no explicit perms set, installed on SD card");
897
898 try {
899 // install the 2 shared apps with needed permissions first
900 mPMHostUtils.installAppAndVerifyExistsOnSDCard(getTestAppFilePath(
901 SHARED_PERMS_FL_APK), SHARED_PERMS_FL_PKG, false);
902 mPMHostUtils.installAppAndVerifyExistsOnSDCard(getTestAppFilePath(
903 SHARED_PERMS_BT_APK), SHARED_PERMS_BT_PKG, false);
904
905 // now install the test app and see if we can launch it without errors
906 mPMHostUtils.installAppAndVerifyExistsOnSDCard(getTestAppFilePath(
907 SHARED_PERMS_APK), SHARED_PERMS_PKG, false);
908 boolean testsPassed = mPMHostUtils.runDeviceTestsDidAllTestsPass(SHARED_PERMS_PKG);
909 assert(testsPassed);
910 }
911 // cleanup test app
912 finally {
913 mPMHostUtils.uninstallApp(SHARED_PERMS_PKG);
914 mPMHostUtils.uninstallApp(SHARED_PERMS_BT_PKG);
915 mPMHostUtils.uninstallApp(SHARED_PERMS_FL_PKG);
916 }
917 }
918
919 /**
920 * Regression test to verify that an app with ACCESS_FINE_LOCATION (GPS) permissions can
921 * run without permissions errors even after a reboot
922 * <p/>
923 * Assumes adb is running as root in device under test.
924 * @throws IOException if adb shell command failed
925 * @throws InterruptedException if the thread was interrupted
926 */
927 public void testInstallAndLaunchFLPermsAppOnSD_Reboot()
928 throws IOException, InterruptedException {
929 Log.i(LOG_TAG, "Test launching an app with location perms set, installed on SD card");
930
931 try {
932 // install the app and verify we can launch it without permissions errors
933 mPMHostUtils.installAppAndVerifyExistsOnSDCard(getTestAppFilePath(
934 SHARED_PERMS_FL_APK), SHARED_PERMS_FL_PKG, false);
935 boolean testsPassed = mPMHostUtils.runDeviceTestsDidAllTestsPass(SHARED_PERMS_FL_PKG);
936 assert(testsPassed);
937
938 mPMHostUtils.rebootDevice();
939
940 testsPassed = mPMHostUtils.runDeviceTestsDidAllTestsPass(SHARED_PERMS_FL_PKG);
941 assert(testsPassed);
942 }
943 // cleanup test app
944 finally {
945 mPMHostUtils.uninstallApp(SHARED_PERMS_FL_PKG);
946 }
947 }
948
949 /**
950 * Regression test to verify that a shared app with no explicit permissions can run if its other
951 * shared apps are installed, even after a reboot.
952 * <p/>
953 * Assumes adb is running as root in device under test.
954 * @throws IOException if adb shell command failed
955 * @throws InterruptedException if the thread was interrupted
956 */
957 public void testInstallAndLaunchSharedPermsAppOnSD_Reboot()
958 throws IOException, InterruptedException {
959 Log.i(LOG_TAG, "Test launching an app on SD, with no explicit perms set after reboot");
960
961 try {
962 // install the 2 shared apps with needed permissions first
963 mPMHostUtils.installAppAndVerifyExistsOnSDCard(getTestAppFilePath(
964 SHARED_PERMS_FL_APK), SHARED_PERMS_FL_PKG, false);
965 mPMHostUtils.installAppAndVerifyExistsOnSDCard(getTestAppFilePath(
966 SHARED_PERMS_BT_APK), SHARED_PERMS_BT_PKG, false);
967
968 // now install the test app and see if we can launch it without errors
969 mPMHostUtils.installAppAndVerifyExistsOnSDCard(getTestAppFilePath(
970 SHARED_PERMS_APK), SHARED_PERMS_PKG, false);
971 boolean testsPassed = mPMHostUtils.runDeviceTestsDidAllTestsPass(SHARED_PERMS_PKG);
972 assert(testsPassed);
973
974 // reboot
975 mPMHostUtils.rebootDevice();
976
977 // Verify we can still launch the app
978 testsPassed = mPMHostUtils.runDeviceTestsDidAllTestsPass(SHARED_PERMS_PKG);
979 assert(testsPassed);
980 }
981 // cleanup test app
982 finally {
983 mPMHostUtils.uninstallApp(SHARED_PERMS_PKG);
984 mPMHostUtils.uninstallApp(SHARED_PERMS_BT_PKG);
985 mPMHostUtils.uninstallApp(SHARED_PERMS_FL_PKG);
986 }
987 }
Brett Chabotcb2003a2010-02-17 11:18:16 -0800988}