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

Commit 9f94d8de authored by Bruno Randolf's avatar Bruno Randolf Committed by Gerrit Code Review
Browse files

Wifi: Get the list of supported channels

Get the list of supported channels/frequencies from wpa_supplicant and provide
them thru WifiManager.getSupportedChannels();

One channel is represented thru the class WifiChannel which includes channel
number, frequency in MHz and a flag if IBSS mode is allowed on this channel.

Like isIbssSupported() we can only expect a result after WIFI_STATE_ENABLED has
been reached.

Change-Id: I9fc34642b9a0047f6871b180a3a7a69d47b7e2ff
parent 99e2985e
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.database.ContentObserver;
import android.net.wifi.IWifiManager;
import android.net.wifi.ScanResult;
import android.net.wifi.SupplicantState;
import android.net.wifi.WifiChannel;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiStateMachine;
@@ -943,6 +944,16 @@ public class WifiService extends IWifiManager.Stub {
        }
    }

    public List<WifiChannel> getSupportedChannels() {
        enforceAccessPermission();
        if (mWifiStateMachineChannel != null) {
            return (mWifiStateMachine.syncGetSupportedChannels(mWifiStateMachineChannel));
        } else {
            Slog.e(TAG, "mWifiStateMachineChannel is not initialized");
            return null;
        }
    }

    /**
     * Return the DHCP-assigned addresses from the last successful DHCP request,
     * if any.
+3 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.net.wifi;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiChannel;
import android.net.DhcpInfo;

import android.os.Messenger;
@@ -71,6 +72,8 @@ interface IWifiManager

    boolean isIbssSupported();

    List<WifiChannel> getSupportedChannels();

    boolean saveConfiguration();

    DhcpInfo getDhcpInfo();
+19 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2013, 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.
 */

package android.net.wifi;

parcelable WifiChannel;
+85 −0
Original line number Diff line number Diff line

package android.net.wifi;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * A class representing one wifi channel or frequency
 * @hide
 */
public class WifiChannel implements Parcelable {
    public int channel;
    public int frequency;
    public boolean ibssAllowed;

    public String toString() {
        StringBuffer sbuf = new StringBuffer();
        sbuf.append(" channel: ").append(channel);
        sbuf.append(" freq: ").append(frequency);
        sbuf.append(" MHz");
        sbuf.append(" IBSS: ").append(ibssAllowed ? "allowed" : "not allowed");
        sbuf.append('\n');
        return sbuf.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (o instanceof WifiChannel) {
            WifiChannel w = (WifiChannel)o;
            return (this.channel == w.channel &&
                    this.frequency == w.frequency &&
                    this.ibssAllowed == w.ibssAllowed);
        }
        return false;
    }

    /** Implement the Parcelable interface */
    public int describeContents() {
        return 0;
    }

    public WifiChannel() {
        channel = 0;
        frequency = 0;
        ibssAllowed = false;
    }

    public WifiChannel(int ch, int freq, boolean ibss) {
        channel = ch;
        frequency = freq;
        ibssAllowed = ibss;
    }

    /* Copy constructor */
    public WifiChannel(WifiChannel source) {
        if (source != null) {
            channel = source.channel;
            frequency = source.frequency;
            ibssAllowed = source.ibssAllowed;
        }
    }

    /** Implement the Parcelable interface */
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(channel);
        dest.writeInt(frequency);
        dest.writeInt(ibssAllowed ? 1 : 0);
    }

    /** Implement the Parcelable interface */
    public static final Creator<WifiChannel> CREATOR =
            new Creator<WifiChannel>() {
                public WifiChannel createFromParcel(Parcel in) {
                    WifiChannel ch = new WifiChannel();
                    ch.channel = in.readInt();
                    ch.frequency = in.readInt();
                    ch.ibssAllowed = (in.readInt() == 1);
                    return ch;
                }

                public WifiChannel[] newArray(int size) {
                    return new WifiChannel[size];
                }
            };
}
+13 −0
Original line number Diff line number Diff line
@@ -883,6 +883,19 @@ public class WifiManager {
        }
    }

    /**
     * Get a list of supported channels / frequencies
     * @return a List of WifiChannels
     * @hide
     */
    public List<WifiChannel> getSupportedChannels() {
        try {
            return mService.getSupportedChannels();
        } catch (RemoteException e) {
            return null;
        }
    }

    /**
     * Return the DHCP-assigned addresses from the last successful DHCP request,
     * if any.
Loading