From ee0a0132ebb0d7e9baf42e778ea9c094966ffb14 Mon Sep 17 00:00:00 2001 From: xinhe Date: Tue, 4 Aug 2015 14:27:27 -0700 Subject: WiFi tethering AP says I can't use 5g in this country while in the US b/22871989 Change-Id: I63c458c7353ecf84aa716118924364bb8f0f2844 --- service/java/com/android/server/wifi/WifiNative.java | 16 +++++++++++++++- .../java/com/android/server/wifi/WifiStateMachine.java | 15 +++++++++++---- service/jni/com_android_server_wifi_WifiNative.cpp | 10 ++++++++-- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java index 5afe4e512..899529ddd 100644 --- a/service/java/com/android/server/wifi/WifiNative.java +++ b/service/java/com/android/server/wifi/WifiNative.java @@ -1901,10 +1901,24 @@ public class WifiNative { synchronized public static int [] getChannelsForBand(int band) { synchronized (mLock) { - return getChannelsForBandNative(sWlan0Index, band); + if (isHalStarted()) { + return getChannelsForBandNative(sWlan0Index, band); + } else { + return null; + } } } + private static native boolean isGetChannelsForBandSupportedNative(); + synchronized public static boolean isGetChannelsForBandSupported(){ + synchronized (mLock) { + if (isHalStarted()) { + return isGetChannelsForBandSupportedNative(); + } else { + return false; + } + } + } private static native boolean setDfsFlagNative(int iface, boolean dfsOn); synchronized public static boolean setDfsFlag(boolean dfsOn) { diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index 8710a039b..60148be53 100644 --- a/service/java/com/android/server/wifi/WifiStateMachine.java +++ b/service/java/com/android/server/wifi/WifiStateMachine.java @@ -5204,14 +5204,21 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno if (config.apChannel == 0) { config.apChannel = chooseApChannel(config.apBand); if (config.apChannel == 0) { - //fail to get available channel - sendMessage(CMD_START_AP_FAILURE, WifiManager.SAP_START_FAILURE_NO_CHANNEL); - return; + if(mWifiNative.isGetChannelsForBandSupported()) { + //fail to get available channel + sendMessage(CMD_START_AP_FAILURE, WifiManager.SAP_START_FAILURE_NO_CHANNEL); + return; + } else { + //for some old device, wifiHal may not be supportedget valid channels are not + //supported + config.apBand = 0; + config.apChannel = 6; + } } } } else { //for some old device, wifiHal may not be supported - config.apChannel = 0; + config.apBand = 0; config.apChannel = 6; } // Start hostapd on a separate thread diff --git a/service/jni/com_android_server_wifi_WifiNative.cpp b/service/jni/com_android_server_wifi_WifiNative.cpp index 4291fd1a3..7556b1e67 100644 --- a/service/jni/com_android_server_wifi_WifiNative.cpp +++ b/service/jni/com_android_server_wifi_WifiNative.cpp @@ -1363,6 +1363,10 @@ static jboolean android_net_wifi_setScanningMacOui(JNIEnv *env, jclass cls, return hal_fn.wifi_set_scanning_mac_oui(handle, (byte *)bytes) == WIFI_SUCCESS; } +static jboolean android_net_wifi_is_get_channels_for_band_supported(JNIEnv *env, jclass cls){ + return (hal_fn.wifi_get_valid_channels == wifi_get_valid_channels_stub); +} + static jintArray android_net_wifi_getValidChannels(JNIEnv *env, jclass cls, jint iface, jint band) { @@ -2194,9 +2198,11 @@ static JNINativeMethod gWifiMethods[] = { { "setBssidBlacklistNative", "(II[Ljava/lang/String;)Z", (void*)android_net_wifi_setBssidBlacklist}, { "setSsidWhitelistNative", "(II[Ljava/lang/String;)Z", - (void*)android_net_wifi_setSsidWhitelist}, + (void*)android_net_wifi_setSsidWhitelist}, {"setLoggingEventHandlerNative", "(II)Z", (void *) android_net_wifi_set_log_handler}, - {"resetLogHandlerNative", "(II)Z", (void *) android_net_wifi_reset_log_handler} + {"resetLogHandlerNative", "(II)Z", (void *) android_net_wifi_reset_log_handler}, + {"isGetChannelsForBandSupportedNative", "()Z", + (void*)android_net_wifi_is_get_channels_for_band_supported} }; int register_android_net_wifi_WifiNative(JNIEnv* env) { -- cgit v1.2.3