From 383ed7f970cad1fd0fa24efac0ec74204ed19776 Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Wed, 31 Jul 2024 10:43:49 -0700 Subject: [PATCH 1/9] Do not allow clearing Android logs if the emulator is not running --- tools/python/run_adb.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/python/run_adb.py b/tools/python/run_adb.py index 7506a8699df05..7802d90275dc6 100755 --- a/tools/python/run_adb.py +++ b/tools/python/run_adb.py @@ -13,7 +13,21 @@ def run_adb(android_sdk_root: str, args: typing.List[str]): sdk_tool_paths = get_sdk_tool_paths(android_sdk_root) - run(sdk_tool_paths.adb, *args) + if is_emulator_running(sdk_tool_paths.adb): + run(sdk_tool_paths.adb, *args) + else: + print("No emulator is running.") + + +def is_emulator_running(adb_path: str) -> bool: + result = run([adb_path, 'devices'], capture_stdout=True) + output = result.stdout + lines = output.strip().split('\n') + if len(lines) > 1: + for line in lines[1:]: + if "emulator" in line: + return True + return False def main(): From 283ca73900928d00b22fdb3157f6e6a801b2736b Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Wed, 31 Jul 2024 15:06:04 -0700 Subject: [PATCH 2/9] sdk_tool_paths --- tools/python/run_adb.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/python/run_adb.py b/tools/python/run_adb.py index 7802d90275dc6..7ebfcf5b16fdb 100755 --- a/tools/python/run_adb.py +++ b/tools/python/run_adb.py @@ -19,8 +19,8 @@ def run_adb(android_sdk_root: str, args: typing.List[str]): print("No emulator is running.") -def is_emulator_running(adb_path: str) -> bool: - result = run([adb_path, 'devices'], capture_stdout=True) +def is_emulator_running(adb_path) -> bool: + result = run(adb_path, "devices", capture_stdout=True) output = result.stdout lines = output.strip().split('\n') if len(lines) > 1: From 033442c9061beaa28f2fed729e17e2ddf00a359b Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Wed, 31 Jul 2024 15:15:12 -0700 Subject: [PATCH 3/9] lines = output.strip().split("\n") --- tools/python/run_adb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/python/run_adb.py b/tools/python/run_adb.py index 7ebfcf5b16fdb..2136f08931aff 100755 --- a/tools/python/run_adb.py +++ b/tools/python/run_adb.py @@ -22,7 +22,7 @@ def run_adb(android_sdk_root: str, args: typing.List[str]): def is_emulator_running(adb_path) -> bool: result = run(adb_path, "devices", capture_stdout=True) output = result.stdout - lines = output.strip().split('\n') + lines = output.strip().split("\n") if len(lines) > 1: for line in lines[1:]: if "emulator" in line: From 10ae66cb2032c5d44e6fb5800f684df2c4bae917 Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Wed, 31 Jul 2024 15:19:25 -0700 Subject: [PATCH 4/9] lines = output.strip().split("\n") --- tools/python/run_adb.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/python/run_adb.py b/tools/python/run_adb.py index 2136f08931aff..46ad09392db70 100755 --- a/tools/python/run_adb.py +++ b/tools/python/run_adb.py @@ -18,7 +18,6 @@ def run_adb(android_sdk_root: str, args: typing.List[str]): else: print("No emulator is running.") - def is_emulator_running(adb_path) -> bool: result = run(adb_path, "devices", capture_stdout=True) output = result.stdout From 5f08d971532504b76baeb35929714f10a022f2a9 Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Wed, 31 Jul 2024 15:20:53 -0700 Subject: [PATCH 5/9] lines = output.strip().split("\n") --- tools/python/run_adb.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/python/run_adb.py b/tools/python/run_adb.py index 46ad09392db70..2136f08931aff 100755 --- a/tools/python/run_adb.py +++ b/tools/python/run_adb.py @@ -18,6 +18,7 @@ def run_adb(android_sdk_root: str, args: typing.List[str]): else: print("No emulator is running.") + def is_emulator_running(adb_path) -> bool: result = run(adb_path, "devices", capture_stdout=True) output = result.stdout From b9d7e34442a3521ce70b5fb5450816bc57d45f13 Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Thu, 1 Aug 2024 10:05:26 -0700 Subject: [PATCH 6/9] splitlines --- tools/python/run_adb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/python/run_adb.py b/tools/python/run_adb.py index 2136f08931aff..0391f9df8641a 100755 --- a/tools/python/run_adb.py +++ b/tools/python/run_adb.py @@ -22,7 +22,7 @@ def run_adb(android_sdk_root: str, args: typing.List[str]): def is_emulator_running(adb_path) -> bool: result = run(adb_path, "devices", capture_stdout=True) output = result.stdout - lines = output.strip().split("\n") + lines = output.strip().splitlines() if len(lines) > 1: for line in lines[1:]: if "emulator" in line: From eef0213493e2d3e62ffbb06604d52550882cf446 Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Thu, 1 Aug 2024 12:06:41 -0700 Subject: [PATCH 7/9] splitlines --- tools/python/run_adb.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/python/run_adb.py b/tools/python/run_adb.py index 0391f9df8641a..500c0a9b553ec 100755 --- a/tools/python/run_adb.py +++ b/tools/python/run_adb.py @@ -22,7 +22,8 @@ def run_adb(android_sdk_root: str, args: typing.List[str]): def is_emulator_running(adb_path) -> bool: result = run(adb_path, "devices", capture_stdout=True) output = result.stdout - lines = output.strip().splitlines() + output_str = output.decode('utf-8').strip() + lines = output_str.splitlines() if len(lines) > 1: for line in lines[1:]: if "emulator" in line: From fb2382378ad83d65f6eda137da38e4eb27a592f5 Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Mon, 5 Aug 2024 10:15:27 -0700 Subject: [PATCH 8/9] splitlines --- tools/python/run_adb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/python/run_adb.py b/tools/python/run_adb.py index 500c0a9b553ec..4455246a25186 100755 --- a/tools/python/run_adb.py +++ b/tools/python/run_adb.py @@ -22,7 +22,7 @@ def run_adb(android_sdk_root: str, args: typing.List[str]): def is_emulator_running(adb_path) -> bool: result = run(adb_path, "devices", capture_stdout=True) output = result.stdout - output_str = output.decode('utf-8').strip() + output_str = output.decode("utf-8").strip() lines = output_str.splitlines() if len(lines) > 1: for line in lines[1:]: From e8fc10f5c824546a0d47f4fbc5a2229d68f72443 Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Thu, 8 Aug 2024 17:27:08 -0700 Subject: [PATCH 9/9] Moving condition check from python to yaml --- .../templates/android-dump-logs-from-steps.yml | 15 +++++++++++++-- tools/python/run_adb.py | 17 +---------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/tools/ci_build/github/azure-pipelines/templates/android-dump-logs-from-steps.yml b/tools/ci_build/github/azure-pipelines/templates/android-dump-logs-from-steps.yml index 212924d695194..2d91c605bf382 100644 --- a/tools/ci_build/github/azure-pipelines/templates/android-dump-logs-from-steps.yml +++ b/tools/ci_build/github/azure-pipelines/templates/android-dump-logs-from-steps.yml @@ -5,12 +5,23 @@ parameters: type: stepList steps: +- task: CmdLine@2 + input: + script: | + if [ -f $(Build.BinariesDirectory)/emulator.pid ]; then + echo "Emulator is running." + echo "##vso[task.setvariable variable=isEmulatorRunning]True" + else + echo "Emulator is not running." + fi + name: Determine if emulator is running + - task: CmdLine@2 inputs: script: | python3 tools/python/run_adb.py logcat --clear displayName: "Clear Android logs" - condition: succeededOrFailed() + condition: eq(variables['isEmulatorRunning'], 'True') - ${{ parameters.steps }} @@ -19,4 +30,4 @@ steps: script: | python3 tools/python/run_adb.py logcat -d displayName: "Dump Android logs" - condition: succeededOrFailed() + condition: eq(variables['isEmulatorRunning'], 'True') diff --git a/tools/python/run_adb.py b/tools/python/run_adb.py index 4455246a25186..7506a8699df05 100755 --- a/tools/python/run_adb.py +++ b/tools/python/run_adb.py @@ -13,22 +13,7 @@ def run_adb(android_sdk_root: str, args: typing.List[str]): sdk_tool_paths = get_sdk_tool_paths(android_sdk_root) - if is_emulator_running(sdk_tool_paths.adb): - run(sdk_tool_paths.adb, *args) - else: - print("No emulator is running.") - - -def is_emulator_running(adb_path) -> bool: - result = run(adb_path, "devices", capture_stdout=True) - output = result.stdout - output_str = output.decode("utf-8").strip() - lines = output_str.splitlines() - if len(lines) > 1: - for line in lines[1:]: - if "emulator" in line: - return True - return False + run(sdk_tool_paths.adb, *args) def main():