From 9f3554176019543e654be7dba5410de2bbe3b55f Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Wed, 13 Jul 2016 14:38:24 -0700 Subject: Use the Shell app to show the bugreport notification on Wear. b/30041885 Change-Id: I998aa1606eb12f74a407fbafd9abc11c9454fb66 --- .../android/shell/BugreportProgressService.java | 88 +++++++++++++--------- 1 file changed, 51 insertions(+), 37 deletions(-) (limited to 'packages/Shell/src') diff --git a/packages/Shell/src/com/android/shell/BugreportProgressService.java b/packages/Shell/src/com/android/shell/BugreportProgressService.java index 6bc4df71fc5c..f04df4b64f84 100644 --- a/packages/Shell/src/com/android/shell/BugreportProgressService.java +++ b/packages/Shell/src/com/android/shell/BugreportProgressService.java @@ -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,56 +444,68 @@ 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); - 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); - infoIntent.setAction(INTENT_BUGREPORT_INFO_LAUNCH); - infoIntent.putExtra(EXTRA_ID, info.id); - final PendingIntent infoPendingIntent = - PendingIntent.getService(mContext, info.id, infoIntent, - PendingIntent.FLAG_UPDATE_CURRENT); - final Action infoAction = new Action.Builder(null, - mContext.getString(R.string.bugreport_info_action), - infoPendingIntent).build(); - final Intent screenshotIntent = new Intent(mContext, BugreportProgressService.class); - screenshotIntent.setAction(INTENT_BUGREPORT_SCREENSHOT); - screenshotIntent.putExtra(EXTRA_ID, info.id); - PendingIntent screenshotPendingIntent = mTakingScreenshot ? null : PendingIntent - .getService(mContext, info.id, screenshotIntent, - PendingIntent.FLAG_UPDATE_CURRENT); - 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); + + 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 notification = newBaseNotification(mContext) + final Notification.Builder builder = 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; + .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); + infoIntent.setAction(INTENT_BUGREPORT_INFO_LAUNCH); + infoIntent.putExtra(EXTRA_ID, info.id); + final PendingIntent infoPendingIntent = + PendingIntent.getService(mContext, info.id, infoIntent, + PendingIntent.FLAG_UPDATE_CURRENT); + final Action infoAction = new Action.Builder(null, + mContext.getString(R.string.bugreport_info_action), + infoPendingIntent).build(); + final Intent screenshotIntent = new Intent(mContext, BugreportProgressService.class); + screenshotIntent.setAction(INTENT_BUGREPORT_SCREENSHOT); + screenshotIntent.putExtra(EXTRA_ID, info.id); + PendingIntent screenshotPendingIntent = mTakingScreenshot ? null : PendingIntent + .getService(mContext, info.id, screenshotIntent, + PendingIntent.FLAG_UPDATE_CURRENT); + final Action screenshotAction = new Action.Builder(null, + mContext.getString(R.string.bugreport_screenshot_action), + screenshotPendingIntent).build(); + 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,10 +871,7 @@ 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); - } + triggerLocalNotification(mContext, info); } /** -- cgit v1.2.3-59-g8ed1b