diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:05:43 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:05:43 -0800 |
commit | f013e1afd1e68af5e3b868c26a653bbfb39538f8 (patch) | |
tree | 7ad6c8fd9c7b55f4b4017171dec1cb760bbd26bf /services/java/com/android/server/WifiWatchdogService.java | |
parent | e70cfafe580c6f2994c4827cd8a534aabf3eb05c (diff) | |
download | frameworks_base-f013e1afd1e68af5e3b868c26a653bbfb39538f8.zip frameworks_base-f013e1afd1e68af5e3b868c26a653bbfb39538f8.tar.gz frameworks_base-f013e1afd1e68af5e3b868c26a653bbfb39538f8.tar.bz2 |
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'services/java/com/android/server/WifiWatchdogService.java')
-rw-r--r-- | services/java/com/android/server/WifiWatchdogService.java | 121 |
1 files changed, 80 insertions, 41 deletions
diff --git a/services/java/com/android/server/WifiWatchdogService.java b/services/java/com/android/server/WifiWatchdogService.java index f9edab4..e686bf0 100644 --- a/services/java/com/android/server/WifiWatchdogService.java +++ b/services/java/com/android/server/WifiWatchdogService.java @@ -31,7 +31,7 @@ import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.SystemProperties; -import android.provider.Settings.System; +import android.provider.Settings; import android.text.TextUtils; import android.util.Config; import android.util.Log; @@ -139,7 +139,7 @@ public class WifiWatchdogService { private void registerForSettingsChanges() { ContentResolver contentResolver = mContext.getContentResolver(); contentResolver.registerContentObserver( - System.getUriFor(System.WIFI_WATCHDOG_ON), false, + Settings.Secure.getUriFor(Settings.Secure.WIFI_WATCHDOG_ON), false, new ContentObserver(mHandler) { @Override public void onChange(boolean selfChange) { @@ -156,84 +156,90 @@ public class WifiWatchdogService { } /** - * @see System#WIFI_WATCHDOG_ON + * @see android.provider.Settings.Secure#WIFI_WATCHDOG_ON */ private boolean isWatchdogEnabled() { - return System.getInt(mContentResolver, System.WIFI_WATCHDOG_ON, 1) == 1; + return Settings.Secure.getInt(mContentResolver, Settings.Secure.WIFI_WATCHDOG_ON, 1) == 1; } /** - * @see System#WIFI_WATCHDOG_AP_COUNT + * @see android.provider.Settings.Secure#WIFI_WATCHDOG_AP_COUNT */ private int getApCount() { - return System.getInt(mContentResolver, System.WIFI_WATCHDOG_AP_COUNT, 2); + return Settings.Secure.getInt(mContentResolver, + Settings.Secure.WIFI_WATCHDOG_AP_COUNT, 2); } /** - * @see System#WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT + * @see android.provider.Settings.Secure#WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT */ private int getInitialIgnoredPingCount() { - return System.getInt(mContentResolver, System.WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT , 2); + return Settings.Secure.getInt(mContentResolver, + Settings.Secure.WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT , 2); } /** - * @see System#WIFI_WATCHDOG_PING_COUNT + * @see android.provider.Settings.Secure#WIFI_WATCHDOG_PING_COUNT */ private int getPingCount() { - return System.getInt(mContentResolver, System.WIFI_WATCHDOG_PING_COUNT, 4); + return Settings.Secure.getInt(mContentResolver, + Settings.Secure.WIFI_WATCHDOG_PING_COUNT, 4); } /** - * @see System#WIFI_WATCHDOG_PING_TIMEOUT_MS + * @see android.provider.Settings.Secure#WIFI_WATCHDOG_PING_TIMEOUT_MS */ private int getPingTimeoutMs() { - return System.getInt(mContentResolver, System.WIFI_WATCHDOG_PING_TIMEOUT_MS, 500); + return Settings.Secure.getInt(mContentResolver, + Settings.Secure.WIFI_WATCHDOG_PING_TIMEOUT_MS, 500); } /** - * @see System#WIFI_WATCHDOG_PING_DELAY_MS + * @see android.provider.Settings.Secure#WIFI_WATCHDOG_PING_DELAY_MS */ private int getPingDelayMs() { - return System.getInt(mContentResolver, System.WIFI_WATCHDOG_PING_DELAY_MS, 250); + return Settings.Secure.getInt(mContentResolver, + Settings.Secure.WIFI_WATCHDOG_PING_DELAY_MS, 250); } /** - * @see System#WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE + * @see android.provider.Settings.Secure#WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE */ private int getAcceptablePacketLossPercentage() { - return System.getInt(mContentResolver, - System.WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE, 25); + return Settings.Secure.getInt(mContentResolver, + Settings.Secure.WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE, 25); } /** - * @see System#WIFI_WATCHDOG_MAX_AP_CHECKS + * @see android.provider.Settings.Secure#WIFI_WATCHDOG_MAX_AP_CHECKS */ private int getMaxApChecks() { - return System.getInt(mContentResolver, System.WIFI_WATCHDOG_MAX_AP_CHECKS, 7); + return Settings.Secure.getInt(mContentResolver, + Settings.Secure.WIFI_WATCHDOG_MAX_AP_CHECKS, 7); } /** - * @see System#WIFI_WATCHDOG_BACKGROUND_CHECK_ENABLED + * @see android.provider.Settings.Secure#WIFI_WATCHDOG_BACKGROUND_CHECK_ENABLED */ private boolean isBackgroundCheckEnabled() { - return System.getInt(mContentResolver, System.WIFI_WATCHDOG_BACKGROUND_CHECK_ENABLED, 1) - == 1; + return Settings.Secure.getInt(mContentResolver, + Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_ENABLED, 1) == 1; } /** - * @see System#WIFI_WATCHDOG_BACKGROUND_CHECK_DELAY_MS + * @see android.provider.Settings.Secure#WIFI_WATCHDOG_BACKGROUND_CHECK_DELAY_MS */ private int getBackgroundCheckDelayMs() { - return System.getInt(mContentResolver, - System.WIFI_WATCHDOG_BACKGROUND_CHECK_DELAY_MS, 5000); + return Settings.Secure.getInt(mContentResolver, + Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_DELAY_MS, 5000); } /** - * @see System#WIFI_WATCHDOG_BACKGROUND_CHECK_TIMEOUT_MS + * @see android.provider.Settings.Secure#WIFI_WATCHDOG_BACKGROUND_CHECK_TIMEOUT_MS */ private int getBackgroundCheckTimeoutMs() { - return System.getInt(mContentResolver, - System.WIFI_WATCHDOG_BACKGROUND_CHECK_TIMEOUT_MS, 1000); + return Settings.Secure.getInt(mContentResolver, + Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_TIMEOUT_MS, 1000); } /** @@ -326,7 +332,7 @@ public class WifiWatchdogService { int pingDelay = getPingDelayMs(); int acceptableLoss = getAcceptablePacketLossPercentage(); - /** See {@link System#WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT} */ + /** See {@link Secure#WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT} */ int ignoredPingCounter = 0; int pingCounter = 0; int successCounter = 0; @@ -959,7 +965,7 @@ public class WifiWatchdogService { * thread will ensure when it sees the message that the state is still * valid for going to sleep. * <p> - * For an explanation of sleep, see {@link System#WIFI_WATCHDOG_MAX_AP_CHECKS}. + * For an explanation of sleep, see {@link android.provider.Settings.Secure#WIFI_WATCHDOG_MAX_AP_CHECKS}. */ static final int MESSAGE_SLEEP = 101; /** Disables the watchdog. */ @@ -1166,7 +1172,7 @@ public class WifiWatchdogService { private static class DnsPinger { /** Number of bytes for the query */ - private static final int DNS_QUERY_BASE_SIZE = 12; + private static final int DNS_QUERY_BASE_SIZE = 33; /** The DNS port */ private static final int DNS_PORT = 53; @@ -1227,21 +1233,54 @@ public class WifiWatchdogService { } private static void fillQuery(byte[] buf) { - int i = 0; - // See RFC2929, section 2 + /* + * See RFC2929 (though the bit tables in there are misleading for + * us. For example, the recursion desired bit is the 0th bit for us, + * but looking there it would appear as the 7th bit of the byte + */ + + // Make sure it's all zeroed out + for (int i = 0; i < buf.length; i++) buf[i] = 0; + + // Form a query for www.android.com - // [0-1] bytes are an ID - buf[i++] = (byte) sRandom.nextInt(256); - buf[i++] = (byte) sRandom.nextInt(256); + // [0-1] bytes are an ID, generate random ID for this query + buf[0] = (byte) sRandom.nextInt(256); + buf[1] = (byte) sRandom.nextInt(256); // [2-3] bytes are for flags. - // The Opcode is '2' for server status. It is on bits [1-4] of this byte. - buf[i++] = 4; - buf[i++] = 0; + buf[2] = 1; // Recursion desired + + // [4-5] bytes are for the query count + buf[5] = 1; // One query + + // [6-7] [8-9] [10-11] are all counts of other fields we don't use + + // [12-15] for www + writeString(buf, 12, "www"); - // [4-5] [6-7] [8-9] [10-11] are all counts of other fields we don't use - for (; i <= 11; i++) buf[i] = 0; + // [16-23] for android + writeString(buf, 16, "android"); + + // [24-27] for com + writeString(buf, 24, "com"); + + // [29-30] bytes are for QTYPE, set to 1 + buf[30] = 1; + + // [31-32] bytes are for QCLASS, set to 1 + buf[32] = 1; + } + + private static void writeString(byte[] buf, int startPos, String string) { + int pos = startPos; + + // Write the length first + buf[pos++] = (byte) string.length(); + for (int i = 0; i < string.length(); i++) { + buf[pos++] = (byte) string.charAt(i); + } } } } |