diff options
Diffstat (limited to 'wifi')
| -rw-r--r-- | wifi/Android.bp | 1 | ||||
| -rw-r--r-- | wifi/TEST_MAPPING | 12 | ||||
| -rw-r--r-- | wifi/api/system-current.txt | 10 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/ITxPacketCountListener.aidl | 28 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/IWifiManager.aidl | 14 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/SoftApCapability.java | 107 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/SoftApConfiguration.java | 99 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/SoftApInfo.java | 56 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/WifiManager.java | 47 | ||||
| -rw-r--r-- | wifi/tests/AndroidManifest.xml | 14 | ||||
| -rw-r--r-- | wifi/tests/src/android/net/wifi/SoftApCapabilityTest.java | 32 | ||||
| -rw-r--r-- | wifi/tests/src/android/net/wifi/SoftApConfigurationTest.java | 38 | ||||
| -rw-r--r-- | wifi/tests/src/android/net/wifi/SoftApInfoTest.java | 4 | ||||
| -rw-r--r-- | wifi/tests/src/android/net/wifi/WifiManagerTest.java | 33 | ||||
| -rw-r--r-- | wifi/tests/src/android/net/wifi/WifiNetworkSuggestionTest.java | 11 |
15 files changed, 386 insertions, 120 deletions
diff --git a/wifi/Android.bp b/wifi/Android.bp index 02616aff2a3f..941ff61b3ba5 100644 --- a/wifi/Android.bp +++ b/wifi/Android.bp @@ -73,7 +73,6 @@ test_access_hidden_api_whitelist = [ "//external/robolectric-shadows:__subpackages__", "//frameworks/base/packages/SettingsLib/tests/integ", "//external/sl4a:__subpackages__", - "//packages/apps/Settings/tests/robotests", // TODO(b/161767237): remove ] // wifi-service needs pre-jarjared version of framework-wifi so it can reference copied utility diff --git a/wifi/TEST_MAPPING b/wifi/TEST_MAPPING new file mode 100644 index 000000000000..fde3a6aa993c --- /dev/null +++ b/wifi/TEST_MAPPING @@ -0,0 +1,12 @@ +{ + "presubmit": [ + { + "name": "CtsWifiTestCases", + "options": [ + { + "exclude-annotation": "android.net.wifi.cts.VirtualDeviceNotSupported" + } + ] + } + ] +} diff --git a/wifi/api/system-current.txt b/wifi/api/system-current.txt index 07793c1eb02a..53c69c47d052 100644 --- a/wifi/api/system-current.txt +++ b/wifi/api/system-current.txt @@ -241,6 +241,7 @@ package android.net.wifi { method public boolean areFeaturesSupported(long); method public int describeContents(); method public int getMaxSupportedClients(); + method @NonNull public int[] getSupportedChannelList(int); method public void writeToParcel(@NonNull android.os.Parcel, int); field @NonNull public static final android.os.Parcelable.Creator<android.net.wifi.SoftApCapability> CREATOR; field public static final long SOFTAP_FEATURE_ACS_OFFLOAD = 1L; // 0x1L @@ -253,6 +254,7 @@ package android.net.wifi { method public int getBand(); method @NonNull public java.util.List<android.net.MacAddress> getBlockedClientList(); method public int getChannel(); + method public int getMacRandomizationSetting(); method public int getMaxNumberOfClients(); method public long getShutdownTimeoutMillis(); method public boolean isAutoShutdownEnabled(); @@ -262,6 +264,8 @@ package android.net.wifi { field public static final int BAND_5GHZ = 2; // 0x2 field public static final int BAND_6GHZ = 4; // 0x4 field public static final int BAND_ANY = 7; // 0x7 + field public static final int RANDOMIZATION_NONE = 0; // 0x0 + field public static final int RANDOMIZATION_PERSISTENT = 1; // 0x1 } public static final class SoftApConfiguration.Builder { @@ -276,6 +280,7 @@ package android.net.wifi { method @NonNull public android.net.wifi.SoftApConfiguration.Builder setChannel(int, int); method @NonNull public android.net.wifi.SoftApConfiguration.Builder setClientControlByUserEnabled(boolean); method @NonNull public android.net.wifi.SoftApConfiguration.Builder setHiddenSsid(boolean); + method @NonNull public android.net.wifi.SoftApConfiguration.Builder setMacRandomizationSetting(int); method @NonNull public android.net.wifi.SoftApConfiguration.Builder setMaxNumberOfClients(@IntRange(from=0) int); method @NonNull public android.net.wifi.SoftApConfiguration.Builder setPassphrase(@Nullable String, int); method @NonNull public android.net.wifi.SoftApConfiguration.Builder setShutdownTimeoutMillis(@IntRange(from=0) long); @@ -285,6 +290,7 @@ package android.net.wifi { public final class SoftApInfo implements android.os.Parcelable { method public int describeContents(); method public int getBandwidth(); + method @Nullable public android.net.MacAddress getBssid(); method public int getFrequency(); method public void writeToParcel(@NonNull android.os.Parcel, int); field public static final int CHANNEL_WIDTH_160MHZ = 6; // 0x6 @@ -436,7 +442,7 @@ package android.net.wifi { method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) public java.util.Map<android.net.wifi.hotspot2.OsuProvider,android.net.wifi.hotspot2.PasspointConfiguration> getMatchingPasspointConfigsForOsuProviders(@NonNull java.util.Set<android.net.wifi.hotspot2.OsuProvider>); method @NonNull @RequiresPermission(allOf={android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.ACCESS_WIFI_STATE}) public java.util.Map<android.net.wifi.WifiNetworkSuggestion,java.util.List<android.net.wifi.ScanResult>> getMatchingScanResults(@NonNull java.util.List<android.net.wifi.WifiNetworkSuggestion>, @Nullable java.util.List<android.net.wifi.ScanResult>); method @RequiresPermission(allOf={android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.ACCESS_WIFI_STATE, android.Manifest.permission.READ_WIFI_CREDENTIAL}) public java.util.List<android.net.wifi.WifiConfiguration> getPrivilegedConfiguredNetworks(); - method @NonNull @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public android.net.wifi.SoftApConfiguration getSoftApConfiguration(); + method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.OVERRIDE_WIFI_CONFIG}) public android.net.wifi.SoftApConfiguration getSoftApConfiguration(); method @RequiresPermission(android.Manifest.permission.ACCESS_WIFI_STATE) public void getWifiActivityEnergyInfoAsync(@NonNull java.util.concurrent.Executor, @NonNull android.net.wifi.WifiManager.OnWifiActivityEnergyInfoListener); method @Deprecated @Nullable @RequiresPermission(android.Manifest.permission.ACCESS_WIFI_STATE) public android.net.wifi.WifiConfiguration getWifiApConfiguration(); method @RequiresPermission(android.Manifest.permission.ACCESS_WIFI_STATE) public int getWifiApState(); @@ -464,7 +470,7 @@ package android.net.wifi { method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void setPasspointMeteredOverride(@NonNull String, int); method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void setScanAlwaysAvailable(boolean); method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void setScanThrottleEnabled(boolean); - method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public boolean setSoftApConfiguration(@NonNull android.net.wifi.SoftApConfiguration); + method @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.OVERRIDE_WIFI_CONFIG}) public boolean setSoftApConfiguration(@NonNull android.net.wifi.SoftApConfiguration); method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void setVerboseLoggingEnabled(boolean); method @Deprecated @RequiresPermission(android.Manifest.permission.CHANGE_WIFI_STATE) public boolean setWifiApConfiguration(android.net.wifi.WifiConfiguration); method @RequiresPermission(android.Manifest.permission.WIFI_UPDATE_USABILITY_STATS_SCORE) public boolean setWifiConnectedNetworkScorer(@NonNull java.util.concurrent.Executor, @NonNull android.net.wifi.WifiManager.WifiConnectedNetworkScorer); diff --git a/wifi/java/android/net/wifi/ITxPacketCountListener.aidl b/wifi/java/android/net/wifi/ITxPacketCountListener.aidl deleted file mode 100644 index 9105bd0265cb..000000000000 --- a/wifi/java/android/net/wifi/ITxPacketCountListener.aidl +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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; - -/** - * Interface for tx packet counter callback. - * @deprecated no longer used, remove once removed from BaseWifiService - * @hide - */ -oneway interface ITxPacketCountListener -{ - void onSuccess(int count); - void onFailure(int reason); -} diff --git a/wifi/java/android/net/wifi/IWifiManager.aidl b/wifi/java/android/net/wifi/IWifiManager.aidl index 5063ad66e446..e4937892e2f7 100644 --- a/wifi/java/android/net/wifi/IWifiManager.aidl +++ b/wifi/java/android/net/wifi/IWifiManager.aidl @@ -80,8 +80,6 @@ interface IWifiManager int matchProviderWithCurrentNetwork(String fqdn); - void deauthenticateNetwork(long holdoff, boolean ess); - boolean removeNetwork(int netId, String packageName); boolean enableNetwork(int netId, boolean disableOthers, String packageName); @@ -124,7 +122,7 @@ interface IWifiManager DhcpInfo getDhcpInfo(); - void setScanAlwaysAvailable(boolean isAvailable); + void setScanAlwaysAvailable(boolean isAvailable, String packageName); boolean isScanAlwaysAvailable(); @@ -144,9 +142,9 @@ interface IWifiManager void updateInterfaceIpState(String ifaceName, int mode); - boolean startSoftAp(in WifiConfiguration wifiConfig); + boolean startSoftAp(in WifiConfiguration wifiConfig, String packageName); - boolean startTetheredHotspot(in SoftApConfiguration softApConfig); + boolean startTetheredHotspot(in SoftApConfiguration softApConfig, String packageName); boolean stopSoftAp(); @@ -239,11 +237,11 @@ interface IWifiManager void updateWifiUsabilityScore(int seqNum, int score, int predictionHorizonSec); - oneway void connect(in WifiConfiguration config, int netId, in IBinder binder, in IActionListener listener, int callbackIdentifier); + oneway void connect(in WifiConfiguration config, int netId, in IActionListener listener); - oneway void save(in WifiConfiguration config, in IBinder binder, in IActionListener listener, int callbackIdentifier); + oneway void save(in WifiConfiguration config, in IActionListener listener); - oneway void forget(int netId, in IBinder binder, in IActionListener listener, int callbackIdentifier); + oneway void forget(int netId, in IActionListener listener); void registerScanResultsCallback(in IScanResultsCallback callback); diff --git a/wifi/java/android/net/wifi/SoftApCapability.java b/wifi/java/android/net/wifi/SoftApCapability.java index dcb57ecc933f..99c4eac7977b 100644 --- a/wifi/java/android/net/wifi/SoftApCapability.java +++ b/wifi/java/android/net/wifi/SoftApCapability.java @@ -20,11 +20,14 @@ import android.annotation.LongDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemApi; +import android.net.wifi.SoftApConfiguration.BandType; +import android.os.Build; import android.os.Parcel; import android.os.Parcelable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.util.Arrays; import java.util.Objects; /** @@ -36,6 +39,8 @@ import java.util.Objects; @SystemApi public final class SoftApCapability implements Parcelable { + private static final String TAG = "SoftApCapability"; + private static final int[] EMPTY_INT_ARRAY = new int[0]; /** * Support for automatic channel selection in driver (ACS). * Driver will auto select best channel based on interference to optimize performance. @@ -83,6 +88,21 @@ public final class SoftApCapability implements Parcelable { private int mMaximumSupportedClientNumber; /** + * A list storing supported 2.4G channels. + */ + private int[] mSupportedChannelListIn24g = EMPTY_INT_ARRAY; + + /** + * A list storing supported 5G channels. + */ + private int[] mSupportedChannelListIn5g = EMPTY_INT_ARRAY; + + /** + * A list storing supported 6G channels. + */ + private int[] mSupportedChannelListIn6g = EMPTY_INT_ARRAY; + + /** * Get the maximum supported client numbers which AP resides on. */ public int getMaxSupportedClients() { @@ -111,12 +131,76 @@ public final class SoftApCapability implements Parcelable { } /** + * Set supported channel list in target band type. + * + * @param band One of the following band types: + * {@link SoftApConfiguation#BAND_2GHZ}, {@link SoftApConfiguation#BAND_5GHZ} or + * {@link SoftApConfiguation#BAND_6GHZ}. + * @param supportedChannelList supported channel list in target band + * @return true if band and supportedChannelList are valid, otherwise false. + * + * @throws IllegalArgumentException when band type is invalid. + * @hide + */ + public boolean setSupportedChannelList(@BandType int band, + @Nullable int[] supportedChannelList) { + if (supportedChannelList == null) return false; + switch (band) { + case SoftApConfiguration.BAND_2GHZ: + mSupportedChannelListIn24g = supportedChannelList; + break; + case SoftApConfiguration.BAND_5GHZ: + mSupportedChannelListIn5g = supportedChannelList; + break; + case SoftApConfiguration.BAND_6GHZ: + mSupportedChannelListIn6g = supportedChannelList; + break; + default: + throw new IllegalArgumentException("Invalid band: " + band); + } + return true; + } + + /** + * Returns a list of the supported channels in the given band. + * The result depends on the on the country code that has been set. + * Can be used to set the channel of the AP with the + * {@link SoftapConfiguration.Builder#setChannel(int, int)} API. + * + * @param band One of the following band types: + * {@link SoftApConfiguation#BAND_2GHZ}, {@link SoftApConfiguation#BAND_5GHZ} or + * {@link SoftApConfiguation#BAND_6GHZ}. + * @return List of supported channels for the band. + * + * @throws IllegalArgumentException when band type is invalid. + */ + @NonNull + public int[] getSupportedChannelList(@BandType int band) { + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) { + throw new UnsupportedOperationException(); + } + switch (band) { + case SoftApConfiguration.BAND_2GHZ: + return mSupportedChannelListIn24g; + case SoftApConfiguration.BAND_5GHZ: + return mSupportedChannelListIn5g; + case SoftApConfiguration.BAND_6GHZ: + return mSupportedChannelListIn6g; + default: + throw new IllegalArgumentException("Invalid band: " + band); + } + } + + /** * @hide */ public SoftApCapability(@Nullable SoftApCapability source) { if (source != null) { mSupportedFeatures = source.mSupportedFeatures; mMaximumSupportedClientNumber = source.mMaximumSupportedClientNumber; + mSupportedChannelListIn24g = source.mSupportedChannelListIn24g; + mSupportedChannelListIn5g = source.mSupportedChannelListIn5g; + mSupportedChannelListIn6g = source.mSupportedChannelListIn6g; } } @@ -144,15 +228,20 @@ public final class SoftApCapability implements Parcelable { public void writeToParcel(@NonNull Parcel dest, int flags) { dest.writeLong(mSupportedFeatures); dest.writeInt(mMaximumSupportedClientNumber); + dest.writeIntArray(mSupportedChannelListIn24g); + dest.writeIntArray(mSupportedChannelListIn5g); + dest.writeIntArray(mSupportedChannelListIn6g); } @NonNull /** Implement the Parcelable interface */ public static final Creator<SoftApCapability> CREATOR = new Creator<SoftApCapability>() { public SoftApCapability createFromParcel(Parcel in) { - long supportedFeatures = in.readLong(); - SoftApCapability capability = new SoftApCapability(supportedFeatures); + SoftApCapability capability = new SoftApCapability(in.readLong()); capability.mMaximumSupportedClientNumber = in.readInt(); + capability.setSupportedChannelList(SoftApConfiguration.BAND_2GHZ, in.createIntArray()); + capability.setSupportedChannelList(SoftApConfiguration.BAND_5GHZ, in.createIntArray()); + capability.setSupportedChannelList(SoftApConfiguration.BAND_6GHZ, in.createIntArray()); return capability; } @@ -167,6 +256,10 @@ public final class SoftApCapability implements Parcelable { StringBuilder sbuf = new StringBuilder(); sbuf.append("SupportedFeatures=").append(mSupportedFeatures); sbuf.append("MaximumSupportedClientNumber=").append(mMaximumSupportedClientNumber); + sbuf.append("SupportedChannelListIn24g") + .append(Arrays.toString(mSupportedChannelListIn24g)); + sbuf.append("SupportedChannelListIn5g").append(Arrays.toString(mSupportedChannelListIn5g)); + sbuf.append("SupportedChannelListIn6g").append(Arrays.toString(mSupportedChannelListIn6g)); return sbuf.toString(); } @@ -176,11 +269,17 @@ public final class SoftApCapability implements Parcelable { if (!(o instanceof SoftApCapability)) return false; SoftApCapability capability = (SoftApCapability) o; return mSupportedFeatures == capability.mSupportedFeatures - && mMaximumSupportedClientNumber == capability.mMaximumSupportedClientNumber; + && mMaximumSupportedClientNumber == capability.mMaximumSupportedClientNumber + && Arrays.equals(mSupportedChannelListIn24g, capability.mSupportedChannelListIn24g) + && Arrays.equals(mSupportedChannelListIn5g, capability.mSupportedChannelListIn5g) + && Arrays.equals(mSupportedChannelListIn6g, capability.mSupportedChannelListIn6g); } @Override public int hashCode() { - return Objects.hash(mSupportedFeatures, mMaximumSupportedClientNumber); + return Objects.hash(mSupportedFeatures, mMaximumSupportedClientNumber, + Arrays.hashCode(mSupportedChannelListIn24g), + Arrays.hashCode(mSupportedChannelListIn5g), + Arrays.hashCode(mSupportedChannelListIn6g)); } } diff --git a/wifi/java/android/net/wifi/SoftApConfiguration.java b/wifi/java/android/net/wifi/SoftApConfiguration.java index a5e76e6c92ee..f919ea4c4797 100644 --- a/wifi/java/android/net/wifi/SoftApConfiguration.java +++ b/wifi/java/android/net/wifi/SoftApConfiguration.java @@ -22,6 +22,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemApi; import android.net.MacAddress; +import android.os.Build; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; @@ -217,6 +218,34 @@ public final class SoftApConfiguration implements Parcelable { */ private final long mShutdownTimeoutMillis; + /** @hide */ + @Retention(RetentionPolicy.SOURCE) + @IntDef(prefix = {"RANDOMIZATION_"}, value = { + RANDOMIZATION_NONE, + RANDOMIZATION_PERSISTENT}) + public @interface MacRandomizationSetting {} + + /** + * Use factory MAC as BSSID for the AP + * @hide + */ + @SystemApi + public static final int RANDOMIZATION_NONE = 0; + /** + * Generate a randomized MAC as BSSID for the AP + * @hide + */ + @SystemApi + public static final int RANDOMIZATION_PERSISTENT = 1; + + /** + * Level of MAC randomization for the AP BSSID. + * @hide + */ + @MacRandomizationSetting + private int mMacRandomizationSetting; + + /** * THe definition of security type OPEN. */ @@ -252,7 +281,8 @@ public final class SoftApConfiguration implements Parcelable { @Nullable String passphrase, boolean hiddenSsid, @BandType int band, int channel, @SecurityType int securityType, int maxNumberOfClients, boolean shutdownTimeoutEnabled, long shutdownTimeoutMillis, boolean clientControlByUser, - @NonNull List<MacAddress> blockedList, @NonNull List<MacAddress> allowedList) { + @NonNull List<MacAddress> blockedList, @NonNull List<MacAddress> allowedList, + int macRandomizationSetting) { mSsid = ssid; mBssid = bssid; mPassphrase = passphrase; @@ -266,6 +296,7 @@ public final class SoftApConfiguration implements Parcelable { mClientControlByUser = clientControlByUser; mBlockedClientList = new ArrayList<>(blockedList); mAllowedClientList = new ArrayList<>(allowedList); + mMacRandomizationSetting = macRandomizationSetting; } @Override @@ -289,7 +320,8 @@ public final class SoftApConfiguration implements Parcelable { && mShutdownTimeoutMillis == other.mShutdownTimeoutMillis && mClientControlByUser == other.mClientControlByUser && Objects.equals(mBlockedClientList, other.mBlockedClientList) - && Objects.equals(mAllowedClientList, other.mAllowedClientList); + && Objects.equals(mAllowedClientList, other.mAllowedClientList) + && mMacRandomizationSetting == other.mMacRandomizationSetting; } @Override @@ -297,7 +329,7 @@ public final class SoftApConfiguration implements Parcelable { return Objects.hash(mSsid, mBssid, mPassphrase, mHiddenSsid, mBand, mChannel, mSecurityType, mMaxNumberOfClients, mAutoShutdownEnabled, mShutdownTimeoutMillis, mClientControlByUser, mBlockedClientList, - mAllowedClientList); + mAllowedClientList, mMacRandomizationSetting); } @Override @@ -317,6 +349,7 @@ public final class SoftApConfiguration implements Parcelable { sbuf.append(" \n ClientControlByUser=").append(mClientControlByUser); sbuf.append(" \n BlockedClientList=").append(mBlockedClientList); sbuf.append(" \n AllowedClientList=").append(mAllowedClientList); + sbuf.append(" \n MacRandomizationSetting=").append(mMacRandomizationSetting); return sbuf.toString(); } @@ -335,6 +368,7 @@ public final class SoftApConfiguration implements Parcelable { dest.writeBoolean(mClientControlByUser); dest.writeTypedList(mBlockedClientList); dest.writeTypedList(mAllowedClientList); + dest.writeInt(mMacRandomizationSetting); } @Override @@ -352,7 +386,7 @@ public final class SoftApConfiguration implements Parcelable { in.readString(), in.readBoolean(), in.readInt(), in.readInt(), in.readInt(), in.readInt(), in.readBoolean(), in.readLong(), in.readBoolean(), in.createTypedArrayList(MacAddress.CREATOR), - in.createTypedArrayList(MacAddress.CREATOR)); + in.createTypedArrayList(MacAddress.CREATOR), in.readInt()); } @Override @@ -509,6 +543,21 @@ public final class SoftApConfiguration implements Parcelable { } /** + * Returns the level of MAC randomization for the AP BSSID. + * {@link Builder#setMacRandomizationSetting(int)}. + * + * @hide + */ + @SystemApi + @MacRandomizationSetting + public int getMacRandomizationSetting() { + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) { + throw new UnsupportedOperationException(); + } + return mMacRandomizationSetting; + } + + /** * Returns a {@link WifiConfiguration} representation of this {@link SoftApConfiguration}. * Note that SoftApConfiguration may contain configuration which is cannot be represented * by the legacy WifiConfiguration, in such cases a null will be returned. @@ -584,6 +633,7 @@ public final class SoftApConfiguration implements Parcelable { private boolean mClientControlByUser; private List<MacAddress> mBlockedClientList; private List<MacAddress> mAllowedClientList; + private int mMacRandomizationSetting; /** * Constructs a Builder with default values (see {@link Builder}). @@ -602,6 +652,7 @@ public final class SoftApConfiguration implements Parcelable { mClientControlByUser = false; mBlockedClientList = new ArrayList<>(); mAllowedClientList = new ArrayList<>(); + mMacRandomizationSetting = RANDOMIZATION_PERSISTENT; } /** @@ -623,6 +674,7 @@ public final class SoftApConfiguration implements Parcelable { mClientControlByUser = other.mClientControlByUser; mBlockedClientList = new ArrayList<>(other.mBlockedClientList); mAllowedClientList = new ArrayList<>(other.mAllowedClientList); + mMacRandomizationSetting = other.mMacRandomizationSetting; } /** @@ -640,7 +692,7 @@ public final class SoftApConfiguration implements Parcelable { return new SoftApConfiguration(mSsid, mBssid, mPassphrase, mHiddenSsid, mBand, mChannel, mSecurityType, mMaxNumberOfClients, mAutoShutdownEnabled, mShutdownTimeoutMillis, mClientControlByUser, - mBlockedClientList, mAllowedClientList); + mBlockedClientList, mAllowedClientList, mMacRandomizationSetting); } /** @@ -672,14 +724,17 @@ public final class SoftApConfiguration implements Parcelable { * @param bssid BSSID, or null to have the BSSID chosen by the framework. The caller is * responsible for avoiding collisions. * @return Builder for chaining. - * @throws IllegalArgumentException when the given BSSID is the all-zero or broadcast MAC - * address. + * @throws IllegalArgumentException when the given BSSID is the all-zero + * , multicast or broadcast MAC address. */ @NonNull public Builder setBssid(@Nullable MacAddress bssid) { if (bssid != null) { Preconditions.checkArgument(!bssid.equals(WifiManager.ALL_ZEROS_MAC_ADDRESS)); - Preconditions.checkArgument(!bssid.equals(MacAddress.BROADCAST_ADDRESS)); + if (bssid.getAddressType() != MacAddress.TYPE_UNICAST) { + throw new IllegalArgumentException("bssid doesn't support " + + "multicast or broadcast mac address"); + } } mBssid = bssid; return this; @@ -769,6 +824,9 @@ public final class SoftApConfiguration implements Parcelable { * Specifies the channel and associated band for the AP. * * The channel which AP resides on. Valid channels are country dependent. + * The {@link SoftApCapability#getSupportedChannelList(int)} can be used to obtain + * valid channels. + * * <p> * The default for the channel is a the special value 0 to have the framework * auto-select a valid channel from the band configured with @@ -968,5 +1026,30 @@ public final class SoftApConfiguration implements Parcelable { mBlockedClientList = new ArrayList<>(blockedClientList); return this; } + + /** + * Specifies the level of MAC randomization for the AP BSSID. + * The Soft AP BSSID will be randomized only if the BSSID isn't set + * {@link #setBssid(MacAddress)} and this method is either uncalled + * or called with {@link #RANDOMIZATION_PERSISTENT}. + * + * <p> + * <li>If not set, defaults to {@link #RANDOMIZATION_PERSISTENT}</li> + * + * @param macRandomizationSetting One of the following setting:. + * {@link #RANDOMIZATION_NONE} or {@link #RANDOMIZATION_PERSISTENT}. + * @return Builder for chaining. + * + * @see #setBssid(MacAddress) + */ + @NonNull + public Builder setMacRandomizationSetting( + @MacRandomizationSetting int macRandomizationSetting) { + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) { + throw new UnsupportedOperationException(); + } + mMacRandomizationSetting = macRandomizationSetting; + return this; + } } } diff --git a/wifi/java/android/net/wifi/SoftApInfo.java b/wifi/java/android/net/wifi/SoftApInfo.java index 24ed8effe471..4791275cdce5 100644 --- a/wifi/java/android/net/wifi/SoftApInfo.java +++ b/wifi/java/android/net/wifi/SoftApInfo.java @@ -19,9 +19,13 @@ package android.net.wifi; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemApi; +import android.net.MacAddress; +import android.os.Build; import android.os.Parcel; import android.os.Parcelable; +import com.android.internal.util.Preconditions; + import java.util.Objects; /** @@ -90,6 +94,10 @@ public final class SoftApInfo implements Parcelable { @WifiAnnotations.Bandwidth private int mBandwidth = CHANNEL_WIDTH_INVALID; + /** The MAC Address which AP resides on. */ + @Nullable + private MacAddress mBssid; + /** * Get the frequency which AP resides on. */ @@ -126,12 +134,42 @@ public final class SoftApInfo implements Parcelable { } /** + * Get the MAC address (BSSID) of the AP. Null when AP disabled. + */ + @Nullable + public MacAddress getBssid() { + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) { + throw new UnsupportedOperationException(); + } + return mBssid; + } + + /** + * Set the MAC address which AP resides on. + * <p> + * <li>If not set, defaults to null.</li> + * @param bssid BSSID, The caller is responsible for avoiding collisions. + * @throws IllegalArgumentException when the given BSSID is the all-zero or broadcast MAC + * address. + * + * @hide + */ + public void setBssid(@Nullable MacAddress bssid) { + if (bssid != null) { + Preconditions.checkArgument(!bssid.equals(WifiManager.ALL_ZEROS_MAC_ADDRESS)); + Preconditions.checkArgument(!bssid.equals(MacAddress.BROADCAST_ADDRESS)); + } + mBssid = bssid; + } + + /** * @hide */ public SoftApInfo(@Nullable SoftApInfo source) { if (source != null) { mFrequency = source.mFrequency; mBandwidth = source.mBandwidth; + mBssid = source.mBssid; } } @@ -152,6 +190,7 @@ public final class SoftApInfo implements Parcelable { public void writeToParcel(@NonNull Parcel dest, int flags) { dest.writeInt(mFrequency); dest.writeInt(mBandwidth); + dest.writeParcelable(mBssid, flags); } @NonNull @@ -161,6 +200,7 @@ public final class SoftApInfo implements Parcelable { SoftApInfo info = new SoftApInfo(); info.mFrequency = in.readInt(); info.mBandwidth = in.readInt(); + info.mBssid = in.readParcelable(MacAddress.class.getClassLoader()); return info; } @@ -172,10 +212,13 @@ public final class SoftApInfo implements Parcelable { @NonNull @Override public String toString() { - return "SoftApInfo{" - + "bandwidth= " + mBandwidth - + ",frequency= " + mFrequency - + '}'; + StringBuilder sbuf = new StringBuilder(); + sbuf.append("SoftApInfo{"); + sbuf.append("bandwidth= ").append(mBandwidth); + sbuf.append(",frequency= ").append(mFrequency); + if (mBssid != null) sbuf.append(",bssid=").append(mBssid.toString()); + sbuf.append("}"); + return sbuf.toString(); } @Override @@ -184,11 +227,12 @@ public final class SoftApInfo implements Parcelable { if (!(o instanceof SoftApInfo)) return false; SoftApInfo softApInfo = (SoftApInfo) o; return mFrequency == softApInfo.mFrequency - && mBandwidth == softApInfo.mBandwidth; + && mBandwidth == softApInfo.mBandwidth + && Objects.equals(mBssid, softApInfo.mBssid); } @Override public int hashCode() { - return Objects.hash(mFrequency, mBandwidth); + return Objects.hash(mFrequency, mBandwidth, mBssid); } } diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java index fb6af5b550b0..b28b902910bf 100644 --- a/wifi/java/android/net/wifi/WifiManager.java +++ b/wifi/java/android/net/wifi/WifiManager.java @@ -2119,22 +2119,6 @@ public class WifiManager { } /** - * Deauthenticate and set the re-authentication hold off time for the current network - * @param holdoff hold off time in milliseconds - * @param ess set if the hold off pertains to an ESS rather than a BSS - * @hide - * - * TODO (140167680): This needs to be removed, the implementation is empty! - */ - public void deauthenticateNetwork(long holdoff, boolean ess) { - try { - mService.deauthenticateNetwork(holdoff, ess); - } catch (RemoteException e) { - throw e.rethrowFromSystemServer(); - } - } - - /** * Remove the specified network from the list of configured networks. * This may result in the asynchronous delivery of state change * events. @@ -2818,7 +2802,7 @@ public class WifiManager { @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void setScanAlwaysAvailable(boolean isAvailable) { try { - mService.setScanAlwaysAvailable(isAvailable); + mService.setScanAlwaysAvailable(isAvailable, mContext.getOpPackageName()); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -3051,7 +3035,7 @@ public class WifiManager { }) public boolean startSoftAp(@Nullable WifiConfiguration wifiConfig) { try { - return mService.startSoftAp(wifiConfig); + return mService.startSoftAp(wifiConfig, mContext.getOpPackageName()); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -3075,7 +3059,7 @@ public class WifiManager { }) public boolean startTetheredHotspot(@Nullable SoftApConfiguration softApConfig) { try { - return mService.startTetheredHotspot(softApConfig); + return mService.startTetheredHotspot(softApConfig, mContext.getOpPackageName()); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -3392,7 +3376,10 @@ public class WifiManager { */ @NonNull @SystemApi - @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) + @RequiresPermission(anyOf = { + android.Manifest.permission.NETWORK_SETTINGS, + android.Manifest.permission.OVERRIDE_WIFI_CONFIG + }) public SoftApConfiguration getSoftApConfiguration() { try { return mService.getSoftApConfiguration(); @@ -3440,7 +3427,10 @@ public class WifiManager { * @hide */ @SystemApi - @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) + @RequiresPermission(anyOf = { + android.Manifest.permission.NETWORK_SETTINGS, + android.Manifest.permission.OVERRIDE_WIFI_CONFIG + }) public boolean setSoftApConfiguration(@NonNull SoftApConfiguration softApConfig) { try { return mService.setSoftApConfiguration( @@ -4144,14 +4134,11 @@ public class WifiManager { private void connectInternal(@Nullable WifiConfiguration config, int networkId, @Nullable ActionListener listener) { ActionListenerProxy listenerProxy = null; - Binder binder = null; if (listener != null) { listenerProxy = new ActionListenerProxy("connect", mLooper, listener); - binder = new Binder(); } try { - mService.connect(config, networkId, binder, listenerProxy, - listener == null ? 0 : listener.hashCode()); + mService.connect(config, networkId, listenerProxy); } catch (RemoteException e) { if (listenerProxy != null) listenerProxy.onFailure(ERROR); } catch (SecurityException e) { @@ -4242,14 +4229,11 @@ public class WifiManager { public void save(@NonNull WifiConfiguration config, @Nullable ActionListener listener) { if (config == null) throw new IllegalArgumentException("config cannot be null"); ActionListenerProxy listenerProxy = null; - Binder binder = null; if (listener != null) { listenerProxy = new ActionListenerProxy("save", mLooper, listener); - binder = new Binder(); } try { - mService.save(config, binder, listenerProxy, - listener == null ? 0 : listener.hashCode()); + mService.save(config, listenerProxy); } catch (RemoteException e) { if (listenerProxy != null) listenerProxy.onFailure(ERROR); } catch (SecurityException e) { @@ -4279,14 +4263,11 @@ public class WifiManager { public void forget(int netId, @Nullable ActionListener listener) { if (netId < 0) throw new IllegalArgumentException("Network id cannot be negative"); ActionListenerProxy listenerProxy = null; - Binder binder = null; if (listener != null) { listenerProxy = new ActionListenerProxy("forget", mLooper, listener); - binder = new Binder(); } try { - mService.forget(netId, binder, listenerProxy, - listener == null ? 0 : listener.hashCode()); + mService.forget(netId, listenerProxy); } catch (RemoteException e) { if (listenerProxy != null) listenerProxy.onFailure(ERROR); } catch (SecurityException e) { diff --git a/wifi/tests/AndroidManifest.xml b/wifi/tests/AndroidManifest.xml index b6c38bcf5a72..8fcf78fc4d84 100644 --- a/wifi/tests/AndroidManifest.xml +++ b/wifi/tests/AndroidManifest.xml @@ -1,5 +1,4 @@ <?xml version="1.0" encoding="utf-8"?> - <!-- ~ Copyright (C) 2016 The Android Open Source Project ~ @@ -17,22 +16,23 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="android.net.wifi.test"> + package="android.net.wifi.test"> <application> - <uses-library android:name="android.test.runner" /> + <uses-library android:name="android.test.runner"/> <activity android:label="WifiTestDummyLabel" - android:name="WifiTestDummyName"> + android:name="WifiTestDummyName" + android:exported="true"> <intent-filter> - <action android:name="android.intent.action.MAIN" /> + <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application> <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner" - android:targetPackage="android.net.wifi.test" - android:label="Frameworks Wifi API Tests"> + android:targetPackage="android.net.wifi.test" + android:label="Frameworks Wifi API Tests"> </instrumentation> </manifest> diff --git a/wifi/tests/src/android/net/wifi/SoftApCapabilityTest.java b/wifi/tests/src/android/net/wifi/SoftApCapabilityTest.java index 73b501a4d8f2..b9c640cc3980 100644 --- a/wifi/tests/src/android/net/wifi/SoftApCapabilityTest.java +++ b/wifi/tests/src/android/net/wifi/SoftApCapabilityTest.java @@ -16,6 +16,7 @@ package android.net.wifi; +import android.os.Build; import android.os.Parcel; import static org.junit.Assert.assertEquals; @@ -37,8 +38,12 @@ public class SoftApCapabilityTest { public void testCopyOperator() throws Exception { long testSoftApFeature = SoftApCapability.SOFTAP_FEATURE_CLIENT_FORCE_DISCONNECT | SoftApCapability.SOFTAP_FEATURE_ACS_OFFLOAD; + int[] testSupported2Glist = {1, 2, 3, 4}; + int[] testSupported5Glist = {36, 149}; SoftApCapability capability = new SoftApCapability(testSoftApFeature); capability.setMaxSupportedClients(10); + capability.setSupportedChannelList(SoftApConfiguration.BAND_2GHZ, testSupported2Glist); + capability.setSupportedChannelList(SoftApConfiguration.BAND_5GHZ, testSupported5Glist); SoftApCapability copiedCapability = new SoftApCapability(capability); @@ -55,6 +60,11 @@ public class SoftApCapabilityTest { | SoftApCapability.SOFTAP_FEATURE_ACS_OFFLOAD; SoftApCapability capability = new SoftApCapability(testSoftApFeature); capability.setMaxSupportedClients(10); + int[] testSupported2Glist = {1, 2, 3, 4}; + int[] testSupported5Glist = {36, 149}; + + capability.setSupportedChannelList(SoftApConfiguration.BAND_2GHZ, testSupported2Glist); + capability.setSupportedChannelList(SoftApConfiguration.BAND_5GHZ, testSupported5Glist); Parcel parcelW = Parcel.obtain(); capability.writeToParcel(parcelW, 0); @@ -70,4 +80,26 @@ public class SoftApCapabilityTest { assertEquals(capability.hashCode(), fromParcel.hashCode()); } + @Test(expected = IllegalArgumentException.class) + public void testSetSupportedChannelListWithInvalidBand() { + long testSoftApFeature = SoftApCapability.SOFTAP_FEATURE_CLIENT_FORCE_DISCONNECT + | SoftApCapability.SOFTAP_FEATURE_ACS_OFFLOAD; + SoftApCapability capability = new SoftApCapability(testSoftApFeature); + capability.setSupportedChannelList( + SoftApConfiguration.BAND_2GHZ | SoftApConfiguration.BAND_5GHZ, new int[0]); + + } + + @Test(expected = IllegalArgumentException.class) + public void testGetSupportedChannelListWithInvalidBand() { + long testSoftApFeature = SoftApCapability.SOFTAP_FEATURE_CLIENT_FORCE_DISCONNECT + | SoftApCapability.SOFTAP_FEATURE_ACS_OFFLOAD; + SoftApCapability capability = new SoftApCapability(testSoftApFeature); + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.R) { + capability.getSupportedChannelList( + SoftApConfiguration.BAND_2GHZ | SoftApConfiguration.BAND_5GHZ); + } else { + throw new IllegalArgumentException("API doesn't support in current SDK version"); + } + } } diff --git a/wifi/tests/src/android/net/wifi/SoftApConfigurationTest.java b/wifi/tests/src/android/net/wifi/SoftApConfigurationTest.java index 1a4427034756..c2d0d6d81e84 100644 --- a/wifi/tests/src/android/net/wifi/SoftApConfigurationTest.java +++ b/wifi/tests/src/android/net/wifi/SoftApConfigurationTest.java @@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertNull; import android.net.MacAddress; +import android.os.Build; import android.os.Parcel; import androidx.test.filters.SmallTest; @@ -34,6 +35,7 @@ import java.util.Random; @SmallTest public class SoftApConfigurationTest { private static final String TEST_CHAR_SET_AS_STRING = "abcdefghijklmnopqrstuvwxyz0123456789"; + private static final String TEST_BSSID = "aa:22:33:aa:bb:cc"; private SoftApConfiguration parcelUnparcel(SoftApConfiguration configIn) { Parcel parcel = Parcel.obtain(); @@ -66,18 +68,23 @@ public class SoftApConfigurationTest { @Test public void testBasicSettings() { + MacAddress testBssid = MacAddress.fromString(TEST_BSSID); SoftApConfiguration original = new SoftApConfiguration.Builder() .setSsid("ssid") - .setBssid(MacAddress.fromString("11:22:33:44:55:66")) + .setBssid(testBssid) .build(); assertThat(original.getSsid()).isEqualTo("ssid"); - assertThat(original.getBssid()).isEqualTo(MacAddress.fromString("11:22:33:44:55:66")); + assertThat(original.getBssid()).isEqualTo(testBssid); assertThat(original.getPassphrase()).isNull(); assertThat(original.getSecurityType()).isEqualTo(SoftApConfiguration.SECURITY_TYPE_OPEN); assertThat(original.getBand()).isEqualTo(SoftApConfiguration.BAND_2GHZ); assertThat(original.getChannel()).isEqualTo(0); assertThat(original.isHiddenSsid()).isEqualTo(false); assertThat(original.getMaxNumberOfClients()).isEqualTo(0); + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.R) { + assertThat(original.getMacRandomizationSetting()) + .isEqualTo(SoftApConfiguration.RANDOMIZATION_PERSISTENT); + } SoftApConfiguration unparceled = parcelUnparcel(original); assertThat(unparceled).isNotSameAs(original); @@ -120,7 +127,7 @@ public class SoftApConfigurationTest { List<MacAddress> testAllowedClientList = new ArrayList<>(); testBlockedClientList.add(MacAddress.fromString("11:22:33:44:55:66")); testAllowedClientList.add(MacAddress.fromString("aa:bb:cc:dd:ee:ff")); - SoftApConfiguration original = new SoftApConfiguration.Builder() + SoftApConfiguration.Builder originalBuilder = new SoftApConfiguration.Builder() .setPassphrase("secretsecret", SoftApConfiguration.SECURITY_TYPE_WPA2_PSK) .setChannel(149, SoftApConfiguration.BAND_5GHZ) .setHiddenSsid(true) @@ -129,8 +136,11 @@ public class SoftApConfigurationTest { .setShutdownTimeoutMillis(500000) .setClientControlByUserEnabled(true) .setBlockedClientList(testBlockedClientList) - .setAllowedClientList(testAllowedClientList) - .build(); + .setAllowedClientList(testAllowedClientList); + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.R) { + originalBuilder.setMacRandomizationSetting(SoftApConfiguration.RANDOMIZATION_NONE); + } + SoftApConfiguration original = originalBuilder.build(); assertThat(original.getPassphrase()).isEqualTo("secretsecret"); assertThat(original.getSecurityType()).isEqualTo( SoftApConfiguration.SECURITY_TYPE_WPA2_PSK); @@ -143,6 +153,10 @@ public class SoftApConfigurationTest { assertThat(original.isClientControlByUserEnabled()).isEqualTo(true); assertThat(original.getBlockedClientList()).isEqualTo(testBlockedClientList); assertThat(original.getAllowedClientList()).isEqualTo(testAllowedClientList); + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.R) { + assertThat(original.getMacRandomizationSetting()) + .isEqualTo(SoftApConfiguration.RANDOMIZATION_NONE); + } SoftApConfiguration unparceled = parcelUnparcel(original); assertThat(unparceled).isNotSameAs(original); @@ -209,6 +223,20 @@ public class SoftApConfigurationTest { } @Test(expected = IllegalArgumentException.class) + public void testInvalidBroadcastBssid() { + SoftApConfiguration original = new SoftApConfiguration.Builder() + .setBssid(MacAddress.BROADCAST_ADDRESS) + .build(); + } + + @Test(expected = IllegalArgumentException.class) + public void testInvalidMulticastBssid() { + SoftApConfiguration original = new SoftApConfiguration.Builder() + .setBssid(MacAddress.fromString("01:aa:bb:cc:dd:ee")) + .build(); + } + + @Test(expected = IllegalArgumentException.class) public void testInvalidShortPasswordLengthForWpa2() { SoftApConfiguration original = new SoftApConfiguration.Builder() .setPassphrase(generateRandomString(SoftApConfiguration.PSK_MIN_LEN - 1), diff --git a/wifi/tests/src/android/net/wifi/SoftApInfoTest.java b/wifi/tests/src/android/net/wifi/SoftApInfoTest.java index 929f3ab88fd8..458a95494438 100644 --- a/wifi/tests/src/android/net/wifi/SoftApInfoTest.java +++ b/wifi/tests/src/android/net/wifi/SoftApInfoTest.java @@ -16,6 +16,7 @@ package android.net.wifi; +import android.net.MacAddress; import android.os.Parcel; import static org.junit.Assert.assertEquals; @@ -38,6 +39,8 @@ public class SoftApInfoTest { SoftApInfo info = new SoftApInfo(); info.setFrequency(2412); info.setBandwidth(SoftApInfo.CHANNEL_WIDTH_20MHZ); + info.setBssid(MacAddress.fromString("aa:bb:cc:dd:ee:ff")); + SoftApInfo copiedInfo = new SoftApInfo(info); @@ -53,6 +56,7 @@ public class SoftApInfoTest { SoftApInfo info = new SoftApInfo(); info.setFrequency(2412); info.setBandwidth(SoftApInfo.CHANNEL_WIDTH_20MHZ); + info.setBssid(MacAddress.fromString("aa:bb:cc:dd:ee:ff")); Parcel parcelW = Parcel.obtain(); info.writeToParcel(parcelW, 0); diff --git a/wifi/tests/src/android/net/wifi/WifiManagerTest.java b/wifi/tests/src/android/net/wifi/WifiManagerTest.java index 1398bfeef031..e7f1916c9e82 100644 --- a/wifi/tests/src/android/net/wifi/WifiManagerTest.java +++ b/wifi/tests/src/android/net/wifi/WifiManagerTest.java @@ -83,7 +83,6 @@ import android.net.wifi.WifiManager.SoftApCallback; import android.net.wifi.WifiManager.SuggestionConnectionStatusListener; import android.net.wifi.WifiManager.TrafficStateCallback; import android.net.wifi.WifiManager.WifiConnectedNetworkScorer; -import android.os.Binder; import android.os.Build; import android.os.Handler; import android.os.HandlerExecutor; @@ -219,10 +218,10 @@ public class WifiManagerTest { */ @Test public void testStartSoftApCallsServiceWithWifiConfig() throws Exception { - when(mWifiService.startSoftAp(eq(mApConfig))).thenReturn(true); + when(mWifiService.startSoftAp(mApConfig, TEST_PACKAGE_NAME)).thenReturn(true); assertTrue(mWifiManager.startSoftAp(mApConfig)); - when(mWifiService.startSoftAp(eq(mApConfig))).thenReturn(false); + when(mWifiService.startSoftAp(mApConfig, TEST_PACKAGE_NAME)).thenReturn(false); assertFalse(mWifiManager.startSoftAp(mApConfig)); } @@ -232,10 +231,10 @@ public class WifiManagerTest { */ @Test public void testStartSoftApCallsServiceWithNullConfig() throws Exception { - when(mWifiService.startSoftAp(eq(null))).thenReturn(true); + when(mWifiService.startSoftAp(null, TEST_PACKAGE_NAME)).thenReturn(true); assertTrue(mWifiManager.startSoftAp(null)); - when(mWifiService.startSoftAp(eq(null))).thenReturn(false); + when(mWifiService.startSoftAp(null, TEST_PACKAGE_NAME)).thenReturn(false); assertFalse(mWifiManager.startSoftAp(null)); } @@ -258,10 +257,12 @@ public class WifiManagerTest { @Test public void testStartTetheredHotspotCallsServiceWithSoftApConfig() throws Exception { SoftApConfiguration softApConfig = generatorTestSoftApConfig(); - when(mWifiService.startTetheredHotspot(eq(softApConfig))).thenReturn(true); + when(mWifiService.startTetheredHotspot(softApConfig, TEST_PACKAGE_NAME)) + .thenReturn(true); assertTrue(mWifiManager.startTetheredHotspot(softApConfig)); - when(mWifiService.startTetheredHotspot(eq(softApConfig))).thenReturn(false); + when(mWifiService.startTetheredHotspot(softApConfig, TEST_PACKAGE_NAME)) + .thenReturn(false); assertFalse(mWifiManager.startTetheredHotspot(softApConfig)); } @@ -271,10 +272,10 @@ public class WifiManagerTest { */ @Test public void testStartTetheredHotspotCallsServiceWithNullConfig() throws Exception { - when(mWifiService.startTetheredHotspot(eq(null))).thenReturn(true); + when(mWifiService.startTetheredHotspot(null, TEST_PACKAGE_NAME)).thenReturn(true); assertTrue(mWifiManager.startTetheredHotspot(null)); - when(mWifiService.startTetheredHotspot(eq(null))).thenReturn(false); + when(mWifiService.startTetheredHotspot(null, TEST_PACKAGE_NAME)).thenReturn(false); assertFalse(mWifiManager.startTetheredHotspot(null)); } @@ -1992,8 +1993,7 @@ public class WifiManagerTest { ArgumentCaptor<IActionListener> binderListenerCaptor = ArgumentCaptor.forClass(IActionListener.class); - verify(mWifiService).connect(eq(null), eq(TEST_NETWORK_ID), any(Binder.class), - binderListenerCaptor.capture(), anyInt()); + verify(mWifiService).connect(eq(null), eq(TEST_NETWORK_ID), binderListenerCaptor.capture()); assertNotNull(binderListenerCaptor.getValue()); // Trigger on success. @@ -2013,8 +2013,7 @@ public class WifiManagerTest { @Test public void testConnectWithListenerHandleSecurityException() throws Exception { doThrow(new SecurityException()).when(mWifiService) - .connect(eq(null), anyInt(), any(IBinder.class), - any(IActionListener.class), anyInt()); + .connect(eq(null), anyInt(), any(IActionListener.class)); ActionListener externalListener = mock(ActionListener.class); mWifiManager.connect(TEST_NETWORK_ID, externalListener); @@ -2028,8 +2027,7 @@ public class WifiManagerTest { @Test public void testConnectWithListenerHandleRemoteException() throws Exception { doThrow(new RemoteException()).when(mWifiService) - .connect(eq(null), anyInt(), any(IBinder.class), - any(IActionListener.class), anyInt()); + .connect(eq(null), anyInt(), any(IActionListener.class)); ActionListener externalListener = mock(ActionListener.class); mWifiManager.connect(TEST_NETWORK_ID, externalListener); @@ -2045,8 +2043,7 @@ public class WifiManagerTest { WifiConfiguration configuration = new WifiConfiguration(); mWifiManager.connect(configuration, null); - verify(mWifiService).connect(configuration, WifiConfiguration.INVALID_NETWORK_ID, null, - null, 0); + verify(mWifiService).connect(configuration, WifiConfiguration.INVALID_NETWORK_ID, null); } /** @@ -2380,7 +2377,7 @@ public class WifiManagerTest { @Test public void testScanAvailable() throws Exception { mWifiManager.setScanAlwaysAvailable(true); - verify(mWifiService).setScanAlwaysAvailable(true); + verify(mWifiService).setScanAlwaysAvailable(true, TEST_PACKAGE_NAME); when(mWifiService.isScanAlwaysAvailable()).thenReturn(false); assertFalse(mWifiManager.isScanAlwaysAvailable()); diff --git a/wifi/tests/src/android/net/wifi/WifiNetworkSuggestionTest.java b/wifi/tests/src/android/net/wifi/WifiNetworkSuggestionTest.java index 16b4ad08a830..f0839e9b3122 100644 --- a/wifi/tests/src/android/net/wifi/WifiNetworkSuggestionTest.java +++ b/wifi/tests/src/android/net/wifi/WifiNetworkSuggestionTest.java @@ -62,6 +62,7 @@ public class WifiNetworkSuggestionTest { assertEquals(-1, suggestion.wifiConfiguration.priority); assertFalse(suggestion.isUserAllowedToManuallyConnect); assertTrue(suggestion.isInitialAutoJoinEnabled); + assertNull(suggestion.getEnterpriseConfig()); } /** @@ -92,6 +93,7 @@ public class WifiNetworkSuggestionTest { assertEquals(0, suggestion.wifiConfiguration.priority); assertFalse(suggestion.isUserAllowedToManuallyConnect); assertTrue(suggestion.isInitialAutoJoinEnabled); + assertNull(suggestion.getEnterpriseConfig()); } /** @@ -122,6 +124,7 @@ public class WifiNetworkSuggestionTest { assertEquals(-1, suggestion.wifiConfiguration.priority); assertTrue(suggestion.isUserAllowedToManuallyConnect); assertFalse(suggestion.isInitialAutoJoinEnabled); + assertNull(suggestion.getEnterpriseConfig()); } /** @@ -152,6 +155,7 @@ public class WifiNetworkSuggestionTest { assertEquals(-1, suggestion.wifiConfiguration.priority); assertTrue(suggestion.isUserAllowedToManuallyConnect); assertFalse(suggestion.isInitialAutoJoinEnabled); + assertNull(suggestion.getEnterpriseConfig()); } /** @@ -174,6 +178,7 @@ public class WifiNetworkSuggestionTest { assertTrue(suggestion.wifiConfiguration.requirePmf); assertFalse(suggestion.isUserAllowedToManuallyConnect); assertTrue(suggestion.isInitialAutoJoinEnabled); + assertNull(suggestion.getEnterpriseConfig()); } /** @@ -197,6 +202,7 @@ public class WifiNetworkSuggestionTest { assertTrue(suggestion.wifiConfiguration.requirePmf); assertTrue(suggestion.isUserAllowedToManuallyConnect); assertFalse(suggestion.isInitialAutoJoinEnabled); + assertNull(suggestion.getEnterpriseConfig()); } @@ -230,6 +236,7 @@ public class WifiNetworkSuggestionTest { // here. assertTrue(suggestion.isUserAllowedToManuallyConnect); assertTrue(suggestion.isInitialAutoJoinEnabled); + assertNotNull(suggestion.getEnterpriseConfig()); } /** @@ -286,6 +293,7 @@ public class WifiNetworkSuggestionTest { .get(WifiConfiguration.GroupCipher.SMS4)); assertEquals("\"" + TEST_PRESHARED_KEY + "\"", suggestion.wifiConfiguration.preSharedKey); + assertNull(suggestion.getEnterpriseConfig()); } @@ -316,6 +324,7 @@ public class WifiNetworkSuggestionTest { suggestion.wifiConfiguration.enterpriseConfig.getEapMethod()); assertEquals(TEST_WAPI_CERT_SUITE, suggestion.wifiConfiguration.enterpriseConfig.getWapiCertSuite()); + assertNotNull(suggestion.getEnterpriseConfig()); } /** @@ -345,6 +354,7 @@ public class WifiNetworkSuggestionTest { suggestion.wifiConfiguration.enterpriseConfig.getEapMethod()); assertEquals("", suggestion.wifiConfiguration.enterpriseConfig.getWapiCertSuite()); + assertNotNull(suggestion.getEnterpriseConfig()); } /** @@ -367,6 +377,7 @@ public class WifiNetworkSuggestionTest { assertEquals(suggestion.getPasspointConfig().getMeteredOverride(), WifiConfiguration.METERED_OVERRIDE_METERED); assertTrue(suggestion.isUserAllowedToManuallyConnect); + assertNull(suggestion.getEnterpriseConfig()); } /** |