publicstatic final int TETHERING_WIFI=0;
mConnectivityManager.startTethering(TETHERING_WIFI,true/* showProvisioningUi */,
mOnStartTetheringCallback,newHandler(Looper.getMainLooper()));
@Override
public boolean startSoftAp(WifiConfiguration wifiConfig){
mLog.info("startSoftAp Band:"+wifiConfig);// NETWORK_STACK is a signature only permission.enforceNetworkStackPermission();
mLog.info("startSoftAp uid=%").c(Binder.getCallingUid()).flush();synchronized(mLocalOnlyHotspotRequests){// If a tethering request comes in while we have an existing tethering session, return// error.if(mIfaceIpModes.contains(WifiManager.IFACE_IP_MODE_TETHERED)){
mLog.err("Tethering is already active.").flush();returnfalse;}// If a tethering request comes in while we have LOHS running (or requested), call stop// for softap mode and restart softap with the tethering config.if(!isConcurrentLohsAndTetheringSupported()&&!mLocalOnlyHotspotRequests.isEmpty()){stopSoftApInternal(WifiManager.IFACE_IP_MODE_LOCAL_ONLY);}returnstartSoftApInternal(wifiConfig, WifiManager.IFACE_IP_MODE_TETHERED);}}private boolean startSoftApInternal(WifiConfiguration wifiConfig, int mode){
mLog.trace("startSoftApInternal uid=% mode=%").c(Binder.getCallingUid()).c(mode).flush();// null wifiConfig is a meaningful input for CMD_SET_APif(wifiConfig ==null|| WifiApConfigStore.validateApWifiConfiguration(wifiConfig)){
SoftApModeConfiguration softApConfig =newSoftApModeConfiguration(mode, wifiConfig);
mWifiController.sendMessage(CMD_SET_AP,1,0, softApConfig);//看这里
Slog.d(TAG,"softApConfig Band"+wifiConfig);returntrue;}
Slog.e(TAG,"Invalid WifiConfiguration");returnfalse;}
@UnsupportedAppUsage
publicvoidsendMessage(int what, int arg1, int arg2, Object obj){// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;if(smh ==null)return;
smh.sendMessage(obtainMessage(what, arg1, arg2, obj));}
WifiController.java中,
class DefaultState extends State,
class DefaultState extends State,
class StaEnabledState extends State,
class StaDisabledWithScanState extends State,
都实现了processMessage()方法,所以看这里有对CMD_SET_AP的处理
caseCMD_SET_AP:// note: CMD_SET_AP is handled/dropped in ECM mode - will not start here
Log.d(TAG,"CMD_SET_AP enterSoftAPMode stopSoftAPMode msg.arg1:"+msg.arg1);if(msg.arg1 ==1){
SoftApModeConfiguration config =(SoftApModeConfiguration) msg.obj;
mActiveModeWarden.enterSoftAPMode((SoftApModeConfiguration) msg.obj);}else{
mActiveModeWarden.stopSoftAPMode(msg.arg2);}break;caseCMD_SET_AP:
Log.d(TAG,"CMD_SET_AP WIFI_DISABLED msg.arg1:"+msg.arg1);if(msg.arg1 ==1){// remember that we were disabled, but pass the command up to start softap
mSettingsStore.setWifiSavedState(WifiSettingsStore.WIFI_DISABLED);}returnNOT_HANDLED;caseCMD_SET_AP:
Log.d(TAG,"CMD_SET_AP setWifiSavedState msg.arg1:"+msg.arg1);if(msg.arg1 ==1){// remember that we were disabled, but pass the command up to start softap
mSettingsStore.setWifiSavedState(WifiSettingsStore.WIFI_DISABLED);//这里关闭了wifi,待确认}returnNOT_HANDLED;caseCMD_SET_AP:
Log.d(TAG,"CMD_SET_AP HANDLED");// do not want to start softap if we are in emergency modereturnHANDLED;