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

Commit c7cc37b3 authored by Vinit Deshpande's avatar Vinit Deshpande
Browse files

Introduce Wifi Adapters

This change extracts all the wifi interfaces on the device; and provides
its supported features.

Change-Id: I7fbdbec684d653a6e4bf851797e3065ce222e873
parent 19024b6d
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.net.wifi;

import android.net.wifi.BatchedScanResult;
import android.net.wifi.BatchedScanSettings;
import android.net.wifi.WifiAdapter;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.ScanSettings;
@@ -25,6 +26,7 @@ import android.net.wifi.WifiChannel;
import android.net.wifi.ScanResult;
import android.net.DhcpInfo;


import android.os.Messenger;
import android.os.WorkSource;

@@ -35,6 +37,8 @@ import android.os.WorkSource;
 */
interface IWifiManager
{
    List<WifiAdapter> getAdaptors();

    List<WifiConfiguration> getConfiguredNetworks();

    int addOrUpdateNetwork(in WifiConfiguration config);
+19 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2008, 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 WifiAdapter;
+135 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 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.os.Parcel;
import android.os.Parcelable;

/** @hide */
public class WifiAdapter implements Parcelable {

    /* Keep this list in sync with wifi_hal.h */
    private static final int WIFI_FEATURE_INFRA            = 0x0001;    // Basic infrastructure mode
    private static final int WIFI_FEATURE_INFRA_5G         = 0x0002;    // Support for 5 GHz Band
    private static final int WIFI_FEATURE_PASSPOINT        = 0x0004;    // Support for GAS/ANQP
    private static final int WIFI_FEATURE_WIFI_DIRECT      = 0x0008;    // Wifi-Direct
    private static final int WIFI_FEATURE_MOBILE_HOTSPOT   = 0x0010;    // Soft AP
    private static final int WIFI_FEATURE_SCANNER          = 0x0020;    // WifiScanner APIs
    private static final int WIFI_FEATURE_NAN              = 0x0040;    // Neighbor Awareness Networking
    private static final int WIFI_FEATURE_D2D_RTT          = 0x0080;    // Device-to-device RTT
    private static final int WIFI_FEATURE_D2AP_RTT         = 0x0100;    // Device-to-AP RTT
    private static final int WIFI_FEATURE_BATCH_SCAN       = 0x0200;    // Batched Scan (deprecated)
    private static final int WIFI_FEATURE_PNO              = 0x0400;    // Preferred network offload
    private static final int WIFI_FEATURE_ADDITIONAL_STA   = 0x0800;    // Support for two STAs
    private static final int WIFI_FEATURE_TDLS             = 0x1000;    // Tunnel directed link setup
    private static final int WIFI_FEATURE_TDLS_OFFCHANNEL  = 0x2000;    // Support for TDLS off channel
    private static final int WIFI_FEATURE_EPR              = 0x4000;    // Enhanced power reporting

    private String name;
    private int    supportedFeatures;

    public WifiAdapter(String name, int supportedFeatures) {
        this.name = name;
        this.supportedFeatures = supportedFeatures;
    }

    public String getName() {
        return name;
    }

    private int getSupportedFeatures() {
        return supportedFeatures;
    }

    private boolean isFeatureSupported(int feature) {
        return (supportedFeatures & feature) == feature;
    }

    public boolean isPasspointSupported() {
        return isFeatureSupported(WIFI_FEATURE_PASSPOINT);
    }

    public boolean isWifiDirectSupported() {
        return isFeatureSupported(WIFI_FEATURE_WIFI_DIRECT);
    }

    public boolean isMobileHotstpoSupported() {
        return isFeatureSupported(WIFI_FEATURE_MOBILE_HOTSPOT);
    }

    public boolean isWifiScannerSupported() {
        return isFeatureSupported(WIFI_FEATURE_SCANNER);
    }

    public boolean isNanSupported() {
        return isFeatureSupported(WIFI_FEATURE_NAN);
    }

    public boolean isDeviceToDeviceRttSupported() {
        return isFeatureSupported(WIFI_FEATURE_D2D_RTT);
    }

    public boolean isDeviceToApRttSupported() {
        return isFeatureSupported(WIFI_FEATURE_D2AP_RTT);
    }

    public boolean isPreferredNetworkOffloadSupported() {
        return isFeatureSupported(WIFI_FEATURE_PNO);
    }

    public boolean isAdditionalStaSupported() {
        return isFeatureSupported(WIFI_FEATURE_ADDITIONAL_STA);
    }

    public boolean isTdlsSupported() {
        return isFeatureSupported(WIFI_FEATURE_TDLS);
    }

    public boolean isOffChannelTdlsSupported() {
        return isFeatureSupported(WIFI_FEATURE_TDLS_OFFCHANNEL);
    }

    public boolean isEnhancedPowerReportingSupported() {
        return isFeatureSupported(WIFI_FEATURE_EPR);
    }

    /* Parcelable implementation */

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

    /** Implement the Parcelable interface {@hide} */
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(name);
        dest.writeInt(supportedFeatures);
    }

    /** Implement the Parcelable interface {@hide} */
    public static final Creator<WifiAdapter> CREATOR =
            new Creator<WifiAdapter>() {
                public WifiAdapter createFromParcel(Parcel in) {
                    WifiAdapter adaptor = new WifiAdapter(in.readString(), in.readInt());
                    return adaptor;
                }

                public WifiAdapter[] newArray(int size) {
                    return new WifiAdapter[size];
                }
            };
}
+11 −0
Original line number Diff line number Diff line
@@ -567,6 +567,17 @@ public class WifiManager {
        init();
    }

    /**
     * @hide
     */
    public List<WifiAdapter> getAdaptors() {
        try {
            return mService.getAdaptors();
        } catch (RemoteException e) {
            return null;
        }
    }

    /**
     * Return a list of all the networks configured in the supplicant.
     * Not all fields of WifiConfiguration are returned. Only the following