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

Commit 2758d5d9 authored by Felipe Leme's avatar Felipe Leme
Browse files

Updates notification while bugreport zip is being changed.

BUG: 26616935

Change-Id: I3bcbaf30621c23541f2c568355948b6faa578e06
parent 6e415b69
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -21,6 +21,10 @@
    <string name="bugreport_in_progress_title">Bug report is being generated</string>
    <string name="bugreport_in_progress_title">Bug report is being generated</string>
    <!-- Title of notification indicating a bugreport has been successfully captured. [CHAR LIMIT=50] -->
    <!-- Title of notification indicating a bugreport has been successfully captured. [CHAR LIMIT=50] -->
    <string name="bugreport_finished_title">Bug report captured</string>
    <string name="bugreport_finished_title">Bug report captured</string>
    <!-- Title of notification indicating a bugreport is being updated before it can be shared. [CHAR LIMIT=50] -->
    <string name="bugreport_updating_title">Adding details to the bug report</string>
    <!-- Content notification indicating a bugreport is being updated before it can be shared, asking the user to wait [CHAR LIMIT=50] -->
    <string name="bugreport_updating_wait">Please wait\u2026</string>


    <!-- Text of notification indicating that swipe left will share the captured bugreport. [CHAR LIMIT=100] -->
    <!-- Text of notification indicating that swipe left will share the captured bugreport. [CHAR LIMIT=100] -->
    <string name="bugreport_finished_text" product="watch">Swipe left to share your bug report</string>
    <string name="bugreport_finished_text" product="watch">Swipe left to share your bug report</string>
+25 −2
Original line number Original line Diff line number Diff line
@@ -464,6 +464,7 @@ public class BugreportProgressService extends Service {
                    + info + ")");
                    + info + ")");
            return;
            return;
        }
        }
        Log.v(TAG, "Sending 'Progress' notification for pid " + info.pid + ": " + percentText);
        NotificationManager.from(mContext).notify(TAG, info.pid, notification);
        NotificationManager.from(mContext).notify(TAG, info.pid, notification);
    }
    }


@@ -852,7 +853,7 @@ public class BugreportProgressService extends Service {
    }
    }


    /**
    /**
     * Sends a notitication indicating the bugreport has finished so use can share it.
     * Sends a notification indicating the bugreport has finished so use can share it.
     */
     */
    private static void sendBugreportNotification(Context context, BugreportInfo info) {
    private static void sendBugreportNotification(Context context, BugreportInfo info) {
        final Intent shareIntent = new Intent(INTENT_BUGREPORT_SHARE);
        final Intent shareIntent = new Intent(INTENT_BUGREPORT_SHARE);
@@ -878,9 +879,29 @@ public class BugreportProgressService extends Service {
            builder.setContentInfo(info.name);
            builder.setContentInfo(info.name);
        }
        }


        Log.v(TAG, "Sending 'Share' notification for pid " + info.pid + ": " + title);
        NotificationManager.from(context).notify(TAG, info.pid, builder.build());
        NotificationManager.from(context).notify(TAG, info.pid, builder.build());
    }
    }


    /**
     * Sends a notification indicating the bugreport is being updated so the user can wait until it
     * finishes - at this point there is nothing to be done other than waiting, hence it has no
     * pending action.
     */
    private static void sendBugreportBeingUpdatedNotification(Context context, int pid) {
        final String title = context.getString(R.string.bugreport_updating_title);
        final Notification.Builder builder = new Notification.Builder(context)
                .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb)
                .setContentTitle(title)
                .setTicker(title)
                .setContentText(context.getString(R.string.bugreport_updating_wait))
                .setLocalOnly(true)
                .setColor(context.getColor(
                        com.android.internal.R.color.system_notification_accent_color));
        Log.v(TAG, "Sending 'Updating zip' notification for pid " + pid + ": " + title);
        NotificationManager.from(context).notify(TAG, pid, builder.build());
    }

    /**
    /**
     * Sends a zipped bugreport notification.
     * Sends a zipped bugreport notification.
     */
     */
@@ -938,11 +959,13 @@ public class BugreportProgressService extends Service {
            Log.d(TAG, "Not touching zip file since neither title nor description are set");
            Log.d(TAG, "Not touching zip file since neither title nor description are set");
            return;
            return;
        }
        }

        // It's not possible to add a new entry into an existing file, so we need to create a new
        // 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.
        // zip, copy all entries, then rename it.
        sendBugreportBeingUpdatedNotification(mContext, info.pid); // ...and that takes time
        final File dir = info.bugreportFile.getParentFile();
        final File dir = info.bugreportFile.getParentFile();
        final File tmpZip = new File(dir, "tmp-" + info.bugreportFile.getName());
        final File tmpZip = new File(dir, "tmp-" + info.bugreportFile.getName());
        Log.d(TAG, "Writing temporary zip file (" + tmpZip + ")");
        Log.d(TAG, "Writing temporary zip file (" + tmpZip + ") with title and/or description");
        try (ZipFile oldZip = new ZipFile(info.bugreportFile);
        try (ZipFile oldZip = new ZipFile(info.bugreportFile);
                ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(tmpZip))) {
                ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(tmpZip))) {