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

Commit 3550ac91 authored by Isaac Levy's avatar Isaac Levy
Browse files

Adding WifiInfo object in CONNECTED broadcast

Adding a parsable wifiinfo object in Connected broadcast, public api.
The connected broadcast only occurs on successful setup on the wifi
interface, so in normal use is very infrequent (once if the wifi
sleeps, or once at new hotspots, etc...)

WifiInfo objects are small, <10 ints, <5 short strings, and contain info
that could be useful to listeners, such as SSID.

The alternative is to the poll the Wifi Manager, using getConnectionInfo.
Because the Wifi Manager can update state in its own thread, polling the
Wifi Manager might result in an info object that's out of sync from the
received broadcast.

Change-Id: Iafcec77f45dd094ea84e6022b7a40e8952ae8137
parent 6461c973
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -11912,6 +11912,7 @@ package android.net.wifi {
    field public static final java.lang.String EXTRA_PREVIOUS_WIFI_STATE = "previous_wifi_state";
    field public static final java.lang.String EXTRA_SUPPLICANT_CONNECTED = "connected";
    field public static final java.lang.String EXTRA_SUPPLICANT_ERROR = "supplicantError";
    field public static final java.lang.String EXTRA_WIFI_INFO = "wifiInfo";
    field public static final java.lang.String EXTRA_WIFI_STATE = "wifi_state";
    field public static final java.lang.String NETWORK_IDS_CHANGED_ACTION = "android.net.wifi.NETWORK_IDS_CHANGED";
    field public static final java.lang.String NETWORK_STATE_CHANGED_ACTION = "android.net.wifi.STATE_CHANGE";
+18 −0
Original line number Diff line number Diff line
@@ -81,6 +81,24 @@ public class WifiInfo implements Parcelable {
        mHiddenSSID = false;
    }

    /**
     * Copy constructor
     * @hide
     */
    public WifiInfo(WifiInfo source) {
        if (source != null) {
            mSupplicantState = source.mSupplicantState;
            mBSSID = source.mBSSID;
            mSSID = source.mSSID;
            mNetworkId = source.mNetworkId;
            mHiddenSSID = source.mHiddenSSID;
            mRssi = source.mRssi;
            mLinkSpeed = source.mLinkSpeed;
            mIpAddress = source.mIpAddress;
            mMacAddress = source.mMacAddress;
        }
    }

    void setSSID(String SSID) {
        mSSID = SSID;
        // network is considered not hidden by default
+11 −2
Original line number Diff line number Diff line
@@ -230,11 +230,13 @@ public class WifiManager {
    /**
     * Broadcast intent action indicating that the state of Wi-Fi connectivity
     * has changed. One extra provides the new state
     * in the form of a {@link android.net.NetworkInfo} object. If the new state is
     * CONNECTED, a second extra may provide the BSSID of the access point,
     * in the form of a {@link android.net.NetworkInfo} object. If the new
     * state is CONNECTED, additional extras may provide the BSSID and WifiInfo of
     * the access point.
     * as a {@code String}.
     * @see #EXTRA_NETWORK_INFO
     * @see #EXTRA_BSSID
     * @see #EXTRA_WIFI_INFO
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String NETWORK_STATE_CHANGED_ACTION = "android.net.wifi.STATE_CHANGE";
@@ -251,6 +253,13 @@ public class WifiManager {
     * {@link android.content.Intent#getStringExtra(String)}.
     */
    public static final String EXTRA_BSSID = "bssid";
    /**
     * The lookup key for a {@link android.net.wifi.WifiInfo} object giving the
     * information about the access point to which we are connected. Only present
     * when the new state is CONNECTED.  Retrieve with
     * {@link android.content.Intent#getParcelableExtra(String)}.
     */
    public static final String EXTRA_WIFI_INFO = "wifiInfo";
    /**
     * Broadcast intent action indicating that the state of establishing a connection to
     * an access point has changed.One extra provides the new
+2 −0
Original line number Diff line number Diff line
@@ -1374,6 +1374,8 @@ public class WifiStateMachine extends StateMachine {
        intent.putExtra(WifiManager.EXTRA_LINK_PROPERTIES, new LinkProperties (mLinkProperties));
        if (bssid != null)
            intent.putExtra(WifiManager.EXTRA_BSSID, bssid);
        if (mNetworkInfo.getState() == NetworkInfo.State.CONNECTED)
            intent.putExtra(WifiManager.EXTRA_WIFI_INFO, new WifiInfo(mWifiInfo));
        mContext.sendStickyBroadcast(intent);
    }