Commit fbda2224 authored by byungchul's avatar byungchul Committed by Commit bot

Finish gracefully on stop events, but not on pause events.

On some circumstances, pause events are generated several times during start up.
Since current implementation finishes CastShellActivity on pause events, the
app doesn't start unexpectedly.

BUG=425812

Review URL: https://codereview.chromium.org/668053003

Cr-Commit-Position: refs/heads/master@{#300714}
parent 498174e9
...@@ -31,11 +31,12 @@ import org.chromium.ui.base.WindowAndroid; ...@@ -31,11 +31,12 @@ import org.chromium.ui.base.WindowAndroid;
*/ */
public class CastShellActivity extends Activity { public class CastShellActivity extends Activity {
private static final String TAG = "CastShellActivity"; private static final String TAG = "CastShellActivity";
private static final boolean DEBUG = false;
private static final String ACTIVE_SHELL_URL_KEY = "activeUrl"; private static final String ACTIVE_SHELL_URL_KEY = "activeUrl";
private static final int DEFAULT_HEIGHT_PIXELS = 720; private static final int DEFAULT_HEIGHT_PIXELS = 720;
public static final String ACTION_EXTRA_RESOLUTION_HEIGHT = public static final String ACTION_EXTRA_RESOLUTION_HEIGHT =
"org.chromium.chromecast.shell.intent.extra.RESOLUTION_HEIGHT"; "org.chromium.chromecast.shell.intent.extra.RESOLUTION_HEIGHT";
private CastWindowManager mCastWindowManager; private CastWindowManager mCastWindowManager;
private AudioManager mAudioManager; private AudioManager mAudioManager;
...@@ -57,6 +58,7 @@ public class CastShellActivity extends Activity { ...@@ -57,6 +58,7 @@ public class CastShellActivity extends Activity {
@Override @Override
protected void onCreate(final Bundle savedInstanceState) { protected void onCreate(final Bundle savedInstanceState) {
if (DEBUG) Log.d(TAG, "onCreate");
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
exitIfUrlMissing(); exitIfUrlMissing();
...@@ -115,7 +117,7 @@ public class CastShellActivity extends Activity { ...@@ -115,7 +117,7 @@ public class CastShellActivity extends Activity {
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); if (DEBUG) Log.d(TAG, "onDestroy");
unregisterBroadcastReceiver(); unregisterBroadcastReceiver();
...@@ -123,10 +125,13 @@ public class CastShellActivity extends Activity { ...@@ -123,10 +125,13 @@ public class CastShellActivity extends Activity {
mCastWindowManager.stopCastWindow(mNativeCastWindow, false /* gracefully */); mCastWindowManager.stopCastWindow(mNativeCastWindow, false /* gracefully */);
mNativeCastWindow = 0; mNativeCastWindow = 0;
} }
super.onDestroy();
} }
@Override @Override
protected void onNewIntent(Intent intent) { protected void onNewIntent(Intent intent) {
if (DEBUG) Log.d(TAG, "onNewIntent");
// Only handle direct intents (e.g. "fling") if this activity is also managing // Only handle direct intents (e.g. "fling") if this activity is also managing
// the browser process. // the browser process.
if (!shouldLaunchBrowser()) return; if (!shouldLaunchBrowser()) return;
...@@ -140,8 +145,24 @@ public class CastShellActivity extends Activity { ...@@ -140,8 +145,24 @@ public class CastShellActivity extends Activity {
getActiveCastWindow().loadUrl(url); getActiveCastWindow().loadUrl(url);
} }
@Override
protected void onStart() {
if (DEBUG) Log.d(TAG, "onStart");
super.onStart();
}
@Override
protected void onStop() {
if (DEBUG) Log.d(TAG, "onStop");
// As soon as the cast app is no longer in the foreground, we ought to immediately tear
// everything down.
finishGracefully();
super.onStop();
}
@Override @Override
protected void onResume() { protected void onResume() {
if (DEBUG) Log.d(TAG, "onResume");
super.onResume(); super.onResume();
// Inform ContentView that this activity is being shown. // Inform ContentView that this activity is being shown.
...@@ -158,9 +179,7 @@ public class CastShellActivity extends Activity { ...@@ -158,9 +179,7 @@ public class CastShellActivity extends Activity {
@Override @Override
protected void onPause() { protected void onPause() {
// As soon as the cast app is no longer in the foreground, we ought to immediately tear if (DEBUG) Log.d(TAG, "onPause");
// everything down. Apps should not continue running and playing sound in the background.
super.onPause();
// Release the audio focus. Note that releasing audio focus does not stop audio playback, // Release the audio focus. Note that releasing audio focus does not stop audio playback,
// it just notifies the framework that this activity has stopped playing audio. // it just notifies the framework that this activity has stopped playing audio.
...@@ -171,7 +190,7 @@ public class CastShellActivity extends Activity { ...@@ -171,7 +190,7 @@ public class CastShellActivity extends Activity {
ContentViewCore view = getActiveContentViewCore(); ContentViewCore view = getActiveContentViewCore();
if (view != null) view.onHide(); if (view != null) view.onHide();
finishGracefully(); super.onPause();
} }
protected void finishGracefully() { protected void finishGracefully() {
...@@ -229,7 +248,7 @@ public class CastShellActivity extends Activity { ...@@ -229,7 +248,7 @@ public class CastShellActivity extends Activity {
} }
// Log an exception so that the exit cause is obvious when reading the logs. // Log an exception so that the exit cause is obvious when reading the logs.
Log.e(TAG, "Activity will not start", Log.e(TAG, "Activity will not start",
new IllegalArgumentException("Intent did not contain a valid url")); new IllegalArgumentException("Intent did not contain a valid url"));
System.exit(-1); System.exit(-1);
} }
......
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