[WIFI][HIDL] Add device-based feature flag support

Add mechanism to define feature support flags to
configure set of Wi-Fi features supported on a particular
device.

Bug: 32997844
Test: integration tests
Change-Id: Iffbf3ba237013f1030b24c0173641234a9c27e5c
diff --git a/wifi/1.0/default/Android.mk b/wifi/1.0/default/Android.mk
index 00e5f98..e84c1c5 100644
--- a/wifi/1.0/default/Android.mk
+++ b/wifi/1.0/default/Android.mk
@@ -18,6 +18,9 @@
 LOCAL_MODULE_RELATIVE_PATH := hw
 LOCAL_PROPRIETARY_MODULE := true
 LOCAL_CPPFLAGS := -Wall -Werror -Wextra
+ifdef WIFI_HIDL_FEATURE_AWARE
+LOCAL_CPPFLAGS += -DWIFI_HIDL_FEATURE_AWARE
+endif
 LOCAL_SRC_FILES := \
     hidl_struct_util.cpp \
     hidl_sync_util.cpp \
diff --git a/wifi/1.0/default/wifi_chip.cpp b/wifi/1.0/default/wifi_chip.cpp
index 6f980c0..9c41a40 100644
--- a/wifi/1.0/default/wifi_chip.cpp
+++ b/wifi/1.0/default/wifi_chip.cpp
@@ -19,6 +19,7 @@
 #include "hidl_return_util.h"
 #include "hidl_struct_util.h"
 #include "wifi_chip.h"
+#include "wifi_feature_flags.h"
 #include "wifi_status_util.h"
 
 namespace {
@@ -388,16 +389,21 @@
   // The chip combination supported for current devices is fixed for now with
   // 2 separate modes of operation:
   // Mode 1 (STA mode): Will support 1 STA and 1 P2P or NAN iface operations
-  // concurrently.
+  // concurrently [NAN conditional on wifiHidlFeatureAware]
   // Mode 2 (AP mode): Will support 1 AP iface operations.
   // TODO (b/32997844): Read this from some device specific flags in the
   // makefile.
   // STA mode iface combinations.
   const IWifiChip::ChipIfaceCombinationLimit
       sta_chip_iface_combination_limit_1 = {{IfaceType::STA}, 1};
-  const IWifiChip::ChipIfaceCombinationLimit
-      sta_chip_iface_combination_limit_2 = {{IfaceType::P2P, IfaceType::NAN},
-                                            1};
+  IWifiChip::ChipIfaceCombinationLimit sta_chip_iface_combination_limit_2;
+  if (WifiFeatureFlags::wifiHidlFeatureAware) {
+    sta_chip_iface_combination_limit_2 = {{IfaceType::P2P, IfaceType::NAN},
+                                          1};
+  } else {
+    sta_chip_iface_combination_limit_2 = {{IfaceType::P2P},
+                                          1};
+  }
   const IWifiChip::ChipIfaceCombination sta_chip_iface_combination = {
       {sta_chip_iface_combination_limit_1, sta_chip_iface_combination_limit_2}};
   const IWifiChip::ChipMode sta_chip_mode = {kStaChipModeId,
@@ -552,18 +558,22 @@
 
 std::pair<WifiStatus, sp<IWifiNanIface>> WifiChip::createNanIfaceInternal() {
   // Only 1 of NAN or P2P iface can be active at a time.
-  if (current_mode_id_ != kStaChipModeId || nan_iface_.get() ||
-      p2p_iface_.get()) {
+  if (WifiFeatureFlags::wifiHidlFeatureAware) {
+    if (current_mode_id_ != kStaChipModeId || nan_iface_.get() ||
+        p2p_iface_.get()) {
+      return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
+    }
+    std::string ifname = legacy_hal_.lock()->getNanIfaceName();
+    nan_iface_ = new WifiNanIface(ifname, legacy_hal_);
+    for (const auto& callback : event_cb_handler_.getCallbacks()) {
+      if (!callback->onIfaceAdded(IfaceType::NAN, ifname).isOk()) {
+        LOG(ERROR) << "Failed to invoke onIfaceAdded callback";
+      }
+    }
+    return {createWifiStatus(WifiStatusCode::SUCCESS), nan_iface_};
+  } else {
     return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
   }
-  std::string ifname = legacy_hal_.lock()->getNanIfaceName();
-  nan_iface_ = new WifiNanIface(ifname, legacy_hal_);
-  for (const auto& callback : event_cb_handler_.getCallbacks()) {
-    if (!callback->onIfaceAdded(IfaceType::NAN, ifname).isOk()) {
-      LOG(ERROR) << "Failed to invoke onIfaceAdded callback";
-    }
-  }
-  return {createWifiStatus(WifiStatusCode::SUCCESS), nan_iface_};
 }
 
 std::pair<WifiStatus, std::vector<hidl_string>>
diff --git a/wifi/1.0/default/wifi_feature_flags.h b/wifi/1.0/default/wifi_feature_flags.h
new file mode 100644
index 0000000..3502fbd
--- /dev/null
+++ b/wifi/1.0/default/wifi_feature_flags.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef WIFI_FEATURE_FLAGS_H_
+#define WIFI_FEATURE_FLAGS_H_
+
+namespace android {
+namespace hardware {
+namespace wifi {
+namespace V1_0 {
+namespace implementation {
+
+class WifiFeatureFlags {
+ public:
+#ifdef WIFI_HIDL_FEATURE_AWARE
+  static const bool wifiHidlFeatureAware = true;
+#else
+  static const bool wifiHidlFeatureAware = false;
+#endif // WIFI_HIDL_FEATURE_AWARE
+};
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace wifi
+}  // namespace hardware
+}  // namespace android
+
+#endif  // WIFI_FEATURE_FLAGS_H_