diff options
author | jcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-12 16:07:30 +0000 |
---|---|---|
committer | jcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-12 16:07:30 +0000 |
commit | ea3420f48a9eaf1d6268eaa7f0003866524079a4 (patch) | |
tree | ef6f920dfc120de9e2a143aa5fe5a231ece966a2 /net/android | |
parent | 8d8e18a3ae07fd1dc070b5c65b6f27cccf602998 (diff) | |
download | chromium_src-ea3420f48a9eaf1d6268eaa7f0003866524079a4.zip chromium_src-ea3420f48a9eaf1d6268eaa7f0003866524079a4.tar.gz chromium_src-ea3420f48a9eaf1d6268eaa7f0003866524079a4.tar.bz2 |
NetworkChangeNotifier now supports changes when in the background.
NetworkChangeNotifier would not send notification if a notification happened
while the embedder activity was in the background.
It now notifies when the activity is brought back to the foreground if a change
happened while it was in the background.
BUG=152710
TEST=Run the instrumentation tests.
Review URL: https://chromiumcodereview.appspot.com/11778115
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176534 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/android')
-rw-r--r-- | net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java | 17 | ||||
-rw-r--r-- | net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java | 18 |
2 files changed, 29 insertions, 6 deletions
diff --git a/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java b/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java index 8d953f2..8310e8f 100644 --- a/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java +++ b/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java @@ -163,12 +163,7 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver // BroadcastReceiver @Override public void onReceive(Context context, Intent intent) { - int newConnectionType = getCurrentConnectionType(); - if (newConnectionType != mConnectionType) { - mConnectionType = newConnectionType; - Log.d(TAG, "Network connectivity changed, type is: " + mConnectionType); - mObserver.onConnectionTypeChanged(newConnectionType); - } + connectionTypeChanged(); } // ActivityStatus.StateListener @@ -177,10 +172,20 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver if (state == ActivityStatus.PAUSED) { unregisterReceiver(); } else if (state == ActivityStatus.RESUMED) { + connectionTypeChanged(); registerReceiver(); } } + private void connectionTypeChanged() { + int newConnectionType = getCurrentConnectionType(); + if (newConnectionType == mConnectionType) return; + + mConnectionType = newConnectionType; + Log.d(TAG, "Network connectivity changed, type is: " + mConnectionType); + mObserver.onConnectionTypeChanged(newConnectionType); + } + private static class NetworkConnectivityIntentFilter extends IntentFilter { NetworkConnectivityIntentFilter() { addAction(ConnectivityManager.CONNECTIVITY_ACTION); diff --git a/net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java b/net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java index 0bea726..b52d184 100644 --- a/net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java +++ b/net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java @@ -12,6 +12,7 @@ import android.test.InstrumentationTestCase; import android.test.UiThreadTest; import android.test.suitebuilder.annotation.MediumTest; +import org.chromium.base.ActivityStatus; import org.chromium.base.test.util.Feature; public class NetworkChangeNotifierTest extends InstrumentationTestCase { @@ -22,6 +23,7 @@ public class NetworkChangeNotifierTest extends InstrumentationTestCase { implements NetworkChangeNotifier.ConnectionTypeObserver { private boolean mReceivedNotification = false; + @Override public void onConnectionTypeChanged(int connectionType) { mReceivedNotification = true; } @@ -29,6 +31,10 @@ public class NetworkChangeNotifierTest extends InstrumentationTestCase { public boolean hasReceivedNotification() { return mReceivedNotification; } + + public void resetHasReceivedNotification() { + mReceivedNotification = false; + } } /** @@ -112,5 +118,17 @@ public class NetworkChangeNotifierTest extends InstrumentationTestCase { Intent noConnectivityIntent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION); receiver.onReceive(getInstrumentation().getTargetContext(), noConnectivityIntent); assertTrue(observer.hasReceivedNotification()); + + observer.resetHasReceivedNotification(); + // Pretend we got moved to the background. + receiver.onActivityStateChange(ActivityStatus.PAUSED); + // Change the state. + connectivityDelegate.setActiveNetworkExists(true); + connectivityDelegate.setNetworkType(NetworkChangeNotifier.CONNECTION_WIFI); + // The NetworkChangeNotifierAutoDetect doesn't receive any notification while we are in the + // background, but when we get back to the foreground the state changed should be detected + // and a notification sent. + receiver.onActivityStateChange(ActivityStatus.RESUMED); + assertTrue(observer.hasReceivedNotification()); } } |