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

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: UI tweaking and rebase Created 4 years, 4 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
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..4035ab656cdc8792960399abfda51e3aeb009386 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;
@@ -36,6 +37,10 @@ public class MediaCaptureNotificationService extends Service {
private static final String NOTIFICATION_ID_EXTRA = "NotificationId";
private static final String NOTIFICATION_MEDIA_TYPE_EXTRA = "NotificationMediaType";
private static final String NOTIFICATION_MEDIA_URL_EXTRA = "NotificationMediaUrl";
+ private static final String ACTION_MEDIA_CAPTURE_UPDATE =
gone 2016/08/10 19:04:02 nit: Alphabetize these.
braveyao 2016/08/12 23:37:44 Done.
+ "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 WEBRTC_NOTIFICATION_IDS = "WebRTCNotificationIds";
private static final String TAG = "MediaCapture";
@@ -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,25 @@ 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);
+
+ switch (action) {
+ case ACTION_MEDIA_CAPTURE_UPDATE:
+ updateNotification(notificationId, mediaType, url);
+ break;
+
+ case ACTION_SCREEN_CAPTURE_STOP:
+ // Notify native to stop screen capture when the STOP button in notification
+ // is clicked.
+ TabWebContentsDelegateAndroid.notifyStopped(notificationId);
+ break;
+
+ default:
+ break;
+ }
}
return super.onStartCommand(intent, flags, startId);
}
@@ -122,7 +143,7 @@ public class MediaCaptureNotificationService extends Service {
}
destroyNotification(notificationId);
if (mediaType != MEDIATYPE_NO_MEDIA) {
- createNotification(notificationId, mediaType, url);
+ createNotification(notificationId, mediaType, url, true);
}
if (mNotifications.size() == 0) stopSelf();
}
@@ -145,7 +166,7 @@ public class MediaCaptureNotificationService extends Service {
* @param mediaType Media type of the notification.
* @param url Url of the current webrtc call.
*/
- private void createNotification(int notificationId, int mediaType, String url) {
+ private void createNotification(int notificationId, int mediaType, String url, boolean headup) {
int notificationContentTextId = 0;
int notificationIconId = 0;
if (mediaType == MEDIATYPE_AUDIO_AND_VIDEO) {
@@ -157,6 +178,9 @@ public class MediaCaptureNotificationService extends Service {
} else if (mediaType == MEDIATYPE_AUDIO_ONLY) {
notificationContentTextId = R.string.audio_call_notification_text_2;
notificationIconId = R.drawable.webrtc_audio;
+ } else if (mediaType == MEDIATYPE_SCREEN_CAPTURE) {
+ notificationContentTextId = R.string.screen_capture_notification_text;
+ notificationIconId = R.drawable.webrtc_video;
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext)
@@ -166,15 +190,29 @@ public class MediaCaptureNotificationService extends Service {
.setSmallIcon(notificationIconId)
.setLocalOnly(true);
- StringBuilder contentText = new StringBuilder(
- mContext.getResources().getString(notificationContentTextId)).append('.');
+ StringBuilder contentText =
+ new StringBuilder(mContext.getResources().getString(notificationContentTextId, 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) {
+ // To screen capture notification, add Stop action button and enable head up
gone 2016/08/10 19:04:02 1) Add a "Stop" button to the screen capture notif
braveyao 2016/08/12 23:37:43 Done.
+ // notification if needed.
+ if (headup) {
+ // Enable the head up notification.
gone 2016/08/10 19:04:02 nit: Don't need to say that you're enabling the he
braveyao 2016/08/12 23:37:44 Done.
+ builder.setPriority(Notification.PRIORITY_HIGH);
+ builder.setVibrate(new long[0]);
+ }
+ builder.addAction(R.drawable.ic_vidcontrol_stop, "Stop",
+ buildPendingIntent(ACTION_SCREEN_CAPTURE_STOP, notificationId, mediaType,
+ url));
+ } else {
+ contentText.append(mContext.getResources().getString(
+ R.string.media_notification_link_text, url));
+ }
} else {
contentText.append(" ").append(url);
}
@@ -227,10 +265,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;
@@ -264,10 +305,10 @@ public class MediaCaptureNotificationService extends Service {
* @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 +334,18 @@ public class MediaCaptureNotificationService extends Service {
context.startService(new Intent(context, MediaCaptureNotificationService.class));
}
+
+ /**
+ * Build PendingIntent for the actions of screen capture notification.
+ */
+ private PendingIntent buildPendingIntent(
+ String action, int notificationId, int mediaType, String url) {
+ Intent intent = new Intent(this, MediaCaptureNotificationService.class);
+ intent.setAction(action);
+ intent.putExtra(NOTIFICATION_ID_EXTRA, notificationId);
+ intent.putExtra(NOTIFICATION_MEDIA_TYPE_EXTRA, mediaType);
+ intent.putExtra(NOTIFICATION_MEDIA_URL_EXTRA, url);
+ return PendingIntent.getService(
+ mContext, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
+ }
}

Powered by Google App Engine
This is Rietveld 408576698