/**
   * Regression test to verify that a shared app with no explicit permissions can run if its other
   * shared apps are installed, even after a reboot.
   *
   * <p>Assumes adb is running as root in device under test.
   */
  public void testInstallAndLaunchSharedPermsAppOnSD_Reboot() throws Exception {
    Log.i(LOG_TAG, "Test launching an app on SD, with no explicit perms set after reboot");

    try {
      // install the 2 shared apps with needed permissions first
      mPMHostUtils.installAppAndVerifyExistsOnSDCard(
          getTestAppFilePath(SHARED_PERMS_FL_APK), SHARED_PERMS_FL_PKG, false);
      mPMHostUtils.installAppAndVerifyExistsOnSDCard(
          getTestAppFilePath(SHARED_PERMS_BT_APK), SHARED_PERMS_BT_PKG, false);

      // now install the test app and see if we can launch it without errors
      mPMHostUtils.installAppAndVerifyExistsOnSDCard(
          getTestAppFilePath(SHARED_PERMS_APK), SHARED_PERMS_PKG, false);
      boolean testsPassed = mPMHostUtils.runDeviceTestsDidAllTestsPass(SHARED_PERMS_PKG);
      assert (testsPassed);

      // reboot
      getDevice().reboot();

      // Verify we can still launch the app
      testsPassed = mPMHostUtils.runDeviceTestsDidAllTestsPass(SHARED_PERMS_PKG);
      assert (testsPassed);
    }
    // cleanup test app
    finally {
      mPMHostUtils.uninstallApp(SHARED_PERMS_PKG);
      mPMHostUtils.uninstallApp(SHARED_PERMS_BT_PKG);
      mPMHostUtils.uninstallApp(SHARED_PERMS_FL_PKG);
    }
  }
  /**
   * Regression test to verify that an app with ACCESS_FINE_LOCATION (GPS) permissions can run
   * without permissions errors even after a reboot
   *
   * <p>Assumes adb is running as root in device under test.
   */
  public void testInstallAndLaunchFLPermsAppOnSD_Reboot() throws Exception {
    Log.i(LOG_TAG, "Test launching an app with location perms set, installed on SD card");

    try {
      // install the app and verify we can launch it without permissions errors
      mPMHostUtils.installAppAndVerifyExistsOnSDCard(
          getTestAppFilePath(SHARED_PERMS_FL_APK), SHARED_PERMS_FL_PKG, false);
      boolean testsPassed = mPMHostUtils.runDeviceTestsDidAllTestsPass(SHARED_PERMS_FL_PKG);
      assert (testsPassed);

      getDevice().reboot();

      testsPassed = mPMHostUtils.runDeviceTestsDidAllTestsPass(SHARED_PERMS_FL_PKG);
      assert (testsPassed);
    }
    // cleanup test app
    finally {
      mPMHostUtils.uninstallApp(SHARED_PERMS_FL_PKG);
    }
  }
  /**
   * Regression test to verify that an app with all permissions set can be installed on SD card and
   * then launched without crashing.
   *
   * <p>Assumes adb is running as root in device under test.
   */
  public void testInstallAndLaunchAllPermsAppOnSD() throws Exception {
    Log.i(LOG_TAG, "Test launching an app with all perms set, installed on SD card");

    try {
      // install the app
      mPMHostUtils.installAppAndVerifyExistsOnSDCard(
          getTestAppFilePath(ALL_PERMS_APK), ALL_PERMS_PKG, false);
      boolean testsPassed = mPMHostUtils.runDeviceTestsDidAllTestsPass(ALL_PERMS_PKG);
      assert (testsPassed);
    }
    // cleanup test app
    finally {
      mPMHostUtils.uninstallApp(ALL_PERMS_PKG);
    }
  }
  /**
   * Regression test to verify that a shared app with no explicit permissions throws a
   * SecurityException when launched if its other shared apps are not installed.
   *
   * <p>Assumes adb is running as root in device under test.
   */
  public void testInstallAndLaunchSharedPermsAppOnSD_NoPerms() throws Exception {
    Log.i(LOG_TAG, "Test launching an app with no explicit perms set, installed on SD card");

    try {
      // Make sure the 2 shared apps with needed permissions are not installed...
      mPMHostUtils.uninstallApp(SHARED_PERMS_FL_PKG);
      mPMHostUtils.uninstallApp(SHARED_PERMS_BT_PKG);

      // now install the app and see if when we launch it we get a permissions error
      mPMHostUtils.installAppAndVerifyExistsOnSDCard(
          getTestAppFilePath(SHARED_PERMS_APK), SHARED_PERMS_PKG, false);

      boolean testsPassed = mPMHostUtils.runDeviceTestsDidAllTestsPass(SHARED_PERMS_PKG);
      assertEquals("Shared perms app should fail to run", false, testsPassed);
    }
    // cleanup test app
    finally {
      mPMHostUtils.uninstallApp(SHARED_PERMS_PKG);
    }
  }