From 0114f6e8e94506d584046fbed61555c65f298e53 Mon Sep 17 00:00:00 2001 From: Robert Greenwalt Date: Wed, 31 Aug 2011 11:46:42 -0700 Subject: [PATCH] Create new isNetworkSupported API Useful for checking if on a wifi-only device. Similar to asking for NetworkInfo for a network type and checking for null, though here the intent is explicit. bug:5087537 Change-Id: Ia3ddd09b6b735b8b3ceb7a347891e015fd96b218 --- core/java/android/net/ConnectivityManager.java | 18 ++++++++++++++++++ .../java/android/net/IConnectivityManager.aidl | 2 ++ .../android/server/ConnectivityService.java | 6 ++++++ 3 files changed, 26 insertions(+) diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index 3441217026..530122c3b2 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -814,4 +814,22 @@ public class ConnectivityManager { } catch (RemoteException e) { } } + + /** + * Returns true if the hardware supports the given network type + * else it returns false. This doesn't indicate we have coverage + * or are authorized onto a network, just whether or not the + * hardware supports it. For example a gsm phone without a sim + * should still return true for mobile data, but a wifi only tablet + * would return false. + * @param networkType The nework type we'd like to check + * @return true if supported, else false + * @hide + */ + public boolean isNetworkSupported(int networkType) { + try { + return mService.isNetworkSupported(networkType); + } catch (RemoteException e) {} + return false; + } } diff --git a/core/java/android/net/IConnectivityManager.aidl b/core/java/android/net/IConnectivityManager.aidl index c9553c05d5..eef658e459 100644 --- a/core/java/android/net/IConnectivityManager.aidl +++ b/core/java/android/net/IConnectivityManager.aidl @@ -43,6 +43,8 @@ interface IConnectivityManager NetworkInfo getNetworkInfo(int networkType); NetworkInfo[] getAllNetworkInfo(); + boolean isNetworkSupported(int networkType); + LinkProperties getActiveLinkProperties(); LinkProperties getLinkProperties(int networkType); diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java index 3815c3b39b..2348d76bb6 100644 --- a/services/java/com/android/server/ConnectivityService.java +++ b/services/java/com/android/server/ConnectivityService.java @@ -703,6 +703,12 @@ public class ConnectivityService extends IConnectivityManager.Stub { return result.toArray(new NetworkInfo[result.size()]); } + @Override + public boolean isNetworkSupported(int networkType) { + enforceAccessPermission(); + return (isNetworkTypeValid(networkType) && (mNetTrackers[networkType] != null)); + } + /** * Return LinkProperties for the active (i.e., connected) default * network interface. It is assumed that at most one default network