Commit 30ccb0cb authored by Alex Chau's avatar Alex Chau Committed by Commit Bot

Removed dismiss action in sharing sending notification

Bug: 1001098
Change-Id: I71a8f2c664e6ff525656e48b80f23d1b551f32a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1789383Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarRichard Knoll <knollr@chromium.org>
Reviewed-by: default avatarMichael van Ouwerkerk <mvanouwerkerk@chromium.org>
Commit-Queue: Alex Chau <alexchau@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695606}
parent 58a2bab7
...@@ -1266,8 +1266,6 @@ android:value="true" /> ...@@ -1266,8 +1266,6 @@ android:value="true" />
<receiver android:name="org.chromium.chrome.browser.send_tab_to_self.NotificationManager$TimeoutReceiver" <receiver android:name="org.chromium.chrome.browser.send_tab_to_self.NotificationManager$TimeoutReceiver"
android:exported="false"/> android:exported="false"/>
<receiver android:name="org.chromium.chrome.browser.sharing.SharingNotificationUtil$ActionReceiver"
android:exported="false"/>
<receiver android:name="org.chromium.chrome.browser.sharing.click_to_call.ClickToCallMessageHandler$TapReceiver" <receiver android:name="org.chromium.chrome.browser.sharing.click_to_call.ClickToCallMessageHandler$TapReceiver"
android:exported="false"/> android:exported="false"/>
<receiver android:name="org.chromium.chrome.browser.sharing.shared_clipboard.SharedClipboardMessageHandler$TapReceiver" <receiver android:name="org.chromium.chrome.browser.sharing.shared_clipboard.SharedClipboardMessageHandler$TapReceiver"
......
...@@ -1352,9 +1352,6 @@ ...@@ -1352,9 +1352,6 @@
<receiver <receiver
android:exported="false" android:exported="false"
android:name="org.chromium.chrome.browser.send_tab_to_self.NotificationManager$TimeoutReceiver"/> android:name="org.chromium.chrome.browser.send_tab_to_self.NotificationManager$TimeoutReceiver"/>
<receiver
android:exported="false"
android:name="org.chromium.chrome.browser.sharing.SharingNotificationUtil$ActionReceiver"/>
<receiver <receiver
android:exported="false" android:exported="false"
android:name="org.chromium.chrome.browser.sharing.click_to_call.ClickToCallMessageHandler$TapReceiver"/> android:name="org.chromium.chrome.browser.sharing.click_to_call.ClickToCallMessageHandler$TapReceiver"/>
......
...@@ -91,7 +91,7 @@ public class NotificationUmaTracker { ...@@ -91,7 +91,7 @@ public class NotificationUmaTracker {
ActionType.DOWNLOAD_PAGE_RESUME, ActionType.DOWNLOAD_PAGE_CANCEL, ActionType.DOWNLOAD_PAGE_RESUME, ActionType.DOWNLOAD_PAGE_CANCEL,
ActionType.CONTENT_SUGGESTION_SETTINGS, ActionType.WEB_APP_ACTION_SHARE, ActionType.CONTENT_SUGGESTION_SETTINGS, ActionType.WEB_APP_ACTION_SHARE,
ActionType.WEB_APP_ACTION_OPEN_IN_CHROME, ActionType.WEB_APP_ACTION_OPEN_IN_CHROME,
ActionType.OFFLINE_CONTENT_SUGGESTION_SETTINGS}) ActionType.OFFLINE_CONTENT_SUGGESTION_SETTINGS, ActionType.SHARING_TRY_AGAIN})
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
public @interface ActionType { public @interface ActionType {
int UNKNOWN = -1; int UNKNOWN = -1;
...@@ -116,7 +116,7 @@ public class NotificationUmaTracker { ...@@ -116,7 +116,7 @@ public class NotificationUmaTracker {
// Setting button in offline content suggestion notification. // Setting button in offline content suggestion notification.
int OFFLINE_CONTENT_SUGGESTION_SETTINGS = 9; int OFFLINE_CONTENT_SUGGESTION_SETTINGS = 9;
// Dismiss button on sharing notification. // Dismiss button on sharing notification.
int SHARING_DISMISS = 10; // int SHARING_DISMISS = 10; deprecated
// Try again button on sharing error notification. // Try again button on sharing error notification.
int SHARING_TRY_AGAIN = 11; int SHARING_TRY_AGAIN = 11;
......
...@@ -5,10 +5,7 @@ ...@@ -5,10 +5,7 @@
package org.chromium.chrome.browser.sharing; package org.chromium.chrome.browser.sharing;
import android.app.Notification; import android.app.Notification;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
...@@ -29,42 +26,13 @@ import org.chromium.chrome.browser.notifications.NotificationUmaTracker.SystemNo ...@@ -29,42 +26,13 @@ import org.chromium.chrome.browser.notifications.NotificationUmaTracker.SystemNo
import org.chromium.chrome.browser.notifications.PendingIntentProvider; import org.chromium.chrome.browser.notifications.PendingIntentProvider;
import org.chromium.chrome.browser.notifications.channels.ChannelDefinitions; import org.chromium.chrome.browser.notifications.channels.ChannelDefinitions;
import java.util.HashSet;
/** /**
* Provides common functionality for handling sharing notifications. * Provides common functionality for handling sharing notifications.
*/ */
public final class SharingNotificationUtil { public final class SharingNotificationUtil {
private static final String EXTRA_NOTIFICATION_TAG = "notification_tag";
private static final String EXTRA_NOTIFICATION_ID = "notification_id";
private static final String EXTRA_NOTIFICATION_TOKEN = "notification_token";
private static final int REQUEST_CODE_DISMISS = 100;
// TODO(himanshujaju) - We have only two small icons, one for error and one for non error. We // TODO(himanshujaju) - We have only two small icons, one for error and one for non error. We
// could avoid passing them around. // could avoid passing them around.
private static HashSet<Integer> sDismissedSendingNotifications = new HashSet<>();
private static int sSendingNotificationCount;
/**
* Handles the action of a notification.
*/
public static final class ActionReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Currently only dismiss is supported.
String tag = intent.getStringExtra(EXTRA_NOTIFICATION_TAG);
int id = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1);
int token = intent.getIntExtra(EXTRA_NOTIFICATION_TOKEN, -1);
if (tag == null || id == -1 || token == -1) {
return;
}
new NotificationManagerProxyImpl(context).cancel(tag, id);
sDismissedSendingNotifications.add(token);
}
}
/** /**
* Shows a notification with a configuration common to all sharing notifications. * Shows a notification with a configuration common to all sharing notifications.
* *
...@@ -120,25 +88,13 @@ public final class SharingNotificationUtil { ...@@ -120,25 +88,13 @@ public final class SharingNotificationUtil {
* @param group The notification group. * @param group The notification group.
* @param id The notification id. * @param id The notification id.
* @param targetName The name of target device * @param targetName The name of target device
* @return token of notification created to be used to call {@link #showSendErrorNotification}
*/ */
public static int showSendingNotification( public static void showSendingNotification(
@SystemNotificationType int type, String group, int id, String targetName) { @SystemNotificationType int type, String group, int id, String targetName) {
int token = sSendingNotificationCount;
sSendingNotificationCount++;
Context context = ContextUtils.getApplicationContext(); Context context = ContextUtils.getApplicationContext();
Resources resources = context.getResources(); Resources resources = context.getResources();
PendingIntentProvider dismissIntent =
PendingIntentProvider.getBroadcast(context, REQUEST_CODE_DISMISS,
new Intent(context, ActionReceiver.class)
.putExtra(EXTRA_NOTIFICATION_TAG, group)
.putExtra(EXTRA_NOTIFICATION_ID, id)
.putExtra(EXTRA_NOTIFICATION_TOKEN, token),
PendingIntent.FLAG_UPDATE_CURRENT);
String contentTitle = String contentTitle =
resources.getString(R.string.sharing_sending_notification_title, targetName); resources.getString(R.string.sharing_sending_notification_title, targetName);
String dismissTitle = resources.getString(R.string.sharing_dismiss_action);
ChromeNotificationBuilder builder = ChromeNotificationBuilder builder =
NotificationBuilderFactory NotificationBuilderFactory
.createChromeNotificationBuilder(/*preferCompat=*/true, .createChromeNotificationBuilder(/*preferCompat=*/true,
...@@ -153,16 +109,12 @@ public final class SharingNotificationUtil { ...@@ -153,16 +109,12 @@ public final class SharingNotificationUtil {
.setSmallIcon(R.drawable.ic_devices_16dp) .setSmallIcon(R.drawable.ic_devices_16dp)
.setProgress(/*max=*/0, /*percentage=*/0, true) .setProgress(/*max=*/0, /*percentage=*/0, true)
.setOngoing(true) .setOngoing(true)
.addAction(R.drawable.ic_cancel_circle, dismissTitle, dismissIntent,
NotificationUmaTracker.ActionType.SHARING_DISMISS)
.setDefaults(Notification.DEFAULT_ALL); .setDefaults(Notification.DEFAULT_ALL);
ChromeNotification notification = builder.buildChromeNotification(); ChromeNotification notification = builder.buildChromeNotification();
new NotificationManagerProxyImpl(context).notify(notification); new NotificationManagerProxyImpl(context).notify(notification);
NotificationUmaTracker.getInstance().onNotificationShown( NotificationUmaTracker.getInstance().onNotificationShown(
type, notification.getNotification()); type, notification.getNotification());
return token;
} }
/** /**
...@@ -173,16 +125,11 @@ public final class SharingNotificationUtil { ...@@ -173,16 +125,11 @@ public final class SharingNotificationUtil {
* @param id The notification id. * @param id The notification id.
* @param contentTitle The title of the notification. * @param contentTitle The title of the notification.
* @param contentText The text shown in the notification. * @param contentText The text shown in the notification.
* @param token Token returned from {@link #showSendingNotification}.
* @param tryAgainIntent PendingIntent to try sharing to same device again. * @param tryAgainIntent PendingIntent to try sharing to same device again.
*/ */
public static void showSendErrorNotification(@SystemNotificationType int type, String group, public static void showSendErrorNotification(@SystemNotificationType int type, String group,
int id, String contentTitle, String contentText, int token, int id, String contentTitle, String contentText,
@Nullable PendingIntentProvider tryAgainIntent) { @Nullable PendingIntentProvider tryAgainIntent) {
if (sDismissedSendingNotifications.remove(token)) {
return;
}
Context context = ContextUtils.getApplicationContext(); Context context = ContextUtils.getApplicationContext();
Resources resources = context.getResources(); Resources resources = context.getResources();
ChromeNotificationBuilder builder = ChromeNotificationBuilder builder =
......
...@@ -71,7 +71,7 @@ public class SharedClipboardMessageHandler { ...@@ -71,7 +71,7 @@ public class SharedClipboardMessageHandler {
return; return;
} }
int token = SharingNotificationUtil.showSendingNotification( SharingNotificationUtil.showSendingNotification(
NotificationUmaTracker.SystemNotificationType.SHARED_CLIPBOARD, NotificationUmaTracker.SystemNotificationType.SHARED_CLIPBOARD,
NotificationConstants.GROUP_SHARED_CLIPBOARD, NotificationConstants.GROUP_SHARED_CLIPBOARD,
NotificationConstants.NOTIFICATION_ID_SHARED_CLIPBOARD_OUTGOING, deviceName); NotificationConstants.NOTIFICATION_ID_SHARED_CLIPBOARD_OUTGOING, deviceName);
...@@ -101,7 +101,7 @@ public class SharedClipboardMessageHandler { ...@@ -101,7 +101,7 @@ public class SharedClipboardMessageHandler {
NotificationUmaTracker.SystemNotificationType.SHARED_CLIPBOARD, NotificationUmaTracker.SystemNotificationType.SHARED_CLIPBOARD,
NotificationConstants.GROUP_SHARED_CLIPBOARD, NotificationConstants.GROUP_SHARED_CLIPBOARD,
NotificationConstants.NOTIFICATION_ID_SHARED_CLIPBOARD_OUTGOING, NotificationConstants.NOTIFICATION_ID_SHARED_CLIPBOARD_OUTGOING,
contentTitle, contentText, token, tryAgainIntent); contentTitle, contentText, tryAgainIntent);
} }
}); });
} }
......
...@@ -3861,9 +3861,6 @@ The site does NOT gain access to the camera. The camera images are only visible ...@@ -3861,9 +3861,6 @@ The site does NOT gain access to the camera. The camera images are only visible
<message name="IDS_SHARING_SENDING_NOTIFICATION_TITLE" desc="Title text displayed in a sharing sending notification."> <message name="IDS_SHARING_SENDING_NOTIFICATION_TITLE" desc="Title text displayed in a sharing sending notification.">
Sharing to <ph name="DEVICE_NAME">%1$s<ex>Pixel 3</ex></ph> Sharing to <ph name="DEVICE_NAME">%1$s<ex>Pixel 3</ex></ph>
</message> </message>
<message name="IDS_SHARING_DISMISS_ACTION" desc="Text for action that dismiss a sharing sending notification.">
Dismiss
</message>
<message name="IDS_SHARING_NO_DEVICES_AVAILABLE_TITLE" desc="Text to show when no device targets are available for sharing."> <message name="IDS_SHARING_NO_DEVICES_AVAILABLE_TITLE" desc="Text to show when no device targets are available for sharing.">
Turn on sync to share across devices Turn on sync to share across devices
</message> </message>
......
da0b6aa681f1f02735f8b1f355c734a8c2e8f58e
\ No newline at end of file
...@@ -58779,7 +58779,8 @@ would be helpful to identify which type is being sent. ...@@ -58779,7 +58779,8 @@ would be helpful to identify which type is being sent.
<int value="7" label="Web app action share"/> <int value="7" label="Web app action share"/>
<int value="8" label="Web app action open in Chrome"/> <int value="8" label="Web app action open in Chrome"/>
<int value="9" label="Offline content suggestion settings"/> <int value="9" label="Offline content suggestion settings"/>
<int value="10" label="Sharing notification dismiss button"/> <int value="10"
label="[Deprecated in M79] Sharing notification dismiss button"/>
<int value="11" label="Sharing error notification try again button"/> <int value="11" label="Sharing error notification try again button"/>
</enum> </enum>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment