1 /* 2 * Copyright (C) 2012 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.tradefed.config.Option; 20 import com.android.tradefed.config.Option.Importance; 21 import com.android.tradefed.device.DeviceNotAvailableException; 22 import com.android.tradefed.log.LogUtil.CLog; 23 import com.android.tradefed.testtype.DeviceTestCase; 24 import com.android.tradefed.util.FileUtil; 25 26 import java.io.File; 27 28 public class PackageManagerOTATests extends DeviceTestCase { 29 30 @Option( 31 name = "test-app-path", 32 description = "path to the app repository containing test apks", 33 importance = Importance.IF_UNSET) 34 private File mTestAppRepositoryPath = null; 35 36 @Option( 37 name = "use-priv-path", 38 description = 39 "set to true if the special priviledged app directory should be used; default is false", 40 importance = Importance.IF_UNSET) 41 private boolean mUsePrivAppDirectory = false; 42 43 private PackageManagerOTATestUtils mUtils = null; 44 private String mSystemAppPath = "/system/app/version_test.apk"; 45 private String mDiffSystemAppPath = "/system/app/version_test_diff.apk"; 46 47 // String constants use for the tests. 48 private static final String PACKAGE_XPATH = 49 "/packages/package[@name=\"" + "com.android.frameworks.coretests.version_test\"]"; 50 private static final String UPDATE_PACKAGE_XPATH = 51 "/packages/updated-package[@name=\"" 52 + "com.android.frameworks.coretests.version_test\"]"; 53 private static final String VERSION_XPATH = 54 "/packages/package[@name=\"" 55 + "com.android.frameworks.coretests.version_test\"]/@version"; 56 private static final String CODE_PATH_XPATH = 57 "/packages/package[@name=\"" 58 + "com.android.frameworks.coretests.version_test\"]/@codePath"; 59 private static final String VERSION_1_APK = "FrameworkCoreTests_version_1.apk"; 60 private static final String VERSION_2_APK = "FrameworkCoreTests_version_2.apk"; 61 private static final String VERSION_3_APK = "FrameworkCoreTests_version_3.apk"; 62 private static final String VERSION_1_NO_SYS_PERMISSION_APK = 63 "FrameworkCoreTests_version_1_nosys.apk"; 64 private static final String DATA_APP_DIRECTORY = "/data/app/"; 65 private static final String PACKAGE_NAME = "com.android.frameworks.coretests.version_test"; 66 private static final String VIBRATE_PERMISSION = "android.permission.VIBRATE"; 67 private static final String CACHE_PERMISSION = "android.permission.ACCESS_CACHE_FILESYSTEM"; 68 69 // Temporary file used when examine the packages xml file from the device. 70 private File mPackageXml = null; 71 72 @Override setUp()73 protected void setUp() throws Exception { 74 super.setUp(); 75 mUtils = new PackageManagerOTATestUtils(getDevice()); 76 77 if (mUsePrivAppDirectory) { 78 mSystemAppPath = "/system/priv-app/version_test.apk"; 79 mDiffSystemAppPath = "/system/priv-app/version_test_diff.apk"; 80 } 81 82 // Clean up any potential old files from previous tests. 83 // delete from /system if exists 84 getDevice().enableAdbRoot(); 85 mUtils.removeSystemApp(mSystemAppPath, false); 86 mUtils.removeSystemApp(mDiffSystemAppPath, false); 87 mUtils.restartSystem(); 88 // delete from /data if there is one 89 getDevice().uninstallPackage(PACKAGE_NAME); 90 91 String res = getDevice().executeShellCommand("pm path " + PACKAGE_NAME).trim(); 92 assertTrue("Package should not be installed before test", res.isEmpty()); 93 } 94 95 @Override tearDown()96 protected void tearDown() throws Exception { 97 // Clean up. 98 if (mPackageXml != null) { 99 FileUtil.deleteFile(mPackageXml); 100 } 101 } 102 103 /** 104 * Get the absolute file system location of test app with given filename 105 * 106 * @param fileName the file name of the test app apk 107 * @return {@link String} of absolute file path 108 */ getTestAppFilePath(String fileName)109 public File getTestAppFilePath(String fileName) { 110 // need to check both data/app/apkFileName and 111 // data/app/apkFileName/apkFileName 112 File file = FileUtil.getFileForPath(mTestAppRepositoryPath, fileName); 113 if (file.exists()) { 114 return file; 115 } 116 117 int index = fileName.lastIndexOf('.'); 118 String dir = fileName.substring(0, index); 119 file = FileUtil.getFileForPath(mTestAppRepositoryPath, dir, fileName); 120 CLog.d("Test path : %s", file.getAbsolutePath()); 121 return file; 122 } 123 124 /** 125 * Test case when system app added is newer than update. 126 * 127 * <p>Assumes adb is running as root in device under test. 128 * 129 * @throws DeviceNotAvailableException 130 */ testSystemAppAddedNewerThanUpdate()131 public void testSystemAppAddedNewerThanUpdate() throws DeviceNotAvailableException { 132 mUtils.installFile(getTestAppFilePath(VERSION_1_APK), true); 133 mPackageXml = mUtils.pullPackagesXML(); 134 assertNotNull("Failed to pull packages xml file from device", mPackageXml); 135 assertTrue( 136 "Initial package should be installed", 137 mUtils.expectExists(mPackageXml, PACKAGE_XPATH)); 138 assertTrue( 139 "Package version should be 1", 140 mUtils.expectEquals(mPackageXml, VERSION_XPATH, "1")); 141 assertFalse( 142 "Updated-package should not be present", 143 mUtils.expectExists(mPackageXml, UPDATE_PACKAGE_XPATH)); 144 assertFalse( 145 "Package should not have FLAG_SYSTEM", 146 mUtils.packageHasFlag(PACKAGE_NAME, " SYSTEM ")); 147 assertTrue( 148 "VIBRATE permission should be granted", 149 mUtils.packageHasPermission(PACKAGE_NAME, VIBRATE_PERMISSION)); 150 assertFalse( 151 "ACCESS_CACHE_FILESYSTEM permission should NOT be granted", 152 mUtils.packageHasPermission(PACKAGE_NAME, CACHE_PERMISSION)); 153 154 mUtils.pushSystemApp(getTestAppFilePath(VERSION_2_APK), mSystemAppPath); 155 mPackageXml = mUtils.pullPackagesXML(); 156 assertTrue( 157 "After system app push, package should still be installed", 158 mUtils.expectExists(mPackageXml, PACKAGE_XPATH)); 159 assertTrue( 160 "After system app push, system app should be visible", 161 mUtils.expectEquals(mPackageXml, VERSION_XPATH, "2")); 162 assertFalse( 163 "Updated-package should not be present", 164 mUtils.expectExists(mPackageXml, UPDATE_PACKAGE_XPATH)); 165 assertTrue( 166 "Package should have FLAG_SYSTEM", mUtils.packageHasFlag(PACKAGE_NAME, " SYSTEM ")); 167 assertTrue( 168 "VIBRATE permission should be granted", 169 mUtils.packageHasPermission(PACKAGE_NAME, VIBRATE_PERMISSION)); 170 assertTrue( 171 "ACCESS_CACHE_FILESYSTEM permission should be granted", 172 mUtils.packageHasPermission(PACKAGE_NAME, CACHE_PERMISSION)); 173 } 174 175 /** 176 * Test case when system app added is older than update. 177 * 178 * <p>Assumes adb is running as root in device under test. 179 * 180 * @throws DeviceNotAvailableException 181 */ testSystemAppAddedOlderThanUpdate()182 public void testSystemAppAddedOlderThanUpdate() throws DeviceNotAvailableException { 183 mUtils.installFile(getTestAppFilePath(VERSION_2_APK), true); 184 mPackageXml = mUtils.pullPackagesXML(); 185 assertNotNull("Failed to pull packages xml file from device", mPackageXml); 186 assertTrue( 187 "Initial package should be installed", 188 mUtils.expectExists(mPackageXml, PACKAGE_XPATH)); 189 assertTrue( 190 "Package version should be 2", 191 mUtils.expectEquals(mPackageXml, VERSION_XPATH, "2")); 192 assertFalse( 193 "Updated-package should not be present", 194 mUtils.expectExists(mPackageXml, UPDATE_PACKAGE_XPATH)); 195 assertFalse( 196 "Package should not have FLAG_SYSTEM", 197 mUtils.packageHasFlag(PACKAGE_NAME, " SYSTEM ")); 198 assertTrue( 199 "VIBRATE permission should be granted", 200 mUtils.packageHasPermission(PACKAGE_NAME, VIBRATE_PERMISSION)); 201 assertFalse( 202 "ACCESS_CACHE_FILESYSTEM permission should NOT be granted", 203 mUtils.packageHasPermission(PACKAGE_NAME, CACHE_PERMISSION)); 204 205 mUtils.pushSystemApp(getTestAppFilePath(VERSION_1_APK), mSystemAppPath); 206 mPackageXml = mUtils.pullPackagesXML(); 207 assertTrue( 208 "After system app push, package should still be installed", 209 mUtils.expectExists(mPackageXml, PACKAGE_XPATH)); 210 assertTrue( 211 "After system app push, system app should be visible", 212 mUtils.expectEquals(mPackageXml, VERSION_XPATH, "2")); 213 assertTrue( 214 "Updated-package should be present", 215 mUtils.expectExists(mPackageXml, UPDATE_PACKAGE_XPATH)); 216 assertTrue( 217 "Package should have FLAG_SYSTEM", mUtils.packageHasFlag(PACKAGE_NAME, " SYSTEM ")); 218 assertTrue( 219 "VIBRATE permission should be granted", 220 mUtils.packageHasPermission(PACKAGE_NAME, VIBRATE_PERMISSION)); 221 assertTrue( 222 "ACCESS_CACHE_FILESYSTEM permission should be granted", 223 mUtils.packageHasPermission(PACKAGE_NAME, CACHE_PERMISSION)); 224 } 225 226 /** 227 * Test when system app gets removed. 228 * 229 * <p>Assumes adb is running as root in device under test. 230 * 231 * @throws DeviceNotAvailableException 232 */ testSystemAppRemoved()233 public void testSystemAppRemoved() throws DeviceNotAvailableException { 234 mUtils.pushSystemApp(getTestAppFilePath(VERSION_1_APK), mSystemAppPath); 235 mPackageXml = mUtils.pullPackagesXML(); 236 assertTrue( 237 "Initial package should be installed", 238 mUtils.expectExists(mPackageXml, PACKAGE_XPATH)); 239 assertTrue( 240 "Package should have FLAG_SYSTEM", mUtils.packageHasFlag(PACKAGE_NAME, " SYSTEM ")); 241 assertFalse( 242 "Updated-package should not be present", 243 mUtils.expectExists(mPackageXml, UPDATE_PACKAGE_XPATH)); 244 mUtils.removeSystemApp(mSystemAppPath, true); 245 mPackageXml = mUtils.pullPackagesXML(); 246 assertFalse( 247 "Package should not be installed", mUtils.expectExists(mPackageXml, PACKAGE_XPATH)); 248 assertFalse( 249 "Updated-package should not be present", 250 mUtils.expectExists(mPackageXml, UPDATE_PACKAGE_XPATH)); 251 } 252 253 /** 254 * Test when update has a newer version. 255 * 256 * <p>Assumes adb is running as root in device under test. 257 * 258 * @throws DeviceNotAvailableException 259 */ testSystemAppUpdatedNewerVersion()260 public void testSystemAppUpdatedNewerVersion() throws DeviceNotAvailableException { 261 mUtils.pushSystemApp(getTestAppFilePath(VERSION_2_APK), mSystemAppPath); 262 mPackageXml = mUtils.pullPackagesXML(); 263 assertTrue( 264 "The package should be installed", mUtils.expectExists(mPackageXml, PACKAGE_XPATH)); 265 assertTrue( 266 "Package version should be 2", 267 mUtils.expectEquals(mPackageXml, VERSION_XPATH, "2")); 268 assertFalse( 269 "Updated-package should not be present", 270 mUtils.expectExists(mPackageXml, UPDATE_PACKAGE_XPATH)); 271 assertTrue( 272 "Package should have FLAG_SYSTEM", mUtils.packageHasFlag(PACKAGE_NAME, " SYSTEM ")); 273 assertTrue( 274 "VIBRATE permission should be granted", 275 mUtils.packageHasPermission(PACKAGE_NAME, VIBRATE_PERMISSION)); 276 assertTrue( 277 "ACCESS_CACHE_FILESYSTEM permission should be granted", 278 mUtils.packageHasPermission(PACKAGE_NAME, CACHE_PERMISSION)); 279 280 mUtils.installFile(getTestAppFilePath(VERSION_3_APK), true); 281 mPackageXml = mUtils.pullPackagesXML(); 282 assertFalse( 283 "After system app upgrade, the path should be the upgraded app on /data", 284 mUtils.expectEquals(mPackageXml, CODE_PATH_XPATH, mSystemAppPath)); 285 assertTrue( 286 "Package version should be 3", 287 mUtils.expectEquals(mPackageXml, VERSION_XPATH, "3")); 288 assertTrue( 289 "Updated-package should be present", 290 mUtils.expectExists(mPackageXml, UPDATE_PACKAGE_XPATH)); 291 assertTrue( 292 "Package should have FLAG_SYSTEM", mUtils.packageHasFlag(PACKAGE_NAME, " SYSTEM ")); 293 assertTrue( 294 "VIBRATE permission should be granted", 295 mUtils.packageHasPermission(PACKAGE_NAME, VIBRATE_PERMISSION)); 296 assertTrue( 297 "ACCESS_CACHE_FILESYSTEM permission should be granted", 298 mUtils.packageHasPermission(PACKAGE_NAME, CACHE_PERMISSION)); 299 300 mUtils.restartSystem(); 301 mPackageXml = mUtils.pullPackagesXML(); 302 assertFalse( 303 "After system app upgrade, the path should be the upgraded app on /data", 304 mUtils.expectEquals(mPackageXml, CODE_PATH_XPATH, mSystemAppPath)); 305 assertTrue( 306 "Package version should be 3", 307 mUtils.expectEquals(mPackageXml, VERSION_XPATH, "3")); 308 assertTrue( 309 "Updated-package should be present", 310 mUtils.expectExists(mPackageXml, UPDATE_PACKAGE_XPATH)); 311 assertTrue( 312 "Package should have FLAG_SYSTEM", mUtils.packageHasFlag(PACKAGE_NAME, " SYSTEM ")); 313 assertTrue( 314 "VIBRATE permission should be granted", 315 mUtils.packageHasPermission(PACKAGE_NAME, VIBRATE_PERMISSION)); 316 assertTrue( 317 "ACCESS_CACHE_FILESYSTEM permission should be granted", 318 mUtils.packageHasPermission(PACKAGE_NAME, CACHE_PERMISSION)); 319 320 mUtils.restartSystem(); 321 mPackageXml = mUtils.pullPackagesXML(); 322 assertFalse( 323 "After system app upgrade, the path should be the upgraded app on /data", 324 mUtils.expectEquals(mPackageXml, CODE_PATH_XPATH, mSystemAppPath)); 325 assertTrue( 326 "Package version should be 3", 327 mUtils.expectEquals(mPackageXml, VERSION_XPATH, "3")); 328 assertTrue( 329 "Updated-package should be present", 330 mUtils.expectExists(mPackageXml, UPDATE_PACKAGE_XPATH)); 331 assertTrue( 332 "Package should have FLAG_SYSTEM", mUtils.packageHasFlag(PACKAGE_NAME, " SYSTEM ")); 333 assertTrue( 334 "VIBRATE permission should be granted", 335 mUtils.packageHasPermission(PACKAGE_NAME, VIBRATE_PERMISSION)); 336 assertTrue( 337 "ACCESS_CACHE_FILESYSTEM permission should be granted", 338 mUtils.packageHasPermission(PACKAGE_NAME, CACHE_PERMISSION)); 339 } 340 341 /** 342 * Test when update has an older version. 343 * 344 * <p>Assumes adb is running as root in device under test. 345 * 346 * @throws DeviceNotAvailableException 347 */ testSystemAppUpdatedOlderVersion()348 public void testSystemAppUpdatedOlderVersion() throws DeviceNotAvailableException { 349 mUtils.pushSystemApp(getTestAppFilePath(VERSION_2_APK), mSystemAppPath); 350 mPackageXml = mUtils.pullPackagesXML(); 351 assertTrue( 352 "After system app push, the package should be installed", 353 mUtils.expectExists(mPackageXml, PACKAGE_XPATH)); 354 assertTrue( 355 "Package version should be 2", 356 mUtils.expectEquals(mPackageXml, VERSION_XPATH, "2")); 357 assertFalse( 358 "Updated-package should not be present", 359 mUtils.expectExists(mPackageXml, UPDATE_PACKAGE_XPATH)); 360 assertTrue( 361 "Package should have FLAG_SYSTEM", mUtils.packageHasFlag(PACKAGE_NAME, " SYSTEM ")); 362 assertTrue( 363 "VIBRATE permission should be granted", 364 mUtils.packageHasPermission(PACKAGE_NAME, VIBRATE_PERMISSION)); 365 assertTrue( 366 "ACCESS_CACHE_FILESYSTEM permission should be granted", 367 mUtils.packageHasPermission(PACKAGE_NAME, CACHE_PERMISSION)); 368 369 // The "-d" command forces a downgrade. 370 mUtils.installFile(getTestAppFilePath(VERSION_1_APK), true, "-d"); 371 mPackageXml = mUtils.pullPackagesXML(); 372 assertTrue( 373 "After system app upgrade, the path should be the upgraded app on /data", 374 mUtils.expectStartsWith( 375 mPackageXml, CODE_PATH_XPATH, DATA_APP_DIRECTORY + PACKAGE_NAME)); 376 assertTrue( 377 "Package version should be 1", 378 mUtils.expectEquals(mPackageXml, VERSION_XPATH, "1")); 379 assertTrue( 380 "Updated-package should be present", 381 mUtils.expectExists(mPackageXml, UPDATE_PACKAGE_XPATH)); 382 assertTrue( 383 "Package should have FLAG_SYSTEM", mUtils.packageHasFlag(PACKAGE_NAME, " SYSTEM ")); 384 assertTrue( 385 "VIBRATE permission should be granted", 386 mUtils.packageHasPermission(PACKAGE_NAME, VIBRATE_PERMISSION)); 387 assertTrue( 388 "ACCESS_CACHE_FILESYSTEM permission should be granted", 389 mUtils.packageHasPermission(PACKAGE_NAME, CACHE_PERMISSION)); 390 391 mUtils.restartSystem(); 392 mPackageXml = mUtils.pullPackagesXML(); 393 assertTrue( 394 "After reboot, the path should be the be installed", 395 mUtils.expectEquals(mPackageXml, CODE_PATH_XPATH, mSystemAppPath)); 396 assertTrue( 397 "Package version should be 2", 398 mUtils.expectEquals(mPackageXml, VERSION_XPATH, "2")); 399 assertFalse( 400 "Updated-package should NOT be present", 401 mUtils.expectExists(mPackageXml, UPDATE_PACKAGE_XPATH)); 402 assertTrue( 403 "Package should have FLAG_SYSTEM", mUtils.packageHasFlag(PACKAGE_NAME, " SYSTEM ")); 404 assertTrue( 405 "VIBRATE permission should be granted", 406 mUtils.packageHasPermission(PACKAGE_NAME, VIBRATE_PERMISSION)); 407 assertTrue( 408 "ACCESS_CACHE_FILESYSTEM permission should be granted", 409 mUtils.packageHasPermission(PACKAGE_NAME, CACHE_PERMISSION)); 410 411 mUtils.restartSystem(); 412 mPackageXml = mUtils.pullPackagesXML(); 413 assertTrue( 414 "After reboot, the path should be the be installed", 415 mUtils.expectEquals(mPackageXml, CODE_PATH_XPATH, mSystemAppPath)); 416 assertTrue( 417 "Package version should be 2", 418 mUtils.expectEquals(mPackageXml, VERSION_XPATH, "2")); 419 assertFalse( 420 "Updated-package should NOT be present", 421 mUtils.expectExists(mPackageXml, UPDATE_PACKAGE_XPATH)); 422 assertTrue( 423 "Package should have FLAG_SYSTEM", mUtils.packageHasFlag(PACKAGE_NAME, " SYSTEM ")); 424 assertTrue( 425 "VIBRATE permission should be granted", 426 mUtils.packageHasPermission(PACKAGE_NAME, VIBRATE_PERMISSION)); 427 assertTrue( 428 "ACCESS_CACHE_FILESYSTEM permission should be granted", 429 mUtils.packageHasPermission(PACKAGE_NAME, CACHE_PERMISSION)); 430 } 431 432 /** 433 * Test when updated system app has the same version. Package manager is expected to use the 434 * newly installed upgrade. 435 * 436 * <p>Assumes adb is running as root in device under test. 437 * 438 * @throws DeviceNotAvailableException 439 */ testSystemAppUpdatedSameVersion_PreferUpdatedApk()440 public void testSystemAppUpdatedSameVersion_PreferUpdatedApk() 441 throws DeviceNotAvailableException { 442 mUtils.pushSystemApp(getTestAppFilePath(VERSION_2_APK), mSystemAppPath); 443 mPackageXml = mUtils.pullPackagesXML(); 444 assertTrue( 445 "The package should be installed", mUtils.expectExists(mPackageXml, PACKAGE_XPATH)); 446 assertTrue( 447 "Package version should be 2", 448 mUtils.expectEquals(mPackageXml, VERSION_XPATH, "2")); 449 assertFalse( 450 "Updated-package should not be present", 451 mUtils.expectExists(mPackageXml, UPDATE_PACKAGE_XPATH)); 452 assertTrue( 453 "Package should have FLAG_SYSTEM", mUtils.packageHasFlag(PACKAGE_NAME, " SYSTEM ")); 454 assertTrue( 455 "VIBRATE permission should be granted", 456 mUtils.packageHasPermission(PACKAGE_NAME, VIBRATE_PERMISSION)); 457 assertTrue( 458 "ACCESS_CACHE_FILESYSTEM permission should be granted", 459 mUtils.packageHasPermission(PACKAGE_NAME, CACHE_PERMISSION)); 460 461 mUtils.installFile(getTestAppFilePath(VERSION_2_APK), true); 462 mPackageXml = mUtils.pullPackagesXML(); 463 assertFalse( 464 "After system app upgrade, the path should be the upgraded app in /data", 465 mUtils.expectEquals(mPackageXml, CODE_PATH_XPATH, mSystemAppPath)); 466 assertTrue( 467 "Package version should be 2", 468 mUtils.expectEquals(mPackageXml, VERSION_XPATH, "2")); 469 assertTrue( 470 "Updated-package should be present", 471 mUtils.expectExists(mPackageXml, UPDATE_PACKAGE_XPATH)); 472 assertTrue( 473 "Package should have FLAG_SYSTEM", mUtils.packageHasFlag(PACKAGE_NAME, " SYSTEM ")); 474 assertTrue( 475 "VIBRATE permission should be granted", 476 mUtils.packageHasPermission(PACKAGE_NAME, VIBRATE_PERMISSION)); 477 assertTrue( 478 "ACCESS_CACHE_FILESYSTEM permission should be granted", 479 mUtils.packageHasPermission(PACKAGE_NAME, CACHE_PERMISSION)); 480 481 mUtils.restartSystem(); 482 mPackageXml = mUtils.pullPackagesXML(); 483 assertFalse( 484 "After reboot, the path should be the upgraded app in /data", 485 mUtils.expectEquals(mPackageXml, CODE_PATH_XPATH, mSystemAppPath)); 486 assertTrue( 487 "Package version should be 2", 488 mUtils.expectEquals(mPackageXml, VERSION_XPATH, "2")); 489 assertTrue( 490 "Updated-package should be present", 491 mUtils.expectExists(mPackageXml, UPDATE_PACKAGE_XPATH)); 492 assertTrue( 493 "Package should have FLAG_SYSTEM", mUtils.packageHasFlag(PACKAGE_NAME, " SYSTEM ")); 494 assertTrue( 495 "VIBRATE permission should be granted", 496 mUtils.packageHasPermission(PACKAGE_NAME, VIBRATE_PERMISSION)); 497 assertTrue( 498 "ACCESS_CACHE_FILESYSTEM permission should be granted", 499 mUtils.packageHasPermission(PACKAGE_NAME, CACHE_PERMISSION)); 500 } 501 502 /** 503 * Test when update has system app removed. 504 * 505 * <p>Assumes adb is running as root in device under test. 506 * 507 * @throws DeviceNotAvailableException 508 */ testUpdatedSystemAppRemoved()509 public void testUpdatedSystemAppRemoved() throws DeviceNotAvailableException { 510 mUtils.pushSystemApp(getTestAppFilePath(VERSION_1_APK), mSystemAppPath); 511 mUtils.installFile(getTestAppFilePath(VERSION_2_APK), true); 512 mPackageXml = mUtils.pullPackagesXML(); 513 assertTrue("Package should be installed", mUtils.expectExists(mPackageXml, PACKAGE_XPATH)); 514 assertTrue( 515 "Updated-package should be present", 516 mUtils.expectExists(mPackageXml, UPDATE_PACKAGE_XPATH)); 517 assertTrue( 518 "Package should have FLAG_SYSTEM", mUtils.packageHasFlag(PACKAGE_NAME, " SYSTEM ")); 519 assertTrue( 520 "VIBRATE permission should be granted", 521 mUtils.packageHasPermission(PACKAGE_NAME, VIBRATE_PERMISSION)); 522 assertTrue( 523 "ACCESS_CACHE_FILESYSTEM permission should be granted", 524 mUtils.packageHasPermission(PACKAGE_NAME, CACHE_PERMISSION)); 525 526 mUtils.removeSystemApp(mSystemAppPath, true); 527 mPackageXml = mUtils.pullPackagesXML(); 528 assertTrue( 529 "Package should still be installed", 530 mUtils.expectExists(mPackageXml, PACKAGE_XPATH)); 531 assertFalse( 532 "Updated-package entry should not be present", 533 mUtils.expectExists(mPackageXml, UPDATE_PACKAGE_XPATH)); 534 assertFalse( 535 "Package should not have FLAG_SYSTEM", 536 mUtils.packageHasFlag(PACKAGE_NAME, " SYSTEM ")); 537 assertTrue( 538 "VIBRATE permission should be granted", 539 mUtils.packageHasPermission(PACKAGE_NAME, VIBRATE_PERMISSION)); 540 assertFalse( 541 "ACCESS_CACHE_FILESYSTEM permission should NOT be granted", 542 mUtils.packageHasPermission(PACKAGE_NAME, CACHE_PERMISSION)); 543 } 544 545 /** 546 * Test when system app is updated with a new permission. Specifically: 547 * 548 * <ol> 549 * <li>system app FOO is present, does not declare system permission 550 * <li>FOO is overlain by an installed update that declares new permission 551 * <li>FOO is replaced during an OTA, but installed update still has higher version number 552 * <li>Verify permission is granted 553 * </ol> 554 * 555 * @throws DeviceNotAvailableException 556 */ testSystemAppUpdatedNewPermission()557 public void testSystemAppUpdatedNewPermission() throws DeviceNotAvailableException { 558 mUtils.pushSystemApp(getTestAppFilePath(VERSION_1_NO_SYS_PERMISSION_APK), mSystemAppPath); 559 mPackageXml = mUtils.pullPackagesXML(); 560 assertTrue( 561 "The package should be installed", mUtils.expectExists(mPackageXml, PACKAGE_XPATH)); 562 assertTrue( 563 "Package version should be 1", 564 mUtils.expectEquals(mPackageXml, VERSION_XPATH, "1")); 565 assertFalse( 566 "Updated-package should not be present", 567 mUtils.expectExists(mPackageXml, UPDATE_PACKAGE_XPATH)); 568 assertTrue( 569 "Package should have FLAG_SYSTEM", mUtils.packageHasFlag(PACKAGE_NAME, " SYSTEM ")); 570 assertTrue( 571 "VIBRATE permission should be granted", 572 mUtils.packageHasPermission(PACKAGE_NAME, VIBRATE_PERMISSION)); 573 assertFalse( 574 "ACCESS_CACHE_FILESYSTEM permission should NOT be granted", 575 mUtils.packageHasPermission(PACKAGE_NAME, CACHE_PERMISSION)); 576 577 mUtils.installFile(getTestAppFilePath(VERSION_3_APK), true); 578 mPackageXml = mUtils.pullPackagesXML(); 579 assertFalse( 580 "After system app upgrade, the path should be the upgraded app on /data", 581 mUtils.expectEquals(mPackageXml, CODE_PATH_XPATH, mSystemAppPath)); 582 assertTrue( 583 "Package version should be 3", 584 mUtils.expectEquals(mPackageXml, VERSION_XPATH, "3")); 585 assertTrue( 586 "Updated-package should be present", 587 mUtils.expectExists(mPackageXml, UPDATE_PACKAGE_XPATH)); 588 assertTrue( 589 "Package should have FLAG_SYSTEM", mUtils.packageHasFlag(PACKAGE_NAME, " SYSTEM ")); 590 assertTrue( 591 "VIBRATE permission should be granted", 592 mUtils.packageHasPermission(PACKAGE_NAME, VIBRATE_PERMISSION)); 593 assertFalse( 594 "ACCESS_CACHE_FILESYSTEM permission should NOT be granted", 595 mUtils.packageHasPermission(PACKAGE_NAME, CACHE_PERMISSION)); 596 597 mUtils.pushSystemApp(getTestAppFilePath(VERSION_2_APK), mSystemAppPath); 598 mUtils.restartSystem(); 599 mPackageXml = mUtils.pullPackagesXML(); 600 assertFalse( 601 "After reboot, the path should be the data app", 602 mUtils.expectEquals(mPackageXml, CODE_PATH_XPATH, mSystemAppPath)); 603 assertTrue( 604 "Package version should be 3", 605 mUtils.expectEquals(mPackageXml, VERSION_XPATH, "3")); 606 assertTrue( 607 "Updated-package should be present", 608 mUtils.expectExists(mPackageXml, UPDATE_PACKAGE_XPATH)); 609 assertTrue( 610 "Package should have FLAG_SYSTEM", mUtils.packageHasFlag(PACKAGE_NAME, " SYSTEM ")); 611 assertTrue( 612 "VIBRATE permission should be granted", 613 mUtils.packageHasPermission(PACKAGE_NAME, VIBRATE_PERMISSION)); 614 assertTrue( 615 "ACCESS_CACHE_FILESYSTEM permission should be granted", 616 mUtils.packageHasPermission(PACKAGE_NAME, CACHE_PERMISSION)); 617 618 mUtils.restartSystem(); 619 mPackageXml = mUtils.pullPackagesXML(); 620 assertFalse( 621 "After reboot, the path should be the data app", 622 mUtils.expectEquals(mPackageXml, CODE_PATH_XPATH, mSystemAppPath)); 623 assertTrue( 624 "Package version should be 3", 625 mUtils.expectEquals(mPackageXml, VERSION_XPATH, "3")); 626 assertTrue( 627 "Updated-package should be present", 628 mUtils.expectExists(mPackageXml, UPDATE_PACKAGE_XPATH)); 629 assertTrue( 630 "Package should have FLAG_SYSTEM", mUtils.packageHasFlag(PACKAGE_NAME, " SYSTEM ")); 631 assertTrue( 632 "VIBRATE permission should be granted", 633 mUtils.packageHasPermission(PACKAGE_NAME, VIBRATE_PERMISSION)); 634 assertTrue( 635 "ACCESS_CACHE_FILESYSTEM permission should be granted", 636 mUtils.packageHasPermission(PACKAGE_NAME, CACHE_PERMISSION)); 637 } 638 } 639