Skip to content

Commit 07ae882

Browse files
NmurtasDevclaude
andcommitted
Fix config.ini parsing to handle spaces around equals sign
- config.ini format uses "key = value" with spaces, not "key=value" - Fix image.sysdir.1 parsing to handle spaces: "image.sysdir.1 = system-images/..." - Fix hw.device.name parsing to handle spaces: "hw.device.name = pixel_7" - Use line.indexOf('=') instead of startsWith with hardcoded offset - Add debug logging to trace extraction process - Now correctly extracts Android version (e.g., "Android 15" from API 35) - Now correctly extracts device type (e.g., "Pixel 7" from pixel_7) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent af45605 commit 07ae882

1 file changed

Lines changed: 28 additions & 15 deletions

File tree

src/main/java/net/nicolamurtas/android/emulator/AndroidEmulatorManager.java

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -364,22 +364,29 @@ private String extractApiLevelFromPath(String avdPath) {
364364
Path configIni = Path.of(avdPath).resolve("config.ini");
365365
if (Files.exists(configIni)) {
366366
String content = Files.readString(configIni);
367-
// Look for image.sysdir.1=system-images/android-35/google_apis/x86_64/
367+
// Look for image.sysdir.1 = system-images/android-35/google_apis/x86_64/
368368
for (String line : content.split("\n")) {
369-
if (line.startsWith("image.sysdir.1=")) {
370-
String sysdir = line.substring(15).trim();
371-
// Extract API number from: system-images/android-35/google_apis/x86_64/
372-
String[] parts = sysdir.split("/");
373-
for (String part : parts) {
374-
if (part.startsWith("android-")) {
375-
return part.substring(8); // Remove "android-" prefix
369+
line = line.trim();
370+
if (line.startsWith("image.sysdir.1")) {
371+
// Parse "image.sysdir.1 = system-images/android-35/google_apis/x86_64/"
372+
int equalPos = line.indexOf('=');
373+
if (equalPos > 0) {
374+
String sysdir = line.substring(equalPos + 1).trim();
375+
// Extract API number from: system-images/android-35/google_apis/x86_64/
376+
String[] parts = sysdir.split("/");
377+
for (String part : parts) {
378+
if (part.startsWith("android-")) {
379+
String api = part.substring(8); // Remove "android-" prefix
380+
logger.debug("Extracted API level {} from sysdir: {}", api, sysdir);
381+
return api;
382+
}
376383
}
377384
}
378385
}
379386
}
380387
}
381388
} catch (Exception e) {
382-
logger.debug("Could not extract API level from path: {}", avdPath);
389+
logger.debug("Could not extract API level from path: {}", avdPath, e);
383390
}
384391

385392
return "Unknown";
@@ -448,17 +455,23 @@ private String extractDeviceType(String avdPath) {
448455
Path configIni = Path.of(avdPath).resolve("config.ini");
449456
if (Files.exists(configIni)) {
450457
String content = Files.readString(configIni);
451-
// Look for hw.device.name=pixel_7
458+
// Look for hw.device.name = pixel_7
452459
for (String line : content.split("\n")) {
453-
if (line.startsWith("hw.device.name=")) {
454-
String deviceName = line.substring(15).trim();
455-
// Format device name: pixel_7 -> Pixel 7
456-
return formatDeviceName(deviceName);
460+
line = line.trim();
461+
if (line.startsWith("hw.device.name")) {
462+
// Parse "hw.device.name = pixel_7"
463+
int equalPos = line.indexOf('=');
464+
if (equalPos > 0) {
465+
String deviceName = line.substring(equalPos + 1).trim();
466+
// Format device name: pixel_7 -> Pixel 7
467+
logger.debug("Extracted device name: {}", deviceName);
468+
return formatDeviceName(deviceName);
469+
}
457470
}
458471
}
459472
}
460473
} catch (Exception e) {
461-
logger.debug("Could not extract device type from path: {}", avdPath);
474+
logger.debug("Could not extract device type from path: {}", avdPath, e);
462475
}
463476

464477
return null;

0 commit comments

Comments
 (0)