/* Return the path to the Android SDK root installation. * * (*pFromEnv) will be set to 1 if it comes from the $ANDROID_SDK_ROOT * environment variable, or 0 otherwise. * * Caller must free() returned string. */ char* path_getSdkRoot( char *pFromEnv ) { const char* env; char* sdkPath; char temp[PATH_MAX], *p=temp, *end=p+sizeof(temp); /* If ANDROID_SDK_ROOT is defined is must point to a directory * containing a valid SDK installation. */ #define SDK_ROOT_ENV "ANDROID_SDK_ROOT" env = getenv(SDK_ROOT_ENV); if (env != NULL && env[0] != 0) { if (path_exists(env)) { D("found " SDK_ROOT_ENV ": %s", env); *pFromEnv = 1; return ASTRDUP(env); } D(SDK_ROOT_ENV " points to unknown directory: %s", env); } *pFromEnv = 0; /* We assume the emulator binary is under tools/ so use its * parent as the Android SDK root. */ (void) bufprint_app_dir(temp, end); sdkPath = path_parent(temp, 1); if (sdkPath == NULL) { derror("can't find root of SDK directory"); return NULL; } D("found SDK root at %s", sdkPath); return sdkPath; }
/* this function is used to perform auto-detection of the * system directory in the case of a SDK installation. * * we want to deal with several historical usages, hence * the slightly complicated logic. * * NOTE: the function returns the path to the directory * containing 'fileName'. this is *not* the full * path to 'fileName'. */ static char* _getSdkImagePath( const char* fileName ) { char temp[MAX_PATH]; char* p = temp; char* end = p + sizeof(temp); char* q; char* app; static const char* const searchPaths[] = { "", /* program's directory */ "/lib/images", /* this is for SDK 1.0 */ "/../platforms/android-1.1/images", /* this is for SDK 1.1 */ NULL }; app = bufprint_app_dir(temp, end); if (app >= end) return NULL; do { int nn; /* first search a few well-known paths */ for (nn = 0; searchPaths[nn] != NULL; nn++) { p = bufprint(app, end, "%s", searchPaths[nn]); q = bufprint(p, end, "/%s", fileName); if (q < end && path_exists(temp)) { *p = 0; goto FOUND_IT; } } /* hmmm. let's assume that we are in a post-1.1 SDK * scan ../platforms if it exists */ p = bufprint(app, end, "/../platforms"); if (p < end) { DirScanner* scanner = dirScanner_new(temp); if (scanner != NULL) { int found = 0; const char* subdir; for (;;) { subdir = dirScanner_next(scanner); if (!subdir) break; q = bufprint(p, end, "/%s/images/%s", subdir, fileName); if (q >= end || !path_exists(temp)) continue; found = 1; p = bufprint(p, end, "/%s/images", subdir); break; } dirScanner_free(scanner); if (found) break; } } /* I'm out of ideas */ return NULL; } while (0); FOUND_IT: //D("image auto-detection: %s/%s", temp, fileName); return android_strdup(temp); }