(manifestPath: string)
| 6 | * Returns the fully qualified class name (e.g. "com.example.MainActivity") or null. |
| 7 | */ |
| 8 | export function findMainActivity(manifestPath: string): string | null { |
| 9 | const content = fs.readFileSync(manifestPath, "utf-8"); |
| 10 | |
| 11 | // Find all <activity> blocks with their intent-filters |
| 12 | // We use a simple regex approach since AndroidManifest is not deeply nested |
| 13 | const activityRegex = |
| 14 | /<activity[^>]*android:name="([^"]+)"[^]*?<\/activity>/g; |
| 15 | |
| 16 | let match: RegExpExecArray | null; |
| 17 | while ((match = activityRegex.exec(content)) !== null) { |
| 18 | const block = match[0]; |
| 19 | const activityName = match[1]; |
| 20 | |
| 21 | // Check for MAIN + LAUNCHER intent filter |
| 22 | const hasMainAction = block.includes("android.intent.action.MAIN"); |
| 23 | const hasLauncherCategory = block.includes( |
| 24 | "android.intent.category.LAUNCHER", |
| 25 | ); |
| 26 | |
| 27 | if (hasMainAction && hasLauncherCategory) { |
| 28 | return resolveActivityName(content, activityName); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | return null; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Resolve a potentially relative activity name to fully qualified. |
no test coverage detected