Allow for LOHS to run in 6GHz for auto

This commit adds an overlay for enabling LOHS on 6GHz for auto.
The 6GHz band will be used only if enabled by this overlay, and if
device supports 6GHz for softAp operation.

Bug: 158126668
Test: atest FrameworksWifiTests
Change-Id: I4e684826a5f2db5c5cf7ca4897dc7916f84e3795
Merged-In: I4e684826a5f2db5c5cf7ca4897dc7916f84e3795
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index 9d12aa0..52fb61f 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -1448,12 +1448,20 @@
 
         @GuardedBy("mLocalOnlyHotspotRequests")
         private void startForFirstRequestLocked(LocalOnlyHotspotRequestInfo request) {
-            boolean is5Ghz = hasAutomotiveFeature(mContext)
-                    && mContext.getResources().getBoolean(
-                    R.bool.config_wifi_local_only_hotspot_5ghz)
-                    && is5GhzBandSupportedInternal();
+            int band = SoftApConfiguration.BAND_2GHZ;
 
-            int band = is5Ghz ? SoftApConfiguration.BAND_5GHZ : SoftApConfiguration.BAND_2GHZ;
+            // For auto only
+            if (hasAutomotiveFeature(mContext)) {
+                if (mContext.getResources().getBoolean(R.bool.config_wifiLocalOnlyHotspot6ghz)
+                        && mContext.getResources().getBoolean(R.bool.config_wifiSoftap6ghzSupported)
+                        && is6GhzBandSupportedInternal()) {
+                    band = SoftApConfiguration.BAND_6GHZ;
+                } else if (mContext.getResources().getBoolean(
+                        R.bool.config_wifi_local_only_hotspot_5ghz)
+                        && is5GhzBandSupportedInternal()) {
+                    band = SoftApConfiguration.BAND_5GHZ;
+                }
+            }
 
             SoftApConfiguration softApConfig = WifiApConfigStore.generateLocalOnlyHotspotConfig(
                     mContext, band, request.getCustomConfig());
diff --git a/service/res/values/config.xml b/service/res/values/config.xml
index 8813738..ad454c1 100644
--- a/service/res/values/config.xml
+++ b/service/res/values/config.xml
@@ -217,8 +217,14 @@
     <!-- Wifi driver supports 6GHz band for softap -->
     <bool translatable="false" name="config_wifiSoftap6ghzSupported">false</bool>
 
-    <!-- Indicates that local-only hotspot should be brought up at 5GHz.  This option is
-         for automotive builds only (the one that have PackageManager#FEATURE_AUTOMOTIVE) -->
+    <!-- Indicates that local-only hotspot should be brought up at 6GHz if possible.
+         This option is for automotive builds only (the one that have
+         PackageManager#FEATURE_AUTOMOTIVE) -->
+    <bool translatable="false" name="config_wifiLocalOnlyHotspot6ghz">false</bool>
+
+    <!-- Indicates that local-only hotspot should be brought up at 5GHz if 6GHz is not enabled
+         or feasible.  This option is for automotive builds only (the one that have
+         PackageManager#FEATURE_AUTOMOTIVE) -->
     <bool translatable="false" name="config_wifi_local_only_hotspot_5ghz">false</bool>
 
     <!-- Indicates that connected MAC randomization is supported on this device -->
diff --git a/service/res/values/overlayable.xml b/service/res/values/overlayable.xml
index 7b77da5..cab5bbf 100644
--- a/service/res/values/overlayable.xml
+++ b/service/res/values/overlayable.xml
@@ -81,6 +81,7 @@
           <item type="bool" name="config_wifiSoftapHeSuBeamformeeSupported" />
           <item type="bool" name="config_wifiSoftapHeMuBeamformerSupported" />
           <item type="bool" name="config_wifiSoftapHeTwtSupported" />
+          <item type="bool" name="config_wifiLocalOnlyHotspot6ghz" />
           <item type="bool" name="config_wifi_local_only_hotspot_5ghz" />
           <item type="bool" name="config_wifi_connected_mac_randomization_supported" />
           <item type="bool" name="config_wifi_p2p_mac_randomization_supported" />
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index 603a4d8..6d1ae29 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -2168,18 +2168,26 @@
     @Test
     public void testStartLocalOnlyHotspotAt2Ghz() {
         registerLOHSRequestFull();
-        verifyLohsBand(WifiConfiguration.AP_BAND_2GHZ);
+        verifyLohsBand(SoftApConfiguration.BAND_2GHZ);
     }
 
     /**
-     * Verify that startLocalOnlyHotspot will start access point at 5 GHz if properly configured.
+     * Verify that startLocalOnlyHotspot will start access point at 6 GHz if properly configured
+     * and if feasible, even if the 5GHz is enabled.
      */
     @Test
-    public void testStartLocalOnlyHotspotAt5Ghz() {
+    public void testStartLocalOnlyHotspotAt6Ghz() {
         when(mResources.getBoolean(
                 eq(R.bool.config_wifi_local_only_hotspot_5ghz)))
                 .thenReturn(true);
+        when(mResources.getBoolean(
+                eq(R.bool.config_wifiLocalOnlyHotspot6ghz)))
+                .thenReturn(true);
         when(mClientModeImpl.isWifiBandSupported(WifiScanner.WIFI_BAND_5_GHZ)).thenReturn(true);
+        when(mClientModeImpl.isWifiBandSupported(WifiScanner.WIFI_BAND_6_GHZ)).thenReturn(true);
+        when(mResources.getBoolean(
+                eq(R.bool.config_wifiSoftap6ghzSupported)))
+                .thenReturn(true);
         when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)).thenReturn(true);
 
         verify(mAsyncChannel).connect(any(), mHandlerCaptor.capture(), any(Handler.class));
@@ -2189,15 +2197,44 @@
 
         mLooper.startAutoDispatch();
         registerLOHSRequestFull();
-        verifyLohsBand(WifiConfiguration.AP_BAND_5GHZ);
+        verifyLohsBand(SoftApConfiguration.BAND_6GHZ);
+    }
+
+    /**
+     * Verify that startLocalOnlyHotspot will start access point at 5 GHz if both 5GHz and 6GHz
+     * are enabled, but SoftAp is not supported for 6GHz.
+     */
+    @Test
+    public void testStartLocalOnlyHotspotAt5Ghz() {
+        when(mResources.getBoolean(
+                eq(R.bool.config_wifi_local_only_hotspot_5ghz)))
+                .thenReturn(true);
+        when(mResources.getBoolean(
+                eq(R.bool.config_wifiLocalOnlyHotspot6ghz)))
+                .thenReturn(true);
+        when(mClientModeImpl.isWifiBandSupported(WifiScanner.WIFI_BAND_5_GHZ)).thenReturn(true);
+        when(mClientModeImpl.isWifiBandSupported(WifiScanner.WIFI_BAND_6_GHZ)).thenReturn(true);
+        when(mResources.getBoolean(
+                eq(R.bool.config_wifiSoftap6ghzSupported)))
+                .thenReturn(false);
+        when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)).thenReturn(true);
+
+        verify(mAsyncChannel).connect(any(), mHandlerCaptor.capture(), any(Handler.class));
+        final Handler handler = mHandlerCaptor.getValue();
+        handler.handleMessage(handler.obtainMessage(
+                AsyncChannel.CMD_CHANNEL_HALF_CONNECTED, AsyncChannel.STATUS_SUCCESSFUL, 0));
+
+        mLooper.startAutoDispatch();
+        registerLOHSRequestFull();
+        verifyLohsBand(SoftApConfiguration.BAND_5GHZ);
     }
 
     private void verifyLohsBand(int expectedBand) {
         verify(mActiveModeWarden).startSoftAp(mSoftApModeConfigCaptor.capture());
-        final WifiConfiguration configuration =
-                mSoftApModeConfigCaptor.getValue().getSoftApConfiguration().toWifiConfiguration();
+        final SoftApConfiguration configuration =
+                mSoftApModeConfigCaptor.getValue().getSoftApConfiguration();
         assertNotNull(configuration);
-        assertEquals(expectedBand, configuration.apBand);
+        assertEquals(expectedBand, configuration.getBand());
     }
 
     private static class FakeLohsCallback extends ILocalOnlyHotspotCallback.Stub {