From c4e31b8d9ebd24be625a91b097810483e1df51d0 Mon Sep 17 00:00:00 2001 From: Yeabkal Wubshit Date: Wed, 7 Apr 2021 23:59:51 -0700 Subject: [PATCH] Support adding System Traces to Wear Bugreports System Traces collected with the native System Tracing App (Traceur) are now added under a separate directory (systraces) for Wear bugreports. Note that this change is functionally no-op for non-Wear form-factors (changes only one log's wordings for non-Wear form-factors). Bug: 183239853 Test: manual Change-Id: Id6b9aa0d38a0d465b763ec86fb1192875379431c (cherry picked from commit 7111510c691ccf20baf372dab5cea2ac30ae0c23) --- .../shell/BugreportProgressService.java | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/packages/Shell/src/com/android/shell/BugreportProgressService.java b/packages/Shell/src/com/android/shell/BugreportProgressService.java index 8c7011253c8a..c4386490b109 100644 --- a/packages/Shell/src/com/android/shell/BugreportProgressService.java +++ b/packages/Shell/src/com/android/shell/BugreportProgressService.java @@ -198,6 +198,15 @@ public class BugreportProgressService extends Service { */ private static final String BUGREPORT_DIR = "bugreports"; + /** + * The directory in which System Trace files from the native System Tracing app are stored for + * Wear devices. + */ + private static final String WEAR_SYSTEM_TRACES_DIRECTORY_ON_DEVICE = "data/local/traces/"; + + /** The directory that contains System Traces in bugreports that include System Traces. */ + private static final String WEAR_SYSTEM_TRACES_DIRECTORY_IN_BUGREPORT = "systraces/"; + private static final String NOTIFICATION_CHANNEL_ID = "bugreports"; /** @@ -1352,6 +1361,16 @@ public class BugreportProgressService extends Service { } } + /** Returns an array of the system trace files collected by the System Tracing native app. */ + private static File[] getSystemTraceFiles() { + try { + return new File(WEAR_SYSTEM_TRACES_DIRECTORY_ON_DEVICE).listFiles(); + } catch (SecurityException e) { + Log.e(TAG, "Error getting system trace files.", e); + return new File[]{}; + } + } + /** * Adds the user-provided info into the bugreport zip file. *

@@ -1371,8 +1390,17 @@ public class BugreportProgressService extends Service { Log.wtf(TAG, "addDetailsToZipFile(): no bugreportFile on " + info); return; } - if (TextUtils.isEmpty(info.getTitle()) && TextUtils.isEmpty(info.getDescription())) { - Log.d(TAG, "Not touching zip file since neither title nor description are set"); + + File[] systemTracesToIncludeInBugreport = new File[] {}; + if (mIsWatch) { + systemTracesToIncludeInBugreport = getSystemTraceFiles(); + Log.d(TAG, "Found " + systemTracesToIncludeInBugreport.length + " system traces."); + } + + if (TextUtils.isEmpty(info.getTitle()) + && TextUtils.isEmpty(info.getDescription()) + && systemTracesToIncludeInBugreport.length == 0) { + Log.d(TAG, "Not touching zip file: no detail to add."); return; } if (info.addedDetailsToZip || info.addingDetailsToZip) { @@ -1383,7 +1411,10 @@ public class BugreportProgressService extends Service { // It's not possible to add a new entry into an existing file, so we need to create a new // zip, copy all entries, then rename it. - sendBugreportBeingUpdatedNotification(mContext, info.id); // ...and that takes time + if (!mIsWatch) { + // TODO(b/184854609): re-introduce this notification for Wear. + sendBugreportBeingUpdatedNotification(mContext, info.id); // ...and that takes time + } final File dir = info.bugreportFile.getParentFile(); final File tmpZip = new File(dir, "tmp-" + info.bugreportFile.getName()); @@ -1404,6 +1435,13 @@ public class BugreportProgressService extends Service { } // Then add the user-provided info. + if (systemTracesToIncludeInBugreport.length != 0) { + for (File trace : systemTracesToIncludeInBugreport) { + addEntry(zos, + WEAR_SYSTEM_TRACES_DIRECTORY_IN_BUGREPORT + trace.getName(), + new FileInputStream(trace)); + } + } addEntry(zos, "title.txt", info.getTitle()); addEntry(zos, "description.txt", info.getDescription()); } catch (IOException e) {