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

Commit 3c7989bf authored by Les Lee's avatar Les Lee Committed by Android (Google) Code Review
Browse files

Merge "wifi: Add SoftApInfo Callback support"

parents c2afdc10 3fd4b647
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -4755,6 +4755,21 @@ package android.net.wifi {
    method @NonNull public android.net.wifi.SoftApConfiguration.Builder setWpa2Passphrase(@Nullable String);
  }
  public final class SoftApInfo implements android.os.Parcelable {
    method public int describeContents();
    method public int getBandwidth();
    method public int getFrequency();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field public static final int CHANNEL_WIDTH_160MHZ = 6; // 0x6
    field public static final int CHANNEL_WIDTH_20MHZ = 2; // 0x2
    field public static final int CHANNEL_WIDTH_20MHZ_NOHT = 1; // 0x1
    field public static final int CHANNEL_WIDTH_40MHZ = 3; // 0x3
    field public static final int CHANNEL_WIDTH_80MHZ = 4; // 0x4
    field public static final int CHANNEL_WIDTH_80MHZ_PLUS_MHZ = 5; // 0x5
    field public static final int CHANNEL_WIDTH_INVALID = 0; // 0x0
    field @NonNull public static final android.os.Parcelable.Creator<android.net.wifi.SoftApInfo> CREATOR;
  }
  public final class WifiClient implements android.os.Parcelable {
    method public int describeContents();
    method @NonNull public android.net.MacAddress getMacAddress();
+8 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */

package android.net.wifi;
import android.net.wifi.SoftApInfo;

import android.net.wifi.WifiClient;

@@ -43,4 +44,11 @@ oneway interface ISoftApCallback
     * @param clients the currently connected clients
     */
    void onConnectedClientsChanged(in List<WifiClient> clients);

    /**
     * Service to manager callback providing information of softap.
     *
     * @param softApInfo is the softap information. {@link SoftApInfo}
     */
    void onInfoChanged(in SoftApInfo softApInfo);
}
+20 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2019, 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 SoftApInfo;
+211 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Objects;

/**
 * A class representing information about SoftAp.
 * {@see WifiManager}
 *
 * @hide
 */
@SystemApi
public final class SoftApInfo implements Parcelable {

    /**
     * AP Channel bandwidth is invalid.
     *
     * @see #getBandwidth()
     */
    public static final int CHANNEL_WIDTH_INVALID = 0;

    /**
     * AP Channel bandwidth is 20 MHZ but no HT.
     *
     * @see #getBandwidth()
     */
    public static final int CHANNEL_WIDTH_20MHZ_NOHT = 1;

    /**
     * AP Channel bandwidth is 20 MHZ.
     *
     * @see #getBandwidth()
     */
    public static final int CHANNEL_WIDTH_20MHZ = 2;

    /**
     * AP Channel bandwidth is 40 MHZ.
     *
     * @see #getBandwidth()
     */
    public static final int CHANNEL_WIDTH_40MHZ = 3;

    /**
     * AP Channel bandwidth is 80 MHZ.
     *
     * @see #getBandwidth()
     */
    public static final int CHANNEL_WIDTH_80MHZ = 4;

    /**
     * AP Channel bandwidth is 160 MHZ, but 80MHZ + 80MHZ.
     *
     * @see #getBandwidth()
     */
    public static final int CHANNEL_WIDTH_80MHZ_PLUS_MHZ = 5;

    /**
     * AP Channel bandwidth is 160 MHZ.
     *
     * @see #getBandwidth()
     */
    public static final int CHANNEL_WIDTH_160MHZ = 6;

    /**
     * @hide
     */
    @IntDef(prefix = { "CHANNEL_WIDTH_" }, value = {
            CHANNEL_WIDTH_INVALID,
            CHANNEL_WIDTH_20MHZ_NOHT,
            CHANNEL_WIDTH_20MHZ,
            CHANNEL_WIDTH_40MHZ,
            CHANNEL_WIDTH_80MHZ,
            CHANNEL_WIDTH_80MHZ_PLUS_MHZ,
            CHANNEL_WIDTH_160MHZ,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface Bandwidth {}


    /** The frequency which AP resides on.  */
    private int mFrequency = 0;

    @Bandwidth
    private int mBandwidth = CHANNEL_WIDTH_INVALID;

    /**
     * Get the frequency which AP resides on.
     */
    public int getFrequency() {
        return mFrequency;
    }

    /**
     * Set the frequency which AP resides on.
     * @hide
     */
    public void setFrequency(int freq) {
        mFrequency = freq;
    }

    /**
     * Get AP Channel bandwidth.
     *
     * @return One of {@link #CHANNEL_WIDTH_20MHZ}, {@link #CHANNEL_WIDTH_40MHZ},
     * {@link #CHANNEL_WIDTH_80MHZ}, {@link #CHANNEL_WIDTH_160MHZ},
     * {@link #CHANNEL_WIDTH_80MHZ_PLUS_MHZ} or {@link #CHANNEL_WIDTH_UNKNOWN}.
     */
    @Bandwidth
    public int getBandwidth() {
        return mBandwidth;
    }

    /**
     * Set AP Channel bandwidth.
     * @hide
     */
    public void setBandwidth(@Bandwidth int bandwidth) {
        mBandwidth = bandwidth;
    }

    /**
     * @hide
     */
    public SoftApInfo(@Nullable SoftApInfo source) {
        if (source != null) {
            mFrequency = source.mFrequency;
            mBandwidth = source.mBandwidth;
        }
    }

    /**
     * @hide
     */
    public SoftApInfo() {
    }

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

    @Override
    /** Implement the Parcelable interface */
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeInt(mFrequency);
        dest.writeInt(mBandwidth);
    }

    @NonNull
    /** Implement the Parcelable interface */
    public static final Creator<SoftApInfo> CREATOR = new Creator<SoftApInfo>() {
        public SoftApInfo createFromParcel(Parcel in) {
            SoftApInfo info = new SoftApInfo();
            info.mFrequency = in.readInt();
            info.mBandwidth = in.readInt();
            return info;
        }

        public SoftApInfo[] newArray(int size) {
            return new SoftApInfo[size];
        }
    };

    @NonNull
    @Override
    public String toString() {
        return "SoftApInfo{"
                + "bandwidth= " + mBandwidth
                + ",frequency= " + mFrequency
                + '}';
    }

    @Override
    public boolean equals(@NonNull Object o) {
        if (this == o) return true;
        if (!(o instanceof SoftApInfo)) return false;
        SoftApInfo softApInfo = (SoftApInfo) o;
        return mFrequency == softApInfo.mFrequency
                && mBandwidth == softApInfo.mBandwidth;
    }

    @Override
    public int hashCode() {
        return Objects.hash(mFrequency, mBandwidth);
    }
}
+19 −0
Original line number Diff line number Diff line
@@ -3315,6 +3315,15 @@ public class WifiManager {
         * @param clients the currently connected clients
         */
        void onConnectedClientsChanged(@NonNull List<WifiClient> clients);

        /**
         * Called when information of softap changes.
         *
         * @param softApInfo is the softap information. {@link SoftApInfo}
         */
        default void onInfoChanged(@NonNull SoftApInfo softApInfo) {
            // Do nothing: can be updated to add SoftApInfo details (e.g. channel) to the UI.
        }
    }

    /**
@@ -3354,6 +3363,16 @@ public class WifiManager {
                mCallback.onConnectedClientsChanged(clients);
            });
        }

        @Override
        public void onInfoChanged(SoftApInfo softApInfo) {
            if (mVerboseLoggingEnabled) {
                Log.v(TAG, "SoftApCallbackProxy: onInfoChange: softApInfo=" + softApInfo);
            }
            mHandler.post(() -> {
                mCallback.onInfoChanged(softApInfo);
            });
        }
    }

    /**
Loading