diff options
| author | Felipe Leme <felipeal@google.com> | 2015-11-18 10:26:10 -0800 |
|---|---|---|
| committer | Felipe Leme <felipeal@google.com> | 2015-11-18 10:46:54 -0800 |
| commit | 3bf521a32e91a65cc00a9fb777bf74e40b51f6f1 (patch) | |
| tree | 97954560fa0898ea0da00f341eea7598bd563c2f | |
| parent | 06993a33d986ff98a7f8994f5fc6cd060df47e0e (diff) | |
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
| -rw-r--r-- | packages/Shell/res/values/strings.xml | 4 | ||||
| -rw-r--r-- | packages/Shell/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 @@ <!-- Title for documents backend that offers bugreports. --> <string name="bugreport_storage_title">Bug reports</string> + + <!-- Toast message sent when the bugreport file could be read. --> + <string name="bugreport_unreadable_text">Bug report file could not be read</string> + </resources> 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<Uri> attachments = Lists.newArrayList(bugreportUri); + if (screenshotUri != null) { + clipData.addItem(new ClipData.Item(null, null, null, screenshotUri)); + attachments.add(screenshotUri); + } intent.setClipData(clipData); - - final ArrayList<Uri> 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) { |
