mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-03 03:27:10 +00:00
feat(android): detect foreground package via adb dumpsys
This commit is contained in:
1 parent
4d26bdf00d
commit
09528d84e6
2 files changed
+69
No files matched your search
@@ -91,3 +91,39 @@ func TestPathContains(t *testing.T) {
|
||||
t.Error("did not expect /nope in PATH")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseForegroundPackage(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
dumpsys string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "mResumedActivity folio",
|
||||
dumpsys: " Stack #0:\n mResumedActivity: ActivityRecord{a1b2c3 u0 app.folio/.MainActivity t42}\n",
|
||||
want: "app.folio",
|
||||
},
|
||||
{
|
||||
name: "topResumedActivity chrome",
|
||||
dumpsys: "ResumedActivity: ActivityRecord{ff u0 com.android.chrome/com.google.android.apps.chrome.Main t9}\n topResumedActivity=ActivityRecord{ff u0 com.android.chrome/com.google.android.apps.chrome.Main}",
|
||||
want: "com.android.chrome",
|
||||
},
|
||||
{
|
||||
name: "launcher",
|
||||
dumpsys: " mResumedActivity: ActivityRecord{x u0 com.google.android.apps.nexuslauncher/.NexusLauncherActivity t1}",
|
||||
want: "com.google.android.apps.nexuslauncher",
|
||||
},
|
||||
{
|
||||
name: "no resumed activity",
|
||||
dumpsys: " some unrelated dumpsys output\n with no resumed line\n",
|
||||
want: "",
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if got := parseForegroundPackage(tc.dumpsys); got != tc.want {
|
||||
t.Errorf("parseForegroundPackage = %q, want %q", got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user