blob: 6766c96a5f510a2fd41f1c9ffc1e6b22863195a1 [file] [log] [blame]
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001/* Copyright (C) 2008 The Android Open Source Project
2**
3** This software is licensed under the terms of the GNU General Public
4** License version 2, as published by the Free Software Foundation, and
5** may be copied, distributed, and modified under those terms.
6**
7** This program is distributed in the hope that it will be useful,
8** but WITHOUT ANY WARRANTY; without even the implied warranty of
9** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10** GNU General Public License for more details.
11*/
12#include "android/avd/info.h"
13#include "android/utils/path.h"
14#include "android/utils/bufprint.h"
15#include "android/utils/filelock.h"
16#include "android/utils/tempfile.h"
17#include "android/utils/debug.h"
18#include "android/utils/dirscanner.h"
19#include <ctype.h>
20#include <stddef.h>
21#include <string.h>
22#include <stdlib.h>
23#include <stdio.h>
24#include <errno.h>
25
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080026/* global variables - see android/globals.h */
27AvdInfoParams android_avdParams[1];
28AvdInfo* android_avdInfo;
29
30/* for debugging */
31#define D(...) VERBOSE_PRINT(init,__VA_ARGS__)
32#define DD(...) VERBOSE_PRINT(avd_config,__VA_ARGS__)
33
34/* technical note on how all of this is supposed to work:
35 *
36 * Each AVD corresponds to a "content directory" that is used to
37 * store persistent disk images and configuration files. Most remarkable
38 * are:
39 *
40 * - a "config.ini" file used to hold configuration information for the
41 * AVD
42 *
43 * - mandatory user data image ("userdata-qemu.img") and cache image
44 * ("cache.img")
45 *
46 * - optional mutable system image ("system-qemu.img"), kernel image
47 * ("kernel-qemu") and read-only ramdisk ("ramdisk.img")
48 *
49 * When starting up an AVD, the emulator looks for relevant disk images
50 * in the content directory. If it doesn't find a given image there, it
51 * will try to search in the list of system directories listed in the
52 * 'config.ini' file through one of the following (key,value) pairs:
53 *
54 * images.sysdir.1 = <first search path>
55 * images.sysdir.2 = <second search path>
56 *
57 * The search paths can be absolute, or relative to the root SDK installation
58 * path (which is determined from the emulator program's location, or from the
59 * ANDROID_SDK_ROOT environment variable).
60 *
61 * Individual image disk search patch can be over-riden on the command-line
62 * with one of the usual options.
63 */
64
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080065/* this is the subdirectory of $HOME/.android where all
66 * root configuration files (and default content directories)
67 * are located.
68 */
69#define ANDROID_AVD_DIR "avd"
70
71/* the prefix of config.ini keys that will be used for search directories
72 * of system images.
73 */
The Android Open Source Project92c73112009-03-05 14:34:31 -080074#define SEARCH_PREFIX "image.sysdir."
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080075
76/* the maximum number of search path keys we're going to read from the
77 * config.ini file
78 */
79#define MAX_SEARCH_PATHS 2
80
81/* the config.ini key that will be used to indicate the full relative
82 * path to the skin directory (including the skin name).
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080083 */
The Android Open Source Project92c73112009-03-05 14:34:31 -080084#define SKIN_PATH "skin.path"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080085
86/* default skin name */
87#define SKIN_DEFAULT "HVGA"
88
David Turner47356942009-04-05 14:23:06 -070089/* the config.ini key that is used to indicate the absolute path
90 * to the SD Card image file, if you don't want to place it in
91 * the content directory.
92 */
93#define SDCARD_PATH "sdcard.path"
94
San Mehat68a8f7b2009-12-05 09:54:44 -080095/* the config.ini key that is used to indicate the absolute path
96 * to the second SD Card image file, if you don't want to place it in
97 * the content directory.
98 */
99#define SDCARD2_PATH "sdcard2.path"
100
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800101/* certain disk image files are mounted read/write by the emulator
102 * to ensure that several emulators referencing the same files
103 * do not corrupt these files, we need to lock them and respond
104 * to collision depending on the image type.
105 *
106 * the enumeration below is used to record information about
107 * each image file path.
108 *
109 * READONLY means that the file will be mounted read-only
110 * and this doesn't need to be locked. must be first in list
111 *
112 * MUSTLOCK means that the file should be locked before
113 * being mounted by the emulator
114 *
115 * TEMPORARY means that the file has been copied to a
116 * temporary image, which can be mounted read/write
117 * but doesn't require locking.
118 */
119typedef enum {
120 IMAGE_STATE_READONLY, /* unlocked */
121 IMAGE_STATE_MUSTLOCK, /* must be locked */
122 IMAGE_STATE_LOCKED, /* locked */
123 IMAGE_STATE_LOCKED_EMPTY, /* locked and empty */
124 IMAGE_STATE_TEMPORARY, /* copied to temp file (no lock needed) */
125} AvdImageState;
126
127struct AvdInfo {
128 /* for the Android build system case */
129 char inAndroidBuild;
130 char* androidOut;
131 char* androidBuildRoot;
132
133 /* for the normal virtual device case */
134 char* deviceName;
135 char* sdkRootPath;
136 char sdkRootPathFromEnv;
137 char* searchPaths[ MAX_SEARCH_PATHS ];
138 int numSearchPaths;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800139 char* contentPath;
140 IniFile* rootIni; /* root <foo>.ini file */
141 IniFile* configIni; /* virtual device's config.ini */
142
143 /* for both */
144 char* skinName; /* skin name */
145 char* skinDirPath; /* skin directory */
146
147 /* image files */
148 char* imagePath [ AVD_IMAGE_MAX ];
149 char imageState[ AVD_IMAGE_MAX ];
150};
151
152
153void
154avdInfo_free( AvdInfo* i )
155{
156 if (i) {
157 int nn;
158
159 for (nn = 0; nn < AVD_IMAGE_MAX; nn++)
160 AFREE(i->imagePath[nn]);
161
162 AFREE(i->skinName);
163 AFREE(i->skinDirPath);
164
165 for (nn = 0; nn < i->numSearchPaths; nn++)
166 AFREE(i->searchPaths[nn]);
167
168 i->numSearchPaths = 0;
169
170 if (i->configIni) {
171 iniFile_free(i->configIni);
172 i->configIni = NULL;
173 }
174
175 if (i->rootIni) {
176 iniFile_free(i->rootIni);
177 i->rootIni = NULL;
178 }
179
180 AFREE(i->contentPath);
181 AFREE(i->sdkRootPath);
182
183 if (i->inAndroidBuild) {
184 AFREE(i->androidOut);
185 AFREE(i->androidBuildRoot);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800186 }
187
188 AFREE(i->deviceName);
189 AFREE(i);
190 }
191}
192
193/* list of default file names for each supported image file type */
194static const char* const _imageFileNames[ AVD_IMAGE_MAX ] = {
195#define _AVD_IMG(x,y,z) y,
196 AVD_IMAGE_LIST
197#undef _AVD_IMG
198};
199
200/* list of short text description for each supported image file type */
201static const char* const _imageFileText[ AVD_IMAGE_MAX ] = {
202#define _AVD_IMG(x,y,z) z,
203 AVD_IMAGE_LIST
204#undef _AVD_IMG
205};
206
207/***************************************************************
208 ***************************************************************
209 *****
210 ***** NORMAL VIRTUAL DEVICE SUPPORT
211 *****
212 *****/
213
214/* compute path to the root SDK directory
215 * assume we are in $SDKROOT/tools/emulator[.exe]
216 */
217static int
218_getSdkRoot( AvdInfo* i )
219{
220 const char* env;
221 char temp[PATH_MAX], *p=temp, *end=p+sizeof(temp);
222
223#define SDK_ROOT_ENV "ANDROID_SDK_ROOT"
224
225 env = getenv(SDK_ROOT_ENV);
226 if (env != NULL && env[0] != 0) {
227 if (path_exists(env)) {
228 D("found " SDK_ROOT_ENV ": %s", env);
229 i->sdkRootPath = ASTRDUP(env);
230 i->sdkRootPathFromEnv = 1;
231 return 0;
232 }
233 D(SDK_ROOT_ENV " points to unknown directory: %s", env);
234 }
235
236 (void) bufprint_app_dir(temp, end);
237
238 i->sdkRootPath = path_parent(temp, 1);
239 if (i->sdkRootPath == NULL) {
240 derror("can't find root of SDK directory");
241 return -1;
242 }
243 D("found SDK root at %s", i->sdkRootPath);
244 return 0;
245}
246
247static void
248_getSearchPaths( AvdInfo* i )
249{
250 char temp[PATH_MAX], *p = temp, *end= p+sizeof temp;
251 int nn, count = 0;
252
253
254
255 for (nn = 0; nn < MAX_SEARCH_PATHS; nn++) {
256 char* path;
257
258 p = bufprint(temp, end, "%s%d", SEARCH_PREFIX, nn+1 );
259 if (p >= end)
260 continue;
261
262 path = iniFile_getString( i->configIni, temp );
263 if (path != NULL) {
264 DD(" found image search path: %s", path);
265 if (!path_is_absolute(path)) {
266 p = bufprint(temp, end, "%s/%s", i->sdkRootPath, path);
267 AFREE(path);
268 path = ASTRDUP(temp);
269 }
270 i->searchPaths[count++] = path;
271 }
272 }
273
274 i->numSearchPaths = count;
The Android Open Source Project92c73112009-03-05 14:34:31 -0800275 if (count == 0) {
276 derror("no search paths found in this AVD's configuration.\n"
277 "Weird, the AVD's config.ini file is malformed. Try re-creating it.\n");
278 exit(2);
279 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800280 else
281 DD("found a total of %d search paths for this AVD", count);
282}
283
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800284static int
285_checkAvdName( const char* name )
286{
287 int len = strlen(name);
288 int len2 = strspn(name, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
289 "abcdefghijklmnopqrstuvwxyz"
290 "0123456789_.-");
291 return (len == len2);
292}
293
294/* parse the root config .ini file. it is located in
295 * ~/.android/avd/<name>.ini or Windows equivalent
296 */
297static int
298_getRootIni( AvdInfo* i )
299{
300 char temp[PATH_MAX], *p=temp, *end=p+sizeof(temp);
301
302 p = bufprint_config_path(temp, end);
303 p = bufprint(p, end, "/" ANDROID_AVD_DIR "/%s.ini", i->deviceName);
304 if (p >= end) {
305 derror("device name too long");
306 return -1;
307 }
308
309 i->rootIni = iniFile_newFromFile(temp);
310 if (i->rootIni == NULL) {
311 derror("unknown virtual device name: '%s'", i->deviceName);
312 return -1;
313 }
314 D("root virtual device file at %s", temp);
315 return 0;
316}
317
318/* the .ini variable name that points to the content directory
319 * in a root AVD ini file. This is required */
320# define ROOT_PATH_KEY "path"
321
322static int
323_getContentPath( AvdInfo* i )
324{
325 i->contentPath = iniFile_getString(i->rootIni, ROOT_PATH_KEY);
326
327 if (i->contentPath == NULL) {
328 derror("bad config: %s",
329 "virtual device file lacks a "ROOT_PATH_KEY" entry");
330 return -1;
331 }
332 D("virtual device content at %s", i->contentPath);
333 return 0;
334}
335
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800336/* find and parse the config.ini file from the content directory */
337static int
338_getConfigIni(AvdInfo* i)
339{
340 char temp[PATH_MAX], *p=temp, *end=p+sizeof(temp);
341
342 p = bufprint(p, end, "%s/config.ini", i->contentPath);
343 if (p >= end) {
344 derror("can't access virtual device content directory");
345 return -1;
346 }
347
348#if 1 /* XXX: TODO: remove this in the future */
349 /* for now, allow a non-existing config.ini */
350 if (!path_exists(temp)) {
351 D("virtual device has no config file - no problem");
352 return 0;
353 }
354#endif
355
356 i->configIni = iniFile_newFromFile(temp);
357 if (i->configIni == NULL) {
358 derror("bad config: %s",
359 "virtual device directory lacks config.ini");
360 return -1;
361 }
362 D("virtual device config file: %s", temp);
363 return 0;
364}
365
366/***************************************************************
367 ***************************************************************
368 *****
369 ***** KERNEL/DISK IMAGE LOADER
370 *****
371 *****/
372
373/* a structure used to handle the loading of
374 * kernel/disk images.
375 */
376typedef struct {
377 AvdInfo* info;
378 AvdInfoParams* params;
379 AvdImageType id;
380 const char* imageFile;
381 const char* imageText;
382 char** pPath;
383 char* pState;
384 char temp[PATH_MAX];
385} ImageLoader;
386
387static void
388imageLoader_init( ImageLoader* l, AvdInfo* info, AvdInfoParams* params )
389{
390 memset(l, 0, sizeof(*l));
391 l->info = info;
392 l->params = params;
393}
394
395/* set the type of the image to load */
396static void
397imageLoader_set( ImageLoader* l, AvdImageType id )
398{
399 l->id = id;
400 l->imageFile = _imageFileNames[id];
401 l->imageText = _imageFileText[id];
402 l->pPath = &l->info->imagePath[id];
403 l->pState = &l->info->imageState[id];
404
405 l->pState[0] = IMAGE_STATE_READONLY;
406}
407
408/* change the image path */
409static char*
410imageLoader_setPath( ImageLoader* l, const char* path )
411{
412 path = path ? ASTRDUP(path) : NULL;
413
414 AFREE(l->pPath[0]);
415 l->pPath[0] = (char*) path;
416
417 return (char*) path;
418}
419
420static char*
421imageLoader_extractPath( ImageLoader* l )
422{
423 char* result = l->pPath[0];
424 l->pPath[0] = NULL;
425 return result;
426}
427
428/* flags used when loading images */
429enum {
430 IMAGE_REQUIRED = (1<<0), /* image is required */
431 IMAGE_SEARCH_SDK = (1<<1), /* search image in SDK */
432 IMAGE_EMPTY_IF_MISSING = (1<<2), /* create empty file if missing */
433 IMAGE_DONT_LOCK = (1<<4), /* don't try to lock image */
434 IMAGE_IGNORE_IF_LOCKED = (1<<5), /* ignore file if it's locked */
435};
436
437#define IMAGE_OPTIONAL 0
438
439/* find an image from the SDK search directories.
440 * returns the full path or NULL if the file could not be found.
441 *
442 * note: this stores the result in the image's path as well
443 */
444static char*
445imageLoader_lookupSdk( ImageLoader* l )
446{
447 AvdInfo* i = l->info;
448 const char* image = l->imageFile;
449 char* temp = l->temp, *p = temp, *end = p + sizeof(l->temp);
450
451 do {
452 /* try the search paths */
453 int nn;
454
455 for (nn = 0; nn < i->numSearchPaths; nn++) {
456 const char* searchDir = i->searchPaths[nn];
457
458 p = bufprint(temp, end, "%s/%s", searchDir, image);
459 if (p < end && path_exists(temp)) {
460 DD("found %s in search dir: %s", image, searchDir);
461 goto FOUND;
462 }
463 DD(" no %s in search dir: %s", image, searchDir);
464 }
465
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800466 return NULL;
467
468 } while (0);
469
470FOUND:
471 l->pState[0] = IMAGE_STATE_READONLY;
472
473 return imageLoader_setPath(l, temp);
474}
475
476/* search for a file in the content directory.
477 * returns NULL if the file cannot be found.
478 *
479 * note that this formats l->temp with the file's path
480 * allowing you to retrieve it if the function returns NULL
481 */
482static char*
483imageLoader_lookupContent( ImageLoader* l )
484{
485 AvdInfo* i = l->info;
486 char* temp = l->temp, *p = temp, *end = p + sizeof(l->temp);
487
488 p = bufprint(temp, end, "%s/%s", i->contentPath, l->imageFile);
489 if (p >= end) {
490 derror("content directory path too long");
491 exit(2);
492 }
493 if (!path_exists(temp)) {
494 DD(" no %s in content directory", l->imageFile);
495 return NULL;
496 }
497 DD("found %s in content directory", l->imageFile);
498
499 /* assume content image files must be locked */
500 l->pState[0] = IMAGE_STATE_MUSTLOCK;
501
502 return imageLoader_setPath(l, temp);
503}
504
505/* lock a file image depending on its state and user flags
506 * note that this clears l->pPath[0] if the lock could not
507 * be acquired and that IMAGE_IGNORE_IF_LOCKED is used.
508 */
509static void
510imageLoader_lock( ImageLoader* l, unsigned flags )
511{
512 const char* path = l->pPath[0];
513
514 if (flags & IMAGE_DONT_LOCK)
515 return;
516
517 if (l->pState[0] != IMAGE_STATE_MUSTLOCK)
518 return;
519
520 D(" locking %s image at %s", l->imageText, path);
521
522 if (filelock_create(path) != NULL) {
523 /* succesful lock */
524 l->pState[0] = IMAGE_STATE_LOCKED;
525 return;
526 }
527
528 if (flags & IMAGE_IGNORE_IF_LOCKED) {
529 dwarning("ignoring locked %s image at %s", l->imageText, path);
530 imageLoader_setPath(l, NULL);
531 return;
532 }
533
534 derror("the %s image is used by another emulator. aborting",
535 l->imageText);
536 exit(2);
537}
538
539/* make a file image empty, this may require locking */
540static void
541imageLoader_empty( ImageLoader* l, unsigned flags )
542{
543 const char* path;
544
545 imageLoader_lock(l, flags);
546
547 path = l->pPath[0];
548 if (path == NULL) /* failed to lock, caller will handle it */
549 return;
550
551 if (path_empty_file(path) < 0) {
552 derror("could not create %s image at %s: %s",
553 l->imageText, path, strerror(errno));
554 exit(2);
555 }
556 l->pState[0] = IMAGE_STATE_LOCKED_EMPTY;
557}
558
559
560/* copy image file from a given source
561 * assumes locking is needed.
562 */
563static void
564imageLoader_copyFrom( ImageLoader* l, const char* srcPath )
565{
566 const char* dstPath = NULL;
567
568 /* find destination file */
569 if (l->params) {
570 dstPath = l->params->forcePaths[l->id];
571 }
572 if (!dstPath) {
573 imageLoader_lookupContent(l);
574 dstPath = l->temp;
575 }
576
577 /* lock destination */
578 imageLoader_setPath(l, dstPath);
579 l->pState[0] = IMAGE_STATE_MUSTLOCK;
580 imageLoader_lock(l, 0);
581
582 /* make the copy */
583 if (path_copy_file(dstPath, srcPath) < 0) {
584 derror("can't initialize %s image from SDK: %s: %s",
585 l->imageText, dstPath, strerror(errno));
586 exit(2);
587 }
588}
589
590/* this will load and eventually lock and image file, depending
591 * on the flags being used. on exit, this function udpates
592 * l->pState[0] and l->pPath[0]
593 *
594 * returns the path to the file. Note that it returns NULL
595 * only if the file was optional and could not be found.
596 *
597 * if the file is required and missing, the function aborts
598 * the program.
599 */
600static char*
601imageLoader_load( ImageLoader* l,
602 unsigned flags )
603{
604 const char* path = NULL;
605
David Turner47356942009-04-05 14:23:06 -0700606 /* set image state */
607 l->pState[0] = (flags & IMAGE_DONT_LOCK) == 0
608 ? IMAGE_STATE_MUSTLOCK
609 : IMAGE_STATE_READONLY;
610
611 /* check user-provided path */
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800612 path = l->params->forcePaths[l->id];
613 if (path != NULL) {
614 imageLoader_setPath(l, path);
615 if (path_exists(path)) {
616 DD("found user-provided %s image: %s", l->imageText, l->imageFile);
617 goto EXIT;
618 }
619 D("user-provided %s image does not exist: %s",
620 l->imageText, path);
621
622 /* if the file is required, abort */
623 if (flags & IMAGE_REQUIRED) {
624 derror("user-provided %s image at %s doesn't exist",
625 l->imageText, path);
626 exit(2);
627 }
628 }
629 else {
630 const char* contentFile;
631
632 /* second, look in the content directory */
633 path = imageLoader_lookupContent(l);
634 if (path) goto EXIT;
635
636 contentFile = ASTRDUP(l->temp);
637
638 /* it's not there */
639 if (flags & IMAGE_SEARCH_SDK) {
640 /* third, look in the SDK directory */
641 path = imageLoader_lookupSdk(l);
642 if (path) {
643 AFREE((char*)contentFile);
644 goto EXIT;
645 }
646 }
647 DD("found no %s image (%s)", l->imageText, l->imageFile);
648
649 /* if the file is required, abort */
650 if (flags & IMAGE_REQUIRED) {
651 AvdInfo* i = l->info;
652
653 derror("could not find required %s image (%s).",
654 l->imageText, l->imageFile);
655
656 if (i->inAndroidBuild) {
657 dprint( "Did you build everything ?" );
658 } else if (!i->sdkRootPathFromEnv) {
659 dprint( "Maybe defining %s to point to a valid SDK "
660 "installation path might help ?", SDK_ROOT_ENV );
661 } else {
662 dprint( "Your %s is probably wrong: %s", SDK_ROOT_ENV,
663 i->sdkRootPath );
664 }
665 exit(2);
666 }
667
668 path = imageLoader_setPath(l, contentFile);
669 AFREE((char*)contentFile);
670 }
671
672 /* otherwise, do we need to create it ? */
673 if (flags & IMAGE_EMPTY_IF_MISSING) {
674 imageLoader_empty(l, flags);
675 return l->pPath[0];
676 }
677 return NULL;
678
679EXIT:
680 imageLoader_lock(l, flags);
681 return l->pPath[0];
682}
683
San Mehat68a8f7b2009-12-05 09:54:44 -0800684static void _sdcardLoadImages(ImageLoader* l, AvdInfo* i, AvdInfoParams* params, AvdImageType sdcardImage)
685{
686 imageLoader_set(l, sdcardImage);
687 imageLoader_load(l, IMAGE_OPTIONAL |
688 IMAGE_IGNORE_IF_LOCKED);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800689
San Mehat68a8f7b2009-12-05 09:54:44 -0800690 /* if the file was not found, ignore it */
691 if (l->pPath[0] && !path_exists(l->pPath[0]))
692 {
693 D("ignoring non-existing %s at %s: %s",
694 l->imageText, l->pPath[0], strerror(errno));
695
696 /* if the user provided the SD Card path by hand,
697 * warn him. */
698 if (params->forcePaths[sdcardImage] != NULL)
699 dwarning("ignoring non-existing SD Card image");
700
701 imageLoader_setPath(l, NULL);
702 }
703}
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800704
705/* find the correct path of all image files we're going to need
706 * and lock the files that need it.
707 */
708static int
709_getImagePaths(AvdInfo* i, AvdInfoParams* params )
710{
711 int wipeData = (params->flags & AVDINFO_WIPE_DATA) != 0;
712 int wipeCache = (params->flags & AVDINFO_WIPE_CACHE) != 0;
713 int noCache = (params->flags & AVDINFO_NO_CACHE) != 0;
714 int noSdCard = (params->flags & AVDINFO_NO_SDCARD) != 0;
715
716 ImageLoader l[1];
717
718 imageLoader_init(l, i, params);
719
720 /* pick up the kernel and ramdisk image files - these don't
721 * need a specific handling.
722 */
723 imageLoader_set ( l, AVD_IMAGE_KERNEL );
724 imageLoader_load( l, IMAGE_REQUIRED | IMAGE_SEARCH_SDK | IMAGE_DONT_LOCK );
725
726 imageLoader_set ( l, AVD_IMAGE_RAMDISK );
727 imageLoader_load( l, IMAGE_REQUIRED | IMAGE_SEARCH_SDK | IMAGE_DONT_LOCK );
728
729 /* the system image
730 *
731 * if there is one in the content directory just lock
732 * and use it.
733 */
734 imageLoader_set ( l, AVD_IMAGE_INITSYSTEM );
David Turner47356942009-04-05 14:23:06 -0700735 imageLoader_load( l, IMAGE_REQUIRED | IMAGE_SEARCH_SDK | IMAGE_DONT_LOCK );
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800736
737 /* the data partition - this one is special because if it
738 * is missing, we need to copy the initial image file into it.
739 *
740 * first, try to see if it is in the content directory
741 * (or the user-provided path)
742 */
743 imageLoader_set( l, AVD_IMAGE_USERDATA );
744 if ( !imageLoader_load( l, IMAGE_OPTIONAL |
745 IMAGE_EMPTY_IF_MISSING |
746 IMAGE_DONT_LOCK ) )
747 {
748 /* it's not, we're going to initialize it. simply
749 * forcing a data wipe should be enough */
750 D("initializing new data partition image: %s", l->pPath[0]);
751 wipeData = 1;
752 }
753
754 if (wipeData) {
755 /* find SDK source file */
756 const char* srcPath;
757
The Android Open Source Project92c73112009-03-05 14:34:31 -0800758 imageLoader_set( l, AVD_IMAGE_INITDATA );
759 if (imageLoader_lookupSdk(l) == NULL) {
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800760 derror("can't locate initial %s image in SDK",
761 l->imageText);
762 exit(2);
763 }
764 srcPath = imageLoader_extractPath(l);
765
The Android Open Source Project92c73112009-03-05 14:34:31 -0800766 imageLoader_set( l, AVD_IMAGE_USERDATA );
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800767 imageLoader_copyFrom( l, srcPath );
768 AFREE((char*) srcPath);
769 }
770 else
771 {
772 /* lock the data partition image */
773 l->pState[0] = IMAGE_STATE_MUSTLOCK;
774 imageLoader_lock( l, 0 );
775 }
776
777 /* the cache partition: unless the user doesn't want one,
778 * we're going to create it in the content directory
779 */
780 if (!noCache) {
781 imageLoader_set (l, AVD_IMAGE_CACHE);
782 imageLoader_load(l, IMAGE_OPTIONAL |
783 IMAGE_EMPTY_IF_MISSING );
784
785 if (wipeCache) {
786 if (path_empty_file(l->pPath[0]) < 0) {
787 derror("cannot wipe %s image at %s: %s",
788 l->imageText, l->pPath[0],
789 strerror(errno));
790 exit(2);
791 }
792 }
793 }
794
795 /* the SD Card image. unless the user doesn't want to, we're
796 * going to mount it if available. Note that if the image is
797 * already used, we must ignore it.
798 */
799 if (!noSdCard) {
San Mehat68a8f7b2009-12-05 09:54:44 -0800800 _sdcardLoadImages(l, i, params, AVD_IMAGE_SDCARD);
801 _sdcardLoadImages(l, i, params, AVD_IMAGE_SDCARD2);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800802 }
803
804 return 0;
805}
806
807/* check that a given directory contains a valid skin.
808 * returns 1 on success, 0 on failure.
809 */
810static int
811_checkSkinPath( const char* skinPath )
812{
813 char temp[MAX_PATH], *p=temp, *end=p+sizeof(temp);
814
815 /* for now, if it has a 'layout' file, it is a valid skin path */
816 p = bufprint(temp, end, "%s/layout", skinPath);
817 if (p >= end || !path_exists(temp))
818 return 0;
819
820 return 1;
821}
822
823/* check that there is a skin named 'skinName' listed from 'skinDirRoot'
824 * this returns 1 on success, 0 on failure
825 * on success, the 'temp' buffer will get the path containing the real
826 * skin directory (after alias expansion), including the skin name.
827 */
828static int
829_checkSkinDir( char* temp,
830 char* end,
831 const char* skinDirRoot,
832 const char* skinName )
833{
834 DirScanner* scanner;
835 char *p;
836 int result;
837
838 p = bufprint(temp, end, "%s/skins/%s",
839 skinDirRoot, skinName);
840
841 if (p >= end || !path_exists(temp)) {
842 DD(" ignore bad skin directory %s", temp);
843 return 0;
844 }
845
846 /* first, is this a normal skin directory ? */
847 if (_checkSkinPath(temp)) {
848 /* yes */
849 DD(" found skin directory: %s", temp);
850 return 1;
851 }
852
853 /* second, is it an alias to another skin ? */
854 *p = 0;
855 result = 0;
856 scanner = dirScanner_new(temp);
857 if (scanner != NULL) {
858 for (;;) {
859 const char* file = dirScanner_next(scanner);
860
861 if (file == NULL)
862 break;
863
864 if (strncmp(file, "alias-", 6) || file[6] == 0)
865 continue;
866
867 p = bufprint(temp, end, "%s/skins/%s",
868 skinDirRoot, file+6);
869
870 if (p < end && _checkSkinPath(temp)) {
871 /* yes, it's an alias */
872 DD(" skin alias '%s' points to skin directory: %s",
873 file+6, temp);
874 result = 1;
875 break;
876 }
877 }
878 dirScanner_free(scanner);
879 }
880 return result;
881}
882
883/* try to see if the skin name leads to a magic skin or skin path directly
884 * returns 1 on success, 0 on error.
885 * on success, this sets up 'skinDirPath' and 'skinName' in the AvdInfo.
886 */
887static int
888_getSkinPathFromName( AvdInfo* i, const char* skinName )
889{
890 char temp[PATH_MAX], *p=temp, *end=p+sizeof(temp);
891
892 /* if the skin name has the format 'NNNNxNNN' where
893 * NNN is a decimal value, then this is a 'magic' skin
894 * name that doesn't require a skin directory
895 */
896 if (isdigit(skinName[0])) {
897 int width, height;
898 if (sscanf(skinName, "%dx%d", &width, &height) == 2) {
899 D("'magic' skin format detected: %s", skinName);
900 i->skinName = ASTRDUP(skinName);
901 i->skinDirPath = NULL;
902 return 1;
903 }
904 }
905
906 /* is the skin name a direct path to the skin directory ? */
907 if (_checkSkinPath(skinName)) {
908 goto FOUND_IT;
909 }
910
911 /* is the skin name a relative path from the SDK root ? */
912 p = bufprint(temp, end, "%s/%s", i->sdkRootPath, skinName);
913 if (p < end && _checkSkinPath(temp)) {
914 skinName = temp;
915 goto FOUND_IT;
916 }
917
918 /* nope */
919 return 0;
920
921FOUND_IT:
922 if (path_split(skinName, &i->skinDirPath, &i->skinName) < 0) {
923 derror("malformed skin name: %s", skinName);
924 exit(2);
925 }
926 D("found skin '%s' in directory: %s", i->skinName, i->skinDirPath);
927 return 1;
928}
929
930/* return 0 on success, -1 on error */
931static int
932_getSkin( AvdInfo* i, AvdInfoParams* params )
933{
934 char* skinName;
935 char temp[PATH_MAX], *p=temp, *end=p+sizeof(temp);
936 char explicitSkin = 1;
937
938 /* this function is used to compute the 'skinName' and 'skinDirPath'
939 * fields of the AvdInfo.
940 */
941
942 /* processing here is a bit tricky, so here's how it happens
943 *
944 * - command-line option '-skin <name>' can be used to specify the
945 * name of a skin, to override the AVD settings.
946 *
947 * - skins are searched from <dir>/../skins for each <dir> in the
948 * images search list, unless a '-skindir <path>' option has been
949 * provided on the command-line
950 *
951 * - otherwise, the config.ini can also contain a SKIN_PATH key that
952 * shall give the full path to the skin directory, either relative
953 * to the SDK root, or an absolute path.
954 *
955 * - skin names like '320x480' corresponds to "magic skins" that
956 * simply display a framebuffer, without any ornaments of the
957 * corresponding size. They do not correspond to any real skin
958 * directory / files and are handled later. But they must be
959 * recognized here and report a NULL skindir.
960 */
961 if (params->skinName) {
962 skinName = ASTRDUP(params->skinName);
963 } else {
964 skinName = iniFile_getString( i->configIni, SKIN_PATH );
965 explicitSkin = 0;
966 }
967
968 /* first, check that the skin name is not magic or a direct
969 * directory path
970 */
971 if (skinName != NULL && _getSkinPathFromName(i, skinName)) {
972 AFREE(skinName);
973 return 0;
974 }
975
976 /* if not, the default skinName is "HVGA" */
977 if (skinName == NULL) {
978 skinName = ASTRDUP(SKIN_DEFAULT);
979 explicitSkin = 0;
980 }
981
982 i->skinName = skinName;
983
984 /* now try to find the skin directory for that name -
985 * first try the content directory */
986 do {
987 /* if there is a single 'skin' directory in
988 * the content directory, assume that's what the
989 * user wants, unless an explicit name was given
990 */
991 if (!explicitSkin) {
992 p = bufprint(temp, end, "%s/skin", i->contentPath);
993 if (p < end && _checkSkinPath(temp)) {
994 D("using skin content from %s", temp);
995 AFREE(i->skinName);
996 i->skinName = ASTRDUP("skin");
997 i->skinDirPath = ASTRDUP(i->contentPath);
998 return 0;
999 }
1000 }
1001
1002 /* look in content directory */
1003 if (_checkSkinDir(temp, end, i->contentPath, skinName))
1004 break;
1005
1006 /* look in the search paths. For each <dir> in the list,
1007 * look the skins in <dir>/.. */
1008 {
1009 int nn;
1010 for (nn = 0; nn < i->numSearchPaths; nn++) {
1011 char* parentDir = path_parent(i->searchPaths[nn], 1);
1012 int ret;
1013 if (parentDir == NULL)
1014 continue;
1015 ret=_checkSkinDir(temp, end, parentDir, skinName);
1016 AFREE(parentDir);
1017 if (ret)
1018 break;
1019 }
1020 if (nn < i->numSearchPaths)
1021 break;
1022 }
1023
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001024 /* didn't find it */
1025 if (explicitSkin) {
1026 derror("could not find directory for skin '%s',"
1027 " please use a different name", skinName);
1028 exit(2);
1029 } else {
1030 dwarning("no skin directory matched '%s', so reverted to default",
1031 skinName);
1032 AFREE(i->skinName);
1033 params->skinName = SKIN_DEFAULT;
1034 return _getSkin(i, params);
1035 }
1036
1037 return -1;
1038
1039 } while (0);
1040
1041 /* separate skin name from parent directory. the skin name
1042 * returned in 'temp' might be different from the original
1043 * one due to alias expansion so strip it.
1044 */
1045 AFREE(i->skinName);
1046
1047 if (path_split(temp, &i->skinDirPath, &i->skinName) < 0) {
1048 derror("weird skin path: %s", temp);
1049 return -1;
1050 }
1051 DD("found skin '%s' in directory: %s", i->skinName, i->skinDirPath);
1052 return 0;
1053}
1054
David Turner47356942009-04-05 14:23:06 -07001055/* If the user didn't explicitely provide an SD Card path,
San Mehat68a8f7b2009-12-05 09:54:44 -08001056 * check the specfied key in config.ini and use that if
David Turner47356942009-04-05 14:23:06 -07001057 * available.
1058 */
1059static void
San Mehat68a8f7b2009-12-05 09:54:44 -08001060_getSDCardPath(AvdInfo* i, AvdInfoParams* params, AvdImageType sdcardImage,
1061 const char* iniKey )
David Turner47356942009-04-05 14:23:06 -07001062{
1063 const char* path;
1064
San Mehat68a8f7b2009-12-05 09:54:44 -08001065 if (params->forcePaths[sdcardImage] != NULL) {
David Turner47356942009-04-05 14:23:06 -07001066 return;
San Mehat68a8f7b2009-12-05 09:54:44 -08001067 }
David Turner47356942009-04-05 14:23:06 -07001068
San Mehat68a8f7b2009-12-05 09:54:44 -08001069 path = iniFile_getString(i->configIni, iniKey);
David Turner47356942009-04-05 14:23:06 -07001070 if (path == NULL)
1071 return;
1072
San Mehat68a8f7b2009-12-05 09:54:44 -08001073 params->forcePaths[sdcardImage] = path;
David Turner47356942009-04-05 14:23:06 -07001074}
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001075
1076AvdInfo*
1077avdInfo_new( const char* name, AvdInfoParams* params )
1078{
1079 AvdInfo* i;
1080
1081 if (name == NULL)
1082 return NULL;
1083
1084 if (!_checkAvdName(name)) {
1085 derror("virtual device name contains invalid characters");
1086 exit(1);
1087 }
1088
1089 ANEW0(i);
1090 i->deviceName = ASTRDUP(name);
1091
1092 if ( _getSdkRoot(i) < 0 ||
1093 _getRootIni(i) < 0 ||
1094 _getContentPath(i) < 0 ||
1095 _getConfigIni(i) < 0 )
1096 goto FAIL;
1097
1098 /* look for image search paths. handle post 1.1/pre cupcake
1099 * obsolete SDKs.
1100 */
1101 _getSearchPaths(i);
San Mehat68a8f7b2009-12-05 09:54:44 -08001102 _getSDCardPath(i, params, AVD_IMAGE_SDCARD, SDCARD_PATH);
1103 _getSDCardPath(i, params, AVD_IMAGE_SDCARD2, SDCARD2_PATH);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001104
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001105 /* don't need this anymore */
1106 iniFile_free(i->rootIni);
1107 i->rootIni = NULL;
1108
1109 if ( _getImagePaths(i, params) < 0 ||
1110 _getSkin (i, params) < 0 )
1111 goto FAIL;
1112
1113 return i;
1114
1115FAIL:
1116 avdInfo_free(i);
1117 return NULL;
1118}
1119
1120/***************************************************************
1121 ***************************************************************
1122 *****
1123 ***** ANDROID BUILD SUPPORT
1124 *****
1125 ***** The code below corresponds to the case where we're
1126 ***** starting the emulator inside the Android build
1127 ***** system. The main differences are that:
1128 *****
1129 ***** - the $ANDROID_PRODUCT_OUT directory is used as the
1130 ***** content file.
1131 *****
1132 ***** - built images must not be modified by the emulator,
1133 ***** so system.img must be copied to a temporary file
1134 ***** and userdata.img must be copied to userdata-qemu.img
1135 ***** if the latter doesn't exist.
1136 *****
1137 ***** - the kernel and default skin directory are taken from
1138 ***** prebuilt
1139 *****
1140 ***** - there is no root .ini file, or any config.ini in
The Android Open Source Project92c73112009-03-05 14:34:31 -08001141 ***** the content directory, no SDK images search path.
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001142 *****/
1143
1144/* used to fake a config.ini located in the content directory */
1145static int
1146_getBuildConfigIni( AvdInfo* i )
1147{
1148 /* a blank file is ok at the moment */
1149 i->configIni = iniFile_newFromMemory( "", 0 );
1150 return 0;
1151}
1152
1153static int
1154_getBuildImagePaths( AvdInfo* i, AvdInfoParams* params )
1155{
1156 int wipeData = (params->flags & AVDINFO_WIPE_DATA) != 0;
1157 int noCache = (params->flags & AVDINFO_NO_CACHE) != 0;
1158 int noSdCard = (params->flags & AVDINFO_NO_SDCARD) != 0;
1159
1160 char temp[PATH_MAX], *p=temp, *end=p+sizeof temp;
1161 char* srcData;
1162 ImageLoader l[1];
1163
1164 imageLoader_init(l, i, params);
1165
1166 /** load the kernel image
1167 **/
1168
1169 /* if it is not in the out directory, get it from prebuilt
1170 */
1171 imageLoader_set ( l, AVD_IMAGE_KERNEL );
1172
1173 if ( !imageLoader_load( l, IMAGE_OPTIONAL |
1174 IMAGE_DONT_LOCK ) )
1175 {
1176#define PREBUILT_KERNEL_PATH "prebuilt/android-arm/kernel/kernel-qemu"
1177 p = bufprint(temp, end, "%s/%s", i->androidBuildRoot,
1178 PREBUILT_KERNEL_PATH);
1179 if (p >= end || !path_exists(temp)) {
1180 derror("bad workspace: cannot find prebuilt kernel in: %s", temp);
1181 exit(1);
1182 }
1183 imageLoader_setPath(l, temp);
1184 }
1185
1186 /** load the data partition. note that we use userdata-qemu.img
1187 ** since we don't want to modify userdata.img at all
1188 **/
1189 imageLoader_set ( l, AVD_IMAGE_USERDATA );
1190 imageLoader_load( l, IMAGE_OPTIONAL | IMAGE_DONT_LOCK );
1191
1192 /* get the path of the source file, and check that it actually exists
1193 * if the user didn't provide an explicit data file
1194 */
1195 srcData = imageLoader_extractPath(l);
1196 if (srcData == NULL && params->forcePaths[AVD_IMAGE_USERDATA] == NULL) {
1197 derror("There is no %s image in your build directory. Please make a full build",
1198 l->imageText, l->imageFile);
1199 exit(2);
1200 }
1201
1202 /* get the path of the target file */
1203 l->imageFile = "userdata-qemu.img";
1204 imageLoader_load( l, IMAGE_OPTIONAL |
1205 IMAGE_EMPTY_IF_MISSING |
1206 IMAGE_IGNORE_IF_LOCKED );
1207
1208 /* force a data wipe if we just created the image */
1209 if (l->pState[0] == IMAGE_STATE_LOCKED_EMPTY)
1210 wipeData = 1;
1211
1212 /* if the image was already locked, create a temp file
1213 * then force a data wipe.
1214 */
1215 if (l->pPath[0] == NULL) {
1216 TempFile* temp = tempfile_create();
1217 imageLoader_setPath(l, tempfile_path(temp));
1218 dwarning( "Another emulator is running. user data changes will *NOT* be saved");
1219 wipeData = 1;
1220 }
1221
1222 /* in the case of a data wipe, copy userdata.img into
1223 * the destination */
1224 if (wipeData) {
1225 if (srcData == NULL || !path_exists(srcData)) {
1226 derror("There is no %s image in your build directory. Please make a full build",
1227 l->imageText, _imageFileNames[l->id]);
1228 exit(2);
1229 }
1230 if (path_copy_file( l->pPath[0], srcData ) < 0) {
1231 derror("could not initialize %s image from %s: %s",
1232 l->imageText, temp, strerror(errno));
1233 exit(2);
1234 }
1235 }
1236
1237 AFREE(srcData);
1238
1239 /** load the ramdisk image
1240 **/
1241 imageLoader_set ( l, AVD_IMAGE_RAMDISK );
1242 imageLoader_load( l, IMAGE_REQUIRED |
1243 IMAGE_DONT_LOCK );
1244
1245 /** load the system image. read-only. the caller must
1246 ** take care of checking the state
1247 **/
1248 imageLoader_set ( l, AVD_IMAGE_INITSYSTEM );
1249 imageLoader_load( l, IMAGE_REQUIRED | IMAGE_DONT_LOCK );
1250
1251 /* force the system image to read-only status */
1252 l->pState[0] = IMAGE_STATE_READONLY;
1253
1254 /** cache partition handling
1255 **/
1256 if (!noCache) {
1257 imageLoader_set (l, AVD_IMAGE_CACHE);
1258
1259 /* if the user provided one cache image, lock & use it */
1260 if ( params->forcePaths[l->id] != NULL ) {
1261 imageLoader_load(l, IMAGE_REQUIRED |
1262 IMAGE_IGNORE_IF_LOCKED);
1263 }
1264 }
1265
1266 /** SD Card image
1267 **/
1268 if (!noSdCard) {
1269 imageLoader_set (l, AVD_IMAGE_SDCARD);
1270 imageLoader_load(l, IMAGE_OPTIONAL | IMAGE_IGNORE_IF_LOCKED);
San Mehat68a8f7b2009-12-05 09:54:44 -08001271
1272 imageLoader_set (l, AVD_IMAGE_SDCARD2);
1273 imageLoader_load(l, IMAGE_OPTIONAL | IMAGE_IGNORE_IF_LOCKED);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001274 }
1275
1276 return 0;
1277}
1278
1279static int
1280_getBuildSkin( AvdInfo* i, AvdInfoParams* params )
1281{
1282 /* the (current) default skin name for our build system */
1283 const char* skinName = params->skinName;
1284 const char* skinDir = params->skinRootPath;
1285 char temp[PATH_MAX], *p=temp, *end=p+sizeof(temp);
1286 char* q;
1287
1288 if (!skinName) {
1289 /* the (current) default skin name for the build system */
1290 skinName = SKIN_DEFAULT;
David Turner2f7bb382009-03-25 15:30:56 -07001291 D("selecting default skin name '%s'", skinName);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001292 }
1293
1294 i->skinName = ASTRDUP(skinName);
1295
1296 if (!skinDir) {
1297
Xavier Ducrohet5bc61822009-11-20 12:24:17 -08001298#define PREBUILT_SKINS_DIR "sdk/emulator/skins"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001299
David Turner94088e22009-04-14 14:46:08 -07001300 do {
1301 /* try in <sysdir>/../skins first */
1302 p = bufprint( temp, end, "%s/../skins",
1303 i->androidBuildRoot );
1304 if (path_exists(temp))
1305 break;
1306
1307 /* the (current) default skin directory */
1308 p = bufprint( temp, end, "%s/%s",
1309 i->androidBuildRoot, PREBUILT_SKINS_DIR );
1310 } while (0);
1311
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001312 } else {
1313 p = bufprint( temp, end, "%s", skinDir );
1314 }
1315
1316 q = bufprint(p, end, "/%s/layout", skinName);
1317 if (q >= end || !path_exists(temp)) {
1318 DD("skin content directory does not exist: %s", temp);
1319 if (skinDir)
1320 dwarning("could not find valid skin '%s' in %s:\n",
1321 skinName, temp);
1322 return -1;
1323 }
1324 *p = 0;
1325 DD("found skin path: %s", temp);
1326 i->skinDirPath = ASTRDUP(temp);
1327
1328 return 0;
1329}
1330
1331AvdInfo*
1332avdInfo_newForAndroidBuild( const char* androidBuildRoot,
1333 const char* androidOut,
1334 AvdInfoParams* params )
1335{
1336 AvdInfo* i;
1337
1338 ANEW0(i);
1339
1340 i->inAndroidBuild = 1;
1341 i->androidBuildRoot = ASTRDUP(androidBuildRoot);
1342 i->androidOut = ASTRDUP(androidOut);
1343 i->contentPath = ASTRDUP(androidOut);
1344
1345 /* TODO: find a way to provide better information from the build files */
1346 i->deviceName = ASTRDUP("<build>");
1347
1348 if (_getBuildConfigIni(i) < 0 ||
1349 _getBuildImagePaths(i, params) < 0 )
1350 goto FAIL;
1351
1352 /* we don't need to fail if there is no valid skin */
1353 _getBuildSkin(i, params);
1354
1355 return i;
1356
1357FAIL:
1358 avdInfo_free(i);
1359 return NULL;
1360}
1361
1362const char*
1363avdInfo_getName( AvdInfo* i )
1364{
1365 return i ? i->deviceName : NULL;
1366}
1367
1368const char*
1369avdInfo_getImageFile( AvdInfo* i, AvdImageType imageType )
1370{
1371 if (i == NULL || (unsigned)imageType >= AVD_IMAGE_MAX)
1372 return NULL;
1373
1374 return i->imagePath[imageType];
1375}
1376
David 'Digit' Turnercd059b12009-08-28 19:36:27 +02001377uint64_t
1378avdInfo_getImageFileSize( AvdInfo* i, AvdImageType imageType )
1379{
1380 const char* file = avdInfo_getImageFile(i, imageType);
1381 uint64_t size;
1382
1383 if (file == NULL)
1384 return 0ULL;
1385
1386 if (path_get_size(file, &size) < 0)
1387 return 0ULL;
1388
1389 return size;
1390}
1391
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001392int
1393avdInfo_isImageReadOnly( AvdInfo* i, AvdImageType imageType )
1394{
1395 if (i == NULL || (unsigned)imageType >= AVD_IMAGE_MAX)
1396 return 1;
1397
1398 return (i->imageState[imageType] == IMAGE_STATE_READONLY);
1399}
1400
1401const char*
1402avdInfo_getSkinName( AvdInfo* i )
1403{
1404 return i->skinName;
1405}
1406
1407const char*
1408avdInfo_getSkinDir ( AvdInfo* i )
1409{
1410 return i->skinDirPath;
1411}
1412
1413int
1414avdInfo_getHwConfig( AvdInfo* i, AndroidHwConfig* hw )
1415{
1416 IniFile* ini = i->configIni;
1417 int ret;
1418
1419 if (ini == NULL)
1420 ini = iniFile_newFromMemory("", 0);
1421
1422 ret = androidHwConfig_read(hw, ini);
1423
1424 if (ini != i->configIni)
1425 iniFile_free(ini);
1426
David Turner2f7bb382009-03-25 15:30:56 -07001427 /* special product-specific hardware configuration */
David Turnere8b10bc2009-03-27 18:21:13 -07001428 if (i->androidOut != NULL)
David Turner2f7bb382009-03-25 15:30:56 -07001429 {
1430 char* p = strrchr(i->androidOut, '/');
1431 if (p != NULL && p[0] != 0) {
1432 if (p[1] == 's') {
1433 hw->hw_keyboard = 0;
1434 }
1435 }
1436 }
1437
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001438 return ret;
1439}
1440
1441const char*
1442avdInfo_getContentPath( AvdInfo* i )
1443{
1444 return i->contentPath;
1445}
1446
1447int
1448avdInfo_inAndroidBuild( AvdInfo* i )
1449{
1450 return i->inAndroidBuild;
1451}
1452
1453char*
1454avdInfo_getTracePath( AvdInfo* i, const char* traceName )
1455{
1456 char tmp[MAX_PATH], *p=tmp, *end=p + sizeof(tmp);
1457
1458 if (i == NULL || traceName == NULL || traceName[0] == 0)
1459 return NULL;
1460
1461 if (i->inAndroidBuild) {
1462 p = bufprint( p, end, "%s" PATH_SEP "traces" PATH_SEP "%s",
1463 i->androidOut, traceName );
1464 } else {
1465 p = bufprint( p, end, "%s" PATH_SEP "traces" PATH_SEP "%s",
1466 i->contentPath, traceName );
1467 }
1468 return ASTRDUP(tmp);
1469}