From 796ea0a96aa6b42df06caa68130225da42846166 Mon Sep 17 00:00:00 2001 From: Nataniel Borges Date: Tue, 17 Aug 2021 14:56:38 +0000 Subject: [PATCH] Fix no files returned by proxy on second consecutive tracing Python map function returns an iterator that cannot be reused. Convert it into a list instead to support multiple usages. Also, add an error message to the ocnsole if no files are returned Test: run proxy, start/stop trace 2+ times in a row Change-Id: I09e4a4a28315b28f8d6eabdbfe60890cdfb8510c --- tools/winscope/adb_proxy/winscope_proxy.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/winscope/adb_proxy/winscope_proxy.py b/tools/winscope/adb_proxy/winscope_proxy.py index f25ba9f7a..8c16e9647 100755 --- a/tools/winscope/adb_proxy/winscope_proxy.py +++ b/tools/winscope/adb_proxy/winscope_proxy.py @@ -93,6 +93,7 @@ class FileMatcher: matchingFiles = call_adb( f"shell su root find {self.path} -name {self.matcher}", device_id) + log.debug("Found file %s", matchingFiles.split('\n')[:-1]) return matchingFiles.split('\n')[:-1] def get_filetype(self): @@ -102,8 +103,8 @@ class FileMatcher: class WinscopeFileMatcher(FileMatcher): def __init__(self, path, matcher, filetype) -> None: self.path = path - self.internal_matchers = map(lambda ext: FileMatcher(path, f'{matcher}{ext}', filetype), - WINSCOPE_EXTS) + self.internal_matchers = list(map(lambda ext: FileMatcher(path, f'{matcher}{ext}', filetype), + WINSCOPE_EXTS)) self.type = filetype def get_filepaths(self, device_id): @@ -111,6 +112,7 @@ class WinscopeFileMatcher(FileMatcher): files = matcher.get_filepaths(device_id) if len(files) > 0: return files + log.debug("No files found") return [] @@ -447,6 +449,9 @@ class FetchFilesEndpoint(DeviceRequestEndpoint): buf = base64.encodebytes(tmp.read()).decode("utf-8") file_buffers[file_type].append(buf) + if (len(file_buffers) == 0): + log.error("Proxy didn't find any file to fetch") + # server.send_header('X-Content-Type-Options', 'nosniff') # add_standard_headers(server) j = json.dumps(file_buffers)