1from sys import argv 2import os 3import subprocess 4import time 5 6APK_DIR = '${ANDROID_PRODUCT_OUT}/system/app/AttestationTestTool/AttestationTestTool.apk' 7FAILURE_TAG = 'AttestationFail' 8FAILURE_PREFIX = 'Failure: ' 9FINISHED_TAG = 'AttestationFinished' 10INFO_TAG = 'AttestationFailInfo' 11INFO_PREFIX = ' ' * len(FAILURE_PREFIX) 12ATTESTATION_PRINT_TAG = 'AttestationPrint' 13ATTESTATION_PRINT_PREFIX = 'Printed Attestation: ' 14devnull = open(os.devnull, 'wb') 15 16# Clear logcat 17subprocess.call('adb logcat -c', shell=True, stdout=devnull) 18subprocess.call('adb install -r ' + APK_DIR, shell=True, stdout=devnull) 19subprocess.call('adb shell am start -a android.intent.action.MAIN -n com.google.attestationexample/.AttestationActivity', 20 shell=True, stdout=devnull) 21finished = False 22read_retry = 0 23failures = 0 24while not finished and read_retry < 5: 25 time.sleep(1) 26 logcat = subprocess.check_output(['adb', 'logcat', '-d'], stderr=subprocess.STDOUT) 27 for line in logcat.decode('utf-8').split('\n'): 28 if ATTESTATION_PRINT_TAG in line: 29 print(ATTESTATION_PRINT_PREFIX + line[line.index('AttestationPrint') + len('AttestationPrint:'):]) 30 elif INFO_TAG in line: 31 print(INFO_PREFIX + line[line.index('AttestationFailInfo') + len('AttestationFailInfo:'):]) 32 elif FAILURE_TAG in line: 33 failures += 1 34 print(FAILURE_PREFIX + line[line.index('AttestationFail') + len('AttestationFail:'):]) 35 elif FINISHED_TAG in line and not finished: 36 print('Finished. Failures: ' + str(failures)) 37 finished = True 38 break 39 read_retry += 1 40 if read_retry == 5: 41 print('Attestation test did not complete, check logcat to determine the source of the error') 42subprocess.call('adb uninstall com.google.attestationexample', shell=True, stdout=devnull) 43