diff options
Diffstat (limited to 'services/java/com')
-rw-r--r-- | services/java/com/android/server/GadgetService.java | 64 | ||||
-rw-r--r-- | services/java/com/android/server/SystemServer.java | 9 | ||||
-rw-r--r-- | services/java/com/android/server/WifiWatchdogService.java | 74 |
3 files changed, 132 insertions, 15 deletions
diff --git a/services/java/com/android/server/GadgetService.java b/services/java/com/android/server/GadgetService.java new file mode 100644 index 0000000..4e49253 --- /dev/null +++ b/services/java/com/android/server/GadgetService.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server; + +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.gadget.GadgetManager; +import android.gadget.GadgetInfo; + +import com.android.internal.gadget.IGadgetService; + +class GadgetService extends IGadgetService.Stub +{ + private static final String TAG = "GadgetService"; + + Context mContext; + + GadgetService(Context context) { + mContext = context; + } + + public int allocateGadgetId(String hostPackage) { + return 42; + } + + public void deleteGadgetId(int gadgetId) { + } + + public void bindGadgetId(int gadgetId, ComponentName provider) { + sendEnabled(provider); + } + + void sendEnabled(ComponentName provider) { + Intent intent = new Intent(GadgetManager.GADGET_ENABLE_ACTION); + intent.setComponent(provider); + mContext.sendBroadcast(intent); + } + + public GadgetInfo getGadgetInfo(int gadgetId) { + GadgetInfo info = new GadgetInfo(); + info.provider = new ComponentName("com.android.gadgethost", + "com.android.gadgethost.TestGadgetProvider"); + info.minWidth = 0; + info.minHeight = 0; + info.updatePeriodMillis = 60 * 1000; // 60s + return info; + } +} + diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index baf57bc..7f7a52e 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -290,7 +290,7 @@ class ServerThread extends Thread { Log.i(TAG, "Starting Audio Service"); ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context)); } catch (Throwable e) { - Log.e(TAG, "Failure starting Volume Service", e); + Log.e(TAG, "Failure starting Audio Service", e); } try { @@ -300,6 +300,13 @@ class ServerThread extends Thread { } catch (Throwable e) { Log.e(TAG, "Failure starting HeadsetObserver", e); } + + try { + Log.i(TAG, "Starting Gadget Service"); + ServiceManager.addService(Context.GADGET_SERVICE, new GadgetService(context)); + } catch (Throwable e) { + Log.e(TAG, "Failure starting Gadget Service", e); + } } // make sure the ADB_ENABLED setting value matches the secure property value diff --git a/services/java/com/android/server/WifiWatchdogService.java b/services/java/com/android/server/WifiWatchdogService.java index 9578c2e..fe97b93 100644 --- a/services/java/com/android/server/WifiWatchdogService.java +++ b/services/java/com/android/server/WifiWatchdogService.java @@ -23,6 +23,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.database.ContentObserver; import android.net.NetworkInfo; +import android.net.DhcpInfo; import android.net.wifi.ScanResult; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; @@ -30,7 +31,6 @@ import android.net.wifi.WifiStateTracker; import android.os.Handler; import android.os.Looper; import android.os.Message; -import android.os.SystemProperties; import android.provider.Settings; import android.text.TextUtils; import android.util.Config; @@ -241,6 +241,15 @@ public class WifiWatchdogService { return Settings.Secure.getInt(mContentResolver, Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_TIMEOUT_MS, 1000); } + + /** + * @see android.provider.Settings.Secure#WIFI_WATCHDOG_WATCH_LIST + * @return the comma-separated list of SSIDs + */ + private String getWatchList() { + return Settings.Secure.getString(mContentResolver, + Settings.Secure.WIFI_WATCHDOG_WATCH_LIST); + } /** * Registers to receive the necessary Wi-Fi broadcasts. @@ -304,8 +313,13 @@ public class WifiWatchdogService { * * @return The DNS of the current AP. */ - private static String getDns() { - return SystemProperties.get(SYSTEMPROPERTY_KEY_DNS); + private int getDns() { + DhcpInfo addressInfo = mWifiManager.getDhcpInfo(); + if (addressInfo != null) { + return addressInfo.dns1; + } else { + return -1; + } } /** @@ -315,18 +329,19 @@ public class WifiWatchdogService { * @return Whether the DNS is reachable */ private boolean checkDnsConnectivity() { - String dns = getDns(); - if (V) { - myLogV("checkDnsConnectivity: Checking " + dns + " for connectivity"); - } - - if (TextUtils.isEmpty(dns)) { + int dns = getDns(); + if (dns == -1) { if (V) { myLogV("checkDnsConnectivity: Invalid DNS, returning false"); } return false; } + if (V) { + myLogV("checkDnsConnectivity: Checking 0x" + + Integer.toHexString(Integer.reverseBytes(dns)) + " for connectivity"); + } + int numInitialIgnoredPings = getInitialIgnoredPingCount(); int numPings = getPingCount(); int pingDelay = getPingDelayMs(); @@ -403,13 +418,13 @@ public class WifiWatchdogService { } private boolean backgroundCheckDnsConnectivity() { - String dns = getDns(); + int dns = getDns(); if (false && V) { myLogV("backgroundCheckDnsConnectivity: Background checking " + dns + " for connectivity"); } - if (TextUtils.isEmpty(dns)) { + if (dns == -1) { if (V) { myLogV("backgroundCheckDnsConnectivity: DNS is empty, returning false"); } @@ -557,7 +572,14 @@ public class WifiWatchdogService { return false; } } - + + if (!isOnWatchList(ssid)) { + if (V) { + Log.v(TAG, " SSID not on watch list, returning false"); + } + return false; + } + // The watchdog only monitors networks with multiple APs if (!hasRequiredNumberOfAps(ssid)) { return false; @@ -565,6 +587,24 @@ public class WifiWatchdogService { return true; } + + private boolean isOnWatchList(String ssid) { + String watchList; + + if (ssid == null || (watchList = getWatchList()) == null) { + return false; + } + + String[] list = watchList.split(" *, *"); + + for (String name : list) { + if (ssid.equals(name)) { + return true; + } + } + + return false; + } /** * Checks if the current scan results have multiple access points with an SSID. @@ -1180,7 +1220,7 @@ public class WifiWatchdogService { /** Used to generate IDs */ private static Random sRandom = new Random(); - static boolean isDnsReachable(String dns, int timeout) { + static boolean isDnsReachable(int dns, int timeout) { try { DatagramSocket socket = new DatagramSocket(); @@ -1191,7 +1231,13 @@ public class WifiWatchdogService { fillQuery(buf); // Send the DNS query - InetAddress dnsAddress = InetAddress.getByName(dns); + byte parts[] = new byte[4]; + parts[0] = (byte)(dns & 0xff); + parts[1] = (byte)((dns >> 8) & 0xff); + parts[2] = (byte)((dns >> 16) & 0xff); + parts[3] = (byte)((dns >> 24) & 0xff); + + InetAddress dnsAddress = InetAddress.getByAddress(parts); DatagramPacket packet = new DatagramPacket(buf, buf.length, dnsAddress, DNS_PORT); socket.send(packet); |