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

Commit 9f355417 authored by Wei Liu's avatar Wei Liu
Browse files

Use the Shell app to show the bugreport notification on Wear.

b/30041885

Change-Id: I998aa1606eb12f74a407fbafd9abc11c9454fb66
parent 4e5008c4
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -25,8 +25,8 @@
    <!-- 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] -->
    <string name="bugreport_finished_text" product="watch">Swipe left to share your bug report</string>
    <!-- Text of notification indicating that bugreport will appear on the phone. [CHAR LIMIT=100] -->
    <string name="bugreport_finished_text" product="watch">The bug report will appear on the phone shortly</string>
    <!-- Text of notification indicating that tapping will share the captured bugreport. [CHAR LIMIT=100] -->
    <string name="bugreport_finished_text" product="default">Tap to share your bug report</string>
    <!-- Text of notification indicating that swipe left will share the captured bugreport, but giving user the option to wait for the screenshot. [CHAR LIMIT=100] -->
+51 −37
Original line number Diff line number Diff line
@@ -212,6 +212,8 @@ public class BugreportProgressService extends Service {

    private static final Bundle sNotificationBundle = new Bundle();

    private boolean mIsWatch;

    @Override
    public void onCreate() {
        mContext = getApplicationContext();
@@ -225,6 +227,9 @@ public class BugreportProgressService extends Service {
                Log.w(TAG, "Could not create directory " + mScreenshotsDir);
            }
        }
        final Configuration conf = mContext.getResources().getConfiguration();
        mIsWatch = (conf.uiMode & Configuration.UI_MODE_TYPE_MASK) ==
                Configuration.UI_MODE_TYPE_WATCH;
    }

    @Override
@@ -439,10 +444,39 @@ public class BugreportProgressService extends Service {
            return;
        }

        if (info.finished) {
            Log.w(TAG, "Not sending progress notification because bugreport has finished already ("
                    + info + ")");
            return;
        }

        final NumberFormat nf = NumberFormat.getPercentInstance();
        nf.setMinimumFractionDigits(2);
        nf.setMaximumFractionDigits(2);
        final String percentageText = nf.format((double) info.progress / info.max);

        String title = mContext.getString(R.string.bugreport_in_progress_title, info.id);

        // TODO: Remove this workaround when notification progress is implemented on Wear.
        if (mIsWatch) {
            nf.setMinimumFractionDigits(0);
            nf.setMaximumFractionDigits(0);
            final String watchPercentageText = nf.format((double) info.progress / info.max);
            title = title + "\n" + watchPercentageText;
        }

        final String name =
                info.name != null ? info.name : mContext.getString(R.string.bugreport_unnamed);

        final Notification.Builder builder = newBaseNotification(mContext)
                .setContentTitle(title)
                .setTicker(title)
                .setContentText(name)
                .setProgress(info.max, info.progress, false)
                .setOngoing(true);

        // Wear bugreport doesn't need the bug info dialog, screenshot and cancel action.
        if (!mIsWatch) {
            final Action cancelAction = new Action.Builder(null, mContext.getString(
                    com.android.internal.R.string.cancel), newCancelIntent(mContext, info)).build();
            final Intent infoIntent = new Intent(mContext, BugreportProgressService.class);
@@ -463,32 +497,15 @@ public class BugreportProgressService extends Service {
            final Action screenshotAction = new Action.Builder(null,
                    mContext.getString(R.string.bugreport_screenshot_action),
                    screenshotPendingIntent).build();

        final String title = mContext.getString(R.string.bugreport_in_progress_title, info.id);

        final String name =
                info.name != null ? info.name : mContext.getString(R.string.bugreport_unnamed);

        final Notification notification = newBaseNotification(mContext)
                .setContentTitle(title)
                .setTicker(title)
                .setContentText(name)
                .setProgress(info.max, info.progress, false)
                .setOngoing(true)
                .setContentIntent(infoPendingIntent)
                .setActions(infoAction, screenshotAction, cancelAction)
                .build();

        if (info.finished) {
            Log.w(TAG, "Not sending progress notification because bugreport has finished already ("
                    + info + ")");
            return;
            builder.setContentIntent(infoPendingIntent)
                .setActions(infoAction, screenshotAction, cancelAction);
        }

        if (DEBUG) {
            Log.d(TAG, "Sending 'Progress' notification for id " + info.id + " (pid " + info.pid
                    + "): " + percentageText);
        }
        sendForegroundabledNotification(info.id, notification);
        sendForegroundabledNotification(info.id, builder.build());
    }

    private void sendForegroundabledNotification(int id, Notification notification) {
@@ -854,11 +871,8 @@ public class BugreportProgressService extends Service {
        // Stop running on foreground, otherwise share notification cannot be dismissed.
        stopForegroundWhenDone(id);

        final Configuration conf = mContext.getResources().getConfiguration();
        if ((conf.uiMode & Configuration.UI_MODE_TYPE_MASK) != Configuration.UI_MODE_TYPE_WATCH) {
        triggerLocalNotification(mContext, info);
    }
    }

    /**
     * Responsible for triggering a notification that allows the user to start a "share" intent with