From 5ee846dd18022307341c9808c9aacded2b2f60fd Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Wed, 9 Mar 2016 10:14:27 -0800 Subject: [PATCH] Warn user when bugreport is finished but screenshot is pending. BUG: 27524556 Change-Id: Iaecdd01605dc4b01cdf669baf443eaee7fb20f6f --- packages/Shell/res/values/strings.xml | 7 +++++- .../android/shell/BugreportProgressService.java | 25 +++++++++++++++------- .../com/android/shell/BugreportReceiverTest.java | 24 +++++++++++++++------ 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/packages/Shell/res/values/strings.xml b/packages/Shell/res/values/strings.xml index 38ea8804a2d8..5d901896cc4a 100644 --- a/packages/Shell/res/values/strings.xml +++ b/packages/Shell/res/values/strings.xml @@ -20,6 +20,8 @@ Bug report #%d is being generated Bug report #%d captured + + Bug report #%d captured but screenshot pending Adding details to the bug report @@ -29,7 +31,10 @@ Swipe left to share your bug report Tap to share your bug report - + + Tap to share your bug report without a screenshot or wait for the screenshot to finish + + Tap to share your bug report without a screenshot or wait for the screenshot to finish Bug reports contain data from the system\'s various log files, including personal and private information. Only share bug reports with apps and people you trust. diff --git a/packages/Shell/src/com/android/shell/BugreportProgressService.java b/packages/Shell/src/com/android/shell/BugreportProgressService.java index 1c6a0710d18f..686766741ace 100644 --- a/packages/Shell/src/com/android/shell/BugreportProgressService.java +++ b/packages/Shell/src/com/android/shell/BugreportProgressService.java @@ -714,7 +714,7 @@ public class BugreportProgressService extends Service { if (info.finished) { Log.d(TAG, "Screenshot finished after bugreport; updating share notification"); info.renameScreenshots(mScreenshotsDir); - sendBugreportNotification(mContext, info); + sendBugreportNotification(mContext, info, mTakingScreenshot); } msg = mContext.getString(R.string.bugreport_screenshot_taken); } else { @@ -803,10 +803,10 @@ public class BugreportProgressService extends Service { boolean isPlainText = info.bugreportFile.getName().toLowerCase().endsWith(".txt"); if (!isPlainText) { // Already zipped, send it right away. - sendBugreportNotification(context, info); + sendBugreportNotification(context, info, mTakingScreenshot); } else { // Asynchronously zip the file first, then send it. - sendZippedBugreportNotification(context, info); + sendZippedBugreportNotification(context, info, mTakingScreenshot); } } @@ -903,7 +903,8 @@ public class BugreportProgressService extends Service { /** * 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, + boolean takingScreenshot) { // Since adding the details can take a while, do it before notifying user. addDetailsToZipFile(context, info); @@ -914,12 +915,20 @@ public class BugreportProgressService extends Service { shareIntent.putExtra(EXTRA_ID, info.id); shareIntent.putExtra(EXTRA_INFO, info); - final String title = context.getString(R.string.bugreport_finished_title, info.id); + final String title, content; + if (takingScreenshot) { + title = context.getString(R.string.bugreport_finished_pending_screenshot_title, + info.id); + content = context.getString(R.string.bugreport_finished_pending_screenshot_text); + } else { + title = context.getString(R.string.bugreport_finished_title, info.id); + content = context.getString(R.string.bugreport_finished_text); + } 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_finished_text)) + .setContentText(content) .setContentIntent(PendingIntent.getService(context, info.id, shareIntent, PendingIntent.FLAG_UPDATE_CURRENT)) .setDeleteIntent(newCancelIntent(context, info)) @@ -958,12 +967,12 @@ public class BugreportProgressService extends Service { * Sends a zipped bugreport notification. */ private static void sendZippedBugreportNotification(final Context context, - final BugreportInfo info) { + final BugreportInfo info, final boolean takingScreenshot) { new AsyncTask() { @Override protected Void doInBackground(Void... params) { zipBugreport(info); - sendBugreportNotification(context, info); + sendBugreportNotification(context, info, takingScreenshot); return null; } }.execute(); diff --git a/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java b/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java index a629aac33d25..47e3b3b8f8f3 100644 --- a/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java +++ b/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java @@ -130,6 +130,9 @@ public class BugreportReceiverTest extends InstrumentationTestCase { private static final boolean RENAMED_SCREENSHOTS = true; private static final boolean DIDNT_RENAME_SCREENSHOTS = false; + private static final boolean PENDING_SCREENSHOT = true; + private static final boolean NOT_PENDING_SCREENSHOT = false; + private String mDescription; private String mPlainTextPath; @@ -409,9 +412,8 @@ public class BugreportReceiverTest extends InstrumentationTestCase { sendBugreportStarted(ID2, PID2, NAME2, 1000); - Bundle extras = sendBugreportFinishedAndGetSharedIntent(ID, mZipPath, mScreenshotPath); - assertActionSendMultiple(extras, BUGREPORT_CONTENT, SCREENSHOT_CONTENT, ID, PID, TITLE, - NEW_NAME, TITLE, DESCRIPTION, 1, RENAMED_SCREENSHOTS); + sendBugreportFinished(ID, mZipPath, mScreenshotPath); + Bundle extras = acceptBugreportAndGetSharedIntent(ID, PENDING_SCREENSHOT); detailsUi = new DetailsUi(mUiBot, ID2); detailsUi.assertName(NAME2); @@ -602,7 +604,7 @@ public class BugreportReceiverTest extends InstrumentationTestCase { private Bundle sendBugreportFinishedAndGetSharedIntent(int id, String bugreportPath, String screenshotPath) { sendBugreportFinished(id, bugreportPath, screenshotPath); - return acceptBugreportAndGetSharedIntent(id); + return acceptBugreportAndGetSharedIntent(id, NOT_PENDING_SCREENSHOT); } /** @@ -611,7 +613,11 @@ public class BugreportReceiverTest extends InstrumentationTestCase { * @return extras sent in the shared intent. */ private Bundle acceptBugreportAndGetSharedIntent(int id) { - acceptBugreport(id); + return acceptBugreportAndGetSharedIntent(id, NOT_PENDING_SCREENSHOT); + } + + private Bundle acceptBugreportAndGetSharedIntent(int id, boolean pendingScreenshot) { + acceptBugreport(id, pendingScreenshot); mUiBot.chooseActivity(UI_NAME); return mListener.getExtras(); } @@ -627,7 +633,13 @@ public class BugreportReceiverTest extends InstrumentationTestCase { * Accepts the notification to share the finished bugreport. */ private void acceptBugreport(int id) { - mUiBot.clickOnNotification(mContext.getString(R.string.bugreport_finished_title, id)); + acceptBugreport(id, NOT_PENDING_SCREENSHOT); + } + + private void acceptBugreport(int id, boolean pendingScreenshot) { + final int res = pendingScreenshot ? R.string.bugreport_finished_pending_screenshot_title + : R.string.bugreport_finished_title; + mUiBot.clickOnNotification(mContext.getString(res, id)); } /** -- 2.11.0