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

Side by Side Diff: net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java

Issue 11419287: android: Improve ActivityStatus and add ChromiumActivity. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.net; 5 package org.chromium.net;
6 6
7 import android.content.BroadcastReceiver; 7 import android.content.BroadcastReceiver;
8 import android.content.Context; 8 import android.content.Context;
9 import android.content.Intent; 9 import android.content.Intent;
10 import android.content.IntentFilter; 10 import android.content.IntentFilter;
11 import android.net.ConnectivityManager; 11 import android.net.ConnectivityManager;
12 import android.net.NetworkInfo; 12 import android.net.NetworkInfo;
13 import android.telephony.TelephonyManager; 13 import android.telephony.TelephonyManager;
14 import android.util.Log; 14 import android.util.Log;
15 15
16 import org.chromium.base.ActivityStatus; 16 import org.chromium.base.ActivityStatus;
17 17
18 /** 18 /**
19 * Used by the NetworkChangeNotifier to listens to platform changes in connectiv ity. 19 * Used by the NetworkChangeNotifier to listens to platform changes in connectiv ity.
20 * Note that use of this class requires that the app have the platform 20 * Note that use of this class requires that the app have the platform
21 * ACCESS_NETWORK_STATE permission. 21 * ACCESS_NETWORK_STATE permission.
22 */ 22 */
23 public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver 23 public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver
24 implements ActivityStatus.Listener { 24 implements ActivityStatus.StateListener {
25 25
26 /** Queries the ConnectivityManager for information about the current connec tion. */ 26 /** Queries the ConnectivityManager for information about the current connec tion. */
27 static class ConnectivityManagerDelegate { 27 static class ConnectivityManagerDelegate {
28 private ConnectivityManager mConnectivityManager; 28 private ConnectivityManager mConnectivityManager;
29 29
30 ConnectivityManagerDelegate(Context context) { 30 ConnectivityManagerDelegate(Context context) {
31 if (context != null) { 31 if (context != null) {
32 mConnectivityManager = (ConnectivityManager) 32 mConnectivityManager = (ConnectivityManager)
33 context.getSystemService(Context.CONNECTIVITY_SERVICE); 33 context.getSystemService(Context.CONNECTIVITY_SERVICE);
34 } 34 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 public static interface Observer { 66 public static interface Observer {
67 public void onConnectionTypeChanged(int newConnectionType); 67 public void onConnectionTypeChanged(int newConnectionType);
68 } 68 }
69 69
70 public NetworkChangeNotifierAutoDetect(Observer observer, Context context) { 70 public NetworkChangeNotifierAutoDetect(Observer observer, Context context) {
71 mObserver = observer; 71 mObserver = observer;
72 mContext = context; 72 mContext = context;
73 mConnectivityManagerDelegate = new ConnectivityManagerDelegate(context); 73 mConnectivityManagerDelegate = new ConnectivityManagerDelegate(context);
74 mConnectionType = currentConnectionType(context); 74 mConnectionType = currentConnectionType(context);
75 75
76 ActivityStatus status = ActivityStatus.getInstance(); 76 if (ActivityStatus.getState() != ActivityStatus.PAUSED) {
digit1 2012/12/04 15:41:55 Same remark here, do we really want to stop this o
77 if (!status.isPaused()) {
78 registerReceiver(); 77 registerReceiver();
79 } 78 }
80 status.registerListener(this); 79 ActivityStatus.registerStateListener(this);
81 } 80 }
82 81
83 /** 82 /**
84 * Allows overriding the ConnectivityManagerDelegate for tests. 83 * Allows overriding the ConnectivityManagerDelegate for tests.
85 */ 84 */
86 void setConnectivityManagerDelegateForTests(ConnectivityManagerDelegate dele gate) { 85 void setConnectivityManagerDelegateForTests(ConnectivityManagerDelegate dele gate) {
87 mConnectivityManagerDelegate = delegate; 86 mConnectivityManagerDelegate = delegate;
88 } 87 }
89 88
90 public void destroy() { 89 public void destroy() {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 int newConnectionType = noConnection ? 160 int newConnectionType = noConnection ?
162 NetworkChangeNotifier.CONNECTION_NONE : currentConnectionType(co ntext); 161 NetworkChangeNotifier.CONNECTION_NONE : currentConnectionType(co ntext);
163 162
164 if (newConnectionType != mConnectionType) { 163 if (newConnectionType != mConnectionType) {
165 mConnectionType = newConnectionType; 164 mConnectionType = newConnectionType;
166 Log.d(TAG, "Network connectivity changed, type is: " + mConnectionTy pe); 165 Log.d(TAG, "Network connectivity changed, type is: " + mConnectionTy pe);
167 mObserver.onConnectionTypeChanged(newConnectionType); 166 mObserver.onConnectionTypeChanged(newConnectionType);
168 } 167 }
169 } 168 }
170 169
171 // AcitivityStatus.Listener 170 // ActivityStatus.StateListener
172 @Override 171 @Override
173 public void onActivityStatusChanged(boolean isPaused) { 172 public void onActivityStateChange(int state) {
174 if (isPaused) { 173 if (state == ActivityStatus.PAUSED) {
175 unregisterReceiver(); 174 unregisterReceiver();
176 } else { 175 } else if (state == ActivityStatus.RESUMED) {
177 registerReceiver(); 176 registerReceiver();
178 } 177 }
179 } 178 }
180 179
181 private static class NetworkConnectivityIntentFilter extends IntentFilter { 180 private static class NetworkConnectivityIntentFilter extends IntentFilter {
182 NetworkConnectivityIntentFilter() { 181 NetworkConnectivityIntentFilter() {
183 addAction(ConnectivityManager.CONNECTIVITY_ACTION); 182 addAction(ConnectivityManager.CONNECTIVITY_ACTION);
184 } 183 }
185 } 184 }
186 } 185 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698