Skip to content

Commit

Permalink
Make CastWebContentsService foreground when playing audio.
Browse files Browse the repository at this point in the history
When the CastWebContentsService plays audio, we need to make it a
foreground service so the sandbox process doesn't get killed by the OOM
killer.

Bug: 68138999
Test: manual test on device: sandboxed process isn't cached when we
casting

Change-Id: Ief340684ca77fada6badb580922b97fffa1cdb55
Reviewed-on: https://chromium-review.googlesource.com/738621
Reviewed-by: Luke Halliwell <halliwell@chromium.org>
Commit-Queue: Ralph Nathan <ralphnathan@google.com>
Cr-Commit-Position: refs/heads/master@{#511743}
  • Loading branch information
Ralph Nathan authored and Commit Bot committed Oct 26, 2017
1 parent ebca331 commit 36612e2
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package org.chromium.chromecast.shell;

import android.app.Notification;
import android.app.Service;
import android.content.Intent;
import android.media.AudioManager;
Expand All @@ -28,6 +29,7 @@
public class CastWebContentsService extends Service {
private static final String TAG = "cr_CastWebService";
private static final boolean DEBUG = true;
private static final int CAST_NOTIFICATION_ID = 100;

private String mInstanceId;
private AudioManager mAudioManager;
Expand Down Expand Up @@ -94,6 +96,9 @@ public IBinder onBind(Intent intent) {
private void showWebContents(WebContents webContents) {
if (DEBUG) Log.d(TAG, "showWebContents");

Notification notification = new Notification.Builder(this).build();
startForeground(CAST_NOTIFICATION_ID, notification);

// TODO(derekjchow): productVersion
mContentViewCore = new ContentViewCore(this, "");
mContentView = ContentView.createContentView(this, mContentViewCore);
Expand All @@ -106,6 +111,9 @@ private void showWebContents(WebContents webContents) {
// Remove the currently displayed webContents. no-op if nothing is being displayed.
private void detachWebContentsIfAny() {
if (DEBUG) Log.d(TAG, "detachWebContentsIfAny");

stopForeground(true /*removeNotification*/ );

if (mContentView != null) {
mContentView = null;
mContentViewCore = null;
Expand Down

0 comments on commit 36612e2

Please sign in to comment.