Merge "Fixing NPE when system image is removed." into studio-1.1-dev
diff --git a/sdklib/src/main/java/com/android/sdklib/internal/avd/AvdInfo.java b/sdklib/src/main/java/com/android/sdklib/internal/avd/AvdInfo.java
index 4b43628..a46a656 100755
--- a/sdklib/src/main/java/com/android/sdklib/internal/avd/AvdInfo.java
+++ b/sdklib/src/main/java/com/android/sdklib/internal/avd/AvdInfo.java
@@ -60,7 +60,9 @@
         /** The {@link Device} this AVD is based on has changed from its original configuration*/
         ERROR_DEVICE_CHANGED,
         /** The {@link Device} this AVD is based on is no longer available */
-        ERROR_DEVICE_MISSING
+        ERROR_DEVICE_MISSING,
+        /** the {@link SystemImage} this AVD is based on is no longer available */
+        ERROR_IMAGE_MISSING
     }
 
     private final String mName;
diff --git a/sdklib/src/main/java/com/android/sdklib/internal/avd/AvdManager.java b/sdklib/src/main/java/com/android/sdklib/internal/avd/AvdManager.java
index 7fc6b36..0557358 100644
--- a/sdklib/src/main/java/com/android/sdklib/internal/avd/AvdManager.java
+++ b/sdklib/src/main/java/com/android/sdklib/internal/avd/AvdManager.java
@@ -1694,6 +1694,9 @@
             }
         }
 
+        // Check the system image from the target
+        ISystemImage sysImage = target.getSystemImage(tag, abiType);
+
         // Get the device status if this AVD is associated with a device
         DeviceStatus deviceStatus = null;
         boolean updateHashV2 = false;
@@ -1750,6 +1753,8 @@
             status = AvdStatus.ERROR_DEVICE_CHANGED;
         } else if (deviceStatus == DeviceStatus.MISSING) {
             status = AvdStatus.ERROR_DEVICE_MISSING;
+        } else if (sysImage == null) {
+            status = AvdStatus.ERROR_IMAGE_MISSING;
         } else {
             status = AvdStatus.OK;
         }