diff options
author | pliard@chromium.org <pliard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-21 11:37:16 +0000 |
---|---|---|
committer | pliard@chromium.org <pliard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-21 11:37:16 +0000 |
commit | a54d293a94d9876cc9845eb035ee5a462aa1c4ee (patch) | |
tree | bb2bb2c9c07a4ba3804f7a43fe91090f5c105867 /net/android | |
parent | 098889248e162d6c901cec413cd4a47ef802492d (diff) | |
download | chromium_src-a54d293a94d9876cc9845eb035ee5a462aa1c4ee.zip chromium_src-a54d293a94d9876cc9845eb035ee5a462aa1c4ee.tar.gz chromium_src-a54d293a94d9876cc9845eb035ee5a462aa1c4ee.tar.bz2 |
Fix crash in Android NCN due to the use of ActivityStatus.CREATED event.
NetworkChangeNotifierAutoDetect was subscribing to the ActivityStatus.CREATED
event to perform its initialization which seems reasonable. Unfortunately this
event can't be used reliably since its notification is deferred (i.e. observers
are notified a long time after Main.onCreate() is called). This means that the
CREATED event can follow any event including STOPPED which is problematic.
Here is what was happening in this specific case:
Main activity: CREATED -> RESUMED -> PAUSED -> STOPPED -------------> DESTROYED
NetworkChangeNotifierAutoDetect: STOPPED -> CREATED
This is problematic since NetworkChangeNotifierAutoDetect must unregister its
intent receiver before the main activity is destroyed which was impossible in
this case since the last event NCNAutoDetect was seeing before the DESTROYED
event (which it doesn't handle) was CREATED.
One could argue that the correct fix would be to have NCNAutoDetect handle the
DESTROYED event. However clients of ActivityStatus should not have to deal
manually with the DESTROYED event in theory since this event is always
preceded by STOPPED (according to the standard Android activity life cycle
graph). This is only true of course if ActivityStatus follows this life cycle
graph (which it should do) but this is not the case unfortunately for now since
the CREATED event is deferred.
TBR=digit
BUG=176292,176837
Review URL: https://codereview.chromium.org/12321044
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@183790 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/android')
-rw-r--r-- | net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java b/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java index c7fec12..c544365 100644 --- a/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java +++ b/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java @@ -171,13 +171,17 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver // overwritten. mContext = context; } - if (state == ActivityStatus.CREATED) { + if (state == ActivityStatus.RESUMED) { + // Note that this also covers the case where the main activity is created. The CREATED + // event is always followed by the RESUMED event. This is a temporary "hack" until + // http://crbug.com/176837 is fixed. The CREATED event can't be used reliably for now + // since its notification is deferred. This means that it can immediately follow a + // DESTROYED/STOPPED/... event which is problematic. + // TODO(pliard): fix http://crbug.com/176837. + connectionTypeChanged(); registerReceiver(); } else if (state == ActivityStatus.PAUSED) { unregisterReceiver(); - } else if (state == ActivityStatus.RESUMED) { - connectionTypeChanged(); - registerReceiver(); } } |