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

Commit 082c5003 authored by Roshan Pius's avatar Roshan Pius Committed by Android (Google) Code Review
Browse files

Merge changes from topics "scanner_multiple_sta", "sta_sta_same_bands"

* changes:
  WifiScanner: Add missing @hide constants
  WifiScanner: Add support to add more results to ScanData
parents 64247a16 f180b094
Loading
Loading
Loading
Loading
+41 −28
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.net.wifi;

import android.Manifest;
import android.annotation.NonNull;
import android.annotation.RequiresPermission;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
@@ -58,13 +59,23 @@ public class WifiScanner {
    /** 5 GHz band excluding DFS channels */
    public static final int WIFI_BAND_5_GHZ = 2;            /* 5 GHz band without DFS channels */
    /** DFS channels from 5 GHz band only */
    public static final int WIFI_BAND_5_GHZ_DFS_ONLY  = 4;  /* 5 GHz band with DFS channels */
    public static final int WIFI_BAND_5_GHZ_DFS_ONLY  = 4;  /* 5 GHz band DFS channels */
    /**
     * 2.4Ghz band + DFS channels from 5 GHz band only
     * @hide
     */
    public static final int WIFI_BAND_24_GHZ_WITH_5GHZ_DFS  = 5;
    /** 5 GHz band including DFS channels */
    public static final int WIFI_BAND_5_GHZ_WITH_DFS  = 6;  /* 5 GHz band with DFS channels */
    /** Both 2.4 GHz band and 5 GHz band; no DFS channels */
    public static final int WIFI_BAND_BOTH = 3;             /* both bands without DFS channels */
    /** Both 2.4 GHz band and 5 GHz band; with DFS channels */
    public static final int WIFI_BAND_BOTH_WITH_DFS = 7;    /* both bands with DFS channels */
    /**
     * Max band value
     * @hide
     */
    public static final int WIFI_BAND_MAX = 8;

    /** Minimum supported scanning period */
    public static final int MIN_SCAN_PERIOD_MS = 1000;      /* minimum supported period */
@@ -375,19 +386,27 @@ public class WifiScanner {
         */
        private int mBandScanned;
        /** all scan results discovered in this scan, sorted by timestamp in ascending order */
        private ScanResult mResults[];
        private final List<ScanResult> mResults;

        ScanData() {}
        ScanData() {
            mResults = new ArrayList<>();
        }

        public ScanData(int id, int flags, ScanResult[] results) {
            mId = id;
            mFlags = flags;
            mResults = results;
            mResults = new ArrayList<>(Arrays.asList(results));
        }

        /** {@hide} */
        public ScanData(int id, int flags, int bucketsScanned, int bandScanned,
                        ScanResult[] results) {
            this(id, flags, bucketsScanned, bandScanned, new ArrayList<>(Arrays.asList(results)));
        }

        /** {@hide} */
        public ScanData(int id, int flags, int bucketsScanned, int bandScanned,
                        List<ScanResult> results) {
            mId = id;
            mFlags = flags;
            mBucketsScanned = bucketsScanned;
@@ -400,11 +419,9 @@ public class WifiScanner {
            mFlags = s.mFlags;
            mBucketsScanned = s.mBucketsScanned;
            mBandScanned = s.mBandScanned;
            mResults = new ScanResult[s.mResults.length];
            for (int i = 0; i < s.mResults.length; i++) {
                ScanResult result = s.mResults[i];
                ScanResult newResult = new ScanResult(result);
                mResults[i] = newResult;
            mResults = new ArrayList<>();
            for (ScanResult scanResult : s.mResults) {
                mResults.add(new ScanResult(scanResult));
            }
        }

@@ -427,7 +444,14 @@ public class WifiScanner {
        }

        public ScanResult[] getResults() {
            return mResults;
            return mResults.toArray(new ScanResult[0]);
        }

        /** {@hide} */
        public void addResults(@NonNull ScanResult[] newResults) {
            for (ScanResult result : newResults) {
                mResults.add(new ScanResult(result));
            }
        }

        /** Implement the Parcelable interface {@hide} */
@@ -437,19 +461,11 @@ public class WifiScanner {

        /** Implement the Parcelable interface {@hide} */
        public void writeToParcel(Parcel dest, int flags) {
            if (mResults != null) {
            dest.writeInt(mId);
            dest.writeInt(mFlags);
            dest.writeInt(mBucketsScanned);
            dest.writeInt(mBandScanned);
                dest.writeInt(mResults.length);
                for (int i = 0; i < mResults.length; i++) {
                    ScanResult result = mResults[i];
                    result.writeToParcel(dest, flags);
                }
            } else {
                dest.writeInt(0);
            }
            dest.writeParcelableList(mResults, 0);
        }

        /** Implement the Parcelable interface {@hide} */
@@ -460,11 +476,8 @@ public class WifiScanner {
                        int flags = in.readInt();
                        int bucketsScanned = in.readInt();
                        int bandScanned = in.readInt();
                        int n = in.readInt();
                        ScanResult results[] = new ScanResult[n];
                        for (int i = 0; i < n; i++) {
                            results[i] = ScanResult.CREATOR.createFromParcel(in);
                        }
                        List<ScanResult> results = new ArrayList<>();
                        in.readParcelableList(results, ScanResult.class.getClassLoader());
                        return new ScanData(id, flags, bucketsScanned, bandScanned, results);
                    }

+33 −1
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
@@ -445,4 +444,37 @@ public class WifiScannerTest {

        assertEquals(WifiScanner.CMD_STOP_PNO_SCAN, message.what);
    }

    @Test
    public void testScanDataAddResults() throws Exception {
        ScanResult scanResult1 = new ScanResult();
        scanResult1.SSID = TEST_SSID_1;
        ScanData scanData = new ScanData(0, 0, new ScanResult[]{scanResult1});

        ScanResult scanResult2 = new ScanResult();
        scanResult2.SSID = TEST_SSID_2;
        scanData.addResults(new ScanResult[]{scanResult2});

        ScanResult[] consolidatedScanResults = scanData.getResults();
        assertEquals(2, consolidatedScanResults.length);
        assertEquals(TEST_SSID_1, consolidatedScanResults[0].SSID);
        assertEquals(TEST_SSID_2, consolidatedScanResults[1].SSID);
    }

    @Test
    public void testScanDataParcel() throws Exception {
        ScanResult scanResult1 = new ScanResult();
        scanResult1.SSID = TEST_SSID_1;
        ScanData scanData = new ScanData(5, 4, new ScanResult[]{scanResult1});

        Parcel parcel = Parcel.obtain();
        scanData.writeToParcel(parcel, 0);
        parcel.setDataPosition(0);    // Rewind data position back to the beginning for read.
        ScanData readScanData = ScanData.CREATOR.createFromParcel(parcel);

        assertEquals(scanData.getId(), readScanData.getId());
        assertEquals(scanData.getFlags(), readScanData.getFlags());
        assertEquals(scanData.getResults().length, readScanData.getResults().length);
        assertEquals(scanData.getResults()[0].SSID, readScanData.getResults()[0].SSID);
    }
}