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

Commit 238be814 authored by Quang Luong's avatar Quang Luong Committed by Android (Google) Code Review
Browse files

Merge "Add APIs for Wifi/Cellular coex channel avoidance"

parents 60797526 1459f65a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -248,7 +248,9 @@ package android {
    field public static final String USE_RESERVED_DISK = "android.permission.USE_RESERVED_DISK";
    field public static final String WHITELIST_AUTO_REVOKE_PERMISSIONS = "android.permission.WHITELIST_AUTO_REVOKE_PERMISSIONS";
    field public static final String WHITELIST_RESTRICTED_PERMISSIONS = "android.permission.WHITELIST_RESTRICTED_PERMISSIONS";
    field public static final String WIFI_ACCESS_COEX_UNSAFE_CHANNELS = "android.permission.WIFI_ACCESS_COEX_UNSAFE_CHANNELS";
    field public static final String WIFI_SET_DEVICE_MOBILITY_STATE = "android.permission.WIFI_SET_DEVICE_MOBILITY_STATE";
    field public static final String WIFI_UPDATE_COEX_UNSAFE_CHANNELS = "android.permission.WIFI_UPDATE_COEX_UNSAFE_CHANNELS";
    field public static final String WIFI_UPDATE_USABILITY_STATS_SCORE = "android.permission.WIFI_UPDATE_USABILITY_STATS_SCORE";
    field public static final String WRITE_DEVICE_CONFIG = "android.permission.WRITE_DEVICE_CONFIG";
    field public static final String WRITE_DREAM_STATE = "android.permission.WRITE_DREAM_STATE";
+10 −0
Original line number Diff line number Diff line
@@ -1815,6 +1815,16 @@
    <permission android:name="android.permission.WIFI_UPDATE_USABILITY_STATS_SCORE"
        android:protectionLevel="signature|privileged" />

    <!-- @SystemApi @hide Allows system APK to update Wifi/Cellular coex channels to avoid.
             <p>Not for use by third-party applications. -->
    <permission android:name="android.permission.WIFI_UPDATE_COEX_UNSAFE_CHANNELS"
        android:protectionLevel="signature" />

    <!-- @SystemApi @hide Allows applications to access Wifi/Cellular coex channels being avoided.
         <p>Not for use by third-party applications. -->
    <permission android:name="android.permission.WIFI_ACCESS_COEX_UNSAFE_CHANNELS"
                android:protectionLevel="signature|privileged" />

    <!-- ======================================= -->
    <!-- Permissions for short range, peripheral networks -->
    <!-- ======================================= -->
+19 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2020, 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 CoexUnsafeChannel;
+24 −0
Original line number Diff line number Diff line
// Signature format: 2.0
package android.net.wifi {

  public final class CoexUnsafeChannel implements android.os.Parcelable {
    ctor public CoexUnsafeChannel(int, int);
    ctor public CoexUnsafeChannel(int, int, int);
    method public int getBand();
    method public int getChannel();
    method public int getPowerCapDbm();
    method public boolean isPowerCapAvailable();
    method public void setPowerCapDbm(int);
    field @NonNull public static final android.os.Parcelable.Creator<android.net.wifi.CoexUnsafeChannel> CREATOR;
  }

  public abstract class EasyConnectStatusCallback {
    ctor public EasyConnectStatusCallback();
    method public void onBootstrapUriGenerated(@NonNull String);
@@ -456,6 +467,8 @@ package android.net.wifi {
    method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void factoryReset();
    method @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD, android.Manifest.permission.NETWORK_STACK}) public void forget(int, @Nullable android.net.wifi.WifiManager.ActionListener);
    method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) public java.util.List<android.util.Pair<android.net.wifi.WifiConfiguration,java.util.Map<java.lang.Integer,java.util.List<android.net.wifi.ScanResult>>>> getAllMatchingWifiConfigs(@NonNull java.util.List<android.net.wifi.ScanResult>);
    method @RequiresPermission(android.Manifest.permission.WIFI_ACCESS_COEX_UNSAFE_CHANNELS) public int getCoexRestrictions();
    method @NonNull @RequiresPermission(android.Manifest.permission.WIFI_ACCESS_COEX_UNSAFE_CHANNELS) public java.util.Set<android.net.wifi.CoexUnsafeChannel> getCoexUnsafeChannels();
    method @Nullable @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public String getCountryCode();
    method @Nullable @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) public android.net.Network getCurrentNetwork();
    method @NonNull @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public String[] getFactoryMacAddresses();
@@ -476,6 +489,7 @@ package android.net.wifi {
    method public boolean isVerboseLoggingEnabled();
    method @RequiresPermission(android.Manifest.permission.ACCESS_WIFI_STATE) public boolean isWifiApEnabled();
    method public boolean isWifiScannerSupported();
    method @RequiresPermission(android.Manifest.permission.WIFI_ACCESS_COEX_UNSAFE_CHANNELS) public void registerCoexCallback(@NonNull java.util.concurrent.Executor, @NonNull android.net.wifi.WifiManager.CoexCallback);
    method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void registerNetworkRequestMatchCallback(@NonNull java.util.concurrent.Executor, @NonNull android.net.wifi.WifiManager.NetworkRequestMatchCallback);
    method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void registerSoftApCallback(@NonNull java.util.concurrent.Executor, @NonNull android.net.wifi.WifiManager.SoftApCallback);
    method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void registerTrafficStateCallback(@NonNull java.util.concurrent.Executor, @NonNull android.net.wifi.WifiManager.TrafficStateCallback);
@@ -487,6 +501,7 @@ package android.net.wifi {
    method @NonNull @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public byte[] retrieveSoftApBackupData();
    method @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD, android.Manifest.permission.NETWORK_STACK}) public void save(@NonNull android.net.wifi.WifiConfiguration, @Nullable android.net.wifi.WifiManager.ActionListener);
    method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void setAutoWakeupEnabled(boolean);
    method @RequiresPermission(android.Manifest.permission.WIFI_UPDATE_COEX_UNSAFE_CHANNELS) public void setCoexUnsafeChannels(@NonNull java.util.Set<android.net.wifi.CoexUnsafeChannel>, int);
    method @RequiresPermission(android.Manifest.permission.WIFI_SET_DEVICE_MOBILITY_STATE) public void setDeviceMobilityState(int);
    method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void setMacRandomizationSettingPasspointEnabled(@NonNull String, boolean);
    method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void setPasspointMeteredOverride(@NonNull String, int);
@@ -507,6 +522,7 @@ package android.net.wifi {
    method @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) public void stopEasyConnectSession();
    method @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_STACK, android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK}) public boolean stopSoftAp();
    method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void stopTemporarilyDisablingAllNonCarrierMergedWifi();
    method @RequiresPermission(android.Manifest.permission.WIFI_ACCESS_COEX_UNSAFE_CHANNELS) public void unregisterCoexCallback(@NonNull android.net.wifi.WifiManager.CoexCallback);
    method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void unregisterNetworkRequestMatchCallback(@NonNull android.net.wifi.WifiManager.NetworkRequestMatchCallback);
    method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void unregisterSoftApCallback(@NonNull android.net.wifi.WifiManager.SoftApCallback);
    method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void unregisterTrafficStateCallback(@NonNull android.net.wifi.WifiManager.TrafficStateCallback);
@@ -520,6 +536,9 @@ package android.net.wifi {
    field public static final int CHANGE_REASON_ADDED = 0; // 0x0
    field public static final int CHANGE_REASON_CONFIG_CHANGE = 2; // 0x2
    field public static final int CHANGE_REASON_REMOVED = 1; // 0x1
    field public static final int COEX_RESTRICTION_SOFTAP = 2; // 0x2
    field public static final int COEX_RESTRICTION_WIFI_AWARE = 4; // 0x4
    field public static final int COEX_RESTRICTION_WIFI_DIRECT = 1; // 0x1
    field public static final String CONFIGURED_NETWORKS_CHANGED_ACTION = "android.net.wifi.CONFIGURED_NETWORKS_CHANGE";
    field public static final int DEVICE_MOBILITY_STATE_HIGH_MVMT = 1; // 0x1
    field public static final int DEVICE_MOBILITY_STATE_LOW_MVMT = 2; // 0x2
@@ -575,6 +594,11 @@ package android.net.wifi {
    method public void onSuccess();
  }

  public abstract static class WifiManager.CoexCallback {
    ctor public WifiManager.CoexCallback();
    method public abstract void onCoexUnsafeChannelsChanged();
  }

  public static interface WifiManager.NetworkRequestMatchCallback {
    method public default void onAbort();
    method public default void onMatch(@NonNull java.util.List<android.net.wifi.ScanResult>);
+176 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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 static android.net.wifi.WifiScanner.WIFI_BAND_24_GHZ;
import static android.net.wifi.WifiScanner.WIFI_BAND_5_GHZ;
import static android.net.wifi.WifiScanner.WIFI_BAND_6_GHZ;

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

import java.util.Objects;

/**
 * Data structure class representing a Wi-Fi channel that would cause interference to/receive
 * interference from the active cellular channels and should be avoided.
 *
 * If {@link #isPowerCapAvailable()} is {@code true}, then a valid power cap value is available
 * through {@link #getPowerCapDbm()} to be used if this channel cannot be avoided. If {@code false},
 * then {@link #getPowerCapDbm()} throws an IllegalStateException and the channel will not need to
 * cap its power.
 *
 * @hide
 */
@SystemApi
public final class CoexUnsafeChannel implements Parcelable {
    private @WifiAnnotations.WifiBandBasic int mBand;
    private int mChannel;
    private boolean mIsPowerCapAvailable = false;
    private int mPowerCapDbm;

    /**
     * Constructor for a CoexUnsafeChannel with no power cap specified.
     * @param band One of {@link WifiAnnotations.WifiBandBasic}
     * @param channel Channel number
     */
    public CoexUnsafeChannel(@WifiAnnotations.WifiBandBasic int band, int channel) {
        mBand = band;
        mChannel = channel;
    }

    /**
     * Constructor for a CoexUnsafeChannel with power cap specified.
     * @param band One of {@link WifiAnnotations.WifiBandBasic}
     * @param channel Channel number
     * @param powerCapDbm Power cap in dBm
     */
    public CoexUnsafeChannel(@WifiAnnotations.WifiBandBasic int band, int channel,
            int powerCapDbm) {
        mBand = band;
        mChannel = channel;
        setPowerCapDbm(powerCapDbm);
    }

    /** Returns the Wi-Fi band of this channel as one of {@link WifiAnnotations.WifiBandBasic} */
    public @WifiAnnotations.WifiBandBasic int getBand() {
        return mBand;
    }

    /** Returns the channel number of this channel. */
    public int getChannel() {
        return mChannel;
    }

    /** Returns {@code true} if {@link #getPowerCapDbm()} is a valid value, else {@code false} */
    public boolean isPowerCapAvailable() {
        return mIsPowerCapAvailable;
    }

    /**
     * Returns the power cap of this channel in dBm. Throws IllegalStateException if
     * {@link #isPowerCapAvailable()} is {@code false}.
     */
    public int getPowerCapDbm() {
        if (!mIsPowerCapAvailable) {
            throw new IllegalStateException("getPowerCapDbm called but power cap is unavailable");
        }
        return mPowerCapDbm;
    }

    /** Set the power cap of this channel. */
    public void setPowerCapDbm(int powerCapDbm) {
        mIsPowerCapAvailable = true;
        mPowerCapDbm = powerCapDbm;
    }

    @Override
    public boolean equals(@Nullable Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        CoexUnsafeChannel that = (CoexUnsafeChannel) o;
        return mBand == that.mBand
                && mChannel == that.mChannel
                && mIsPowerCapAvailable == that.mIsPowerCapAvailable
                && mPowerCapDbm == that.mPowerCapDbm;
    }

    @Override
    public int hashCode() {
        return Objects.hash(mBand, mChannel, mIsPowerCapAvailable, mPowerCapDbm);
    }

    @Override
    public String toString() {
        StringBuilder sj = new StringBuilder("CoexUnsafeChannel{");
        sj.append(mChannel);
        sj.append(", ");
        if (mBand == WIFI_BAND_24_GHZ) {
            sj.append("2.4GHz");
        } else if (mBand == WIFI_BAND_5_GHZ) {
            sj.append("5GHz");
        } else if (mBand == WIFI_BAND_6_GHZ) {
            sj.append("6GHz");
        } else {
            sj.append("UNKNOWN BAND");
        }
        if (mIsPowerCapAvailable) {
            sj.append(", ").append(mPowerCapDbm).append("dBm");
        }
        sj.append('}');
        return sj.toString();
    }

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

    /** Implement the Parcelable interface {@hide} */
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(mBand);
        dest.writeInt(mChannel);
        dest.writeBoolean(mIsPowerCapAvailable);
        if (mIsPowerCapAvailable) {
            dest.writeInt(mPowerCapDbm);
        }
    }

    /** Implement the Parcelable interface */
    public static final @NonNull Creator<CoexUnsafeChannel> CREATOR =
            new Creator<CoexUnsafeChannel>() {
                public CoexUnsafeChannel createFromParcel(Parcel in) {
                    final int band = in.readInt();
                    final int channel = in.readInt();
                    final boolean isPowerCapAvailable = in.readBoolean();
                    if (isPowerCapAvailable) {
                        final int powerCapDbm = in.readInt();
                        return new CoexUnsafeChannel(band, channel, powerCapDbm);
                    }
                    return new CoexUnsafeChannel(band, channel);
                }

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