Skip to content

Commit b80dc91

Browse files
author
The android_world Authors
committed
Internal changes.
PiperOrigin-RevId: 707453938
1 parent 1c05f3c commit b80dc91

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

android_world/env/adb_utils.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -544,23 +544,18 @@ def get_adb_activity(app_name: str) -> Optional[str]:
544544
return activity
545545

546546

547-
def get_all_apps(
547+
def get_all_package_names(
548548
env: env_interface.AndroidEnvInterface,
549549
timeout_sec: Optional[float] = _DEFAULT_TIMEOUT_SECS,
550550
) -> list[str]:
551551
"""Returns all packages installed on the device.
552552
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-
557553
Args:
558554
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.
561556
562557
Returns:
563-
A list of app names.
558+
A list of installed package names.
564559
"""
565560
response = env.execute_adb_call(
566561
adb_pb2.AdbRequest(
@@ -573,16 +568,36 @@ def get_all_apps(
573568
)
574569
)
575570
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.
579586
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)
580596
package_to_app = {
581597
v.split('/')[0]: k.split('|')[0] for k, v in _PATTERN_TO_ACTIVITY.items()
582598
}
583-
584599
app_names = []
585-
for package in response.package_manager.list.items:
600+
for package in packages:
586601
if package in package_to_app:
587602
app_names.append(package_to_app[package])
588603

0 commit comments

Comments
 (0)