am 4f35e5e: AI 147771: CTS: Throw exception on attempts to install a non

Merge commit '4f35e5e9c5fa551355e250186230ee29a4c6563f' into donut

* commit '4f35e5e9c5fa551355e250186230ee29a4c6563f':
  AI 147771: CTS: Throw exception on attempts to install a nonexistent APK
diff --git a/tools/host/src/com/android/cts/ConsoleUi.java b/tools/host/src/com/android/cts/ConsoleUi.java
index d594567..78c561a 100644
--- a/tools/host/src/com/android/cts/ConsoleUi.java
+++ b/tools/host/src/com/android/cts/ConsoleUi.java
@@ -518,6 +518,10 @@
             Log.e("Device " + e.getMessage() + " disconnected ", null);
         } catch (NoSuchAlgorithmException e) {
             Log.e("Fail to initialise SHA-1 algorithm", e);
+        } catch (InvalidApkPathException e) {
+            Log.e(e.getMessage(), null);
+        } catch (InvalidNameSpaceException e) {
+            Log.e(e.getMessage(), null);
         }
     }
 
diff --git a/tools/host/src/com/android/cts/ReferenceAppTestPackage.java b/tools/host/src/com/android/cts/ReferenceAppTestPackage.java
index ac50c3c..2b70b86 100644
--- a/tools/host/src/com/android/cts/ReferenceAppTestPackage.java
+++ b/tools/host/src/com/android/cts/ReferenceAppTestPackage.java
@@ -77,10 +77,10 @@
      */
     @Override
     public void run(final TestDevice device, final String javaPkgName,
-                    TestSessionLog testSessionLog) throws DeviceDisconnectedException {
+                    TestSessionLog testSessionLog) throws DeviceDisconnectedException,
+                    InvalidApkPathException, InvalidNameSpaceException {
         Test test = getTests().iterator().next();
         if ((test != null) && (test.getResult().isNotExecuted())) {
-
             String appToTestApkPath =
                 HostConfig.getInstance().getCaseRepository().getApkPath(apkToTestName);
 
@@ -92,8 +92,8 @@
             device.waitForCommandFinish();
 
             // Install the Reference App Tests
-            String testApkPath =
-                HostConfig.getInstance().getCaseRepository().getApkPath(getAppBinaryName());
+            String testApkPath = HostConfig.getInstance().getCaseRepository()
+                    .getApkPath(getAppBinaryName());
             device.installAPK(testApkPath);
             device.waitForCommandFinish();
 
diff --git a/tools/host/src/com/android/cts/SignatureCheckPackage.java b/tools/host/src/com/android/cts/SignatureCheckPackage.java
index c61b37e..c31fbe8 100644
--- a/tools/host/src/com/android/cts/SignatureCheckPackage.java
+++ b/tools/host/src/com/android/cts/SignatureCheckPackage.java
@@ -74,7 +74,8 @@
     @Override
     public void run(final TestDevice device, final String javaPkgName,
             TestSessionLog testSesssionLog)
-    throws DeviceDisconnectedException {
+            throws DeviceDisconnectedException, InvalidNameSpaceException,
+            InvalidApkPathException {
         Test test = getTests().iterator().next();
         if ((test != null) && (test.getResult().isNotExecuted())) {
 
@@ -100,7 +101,8 @@
      * @return test result
      */
     public ArrayList<String> startSignatureTest(TestDevice device)
-                throws DeviceDisconnectedException {
+                throws DeviceDisconnectedException, InvalidNameSpaceException,
+                InvalidApkPathException {
         Log.d("installing APICheck apk");
         mAPICheckResult = new ArrayList<String>();
         // TODO: This is non-obvious and should be cleaned up
diff --git a/tools/host/src/com/android/cts/TestDevice.java b/tools/host/src/com/android/cts/TestDevice.java
index f4693cb..d1db0a2 100644
--- a/tools/host/src/com/android/cts/TestDevice.java
+++ b/tools/host/src/com/android/cts/TestDevice.java
@@ -142,10 +142,11 @@
     /**
      * get the information of this device
      *
-     * @return information of this device
+     * @return information of this device.
      */
     public DeviceParameterCollector getDeviceInfo()
-                throws DeviceDisconnectedException {
+                throws DeviceDisconnectedException, InvalidNameSpaceException,
+                InvalidApkPathException {
         if (mDeviceInfo.size() == 0) {
             logServiceThread = new LogServiceThread();
             logServiceThread.start();
@@ -243,7 +244,8 @@
     /**
      * Run device information collector apk to got the device info.
      */
-    private void genDeviceInfo() throws DeviceDisconnectedException {
+    private void genDeviceInfo() throws DeviceDisconnectedException,
+                InvalidNameSpaceException, InvalidApkPathException {
         String apkName = "DeviceInfoCollector";
 
         String apkPath = HostConfig.getInstance().getCaseRepository().getApkPath(apkName);
@@ -273,7 +275,6 @@
         uninstallAPK(GET_INFO_APP_PACKAGE_NAME);
         waitForCommandFinish();
         Log.d("uninstall device information collector successfully");
-
         mDeviceObserver = tmpDeviceObserver;
     }
 
@@ -816,9 +817,10 @@
      *
      * @param apkPath Name of the package to be installed.
      */
-    public void installAPK(final String apkPath) throws DeviceDisconnectedException {
+    public void installAPK(final String apkPath) throws DeviceDisconnectedException,
+                InvalidApkPathException {
         if ((apkPath == null) || (apkPath.length() == 0) || (!HostUtils.isFileExist(apkPath))) {
-            return;
+            throw new InvalidApkPathException(apkPath);
         }
 
         // Use re-install directly
@@ -874,9 +876,10 @@
      *
      * @param packageName The package to be un-installed.
      */
-    public void uninstallAPK(String packageName) throws DeviceDisconnectedException {
-        if (packageName == null) {
-            return;
+    public void uninstallAPK(String packageName) throws DeviceDisconnectedException,
+                InvalidNameSpaceException {
+        if ((packageName == null) || (packageName.length() == 0)) {
+            throw new InvalidNameSpaceException(packageName);
         }
 
         uninstallAPKImpl(packageName, mUninstallObserver);
diff --git a/tools/host/src/com/android/cts/TestHost.java b/tools/host/src/com/android/cts/TestHost.java
index 14c63a9..d412e4f 100644
--- a/tools/host/src/com/android/cts/TestHost.java
+++ b/tools/host/src/com/android/cts/TestHost.java
@@ -146,7 +146,8 @@
                        TestPlanNotFoundException,
                        IllegalTestNameException,
                        InterruptedException, DeviceDisconnectedException,
-                       NoSuchAlgorithmException {
+                       NoSuchAlgorithmException, InvalidNameSpaceException,
+                       InvalidApkPathException {
 
         // step 1: add package
         if (!addPackage(pathName)) {
@@ -443,7 +444,9 @@
     static private void runTest(final TestSession ts, final String deviceId,
             final String testFullName, final String javaPkgName, ActionType type) throws
             DeviceNotAvailableException, TestNotFoundException, IllegalTestNameException,
-            DeviceDisconnectedException {
+            DeviceDisconnectedException, InvalidNameSpaceException,
+            InvalidApkPathException {
+
         if (ts == null) {
             return;
         }
@@ -633,7 +636,8 @@
             throws IOException, DeviceNotAvailableException,
             TestNotFoundException, SAXException, ParserConfigurationException,
             TestPlanNotFoundException, IllegalTestNameException,
-            DeviceDisconnectedException, NoSuchAlgorithmException {
+            DeviceDisconnectedException, NoSuchAlgorithmException,
+            InvalidNameSpaceException, InvalidApkPathException {
 
         TestSession ts = createSession(testPlanName);
         if ((javaPkgName != null) && (javaPkgName.length() != 0)) {
@@ -659,7 +663,8 @@
             final String testFullName, final String javaPkgName, ActionType type)
             throws DeviceNotAvailableException,
             TestNotFoundException, IllegalTestNameException,
-            DeviceDisconnectedException {
+            DeviceDisconnectedException, InvalidNameSpaceException,
+            InvalidApkPathException {
 
         runTest(ts, deviceId, testFullName, javaPkgName, type);
         ts.getSessionLog().sessionComplete();
diff --git a/tools/host/src/com/android/cts/TestPackage.java b/tools/host/src/com/android/cts/TestPackage.java
index 0bbdf75..170e74c 100644
--- a/tools/host/src/com/android/cts/TestPackage.java
+++ b/tools/host/src/com/android/cts/TestPackage.java
@@ -641,7 +641,7 @@
      *
      * @return If succeed in installing, return true; else, return false.
      */
-    private boolean install() throws DeviceDisconnectedException {
+    private boolean install() throws DeviceDisconnectedException, InvalidApkPathException {
         String packageBinaryName = getAppBinaryName();
         String targetBinaryName = getTargetBinaryName();
         String packagePath = getFullPath(packageBinaryName);
@@ -649,21 +649,9 @@
 
         boolean success = true;
         if (packagePath != null) {
-            if (HostUtils.isFileExist(packagePath)) {
-                installAPK(packagePath);
-                if (!mTestStop) {
-                    if (targetApkPath != null) {
-                        if (HostUtils.isFileExist(targetApkPath)) {
-                            installAPK(targetApkPath);
-                        } else {
-                            success = false;
-                            Log.e("The following APK file doesn't exist: " + targetApkPath, null);
-                        }
-                    }
-                }
-            } else {
-                success = false;
-                Log.e("The following APK file doesn't exist: " + packagePath, null);
+            installAPK(packagePath);
+            if ((!mTestStop) && (targetApkPath != null)) {
+                installAPK(targetApkPath);
             }
         } else {
             success = false;
@@ -681,7 +669,7 @@
     /**
      * Uninstall test package and target package(if it exists)
      */
-    private void uninstall() throws DeviceDisconnectedException {
+    private void uninstall() throws DeviceDisconnectedException, InvalidNameSpaceException {
 
         String testPkgBinaryName = getAppBinaryName();
         String appNameSpace = getAppNameSpace();
@@ -701,7 +689,8 @@
     /**
      * Uninstall the specified package(.apk)
      */
-    private void uninstallAPK(final String packageName) throws DeviceDisconnectedException {
+    private void uninstallAPK(final String packageName) throws DeviceDisconnectedException,
+                InvalidNameSpaceException {
         Log.d("Uninstall: " + packageName);
         mDevice.uninstallAPK(packageName);
         waitPackageActionComplete();
@@ -712,7 +701,8 @@
      *
      * @param apkPath The test package to be installed.
      */
-    private void installAPK(final String apkPath) throws DeviceDisconnectedException {
+    private void installAPK(final String apkPath) throws DeviceDisconnectedException,
+            InvalidApkPathException {
         Log.d("installAPK " + apkPath + " ...");
         mDevice.installAPK(apkPath);
         waitPackageActionComplete();
@@ -951,7 +941,9 @@
      */
     public void run(final TestDevice device, final String javaPkgName,
                     TestSessionLog sessionLog)
-            throws IOException, DeviceDisconnectedException, ADBServerNeedRestartException {
+            throws IOException, DeviceDisconnectedException,
+            ADBServerNeedRestartException, InvalidApkPathException,
+            InvalidNameSpaceException {
         if (isAllTestsRun()) {
             return;
         }
@@ -966,7 +958,8 @@
      * @param javaPkgName The JAVA package name.
      */
     protected void runImpl(final String javaPkgName) throws IOException,
-            DeviceDisconnectedException, ADBServerNeedRestartException {
+            DeviceDisconnectedException, ADBServerNeedRestartException, InvalidApkPathException,
+            InvalidNameSpaceException {
         try {
             if (!install()) {
                 return;
@@ -1055,7 +1048,9 @@
      * @param test The specific test to be run.
      */
     public void runTest(final TestDevice device, final Test test)
-            throws DeviceDisconnectedException, ADBServerNeedRestartException {
+            throws DeviceDisconnectedException, ADBServerNeedRestartException,
+            InvalidApkPathException, InvalidNameSpaceException {
+
         if (test == null) {
             return;
         }
@@ -1076,7 +1071,8 @@
      * @param test The test to be run.
      */
     protected void runTestImpl(final Test test) throws DeviceDisconnectedException,
-            ADBServerNeedRestartException {
+            ADBServerNeedRestartException, InvalidApkPathException,
+            InvalidNameSpaceException {
         try {
             if (!install()) {
                 return;
diff --git a/tools/host/src/com/android/cts/TestSession.java b/tools/host/src/com/android/cts/TestSession.java
index f511c86..fd5c236 100644
--- a/tools/host/src/com/android/cts/TestSession.java
+++ b/tools/host/src/com/android/cts/TestSession.java
@@ -407,6 +407,10 @@
                     markNeedRestartADBServer();
                     return;
                 }
+            } catch (InvalidApkPathException e) {
+                Log.e(e.getMessage(), null);
+            } catch (InvalidNameSpaceException e) {
+                Log.e(e.getMessage(), null);
             }
 
             long startTime = getSessionLog().getStartTime().getTime();