Post a silent notification if screenshot is dismissed

Replicates the old behavior of being able to use the notifications
shade as a "to-do" area for screenshots. If the screenshot is
dismissed explicitly or by timeout (i.e., not by tapping the share
or edit buttons), we post a silent notification.

Bug: 156343422
Fix: 156343422
Test: manual
Change-Id: Ie2c1db4212e7332c5fba2e93c3d1d4d5e0c99a25
This commit is contained in:
Miranda Kephart
2020-06-09 11:09:55 -04:00
parent b121512580
commit c0841cf102
2 changed files with 72 additions and 0 deletions

View File

@@ -208,6 +208,7 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset
private Animator mScreenshotAnimation;
private Runnable mOnCompleteRunnable;
private Animator mDismissAnimation;
private SavedImageData mImageData;
private boolean mInDarkMode = false;
private boolean mDirectionLTR = true;
private boolean mOrientationPortrait = true;
@@ -226,6 +227,9 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset
switch (msg.what) {
case MESSAGE_CORNER_TIMEOUT:
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_INTERACTION_TIMEOUT);
if (mImageData != null) {
mNotificationsController.showSilentScreenshotNotification(mImageData);
}
GlobalScreenshot.this.dismissScreenshot("timeout", false);
mOnCompleteRunnable.run();
break;
@@ -396,6 +400,9 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset
mDismissButton = mScreenshotLayout.findViewById(R.id.global_screenshot_dismiss_button);
mDismissButton.setOnClickListener(view -> {
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_EXPLICIT_DISMISSAL);
if (mImageData != null) {
mNotificationsController.showSilentScreenshotNotification(mImageData);
}
dismissScreenshot("dismiss_button", false);
mOnCompleteRunnable.run();
});
@@ -436,6 +443,10 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset
});
}
mImageData = null; // make sure we clear the current stored data
mNotificationsController.reset();
mNotificationsController.setImage(mScreenBitmap);
mSaveInBgTask = new SaveImageInBackgroundTask(mContext, data);
mSaveInBgTask.execute();
}
@@ -643,6 +654,7 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset
*/
private void showUiOnActionsReady(SavedImageData imageData) {
logSuccessOnActionsReady(imageData);
mImageData = imageData;
AccessibilityManager accessibilityManager = (AccessibilityManager)
mContext.getSystemService(Context.ACCESSIBILITY_SERVICE);

View File

@@ -225,6 +225,66 @@ public class ScreenshotNotificationsController {
mNotificationBuilder.build());
}
/**
* Shows a silent notification with the saved screenshot and actions that can be taken with it.
*
* @param actionData SavedImageData struct with image URI and actions
*/
public void showSilentScreenshotNotification(
GlobalScreenshot.SavedImageData actionData) {
mNotificationBuilder.addAction(actionData.shareAction);
mNotificationBuilder.addAction(actionData.editAction);
mNotificationBuilder.addAction(actionData.deleteAction);
for (Notification.Action smartAction : actionData.smartActions) {
mNotificationBuilder.addAction(smartAction);
}
// Create the intent to show the screenshot in gallery
Intent launchIntent = new Intent(Intent.ACTION_VIEW);
launchIntent.setDataAndType(actionData.uri, "image/png");
launchIntent.setFlags(
Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION);
final long now = System.currentTimeMillis();
// Update the text and the icon for the existing notification
mPublicNotificationBuilder
.setContentTitle(mResources.getString(R.string.screenshot_saved_title))
.setContentText(mResources.getString(R.string.screenshot_saved_text))
.setContentIntent(PendingIntent.getActivity(mContext, 0, launchIntent, 0))
.setSmallIcon(R.drawable.stat_notify_image)
.setCategory(Notification.CATEGORY_PROGRESS)
.setWhen(now)
.setShowWhen(true)
.setAutoCancel(true)
.setColor(mContext.getColor(
com.android.internal.R.color.system_notification_accent_color))
.setGroup("silent")
.setGroupAlertBehavior(Notification.GROUP_ALERT_SUMMARY);
mNotificationBuilder
.setContentTitle(mResources.getString(R.string.screenshot_saved_title))
.setContentText(mResources.getString(R.string.screenshot_saved_text))
.setContentIntent(PendingIntent.getActivity(mContext, 0, launchIntent, 0))
.setSmallIcon(R.drawable.stat_notify_image)
.setCategory(Notification.CATEGORY_PROGRESS)
.setWhen(now)
.setShowWhen(true)
.setAutoCancel(true)
.setColor(mContext.getColor(
com.android.internal.R.color.system_notification_accent_color))
.setPublicVersion(mPublicNotificationBuilder.build())
.setStyle(mNotificationStyle)
.setFlag(Notification.FLAG_NO_CLEAR, false)
.setGroup("silent")
.setGroupAlertBehavior(Notification.GROUP_ALERT_SUMMARY);
SystemUI.overrideNotificationAppName(mContext, mPublicNotificationBuilder, true);
SystemUI.overrideNotificationAppName(mContext, mNotificationBuilder, true);
mNotificationManager.notify(SystemMessageProto.SystemMessage.NOTE_GLOBAL_SCREENSHOT,
mNotificationBuilder.build());
}
/**
* Sends a notification that the screenshot capture has failed.
*/