summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorAmith Yamasani <yamasani@google.com>2011-03-01 12:41:04 -0800
committerAmith Yamasani <yamasani@google.com>2011-03-01 12:41:04 -0800
commit8d394fa8993f7143dee6f894a41be888bdd16bc0 (patch)
tree61fd6fce4eb1a46f78b81049ddc563cca672edda /services
parent9967ce04572e916a5f68ae0f9345f13b35ec20b0 (diff)
downloadframeworks_base-8d394fa8993f7143dee6f894a41be888bdd16bc0.zip
frameworks_base-8d394fa8993f7143dee6f894a41be888bdd16bc0.tar.gz
frameworks_base-8d394fa8993f7143dee6f894a41be888bdd16bc0.tar.bz2
Check for NTP time as soon as WIFI is connected.
Listen for connectivity changes. If WIFI is connected, check if we have recently checked for NTP time. If we haven't yet checked the time or it has been long enough (a day), then connect to the NTP server and get the latest time. Update the time if it is significantly out of sync. This doesn't poll the NTP server every time there is connectivity, only if it hasn't been checked since boot or has been a day. This fixes the problem that during SetupWizard, we try to contact the NTP server before there is connectivity and fail. Now, as soon as the user chooses a WiFi network to connect to, it will update the time before getting to the Date/Time step. Then as soon as the user corrects the TZ, the date/time should be correct. Bug: 3491920 Change-Id: I62664156616510b67ecd6a1c24dd838b98d5204f
Diffstat (limited to 'services')
-rw-r--r--services/java/com/android/server/NetworkTimeUpdateService.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/services/java/com/android/server/NetworkTimeUpdateService.java b/services/java/com/android/server/NetworkTimeUpdateService.java
index 52f84eb..15f22c0 100644
--- a/services/java/com/android/server/NetworkTimeUpdateService.java
+++ b/services/java/com/android/server/NetworkTimeUpdateService.java
@@ -26,6 +26,8 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.ContentObserver;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
import android.net.SntpClient;
import android.os.Handler;
import android.os.HandlerThread;
@@ -58,6 +60,7 @@ public class NetworkTimeUpdateService {
private static final int EVENT_AUTO_TIME_CHANGED = 1;
private static final int EVENT_POLL_NETWORK_TIME = 2;
+ private static final int EVENT_WIFI_CONNECTED = 3;
/** Normal polling frequency */
private static final long POLLING_INTERVAL_MS = 24L * 60 * 60 * 1000; // 24 hrs
@@ -113,6 +116,7 @@ public class NetworkTimeUpdateService {
registerForTelephonyIntents();
registerForAlarms();
+ registerForConnectivityIntents();
mThread = new HandlerThread(TAG);
mThread.start();
@@ -162,6 +166,12 @@ public class NetworkTimeUpdateService {
}, new IntentFilter(ACTION_POLL));
}
+ private void registerForConnectivityIntents() {
+ IntentFilter intentFilter = new IntentFilter();
+ intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
+ mContext.registerReceiver(mConnectivityReceiver, intentFilter);
+ }
+
private void onPollNetworkTime(int event) {
// If Automatic time is not set, don't bother.
if (!isAutomaticTimeRequested()) return;
@@ -253,6 +263,27 @@ public class NetworkTimeUpdateService {
}
};
+ /** Receiver for ConnectivityManager events */
+ private BroadcastReceiver mConnectivityReceiver = new BroadcastReceiver() {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) {
+ // There is connectivity
+ NetworkInfo netInfo = (NetworkInfo)intent.getParcelableExtra(
+ ConnectivityManager.EXTRA_NETWORK_INFO);
+ if (netInfo != null) {
+ // Verify that it's a WIFI connection
+ if (netInfo.getState() == NetworkInfo.State.CONNECTED &&
+ netInfo.getType() == ConnectivityManager.TYPE_WIFI ) {
+ mHandler.obtainMessage(EVENT_WIFI_CONNECTED).sendToTarget();
+ }
+ }
+ }
+ }
+ };
+
/** Handler to do the network accesses on */
private class MyHandler extends Handler {
@@ -265,6 +296,7 @@ public class NetworkTimeUpdateService {
switch (msg.what) {
case EVENT_AUTO_TIME_CHANGED:
case EVENT_POLL_NETWORK_TIME:
+ case EVENT_WIFI_CONNECTED:
onPollNetworkTime(msg.what);
break;
}