From ecbcb6a326c08e841bd62a53e16cdfe142caff63 Mon Sep 17 00:00:00 2001 From: Markus Stange Date: Fri, 24 May 2024 16:17:29 -0400 Subject: [PATCH] Add support for screen recording with VIEW intent. You can run it as follows: ``` python3 ./record_adb.py --mode intent --package org.mozilla.fenix --url https://theme-crave-demo.myshopify.com/ --output shopify-app-link.mp4 ``` --- record_adb.py | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/record_adb.py b/record_adb.py index 0cb1600..7952fcc 100644 --- a/record_adb.py +++ b/record_adb.py @@ -6,23 +6,22 @@ import argparse import subprocess import time -import os -import signal -# This script records the phone either through intent or simulating user touch +# This script records the phone either through view intent or simulating user touch # for the purpose of generating videos that are consistent. # The consistency allows us to compare said video. def main(args): - method = args.input + mode = args.mode device_path = './sdcard/output.mp4' - if method in 'touch' and (args.coordinate_x is None or args.coordinate_y is None): - print('--touch requires --coordinate-x --coordinate-y to use the touch input') + if mode == 'touch' and (args.coordinate_x is None or args.coordinate_y is None): + print('--mode touch requires --coordinate-x --coordinate-y to use the touch input. Enable the touch coordinate overlay in the Android debug settings to find the right coordinates.') + sys.exit() + + if mode == 'intent' and (args.url is None or args.package is None): + print('--mode intent requires --url and --package arguments') sys.exit() - # if method in 'intent' and args.package is None: - # print('--intent requires --package ') - # sys.exit() kill_existing_processes("org.mozilla") kill_existing_processes("com.android.chrome") @@ -34,20 +33,25 @@ def main(args): record_process = subprocess.Popen(['adb', 'shell', 'screenrecord', '--bugreport'] + [device_path]) time.sleep(3) - # TODO allow intent trigger - # if method in 'intent': - # record_with_intent(args.package) - # else: - simulate_input(args.coordinate_x, args.coordinate_y) + if mode == "touch": + simulate_input(args.coordinate_x, args.coordinate_y) + else: + if args.package.startswith("org.mozilla"): + activity = args.package + "/org.mozilla.fenix.IntentReceiverActivity" + else: + # Assume Chrome + activity = args.package + "/com.google.android.apps.chrome.IntentDispatcher" + record_with_view_intent(activity, args.url) + time.sleep(5) record_process.kill() time.sleep(5) pull_recording(device_path, args.output) -# def record_with_intent(package): -# activity_start = subprocess.Popen(['adb', 'shell', 'am', 'start-activity', package +'/.App', -# '--ez finishonboarding true']) -# activity_start.wait() + +def record_with_view_intent(activity, url): + activity_start = subprocess.Popen(['adb', 'shell', 'am', 'start-activity', '-d', url, '-a', 'android.intent.action.VIEW', activity]) + activity_start.wait() def simulate_input(x, y): @@ -79,13 +83,14 @@ def kill_existing_processes(package_substr): if __name__ == "__main__": parser = argparse.ArgumentParser(description='record video through adb', - usage=('record_adb.py --input --coordinate-x and --cordinate-y ' + usage=('record_adb.py --mode touch -cx 660 -cy 2222 ' '--output ')) # add intent later - parser.add_argument('-i', '--input', required=True, choices=("touch")) + parser.add_argument('-m', '--mode', required=True, choices=("touch", "intent")) parser.add_argument('-cx', '--coordinate-x', type=int, help="X position of touch event") parser.add_argument('-cy', '--coordinate-y', type=int, help="Y position of touch event") - # parser.add_argument('-p','--package', type=str, help='package name to record if intent is used') - parser.add_argument('-o', '--output', type=str, help="output name of file") + parser.add_argument('-u', '--url', type=str, help="App link URL") + parser.add_argument('-p', '--package', type=str, help="App package for app link") + parser.add_argument('-o', '--output', required=True, type=str, help="output name of file") args = parser.parse_args() main(args)