Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 98b1d8d5 authored by Etan Cohen's avatar Etan Cohen
Browse files

[WIFICOND][API] Update channel API from array to list

Per API council feedback.

Bug: 148680192
Test: atest android.net.wifi
Change-Id: I3a6230eee6fbace68df8b67fb3fa64e299152d40
parent a6528df8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -8267,7 +8267,7 @@ package android.net.wifi.wificond {
  public class WifiCondManager {
    method public void abortScan(@NonNull String);
    method public void enableVerboseLogging(boolean);
    method @NonNull public int[] getChannelsMhzForBand(int);
    method @NonNull public java.util.List<java.lang.Integer> getChannelsMhzForBand(int);
    method @Nullable public android.net.wifi.wificond.DeviceWiphyCapabilities getDeviceWiphyCapabilities(@NonNull String);
    method @NonNull public java.util.List<android.net.wifi.wificond.NativeScanResult> getScanResults(@NonNull String, int);
    method @Nullable public android.net.wifi.wificond.WifiCondManager.TxPacketCounters getTxPacketCounters(@NonNull String);
+10 −7
Original line number Diff line number Diff line
@@ -41,16 +41,19 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

/**
 * This class encapsulates the interface the wificond daemon presents to the Wi-Fi framework. The
 * interface is only for use by the Wi-Fi framework and access is protected by SELinux permissions.
 * This class encapsulates the interface the wificond (Wi-Fi Conductor) daemon presents to the
 * Wi-Fi framework. The interface is only for use by the Wi-Fi framework and access is protected
 * by SELinux permissions: only the system server and wpa_supplicant can use WifiCondManager.
 *
 * @hide
 */
@@ -1011,13 +1014,13 @@ public class WifiCondManager {
     * WifiScanner.WIFI_BAND_5_GHZ
     * WifiScanner.WIFI_BAND_5_GHZ_DFS_ONLY
     * WifiScanner.WIFI_BAND_6_GHZ
     * @return frequencies vector of valid frequencies (MHz), or an empty array for error.
     * @return frequencies List of valid frequencies (MHz), or an empty list for error.
     * @throws IllegalArgumentException if band is not recognized.
     */
    public @NonNull int[] getChannelsMhzForBand(@WifiAnnotations.WifiBandBasic int band) {
    public @NonNull List<Integer> getChannelsMhzForBand(@WifiAnnotations.WifiBandBasic int band) {
        if (mWificond == null) {
            Log.e(TAG, "No valid wificond scanner interface handler");
            return new int[0];
            return Collections.emptyList();
        }
        int[] result = null;
        try {
@@ -1041,9 +1044,9 @@ public class WifiCondManager {
            Log.e(TAG, "Failed to request getChannelsForBand due to remote exception");
        }
        if (result == null) {
            result = new int[0];
            return Collections.emptyList();
        }
        return result;
        return Arrays.stream(result).boxed().collect(Collectors.toList());
    }

    /** Helper function to look up the interface handle using name */
+35 −1
Original line number Diff line number Diff line
@@ -65,6 +65,8 @@ import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -741,10 +743,42 @@ public class WifiCondManagerTest {
        verify(deathHandler).run();

        // The handles should be cleared after death.
        assertEquals(0, mWificondControl.getChannelsMhzForBand(WifiScanner.WIFI_BAND_5_GHZ).length);
        assertEquals(0, mWificondControl.getChannelsMhzForBand(WifiScanner.WIFI_BAND_5_GHZ).size());
        verify(mWificond, never()).getAvailable5gNonDFSChannels();
    }

    /**
     * Verify primitive array to list translation of channel API.
     */
    @Test
    public void testGetChannels() throws Exception {
        int[] resultsEmpty = new int[0];
        int[] resultsSingle = new int[]{100};
        int[] resultsMore = new int[]{100, 200};

        List<Integer> emptyList = Collections.emptyList();
        List<Integer> singleList = Arrays.asList(100);
        List<Integer> moreList = Arrays.asList(100, 200);

        when(mWificond.getAvailable2gChannels()).thenReturn(null);
        assertEquals(mWificondControl.getChannelsMhzForBand(WifiScanner.WIFI_BAND_24_GHZ),
                emptyList);
        assertEquals(mWificondControl.getChannelsMhzForBand(WifiScanner.WIFI_BAND_5_GHZ),
                emptyList);

        when(mWificond.getAvailable2gChannels()).thenReturn(resultsEmpty);
        assertEquals(mWificondControl.getChannelsMhzForBand(WifiScanner.WIFI_BAND_24_GHZ),
                emptyList);

        when(mWificond.getAvailable2gChannels()).thenReturn(resultsSingle);
        assertEquals(mWificondControl.getChannelsMhzForBand(WifiScanner.WIFI_BAND_24_GHZ),
                singleList);

        when(mWificond.getAvailable2gChannels()).thenReturn(resultsMore);
        assertEquals(mWificondControl.getChannelsMhzForBand(WifiScanner.WIFI_BAND_24_GHZ),
                moreList);
    }

    /**
     * sendMgmtFrame() should fail if a null callback is passed in.
     */