@@ -544,23 +544,18 @@ def get_adb_activity(app_name: str) -> Optional[str]:
544
544
return activity
545
545
546
546
547
- def get_all_apps (
547
+ def get_all_package_names (
548
548
env : env_interface .AndroidEnvInterface ,
549
549
timeout_sec : Optional [float ] = _DEFAULT_TIMEOUT_SECS ,
550
550
) -> list [str ]:
551
551
"""Returns all packages installed on the device.
552
552
553
- Note: the output list will not be exhaustive as it is currently based on a
554
- mapping we define, so any apps not included in that mapping will not be
555
- output here.
556
-
557
553
Args:
558
554
env: The AndroidEnv interface.
559
- timeout_sec: A timeout to use for this operation. If not set the default
560
- timeout will be used.
555
+ timeout_sec: A timeout to use for this operation.
561
556
562
557
Returns:
563
- A list of app names.
558
+ A list of installed package names.
564
559
"""
565
560
response = env .execute_adb_call (
566
561
adb_pb2 .AdbRequest (
@@ -573,16 +568,36 @@ def get_all_apps(
573
568
)
574
569
)
575
570
if response .status != adb_pb2 .AdbResponse .Status .OK :
576
- logging .error (
577
- 'Failed to issue package manager request' ,
578
- )
571
+ logging .error ('Failed to issue package manager request.' )
572
+
573
+ package_names = list (response .package_manager .list .items )
574
+ return package_names
575
+
576
+
577
+ def get_all_apps (
578
+ env : env_interface .AndroidEnvInterface ,
579
+ timeout_sec : Optional [float ] = _DEFAULT_TIMEOUT_SECS ,
580
+ ) -> list [str ]:
581
+ """Returns all apps installed on the device.
582
+
583
+ Note: the output list will not be exhaustive as it is currently based on a
584
+ mapping we define, so any apps not included in that mapping will not be
585
+ output here.
579
586
587
+ Args:
588
+ env: The AndroidEnv interface.
589
+ timeout_sec: A timeout to use for this operation. If not set the default
590
+ timeout will be used.
591
+
592
+ Returns:
593
+ A list of app names.
594
+ """
595
+ packages = get_all_package_names (env , timeout_sec )
580
596
package_to_app = {
581
597
v .split ('/' )[0 ]: k .split ('|' )[0 ] for k , v in _PATTERN_TO_ACTIVITY .items ()
582
598
}
583
-
584
599
app_names = []
585
- for package in response . package_manager . list . items :
600
+ for package in packages :
586
601
if package in package_to_app :
587
602
app_names .append (package_to_app [package ])
588
603
0 commit comments