Merge "Allow using dynamic skin from android build" into idea133
 Auto-merge: 3e9ec80

* commit '3e9ec80327f4550c041b9218cdf3a0232e07cc02':
  Allow using dynamic skin from android build
diff --git a/android/avd/info.c b/android/avd/info.c
index 6e97703..d67b46d 100644
--- a/android/avd/info.c
+++ b/android/avd/info.c
@@ -1284,6 +1284,23 @@
 }
 
 char*
+avdInfo_getDynamicSkinPath( AvdInfo* i)
+{
+    char tmp[PATH_MAX];
+
+    if (i->inAndroidBuild) {
+        snprintf(tmp, sizeof(tmp), "%s/sdk/emulator/skins/dynamic/", i->androidBuildRoot);
+    } else {
+        snprintf(tmp, sizeof(tmp), "%s/tools/lib/emulator/skins/dynamic/", i->sdkRootPath);
+    }
+
+    if (!path_exists(tmp))
+        return NULL;
+
+    return ASTRDUP(tmp);
+}
+
+char*
 avdInfo_getCharmapFile( AvdInfo* i, const char* charmapName )
 {
     char        fileNameBuff[PATH_MAX];
diff --git a/android/avd/info.h b/android/avd/info.h
index 41ee309..d2b0b74 100644
--- a/android/avd/info.h
+++ b/android/avd/info.h
@@ -229,6 +229,9 @@
 /* Returns whether the AVD specifies the use of a dynamic skin */
 int          avdInfo_shouldUseDynamicSkin( AvdInfo* i);
 
+/* Returns the path that contains layout and assets for dynamic skin */
+char*        avdInfo_getDynamicSkinPath( AvdInfo* i);
+
 /* Find a charmap file named <charmapName>.kcm for this AVD.
  * Returns the path of the file on success, or NULL if not found.
  * The result string must be freed by the caller.
diff --git a/android/main-common.c b/android/main-common.c
index e2d1e5e..4221d72 100644
--- a/android/main-common.c
+++ b/android/main-common.c
@@ -424,20 +424,13 @@
     int       i;
     int       max_part_width;
     char      fromEnv;
-    char*     sdkRoot = path_getSdkRoot(&fromEnv);
 
-    if (sdkRoot == NULL) {
-        dwarning("Unable to locate sdk root. Will not use dynamic skin.");
+    *skinDirPath = avdInfo_getDynamicSkinPath(android_avdInfo);
+    if (*skinDirPath == NULL) {
+        dwarning("Unable to locate dynamic skin directory. Will not use dynamic skin.");
         return 0;
     }
 
-    snprintf(tmp, sizeof(tmp), "%s/tools/lib/emulator/skins/dynamic/", sdkRoot);
-    free(sdkRoot);
-
-    if (!path_exists(tmp))
-        return 0;
-
-    *skinDirPath = strdup(tmp);
     snprintf(tmp, sizeof(tmp), "%s/layout", *skinDirPath);
     D("trying to load skin file '%s'", tmp);