< >
最近在 rk328/7 上 rk3283 android15.1 和 7.1 上调试了 android166 芯片(该芯片支持 5G 内部),但是我打开 AP 生成 2.4G 的 9 个 5G 时的 AP。在“WLAN”有一个“才选择AP”的选项是android5.1,也是后来我没有解决这个问题的时候,我已经解决了这个问题),但该车只有一个2.4GHz的选项。我在这个G网的文章//0303032里有怎么写死的文章//
03032里有怎么写死的AP,打开5G的标题,然后打开5G不过在里面有“2.4G选项也有5G设置”的选项,那一定是5G的,5G应该被系统选项隐藏了,调查,来打开5G 1.在sapps
/apps/目录设置/packageSettings/下关键字“2.4GHz 选项/设置目录”
值设置/插件设置/插件设置/插件/apps.xml: 插件设置-zh-rCN/strings.xml
继续搜索“2.4 GHz 2.4GHz 包到”包地址。
目录字符串名称 到达ap_choose_2G,目录下:
packages/apps//res/values/arrayxml:
- @string/wifi_ap_choose_2G
3.进入array.xml查看该xml
- @string/wifi_ap_choose_2G
- @string/wifi_ap_choose_5G
- @string/wifi_ap_choose_2G item>
看到果然是有5G选项的字符串:wifi_ap_choose_5G
4.提取目录wifi_ap_band_config_full字符,packages/apps/Settings下继续搜索:
packages/apps/Settings/src/com/android/设置/wifi/WifiApDialog.java:R.array.wifi_ap_band_config_full,android.R.layout.simple_spinner_item);
5.进到WifiApDialog.java下,查看:
if (!mWifiManager.isDualBandSupported() || countryCode == null) {
//如果没有国家代码,则禁止使用 5GHz AP
Log.i(TAG,(!mWifiManager.isDualBandSupported() ? "Device do not support 5GHz " :" ")
+ (countryCode == null ?" NO country code" :"") + "forbid 5GHz");
channelAdapter = ArrayAdapter.createFromResource(mContext,
R.array.wifi_ap_band_config_2G_only, android.R.layout.simple_spinner_item);
mWifiConfig.apBand = 0;
} else {
channelAdapter = ArrayAdapter.createFromResource(mContext,
R.array.wifi_ap_band_config_full, android.R.layout.simple_spinner_item);
}
这里很明显了,有一个if判断:if (!mWifiManager. isDualBandSupported() || 国家代码 == 空)
也是mWifiManager.isDualBandSupported() !=null 并且countryCode != null,进入wifi_ap_band_config_full模式,
countryCode字面就是允许自己的国家代码,在我们中国国内5G信道只允许使用149个以上的信道,因此没有国家是不能使用的国家代码使用5G热点的。
国家代码先放一边,先来查询isDualBandSupported的作用:
6.在frameworks/opt/net/service/java/com/android/server/wifi/wifiServiceImpl.java目录下有对isDualBandSupported的方法的定义:
public boolean isDualBandSupported() {
//TODO: 应该转向添加一个在运行时检查的驱动 API
return mContext.getResources().getBoolean(
com.android.internal.R.bool.config_wifi_dual_band_support);
}
从代码中可以理解到,isDualBandSupported 方法返回值是个布尔类型值,它返回的是config_wifi_dual_band_support所的值,因此我们只要还是去确认config_wifi_dual_band_support 是true false就可以了,不过现在看来该值应该是被该设置成false,下面我们继续去查找值真正被设置成什么:
7.在frameworks/base/core/res/res/values/config.xml目录下,有对config_wifi_dual_band_support值的设置,该值当然是被设置成false,现在把它变成true。
- 3
+
+
+
+ - @string/wifi_ap_choose_2G
+ - @string /wifi_ap_choose_5G
+
+
+ - @string/wifi_ap_choose_2G
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
索引 068df77..9cbbf33 100755
--- a/res/values/strings.xml
++ + b/res/values/strings.xml
@@ -1590,
显示密码
-
- IP 设置
+
+
+ "Seleccionar banda de AP"< /string>
+ "2.4 GHz Band"
+ "5 GHz Band"
+ IP settings
<字符串>(不变)字符串>
diff --git a/src/com/android/settings/wifi/WifiApDialog.java b/src/com/android/settings/wifi/WifiApDialog.java
index fb8026a..6ec1f6c 100644
--- a/src/com/android /settings/wifi/WifiApDialog.java
+++ b/src/com/android/settings/wifi/WifiApDialog.java
@@ -22,12 +22,15 @@ import android.content.DialogInterface;
导入android.net.wifi.WifiConfiguration;
导入android.net.wifi.WifiConfiguration.AuthAlgorithm;
导入android.net.wifi.WifiConfiguration.KeyMgmt;
+导入android.net.wifi.WifiManager;
导入android.os.Bundle;
导入 android.text.Editable;
导入 android.text.InputType;
导入 android.text.TextWatcher;
+导入android.util.Log;
导入android.view.View;
导入 android.widget.AdapterView;
+导入android.widget.ArrayAdapter;
导入 android.widget.CheckBox;
导入 android.widget.EditText;
导入 android.widget.Spinner;
@@ -35,6 +38,8 @@ import android.widget.TextView;
导入 com.android.settings.R;
+导入java.nio.charset.Charset;
+
/**
* 配置 SSID 和安全设置的对话框
* 用于接入点操作
@@ -53,8 +58,13 @@ public class WifiApDialog extends AlertDialog implements View.OnClickListener,
private TextView mSsid;
私有 int mSecurityTypeIndex = OPEN_INDEX;
私人 EditText mPassword;
+ 私有 int mBandIndex = OPEN_INDEX;
WifiConfiguration mWifiConfig;
+ WifiManager mWifiManager;
+ 私有上下文 mContext;
++
私有静态最终字符串标签=“WifiApDialog”;
public WifiApDialog(Context context, DialogInterface.OnClickListener listener,
WifiConfiguration wifiConfig) {
@@ -64,6 +74,8 @@ public class WifiApDialog extends AlertDialog implements View.OnClickListener,
if (wifiConfig != null) {
mSecurityTypeIndex = getSecurityTypeIndex(wifiConfig );
}
+ mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
+ mContext = 上下文;
}
public static int getSecurityTypeIndex(WifiConfiguration wifiConfig) {
@@ -85,6 +97,8 @@ public class WifiApDialog extends AlertDialog implements View.OnClickListener,
*/
config.SSID = mSsid.getText().toString();
+ config.apBand = mBandIndex;
+
switch (mSecurityTypeIndex) {
case OPEN_INDEX:
config.allowedKeyManagement.set(KeyMgmt.NONE);
@@ -104,9 +118,10 @@ public class WifiApDialog extends AlertDialog implements View.OnClickListener, @Override
protected
void onCreate(Bundle savedInstanceState) {
-
+ boolean mInit = true;
mView = getLayoutInflater().inflate(R.layout.wifi_ap_dialog, null);
微调器 mSecurity = ((Spinner) mView.findViewById(R.id.security));
+ 最终 Spinner mChannel = (Spinner) mView.findViewById(R.id.choose_channel);
设置视图(mView);
setInverseBackgroundForced(true);
@@ -118,18 +133,68 @@ public class WifiApDialog extends AlertDialog implements View.OnClickListener,
mSsid = (TextView) mView.findViewById(R.id.ssid);
mPassword = (EditText) mView.findViewById(R.id.password);
+ ArrayAdapter 通道适配器;
+ //String countryCode = mWifiManager.getCountryCode();
+ 字符串国家代码 = "CN"; //louhn:这里写死为CN
+
+ if (countryCode == null) {
+ //如果没有国家代码,5GHz AP被禁止
+ Log.i(TAG,(!mWifiManager.isDualBandSupported() ? "Device do not support 5GHz " :"")
+ + (countryCode == null ? " NO country code" :"") + " forbid 5GHz");
+ channelAdapter = ArrayAdapter.createFromResource(mContext,
+ R.array.wifi_ap_band_config_2G_only, android.R.layout.simple_spinner_item);
+ mWifiConfig.apBand = 0;
+ } else {
+ channelAdapter = ArrayAdapter.createFromResource(mContext,
+ R.array.wifi_ap_band_config_full, android.R.layout.simple_spinner_item);
+
+ channelAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+
setButton(BUTTON_SUBMIT, context.getString(R.string.wifi_save), mListener);
setButton(DialogInterface.BUTTON_NEGATIVE,
context.getString(R.string.wifi_cancel), mListener);
if (mWifiConfig != null) {
mSsid.setText(mWifiConfig.SSID);
+ if (mWifiConfig.apBand == 0) {
+ mBandIndex = 0;
+ } 其他 {
+ mBandIndex = 1;
+ }
+
mSecurity.setSelection(mSecurityTypeIndex);
如果(mSecurityTypeIndex == WPA2_INDEX){
- mPassword.setText(mWifiConfig.preSharedKey);
+ mPassword.setText(mWifiConfig.preSharedKey);
}
}
+ mChannel.setAdapter(channelAdapter);
+ mChannel.setOnItemSelectedListener(
+ new AdapterView.OnItemSelectedListener() {
+ boolean mInit = true;
+
@Override + public void onItemSelected(AdapterView> adapterView, View view, int position,
+ long id) {
+ if (!mInit) {
+ mBandIndex = 位置;
+ mWifiConfig.apBand = mBandIndex;
+ Log.i(TAG, "config on channelIndex : " + mBandIndex + " Band: " +
+ mWifiConfig.apBand);
+ } 其他 {
+ mInit = false;
+ mChannel.setSelection(mBandIndex);
+ }
+
+ }
+
+
@Override + public void onNothingSelected(AdapterView> adapterView) {
+
+ }
+ }
+ );
+
mSsid.addTextChangedListener(this);
mPassword.addTextChangedListener(this);
((CheckBox) mView.findViewById(R.id.show_password)).setOnClickListener(this);
@@ -141,10 +206,21 @@ public class WifiApDialog extends AlertDialog implements View.OnClickListener,
validate();
}
+ public void onRestoreInstanceState(Bundle savedInstanceState) {
+ super.onRestoreInstanceState(savedInstanceState);
+ mPassword.setInputType(
+ InputType.TYPE_CLASS_TEXT |
+ (((CheckBox) mView.findViewById(R.id.show_password)).isChecked() ?
+ InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD :
+ InputType.TYPE_TEXT_VARIATION_PASSWORD));
+ }
+
私人无效验证() {
- if ((mSsid != null && mSsid.length() == 0) ||
- ((mSecurityTypeIndex == WPA2_INDEX)&&
- mPassword.length() < 8)) {
+ String mSsidString = mSsid.getText()。 toString();
+ if ((mSsid != null && mSsid.length() == 0)
+ || ((mSecurityTypeIndex == WPA2_INDEX) && mPassword.length() < 8)
+ || (mSsid != null &&
+ Charset.forName ("UTF-8").encode(mSsidString).limit() > 32)) {
getButton(BUTTON_SUBMIT).setEnabled(false);
} else {
getButton(BUTTON_SUBMIT).setEnabled(true);
2.4G 和设置 5G 后,你应该在界面上打上这个按钮的那个按钮“在界面上看到 2.4G 和设置的 5 个选项列表”,没有选择按钮,但是无论是 4G 还是该按钮。 5G,放出我的首选都只有2.4G的。我们就来解决如何把5G AP的功能加入到5G的寻找按钮上:
2.1、一开始头绪,我们就从7.1的源头开始思路,先把7.1的源码理顺了,再去修改5.1的代码。
我们从7.1的frameworks/opt/net/wifi/service/java/com/android/server/wifi/util/ApConfigUtil.java文件出发,看看它是如何设置 2.4G 和 5G 的选择:
public static int updateApChannelConfig(WifiNative wifiNative,
String countryCode,
ArrayList allowed2GChannels,
WifiConfiguration config) {
/* 对没有 HAL 的设备使用默认频段和频道。*/
if (!wifiNative.isHalStarted()) {
//由 louhn 添加
if (WifiConfiguration.AP_BAND_2GHZ == config.apBand)
config.apChannel = DEFAULT_AP_CHANNEL;
否则,如果(WifiConfiguration.AP_BAND_5GHZ == config.apBand)
config.apChannel = DEFAULT_AP_CHANNEL_5GHz;
否则 {
config.apBand = DEFAULT_AP_BAND;
config.apChannel = DEFAULT_AP_CHANNEL;
}
//添加结束
返回成功;
}
在updateApChannelConfig方法里面是根据config.apBand这个值来设置判断现在选择2.4G还是5G,而这个config是从哪里传来的呢?继续调查updateApChannelConfig是从哪里调用的。
2.2、搜索发现, frameworks/opt/net/wifi/service/java/com/android/server/wifi/SoftApManager.java目录下有调用updateApChannelConfig方法,直接进去看看具体情况:
private int startSoftAp(WifiConfiguration config) {
if (config == null) {
Log.e(TAG, "Unable to start soft AP without configuration");
返回 ERROR_GENERIC;
}
/* 复制配置以更新 AP 频段和频道。*/
WifiConfiguration localConfig = new WifiConfiguration(config);
int result = ApConfigUtil.updateApChannelConfig(
mWifiNative, mCountryCode, mAllowed2GChannels, localConfig);
if (result != SUCCESS) {
Log.e(TAG, "Failed to update AP band and channel");
返回结果;
}
/* 设置国家代码(如果提供)。*/
if (mCountryCode != null) {
/**
* 5GHz 频段必须填写国家代码,如果设置失败会返回错误
* 当AP 配置为5GHz 频段时,国家代码。
*
这个方法(WifiConfiguration config)里面,调用updateApChannelConfig,而要调用一个config的startSoftAp配置方法,本地配置是本地WifiConfiguration localConfig = WifiConfiguration);我们再去寻找startSoftAp是在的被调用的:
2.3、还是在frameworks/opt/net/wifi/service/java/com/android/server/wifi/SoftApManager.java目录下有被调用的SoftAp的方法:
private class IdleState extends State {
@Override
public boolean processMessage(Message message) {
switch (message.what) {
case CMD_START:
updateApState(WifiManager.WIFI_AP_STATE_ENABLING, 0);
int 结果 = startSoftAp((WifiConfiguration) message.obj);
if (result == SUCCESS) {
updateApState(WifiManager.WIFI_AP_STATE_ENABLED, 0);
过渡到(mStartedState);
} 其他 {
int 原因 = WifiManager.SAP_START_FAILURE_GENERAL;
如果(结果 == ERROR_NO_CHANNEL){
原因 = WifiManager.SAP_START_FAILURE_NO_CHANNEL;
}
updateApState(WifiManager.WIFI_AP_STATE_FAILED,原因);
}
打破;
默认值:
/* 忽略所有其他命令。*/
休息;
}
returnANDLED;
而试调用的H是message。着去估计一下AP:应该是我们在目录开始打开的阶段,在下搜索CMD_START哪里是被定义的:
private {classApStateMachine extends StateMachine
Commands for the state machine. */
public static final int CMD_START = 0;
公共静态最终 int CMD_STOP = 1;
私有最终状态 mIdleState = new IdleState();
私有最终状态 mStartedState = new StartedState();
SoftApStateMachine(Looper looper) {
super(TAG, looper);
addState(mIdleState);
addState(mStartedState, mIdleState);
setInitialState(mIdleState);
开始();
}
SoftApStateMachine 类里面有对 CMD_START 的定义,那顺理成章的我们再搜索 SoftApStateMachine.CMD_START 是在被使用到的:
/**
* 用给定的配置启动软 AP。
* @param config AP 配置
*/
public void start(WifiConfiguration config) {
mStateMachine.sendMessage(SoftApStateMachine.CMD_START, config);
}
还是在当前目录,升级启动方法,有发送SoftApStateMachine.CMD_START,继续搜索SoftApManager.start
2.4、在frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiStateMachine.java目录下,有调用mSoftApManager.start,我们进入源码查看:
@Override
public void enter() {
final Message message = getCurrentMessage();
if (message.what == CMD_START_AP) {
WifiConfiguration config = (WifiConfiguration) message.obj;
if (config == null) {
/**
* 命令中未提供配置,回退到使用当前
* 配置。
*/
config = mWifiApConfigStore.getApConfiguration();
} else {
/* 更新 AP 配置。*/
mWifiApConfigStore.setApConfiguration(config);
}
checkAndSetConnectivityInstance();
mSoftApManager = mFacade.makeSoftApManager(
mContext, getHandler().getLooper(), mWifiNative, mNwService,
mCm, mCountryCode.getCountryCode(),
mWifiApConfigStore.getAllowed2GChannel(),
new SoftApListener());
mSoftApManager.start(config);
} else {
throw new RuntimeException("非法转换到 SoftApState:" + message);
}
}
mSoftApManager config是在Message接收到CMD_STARTAP的,而config是Wifi config = (WifiConfiguration) message.objstart的配置,执行后也执行到这个待会儿目录下查看5.1代码时候进到这个目录下查看5.1在这个地方具体做了什么,我们再来看下config是怎么定义的,config的类是WifiConfiguration,我们直接搜索WifiConfiguration.java:
2.5:frameworks/base/wifi/java/android/net/wifi/WifiConfiguration。 java:WifiConfiguration这个类里面定义了ssid,bssid,psk,scan_ssid等等,而在我们的5G选择按钮AP_BAND_5GHZ也是在这里添加的,因为5.1压根就没有2.4G和5G的选择按钮,所以在5.1的WifiConfiguration.java目录下,也一定要添加对2.4G和5G的选择。
因此我们回到5.1,在5.1上的WifiConfiguration.java文件里面添加2.4G和5G的选择开关:
diff --git a/wifi/java/android/net/wifi/WifiConfiguration.java b/wifi/java/android/net/wifi/WifiConfiguration.java
index 87db951..c9963b9 100644
--- a/wifi/java/android/net/wifi/WifiConfiguration.java
+++ b/wifi/java/android/net/wifi/WifiConfiguration.java
@@ -237,6 +237,36 @@公共类WifiConfiguration 实现 Parcelable {
* AAA 服务器或 RADIUS 服务器的完全限定域名 (FQDN)
* 例如 {@code "mail.example.com"}。
*/
+
+ /**
+ * 2GHz 频段。
+ * @隐藏
+ */
+ public static final int AP_BAND_2GHZ = 0;
+
+ /**
+ * 5GHz 频段。
+ * @hide
+ */
+ public static final int AP_BAND_5GHZ = 1;
+
+ /**
+ * AP所在的频段
+ * 0-2G 1-5G
+ * 默认选择2G
+ * @hide
+ */
+ public int apBand = AP_BAND_2GHZ;
+
+ /**
+ * AP所在的频道,目前仅限美国
+ * 2G 1-11
+ * 5G 36,40,44,48,149,153,157,161,165
+ * 0 - 根据apBand随机找一个可用频道
+ * @hide
+ */
+ public int apChannel = 0;
+
公共字符串 FQDN;
/**
* 网络访问标识符 (NAI) 领域,用于 Passpoint 凭证。
@@ -1500,7 +1530,10 @@ public class WifiConfiguration 实现 Parcelable {
FQDN = source.FQDN;
naiRealm = source.naiRealm;
preSharedKey = source.preSharedKey;
-
+ //由 louhn 添加
+ apBand = source.apBand;
+ apChannel = source.apChannel;
+ //添加结束
wepKeys = new String[4];
for (int i = 0; i < wepKeys.length; i++) {
wepKeys = source.wepKeys ;
@@ -1593,7 +1626,11 @@ public class WifiConfiguration 实现 Parcelable {
dest.writeInt(disableReason);
dest.writeString(SSID);
dest.writeString(BSSID);
- dest.writeString(autoJoinBSSID);
+ //由 louhn 添加
+ dest.writeInt(apBand);
+ dest.writeInt(apChannel);
+ //结束
+ dest.writeString(autoJoinBSSID);
dest.writeString(FQDN);
dest.writeString(naiRealm);
dest.writeString(preSharedKey);
@@ -1658,7 +1695,11 @@ public class WifiConfiguration 实现 Parcelable {
config.disableReason = in.readInt();
config.SSID = in.readString();
config.BSSID = in.readString();
- config.autoJoinBSSID = in.readString();
+ //由 louhn 添加
+ config.apBand = in.readInt();
+ config.apChannel = in.readInt();
+ //添加结束
+ config.autoJoinBSSID = in.readString();
config.FQDN = in.readString();
config.naiRealm = in.readString();
config.preSharedKey = in.readString();
再回到5.1的frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiStateMachine.java,查看5.1在SoftApState处具体做了什么:
class SoftApStartingState 扩展状态 { @Override
public
void enter() {
final Message message = getCurrentMessage();
if (message.what == CMD_START_AP) {
final WifiConfiguration config = (WifiConfiguration) message.obj;
if (config == null) {
mWifiApConfigChannel.sendMessage(CMD_REQUEST_AP_CONFIG);
} else {
mWifiApConfigChannel.sendMessage(CMD_SET_AP_CONFIG, config);
startSoftApWithConfig(config);
}
} else {
throw new RuntimeException("非法转换到 SoftApStartingState:" + message);
}
}
@Override
public boolean processMessage(Message message) {
logStateAndMessage(message, getClass().getSimpleName());
switch(message.what) {
case CMD_START_SUPPLICANT:
case CMD_STOP_SUPPLICANT:
case CMD_START_AP:
case CMD_STOP_AP:
case CMD_START_DRIVER:
case CMD_STOP_DRIVER:
case CMD_SET_OPERATIONAL_MODE:
case CMD_SET_COUNTRY_CODE:
case CMD_SET_FREQUENCY_BAND:
case CMD_START_PACKET_FILTERING:
case CMD_STOP_PACKET_FILTERING:
case CMD_TETHER_STATE_CHANGE:
deferMessage(message);
休息;
case WifiStateMachine.CMD_RESPONSE_AP_CONFIG:
WifiConfiguration config = (WifiConfiguration) message.obj;
if (config != null) {
startSoftApWithConfig(config);
} else {
loge("Softap 配置为空!");
发送消息(CMD_START_AP_FAILURE);
}
打破;
案例 CMD_START_AP_SUCCESS:
setWifiApState(WIFI_AP_STATE_ENABLED);
过渡到(mSoftApStartedState);
休息;
案例 CMD_START_AP_FAILURE:
setWifiApState(WIFI_AP_STATE_FAILED);
过渡到(初始状态);
休息;
默认值:
返回 NOT_HANDLED;
}
返回处理;
}
}
则android5.1源码里面不叫SoftApState而是叫SoftApStartingState,这里定义if(config == null),elsestartSoftApWithConfig(config),执行到startSoftApWithConfig,查看该方法具体做了什么:
还是在本目录下:
private void startSoftApWithConfig(final WifiConfiguration config) {
// 在单独的线程上启动 hostapd
new Thread(new Runnable() {
public void run() {
try {
mNwService.startAccessPoint(config, mInterfaceName);
} catch (Exception e) {
loge ("softap start 异常" + e);
try {
mNwService.stopAccessPoint(mInterfaceName);
mNwService.startAccessPoint(config, mInterfaceName);
} catch (Exception e1) {
loge("softap re-start 异常" + e1);
发送消息(CMD_START_AP_FAILURE);
返回;
}
}
if (DBG) log("软AP启动成功");
发送消息(CMD_START_AP_SUCCESS);
if(!mSoftApWakeLock.isHeld()) {
loge("---- mSoftApWakeLock.acquire ----");
mSoftApWakeLock.acquire();
}
}
}).start();
该方法返回执行mNwService.startAccessPoint
(config, mInterfaceName);我们继续再搜索mNwService.startAccessPoint
在frameworks/base/services/core/java/com/android/server/NetworkManagementService.java中做了什么,有对startAccessPoint的定义,进入目录,继续查看。 终于,我们在startAccessPoint里找到了我们想看到的内容:
mConnector.execute("softap", "set", wlanIface, wifiConfig.SSID,
"broadcast", "6", ArconfigType
(wifiSecurityConfig.preSensitive Key));
的SSID,等,这里我们可以看到设置只有一个"6",只需要一个"6",只需要一个wifi设置了 2.4G 的打开,那么我们可以在这里做一个选择,根据 2.4G 和 5G 的选择开关,选择到底是 2.4G 还是 5G:
diff --git a/services/core/java/com/android /server/NetworkManagementService.java b/services/core/java/com/android/server/NetworkManagementService.java
索引 18bf838..857fff4 100644
--- a/services/core/java/com/android/server/NetworkManagementService.java
+ ++ b/services/core/java/com/android/server/NetworkManagementService.java
@@ -1365,10 +1365,29 @@ public class NetworkManagementService extends
INetworkManagementService.Stub if (wifiConfig == null) {
mConnector.execute("softap", "set", wlanIface);
} else {
- mConnector.execute("softap", "set", wlanIface, wifiConfig.SSID,
+ //由 louhn 添加
+ if(wifiConfig.apBand == 0)//AP_BAND_2GHZ
+ {
+ mConnector.execute("softap ", "设置", wlanIface, wifiConfig.SSID,
+ "广播", "6", getSecurityType(wifiConfig),
+ new SensitiveArg(wifiConfig.preSharedKey));
+ Log.e("LOUHN", "wifiConfig.apBand: AP_BAND_2GHZ");
+ }
+ else if(wifiConfig.apBand == 1)//AP_BAND_5GHZ
+ {
+ mConnector.execute("softap", "set", wlanIface, wifiConfig.SSID,
+ "broadcast", "153", getSecurityType(wifiConfig) ,
+ 新的 SensitiveArg(wifiConfig.preSharedKey));
+ Log.e("LOUHN", "wifiConfig.apBand: AP_BAND_5GHZ");
+ else
+ {
+ mConnector.execute("softap", "set", wlanIface, wifiConfig.SSID,
"broadcast", "6", getSecurityType(wifiConfig),
new SensitiveArg(wifiConfig.preSharedKey));
- }
+ Log.e("LOUHN", "不知道 wifiConfig.apBand");
+ }
+ }
mConnector.execute("softap", "startap");
} catch (NativeDaemonConnectorException e) {
throw e.rethrowAsParcelableException();
< >
最近在 rk328/7 上 rk3283 android15.1 和 7.1 上调试了 android166 芯片(该芯片支持 5G 内部),但是我打开 AP 生成 2.4G 的 9 个 5G 时的 AP。在“WLAN”有一个“才选择AP”的选项是android5.1,也是后来我没有解决这个问题的时候,我已经解决了这个问题),但该车只有一个2.4GHz的选项。我在这个G网的文章//0303032里有怎么写死的文章//
03032里有怎么写死的AP,打开5G的标题,然后打开5G不过在里面有“2.4G选项也有5G设置”的选项,那一定是5G的,5G应该被系统选项隐藏了,调查,来打开5G 1.在sapps
/apps/目录设置/packageSettings/下关键字“2.4GHz 选项/设置目录”
值设置/插件设置/插件设置/插件/apps.xml: 插件设置-zh-rCN/strings.xml
继续搜索“2.4 GHz 2.4GHz 包到”包地址。
目录字符串名称 到达ap_choose_2G,目录下:
packages/apps//res/values/arrayxml:
- @string/wifi_ap_choose_2G
3.进入array.xml查看该xml
- @string/wifi_ap_choose_2G
- @string/wifi_ap_choose_5G
- @string/wifi_ap_choose_2G item>
看到果然是有5G选项的字符串:wifi_ap_choose_5G
4.提取目录wifi_ap_band_config_full字符,packages/apps/Settings下继续搜索:
packages/apps/Settings/src/com/android/设置/wifi/WifiApDialog.java:R.array.wifi_ap_band_config_full,android.R.layout.simple_spinner_item);
5.进到WifiApDialog.java下,查看:
if (!mWifiManager.isDualBandSupported() || countryCode == null) {
//如果没有国家代码,则禁止使用 5GHz AP
Log.i(TAG,(!mWifiManager.isDualBandSupported() ? "Device do not support 5GHz " :" ")
+ (countryCode == null ?" NO country code" :"") + "forbid 5GHz");
channelAdapter = ArrayAdapter.createFromResource(mContext,
R.array.wifi_ap_band_config_2G_only, android.R.layout.simple_spinner_item);
mWifiConfig.apBand = 0;
} else {
channelAdapter = ArrayAdapter.createFromResource(mContext,
R.array.wifi_ap_band_config_full, android.R.layout.simple_spinner_item);
}
这里很明显了,有一个if判断:if (!mWifiManager. isDualBandSupported() || 国家代码 == 空)
也是mWifiManager.isDualBandSupported() !=null 并且countryCode != null,进入wifi_ap_band_config_full模式,
countryCode字面就是允许自己的国家代码,在我们中国国内5G信道只允许使用149个以上的信道,因此没有国家是不能使用的国家代码使用5G热点的。
国家代码先放一边,先来查询isDualBandSupported的作用:
6.在frameworks/opt/net/service/java/com/android/server/wifi/wifiServiceImpl.java目录下有对isDualBandSupported的方法的定义:
public boolean isDualBandSupported() {
//TODO: 应该转向添加一个在运行时检查的驱动 API
return mContext.getResources().getBoolean(
com.android.internal.R.bool.config_wifi_dual_band_support);
}
从代码中可以理解到,isDualBandSupported 方法返回值是个布尔类型值,它返回的是config_wifi_dual_band_support所的值,因此我们只要还是去确认config_wifi_dual_band_support 是true false就可以了,不过现在看来该值应该是被该设置成false,下面我们继续去查找值真正被设置成什么:
7.在frameworks/base/core/res/res/values/config.xml目录下,有对config_wifi_dual_band_support值的设置,该值当然是被设置成false,现在把它变成true。
- 3
+
+
+
+ - @string/wifi_ap_choose_2G
+ - @string /wifi_ap_choose_5G
+
+
+ - @string/wifi_ap_choose_2G
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
索引 068df77..9cbbf33 100755
--- a/res/values/strings.xml
++ + b/res/values/strings.xml
@@ -1590,
显示密码
-
- IP 设置
+
+
+ "Seleccionar banda de AP"< /string>
+ "2.4 GHz Band"
+ "5 GHz Band"
+ IP settings
<字符串>(不变)字符串>
diff --git a/src/com/android/settings/wifi/WifiApDialog.java b/src/com/android/settings/wifi/WifiApDialog.java
index fb8026a..6ec1f6c 100644
--- a/src/com/android /settings/wifi/WifiApDialog.java
+++ b/src/com/android/settings/wifi/WifiApDialog.java
@@ -22,12 +22,15 @@ import android.content.DialogInterface;
导入android.net.wifi.WifiConfiguration;
导入android.net.wifi.WifiConfiguration.AuthAlgorithm;
导入android.net.wifi.WifiConfiguration.KeyMgmt;
+导入android.net.wifi.WifiManager;
导入android.os.Bundle;
导入 android.text.Editable;
导入 android.text.InputType;
导入 android.text.TextWatcher;
+导入android.util.Log;
导入android.view.View;
导入 android.widget.AdapterView;
+导入android.widget.ArrayAdapter;
导入 android.widget.CheckBox;
导入 android.widget.EditText;
导入 android.widget.Spinner;
@@ -35,6 +38,8 @@ import android.widget.TextView;
导入 com.android.settings.R;
+导入java.nio.charset.Charset;
+
/**
* 配置 SSID 和安全设置的对话框
* 用于接入点操作
@@ -53,8 +58,13 @@ public class WifiApDialog extends AlertDialog implements View.OnClickListener,
private TextView mSsid;
私有 int mSecurityTypeIndex = OPEN_INDEX;
私人 EditText mPassword;
+ 私有 int mBandIndex = OPEN_INDEX;
WifiConfiguration mWifiConfig;
+ WifiManager mWifiManager;
+ 私有上下文 mContext;
++
私有静态最终字符串标签=“WifiApDialog”;
public WifiApDialog(Context context, DialogInterface.OnClickListener listener,
WifiConfiguration wifiConfig) {
@@ -64,6 +74,8 @@ public class WifiApDialog extends AlertDialog implements View.OnClickListener,
if (wifiConfig != null) {
mSecurityTypeIndex = getSecurityTypeIndex(wifiConfig );
}
+ mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
+ mContext = 上下文;
}
public static int getSecurityTypeIndex(WifiConfiguration wifiConfig) {
@@ -85,6 +97,8 @@ public class WifiApDialog extends AlertDialog implements View.OnClickListener,
*/
config.SSID = mSsid.getText().toString();
+ config.apBand = mBandIndex;
+
switch (mSecurityTypeIndex) {
case OPEN_INDEX:
config.allowedKeyManagement.set(KeyMgmt.NONE);
@@ -104,9 +118,10 @@ public class WifiApDialog extends AlertDialog implements View.OnClickListener, @Override
protected
void onCreate(Bundle savedInstanceState) {
-
+ boolean mInit = true;
mView = getLayoutInflater().inflate(R.layout.wifi_ap_dialog, null);
微调器 mSecurity = ((Spinner) mView.findViewById(R.id.security));
+ 最终 Spinner mChannel = (Spinner) mView.findViewById(R.id.choose_channel);
设置视图(mView);
setInverseBackgroundForced(true);
@@ -118,18 +133,68 @@ public class WifiApDialog extends AlertDialog implements View.OnClickListener,
mSsid = (TextView) mView.findViewById(R.id.ssid);
mPassword = (EditText) mView.findViewById(R.id.password);
+ ArrayAdapter 通道适配器;
+ //String countryCode = mWifiManager.getCountryCode();
+ 字符串国家代码 = "CN"; //louhn:这里写死为CN
+
+ if (countryCode == null) {
+ //如果没有国家代码,5GHz AP被禁止
+ Log.i(TAG,(!mWifiManager.isDualBandSupported() ? "Device do not support 5GHz " :"")
+ + (countryCode == null ? " NO country code" :"") + " forbid 5GHz");
+ channelAdapter = ArrayAdapter.createFromResource(mContext,
+ R.array.wifi_ap_band_config_2G_only, android.R.layout.simple_spinner_item);
+ mWifiConfig.apBand = 0;
+ } else {
+ channelAdapter = ArrayAdapter.createFromResource(mContext,
+ R.array.wifi_ap_band_config_full, android.R.layout.simple_spinner_item);
+
+ channelAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+
setButton(BUTTON_SUBMIT, context.getString(R.string.wifi_save), mListener);
setButton(DialogInterface.BUTTON_NEGATIVE,
context.getString(R.string.wifi_cancel), mListener);
if (mWifiConfig != null) {
mSsid.setText(mWifiConfig.SSID);
+ if (mWifiConfig.apBand == 0) {
+ mBandIndex = 0;
+ } 其他 {
+ mBandIndex = 1;
+ }
+
mSecurity.setSelection(mSecurityTypeIndex);
如果(mSecurityTypeIndex == WPA2_INDEX){
- mPassword.setText(mWifiConfig.preSharedKey);
+ mPassword.setText(mWifiConfig.preSharedKey);
}
}
+ mChannel.setAdapter(channelAdapter);
+ mChannel.setOnItemSelectedListener(
+ new AdapterView.OnItemSelectedListener() {
+ boolean mInit = true;
+
@Override + public void onItemSelected(AdapterView> adapterView, View view, int position,
+ long id) {
+ if (!mInit) {
+ mBandIndex = 位置;
+ mWifiConfig.apBand = mBandIndex;
+ Log.i(TAG, "config on channelIndex : " + mBandIndex + " Band: " +
+ mWifiConfig.apBand);
+ } 其他 {
+ mInit = false;
+ mChannel.setSelection(mBandIndex);
+ }
+
+ }
+
+
@Override + public void onNothingSelected(AdapterView> adapterView) {
+
+ }
+ }
+ );
+
mSsid.addTextChangedListener(this);
mPassword.addTextChangedListener(this);
((CheckBox) mView.findViewById(R.id.show_password)).setOnClickListener(this);
@@ -141,10 +206,21 @@ public class WifiApDialog extends AlertDialog implements View.OnClickListener,
validate();
}
+ public void onRestoreInstanceState(Bundle savedInstanceState) {
+ super.onRestoreInstanceState(savedInstanceState);
+ mPassword.setInputType(
+ InputType.TYPE_CLASS_TEXT |
+ (((CheckBox) mView.findViewById(R.id.show_password)).isChecked() ?
+ InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD :
+ InputType.TYPE_TEXT_VARIATION_PASSWORD));
+ }
+
私人无效验证() {
- if ((mSsid != null && mSsid.length() == 0) ||
- ((mSecurityTypeIndex == WPA2_INDEX)&&
- mPassword.length() < 8)) {
+ String mSsidString = mSsid.getText()。 toString();
+ if ((mSsid != null && mSsid.length() == 0)
+ || ((mSecurityTypeIndex == WPA2_INDEX) && mPassword.length() < 8)
+ || (mSsid != null &&
+ Charset.forName ("UTF-8").encode(mSsidString).limit() > 32)) {
getButton(BUTTON_SUBMIT).setEnabled(false);
} else {
getButton(BUTTON_SUBMIT).setEnabled(true);
2.4G 和设置 5G 后,你应该在界面上打上这个按钮的那个按钮“在界面上看到 2.4G 和设置的 5 个选项列表”,没有选择按钮,但是无论是 4G 还是该按钮。 5G,放出我的首选都只有2.4G的。我们就来解决如何把5G AP的功能加入到5G的寻找按钮上:
2.1、一开始头绪,我们就从7.1的源头开始思路,先把7.1的源码理顺了,再去修改5.1的代码。
我们从7.1的frameworks/opt/net/wifi/service/java/com/android/server/wifi/util/ApConfigUtil.java文件出发,看看它是如何设置 2.4G 和 5G 的选择:
public static int updateApChannelConfig(WifiNative wifiNative,
String countryCode,
ArrayList allowed2GChannels,
WifiConfiguration config) {
/* 对没有 HAL 的设备使用默认频段和频道。*/
if (!wifiNative.isHalStarted()) {
//由 louhn 添加
if (WifiConfiguration.AP_BAND_2GHZ == config.apBand)
config.apChannel = DEFAULT_AP_CHANNEL;
否则,如果(WifiConfiguration.AP_BAND_5GHZ == config.apBand)
config.apChannel = DEFAULT_AP_CHANNEL_5GHz;
否则 {
config.apBand = DEFAULT_AP_BAND;
config.apChannel = DEFAULT_AP_CHANNEL;
}
//添加结束
返回成功;
}
在updateApChannelConfig方法里面是根据config.apBand这个值来设置判断现在选择2.4G还是5G,而这个config是从哪里传来的呢?继续调查updateApChannelConfig是从哪里调用的。
2.2、搜索发现, frameworks/opt/net/wifi/service/java/com/android/server/wifi/SoftApManager.java目录下有调用updateApChannelConfig方法,直接进去看看具体情况:
private int startSoftAp(WifiConfiguration config) {
if (config == null) {
Log.e(TAG, "Unable to start soft AP without configuration");
返回 ERROR_GENERIC;
}
/* 复制配置以更新 AP 频段和频道。*/
WifiConfiguration localConfig = new WifiConfiguration(config);
int result = ApConfigUtil.updateApChannelConfig(
mWifiNative, mCountryCode, mAllowed2GChannels, localConfig);
if (result != SUCCESS) {
Log.e(TAG, "Failed to update AP band and channel");
返回结果;
}
/* 设置国家代码(如果提供)。*/
if (mCountryCode != null) {
/**
* 5GHz 频段必须填写国家代码,如果设置失败会返回错误
* 当AP 配置为5GHz 频段时,国家代码。
*
这个方法(WifiConfiguration config)里面,调用updateApChannelConfig,而要调用一个config的startSoftAp配置方法,本地配置是本地WifiConfiguration localConfig = WifiConfiguration);我们再去寻找startSoftAp是在的被调用的:
2.3、还是在frameworks/opt/net/wifi/service/java/com/android/server/wifi/SoftApManager.java目录下有被调用的SoftAp的方法:
private class IdleState extends State {
@Override
public boolean processMessage(Message message) {
switch (message.what) {
case CMD_START:
updateApState(WifiManager.WIFI_AP_STATE_ENABLING, 0);
int 结果 = startSoftAp((WifiConfiguration) message.obj);
if (result == SUCCESS) {
updateApState(WifiManager.WIFI_AP_STATE_ENABLED, 0);
过渡到(mStartedState);
} 其他 {
int 原因 = WifiManager.SAP_START_FAILURE_GENERAL;
如果(结果 == ERROR_NO_CHANNEL){
原因 = WifiManager.SAP_START_FAILURE_NO_CHANNEL;
}
updateApState(WifiManager.WIFI_AP_STATE_FAILED,原因);
}
打破;
默认值:
/* 忽略所有其他命令。*/
休息;
}
returnANDLED;
而试调用的H是message。着去估计一下AP:应该是我们在目录开始打开的阶段,在下搜索CMD_START哪里是被定义的:
private {classApStateMachine extends StateMachine
Commands for the state machine. */
public static final int CMD_START = 0;
公共静态最终 int CMD_STOP = 1;
私有最终状态 mIdleState = new IdleState();
私有最终状态 mStartedState = new StartedState();
SoftApStateMachine(Looper looper) {
super(TAG, looper);
addState(mIdleState);
addState(mStartedState, mIdleState);
setInitialState(mIdleState);
开始();
}
SoftApStateMachine 类里面有对 CMD_START 的定义,那顺理成章的我们再搜索 SoftApStateMachine.CMD_START 是在被使用到的:
/**
* 用给定的配置启动软 AP。
* @param config AP 配置
*/
public void start(WifiConfiguration config) {
mStateMachine.sendMessage(SoftApStateMachine.CMD_START, config);
}
还是在当前目录,升级启动方法,有发送SoftApStateMachine.CMD_START,继续搜索SoftApManager.start
2.4、在frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiStateMachine.java目录下,有调用mSoftApManager.start,我们进入源码查看:
@Override
public void enter() {
final Message message = getCurrentMessage();
if (message.what == CMD_START_AP) {
WifiConfiguration config = (WifiConfiguration) message.obj;
if (config == null) {
/**
* 命令中未提供配置,回退到使用当前
* 配置。
*/
config = mWifiApConfigStore.getApConfiguration();
} else {
/* 更新 AP 配置。*/
mWifiApConfigStore.setApConfiguration(config);
}
checkAndSetConnectivityInstance();
mSoftApManager = mFacade.makeSoftApManager(
mContext, getHandler().getLooper(), mWifiNative, mNwService,
mCm, mCountryCode.getCountryCode(),
mWifiApConfigStore.getAllowed2GChannel(),
new SoftApListener());
mSoftApManager.start(config);
} else {
throw new RuntimeException("非法转换到 SoftApState:" + message);
}
}
mSoftApManager config是在Message接收到CMD_STARTAP的,而config是Wifi config = (WifiConfiguration) message.objstart的配置,执行后也执行到这个待会儿目录下查看5.1代码时候进到这个目录下查看5.1在这个地方具体做了什么,我们再来看下config是怎么定义的,config的类是WifiConfiguration,我们直接搜索WifiConfiguration.java:
2.5:frameworks/base/wifi/java/android/net/wifi/WifiConfiguration。 java:WifiConfiguration这个类里面定义了ssid,bssid,psk,scan_ssid等等,而在我们的5G选择按钮AP_BAND_5GHZ也是在这里添加的,因为5.1压根就没有2.4G和5G的选择按钮,所以在5.1的WifiConfiguration.java目录下,也一定要添加对2.4G和5G的选择。
因此我们回到5.1,在5.1上的WifiConfiguration.java文件里面添加2.4G和5G的选择开关:
diff --git a/wifi/java/android/net/wifi/WifiConfiguration.java b/wifi/java/android/net/wifi/WifiConfiguration.java
index 87db951..c9963b9 100644
--- a/wifi/java/android/net/wifi/WifiConfiguration.java
+++ b/wifi/java/android/net/wifi/WifiConfiguration.java
@@ -237,6 +237,36 @@公共类WifiConfiguration 实现 Parcelable {
* AAA 服务器或 RADIUS 服务器的完全限定域名 (FQDN)
* 例如 {@code "mail.example.com"}。
*/
+
+ /**
+ * 2GHz 频段。
+ * @隐藏
+ */
+ public static final int AP_BAND_2GHZ = 0;
+
+ /**
+ * 5GHz 频段。
+ * @hide
+ */
+ public static final int AP_BAND_5GHZ = 1;
+
+ /**
+ * AP所在的频段
+ * 0-2G 1-5G
+ * 默认选择2G
+ * @hide
+ */
+ public int apBand = AP_BAND_2GHZ;
+
+ /**
+ * AP所在的频道,目前仅限美国
+ * 2G 1-11
+ * 5G 36,40,44,48,149,153,157,161,165
+ * 0 - 根据apBand随机找一个可用频道
+ * @hide
+ */
+ public int apChannel = 0;
+
公共字符串 FQDN;
/**
* 网络访问标识符 (NAI) 领域,用于 Passpoint 凭证。
@@ -1500,7 +1530,10 @@ public class WifiConfiguration 实现 Parcelable {
FQDN = source.FQDN;
naiRealm = source.naiRealm;
preSharedKey = source.preSharedKey;
-
+ //由 louhn 添加
+ apBand = source.apBand;
+ apChannel = source.apChannel;
+ //添加结束
wepKeys = new String[4];
for (int i = 0; i < wepKeys.length; i++) {
wepKeys = source.wepKeys ;
@@ -1593,7 +1626,11 @@ public class WifiConfiguration 实现 Parcelable {
dest.writeInt(disableReason);
dest.writeString(SSID);
dest.writeString(BSSID);
- dest.writeString(autoJoinBSSID);
+ //由 louhn 添加
+ dest.writeInt(apBand);
+ dest.writeInt(apChannel);
+ //结束
+ dest.writeString(autoJoinBSSID);
dest.writeString(FQDN);
dest.writeString(naiRealm);
dest.writeString(preSharedKey);
@@ -1658,7 +1695,11 @@ public class WifiConfiguration 实现 Parcelable {
config.disableReason = in.readInt();
config.SSID = in.readString();
config.BSSID = in.readString();
- config.autoJoinBSSID = in.readString();
+ //由 louhn 添加
+ config.apBand = in.readInt();
+ config.apChannel = in.readInt();
+ //添加结束
+ config.autoJoinBSSID = in.readString();
config.FQDN = in.readString();
config.naiRealm = in.readString();
config.preSharedKey = in.readString();
再回到5.1的frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiStateMachine.java,查看5.1在SoftApState处具体做了什么:
class SoftApStartingState 扩展状态 { @Override
public
void enter() {
final Message message = getCurrentMessage();
if (message.what == CMD_START_AP) {
final WifiConfiguration config = (WifiConfiguration) message.obj;
if (config == null) {
mWifiApConfigChannel.sendMessage(CMD_REQUEST_AP_CONFIG);
} else {
mWifiApConfigChannel.sendMessage(CMD_SET_AP_CONFIG, config);
startSoftApWithConfig(config);
}
} else {
throw new RuntimeException("非法转换到 SoftApStartingState:" + message);
}
}
@Override
public boolean processMessage(Message message) {
logStateAndMessage(message, getClass().getSimpleName());
switch(message.what) {
case CMD_START_SUPPLICANT:
case CMD_STOP_SUPPLICANT:
case CMD_START_AP:
case CMD_STOP_AP:
case CMD_START_DRIVER:
case CMD_STOP_DRIVER:
case CMD_SET_OPERATIONAL_MODE:
case CMD_SET_COUNTRY_CODE:
case CMD_SET_FREQUENCY_BAND:
case CMD_START_PACKET_FILTERING:
case CMD_STOP_PACKET_FILTERING:
case CMD_TETHER_STATE_CHANGE:
deferMessage(message);
休息;
case WifiStateMachine.CMD_RESPONSE_AP_CONFIG:
WifiConfiguration config = (WifiConfiguration) message.obj;
if (config != null) {
startSoftApWithConfig(config);
} else {
loge("Softap 配置为空!");
发送消息(CMD_START_AP_FAILURE);
}
打破;
案例 CMD_START_AP_SUCCESS:
setWifiApState(WIFI_AP_STATE_ENABLED);
过渡到(mSoftApStartedState);
休息;
案例 CMD_START_AP_FAILURE:
setWifiApState(WIFI_AP_STATE_FAILED);
过渡到(初始状态);
休息;
默认值:
返回 NOT_HANDLED;
}
返回处理;
}
}
则android5.1源码里面不叫SoftApState而是叫SoftApStartingState,这里定义if(config == null),elsestartSoftApWithConfig(config),执行到startSoftApWithConfig,查看该方法具体做了什么:
还是在本目录下:
private void startSoftApWithConfig(final WifiConfiguration config) {
// 在单独的线程上启动 hostapd
new Thread(new Runnable() {
public void run() {
try {
mNwService.startAccessPoint(config, mInterfaceName);
} catch (Exception e) {
loge ("softap start 异常" + e);
try {
mNwService.stopAccessPoint(mInterfaceName);
mNwService.startAccessPoint(config, mInterfaceName);
} catch (Exception e1) {
loge("softap re-start 异常" + e1);
发送消息(CMD_START_AP_FAILURE);
返回;
}
}
if (DBG) log("软AP启动成功");
发送消息(CMD_START_AP_SUCCESS);
if(!mSoftApWakeLock.isHeld()) {
loge("---- mSoftApWakeLock.acquire ----");
mSoftApWakeLock.acquire();
}
}
}).start();
该方法返回执行mNwService.startAccessPoint
(config, mInterfaceName);我们继续再搜索mNwService.startAccessPoint
在frameworks/base/services/core/java/com/android/server/NetworkManagementService.java中做了什么,有对startAccessPoint的定义,进入目录,继续查看。 终于,我们在startAccessPoint里找到了我们想看到的内容:
mConnector.execute("softap", "set", wlanIface, wifiConfig.SSID,
"broadcast", "6", ArconfigType
(wifiSecurityConfig.preSensitive Key));
的SSID,等,这里我们可以看到设置只有一个"6",只需要一个"6",只需要一个wifi设置了 2.4G 的打开,那么我们可以在这里做一个选择,根据 2.4G 和 5G 的选择开关,选择到底是 2.4G 还是 5G:
diff --git a/services/core/java/com/android /server/NetworkManagementService.java b/services/core/java/com/android/server/NetworkManagementService.java
索引 18bf838..857fff4 100644
--- a/services/core/java/com/android/server/NetworkManagementService.java
+ ++ b/services/core/java/com/android/server/NetworkManagementService.java
@@ -1365,10 +1365,29 @@ public class NetworkManagementService extends
INetworkManagementService.Stub if (wifiConfig == null) {
mConnector.execute("softap", "set", wlanIface);
} else {
- mConnector.execute("softap", "set", wlanIface, wifiConfig.SSID,
+ //由 louhn 添加
+ if(wifiConfig.apBand == 0)//AP_BAND_2GHZ
+ {
+ mConnector.execute("softap ", "设置", wlanIface, wifiConfig.SSID,
+ "广播", "6", getSecurityType(wifiConfig),
+ new SensitiveArg(wifiConfig.preSharedKey));
+ Log.e("LOUHN", "wifiConfig.apBand: AP_BAND_2GHZ");
+ }
+ else if(wifiConfig.apBand == 1)//AP_BAND_5GHZ
+ {
+ mConnector.execute("softap", "set", wlanIface, wifiConfig.SSID,
+ "broadcast", "153", getSecurityType(wifiConfig) ,
+ 新的 SensitiveArg(wifiConfig.preSharedKey));
+ Log.e("LOUHN", "wifiConfig.apBand: AP_BAND_5GHZ");
+ else
+ {
+ mConnector.execute("softap", "set", wlanIface, wifiConfig.SSID,
"broadcast", "6", getSecurityType(wifiConfig),
new SensitiveArg(wifiConfig.preSharedKey));
- }
+ Log.e("LOUHN", "不知道 wifiConfig.apBand");
+ }
+ }
mConnector.execute("softap", "startap");
} catch (NativeDaemonConnectorException e) {
throw e.rethrowAsParcelableException();
举报