From 3bf521a32e91a65cc00a9fb777bf74e40b51f6f1 Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Wed, 18 Nov 2015 10:26:10 -0800 Subject: Improves how cornercase scenarios are handled: - Bug reports without screenshots are supported. - Shows a toast message when the bugreport file cannot be read. BUG: 25751868 Change-Id: I4ed2c47a89b373cf878720ebcba90c96bd51342b --- packages/Shell/res/values/strings.xml | 4 ++++ .../src/com/android/shell/BugreportReceiver.java | 24 +++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/packages/Shell/res/values/strings.xml b/packages/Shell/res/values/strings.xml index 3db0848ed632..4469d387853c 100644 --- a/packages/Shell/res/values/strings.xml +++ b/packages/Shell/res/values/strings.xml @@ -33,4 +33,8 @@ Bug reports + + + Bug report file could not be read + diff --git a/packages/Shell/src/com/android/shell/BugreportReceiver.java b/packages/Shell/src/com/android/shell/BugreportReceiver.java index e90a3b5a4824..c26437285050 100644 --- a/packages/Shell/src/com/android/shell/BugreportReceiver.java +++ b/packages/Shell/src/com/android/shell/BugreportReceiver.java @@ -37,6 +37,7 @@ import android.support.v4.content.FileProvider; import android.text.format.DateUtils; import android.util.Log; import android.util.Patterns; +import android.widget.Toast; import com.google.android.collect.Lists; import libcore.io.Streams; @@ -105,6 +106,13 @@ public class BugreportReceiver extends BroadcastReceiver { */ private void triggerLocalNotification(final Context context, final File bugreportFile, final File screenshotFile) { + if (!bugreportFile.exists() || !bugreportFile.canRead()) { + Log.e(TAG, "Could not read bugreport file " + bugreportFile); + Toast.makeText(context, context.getString(R.string.bugreport_unreadable_text), + Toast.LENGTH_LONG).show(); + return; + } + boolean isPlainText = bugreportFile.getName().toLowerCase().endsWith(".txt"); if (!isPlainText) { // Already zipped, send it right away. @@ -141,10 +149,12 @@ public class BugreportReceiver extends BroadcastReceiver { intent.putExtra(Intent.EXTRA_TEXT, messageBody); final ClipData clipData = new ClipData(null, new String[] { mimeType }, new ClipData.Item(null, null, null, bugreportUri)); - clipData.addItem(new ClipData.Item(null, null, null, screenshotUri)); + final ArrayList attachments = Lists.newArrayList(bugreportUri); + if (screenshotUri != null) { + clipData.addItem(new ClipData.Item(null, null, null, screenshotUri)); + attachments.add(screenshotUri); + } intent.setClipData(clipData); - - final ArrayList attachments = Lists.newArrayList(bugreportUri, screenshotUri); intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachments); final Account sendToAccount = findSendToAccount(context); @@ -162,8 +172,8 @@ public class BugreportReceiver extends BroadcastReceiver { File screenshotFile) { // Files are kept on private storage, so turn into Uris that we can // grant temporary permissions for. - final Uri bugreportUri = FileProvider.getUriForFile(context, AUTHORITY, bugreportFile); - final Uri screenshotUri = FileProvider.getUriForFile(context, AUTHORITY, screenshotFile); + final Uri bugreportUri = getUri(context, bugreportFile); + final Uri screenshotUri = getUri(context, screenshotFile); Intent sendIntent = buildSendIntent(context, bugreportUri, screenshotUri); Intent notifIntent; @@ -272,6 +282,10 @@ public class BugreportReceiver extends BroadcastReceiver { return foundAccount; } + private static Uri getUri(Context context, File file) { + return file != null ? FileProvider.getUriForFile(context, AUTHORITY, file) : null; + } + private static File getFileExtra(Intent intent, String key) { final String path = intent.getStringExtra(key); if (path != null) { -- cgit v1.2.3-59-g8ed1b