Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 42ca0087 authored by Felipe Leme's avatar Felipe Leme Committed by Android (Google) Code Review
Browse files

Merge "Improves how cornercase scenarios are handled:"

parents ed3a0a78 3bf521a3
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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>
+19 −5
Original line number Diff line number Diff line
@@ -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));
        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) {