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

Commit 5a600f5d authored by Roshan Pius's avatar Roshan Pius
Browse files

WifiScanner: Pass the band scanned in ScanData

Replace the existing |isAllChannelsScanned| variable with the exact band
that was scanned.
|isAllChannelsScanned| flag has been overloaded over the years to convey
both {2g + 5g} & {2g + 5g + dfs} scans. This was needed for wifi wake
and other clients for whom both were equivalent. For sending out
scan broadcasts to external apps, we need to identify scans with
{2g + 5g + dfs} only.

Also, add annotation for the permission required for |registerScanListener|.
This should only be available to wifi stack.

Bug: 119316884
Test: ./frameworks/base/wifi/tests/runtests.sh
Test: Will send for integration tests
Change-Id: Iea50851ef9f1e98d2e06601ba89d112cd2dd4e38
parent 79e4b948
Loading
Loading
Loading
Loading
+14 −12
Original line number Diff line number Diff line
@@ -344,11 +344,12 @@ public class WifiScanner {
         */
        private int mBucketsScanned;
        /**
         * Indicates that the scan results received are as a result of a scan of all available
         * channels. This should only be expected to function for single scans.
         * Bands scanned. One of the WIFI_BAND values.
         * Will be {@link #WIFI_BAND_UNSPECIFIED} if the list of channels do not fully cover
         * any of the bands.
         * {@hide}
         */
        private boolean mAllChannelsScanned;
        private int mBandScanned;
        /** all scan results discovered in this scan, sorted by timestamp in ascending order */
        private ScanResult mResults[];

@@ -361,12 +362,12 @@ public class WifiScanner {
        }

        /** {@hide} */
        public ScanData(int id, int flags, int bucketsScanned, boolean allChannelsScanned,
        public ScanData(int id, int flags, int bucketsScanned, int bandScanned,
                        ScanResult[] results) {
            mId = id;
            mFlags = flags;
            mBucketsScanned = bucketsScanned;
            mAllChannelsScanned = allChannelsScanned;
            mBandScanned = bandScanned;
            mResults = results;
        }

@@ -374,7 +375,7 @@ public class WifiScanner {
            mId = s.mId;
            mFlags = s.mFlags;
            mBucketsScanned = s.mBucketsScanned;
            mAllChannelsScanned = s.mAllChannelsScanned;
            mBandScanned = s.mBandScanned;
            mResults = new ScanResult[s.mResults.length];
            for (int i = 0; i < s.mResults.length; i++) {
                ScanResult result = s.mResults[i];
@@ -397,8 +398,8 @@ public class WifiScanner {
        }

        /** {@hide} */
        public boolean isAllChannelsScanned() {
            return mAllChannelsScanned;
        public int getBandScanned() {
            return mBandScanned;
        }

        public ScanResult[] getResults() {
@@ -416,7 +417,7 @@ public class WifiScanner {
                dest.writeInt(mId);
                dest.writeInt(mFlags);
                dest.writeInt(mBucketsScanned);
                dest.writeInt(mAllChannelsScanned ? 1 : 0);
                dest.writeInt(mBandScanned);
                dest.writeInt(mResults.length);
                for (int i = 0; i < mResults.length; i++) {
                    ScanResult result = mResults[i];
@@ -434,13 +435,13 @@ public class WifiScanner {
                        int id = in.readInt();
                        int flags = in.readInt();
                        int bucketsScanned = in.readInt();
                        boolean allChannelsScanned = in.readInt() != 0;
                        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);
                        }
                        return new ScanData(id, flags, bucketsScanned, allChannelsScanned, results);
                        return new ScanData(id, flags, bucketsScanned, bandScanned, results);
                    }

                    public ScanData[] newArray(int size) {
@@ -746,6 +747,7 @@ public class WifiScanner {
     *                 Multiple requests should also not share this object.
     * {@hide}
     */
    @RequiresPermission(Manifest.permission.NETWORK_STACK)
    public void registerScanListener(ScanListener listener) {
        Preconditions.checkNotNull(listener, "listener cannot be null");
        int key = addListener(listener);
+27 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.net.wifi;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -26,6 +27,7 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.net.wifi.WifiScanner.PnoSettings;
import android.net.wifi.WifiScanner.PnoSettings.PnoNetwork;
import android.net.wifi.WifiScanner.ScanData;
import android.net.wifi.WifiScanner.ScanSettings;
import android.os.Handler;
import android.os.Parcel;
@@ -203,4 +205,29 @@ public class WifiScannerTest {
        assertNotNull(pnoNetwork.frequencies);
    }

    /**
     * Verify parcel read/write for ScanData.
     */
    @Test
    public void verifyScanDataParcel() throws Exception {
        ScanData writeScanData = new ScanData(2, 0, 3,
                WifiScanner.WIFI_BAND_BOTH_WITH_DFS, new ScanResult[0]);

        ScanData readScanData = parcelWriteRead(writeScanData);
        assertEquals(writeScanData.getId(), readScanData.getId());
        assertEquals(writeScanData.getFlags(), readScanData.getFlags());
        assertEquals(writeScanData.getBucketsScanned(), readScanData.getBucketsScanned());
        assertEquals(writeScanData.getBandScanned(), readScanData.getBandScanned());
        assertArrayEquals(writeScanData.getResults(), readScanData.getResults());
    }

    /**
     * Write the provided {@link ScanData} to a parcel and deserialize it.
     */
    private static ScanData parcelWriteRead(ScanData writeScanData) throws Exception {
        Parcel parcel = Parcel.obtain();
        writeScanData.writeToParcel(parcel, 0);
        parcel.setDataPosition(0);    // Rewind data position back to the beginning for read.
        return ScanData.CREATOR.createFromParcel(parcel);
    }
}