MCPcopy
hub / github.com/APKLab/APKLab / findMainActivity

Function findMainActivity

src/utils/manifest.ts:8–33  ·  view source on GitHub ↗
(manifestPath: string)

Source from the content-addressed store, hash-verified

6 * Returns the fully qualified class name (e.g. "com.example.MainActivity") or null.
7 */
8export 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.

Callers 2

injectGadgetFunction · 0.90
manifest.test.tsFile · 0.90

Calls 1

resolveActivityNameFunction · 0.85

Tested by

no test coverage detected