diff options
| author | 2016-07-19 17:22:30 +0000 | |
|---|---|---|
| committer | 2016-07-19 17:22:30 +0000 | |
| commit | bc3c068189eb256a336c21a010c5a633548571af (patch) | |
| tree | 84f688427a4d7929825776a07259199c5b89b7c2 /packages/Shell/src | |
| parent | 84e763670dca73b97b173a87d45249b8f4d3a845 (diff) | |
| parent | 1dfbf794b5464da759b47836564aaf79f6f92bbc (diff) | |
Merge \"Use the Shell app to show the bugreport notification on Wear.\" into nyc-mr1-dev
am: 1dfbf794b5
Change-Id: Ibb3310be1330d238059e4f70aa26763731b19a30
Diffstat (limited to 'packages/Shell/src')
| -rw-r--r-- | packages/Shell/src/com/android/shell/BugreportProgressService.java | 88 |
1 files changed, 51 insertions, 37 deletions
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); } /** |