Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1070)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/media/MediaCaptureNotificationService.java

Issue 2123863004: ScreenCapture for Android phase1, part II (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/tab/TabWebContentsDelegateAndroid.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/media/MediaCaptureNotificationService.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/media/MediaCaptureNotificationService.java b/chrome/android/java/src/org/chromium/chrome/browser/media/MediaCaptureNotificationService.java
index 44e8838341b16c7dc730d63d857e565bf488c85d..f58c47939ca2446b90624df0e601d86a54658797 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/media/MediaCaptureNotificationService.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/media/MediaCaptureNotificationService.java
@@ -19,6 +19,7 @@ import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.tab.Tab;
+import org.chromium.chrome.browser.tab.TabWebContentsDelegateAndroid;
import java.net.MalformedURLException;
import java.net.URL;
@@ -30,6 +31,10 @@ import java.util.Set;
* Service that creates/destroys the WebRTC notification when media capture starts/stops.
*/
public class MediaCaptureNotificationService extends Service {
+ private static final String ACTION_MEDIA_CAPTURE_UPDATE =
+ "org.chromium.chrome.browser.media.SCREEN_CAPTURE_UPDATE";
+ private static final String ACTION_SCREEN_CAPTURE_STOP =
+ "org.chromium.chrome.browser.media.SCREEN_CAPTURE_STOP";
private static final String NOTIFICATION_NAMESPACE = "MediaCaptureNotificationService";
@@ -44,6 +49,7 @@ public class MediaCaptureNotificationService extends Service {
private static final int MEDIATYPE_AUDIO_AND_VIDEO = 1;
private static final int MEDIATYPE_VIDEO_ONLY = 2;
private static final int MEDIATYPE_AUDIO_ONLY = 3;
+ private static final int MEDIATYPE_SCREEN_CAPTURE = 4;
private NotificationManager mNotificationManager;
private Context mContext;
@@ -83,10 +89,18 @@ public class MediaCaptureNotificationService extends Service {
cancelPreviousWebRtcNotifications();
stopSelf();
} else {
- updateNotification(
- intent.getIntExtra(NOTIFICATION_ID_EXTRA, Tab.INVALID_TAB_ID),
- intent.getIntExtra(NOTIFICATION_MEDIA_TYPE_EXTRA, MEDIATYPE_NO_MEDIA),
- intent.getStringExtra(NOTIFICATION_MEDIA_URL_EXTRA));
+ String action = intent.getAction();
+ int notificationId = intent.getIntExtra(NOTIFICATION_ID_EXTRA, Tab.INVALID_TAB_ID);
+ int mediaType = intent.getIntExtra(NOTIFICATION_MEDIA_TYPE_EXTRA, MEDIATYPE_NO_MEDIA);
+ String url = intent.getStringExtra(NOTIFICATION_MEDIA_URL_EXTRA);
+
+ if (ACTION_MEDIA_CAPTURE_UPDATE.equals(action)) {
+ updateNotification(notificationId, mediaType, url);
+ } else if (ACTION_SCREEN_CAPTURE_STOP.equals(action)) {
+ // Notify native to stop screen capture when the STOP button in notification
+ // is clicked.
+ TabWebContentsDelegateAndroid.notifyStopped(notificationId);
+ }
}
return super.onStartCommand(intent, flags, startId);
}
@@ -146,35 +160,33 @@ public class MediaCaptureNotificationService extends Service {
* @param url Url of the current webrtc call.
*/
private void createNotification(int notificationId, int mediaType, String url) {
- int notificationContentTextId = 0;
- int notificationIconId = 0;
- if (mediaType == MEDIATYPE_AUDIO_AND_VIDEO) {
- notificationContentTextId = R.string.video_audio_call_notification_text_2;
- notificationIconId = R.drawable.webrtc_video;
- } else if (mediaType == MEDIATYPE_VIDEO_ONLY) {
- notificationContentTextId = R.string.video_call_notification_text_2;
- notificationIconId = R.drawable.webrtc_video;
- } else if (mediaType == MEDIATYPE_AUDIO_ONLY) {
- notificationContentTextId = R.string.audio_call_notification_text_2;
- notificationIconId = R.drawable.webrtc_audio;
- }
+ NotificationCompat.Builder builder =
+ new NotificationCompat.Builder(mContext)
+ .setAutoCancel(false)
+ .setOngoing(true)
+ .setContentTitle(mContext.getString(R.string.app_name))
+ .setSmallIcon(getNotificationIconId(mediaType))
+ .setLocalOnly(true);
- NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext)
- .setAutoCancel(false)
- .setOngoing(true)
- .setContentTitle(mContext.getString(R.string.app_name))
- .setSmallIcon(notificationIconId)
- .setLocalOnly(true);
-
- StringBuilder contentText = new StringBuilder(
- mContext.getResources().getString(notificationContentTextId)).append('.');
+ StringBuilder contentText =
+ new StringBuilder(getNotificationContentText(mediaType, url)).append('.');
Intent tabIntent = Tab.createBringTabToFrontIntent(notificationId);
if (tabIntent != null) {
PendingIntent contentIntent = PendingIntent.getActivity(
mContext, notificationId, tabIntent, 0);
builder.setContentIntent(contentIntent);
- contentText.append(
- mContext.getResources().getString(R.string.media_notification_link_text, url));
+ if (mediaType == MEDIATYPE_SCREEN_CAPTURE) {
+ // Add a "Stop" button to the screen capture notification and turn the notification
+ // into a high priority one.
+ builder.setPriority(Notification.PRIORITY_HIGH);
+ builder.setVibrate(new long[0]);
+ builder.addAction(R.drawable.ic_vidcontrol_stop,
+ mContext.getResources().getString(R.string.accessibility_stop),
+ buildStopCapturePendingIntent(notificationId));
+ } else {
+ contentText.append(mContext.getResources().getString(
+ R.string.media_notification_link_text, url));
+ }
} else {
contentText.append(" ").append(url);
}
@@ -188,6 +200,48 @@ public class MediaCaptureNotificationService extends Service {
}
/**
+ * Builds notification content text for the provided mediaType and url.
+ * @param mediaType Media type of the notification.
+ * @param url Url of the current webrtc call.
+ * @return A string builder initialized to the contents of the specified string.
+ */
+ private String getNotificationContentText(int mediaType, String url) {
+ if (mediaType == MEDIATYPE_SCREEN_CAPTURE) {
+ return mContext.getResources().getString(
+ R.string.screen_capture_notification_text, url);
+ }
+
+ int notificationContentTextId = 0;
+ if (mediaType == MEDIATYPE_AUDIO_AND_VIDEO) {
+ notificationContentTextId = R.string.video_audio_call_notification_text_2;
+ } else if (mediaType == MEDIATYPE_VIDEO_ONLY) {
+ notificationContentTextId = R.string.video_call_notification_text_2;
+ } else if (mediaType == MEDIATYPE_AUDIO_ONLY) {
+ notificationContentTextId = R.string.audio_call_notification_text_2;
+ }
+
+ return mContext.getResources().getString(notificationContentTextId);
+ }
+
+ /**
+ * @param mediaType Media type of the notification.
+ * @return An icon id of the provided mediaType.
+ */
+ private int getNotificationIconId(int mediaType) {
+ int notificationIconId = 0;
+ if (mediaType == MEDIATYPE_AUDIO_AND_VIDEO) {
+ notificationIconId = R.drawable.webrtc_video;
+ } else if (mediaType == MEDIATYPE_VIDEO_ONLY) {
+ notificationIconId = R.drawable.webrtc_video;
+ } else if (mediaType == MEDIATYPE_AUDIO_ONLY) {
+ notificationIconId = R.drawable.webrtc_audio;
+ } else if (mediaType == MEDIATYPE_SCREEN_CAPTURE) {
+ notificationIconId = R.drawable.webrtc_video;
+ }
+ return notificationIconId;
+ }
+
+ /**
* Update shared preferences entry with ids of the visible notifications.
* @param notificationId Id of the notification.
* @param remove Boolean describing if the notification was added or removed.
@@ -227,10 +281,13 @@ public class MediaCaptureNotificationService extends Service {
/**
* @param audio If audio is being captured.
* @param video If video is being captured.
+ * @param screen If screen is being captured.
* @return A constant identify what media is being captured.
*/
- public static int getMediaType(boolean audio, boolean video) {
- if (audio && video) {
+ public static int getMediaType(boolean audio, boolean video, boolean screen) {
+ if (screen) {
+ return MEDIATYPE_SCREEN_CAPTURE;
+ } else if (audio && video) {
return MEDIATYPE_AUDIO_AND_VIDEO;
} else if (audio) {
return MEDIATYPE_AUDIO_ONLY;
@@ -259,15 +316,14 @@ public class MediaCaptureNotificationService extends Service {
* Send an intent to MediaCaptureNotificationService to either create, update or destroy the
* notification identified by tabId.
* @param tabId Unique notification id.
- * @param audio If audio is being captured.
- * @param video If video is being captured.
+ * @param mediaType The media type that is being captured.
* @param fullUrl Url of the current webrtc call.
*/
public static void updateMediaNotificationForTab(
- Context context, int tabId, boolean audio, boolean video, String fullUrl) {
- int mediaType = getMediaType(audio, video);
+ Context context, int tabId, int mediaType, String fullUrl) {
if (!shouldStartService(context, mediaType, tabId)) return;
Intent intent = new Intent(context, MediaCaptureNotificationService.class);
+ intent.setAction(ACTION_MEDIA_CAPTURE_UPDATE);
intent.putExtra(NOTIFICATION_ID_EXTRA, tabId);
String baseUrl = fullUrl;
try {
@@ -293,4 +349,15 @@ public class MediaCaptureNotificationService extends Service {
context.startService(new Intent(context, MediaCaptureNotificationService.class));
}
+
+ /**
+ * Build PendingIntent for the actions of screen capture notification.
+ */
+ private PendingIntent buildStopCapturePendingIntent(int notificationId) {
+ Intent intent = new Intent(this, MediaCaptureNotificationService.class);
+ intent.setAction(ACTION_SCREEN_CAPTURE_STOP);
+ intent.putExtra(NOTIFICATION_ID_EXTRA, notificationId);
+ return PendingIntent.getService(
+ mContext, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
+ }
}
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/tab/TabWebContentsDelegateAndroid.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698