Skip to content

Commit 9157214

Browse files
Miranda KephartGenkzsz11
authored andcommitted
Bring back "Post a silent notification if screenshot is dismissed"
* Remove broken "Delete" action. 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 Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
1 parent d7f59db commit 9157214

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ abstract static class ActionsReadyListener {
222222
private Animator mScreenshotAnimation;
223223
private Runnable mOnCompleteRunnable;
224224
private Animator mDismissAnimation;
225+
private SavedImageData mImageData;
225226
private boolean mInDarkMode;
226227
private boolean mDirectionLTR;
227228
private boolean mOrientationPortrait;
@@ -246,6 +247,9 @@ public void handleMessage(Message msg) {
246247
switch (msg.what) {
247248
case MESSAGE_CORNER_TIMEOUT:
248249
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_INTERACTION_TIMEOUT);
250+
if (mImageData != null) {
251+
mNotificationsController.showSilentScreenshotNotification(mImageData);
252+
}
249253
GlobalScreenshot.this.dismissScreenshot("timeout", false);
250254
mOnCompleteRunnable.run();
251255
break;
@@ -673,6 +677,9 @@ public void getOutline(View view, Outline outline) {
673677
mDismissButton = mScreenshotLayout.findViewById(R.id.global_screenshot_dismiss_button);
674678
mDismissButton.setOnClickListener(view -> {
675679
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_EXPLICIT_DISMISSAL);
680+
if (mImageData != null) {
681+
mNotificationsController.showSilentScreenshotNotification(mImageData);
682+
}
676683
dismissScreenshot("dismiss_button", false);
677684
mOnCompleteRunnable.run();
678685
});
@@ -890,6 +897,10 @@ void onActionsReady(SavedImageData imageData) {
890897
});
891898
}
892899

900+
mImageData = null; // make sure we clear the current stored data
901+
mNotificationsController.reset();
902+
mNotificationsController.setImage(mScreenBitmap);
903+
893904
mSaveInBgTask = new SaveImageInBackgroundTask(mContext, mScreenshotSmartActions, data);
894905
mSaveInBgTask.execute();
895906
}
@@ -899,6 +910,7 @@ void onActionsReady(SavedImageData imageData) {
899910
*/
900911
private void showUiOnActionsReady(SavedImageData imageData) {
901912
logSuccessOnActionsReady(imageData);
913+
mImageData = imageData;
902914

903915
AccessibilityManager accessibilityManager = (AccessibilityManager)
904916
mContext.getSystemService(Context.ACCESSIBILITY_SERVICE);

packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotNotificationsController.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,65 @@ public void showScreenshotActionsNotification(
227227
mNotificationBuilder.build());
228228
}
229229

230+
/**
231+
* Shows a silent notification with the saved screenshot and actions that can be taken with it.
232+
*
233+
* @param actionData SavedImageData struct with image URI and actions
234+
*/
235+
public void showSilentScreenshotNotification(
236+
GlobalScreenshot.SavedImageData actionData) {
237+
mNotificationBuilder.addAction(actionData.shareAction);
238+
mNotificationBuilder.addAction(actionData.editAction);
239+
for (Notification.Action smartAction : actionData.smartActions) {
240+
mNotificationBuilder.addAction(smartAction);
241+
}
242+
243+
// Create the intent to show the screenshot in gallery
244+
Intent launchIntent = new Intent(Intent.ACTION_VIEW);
245+
launchIntent.setDataAndType(actionData.uri, "image/png");
246+
launchIntent.setFlags(
247+
Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION);
248+
249+
final long now = System.currentTimeMillis();
250+
251+
// Update the text and the icon for the existing notification
252+
mPublicNotificationBuilder
253+
.setContentTitle(mResources.getString(R.string.screenshot_saved_title))
254+
.setContentText(mResources.getString(R.string.screenshot_saved_text))
255+
.setContentIntent(PendingIntent.getActivity(mContext, 0, launchIntent, 0))
256+
.setSmallIcon(R.drawable.stat_notify_image)
257+
.setCategory(Notification.CATEGORY_PROGRESS)
258+
.setWhen(now)
259+
.setShowWhen(true)
260+
.setAutoCancel(true)
261+
.setColor(mContext.getColor(
262+
com.android.internal.R.color.system_notification_accent_color))
263+
.setGroup("silent")
264+
.setGroupAlertBehavior(Notification.GROUP_ALERT_SUMMARY);
265+
mNotificationBuilder
266+
.setContentTitle(mResources.getString(R.string.screenshot_saved_title))
267+
.setContentText(mResources.getString(R.string.screenshot_saved_text))
268+
.setContentIntent(PendingIntent.getActivity(mContext, 0, launchIntent, 0))
269+
.setSmallIcon(R.drawable.stat_notify_image)
270+
.setCategory(Notification.CATEGORY_PROGRESS)
271+
.setWhen(now)
272+
.setShowWhen(true)
273+
.setAutoCancel(true)
274+
.setColor(mContext.getColor(
275+
com.android.internal.R.color.system_notification_accent_color))
276+
.setPublicVersion(mPublicNotificationBuilder.build())
277+
.setStyle(mNotificationStyle)
278+
.setFlag(Notification.FLAG_NO_CLEAR, false)
279+
.setGroup("silent")
280+
.setGroupAlertBehavior(Notification.GROUP_ALERT_SUMMARY);
281+
282+
SystemUI.overrideNotificationAppName(mContext, mPublicNotificationBuilder, true);
283+
SystemUI.overrideNotificationAppName(mContext, mNotificationBuilder, true);
284+
285+
mNotificationManager.notify(SystemMessageProto.SystemMessage.NOTE_GLOBAL_SCREENSHOT,
286+
mNotificationBuilder.build());
287+
}
288+
230289
/**
231290
* Sends a notification that the screenshot capture has failed.
232291
*/

0 commit comments

Comments
 (0)