Merge "Create new isNetworkSupported API"
This commit is contained in:
committed by
Android (Google) Code Review
commit
2d012c128f
@@ -814,4 +814,22 @@ public class ConnectivityManager {
|
|||||||
} catch (RemoteException e) {
|
} 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ interface IConnectivityManager
|
|||||||
NetworkInfo getNetworkInfo(int networkType);
|
NetworkInfo getNetworkInfo(int networkType);
|
||||||
NetworkInfo[] getAllNetworkInfo();
|
NetworkInfo[] getAllNetworkInfo();
|
||||||
|
|
||||||
|
boolean isNetworkSupported(int networkType);
|
||||||
|
|
||||||
LinkProperties getActiveLinkProperties();
|
LinkProperties getActiveLinkProperties();
|
||||||
LinkProperties getLinkProperties(int networkType);
|
LinkProperties getLinkProperties(int networkType);
|
||||||
|
|
||||||
|
|||||||
@@ -130,6 +130,8 @@ public class NetworkController extends BroadcastReceiver {
|
|||||||
int mLastDataTypeIconId = -1;
|
int mLastDataTypeIconId = -1;
|
||||||
String mLastLabel = "";
|
String mLastLabel = "";
|
||||||
|
|
||||||
|
private boolean mHasMobileDataFeature;
|
||||||
|
|
||||||
boolean mDataAndWifiStacked = false;
|
boolean mDataAndWifiStacked = false;
|
||||||
|
|
||||||
// yuck -- stop doing this here and put it in the framework
|
// yuck -- stop doing this here and put it in the framework
|
||||||
@@ -147,6 +149,10 @@ public class NetworkController extends BroadcastReceiver {
|
|||||||
public NetworkController(Context context) {
|
public NetworkController(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
|
||||||
|
ConnectivityManager cm = (ConnectivityManager)mContext.getSystemService(
|
||||||
|
Context.CONNECTIVITY_SERVICE);
|
||||||
|
mHasMobileDataFeature = cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
|
||||||
|
|
||||||
// set up the default wifi icon, used when no radios have ever appeared
|
// set up the default wifi icon, used when no radios have ever appeared
|
||||||
updateWifiIcons();
|
updateWifiIcons();
|
||||||
|
|
||||||
@@ -229,7 +235,7 @@ public class NetworkController extends BroadcastReceiver {
|
|||||||
mWifiIconId,
|
mWifiIconId,
|
||||||
mWifiActivityIconId);
|
mWifiActivityIconId);
|
||||||
cluster.setMobileDataIndicators(
|
cluster.setMobileDataIndicators(
|
||||||
hasMobileDataFeature(),
|
mHasMobileDataFeature,
|
||||||
mPhoneSignalIconId,
|
mPhoneSignalIconId,
|
||||||
mMobileActivityIconId,
|
mMobileActivityIconId,
|
||||||
mDataTypeIconId);
|
mDataTypeIconId);
|
||||||
@@ -376,12 +382,6 @@ public class NetworkController extends BroadcastReceiver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasMobileDataFeature() {
|
|
||||||
// XXX: HAX: replace when a more reliable method is available
|
|
||||||
return (! "wifi-only".equals(SystemProperties.get("ro.carrier")));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void updateAirplaneMode() {
|
private void updateAirplaneMode() {
|
||||||
mAirplaneMode = (Settings.System.getInt(mContext.getContentResolver(),
|
mAirplaneMode = (Settings.System.getInt(mContext.getContentResolver(),
|
||||||
Settings.System.AIRPLANE_MODE_ON, 0) == 1);
|
Settings.System.AIRPLANE_MODE_ON, 0) == 1);
|
||||||
@@ -828,8 +828,8 @@ public class NetworkController extends BroadcastReceiver {
|
|||||||
label = context.getString(R.string.status_bar_settings_signal_meter_disconnected);
|
label = context.getString(R.string.status_bar_settings_signal_meter_disconnected);
|
||||||
// On devices without mobile radios, we want to show the wifi icon
|
// On devices without mobile radios, we want to show the wifi icon
|
||||||
combinedSignalIconId =
|
combinedSignalIconId =
|
||||||
hasMobileDataFeature() ? mDataSignalIconId : mWifiIconId;
|
mHasMobileDataFeature ? mDataSignalIconId : mWifiIconId;
|
||||||
mContentDescriptionCombinedSignal = hasMobileDataFeature()
|
mContentDescriptionCombinedSignal = mHasMobileDataFeature
|
||||||
? mContentDescriptionDataType : mContentDescriptionWifi;
|
? mContentDescriptionDataType : mContentDescriptionWifi;
|
||||||
mDataTypeIconId = 0;
|
mDataTypeIconId = 0;
|
||||||
}
|
}
|
||||||
@@ -866,7 +866,7 @@ public class NetworkController extends BroadcastReceiver {
|
|||||||
mWifiIconId,
|
mWifiIconId,
|
||||||
mWifiActivityIconId);
|
mWifiActivityIconId);
|
||||||
cluster.setMobileDataIndicators(
|
cluster.setMobileDataIndicators(
|
||||||
hasMobileDataFeature(),
|
mHasMobileDataFeature,
|
||||||
mPhoneSignalIconId,
|
mPhoneSignalIconId,
|
||||||
mMobileActivityIconId,
|
mMobileActivityIconId,
|
||||||
mDataTypeIconId);
|
mDataTypeIconId);
|
||||||
|
|||||||
@@ -703,6 +703,12 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
return result.toArray(new NetworkInfo[result.size()]);
|
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
|
* Return LinkProperties for the active (i.e., connected) default
|
||||||
* network interface. It is assumed that at most one default network
|
* network interface. It is assumed that at most one default network
|
||||||
|
|||||||
@@ -350,7 +350,6 @@ class ServerThread extends Thread {
|
|||||||
Slog.i(TAG, "Wi-Fi Service");
|
Slog.i(TAG, "Wi-Fi Service");
|
||||||
wifi = new WifiService(context);
|
wifi = new WifiService(context);
|
||||||
ServiceManager.addService(Context.WIFI_SERVICE, wifi);
|
ServiceManager.addService(Context.WIFI_SERVICE, wifi);
|
||||||
wifi.checkAndStartWifi();
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
reportWtf("starting Wi-Fi Service", e);
|
reportWtf("starting Wi-Fi Service", e);
|
||||||
}
|
}
|
||||||
@@ -361,6 +360,7 @@ class ServerThread extends Thread {
|
|||||||
ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
|
ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
|
||||||
networkStats.bindConnectivityManager(connectivity);
|
networkStats.bindConnectivityManager(connectivity);
|
||||||
networkPolicy.bindConnectivityManager(connectivity);
|
networkPolicy.bindConnectivityManager(connectivity);
|
||||||
|
wifi.checkAndStartWifi();
|
||||||
wifiP2p.connectivityServiceReady();
|
wifiP2p.connectivityServiceReady();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
reportWtf("starting Connectivity Service", e);
|
reportWtf("starting Connectivity Service", e);
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
import android.net.LocalSocket;
|
import android.net.LocalSocket;
|
||||||
import android.net.LocalSocketAddress;
|
import android.net.LocalSocketAddress;
|
||||||
import android.os.AsyncResult;
|
import android.os.AsyncResult;
|
||||||
@@ -230,8 +231,6 @@ public final class RIL extends BaseCommands implements CommandsInterface {
|
|||||||
|
|
||||||
Object mLastNITZTimeInfo;
|
Object mLastNITZTimeInfo;
|
||||||
|
|
||||||
private static final String WIFI_ONLY_CARRIER = "wifi-only";
|
|
||||||
|
|
||||||
//***** Events
|
//***** Events
|
||||||
|
|
||||||
static final int EVENT_SEND = 1;
|
static final int EVENT_SEND = 1;
|
||||||
@@ -626,10 +625,9 @@ public final class RIL extends BaseCommands implements CommandsInterface {
|
|||||||
Looper looper = mSenderThread.getLooper();
|
Looper looper = mSenderThread.getLooper();
|
||||||
mSender = new RILSender(looper);
|
mSender = new RILSender(looper);
|
||||||
|
|
||||||
// TODO: Provide a common API for determining if a
|
ConnectivityManager cm = (ConnectivityManager)context.getSystemService(
|
||||||
// device is wifi-only. bug: 3480713
|
Context.CONNECTIVITY_SERVICE);
|
||||||
String carrier = SystemProperties.get("ro.carrier");
|
if (cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE) == false) {
|
||||||
if (WIFI_ONLY_CARRIER.equals(carrier)) {
|
|
||||||
riljLog("Not starting RILReceiver: wifi-only");
|
riljLog("Not starting RILReceiver: wifi-only");
|
||||||
} else {
|
} else {
|
||||||
riljLog("Starting RILReceiver");
|
riljLog("Starting RILReceiver");
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import android.os.SystemProperties;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.provider.Settings.Secure;
|
import android.provider.Settings.Secure;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.internal.util.Protocol;
|
import com.android.internal.util.Protocol;
|
||||||
import com.android.internal.util.State;
|
import com.android.internal.util.State;
|
||||||
@@ -174,7 +175,7 @@ public class WifiWatchdogStateMachine extends StateMachine {
|
|||||||
* It triggers a disableNetwork call if a DNS check fails.
|
* It triggers a disableNetwork call if a DNS check fails.
|
||||||
*/
|
*/
|
||||||
public boolean mDisableAPNextFailure = false;
|
public boolean mDisableAPNextFailure = false;
|
||||||
private ConnectivityManager mConnectivityManager;
|
private static boolean sWifiOnly = false;
|
||||||
private boolean mNotificationShown;
|
private boolean mNotificationShown;
|
||||||
public boolean mHasConnectedWifiManager = false;
|
public boolean mHasConnectedWifiManager = false;
|
||||||
|
|
||||||
@@ -219,9 +220,14 @@ public class WifiWatchdogStateMachine extends StateMachine {
|
|||||||
|
|
||||||
public static WifiWatchdogStateMachine makeWifiWatchdogStateMachine(Context context) {
|
public static WifiWatchdogStateMachine makeWifiWatchdogStateMachine(Context context) {
|
||||||
ContentResolver contentResolver = context.getContentResolver();
|
ContentResolver contentResolver = context.getContentResolver();
|
||||||
|
|
||||||
|
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(
|
||||||
|
Context.CONNECTIVITY_SERVICE);
|
||||||
|
sWifiOnly = (cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE) == false);
|
||||||
|
|
||||||
// Disable for wifi only devices.
|
// Disable for wifi only devices.
|
||||||
if (Settings.Secure.getString(contentResolver, Settings.Secure.WIFI_WATCHDOG_ON) == null &&
|
if (Settings.Secure.getString(contentResolver, Settings.Secure.WIFI_WATCHDOG_ON) == null &&
|
||||||
"wifi-only".equals(SystemProperties.get("ro.carrier"))) {
|
sWifiOnly) {
|
||||||
putSettingsBoolean(contentResolver, Settings.Secure.WIFI_WATCHDOG_ON, false);
|
putSettingsBoolean(contentResolver, Settings.Secure.WIFI_WATCHDOG_ON, false);
|
||||||
}
|
}
|
||||||
WifiWatchdogStateMachine wwsm = new WifiWatchdogStateMachine(context);
|
WifiWatchdogStateMachine wwsm = new WifiWatchdogStateMachine(context);
|
||||||
@@ -508,22 +514,6 @@ public class WifiWatchdogStateMachine extends StateMachine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return true if there is definitely no mobile data (we'll be less aggressive)
|
|
||||||
*/
|
|
||||||
private boolean hasNoMobileData() {
|
|
||||||
if (mConnectivityManager == null) {
|
|
||||||
mConnectivityManager = (ConnectivityManager) mContext.getSystemService(
|
|
||||||
Context.CONNECTIVITY_SERVICE);
|
|
||||||
}
|
|
||||||
NetworkInfo mobileNetInfo = mConnectivityManager.getNetworkInfo(
|
|
||||||
ConnectivityManager.TYPE_MOBILE);
|
|
||||||
if (mobileNetInfo == null || !mobileNetInfo.isAvailable()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
class DefaultState extends State {
|
class DefaultState extends State {
|
||||||
@Override
|
@Override
|
||||||
public boolean processMessage(Message msg) {
|
public boolean processMessage(Message msg) {
|
||||||
@@ -941,7 +931,7 @@ public class WifiWatchdogStateMachine extends StateMachine {
|
|||||||
|
|
||||||
if (mDisableAPNextFailure || mNumCheckFailures >= mBssids.size()
|
if (mDisableAPNextFailure || mNumCheckFailures >= mBssids.size()
|
||||||
|| mNumCheckFailures >= mMaxSsidBlacklists) {
|
|| mNumCheckFailures >= mMaxSsidBlacklists) {
|
||||||
if (hasNoMobileData()) {
|
if (sWifiOnly) {
|
||||||
Slog.w(WWSM_TAG, "Would disable bad network, but device has no mobile data!" +
|
Slog.w(WWSM_TAG, "Would disable bad network, but device has no mobile data!" +
|
||||||
" Going idle...");
|
" Going idle...");
|
||||||
// This state should be called idle -- will be changing flow.
|
// This state should be called idle -- will be changing flow.
|
||||||
|
|||||||
Reference in New Issue
Block a user