OSDN Git Service

SDK Manager: correctly handle lack of AvdManager
[android-x86/sdk.git] / sdkmanager / libs / sdkuilib / src / com / android / sdkuilib / internal / repository / UpdaterData.java
index 5e40e5b..3d5405c 100755 (executable)
@@ -18,6 +18,7 @@ package com.android.sdkuilib.internal.repository;
 \r
 import com.android.prefs.AndroidLocation.AndroidLocationException;\r
 import com.android.sdklib.ISdkLog;\r
+import com.android.sdklib.SdkConstants;\r
 import com.android.sdklib.SdkManager;\r
 import com.android.sdklib.internal.avd.AvdManager;\r
 import com.android.sdklib.internal.repository.AddonPackage;\r
@@ -70,6 +71,8 @@ class UpdaterData {
 \r
     private Shell mWindowShell;\r
 \r
+    private AndroidLocationException mAvdManagerInitError;\r
+\r
     /**\r
      * Creates a new updater data.\r
      *\r
@@ -167,6 +170,36 @@ class UpdaterData {
         return mWindowShell;\r
     }\r
 \r
+    /**\r
+     * Check if any error occurred during initialization.\r
+     * If it did, display an error message.\r
+     *\r
+     * @return True if an error occurred, false if we should continue.\r
+     */\r
+    public boolean checkIfInitFailed() {\r
+        if (mAvdManagerInitError != null) {\r
+            String example;\r
+            if (SdkConstants.currentPlatform() == SdkConstants.PLATFORM_WINDOWS) {\r
+                example = "%USERPROFILE%";     //$NON-NLS-1$\r
+            } else {\r
+                example = "~";                 //$NON-NLS-1$\r
+            }\r
+\r
+            MessageDialog.openError(mWindowShell,\r
+                "Android Virtual Devices Manager",\r
+                String.format(\r
+                    "The AVD manager normally uses the user's profile directory to store " +\r
+                    "AVD files. However it failed to find the default profile directory. " +\r
+                    "\n" +\r
+                    "To fix this please set the environment variable ANDROID_SDK_HOME to " +\r
+                    "a valid path such as \"%s\".",\r
+                    example));\r
+\r
+            return true;\r
+        }\r
+        return false;\r
+    }\r
+\r
     // -----\r
 \r
     /**\r
@@ -178,7 +211,15 @@ class UpdaterData {
             mAvdManager = null; // remove the old one if needed.\r
             mAvdManager = new AvdManager(mSdkManager, mSdkLog);\r
         } catch (AndroidLocationException e) {\r
-            mSdkLog.error(e, "Unable to read AVDs");\r
+            mSdkLog.error(e, "Unable to read AVDs: " + e.toString());  //$NON-NLS-1$\r
+\r
+            // Note: we used to continue here, but the thing is that\r
+            // mAvdManager==null so nothing is really going to work as\r
+            // expected. Let's just display an error later in checkIfInitFailed()\r
+            // and abort right there. This step is just too early in the SWT\r
+            // setup process to display a message box yet.\r
+\r
+            mAvdManagerInitError = e;\r
         }\r
 \r
         // notify adapters/parsers\r