• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

frameworks/base


Commit MetaInfo

Revision090df1dc4188e5b9ef10a0aca5081a196085ff56 (tree)
Time2011-08-05 08:10:11
AuthorWink Saville <wink@goog...>
CommiterAndroid (Google) Code Review

Log Message

Merge "Delay connectivity change notifications." into honeycomb-LTE

Change Summary

Incremental Difference

--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -3023,6 +3023,18 @@ public final class Settings {
30233023 public static final String TTY_MODE_ENABLED = "tty_mode_enabled";
30243024
30253025 /**
3026+ * The number of milliseconds to delay before sending out Connectivyt Change broadcasts
3027+ * @hide
3028+ */
3029+ public static final String CONNECTIVITY_CHANGE_DELAY = "connectivity_change_delay";
3030+
3031+ /**
3032+ * Default value for CONNECTIVITY_CHANGE_DELAY in milliseconds.
3033+ * @hide
3034+ */
3035+ public static final int CONNECTIVITY_CHANGE_DELAY_DEFAULT = 3000;
3036+
3037+ /**
30263038 * Controls whether settings backup is enabled.
30273039 * Type: int ( 0 = disabled, 1 = enabled )
30283040 * @hide
--- a/services/java/com/android/server/ConnectivityService.java
+++ b/services/java/com/android/server/ConnectivityService.java
@@ -216,6 +216,12 @@ public class ConnectivityService extends IConnectivityManager.Stub {
216216 private static final int EVENT_SET_DEPENDENCY_MET =
217217 MAX_NETWORK_STATE_TRACKER_EVENT + 10;
218218
219+ /**
220+ * used internally to send a sticky broadcast delayed.
221+ */
222+ private static final int EVENT_SEND_STICKY_BROADCAST_INTENT =
223+ MAX_NETWORK_STATE_TRACKER_EVENT + 11;
224+
219225 private Handler mHandler;
220226
221227 // list of DeathRecipients used to make sure features are turned off when
@@ -511,6 +517,17 @@ public class ConnectivityService extends IConnectivityManager.Stub {
511517 }
512518 }
513519
520+ private int getConnectivityChangeDelay() {
521+ final ContentResolver cr = mContext.getContentResolver();
522+
523+ /** Check system properties for the default value then use secure settings value, if any. */
524+ int defaultDelay = SystemProperties.getInt(
525+ "conn." + Settings.Secure.CONNECTIVITY_CHANGE_DELAY,
526+ Settings.Secure.CONNECTIVITY_CHANGE_DELAY_DEFAULT);
527+ return Settings.Secure.getInt(cr, Settings.Secure.CONNECTIVITY_CHANGE_DELAY,
528+ defaultDelay);
529+ }
530+
514531 private int getPersistedNetworkPreference() {
515532 final ContentResolver cr = mContext.getContentResolver();
516533
@@ -1243,13 +1260,14 @@ public class ConnectivityService extends IConnectivityManager.Stub {
12431260 // do this before we broadcast the change
12441261 handleConnectivityChange(prevNetType, doReset);
12451262
1246- sendStickyBroadcast(intent);
1263+ sendStickyBroadcastDelayed(intent, getConnectivityChangeDelay());
12471264 /*
12481265 * If the failover network is already connected, then immediately send
12491266 * out a followup broadcast indicating successful failover
12501267 */
12511268 if (mActiveDefaultNetwork != -1) {
1252- sendConnectedBroadcast(mNetTrackers[mActiveDefaultNetwork].getNetworkInfo());
1269+ sendConnectedBroadcastDelayed(mNetTrackers[mActiveDefaultNetwork].getNetworkInfo(),
1270+ getConnectivityChangeDelay());
12531271 }
12541272 }
12551273
@@ -1303,11 +1321,15 @@ public class ConnectivityService extends IConnectivityManager.Stub {
13031321 sendGeneralBroadcast(info, ConnectivityManager.CONNECTIVITY_ACTION);
13041322 }
13051323
1324+ private void sendConnectedBroadcastDelayed(NetworkInfo info, int delayMs) {
1325+ sendGeneralBroadcastDelayed(info, ConnectivityManager.CONNECTIVITY_ACTION, delayMs);
1326+ }
1327+
13061328 private void sendInetConditionBroadcast(NetworkInfo info) {
13071329 sendGeneralBroadcast(info, ConnectivityManager.INET_CONDITION_ACTION);
13081330 }
13091331
1310- private void sendGeneralBroadcast(NetworkInfo info, String bcastType) {
1332+ private Intent makeGeneralIntent(NetworkInfo info, String bcastType) {
13111333 Intent intent = new Intent(bcastType);
13121334 intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, info);
13131335 if (info.isFailover()) {
@@ -1322,7 +1344,15 @@ public class ConnectivityService extends IConnectivityManager.Stub {
13221344 info.getExtraInfo());
13231345 }
13241346 intent.putExtra(ConnectivityManager.EXTRA_INET_CONDITION, mDefaultInetConditionPublished);
1325- sendStickyBroadcast(intent);
1347+ return intent;
1348+ }
1349+
1350+ private void sendGeneralBroadcast(NetworkInfo info, String bcastType) {
1351+ sendStickyBroadcast(makeGeneralIntent(info, bcastType));
1352+ }
1353+
1354+ private void sendGeneralBroadcastDelayed(NetworkInfo info, String bcastType, int delayMs) {
1355+ sendStickyBroadcastDelayed(makeGeneralIntent(info, bcastType), delayMs);
13261356 }
13271357
13281358 /**
@@ -1387,10 +1417,25 @@ public class ConnectivityService extends IConnectivityManager.Stub {
13871417 mInitialBroadcast = new Intent(intent);
13881418 }
13891419 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
1420+ if (DBG) {
1421+ log("sendStickyBroadcast: NetworkInfo=" +
1422+ intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO));
1423+ }
1424+
13901425 mContext.sendStickyBroadcast(intent);
13911426 }
13921427 }
13931428
1429+ private void sendStickyBroadcastDelayed(Intent intent, int delayMs) {
1430+ if (delayMs <= 0) {
1431+ sendStickyBroadcast(intent);
1432+ } else {
1433+ if (DBG) log("sendStickyBroadcastDelayed: delayMs=" + delayMs + " intent=" + intent);
1434+ mHandler.sendMessageDelayed(mHandler.obtainMessage(
1435+ EVENT_SEND_STICKY_BROADCAST_INTENT, intent), delayMs);
1436+ }
1437+ }
1438+
13941439 void systemReady() {
13951440 IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
13961441 mNetd = INetworkManagementService.Stub.asInterface(b);
@@ -1466,7 +1511,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
14661511 thisNet.setTeardownRequested(false);
14671512 updateNetworkSettings(thisNet);
14681513 handleConnectivityChange(type, false);
1469- sendConnectedBroadcast(info);
1514+ sendConnectedBroadcastDelayed(info, getConnectivityChangeDelay());
14701515 }
14711516
14721517 /**
@@ -2036,6 +2081,13 @@ public class ConnectivityService extends IConnectivityManager.Stub {
20362081 handleSetDependencyMet(msg.arg2, met);
20372082 break;
20382083 }
2084+ case EVENT_SEND_STICKY_BROADCAST_INTENT:
2085+ {
2086+ Intent intent = (Intent)msg.obj;
2087+ log("EVENT_SEND_STICKY_BROADCAST_INTENT: sendStickyBroadcast intent=" + intent);
2088+ sendStickyBroadcast(intent);
2089+ break;
2090+ }
20392091 }
20402092 }
20412093 }
@@ -2222,10 +2274,13 @@ public class ConnectivityService extends IConnectivityManager.Stub {
22222274 if (DBG) log("event hold for obsolete network - aborting");
22232275 return;
22242276 }
2225- if (mDefaultInetConditionPublished == mDefaultInetCondition) {
2226- if (DBG) log("no change in condition - aborting");
2227- return;
2228- }
2277+ // TODO: Figure out why this optimization sometimes causes a
2278+ // change in mDefaultInetCondition to be missed and the
2279+ // UI to not be updated.
2280+ //if (mDefaultInetConditionPublished == mDefaultInetCondition) {
2281+ // if (DBG) log("no change in condition - aborting");
2282+ // return;
2283+ //}
22292284 NetworkInfo networkInfo = mNetTrackers[mActiveDefaultNetwork].getNetworkInfo();
22302285 if (networkInfo.isConnected() == false) {
22312286 if (DBG) log("default network not connected - aborting");