resolved conflicts for merge of ee0a0132 to mnc-dr-dev

Change-Id: I61046edb56b9b54a759e4964762fa7b01d4eaba1
diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java
index e952d8d..d762f47 100644
--- a/service/java/com/android/server/wifi/WifiNative.java
+++ b/service/java/com/android/server/wifi/WifiNative.java
@@ -1903,10 +1903,24 @@
 
     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 44968f8..aa1750c 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -5279,14 +5279,21 @@
             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 567eac2..92bd3cd 100644
--- a/service/jni/com_android_server_wifi_WifiNative.cpp
+++ b/service/jni/com_android_server_wifi_WifiNative.cpp
@@ -1363,6 +1363,10 @@
     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)  {
 
@@ -2270,7 +2274,7 @@
     { "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},
     { "startSendingOffloadedPacketNative", "(II[B[B[BI)I",
@@ -2280,7 +2284,9 @@
     {"startRssiMonitoringNative", "(IIBB)I",
             (void*)android_net_wifi_start_rssi_monitoring_native},
     {"stopRssiMonitoringNative", "(II)I",
-            (void*)android_net_wifi_stop_rssi_monitoring_native}
+            (void*)android_net_wifi_stop_rssi_monitoring_native},
+    {"isGetChannelsForBandSupportedNative", "()Z",
+            (void*)android_net_wifi_is_get_channels_for_band_supported}
 };
 
 int register_android_net_wifi_WifiNative(JNIEnv* env) {