ConnectivityManager.java revision 75fbb4bdfde9188081f000506845d852f31362f0
19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/* 29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Copyright (C) 2008 The Android Open Source Project 39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you may not use this file except in compliance with the License. 69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * You may obtain a copy of the License at 79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * See the License for the specific language governing permissions and 149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * limitations under the License. 159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpackage android.net; 189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 19f0ceede8fff5df24e5c98701d81c2b71eb138aa9Jeff Sharkeyimport static com.android.internal.util.Preconditions.checkNotNull; 20f0ceede8fff5df24e5c98701d81c2b71eb138aa9Jeff Sharkey 219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.annotation.SdkConstant; 229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.annotation.SdkConstant.SdkConstantType; 238fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkeyimport android.content.Context; 2442acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwaltimport android.os.Binder; 253a844fcf5a0e70a19c38dc500306b9ebe4e1413bJeff Sharkeyimport android.os.Build.VERSION_CODES; 269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.RemoteException; 27961e30458319cfd50e1892ba7dd14a1d0ebe4cc7Jeff Sharkeyimport android.provider.Settings; 289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 29585ac0fc8dde3fe35ec4c71c8f215f2c84139b8bRobert Greenwaltimport java.net.InetAddress; 30585ac0fc8dde3fe35ec4c71c8f215f2c84139b8bRobert Greenwalt 319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/** 329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Class that answers queries about the state of network connectivity. It also 339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * notifies applications when network connectivity changes. Get an instance 349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * of this class by calling 359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link android.content.Context#getSystemService(String) Context.getSystemService(Context.CONNECTIVITY_SERVICE)}. 369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p> 379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * The primary responsibilities of this class are to: 389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <ol> 399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>Monitor network connections (Wi-Fi, GPRS, UMTS, etc.)</li> 409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>Send broadcast intents when network connectivity changes</li> 419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>Attempt to "fail over" to another network when connectivity to a network 429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * is lost</li> 439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>Provide an API that allows applications to query the coarse-grained or fine-grained 449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * state of the available networks</li> 459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </ol> 469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 47c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkeypublic class ConnectivityManager { 48c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey private static final String TAG = "ConnectivityManager"; 49c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey 509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * A change in network connectivity has occurred. A connection has either 529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * been established or lost. The NetworkInfo for the affected network is 539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * sent as an extra; it should be consulted to see what kind of 549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * connectivity event occurred. 559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p/> 569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * If this is a connection that was the result of failing over from a 579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * disconnected network, then the FAILOVER_CONNECTION boolean extra is 589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * set to true. 599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p/> 609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * For a loss of connectivity, if the connectivity manager is attempting 619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * to connect (or has already connected) to another network, the 629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * NetworkInfo for the new network is also passed as an extra. This lets 639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * any receivers of the broadcast know that they should not necessarily 649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * tell the user that no data traffic will be possible. Instead, the 659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * reciever should expect another broadcast soon, indicating either that 669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the failover attempt succeeded (and so there is still overall data 679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * connectivity), or that the failover attempt failed, meaning that all 689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * connectivity has been lost. 699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p/> 709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * For a disconnect event, the boolean extra EXTRA_NO_CONNECTIVITY 719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * is set to {@code true} if there are no connected networks at all. 729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final String CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE"; 74f0ceede8fff5df24e5c98701d81c2b71eb138aa9Jeff Sharkey 759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 76961e30458319cfd50e1892ba7dd14a1d0ebe4cc7Jeff Sharkey * Identical to {@link #CONNECTIVITY_ACTION} broadcast, but sent without any 77961e30458319cfd50e1892ba7dd14a1d0ebe4cc7Jeff Sharkey * applicable {@link Settings.Secure#CONNECTIVITY_CHANGE_DELAY}. 78961e30458319cfd50e1892ba7dd14a1d0ebe4cc7Jeff Sharkey * 79961e30458319cfd50e1892ba7dd14a1d0ebe4cc7Jeff Sharkey * @hide 80961e30458319cfd50e1892ba7dd14a1d0ebe4cc7Jeff Sharkey */ 81961e30458319cfd50e1892ba7dd14a1d0ebe4cc7Jeff Sharkey public static final String CONNECTIVITY_ACTION_IMMEDIATE = 82961e30458319cfd50e1892ba7dd14a1d0ebe4cc7Jeff Sharkey "android.net.conn.CONNECTIVITY_CHANGE_IMMEDIATE"; 83961e30458319cfd50e1892ba7dd14a1d0ebe4cc7Jeff Sharkey 84961e30458319cfd50e1892ba7dd14a1d0ebe4cc7Jeff Sharkey /** 859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * The lookup key for a {@link NetworkInfo} object. Retrieve with 869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link android.content.Intent#getParcelableExtra(String)}. 87f0ceede8fff5df24e5c98701d81c2b71eb138aa9Jeff Sharkey * 88f0ceede8fff5df24e5c98701d81c2b71eb138aa9Jeff Sharkey * @deprecated Since {@link NetworkInfo} can vary based on UID, applications 89f0ceede8fff5df24e5c98701d81c2b71eb138aa9Jeff Sharkey * should always obtain network information through 90f0ceede8fff5df24e5c98701d81c2b71eb138aa9Jeff Sharkey * {@link #getActiveNetworkInfo()} or 91f0ceede8fff5df24e5c98701d81c2b71eb138aa9Jeff Sharkey * {@link #getAllNetworkInfo()}. 9275fbb4bdfde9188081f000506845d852f31362f0Jeff Sharkey * @see #EXTRA_NETWORK_TYPE 939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 94f0ceede8fff5df24e5c98701d81c2b71eb138aa9Jeff Sharkey @Deprecated 959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final String EXTRA_NETWORK_INFO = "networkInfo"; 96f0ceede8fff5df24e5c98701d81c2b71eb138aa9Jeff Sharkey 979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 9875fbb4bdfde9188081f000506845d852f31362f0Jeff Sharkey * Network type which triggered a {@link #CONNECTIVITY_ACTION} broadcast. 9975fbb4bdfde9188081f000506845d852f31362f0Jeff Sharkey * Can be used with {@link #getNetworkInfo(int)} to get {@link NetworkInfo} 10075fbb4bdfde9188081f000506845d852f31362f0Jeff Sharkey * state based on the calling application. 10175fbb4bdfde9188081f000506845d852f31362f0Jeff Sharkey * 10275fbb4bdfde9188081f000506845d852f31362f0Jeff Sharkey * @see android.content.Intent#getIntExtra(String, int) 10375fbb4bdfde9188081f000506845d852f31362f0Jeff Sharkey */ 10475fbb4bdfde9188081f000506845d852f31362f0Jeff Sharkey public static final String EXTRA_NETWORK_TYPE = "networkType"; 10575fbb4bdfde9188081f000506845d852f31362f0Jeff Sharkey 10675fbb4bdfde9188081f000506845d852f31362f0Jeff Sharkey /** 1079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * The lookup key for a boolean that indicates whether a connect event 1089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * is for a network to which the connectivity manager was failing over 1099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * following a disconnect on another network. 1109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}. 1119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final String EXTRA_IS_FAILOVER = "isFailover"; 1139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * The lookup key for a {@link NetworkInfo} object. This is supplied when 1159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * there is another network that it may be possible to connect to. Retrieve with 1169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link android.content.Intent#getParcelableExtra(String)}. 1179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final String EXTRA_OTHER_NETWORK_INFO = "otherNetwork"; 1199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * The lookup key for a boolean that indicates whether there is a 1219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * complete lack of connectivity, i.e., no network is available. 1229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}. 1239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final String EXTRA_NO_CONNECTIVITY = "noConnectivity"; 1259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * The lookup key for a string that indicates why an attempt to connect 1279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * to a network failed. The string has no particular structure. It is 1289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * intended to be used in notifications presented to users. Retrieve 1299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * it with {@link android.content.Intent#getStringExtra(String)}. 1309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final String EXTRA_REASON = "reason"; 1329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * The lookup key for a string that provides optionally supplied 1349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * extra information about the network state. The information 1359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * may be passed up from the lower networking layers, and its 1369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * meaning may be specific to a particular network type. Retrieve 1379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * it with {@link android.content.Intent#getStringExtra(String)}. 1389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final String EXTRA_EXTRA_INFO = "extraInfo"; 140d7085fcf6567452a9d6fc69b0c6b1bf556f4c1b9Robert Greenwalt /** 141d7085fcf6567452a9d6fc69b0c6b1bf556f4c1b9Robert Greenwalt * The lookup key for an int that provides information about 142d7085fcf6567452a9d6fc69b0c6b1bf556f4c1b9Robert Greenwalt * our connection to the internet at large. 0 indicates no connection, 143d7085fcf6567452a9d6fc69b0c6b1bf556f4c1b9Robert Greenwalt * 100 indicates a great connection. Retrieve it with 144c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey * {@link android.content.Intent#getIntExtra(String, int)}. 145d7085fcf6567452a9d6fc69b0c6b1bf556f4c1b9Robert Greenwalt * {@hide} 146d7085fcf6567452a9d6fc69b0c6b1bf556f4c1b9Robert Greenwalt */ 147d7085fcf6567452a9d6fc69b0c6b1bf556f4c1b9Robert Greenwalt public static final String EXTRA_INET_CONDITION = "inetCondition"; 1489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 150db3c8678e5cbdfec011afaf25bde2091152c30adHaoyu Bai * Broadcast action to indicate the change of data activity status 151db3c8678e5cbdfec011afaf25bde2091152c30adHaoyu Bai * (idle or active) on a network in a recent period. 152db3c8678e5cbdfec011afaf25bde2091152c30adHaoyu Bai * The network becomes active when data transimission is started, or 153db3c8678e5cbdfec011afaf25bde2091152c30adHaoyu Bai * idle if there is no data transimition for a period of time. 154db3c8678e5cbdfec011afaf25bde2091152c30adHaoyu Bai * {@hide} 155db3c8678e5cbdfec011afaf25bde2091152c30adHaoyu Bai */ 156db3c8678e5cbdfec011afaf25bde2091152c30adHaoyu Bai @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 157db3c8678e5cbdfec011afaf25bde2091152c30adHaoyu Bai public static final String ACTION_DATA_ACTIVITY_CHANGE = "android.net.conn.DATA_ACTIVITY_CHANGE"; 158db3c8678e5cbdfec011afaf25bde2091152c30adHaoyu Bai /** 159db3c8678e5cbdfec011afaf25bde2091152c30adHaoyu Bai * The lookup key for an enum that indicates the network device type on which this data activity 160db3c8678e5cbdfec011afaf25bde2091152c30adHaoyu Bai * change happens. 161db3c8678e5cbdfec011afaf25bde2091152c30adHaoyu Bai * {@hide} 162db3c8678e5cbdfec011afaf25bde2091152c30adHaoyu Bai */ 163db3c8678e5cbdfec011afaf25bde2091152c30adHaoyu Bai public static final String EXTRA_DEVICE_TYPE = "deviceType"; 164db3c8678e5cbdfec011afaf25bde2091152c30adHaoyu Bai /** 165db3c8678e5cbdfec011afaf25bde2091152c30adHaoyu Bai * The lookup key for a boolean that indicates the device is active or not. {@code true} means 166db3c8678e5cbdfec011afaf25bde2091152c30adHaoyu Bai * it is actively sending or receiving data and {@code false} means it is idle. 167db3c8678e5cbdfec011afaf25bde2091152c30adHaoyu Bai * {@hide} 168db3c8678e5cbdfec011afaf25bde2091152c30adHaoyu Bai */ 169db3c8678e5cbdfec011afaf25bde2091152c30adHaoyu Bai public static final String EXTRA_IS_ACTIVE = "isActive"; 170db3c8678e5cbdfec011afaf25bde2091152c30adHaoyu Bai 171db3c8678e5cbdfec011afaf25bde2091152c30adHaoyu Bai /** 1729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Broadcast Action: The setting for background data usage has changed 1739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * values. Use {@link #getBackgroundDataSetting()} to get the current value. 1749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p> 1759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * If an application uses the network in the background, it should listen 1769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * for this broadcast and stop using the background data if the value is 177c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey * {@code false}. 17854ee2adf1711ce34c309c65c17ed6fd4d8f0d632Jeff Sharkey * <p> 17954ee2adf1711ce34c309c65c17ed6fd4d8f0d632Jeff Sharkey * 18054ee2adf1711ce34c309c65c17ed6fd4d8f0d632Jeff Sharkey * @deprecated As of {@link VERSION_CODES#ICE_CREAM_SANDWICH}, availability 18154ee2adf1711ce34c309c65c17ed6fd4d8f0d632Jeff Sharkey * of background data depends on several combined factors, and 18254ee2adf1711ce34c309c65c17ed6fd4d8f0d632Jeff Sharkey * this broadcast is no longer sent. Instead, when background 18354ee2adf1711ce34c309c65c17ed6fd4d8f0d632Jeff Sharkey * data is unavailable, {@link #getActiveNetworkInfo()} will now 18454ee2adf1711ce34c309c65c17ed6fd4d8f0d632Jeff Sharkey * appear disconnected. During first boot after a platform 18554ee2adf1711ce34c309c65c17ed6fd4d8f0d632Jeff Sharkey * upgrade, this broadcast will be sent once if 18654ee2adf1711ce34c309c65c17ed6fd4d8f0d632Jeff Sharkey * {@link #getBackgroundDataSetting()} was {@code false} before 18754ee2adf1711ce34c309c65c17ed6fd4d8f0d632Jeff Sharkey * the upgrade. 1889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 19054ee2adf1711ce34c309c65c17ed6fd4d8f0d632Jeff Sharkey @Deprecated 1919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final String ACTION_BACKGROUND_DATA_SETTING_CHANGED = 1929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project "android.net.conn.BACKGROUND_DATA_SETTING_CHANGED"; 1939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1941e9aac2bd855f12708d3049eff4435fa4a2f4317Robert Greenwalt /** 1951e9aac2bd855f12708d3049eff4435fa4a2f4317Robert Greenwalt * Broadcast Action: The network connection may not be good 1961e9aac2bd855f12708d3049eff4435fa4a2f4317Robert Greenwalt * uses {@code ConnectivityManager.EXTRA_INET_CONDITION} and 1971e9aac2bd855f12708d3049eff4435fa4a2f4317Robert Greenwalt * {@code ConnectivityManager.EXTRA_NETWORK_INFO} to specify 1981e9aac2bd855f12708d3049eff4435fa4a2f4317Robert Greenwalt * the network and it's condition. 1991e9aac2bd855f12708d3049eff4435fa4a2f4317Robert Greenwalt * @hide 2001e9aac2bd855f12708d3049eff4435fa4a2f4317Robert Greenwalt */ 2011e9aac2bd855f12708d3049eff4435fa4a2f4317Robert Greenwalt public static final String INET_CONDITION_ACTION = 2021e9aac2bd855f12708d3049eff4435fa4a2f4317Robert Greenwalt "android.net.conn.INET_CONDITION_ACTION"; 2031e9aac2bd855f12708d3049eff4435fa4a2f4317Robert Greenwalt 20442acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt /** 205d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt * Broadcast Action: A tetherable connection has come or gone 206d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt * TODO - finish the doc 207d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt * @hide 208d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt */ 209d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt public static final String ACTION_TETHER_STATE_CHANGED = 210d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt "android.net.conn.TETHER_STATE_CHANGED"; 211d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt 212d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt /** 213d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt * @hide 2142a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt * gives a String[] 215d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt */ 2162a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt public static final String EXTRA_AVAILABLE_TETHER = "availableArray"; 217d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt 218d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt /** 219d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt * @hide 2202a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt * gives a String[] 221d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt */ 2222a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt public static final String EXTRA_ACTIVE_TETHER = "activeArray"; 2232a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt 2242a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt /** 2252a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt * @hide 2262a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt * gives a String[] 2272a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt */ 2282a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt public static final String EXTRA_ERRORED_TETHER = "erroredArray"; 229d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt 230d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt /** 231ccf83af1017b7b1eaf12f6ec3d2cb2137a7cdda9Robert Greenwalt * The absence of APN.. 232ccf83af1017b7b1eaf12f6ec3d2cb2137a7cdda9Robert Greenwalt * @hide 233ccf83af1017b7b1eaf12f6ec3d2cb2137a7cdda9Robert Greenwalt */ 234ccf83af1017b7b1eaf12f6ec3d2cb2137a7cdda9Robert Greenwalt public static final int TYPE_NONE = -1; 235ccf83af1017b7b1eaf12f6ec3d2cb2137a7cdda9Robert Greenwalt 236ccf83af1017b7b1eaf12f6ec3d2cb2137a7cdda9Robert Greenwalt /** 23742acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt * The Default Mobile data connection. When active, all data traffic 23897ab2d4f86ee9c2b661a00688e934fc7030df22eRobert Greenwalt * will use this connection by default. 23942acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt */ 24042acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt public static final int TYPE_MOBILE = 0; 24142acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt /** 24242acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt * The Default WIFI data connection. When active, all data traffic 24397ab2d4f86ee9c2b661a00688e934fc7030df22eRobert Greenwalt * will use this connection by default. 24442acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt */ 24542acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt public static final int TYPE_WIFI = 1; 24642acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt /** 24742acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt * An MMS-specific Mobile data connection. This connection may be the 2481bc3c3775b7b2cbaec50cd377db437f284478de0Robert Greenwalt * same as {@link #TYPE_MOBILE} but it may be different. This is used 24942acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt * by applications needing to talk to the carrier's Multimedia Messaging 25042acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt * Service servers. It may coexist with default data connections. 25142acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt */ 25242acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt public static final int TYPE_MOBILE_MMS = 2; 25342acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt /** 25442acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt * A SUPL-specific Mobile data connection. This connection may be the 2551bc3c3775b7b2cbaec50cd377db437f284478de0Robert Greenwalt * same as {@link #TYPE_MOBILE} but it may be different. This is used 25642acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt * by applications needing to talk to the carrier's Secure User Plane 25742acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt * Location servers for help locating the device. It may coexist with 25842acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt * default data connections. 25942acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt */ 26042acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt public static final int TYPE_MOBILE_SUPL = 3; 26142acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt /** 26242acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt * A DUN-specific Mobile data connection. This connection may be the 2631bc3c3775b7b2cbaec50cd377db437f284478de0Robert Greenwalt * same as {@link #TYPE_MOBILE} but it may be different. This is used 26442acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt * by applicaitons performing a Dial Up Networking bridge so that 26542acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt * the carrier is aware of DUN traffic. It may coexist with default data 26642acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt * connections. 26742acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt */ 26842acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt public static final int TYPE_MOBILE_DUN = 4; 26942acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt /** 27042acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt * A High Priority Mobile data connection. This connection is typically 2711bc3c3775b7b2cbaec50cd377db437f284478de0Robert Greenwalt * the same as {@link #TYPE_MOBILE} but the routing setup is different. 27242acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt * Only requesting processes will have access to the Mobile DNS servers 27342acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt * and only IP's explicitly requested via {@link #requestRouteToHost} 274c849cdf5cfde007ce591838c4e2b777fb4843c8dRobert Greenwalt * will route over this interface if a default route exists. 27542acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt */ 27642acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt public static final int TYPE_MOBILE_HIPRI = 5; 2778214deb542392f48b6c3fdc377fdf976c0b17a32jsh /** 2788214deb542392f48b6c3fdc377fdf976c0b17a32jsh * The Default WiMAX data connection. When active, all data traffic 27997ab2d4f86ee9c2b661a00688e934fc7030df22eRobert Greenwalt * will use this connection by default. 2808214deb542392f48b6c3fdc377fdf976c0b17a32jsh */ 2818214deb542392f48b6c3fdc377fdf976c0b17a32jsh public static final int TYPE_WIMAX = 6; 282da3d5e6587c1476d489495ac93e84ebf223024c9Robert Greenwalt 28315c7439acb22ab079dd2ebe42bdf0d2ffd525c5dJaikumar Ganesh /** 28497ab2d4f86ee9c2b661a00688e934fc7030df22eRobert Greenwalt * The Default Bluetooth data connection. When active, all data traffic 28597ab2d4f86ee9c2b661a00688e934fc7030df22eRobert Greenwalt * will use this connection by default. 28615c7439acb22ab079dd2ebe42bdf0d2ffd525c5dJaikumar Ganesh */ 28715c7439acb22ab079dd2ebe42bdf0d2ffd525c5dJaikumar Ganesh public static final int TYPE_BLUETOOTH = 7; 28815c7439acb22ab079dd2ebe42bdf0d2ffd525c5dJaikumar Ganesh 2896081084e8831d12d2dd5a9a340ee7d35a54edb8aRobert Greenwalt /** 2906081084e8831d12d2dd5a9a340ee7d35a54edb8aRobert Greenwalt * Dummy data connection. This should not be used on shipping devices. 2916081084e8831d12d2dd5a9a340ee7d35a54edb8aRobert Greenwalt */ 29215c7439acb22ab079dd2ebe42bdf0d2ffd525c5dJaikumar Ganesh public static final int TYPE_DUMMY = 8; 2939d7d62801ddb206d2ea96d74864a9edfe54d2eeeWink Saville 2946081084e8831d12d2dd5a9a340ee7d35a54edb8aRobert Greenwalt /** 29597ab2d4f86ee9c2b661a00688e934fc7030df22eRobert Greenwalt * The Default Ethernet data connection. When active, all data traffic 29697ab2d4f86ee9c2b661a00688e934fc7030df22eRobert Greenwalt * will use this connection by default. 2976081084e8831d12d2dd5a9a340ee7d35a54edb8aRobert Greenwalt */ 298e12aec941dfc93b76b5efb9bc9f30d2ba3469434Robert Greenwalt public static final int TYPE_ETHERNET = 9; 2996081084e8831d12d2dd5a9a340ee7d35a54edb8aRobert Greenwalt 3009d7d62801ddb206d2ea96d74864a9edfe54d2eeeWink Saville /** 3019d7d62801ddb206d2ea96d74864a9edfe54d2eeeWink Saville * Over the air Adminstration. 3029d7d62801ddb206d2ea96d74864a9edfe54d2eeeWink Saville * {@hide} 3039d7d62801ddb206d2ea96d74864a9edfe54d2eeeWink Saville */ 3049d7d62801ddb206d2ea96d74864a9edfe54d2eeeWink Saville public static final int TYPE_MOBILE_FOTA = 10; 3059d7d62801ddb206d2ea96d74864a9edfe54d2eeeWink Saville 3069d7d62801ddb206d2ea96d74864a9edfe54d2eeeWink Saville /** 3079d7d62801ddb206d2ea96d74864a9edfe54d2eeeWink Saville * IP Multimedia Subsystem 3089d7d62801ddb206d2ea96d74864a9edfe54d2eeeWink Saville * {@hide} 3099d7d62801ddb206d2ea96d74864a9edfe54d2eeeWink Saville */ 3109d7d62801ddb206d2ea96d74864a9edfe54d2eeeWink Saville public static final int TYPE_MOBILE_IMS = 11; 3119d7d62801ddb206d2ea96d74864a9edfe54d2eeeWink Saville 3129d7d62801ddb206d2ea96d74864a9edfe54d2eeeWink Saville /** 3139d7d62801ddb206d2ea96d74864a9edfe54d2eeeWink Saville * Carrier Branded Services 3149d7d62801ddb206d2ea96d74864a9edfe54d2eeeWink Saville * {@hide} 3159d7d62801ddb206d2ea96d74864a9edfe54d2eeeWink Saville */ 3169d7d62801ddb206d2ea96d74864a9edfe54d2eeeWink Saville public static final int TYPE_MOBILE_CBS = 12; 3179d7d62801ddb206d2ea96d74864a9edfe54d2eeeWink Saville 318aea743aaa43a833fd8ff3dc56205197583152d5frepo sync /** 319aea743aaa43a833fd8ff3dc56205197583152d5frepo sync * A Wi-Fi p2p connection. Only requesting processes will have access to 320aea743aaa43a833fd8ff3dc56205197583152d5frepo sync * the peers connected. 321aea743aaa43a833fd8ff3dc56205197583152d5frepo sync * {@hide} 322aea743aaa43a833fd8ff3dc56205197583152d5frepo sync */ 323aea743aaa43a833fd8ff3dc56205197583152d5frepo sync public static final int TYPE_WIFI_P2P = 13; 324aea743aaa43a833fd8ff3dc56205197583152d5frepo sync 3259d7d62801ddb206d2ea96d74864a9edfe54d2eeeWink Saville /** {@hide} */ 326aea743aaa43a833fd8ff3dc56205197583152d5frepo sync public static final int MAX_RADIO_TYPE = TYPE_WIFI_P2P; 3279d7d62801ddb206d2ea96d74864a9edfe54d2eeeWink Saville 3289d7d62801ddb206d2ea96d74864a9edfe54d2eeeWink Saville /** {@hide} */ 329aea743aaa43a833fd8ff3dc56205197583152d5frepo sync public static final int MAX_NETWORK_TYPE = TYPE_WIFI_P2P; 3309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 3319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_WIFI; 3329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 333c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey private final IConnectivityManager mService; 3349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 335d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey public static boolean isNetworkTypeValid(int networkType) { 33642acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt return networkType >= 0 && networkType <= MAX_NETWORK_TYPE; 3379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 3389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 339d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey /** {@hide} */ 340d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey public static String getNetworkTypeName(int type) { 341d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey switch (type) { 342d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey case TYPE_MOBILE: 343d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey return "MOBILE"; 344d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey case TYPE_WIFI: 345d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey return "WIFI"; 346d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey case TYPE_MOBILE_MMS: 347d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey return "MOBILE_MMS"; 348d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey case TYPE_MOBILE_SUPL: 349d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey return "MOBILE_SUPL"; 350d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey case TYPE_MOBILE_DUN: 351d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey return "MOBILE_DUN"; 352d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey case TYPE_MOBILE_HIPRI: 353d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey return "MOBILE_HIPRI"; 354d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey case TYPE_WIMAX: 355d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey return "WIMAX"; 356d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey case TYPE_BLUETOOTH: 357d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey return "BLUETOOTH"; 358d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey case TYPE_DUMMY: 359d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey return "DUMMY"; 360d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey case TYPE_ETHERNET: 361d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey return "ETHERNET"; 362d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey case TYPE_MOBILE_FOTA: 363d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey return "MOBILE_FOTA"; 364d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey case TYPE_MOBILE_IMS: 365d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey return "MOBILE_IMS"; 366d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey case TYPE_MOBILE_CBS: 367d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey return "MOBILE_CBS"; 368aea743aaa43a833fd8ff3dc56205197583152d5frepo sync case TYPE_WIFI_P2P: 369aea743aaa43a833fd8ff3dc56205197583152d5frepo sync return "WIFI_P2P"; 370d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey default: 371d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey return Integer.toString(type); 372d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey } 373d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey } 374d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey 375d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey /** {@hide} */ 376d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey public static boolean isNetworkTypeMobile(int networkType) { 377d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey switch (networkType) { 378d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey case TYPE_MOBILE: 379d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey case TYPE_MOBILE_MMS: 380d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey case TYPE_MOBILE_SUPL: 381d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey case TYPE_MOBILE_DUN: 382d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey case TYPE_MOBILE_HIPRI: 383d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey case TYPE_MOBILE_FOTA: 384d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey case TYPE_MOBILE_IMS: 385d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey case TYPE_MOBILE_CBS: 386d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey return true; 387d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey default: 388d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey return false; 389d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey } 390d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey } 391d2a458750e5a3d490af09cecb5c28370baf0a913Jeff Sharkey 3929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setNetworkPreference(int preference) { 3939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 3949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mService.setNetworkPreference(preference); 3959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) { 3969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 3979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 3989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 3999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public int getNetworkPreference() { 4009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 4019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return mService.getNetworkPreference(); 4029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) { 4039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return -1; 4049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 407671644c3ef92a9153ea5bd495e132d5fe6674234Scott Main /** 4089f7cbf0e50bcb7e9163b23524814003ba8784732Jeff Sharkey * Returns details about the currently active data network. When connected, 4099f7cbf0e50bcb7e9163b23524814003ba8784732Jeff Sharkey * this network is the default route for outgoing connections. You should 4109f7cbf0e50bcb7e9163b23524814003ba8784732Jeff Sharkey * always check {@link NetworkInfo#isConnected()} before initiating network 4119f7cbf0e50bcb7e9163b23524814003ba8784732Jeff Sharkey * traffic. This may return {@code null} when no networks are available. 4129530e3a22d5ffa2019d1a5177b6a441d4d6d048bNicolas Falliere * <p>This method requires the caller to hold the permission 4139530e3a22d5ffa2019d1a5177b6a441d4d6d048bNicolas Falliere * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. 4149f7cbf0e50bcb7e9163b23524814003ba8784732Jeff Sharkey */ 4159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public NetworkInfo getActiveNetworkInfo() { 4169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 4179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return mService.getActiveNetworkInfo(); 4189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) { 4199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return null; 4209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 423c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey /** {@hide} */ 424c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey public NetworkInfo getActiveNetworkInfoForUid(int uid) { 425c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey try { 426c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey return mService.getActiveNetworkInfoForUid(uid); 427c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey } catch (RemoteException e) { 428c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey return null; 429c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey } 430c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey } 431c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey 4329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public NetworkInfo getNetworkInfo(int networkType) { 4339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 4349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return mService.getNetworkInfo(networkType); 4359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) { 4369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return null; 4379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 4409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public NetworkInfo[] getAllNetworkInfo() { 4419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 4429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return mService.getAllNetworkInfo(); 4439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) { 4449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return null; 4459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 448c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey /** {@hide} */ 449d192dad69e9e5a820c5c11d8cd34460c9cc2ed11Robert Greenwalt public LinkProperties getActiveLinkProperties() { 450d192dad69e9e5a820c5c11d8cd34460c9cc2ed11Robert Greenwalt try { 451d192dad69e9e5a820c5c11d8cd34460c9cc2ed11Robert Greenwalt return mService.getActiveLinkProperties(); 452d192dad69e9e5a820c5c11d8cd34460c9cc2ed11Robert Greenwalt } catch (RemoteException e) { 453d192dad69e9e5a820c5c11d8cd34460c9cc2ed11Robert Greenwalt return null; 454d192dad69e9e5a820c5c11d8cd34460c9cc2ed11Robert Greenwalt } 455d192dad69e9e5a820c5c11d8cd34460c9cc2ed11Robert Greenwalt } 456d192dad69e9e5a820c5c11d8cd34460c9cc2ed11Robert Greenwalt 457c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey /** {@hide} */ 458d192dad69e9e5a820c5c11d8cd34460c9cc2ed11Robert Greenwalt public LinkProperties getLinkProperties(int networkType) { 459d192dad69e9e5a820c5c11d8cd34460c9cc2ed11Robert Greenwalt try { 460d192dad69e9e5a820c5c11d8cd34460c9cc2ed11Robert Greenwalt return mService.getLinkProperties(networkType); 461d192dad69e9e5a820c5c11d8cd34460c9cc2ed11Robert Greenwalt } catch (RemoteException e) { 462d192dad69e9e5a820c5c11d8cd34460c9cc2ed11Robert Greenwalt return null; 463d192dad69e9e5a820c5c11d8cd34460c9cc2ed11Robert Greenwalt } 464d192dad69e9e5a820c5c11d8cd34460c9cc2ed11Robert Greenwalt } 465d192dad69e9e5a820c5c11d8cd34460c9cc2ed11Robert Greenwalt 4669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** {@hide} */ 4679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public boolean setRadios(boolean turnOn) { 4689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 4699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return mService.setRadios(turnOn); 4709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) { 4719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return false; 4729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 4759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** {@hide} */ 4769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public boolean setRadio(int networkType, boolean turnOn) { 4779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 4789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return mService.setRadio(networkType, turnOn); 4799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) { 4809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return false; 4819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 4849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 4859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Tells the underlying networking system that the caller wants to 4869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * begin using the named feature. The interpretation of {@code feature} 4879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * is completely up to each networking implementation. 4889530e3a22d5ffa2019d1a5177b6a441d4d6d048bNicolas Falliere * <p>This method requires the caller to hold the permission 4899530e3a22d5ffa2019d1a5177b6a441d4d6d048bNicolas Falliere * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. 4909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param networkType specifies which network the request pertains to 4919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param feature the name of the feature to be used 4929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return an integer value representing the outcome of the request. 4939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * The interpretation of this value is specific to each networking 4949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * implementation+feature combination, except that the value {@code -1} 4959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * always indicates failure. 4969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public int startUsingNetworkFeature(int networkType, String feature) { 4989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 49942acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt return mService.startUsingNetworkFeature(networkType, feature, 50042acef37339afe6ac608c842f1637870ee9c4f6cRobert Greenwalt new Binder()); 5019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) { 5029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return -1; 5039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 5049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 5059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 5069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 5079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Tells the underlying networking system that the caller is finished 5089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * using the named feature. The interpretation of {@code feature} 5099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * is completely up to each networking implementation. 5109530e3a22d5ffa2019d1a5177b6a441d4d6d048bNicolas Falliere * <p>This method requires the caller to hold the permission 5119530e3a22d5ffa2019d1a5177b6a441d4d6d048bNicolas Falliere * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. 5129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param networkType specifies which network the request pertains to 5139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param feature the name of the feature that is no longer needed 5149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return an integer value representing the outcome of the request. 5159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * The interpretation of this value is specific to each networking 5169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * implementation+feature combination, except that the value {@code -1} 5179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * always indicates failure. 5189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 5199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public int stopUsingNetworkFeature(int networkType, String feature) { 5209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 5219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return mService.stopUsingNetworkFeature(networkType, feature); 5229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) { 5239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return -1; 5249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 5259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 5269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 5279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 5289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Ensure that a network route exists to deliver traffic to the specified 5299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * host via the specified network interface. An attempt to add a route that 5309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * already exists is ignored, but treated as successful. 5319530e3a22d5ffa2019d1a5177b6a441d4d6d048bNicolas Falliere * <p>This method requires the caller to hold the permission 5329530e3a22d5ffa2019d1a5177b6a441d4d6d048bNicolas Falliere * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. 5339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param networkType the type of the network over which traffic to the specified 5349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * host is to be routed 5359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param hostAddress the IP address of the host to which the route is desired 5369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return {@code true} on success, {@code false} on failure 5379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 5389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public boolean requestRouteToHost(int networkType, int hostAddress) { 539585ac0fc8dde3fe35ec4c71c8f215f2c84139b8bRobert Greenwalt InetAddress inetAddress = NetworkUtils.intToInetAddress(hostAddress); 540585ac0fc8dde3fe35ec4c71c8f215f2c84139b8bRobert Greenwalt 541585ac0fc8dde3fe35ec4c71c8f215f2c84139b8bRobert Greenwalt if (inetAddress == null) { 542585ac0fc8dde3fe35ec4c71c8f215f2c84139b8bRobert Greenwalt return false; 543585ac0fc8dde3fe35ec4c71c8f215f2c84139b8bRobert Greenwalt } 544585ac0fc8dde3fe35ec4c71c8f215f2c84139b8bRobert Greenwalt 545585ac0fc8dde3fe35ec4c71c8f215f2c84139b8bRobert Greenwalt return requestRouteToHostAddress(networkType, inetAddress); 546585ac0fc8dde3fe35ec4c71c8f215f2c84139b8bRobert Greenwalt } 547585ac0fc8dde3fe35ec4c71c8f215f2c84139b8bRobert Greenwalt 548585ac0fc8dde3fe35ec4c71c8f215f2c84139b8bRobert Greenwalt /** 549585ac0fc8dde3fe35ec4c71c8f215f2c84139b8bRobert Greenwalt * Ensure that a network route exists to deliver traffic to the specified 550585ac0fc8dde3fe35ec4c71c8f215f2c84139b8bRobert Greenwalt * host via the specified network interface. An attempt to add a route that 551585ac0fc8dde3fe35ec4c71c8f215f2c84139b8bRobert Greenwalt * already exists is ignored, but treated as successful. 552585ac0fc8dde3fe35ec4c71c8f215f2c84139b8bRobert Greenwalt * @param networkType the type of the network over which traffic to the specified 553585ac0fc8dde3fe35ec4c71c8f215f2c84139b8bRobert Greenwalt * host is to be routed 554585ac0fc8dde3fe35ec4c71c8f215f2c84139b8bRobert Greenwalt * @param hostAddress the IP address of the host to which the route is desired 555585ac0fc8dde3fe35ec4c71c8f215f2c84139b8bRobert Greenwalt * @return {@code true} on success, {@code false} on failure 556585ac0fc8dde3fe35ec4c71c8f215f2c84139b8bRobert Greenwalt * @hide 557585ac0fc8dde3fe35ec4c71c8f215f2c84139b8bRobert Greenwalt */ 558585ac0fc8dde3fe35ec4c71c8f215f2c84139b8bRobert Greenwalt public boolean requestRouteToHostAddress(int networkType, InetAddress hostAddress) { 559585ac0fc8dde3fe35ec4c71c8f215f2c84139b8bRobert Greenwalt byte[] address = hostAddress.getAddress(); 5609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 561585ac0fc8dde3fe35ec4c71c8f215f2c84139b8bRobert Greenwalt return mService.requestRouteToHostAddress(networkType, address); 5629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) { 5639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return false; 5649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 5659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 5669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 5679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 5689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Returns the value of the setting for background data usage. If false, 5699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * applications should not use the network if the application is not in the 5709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * foreground. Developers should respect this setting, and check the value 5719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * of this before performing any background data operations. 5729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p> 5739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * All applications that have background services that use the network 5749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * should listen to {@link #ACTION_BACKGROUND_DATA_SETTING_CHANGED}. 5753a844fcf5a0e70a19c38dc500306b9ebe4e1413bJeff Sharkey * <p> 5764cc5333539f57b54663b0a6e398a11a0aaefc8bbScott Main * @deprecated As of {@link VERSION_CODES#ICE_CREAM_SANDWICH}, availability of 5773a844fcf5a0e70a19c38dc500306b9ebe4e1413bJeff Sharkey * background data depends on several combined factors, and this method will 5783a844fcf5a0e70a19c38dc500306b9ebe4e1413bJeff Sharkey * always return {@code true}. Instead, when background data is unavailable, 5793a844fcf5a0e70a19c38dc500306b9ebe4e1413bJeff Sharkey * {@link #getActiveNetworkInfo()} will now appear disconnected. 5806fdd0c6274c81b337ad35b70480f881daf7354c3Danica Chang * 5819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return Whether background data usage is allowed. 5829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 5833a844fcf5a0e70a19c38dc500306b9ebe4e1413bJeff Sharkey @Deprecated 5849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public boolean getBackgroundDataSetting() { 5853a844fcf5a0e70a19c38dc500306b9ebe4e1413bJeff Sharkey // assume that background data is allowed; final authority is 5863a844fcf5a0e70a19c38dc500306b9ebe4e1413bJeff Sharkey // NetworkInfo which may be blocked. 5873a844fcf5a0e70a19c38dc500306b9ebe4e1413bJeff Sharkey return true; 5889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 5899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 5909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 5919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the value of the setting for background data usage. 592c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt * 5939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param allowBackgroundData Whether an application should use data while 5949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * it is in the background. 595c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt * 5969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @attr ref android.Manifest.permission#CHANGE_BACKGROUND_DATA_SETTING 5979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see #getBackgroundDataSetting() 5989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @hide 5999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 6003a844fcf5a0e70a19c38dc500306b9ebe4e1413bJeff Sharkey @Deprecated 6019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setBackgroundDataSetting(boolean allowBackgroundData) { 6023a844fcf5a0e70a19c38dc500306b9ebe4e1413bJeff Sharkey // ignored 6039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 604c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt 605c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt /** 606f0ceede8fff5df24e5c98701d81c2b71eb138aa9Jeff Sharkey * Return quota status for the current active network, or {@code null} if no 607f0ceede8fff5df24e5c98701d81c2b71eb138aa9Jeff Sharkey * network is active. Quota status can change rapidly, so these values 608f0ceede8fff5df24e5c98701d81c2b71eb138aa9Jeff Sharkey * shouldn't be cached. 60944a3e0d497f19fad1de4b73eb0eb6d3b6132c405Jeff Sharkey * 61044a3e0d497f19fad1de4b73eb0eb6d3b6132c405Jeff Sharkey * @hide 611f0ceede8fff5df24e5c98701d81c2b71eb138aa9Jeff Sharkey */ 612f0ceede8fff5df24e5c98701d81c2b71eb138aa9Jeff Sharkey public NetworkQuotaInfo getActiveNetworkQuotaInfo() { 613f0ceede8fff5df24e5c98701d81c2b71eb138aa9Jeff Sharkey try { 614f0ceede8fff5df24e5c98701d81c2b71eb138aa9Jeff Sharkey return mService.getActiveNetworkQuotaInfo(); 615f0ceede8fff5df24e5c98701d81c2b71eb138aa9Jeff Sharkey } catch (RemoteException e) { 616f0ceede8fff5df24e5c98701d81c2b71eb138aa9Jeff Sharkey return null; 617f0ceede8fff5df24e5c98701d81c2b71eb138aa9Jeff Sharkey } 618f0ceede8fff5df24e5c98701d81c2b71eb138aa9Jeff Sharkey } 619f0ceede8fff5df24e5c98701d81c2b71eb138aa9Jeff Sharkey 620f0ceede8fff5df24e5c98701d81c2b71eb138aa9Jeff Sharkey /** 621c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt * Gets the value of the setting for enabling Mobile data. 622c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt * 623c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt * @return Whether mobile data is enabled. 624c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt * @hide 625c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt */ 626c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt public boolean getMobileDataEnabled() { 627c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt try { 628c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt return mService.getMobileDataEnabled(); 629c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt } catch (RemoteException e) { 630c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt return true; 631c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt } 632c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt } 633c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt 634c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt /** 635c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt * Sets the persisted value for enabling/disabling Mobile data. 636c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt * 6375a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt * @param enabled Whether the mobile data connection should be 638c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt * used or not. 639c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt * @hide 640c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt */ 641c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt public void setMobileDataEnabled(boolean enabled) { 642c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt try { 643c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt mService.setMobileDataEnabled(enabled); 644c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt } catch (RemoteException e) { 645c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt } 646c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt } 647c03fa5014912684367174ff3cce664deb29f5e0eRobert Greenwalt 6489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 6499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@hide} 6509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 6519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public ConnectivityManager(IConnectivityManager service) { 652f0ceede8fff5df24e5c98701d81c2b71eb138aa9Jeff Sharkey mService = checkNotNull(service, "missing IConnectivityManager"); 6539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 654d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt 6558fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey /** {@hide} */ 6568fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey public static ConnectivityManager from(Context context) { 6578fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 6588fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey } 6598fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey 660d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt /** 661d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt * {@hide} 662d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt */ 663d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt public String[] getTetherableIfaces() { 664d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt try { 665d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt return mService.getTetherableIfaces(); 666d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt } catch (RemoteException e) { 667d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt return new String[0]; 668d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt } 669d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt } 670d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt 671d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt /** 672d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt * {@hide} 673d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt */ 674d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt public String[] getTetheredIfaces() { 675d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt try { 676d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt return mService.getTetheredIfaces(); 677d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt } catch (RemoteException e) { 678d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt return new String[0]; 679d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt } 680d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt } 681d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt 682d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt /** 683d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt * {@hide} 684d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt */ 6855a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt public String[] getTetheringErroredIfaces() { 6865a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt try { 6875a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt return mService.getTetheringErroredIfaces(); 6885a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt } catch (RemoteException e) { 6895a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt return new String[0]; 6905a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt } 6915a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt } 6925a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt 6935a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt /** 6945a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt * @return error A TETHER_ERROR value indicating success or failure type 6955a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt * {@hide} 6965a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt */ 6975a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt public int tether(String iface) { 698d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt try { 699d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt return mService.tether(iface); 700d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt } catch (RemoteException e) { 7015a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt return TETHER_ERROR_SERVICE_UNAVAIL; 702d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt } 703d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt } 704d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt 705d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt /** 7065a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt * @return error A TETHER_ERROR value indicating success or failure type 707d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt * {@hide} 708d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt */ 7095a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt public int untether(String iface) { 710d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt try { 711d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt return mService.untether(iface); 712d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt } catch (RemoteException e) { 7135a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt return TETHER_ERROR_SERVICE_UNAVAIL; 714d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt } 715d0e18ffb82b59d38aeaf0e552f48e734202719abRobert Greenwalt } 7162a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt 7172a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt /** 7182a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt * {@hide} 7192a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt */ 7202a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt public boolean isTetheringSupported() { 7212a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt try { 7222a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt return mService.isTetheringSupported(); 7232a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt } catch (RemoteException e) { 7242a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt return false; 7252a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt } 7262a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt } 7272a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt 7282a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt /** 7292a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt * {@hide} 7302a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt */ 7312a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt public String[] getTetherableUsbRegexs() { 7322a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt try { 7332a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt return mService.getTetherableUsbRegexs(); 7342a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt } catch (RemoteException e) { 7352a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt return new String[0]; 7362a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt } 7372a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt } 7382a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt 7392a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt /** 7402a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt * {@hide} 7412a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt */ 7422a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt public String[] getTetherableWifiRegexs() { 7432a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt try { 7442a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt return mService.getTetherableWifiRegexs(); 7452a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt } catch (RemoteException e) { 7462a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt return new String[0]; 7472a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt } 7482a091d7aa0c174986387e5d56bf97a87fe075bdbRobert Greenwalt } 7495a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt 7506fdd0c6274c81b337ad35b70480f881daf7354c3Danica Chang /** 7516fdd0c6274c81b337ad35b70480f881daf7354c3Danica Chang * {@hide} 7526fdd0c6274c81b337ad35b70480f881daf7354c3Danica Chang */ 7536fdd0c6274c81b337ad35b70480f881daf7354c3Danica Chang public String[] getTetherableBluetoothRegexs() { 7546fdd0c6274c81b337ad35b70480f881daf7354c3Danica Chang try { 7556fdd0c6274c81b337ad35b70480f881daf7354c3Danica Chang return mService.getTetherableBluetoothRegexs(); 7566fdd0c6274c81b337ad35b70480f881daf7354c3Danica Chang } catch (RemoteException e) { 7576fdd0c6274c81b337ad35b70480f881daf7354c3Danica Chang return new String[0]; 7586fdd0c6274c81b337ad35b70480f881daf7354c3Danica Chang } 7596fdd0c6274c81b337ad35b70480f881daf7354c3Danica Chang } 7606fdd0c6274c81b337ad35b70480f881daf7354c3Danica Chang 7616c2260b3af3a9243aa7f04cf03106f31817cb4c1Mike Lockwood /** 7626c2260b3af3a9243aa7f04cf03106f31817cb4c1Mike Lockwood * {@hide} 7636c2260b3af3a9243aa7f04cf03106f31817cb4c1Mike Lockwood */ 7646c2260b3af3a9243aa7f04cf03106f31817cb4c1Mike Lockwood public int setUsbTethering(boolean enable) { 7656c2260b3af3a9243aa7f04cf03106f31817cb4c1Mike Lockwood try { 7666c2260b3af3a9243aa7f04cf03106f31817cb4c1Mike Lockwood return mService.setUsbTethering(enable); 7676c2260b3af3a9243aa7f04cf03106f31817cb4c1Mike Lockwood } catch (RemoteException e) { 7686c2260b3af3a9243aa7f04cf03106f31817cb4c1Mike Lockwood return TETHER_ERROR_SERVICE_UNAVAIL; 7696c2260b3af3a9243aa7f04cf03106f31817cb4c1Mike Lockwood } 7706c2260b3af3a9243aa7f04cf03106f31817cb4c1Mike Lockwood } 7716c2260b3af3a9243aa7f04cf03106f31817cb4c1Mike Lockwood 7725a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt /** {@hide} */ 7735a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt public static final int TETHER_ERROR_NO_ERROR = 0; 7745a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt /** {@hide} */ 7755a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt public static final int TETHER_ERROR_UNKNOWN_IFACE = 1; 7765a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt /** {@hide} */ 7775a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt public static final int TETHER_ERROR_SERVICE_UNAVAIL = 2; 7785a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt /** {@hide} */ 7795a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt public static final int TETHER_ERROR_UNSUPPORTED = 3; 7805a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt /** {@hide} */ 7815a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt public static final int TETHER_ERROR_UNAVAIL_IFACE = 4; 7825a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt /** {@hide} */ 7835a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt public static final int TETHER_ERROR_MASTER_ERROR = 5; 7845a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt /** {@hide} */ 7855a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt public static final int TETHER_ERROR_TETHER_IFACE_ERROR = 6; 7865a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt /** {@hide} */ 7875a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt public static final int TETHER_ERROR_UNTETHER_IFACE_ERROR = 7; 7885a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt /** {@hide} */ 7895a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt public static final int TETHER_ERROR_ENABLE_NAT_ERROR = 8; 7905a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt /** {@hide} */ 7915a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt public static final int TETHER_ERROR_DISABLE_NAT_ERROR = 9; 7925a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt /** {@hide} */ 7935a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt public static final int TETHER_ERROR_IFACE_CFG_ERROR = 10; 7945a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt 7955a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt /** 7965a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt * @param iface The name of the interface we're interested in 7975a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt * @return error The error code of the last error tethering or untethering the named 7985a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt * interface 7995a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt * {@hide} 8005a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt */ 8015a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt public int getLastTetherError(String iface) { 8025a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt try { 8035a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt return mService.getLastTetherError(iface); 8045a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt } catch (RemoteException e) { 8055a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt return TETHER_ERROR_SERVICE_UNAVAIL; 8065a73506cdd466f2b96686ced3ff0f7ca224d1143Robert Greenwalt } 80714f2ef4c9da27a3d58d65dc9f684c5f764ee279aRobert Greenwalt } 80814f2ef4c9da27a3d58d65dc9f684c5f764ee279aRobert Greenwalt 80914f2ef4c9da27a3d58d65dc9f684c5f764ee279aRobert Greenwalt /** 81014f2ef4c9da27a3d58d65dc9f684c5f764ee279aRobert Greenwalt * Ensure the device stays awake until we connect with the next network 81114f2ef4c9da27a3d58d65dc9f684c5f764ee279aRobert Greenwalt * @param forWhome The name of the network going down for logging purposes 81214f2ef4c9da27a3d58d65dc9f684c5f764ee279aRobert Greenwalt * @return {@code true} on success, {@code false} on failure 81314f2ef4c9da27a3d58d65dc9f684c5f764ee279aRobert Greenwalt * {@hide} 81414f2ef4c9da27a3d58d65dc9f684c5f764ee279aRobert Greenwalt */ 81514f2ef4c9da27a3d58d65dc9f684c5f764ee279aRobert Greenwalt public boolean requestNetworkTransitionWakelock(String forWhom) { 81614f2ef4c9da27a3d58d65dc9f684c5f764ee279aRobert Greenwalt try { 81714f2ef4c9da27a3d58d65dc9f684c5f764ee279aRobert Greenwalt mService.requestNetworkTransitionWakelock(forWhom); 81814f2ef4c9da27a3d58d65dc9f684c5f764ee279aRobert Greenwalt return true; 81914f2ef4c9da27a3d58d65dc9f684c5f764ee279aRobert Greenwalt } catch (RemoteException e) { 82014f2ef4c9da27a3d58d65dc9f684c5f764ee279aRobert Greenwalt return false; 82114f2ef4c9da27a3d58d65dc9f684c5f764ee279aRobert Greenwalt } 82214f2ef4c9da27a3d58d65dc9f684c5f764ee279aRobert Greenwalt } 823ca4306c976d393c3cd04270bc2de0af2f4f30fa5Robert Greenwalt 82467fd6c92922a94f46c7b6793a808f473a43eddd3Robert Greenwalt /** 825d7085fcf6567452a9d6fc69b0c6b1bf556f4c1b9Robert Greenwalt * @param networkType The type of network you want to report on 826d7085fcf6567452a9d6fc69b0c6b1bf556f4c1b9Robert Greenwalt * @param percentage The quality of the connection 0 is bad, 100 is good 827d7085fcf6567452a9d6fc69b0c6b1bf556f4c1b9Robert Greenwalt * {@hide} 828d7085fcf6567452a9d6fc69b0c6b1bf556f4c1b9Robert Greenwalt */ 829d7085fcf6567452a9d6fc69b0c6b1bf556f4c1b9Robert Greenwalt public void reportInetCondition(int networkType, int percentage) { 830d7085fcf6567452a9d6fc69b0c6b1bf556f4c1b9Robert Greenwalt try { 831d7085fcf6567452a9d6fc69b0c6b1bf556f4c1b9Robert Greenwalt mService.reportInetCondition(networkType, percentage); 832d7085fcf6567452a9d6fc69b0c6b1bf556f4c1b9Robert Greenwalt } catch (RemoteException e) { 833d7085fcf6567452a9d6fc69b0c6b1bf556f4c1b9Robert Greenwalt } 834d7085fcf6567452a9d6fc69b0c6b1bf556f4c1b9Robert Greenwalt } 835434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt 836434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt /** 837434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt * @param proxyProperties The definition for the new global http proxy 838434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt * {@hide} 839434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt */ 840434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt public void setGlobalProxy(ProxyProperties p) { 841434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt try { 842434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt mService.setGlobalProxy(p); 843434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt } catch (RemoteException e) { 844434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt } 845434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt } 846434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt 847434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt /** 848434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt * @return proxyProperties for the current global proxy 849434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt * {@hide} 850434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt */ 851434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt public ProxyProperties getGlobalProxy() { 852434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt try { 853434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt return mService.getGlobalProxy(); 854434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt } catch (RemoteException e) { 855434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt return null; 856434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt } 857434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt } 858434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt 859434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt /** 860434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt * @return proxyProperties for the current proxy (global if set, network specific if not) 861434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt * {@hide} 862434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt */ 863434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt public ProxyProperties getProxy() { 864434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt try { 865434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt return mService.getProxy(); 866434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt } catch (RemoteException e) { 867434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt return null; 868434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt } 869434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt } 870d55a6b498d66d8fc415908ecf63e50f46cce67e8Robert Greenwalt 871d55a6b498d66d8fc415908ecf63e50f46cce67e8Robert Greenwalt /** 872d55a6b498d66d8fc415908ecf63e50f46cce67e8Robert Greenwalt * @param networkType The network who's dependence has changed 873d55a6b498d66d8fc415908ecf63e50f46cce67e8Robert Greenwalt * @param met Boolean - true if network use is ok, false if not 874d55a6b498d66d8fc415908ecf63e50f46cce67e8Robert Greenwalt * {@hide} 875d55a6b498d66d8fc415908ecf63e50f46cce67e8Robert Greenwalt */ 876d55a6b498d66d8fc415908ecf63e50f46cce67e8Robert Greenwalt public void setDataDependency(int networkType, boolean met) { 877d55a6b498d66d8fc415908ecf63e50f46cce67e8Robert Greenwalt try { 878d55a6b498d66d8fc415908ecf63e50f46cce67e8Robert Greenwalt mService.setDataDependency(networkType, met); 879d55a6b498d66d8fc415908ecf63e50f46cce67e8Robert Greenwalt } catch (RemoteException e) { 880d55a6b498d66d8fc415908ecf63e50f46cce67e8Robert Greenwalt } 881d55a6b498d66d8fc415908ecf63e50f46cce67e8Robert Greenwalt } 8829b2886e24301e5d4e7052ec4a6eaff273d3f516cRobert Greenwalt 8839b2886e24301e5d4e7052ec4a6eaff273d3f516cRobert Greenwalt /** 8849b2886e24301e5d4e7052ec4a6eaff273d3f516cRobert Greenwalt * Returns true if the hardware supports the given network type 8859b2886e24301e5d4e7052ec4a6eaff273d3f516cRobert Greenwalt * else it returns false. This doesn't indicate we have coverage 8869b2886e24301e5d4e7052ec4a6eaff273d3f516cRobert Greenwalt * or are authorized onto a network, just whether or not the 8879b2886e24301e5d4e7052ec4a6eaff273d3f516cRobert Greenwalt * hardware supports it. For example a gsm phone without a sim 8889b2886e24301e5d4e7052ec4a6eaff273d3f516cRobert Greenwalt * should still return true for mobile data, but a wifi only tablet 8899b2886e24301e5d4e7052ec4a6eaff273d3f516cRobert Greenwalt * would return false. 8909b2886e24301e5d4e7052ec4a6eaff273d3f516cRobert Greenwalt * @param networkType The nework type we'd like to check 8919b2886e24301e5d4e7052ec4a6eaff273d3f516cRobert Greenwalt * @return true if supported, else false 8929b2886e24301e5d4e7052ec4a6eaff273d3f516cRobert Greenwalt * @hide 8939b2886e24301e5d4e7052ec4a6eaff273d3f516cRobert Greenwalt */ 8949b2886e24301e5d4e7052ec4a6eaff273d3f516cRobert Greenwalt public boolean isNetworkSupported(int networkType) { 8959b2886e24301e5d4e7052ec4a6eaff273d3f516cRobert Greenwalt try { 8969b2886e24301e5d4e7052ec4a6eaff273d3f516cRobert Greenwalt return mService.isNetworkSupported(networkType); 8979b2886e24301e5d4e7052ec4a6eaff273d3f516cRobert Greenwalt } catch (RemoteException e) {} 8989b2886e24301e5d4e7052ec4a6eaff273d3f516cRobert Greenwalt return false; 8999b2886e24301e5d4e7052ec4a6eaff273d3f516cRobert Greenwalt } 9009f7cbf0e50bcb7e9163b23524814003ba8784732Jeff Sharkey 9019f7cbf0e50bcb7e9163b23524814003ba8784732Jeff Sharkey /** 9029f7cbf0e50bcb7e9163b23524814003ba8784732Jeff Sharkey * Returns if the currently active data network is metered. A network is 9039f7cbf0e50bcb7e9163b23524814003ba8784732Jeff Sharkey * classified as metered when the user is sensitive to heavy data usage on 9049f7cbf0e50bcb7e9163b23524814003ba8784732Jeff Sharkey * that connection. You should check this before doing large data transfers, 9059f7cbf0e50bcb7e9163b23524814003ba8784732Jeff Sharkey * and warn the user or delay the operation until another network is 9069f7cbf0e50bcb7e9163b23524814003ba8784732Jeff Sharkey * available. 9079f7cbf0e50bcb7e9163b23524814003ba8784732Jeff Sharkey */ 9089f7cbf0e50bcb7e9163b23524814003ba8784732Jeff Sharkey public boolean isActiveNetworkMetered() { 9099f7cbf0e50bcb7e9163b23524814003ba8784732Jeff Sharkey try { 9109f7cbf0e50bcb7e9163b23524814003ba8784732Jeff Sharkey return mService.isActiveNetworkMetered(); 9119f7cbf0e50bcb7e9163b23524814003ba8784732Jeff Sharkey } catch (RemoteException e) { 9129f7cbf0e50bcb7e9163b23524814003ba8784732Jeff Sharkey return false; 9139f7cbf0e50bcb7e9163b23524814003ba8784732Jeff Sharkey } 9149f7cbf0e50bcb7e9163b23524814003ba8784732Jeff Sharkey } 9159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project} 916