Merge "Use the Shell app to show the bugreport notification on Wear." into nyc-mr1-dev
This commit is contained in:
@@ -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] -->
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user