diff options
author | 2025-03-21 20:23:25 -0700 | |
---|---|---|
committer | 2025-03-21 20:23:25 -0700 | |
commit | a43f3bba39e502a67879ea896cf53d3917266d8d (patch) | |
tree | 3b5fb58384f4fbaa25f26b6af2dd999acb0af5e5 | |
parent | 03313eda7435b4caf8f18306853329cc03db9de1 (diff) | |
parent | da844144fd9c5df04fe8ac225660808642ef0040 (diff) |
Snap for 13256841 from da844144fd9c5df04fe8ac225660808642ef0040 to 25Q2-release
Change-Id: I16325a9e2adb27470f5ef76e57ff51dc5509c385
23 files changed, 767 insertions, 130 deletions
diff --git a/framework/java/android/net/wifi/IWifiManager.aidl b/framework/java/android/net/wifi/IWifiManager.aidl index 2382f94382..9e126e3c95 100644 --- a/framework/java/android/net/wifi/IWifiManager.aidl +++ b/framework/java/android/net/wifi/IWifiManager.aidl @@ -228,9 +228,10 @@ interface IWifiManager { boolean isMulticastEnabled(); - void acquireMulticastLock(IBinder binder, String tag); + void acquireMulticastLock( + IBinder binder, String lockTag, String attributionTag, String packageName); - void releaseMulticastLock(IBinder binder, String tag); + void releaseMulticastLock(IBinder binder, String lockTag); void updateInterfaceIpState(String ifaceName, int mode); diff --git a/framework/java/android/net/wifi/WifiManager.java b/framework/java/android/net/wifi/WifiManager.java index 0ebf06fa5d..c642e04dc8 100644 --- a/framework/java/android/net/wifi/WifiManager.java +++ b/framework/java/android/net/wifi/WifiManager.java @@ -8465,7 +8465,8 @@ public class WifiManager { synchronized (mBinder) { if (mRefCounted ? (++mRefCount == 1) : (!mHeld)) { try { - mService.acquireMulticastLock(mBinder, mTag); + mService.acquireMulticastLock(mBinder, mTag, + mContext.getAttributionTag(), mContext.getOpPackageName()); synchronized (WifiManager.this) { if (mActiveLockCount >= MAX_ACTIVE_LOCKS) { mService.releaseMulticastLock(mBinder, mTag); diff --git a/framework/java/android/net/wifi/rtt/PasnConfig.java b/framework/java/android/net/wifi/rtt/PasnConfig.java index 547d94bb67..291a963f5b 100644 --- a/framework/java/android/net/wifi/rtt/PasnConfig.java +++ b/framework/java/android/net/wifi/rtt/PasnConfig.java @@ -120,17 +120,14 @@ public final class PasnConfig implements Parcelable { static { sStringToAkm.put("None", AKM_NONE); - sStringToAkm.put("PASN-", AKM_PASN); - // Transition mode. e.g. "[RSN-SAE+SAE_EXT_KEY-CCMP]" - sStringToAkm.put("SAE+", AKM_SAE); - // SAE mode only. e.g. "[RSN-PSK+SAE-CCMP]" - sStringToAkm.put("SAE-", AKM_SAE); - sStringToAkm.put("EAP-FILS-SHA256-", AKM_FILS_EAP_SHA256); - sStringToAkm.put("EAP-FILS-SHA384-", AKM_FILS_EAP_SHA384); - sStringToAkm.put("FT/EAP-", AKM_FT_EAP_SHA256); - sStringToAkm.put("FT/PSK-", AKM_FT_PSK_SHA256); - sStringToAkm.put("EAP-FT-SHA384-", AKM_FT_EAP_SHA384); - sStringToAkm.put("FT/PSK-SHA384-", AKM_FT_PSK_SHA384); + sStringToAkm.put("PASN", AKM_PASN); + sStringToAkm.put("SAE", AKM_SAE); + sStringToAkm.put("EAP-FILS-SHA256", AKM_FILS_EAP_SHA256); + sStringToAkm.put("EAP-FILS-SHA384", AKM_FILS_EAP_SHA384); + sStringToAkm.put("FT/EAP", AKM_FT_EAP_SHA256); + sStringToAkm.put("FT/PSK", AKM_FT_PSK_SHA256); + sStringToAkm.put("EAP-FT-SHA384", AKM_FT_EAP_SHA384); + sStringToAkm.put("FT/PSK-SHA384", AKM_FT_PSK_SHA384); } /** @@ -174,10 +171,10 @@ public final class PasnConfig implements Parcelable { static { sStringToCipher.put("None", CIPHER_NONE); - sStringToCipher.put("-CCMP]", CIPHER_CCMP_128); - sStringToCipher.put("-CCMP-256]", CIPHER_CCMP_256); - sStringToCipher.put("-GCMP]", CIPHER_GCMP_128); - sStringToCipher.put("-GCMP-256]", CIPHER_GCMP_256); + sStringToCipher.put("CCMP-128", CIPHER_CCMP_128); + sStringToCipher.put("CCMP-256", CIPHER_CCMP_256); + sStringToCipher.put("GCMP-128", CIPHER_GCMP_128); + sStringToCipher.put("GCMP-256", CIPHER_GCMP_256); } @AkmType diff --git a/framework/tests/src/android/net/wifi/rtt/PasnConfigTest.java b/framework/tests/src/android/net/wifi/rtt/PasnConfigTest.java index a5e4798cad..d6a52be8c8 100644 --- a/framework/tests/src/android/net/wifi/rtt/PasnConfigTest.java +++ b/framework/tests/src/android/net/wifi/rtt/PasnConfigTest.java @@ -184,11 +184,13 @@ public class PasnConfigTest { assertEquals(PasnConfig.AKM_NONE, PasnConfig.getBaseAkmsFromCapabilities(null)); assertEquals(PasnConfig.AKM_NONE, PasnConfig.getBaseAkmsFromCapabilities("")); assertEquals(PasnConfig.AKM_SAE, - PasnConfig.getBaseAkmsFromCapabilities("[RSN-SAE+SAE_EXT_KEY-CCMP]")); + PasnConfig.getBaseAkmsFromCapabilities("[RSN-SAE+SAE_EXT_KEY-CCMP-128]")); assertEquals(PasnConfig.AKM_SAE, - PasnConfig.getBaseAkmsFromCapabilities("[RSN-PSK+SAE-CCMP]")); + PasnConfig.getBaseAkmsFromCapabilities("[RSN-PSK+SAE-CCMP-128]")); assertEquals(PasnConfig.AKM_FT_PSK_SHA256, - PasnConfig.getBaseAkmsFromCapabilities("[RSN-FT/PSK-CCMP]")); + PasnConfig.getBaseAkmsFromCapabilities("[RSN-FT/PSK-CCMP-128]")); + assertEquals(PasnConfig.AKM_SAE | PasnConfig.AKM_PASN, + PasnConfig.getBaseAkmsFromCapabilities("[RSN-PSK+SAE+PASN-CCMP-128]")); } /** @@ -199,13 +201,15 @@ public class PasnConfigTest { assertEquals(PasnConfig.CIPHER_NONE, PasnConfig.getCiphersFromCapabilities(null)); assertEquals(PasnConfig.CIPHER_NONE, PasnConfig.getCiphersFromCapabilities("")); assertEquals(PasnConfig.CIPHER_CCMP_128, - PasnConfig.getCiphersFromCapabilities("[RSN-SAE+SAE_EXT_KEY-CCMP]")); + PasnConfig.getCiphersFromCapabilities("[RSN-SAE+SAE_EXT_KEY-CCMP-128]")); assertEquals(PasnConfig.CIPHER_CCMP_256, PasnConfig.getCiphersFromCapabilities("[RSN-SAE+SAE_EXT_KEY-CCMP-256]")); assertEquals(PasnConfig.CIPHER_GCMP_128, - PasnConfig.getCiphersFromCapabilities("[RSN-SAE+SAE_EXT_KEY-GCMP]")); + PasnConfig.getCiphersFromCapabilities("[RSN-SAE+SAE_EXT_KEY-GCMP-128]")); assertEquals(PasnConfig.CIPHER_GCMP_256, PasnConfig.getCiphersFromCapabilities("[RSN-SAE+SAE_EXT_KEY-GCMP-256]")); + assertEquals(PasnConfig.CIPHER_GCMP_256 | PasnConfig.CIPHER_CCMP_128, + PasnConfig.getCiphersFromCapabilities("[RSN-SAE+SAE_EXT_KEY-GCMP-256+CCMP-128]")); } /** diff --git a/framework/tests/src/android/net/wifi/rtt/WifiRttManagerTest.java b/framework/tests/src/android/net/wifi/rtt/WifiRttManagerTest.java index 3426b76800..08d5f40385 100644 --- a/framework/tests/src/android/net/wifi/rtt/WifiRttManagerTest.java +++ b/framework/tests/src/android/net/wifi/rtt/WifiRttManagerTest.java @@ -864,7 +864,7 @@ public class WifiRttManagerTest { scanResult.setFlag( ScanResult.FLAG_80211az_NTB_RESPONDER | ScanResult.FLAG_SECURE_HE_LTF_SUPPORTED); scanResult.informationElements = ie; - scanResult.capabilities = "[RSN-PASN-SAE+SAE_EXT_KEY-GCMP]"; + scanResult.capabilities = "[RSN-PASN-SAE+SAE_EXT_KEY-GCMP-128]"; scanResult.setWifiSsid(WifiSsid.fromString("\"TEST_SSID\"")); RangingRequest.Builder builder = new RangingRequest.Builder(); diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java index 9bcf627f9a..08e93bdf7f 100644 --- a/service/java/com/android/server/wifi/ClientModeImpl.java +++ b/service/java/com/android/server/wifi/ClientModeImpl.java @@ -3659,7 +3659,7 @@ public class ClientModeImpl extends StateMachine implements ClientMode { // Update link layer stats getWifiLinkLayerStats(); - if (mWifiP2pConnection.isConnected() && !mWifiP2pConnection.isP2pInWaitingState()) { + if (mWifiP2pConnection.isConnected() && !mWifiP2pConnection.isP2pInDisabledState()) { // P2P discovery breaks DHCP, so shut it down in order to get through this. // Once P2P service receives this message and processes it accordingly, it is supposed // to send arg2 (i.e. CMD_PRE_DHCP_ACTION_COMPLETE) in a new Message.what back to diff --git a/service/java/com/android/server/wifi/WifiLockManager.java b/service/java/com/android/server/wifi/WifiLockManager.java index d6f6742998..33833f4b9a 100644 --- a/service/java/com/android/server/wifi/WifiLockManager.java +++ b/service/java/com/android/server/wifi/WifiLockManager.java @@ -678,7 +678,7 @@ public class WifiLockManager { switch(wifiLock.mMode) { case WifiManager.WIFI_MODE_FULL_HIGH_PERF: - mWifiMetrics.addWifiLockAcqSession(WifiManager.WIFI_MODE_FULL_HIGH_PERF, + mWifiMetrics.addWifiLockManagerAcqSession(WifiManager.WIFI_MODE_FULL_HIGH_PERF, uidsAndTags.first, uidsAndTags.second, mWifiPermissionsUtil.getWifiCallerType(wifiLock.getUid(), @@ -696,7 +696,7 @@ public class WifiLockManager { } break; case WifiManager.WIFI_MODE_FULL_LOW_LATENCY: - mWifiMetrics.addWifiLockAcqSession(WifiManager.WIFI_MODE_FULL_LOW_LATENCY, + mWifiMetrics.addWifiLockManagerAcqSession(WifiManager.WIFI_MODE_FULL_LOW_LATENCY, uidsAndTags.first, uidsAndTags.second, mWifiPermissionsUtil.getWifiCallerType(wifiLock.getUid(), diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java index 58b13fc2ea..68ac00f1ef 100644 --- a/service/java/com/android/server/wifi/WifiMetrics.java +++ b/service/java/com/android/server/wifi/WifiMetrics.java @@ -8914,8 +8914,11 @@ public class WifiMetrics { } } - /** Add a WifiLock acquisition session */ - public void addWifiLockAcqSession(int lockType, int[] attrUids, String[] attrTags, + /** + * Add a WifiLockManager acquisition session. This represents the session during which + * a single lock was held. + */ + public void addWifiLockManagerAcqSession(int lockType, int[] attrUids, String[] attrTags, int callerType, long duration, boolean isPowersaveDisableAllowed, boolean isAppExemptedFromScreenOn, boolean isAppExemptedFromForeground) { int lockMode; @@ -8933,6 +8936,27 @@ public class WifiMetrics { Log.e(TAG, "addWifiLockAcqSession: Invalid lock type: " + lockType); return; } + writeWifiLockAcqSession(lockMode, attrUids, attrTags, callerType, duration, + isPowersaveDisableAllowed, isAppExemptedFromScreenOn, isAppExemptedFromForeground); + } + + /** + * Add a MulticastLockManager acquisition session. This represents the session during which + * a single lock was held. + */ + public void addMulticastLockManagerAcqSession( + int uid, String attributionTag, int callerType, long duration) { + // Use a default value for the boolean parameters, since these fields + // don't apply to multicast locks. + writeWifiLockAcqSession( + WifiStatsLog.WIFI_LOCK_RELEASED__MODE__WIFI_MODE_MULTICAST_FILTERING_DISABLED, + new int[]{uid}, new String[]{attributionTag}, callerType, duration, + false, false, false); + } + + private void writeWifiLockAcqSession(int lockMode, int[] attrUids, String[] attrTags, + int callerType, long duration, boolean isPowersaveDisableAllowed, + boolean isAppExemptedFromScreenOn, boolean isAppExemptedFromForeground) { WifiStatsLog.write(WifiStatsLog.WIFI_LOCK_RELEASED, attrUids, attrTags, diff --git a/service/java/com/android/server/wifi/WifiMulticastLockManager.java b/service/java/com/android/server/wifi/WifiMulticastLockManager.java index fa40fd7d3b..e25d9c86c6 100644 --- a/service/java/com/android/server/wifi/WifiMulticastLockManager.java +++ b/service/java/com/android/server/wifi/WifiMulticastLockManager.java @@ -89,11 +89,16 @@ public class WifiMulticastLockManager { String mTag; int mUid; IBinder mBinder; + String mAttributionTag; + String mPackageName; - Multicaster(int uid, IBinder binder, String tag) { + Multicaster(int uid, IBinder binder, String tag, String attributionTag, + String packageName) { mTag = tag; mUid = uid; mBinder = binder; + mAttributionTag = attributionTag; + mPackageName = packageName; try { mBinder.linkToDeath(this, 0); } catch (RemoteException e) { @@ -130,6 +135,14 @@ public class WifiMulticastLockManager { return mBinder; } + public String getAttributionTag() { + return mAttributionTag; + } + + public String getPackageName() { + return mPackageName; + } + public String toString() { return "Multicaster{" + mTag + " uid=" + mUid + "}"; } @@ -221,10 +234,14 @@ public class WifiMulticastLockManager { /** * Acquire a multicast lock. + * @param uid uid of the calling application * @param binder a binder used to ensure caller is still alive - * @param tag string name of the caller. + * @param lockTag caller-provided tag to identify this lock + * @param attributionTag attribution tag of the calling application + * @param packageName package name of the calling application */ - public void acquireLock(int uid, IBinder binder, String tag) { + public void acquireLock(int uid, IBinder binder, String lockTag, String attributionTag, + String packageName) { synchronized (mLock) { mMulticastEnabled++; @@ -234,7 +251,7 @@ public class WifiMulticastLockManager { } int numLocksHeldByUid = mNumLocksPerActiveOwner.getOrDefault(uid, 0); mNumLocksPerActiveOwner.put(uid, numLocksHeldByUid + 1); - mMulticasters.add(new Multicaster(uid, binder, tag)); + mMulticasters.add(new Multicaster(uid, binder, lockTag, attributionTag, packageName)); // Note that we could call stopFilteringMulticastPackets only when // our new size == 1 (first call), but this function won't @@ -249,20 +266,20 @@ public class WifiMulticastLockManager { mBatteryStats.reportWifiMulticastEnabled(new WorkSource(uid)); WifiStatsLog.write_non_chained( WifiStatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED, uid, null, - WifiStatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED__STATE__ON, tag); + WifiStatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED__STATE__ON, lockTag); Binder.restoreCallingIdentity(ident); } /** Releases a multicast lock */ - public void releaseLock(int uid, IBinder binder, String tag) { + public void releaseLock(int uid, IBinder binder, String lockTag) { synchronized (mLock) { mMulticastDisabled++; int size = mMulticasters.size(); for (int i = size - 1; i >= 0; i--) { Multicaster m = mMulticasters.get(i); - if ((m != null) && (m.getUid() == uid) && (m.getTag().equals(tag)) + if ((m != null) && (m.getUid() == uid) && (m.getTag().equals(lockTag)) && (m.getBinder() == binder)) { - removeMulticasterLocked(i, uid, tag); + removeMulticasterLocked(i, uid, lockTag); break; } } diff --git a/service/java/com/android/server/wifi/WifiP2pConnection.java b/service/java/com/android/server/wifi/WifiP2pConnection.java index 907ab0d197..f1c665dd01 100644 --- a/service/java/com/android/server/wifi/WifiP2pConnection.java +++ b/service/java/com/android/server/wifi/WifiP2pConnection.java @@ -45,8 +45,8 @@ public class WifiP2pConnection { private AsyncChannel mWifiP2pChannel; private boolean mTemporarilyDisconnectWifi = false; - /** Used to check if P2P state machine is in waitingState */ - private boolean mWaitingState = false; + /** Used to check if P2P state machine is in DisabledState */ + private boolean mDisabledState = false; public WifiP2pConnection(Context context, Looper looper, ActiveModeWarden activeModeWarden) { mContext = context; @@ -191,12 +191,12 @@ public class WifiP2pConnection { return mTemporarilyDisconnectWifi; } - public void setP2pInWaitingState(boolean inWaitingState) { - mWaitingState = inWaitingState; + public void setP2pInDisabledState(boolean inDisabledState) { + mDisabledState = inDisabledState; } - /** whether the P2P state machine is in waitingState for user response to create interface */ - public boolean isP2pInWaitingState() { - return mWaitingState; + /** whether the P2P state machine is in disabled state */ + public boolean isP2pInDisabledState() { + return mDisabledState; } } diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index ec20ffbd66..9055d857be 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -6171,19 +6171,20 @@ public class WifiServiceImpl extends IWifiManager.Stub { } @Override - public void acquireMulticastLock(IBinder binder, String tag) { + public void acquireMulticastLock(IBinder binder, String lockTag, String attributionTag, + String packageName) { enforceMulticastChangePermission(); int uid = Binder.getCallingUid(); - mLog.info("acquireMulticastLock uid=% tag=%").c(uid).c(tag).flush(); - mWifiMulticastLockManager.acquireLock(uid, binder, tag); + mLog.info("acquireMulticastLock uid=% lockTag=%").c(uid).c(lockTag).flush(); + mWifiMulticastLockManager.acquireLock(uid, binder, lockTag, attributionTag, packageName); } @Override - public void releaseMulticastLock(IBinder binder, String tag) { + public void releaseMulticastLock(IBinder binder, String lockTag) { enforceMulticastChangePermission(); int uid = Binder.getCallingUid(); - mLog.info("releaseMulticastLock uid=% tag=%").c(uid).c(tag).flush(); - mWifiMulticastLockManager.releaseLock(uid, binder, tag); + mLog.info("releaseMulticastLock uid=% lockTag=%").c(uid).c(lockTag).flush(); + mWifiMulticastLockManager.releaseLock(uid, binder, lockTag); } @Override diff --git a/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java b/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java index 19047477dc..3f4460ed8b 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java @@ -2661,8 +2661,8 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe onAwareDownLocal(); if (reason != NanStatusCode.SUCCESS) { sendAwareStateChangedBroadcast(false); + releaseAwareInterface(); } - releaseAwareInterface(); break; } case NOTIFICATION_TYPE_ON_MESSAGE_SEND_SUCCESS: { diff --git a/service/java/com/android/server/wifi/mainline_supplicant/MainlineSupplicant.java b/service/java/com/android/server/wifi/mainline_supplicant/MainlineSupplicant.java index 6310577077..1ac2ad8f64 100644 --- a/service/java/com/android/server/wifi/mainline_supplicant/MainlineSupplicant.java +++ b/service/java/com/android/server/wifi/mainline_supplicant/MainlineSupplicant.java @@ -18,6 +18,10 @@ package com.android.server.wifi.mainline_supplicant; import android.annotation.NonNull; import android.annotation.Nullable; +import android.net.MacAddress; +import android.net.wifi.usd.Config; +import android.net.wifi.usd.PublishConfig; +import android.net.wifi.usd.SubscribeConfig; import android.net.wifi.util.Environment; import android.os.IBinder; import android.os.RemoteException; @@ -25,13 +29,18 @@ import android.os.ServiceSpecificException; import android.system.wifi.mainline_supplicant.IMainlineSupplicant; import android.system.wifi.mainline_supplicant.IStaInterface; import android.system.wifi.mainline_supplicant.IStaInterfaceCallback; +import android.system.wifi.mainline_supplicant.UsdMessageInfo; +import android.system.wifi.mainline_supplicant.UsdServiceProtoType; import android.util.Log; import com.android.internal.annotations.VisibleForTesting; +import com.android.server.wifi.SupplicantStaIfaceHal; import com.android.server.wifi.WifiNative; import com.android.server.wifi.WifiThreadRunner; +import com.android.server.wifi.usd.UsdNativeManager; import com.android.wifi.flags.Flags; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.concurrent.CountDownLatch; @@ -47,6 +56,7 @@ public class MainlineSupplicant { private static final String TAG = "MainlineSupplicant"; private static final String MAINLINE_SUPPLICANT_SERVICE_NAME = "wifi_mainline_supplicant"; private static final long WAIT_FOR_DEATH_TIMEOUT_MS = 50L; + protected static final int DEFAULT_USD_FREQ_MHZ = 2437; private IMainlineSupplicant mIMainlineSupplicant; private final Object mLock = new Object(); @@ -57,6 +67,7 @@ public class MainlineSupplicant { private final boolean mIsServiceAvailable; private Map<String, IStaInterface> mActiveStaIfaces = new HashMap<>(); private Map<String, IStaInterfaceCallback> mStaIfaceCallbacks = new HashMap<>(); + private UsdNativeManager.UsdEventsCallback mUsdEventsCallback = null; public MainlineSupplicant(@NonNull WifiThreadRunner wifiThreadRunner) { mWifiThreadRunner = wifiThreadRunner; @@ -281,6 +292,22 @@ public class MainlineSupplicant { } /** + * Register a framework callback to receive USD events. + */ + public void registerUsdEventsCallback( + @NonNull UsdNativeManager.UsdEventsCallback usdEventsCallback) { + mUsdEventsCallback = usdEventsCallback; + } + + /** + * Get the registered USD events callback. Method should only be used + * by {@link MainlineSupplicantStaIfaceCallback}. + */ + protected @Nullable UsdNativeManager.UsdEventsCallback getUsdEventsCallback() { + return mUsdEventsCallback; + } + + /** * Stop the mainline supplicant process. */ public void stopService() { @@ -342,6 +369,324 @@ public class MainlineSupplicant { } } + private static byte frameworkToHalUsdTransmissionType( + @Config.TransmissionType int transmissionType) { + switch (transmissionType) { + case Config.TRANSMISSION_TYPE_MULTICAST: + return IStaInterface.UsdPublishTransmissionType.MULTICAST; + case Config.TRANSMISSION_TYPE_UNICAST: + default: + return IStaInterface.UsdPublishTransmissionType.UNICAST; + } + } + + private static byte frameworkToHalUsdProtoType( + @Config.ServiceProtoType int protoType) { + switch (protoType) { + case Config.SERVICE_PROTO_TYPE_GENERIC: + return UsdServiceProtoType.GENERIC; + case Config.SERVICE_PROTO_TYPE_CSA_MATTER: + return UsdServiceProtoType.CSA_MATTER; + default: + return UsdServiceProtoType.UNKNOWN; + } + } + + @VisibleForTesting + protected static IStaInterface.UsdPublishConfig frameworkToHalUsdPublishConfig( + PublishConfig frameworkConfig) { + IStaInterface.UsdPublishConfig aidlConfig = new IStaInterface.UsdPublishConfig(); + // USD publisher is always solicited and unsolicited + aidlConfig.publishType = IStaInterface.UsdPublishType.SOLICITED_AND_UNSOLICITED; + // FSD is always enabled for USD + aidlConfig.isFsd = true; + aidlConfig.transmissionType = frameworkToHalUsdTransmissionType( + frameworkConfig.getSolicitedTransmissionType()); + aidlConfig.announcementPeriodMillis = frameworkConfig.getAnnouncementPeriodMillis(); + aidlConfig.baseConfig = new IStaInterface.UsdBaseConfig(); + aidlConfig.baseConfig.ttlSec = frameworkConfig.getTtlSeconds(); + int[] freqs = frameworkConfig.getOperatingFrequenciesMhz(); + aidlConfig.baseConfig.defaultFreqMhz = (freqs == null || freqs.length == 0) + ? DEFAULT_USD_FREQ_MHZ : freqs[0]; + aidlConfig.baseConfig.freqsMhz = (freqs == null || freqs.length <= 1) + ? new int[0] : Arrays.copyOfRange(freqs, 1, freqs.length); + aidlConfig.baseConfig.serviceName = Arrays.toString(frameworkConfig.getServiceName()); + aidlConfig.baseConfig.serviceSpecificInfo = + frameworkConfig.getServiceSpecificInfo() != null + ? frameworkConfig.getServiceSpecificInfo() : new byte[0]; + aidlConfig.baseConfig.rxMatchFilter = frameworkConfig.getRxMatchFilterTlv() != null + ? frameworkConfig.getRxMatchFilterTlv() : new byte[0]; + aidlConfig.baseConfig.txMatchFilter = frameworkConfig.getTxMatchFilterTlv() != null + ? frameworkConfig.getTxMatchFilterTlv() : new byte[0]; + aidlConfig.baseConfig.serviceProtoType = frameworkToHalUsdProtoType( + frameworkConfig.getServiceProtoType()); + return aidlConfig; + } + + /** + * Start a USD publish operation. + * + * @param ifaceName Name of the interface + * @param cmdId An id for this command + * @param publishConfig Publish configuration + * @return true if successful, false otherwise + */ + public boolean startUsdPublish(@NonNull String ifaceName, int cmdId, + @NonNull PublishConfig publishConfig) { + synchronized (mLock) { + final String methodName = "startUsdPublish"; + if (ifaceName == null || publishConfig == null) { + return false; + } + IStaInterface iface = getStaIfaceOrLogError(ifaceName, methodName); + if (iface == null) { + return false; + } + try { + iface.startUsdPublish(cmdId, frameworkToHalUsdPublishConfig(publishConfig)); + return true; + } catch (ServiceSpecificException e) { + handleServiceSpecificException(e, methodName); + } catch (RemoteException e) { + handleRemoteException(e, methodName); + } + return false; + } + } + + private static byte frameworkToHalUsdSubscribeType( + @Config.SubscribeType int subscribeType) { + switch (subscribeType) { + case Config.SUBSCRIBE_TYPE_ACTIVE: + return IStaInterface.UsdSubscribeType.ACTIVE_MODE; + case Config.SUBSCRIBE_TYPE_PASSIVE: + default: + return IStaInterface.UsdSubscribeType.PASSIVE_MODE; + } + } + + @VisibleForTesting + protected static IStaInterface.UsdSubscribeConfig frameworkToHalUsdSubscribeConfig( + SubscribeConfig frameworkConfig) { + IStaInterface.UsdSubscribeConfig aidlConfig = new IStaInterface.UsdSubscribeConfig(); + aidlConfig.subscribeType = + frameworkToHalUsdSubscribeType(frameworkConfig.getSubscribeType()); + aidlConfig.queryPeriodMillis = frameworkConfig.getQueryPeriodMillis(); + aidlConfig.baseConfig = new IStaInterface.UsdBaseConfig(); + aidlConfig.baseConfig.ttlSec = frameworkConfig.getTtlSeconds(); + int[] freqs = frameworkConfig.getOperatingFrequenciesMhz(); + aidlConfig.baseConfig.defaultFreqMhz = (freqs == null || freqs.length == 0) + ? DEFAULT_USD_FREQ_MHZ : freqs[0]; + aidlConfig.baseConfig.freqsMhz = (freqs == null || freqs.length <= 1) + ? new int[0] : Arrays.copyOfRange(freqs, 1, freqs.length); + aidlConfig.baseConfig.serviceName = Arrays.toString(frameworkConfig.getServiceName()); + aidlConfig.baseConfig.serviceSpecificInfo = + frameworkConfig.getServiceSpecificInfo() != null + ? frameworkConfig.getServiceSpecificInfo() : new byte[0]; + aidlConfig.baseConfig.rxMatchFilter = frameworkConfig.getRxMatchFilterTlv() != null + ? frameworkConfig.getRxMatchFilterTlv() : new byte[0]; + aidlConfig.baseConfig.txMatchFilter = frameworkConfig.getTxMatchFilterTlv() != null + ? frameworkConfig.getTxMatchFilterTlv() : new byte[0]; + aidlConfig.baseConfig.serviceProtoType = frameworkToHalUsdProtoType( + frameworkConfig.getServiceProtoType()); + return aidlConfig; + } + + /** + * Start a USD subscribe operation. + * + * @param ifaceName Name of the interface + * @param cmdId An id for this command + * @param subscribeConfig Subscribe configuration + * @return true if successful, false otherwise + */ + public boolean startUsdSubscribe(@NonNull String ifaceName, int cmdId, + @NonNull SubscribeConfig subscribeConfig) { + synchronized (mLock) { + final String methodName = "startUsdSubscribe"; + if (ifaceName == null || subscribeConfig == null) { + return false; + } + IStaInterface iface = getStaIfaceOrLogError(ifaceName, methodName); + if (iface == null) { + return false; + } + try { + iface.startUsdSubscribe(cmdId, frameworkToHalUsdSubscribeConfig(subscribeConfig)); + return true; + } catch (ServiceSpecificException e) { + handleServiceSpecificException(e, methodName); + } catch (RemoteException e) { + handleRemoteException(e, methodName); + } + return false; + } + } + + /** + * Get the USD capabilities for the interface. + * + * @param ifaceName Name of the interface + * @return UsdCapabilities if available, otherwise null + */ + public @Nullable SupplicantStaIfaceHal.UsdCapabilitiesInternal getUsdCapabilities( + @NonNull String ifaceName) { + synchronized (mLock) { + final String methodName = "getUsdCapabilities"; + if (ifaceName == null) { + return null; + } + IStaInterface iface = getStaIfaceOrLogError(ifaceName, methodName); + if (iface == null) { + return null; + } + try { + IStaInterface.UsdCapabilities aidlCaps = iface.getUsdCapabilities(); + if (aidlCaps == null) { + Log.e(TAG, "Received null USD capabilities from the HAL"); + return null; + } + return new SupplicantStaIfaceHal.UsdCapabilitiesInternal( + aidlCaps.isUsdPublisherSupported, + aidlCaps.isUsdSubscriberSupported, + aidlCaps.maxLocalSsiLengthBytes, + aidlCaps.maxServiceNameLengthBytes, + aidlCaps.maxMatchFilterLengthBytes, + aidlCaps.maxNumPublishSessions, + aidlCaps.maxNumSubscribeSessions); + } catch (ServiceSpecificException e) { + handleServiceSpecificException(e, methodName); + } catch (RemoteException e) { + handleRemoteException(e, methodName); + } + return null; + } + } + + /** + * Update an ongoing USD publish operation. + * + * @param ifaceName Name of the interface + * @param publishId Publish id for this session + * @param ssi Service specific info + */ + public void updateUsdPublish(@NonNull String ifaceName, int publishId, + @NonNull byte[] ssi) { + synchronized (mLock) { + final String methodName = "updateUsdPublish"; + if (ifaceName == null || ssi == null) { + return; + } + IStaInterface iface = getStaIfaceOrLogError(ifaceName, methodName); + if (iface == null) { + return; + } + try { + iface.updateUsdPublish(publishId, ssi); + } catch (ServiceSpecificException e) { + handleServiceSpecificException(e, methodName); + } catch (RemoteException e) { + handleRemoteException(e, methodName); + } + } + } + + /** + * Cancel an ongoing USD publish session. + * + * @param ifaceName Name of the interface + * @param publishId Publish id for the session + */ + public void cancelUsdPublish(@NonNull String ifaceName, int publishId) { + synchronized (mLock) { + final String methodName = "cancelUsdPublish"; + if (ifaceName == null) { + return; + } + IStaInterface iface = getStaIfaceOrLogError(ifaceName, methodName); + if (iface == null) { + return; + } + try { + iface.cancelUsdPublish(publishId); + } catch (ServiceSpecificException e) { + handleServiceSpecificException(e, methodName); + } catch (RemoteException e) { + handleRemoteException(e, methodName); + } + } + } + + /** + * Cancel an ongoing USD subscribe session. + * + * @param ifaceName Name of the interface + * @param subscribeId Subscribe id for the session + */ + public void cancelUsdSubscribe(@NonNull String ifaceName, int subscribeId) { + synchronized (mLock) { + final String methodName = "cancelUsdSubscribe"; + if (ifaceName == null) { + return; + } + IStaInterface iface = getStaIfaceOrLogError(ifaceName, methodName); + if (iface == null) { + return; + } + try { + iface.cancelUsdSubscribe(subscribeId); + } catch (ServiceSpecificException e) { + handleServiceSpecificException(e, methodName); + } catch (RemoteException e) { + handleRemoteException(e, methodName); + } + } + } + + private static UsdMessageInfo createUsdMessageInfo(int ownId, int peerId, + MacAddress peerMacAddress, byte[] message) { + UsdMessageInfo messageInfo = new UsdMessageInfo(); + messageInfo.ownId = ownId; + messageInfo.peerId = peerId; + messageInfo.message = message; + messageInfo.peerMacAddress = peerMacAddress.toByteArray(); + return messageInfo; + } + + /** + * Send a message to an ongoing USD publish or subscribe session. + * + * @param ifaceName Name of the interface + * @param ownId Id for the session + * @param peerId Id for the peer session + * @param peerMacAddress Mac address of the peer session + * @param message Data to send + * @return true if successful, false otherwise + */ + public boolean sendUsdMessage(@NonNull String ifaceName, int ownId, int peerId, + @NonNull MacAddress peerMacAddress, @NonNull byte[] message) { + synchronized (mLock) { + final String methodName = "sendUsdMessage"; + if (ifaceName == null || peerMacAddress == null || message == null) { + return false; + } + IStaInterface iface = getStaIfaceOrLogError(ifaceName, methodName); + if (iface == null) { + return false; + } + try { + iface.sendUsdMessage( + createUsdMessageInfo(ownId, peerId, peerMacAddress, message)); + return true; + } catch (ServiceSpecificException e) { + handleServiceSpecificException(e, methodName); + } catch (RemoteException e) { + handleRemoteException(e, methodName); + } + return false; + } + } + private void handleServiceSpecificException(ServiceSpecificException e, String methodName) { Log.e(TAG, methodName + " encountered ServiceSpecificException " + e); } @@ -354,6 +699,17 @@ public class MainlineSupplicant { return true; } + private @Nullable IStaInterface getStaIfaceOrLogError(String ifaceName, String methodName) { + synchronized (mLock) { + if (!mActiveStaIfaces.containsKey(ifaceName)) { + Log.e(TAG, "Unable to call " + methodName + " since iface " + + ifaceName + " does not exist"); + return null; + } + return mActiveStaIfaces.get(ifaceName); + } + } + private void handleRemoteException(RemoteException e, String methodName) { synchronized (mLock) { Log.e(TAG, methodName + " encountered RemoteException " + e); diff --git a/service/java/com/android/server/wifi/mainline_supplicant/MainlineSupplicantStaIfaceCallback.java b/service/java/com/android/server/wifi/mainline_supplicant/MainlineSupplicantStaIfaceCallback.java index 20cda62861..4d6207357e 100644 --- a/service/java/com/android/server/wifi/mainline_supplicant/MainlineSupplicantStaIfaceCallback.java +++ b/service/java/com/android/server/wifi/mainline_supplicant/MainlineSupplicantStaIfaceCallback.java @@ -17,15 +17,26 @@ package com.android.server.wifi.mainline_supplicant; import android.annotation.NonNull; +import android.annotation.Nullable; +import android.annotation.SuppressLint; +import android.net.MacAddress; +import android.net.wifi.usd.Config; +import android.net.wifi.usd.SessionCallback; import android.system.wifi.mainline_supplicant.IStaInterfaceCallback; import android.system.wifi.mainline_supplicant.UsdMessageInfo; +import android.system.wifi.mainline_supplicant.UsdServiceProtoType; +import android.util.Log; import com.android.server.wifi.WifiThreadRunner; +import com.android.server.wifi.usd.UsdNativeManager; +import com.android.server.wifi.usd.UsdRequestManager; /** * Implementation of the mainline supplicant {@link IStaInterfaceCallback}. */ public class MainlineSupplicantStaIfaceCallback extends IStaInterfaceCallback.Stub { + private static final String TAG = "MainlineSupplicantStaIfaceCallback"; + private final MainlineSupplicant mMainlineSupplicant; private final String mIfaceName; private final WifiThreadRunner mWifiThreadRunner; @@ -45,7 +56,17 @@ public class MainlineSupplicantStaIfaceCallback extends IStaInterfaceCallback.St * @param publishId Identifier for the publish session. */ @Override - public void onUsdPublishStarted(int cmdId, int publishId) { } + public void onUsdPublishStarted(int cmdId, int publishId) { + mWifiThreadRunner.post(() -> { + UsdNativeManager.UsdEventsCallback usdCallback = + mMainlineSupplicant.getUsdEventsCallback(); + if (usdCallback == null) { + Log.e(TAG, "UsdEventsCallback callback is null"); + return; + } + usdCallback.onUsdPublishStarted(cmdId, publishId); + }); + } /** * Called in response to startUsdSubscribe to indicate that the subscribe session @@ -55,7 +76,30 @@ public class MainlineSupplicantStaIfaceCallback extends IStaInterfaceCallback.St * @param subscribeId Identifier for the subscribe session. */ @Override - public void onUsdSubscribeStarted(int cmdId, int subscribeId) { } + public void onUsdSubscribeStarted(int cmdId, int subscribeId) { + mWifiThreadRunner.post(() -> { + UsdNativeManager.UsdEventsCallback usdCallback = + mMainlineSupplicant.getUsdEventsCallback(); + if (usdCallback == null) { + Log.e(TAG, "UsdEventsCallback callback is null"); + return; + } + usdCallback.onUsdSubscribeStarted(cmdId, subscribeId); + }); + } + + @SuppressLint("NewApi") + private static @SessionCallback.FailureCode int + convertHalToFrameworkUsdConfigErrorCode(int errorCode) { + switch (errorCode) { + case UsdConfigErrorCode.FAILURE_TIMEOUT: + return SessionCallback.FAILURE_TIMEOUT; + case UsdConfigErrorCode.FAILURE_NOT_AVAILABLE: + return SessionCallback.FAILURE_NOT_AVAILABLE; + default: + return SessionCallback.FAILURE_UNKNOWN; + } + } /** * Called in response to startUsdPublish to indicate that the publish session @@ -64,7 +108,18 @@ public class MainlineSupplicantStaIfaceCallback extends IStaInterfaceCallback.St * @param cmdId Identifier for the original request. * @param errorCode Code indicating the failure reason. */ - @Override public void onUsdPublishConfigFailed(int cmdId, int errorCode) { } + @Override public void onUsdPublishConfigFailed(int cmdId, int errorCode) { + mWifiThreadRunner.post(() -> { + UsdNativeManager.UsdEventsCallback usdCallback = + mMainlineSupplicant.getUsdEventsCallback(); + if (usdCallback == null) { + Log.e(TAG, "UsdEventsCallback callback is null"); + return; + } + usdCallback.onUsdPublishConfigFailed(cmdId, + convertHalToFrameworkUsdConfigErrorCode(errorCode)); + }); + } /** * Called in response to startUsdSubscribe to indicate that the subscribe session @@ -74,7 +129,29 @@ public class MainlineSupplicantStaIfaceCallback extends IStaInterfaceCallback.St * @param errorCode Code indicating the failure reason. */ @Override - public void onUsdSubscribeConfigFailed(int cmdId, int errorCode) { } + public void onUsdSubscribeConfigFailed(int cmdId, int errorCode) { + mWifiThreadRunner.post(() -> { + UsdNativeManager.UsdEventsCallback usdCallback = + mMainlineSupplicant.getUsdEventsCallback(); + if (usdCallback == null) { + Log.e(TAG, "UsdEventsCallback callback is null"); + return; + } + usdCallback.onUsdSubscribeConfigFailed(cmdId, + convertHalToFrameworkUsdConfigErrorCode(errorCode)); + }); + } + + @SuppressLint("NewApi") + private static @SessionCallback.TerminationReasonCode int + convertHalToFrameworkUsdTerminateReasonCode(int reasonCode) { + switch (reasonCode) { + case UsdTerminateReasonCode.USER_REQUESTED: + return SessionCallback.TERMINATION_REASON_USER_INITIATED; + default: + return SessionCallback.TERMINATION_REASON_UNKNOWN; + } + } /** * Called in response to cancelUsdPublish to indicate that the session was cancelled @@ -84,7 +161,18 @@ public class MainlineSupplicantStaIfaceCallback extends IStaInterfaceCallback.St * @param reasonCode Code indicating the reason for the session cancellation. */ @Override - public void onUsdPublishTerminated(int publishId, int reasonCode) { } + public void onUsdPublishTerminated(int publishId, int reasonCode) { + mWifiThreadRunner.post(() -> { + UsdNativeManager.UsdEventsCallback usdCallback = + mMainlineSupplicant.getUsdEventsCallback(); + if (usdCallback == null) { + Log.e(TAG, "UsdEventsCallback callback is null"); + return; + } + usdCallback.onUsdPublishTerminated(publishId, + convertHalToFrameworkUsdTerminateReasonCode(reasonCode)); + }); + } /** * Called in response to cancelUsdSubscribe to indicate that the session was cancelled @@ -94,7 +182,59 @@ public class MainlineSupplicantStaIfaceCallback extends IStaInterfaceCallback.St * @param reasonCode Code indicating the reason for the session cancellation. */ @Override - public void onUsdSubscribeTerminated(int subscribeId, int reasonCode) { } + public void onUsdSubscribeTerminated(int subscribeId, int reasonCode) { + mWifiThreadRunner.post(() -> { + UsdNativeManager.UsdEventsCallback usdCallback = + mMainlineSupplicant.getUsdEventsCallback(); + if (usdCallback == null) { + Log.e(TAG, "UsdEventsCallback callback is null"); + return; + } + usdCallback.onUsdSubscribeTerminated(subscribeId, + convertHalToFrameworkUsdTerminateReasonCode(reasonCode)); + }); + } + + private static @Config.ServiceProtoType int + convertHalToFrameworkUsdProtocolType(int protocolType) { + switch (protocolType) { + case UsdServiceProtoType.CSA_MATTER: + return Config.SERVICE_PROTO_TYPE_CSA_MATTER; + default: + return Config.SERVICE_PROTO_TYPE_GENERIC; + } + } + + private static @Nullable MacAddress safeConvertMacAddress(byte[] macAddrBytes) { + if (macAddrBytes == null) return null; + try { + return MacAddress.fromBytes(macAddrBytes); + } catch (Exception e) { + return null; + } + } + + private static UsdRequestManager.UsdHalDiscoveryInfo + convertHalToFrameworkUsdDiscoveryInfo(UsdServiceDiscoveryInfo discoveryInfo) { + if (discoveryInfo.peerMacAddress == null + || discoveryInfo.serviceSpecificInfo == null + || discoveryInfo.matchFilter == null) { + Log.e(TAG, "USD discovery info contains a null parameter"); + return null; + } + MacAddress peerAddress = safeConvertMacAddress(discoveryInfo.peerMacAddress); + if (peerAddress == null) { + Log.e(TAG, "USD discovery info contains an invalid peer address"); + return null; + } + return new UsdRequestManager.UsdHalDiscoveryInfo(discoveryInfo.ownId, + discoveryInfo.peerId, + peerAddress, + discoveryInfo.serviceSpecificInfo, + convertHalToFrameworkUsdProtocolType(discoveryInfo.serviceProtoType), + discoveryInfo.isFsd, + discoveryInfo.matchFilter); + } /** * Indicates that the publisher sent a solicited publish message to the subscriber. @@ -102,7 +242,22 @@ public class MainlineSupplicantStaIfaceCallback extends IStaInterfaceCallback.St * @param info Instance of |UsdServiceDiscoveryInfo| containing information about the reply. */ @Override - public void onUsdPublishReplied(UsdServiceDiscoveryInfo info) { } + public void onUsdPublishReplied(UsdServiceDiscoveryInfo info) { + mWifiThreadRunner.post(() -> { + UsdNativeManager.UsdEventsCallback usdCallback = + mMainlineSupplicant.getUsdEventsCallback(); + if (usdCallback == null) { + Log.e(TAG, "UsdEventsCallback callback is null"); + return; + } + UsdRequestManager.UsdHalDiscoveryInfo convertedInfo = + convertHalToFrameworkUsdDiscoveryInfo(info); + if (convertedInfo == null) { + return; + } + usdCallback.onUsdPublishReplied(convertedInfo); + }); + } /** * Indicates that a publisher was discovered. Only called if this device is acting as a @@ -111,7 +266,22 @@ public class MainlineSupplicantStaIfaceCallback extends IStaInterfaceCallback.St * @param info Instance of |UsdServiceDiscoveryInfo| containing information about the service. */ @Override - public void onUsdServiceDiscovered(UsdServiceDiscoveryInfo info) { } + public void onUsdServiceDiscovered(UsdServiceDiscoveryInfo info) { + mWifiThreadRunner.post(() -> { + UsdNativeManager.UsdEventsCallback usdCallback = + mMainlineSupplicant.getUsdEventsCallback(); + if (usdCallback == null) { + Log.e(TAG, "UsdEventsCallback callback is null"); + return; + } + UsdRequestManager.UsdHalDiscoveryInfo convertedInfo = + convertHalToFrameworkUsdDiscoveryInfo(info); + if (convertedInfo == null) { + return; + } + usdCallback.onUsdServiceDiscovered(convertedInfo); + }); + } /** * Indicates that a message was received on an active USD link. @@ -119,5 +289,27 @@ public class MainlineSupplicantStaIfaceCallback extends IStaInterfaceCallback.St * @param messageInfo Information about the message that was received. */ @Override - public void onUsdMessageReceived(UsdMessageInfo messageInfo) { } + public void onUsdMessageReceived(UsdMessageInfo messageInfo) { + mWifiThreadRunner.post(() -> { + UsdNativeManager.UsdEventsCallback usdCallback = + mMainlineSupplicant.getUsdEventsCallback(); + if (usdCallback == null) { + Log.e(TAG, "UsdEventsCallback callback is null"); + return; + } + MacAddress peerAddress = safeConvertMacAddress(messageInfo.peerMacAddress); + if (peerAddress == null) { + Log.e(TAG, "USD message info contains an invalid peer address"); + return; + } + if (messageInfo.message == null) { + Log.e(TAG, "USD message info contains a null message"); + return; + } + usdCallback.onUsdMessageReceived(messageInfo.ownId, + messageInfo.peerId, + peerAddress, + messageInfo.message); + }); + } } diff --git a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java index 450f3b4ec7..05a21be4a3 100644 --- a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java +++ b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java @@ -3026,12 +3026,12 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub { @Override public void enterImpl() { - + mWifiInjector.getWifiP2pConnection().setP2pInDisabledState(true); } @Override public void exitImpl() { - + mWifiInjector.getWifiP2pConnection().setP2pInDisabledState(false); } @Override @@ -3055,14 +3055,12 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub { Log.i(TAG, "No valid package name, ignore ENABLE_P2P"); break; } - mWifiInjector.getWifiP2pConnection().setP2pInWaitingState(true); int proceedWithOperation = mInterfaceConflictManager.manageInterfaceConflictForStateMachine( TAG, message, mP2pStateMachine, mWaitingState, mP2pDisabledState, HalDeviceManager.HDM_CREATE_IFACE_P2P, createRequestorWs(message.sendingUid, packageName), false /* bypassDialog */); - mWifiInjector.getWifiP2pConnection().setP2pInWaitingState(false); if (proceedWithOperation == InterfaceConflictManager.ICM_ABORT_COMMAND) { Log.e(TAG, "User refused to set up P2P"); updateThisDevice(WifiP2pDevice.UNAVAILABLE); @@ -3131,14 +3129,12 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub { Log.i(TAG, "No valid package name, do not set up the P2P interface"); return NOT_HANDLED; } - mWifiInjector.getWifiP2pConnection().setP2pInWaitingState(true); int proceedWithOperation = mInterfaceConflictManager.manageInterfaceConflictForStateMachine( TAG, message, mP2pStateMachine, mWaitingState, mP2pDisabledState, HalDeviceManager.HDM_CREATE_IFACE_P2P, createRequestorWs(message.sendingUid, packageName), false /* bypassDialog */); - mWifiInjector.getWifiP2pConnection().setP2pInWaitingState(false); if (proceedWithOperation == InterfaceConflictManager.ICM_ABORT_COMMAND) { Log.e(TAG, "User refused to set up P2P"); updateThisDevice(WifiP2pDevice.UNAVAILABLE); diff --git a/service/java/com/android/server/wifi/util/InformationElementUtil.java b/service/java/com/android/server/wifi/util/InformationElementUtil.java index f4fd25c168..9ac19d6283 100644 --- a/service/java/com/android/server/wifi/util/InformationElementUtil.java +++ b/service/java/com/android/server/wifi/util/InformationElementUtil.java @@ -2492,11 +2492,11 @@ public class InformationElementUtil { case ScanResult.CIPHER_NONE: return "None"; case ScanResult.CIPHER_CCMP: - return "CCMP"; + return "CCMP-128"; case ScanResult.CIPHER_CCMP_256: return "CCMP-256"; case ScanResult.CIPHER_GCMP_128: - return "GCMP"; + return "GCMP-128"; case ScanResult.CIPHER_GCMP_256: return "GCMP-256"; case ScanResult.CIPHER_TKIP: diff --git a/service/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/service/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java index 19f15a21a7..37ae9aa13e 100644 --- a/service/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java +++ b/service/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java @@ -11126,8 +11126,8 @@ public class ClientModeImplTest extends WifiBaseTest { } /** - * Verify that during DHCP process, 1. If P2P is in waiting state, clientModeImpl doesn't send a - * message to block P2P discovery. 2. If P2P is not in waiting state, clientModeImpl sends a + * Verify that during DHCP process, 1. If P2P is in disabled state, clientModeImpl doesn't send + * a message to block P2P discovery. 2. If P2P is not in disabled state, clientModeImpl sends a * message to block P2P discovery. 3. On DHCP completion, clientModeImpl sends a message to * unblock P2P discovery. */ @@ -11162,7 +11162,7 @@ public class ClientModeImplTest extends WifiBaseTest { assertEquals("L3ProvisioningState", getCurrentState().getName()); when(mWifiP2pConnection.isConnected()).thenReturn(true); - when(mWifiP2pConnection.isP2pInWaitingState()).thenReturn(true); + when(mWifiP2pConnection.isP2pInDisabledState()).thenReturn(true); mIpClientCallback.onPreDhcpAction(); mLooper.dispatchAll(); @@ -11170,7 +11170,7 @@ public class ClientModeImplTest extends WifiBaseTest { verify(mIpClient).completedPreDhcpAction(); when(mWifiP2pConnection.isConnected()).thenReturn(true); - when(mWifiP2pConnection.isP2pInWaitingState()).thenReturn(false); + when(mWifiP2pConnection.isP2pInDisabledState()).thenReturn(false); mIpClientCallback.onPreDhcpAction(); mLooper.dispatchAll(); diff --git a/service/tests/wifitests/src/com/android/server/wifi/WifiLockManagerTest.java b/service/tests/wifitests/src/com/android/server/wifi/WifiLockManagerTest.java index 4e5250d387..64831e172d 100644 --- a/service/tests/wifitests/src/com/android/server/wifi/WifiLockManagerTest.java +++ b/service/tests/wifitests/src/com/android/server/wifi/WifiLockManagerTest.java @@ -303,7 +303,7 @@ public class WifiLockManagerTest extends WifiBaseTest { acquireWifiLockSuccessful(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "", mBinder, mWorkSource); releaseWifiLockSuccessful(mBinder); - verify(mWifiMetrics).addWifiLockAcqSession( + verify(mWifiMetrics).addWifiLockManagerAcqSession( eq(mDeviceConfigFacade.isHighPerfLockDeprecated() && SdkLevel.isAtLeastU() ? WifiManager.WIFI_MODE_FULL_LOW_LATENCY : WifiManager.WIFI_MODE_FULL_HIGH_PERF), eq(new int[]{DEFAULT_TEST_UID_1}), @@ -632,7 +632,7 @@ public class WifiLockManagerTest extends WifiBaseTest { // Release the first lock releaseWifiLockSuccessful(mBinder); - verify(mWifiMetrics).addWifiLockAcqSession(eq(WifiManager.WIFI_MODE_FULL_HIGH_PERF), + verify(mWifiMetrics).addWifiLockManagerAcqSession(eq(WifiManager.WIFI_MODE_FULL_HIGH_PERF), eq(new int[]{DEFAULT_TEST_UID_1}), eq(new String[]{null}), anyInt(), anyLong(), anyBoolean(), anyBoolean(), anyBoolean()); @@ -782,7 +782,7 @@ public class WifiLockManagerTest extends WifiBaseTest { false); releaseWifiLockSuccessful(mBinder); - verify(mWifiMetrics).addWifiLockAcqSession(eq(expectedMode), + verify(mWifiMetrics).addWifiLockManagerAcqSession(eq(expectedMode), eq(new int[]{DEFAULT_TEST_UID_1}), eq(new String[]{null}), anyInt(), anyLong(), anyBoolean(), anyBoolean(), anyBoolean()); assertEquals(WifiManager.WIFI_MODE_NO_LOCKS_HELD, @@ -863,7 +863,7 @@ public class WifiLockManagerTest extends WifiBaseTest { eq(ClientMode.POWER_SAVE_CLIENT_WIFI_LOCK), anyBoolean()); releaseWifiLockSuccessful(mBinder); - verify(mWifiMetrics).addWifiLockAcqSession(eq(WifiManager.WIFI_MODE_FULL_HIGH_PERF), + verify(mWifiMetrics).addWifiLockManagerAcqSession(eq(WifiManager.WIFI_MODE_FULL_HIGH_PERF), eq(new int[]{DEFAULT_TEST_UID_1}), eq(new String[]{null}), anyInt(), anyLong(), anyBoolean(), anyBoolean(), anyBoolean()); assertEquals(WifiManager.WIFI_MODE_FULL_HIGH_PERF, @@ -1757,7 +1757,7 @@ public class WifiLockManagerTest extends WifiBaseTest { when(mClock.getElapsedSinceBootMillis()).thenReturn(releaseTime); releaseWifiLockSuccessful_noBatteryStats(mBinder); - verify(mWifiMetrics).addWifiLockAcqSession(eq(expectedMode), + verify(mWifiMetrics).addWifiLockManagerAcqSession(eq(expectedMode), eq(new int[]{DEFAULT_TEST_UID_1}), eq(new String[]{null}), anyInt(), eq(releaseTime - acquireTime), eq(true), eq(false), eq(false)); } @@ -1808,7 +1808,8 @@ public class WifiLockManagerTest extends WifiBaseTest { when(mClock.getElapsedSinceBootMillis()).thenReturn(releaseTime); releaseWifiLockSuccessful_noBatteryStats(mBinder); - verify(mWifiMetrics).addWifiLockAcqSession(eq(WifiManager.WIFI_MODE_FULL_LOW_LATENCY), + verify(mWifiMetrics).addWifiLockManagerAcqSession( + eq(WifiManager.WIFI_MODE_FULL_LOW_LATENCY), eq(new int[]{DEFAULT_TEST_UID_1}), eq(new String[]{null}), anyInt(), eq(releaseTime - acquireTime), eq(true), eq(false), eq(false)); @@ -1851,7 +1852,7 @@ public class WifiLockManagerTest extends WifiBaseTest { acquireWifiLockSuccessful(WifiManager.WIFI_MODE_FULL_HIGH_PERF, TEST_WIFI_LOCK_TAG, mBinder, mWorkSource); releaseWifiLockSuccessful(mBinder); - verify(mWifiMetrics).addWifiLockAcqSession(eq(expectedMode), + verify(mWifiMetrics).addWifiLockManagerAcqSession(eq(expectedMode), eq(new int[]{DEFAULT_TEST_UID_1}), eq(new String[]{null}), anyInt(), anyLong(), anyBoolean(), anyBoolean(), anyBoolean()); acquireWifiLockSuccessful(WifiManager.WIFI_MODE_FULL_HIGH_PERF, TEST_WIFI_LOCK_TAG, diff --git a/service/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/service/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java index 3d3a2e6924..e16c2b1272 100644 --- a/service/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java +++ b/service/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java @@ -5624,8 +5624,8 @@ public class WifiMetricsTest extends WifiBaseTest { * Test the WifiLock acquisition session statistics */ @Test - public void testWifiLockAcqSession() throws Exception { - mWifiMetrics.addWifiLockAcqSession(WifiManager.WIFI_MODE_FULL_HIGH_PERF, + public void testWifiLockManagerAcqSession() throws Exception { + mWifiMetrics.addWifiLockManagerAcqSession(WifiManager.WIFI_MODE_FULL_HIGH_PERF, new int[]{TEST_UID}, new String[]{TEST_TAG}, 0, 100000, false, false, false); ExtendedMockito.verify( () -> WifiStatsLog.write(WifiStatsLog.WIFI_LOCK_RELEASED, new int[]{TEST_UID}, @@ -5633,7 +5633,7 @@ public class WifiMetricsTest extends WifiBaseTest { WifiStatsLog.WIFI_LOCK_RELEASED__MODE__WIFI_MODE_FULL_HIGH_PERF, 100000, false, false, false)); - mWifiMetrics.addWifiLockAcqSession(WifiManager.WIFI_MODE_FULL_HIGH_PERF, + mWifiMetrics.addWifiLockManagerAcqSession(WifiManager.WIFI_MODE_FULL_HIGH_PERF, new int[]{TEST_UID}, new String[]{TEST_TAG}, 0, 10000, true, false, false); ExtendedMockito.verify( () -> WifiStatsLog.write(WifiStatsLog.WIFI_LOCK_RELEASED, new int[]{TEST_UID}, @@ -5641,7 +5641,7 @@ public class WifiMetricsTest extends WifiBaseTest { WifiStatsLog.WIFI_LOCK_RELEASED__MODE__WIFI_MODE_FULL_HIGH_PERF, 10000, true, false, false)); - mWifiMetrics.addWifiLockAcqSession(WifiManager.WIFI_MODE_FULL_HIGH_PERF, + mWifiMetrics.addWifiLockManagerAcqSession(WifiManager.WIFI_MODE_FULL_HIGH_PERF, new int[]{TEST_UID}, new String[]{TEST_TAG}, 0, 10000000, true, true, false); ExtendedMockito.verify( () -> WifiStatsLog.write(WifiStatsLog.WIFI_LOCK_RELEASED, new int[]{TEST_UID}, @@ -5649,7 +5649,7 @@ public class WifiMetricsTest extends WifiBaseTest { WifiStatsLog.WIFI_LOCK_RELEASED__MODE__WIFI_MODE_FULL_HIGH_PERF, 10000000, true, true, false)); - mWifiMetrics.addWifiLockAcqSession(WifiManager.WIFI_MODE_FULL_HIGH_PERF, + mWifiMetrics.addWifiLockManagerAcqSession(WifiManager.WIFI_MODE_FULL_HIGH_PERF, new int[]{TEST_UID}, new String[]{TEST_TAG}, 0, 1000, true, true, true); ExtendedMockito.verify( () -> WifiStatsLog.write(WifiStatsLog.WIFI_LOCK_RELEASED, new int[]{TEST_UID}, @@ -5658,7 +5658,7 @@ public class WifiMetricsTest extends WifiBaseTest { true, true, true)); - mWifiMetrics.addWifiLockAcqSession(WifiManager.WIFI_MODE_FULL_LOW_LATENCY, + mWifiMetrics.addWifiLockManagerAcqSession(WifiManager.WIFI_MODE_FULL_LOW_LATENCY, new int[]{TEST_UID}, new String[]{TEST_TAG}, 0, 90000, false, false, false); ExtendedMockito.verify( () -> WifiStatsLog.write(WifiStatsLog.WIFI_LOCK_RELEASED, new int[]{TEST_UID}, @@ -5666,7 +5666,7 @@ public class WifiMetricsTest extends WifiBaseTest { WifiStatsLog.WIFI_LOCK_RELEASED__MODE__WIFI_MODE_FULL_LOW_LATENCY, 90000, false, false, false)); - mWifiMetrics.addWifiLockAcqSession(WifiManager.WIFI_MODE_FULL_LOW_LATENCY, + mWifiMetrics.addWifiLockManagerAcqSession(WifiManager.WIFI_MODE_FULL_LOW_LATENCY, new int[]{TEST_UID}, new String[]{TEST_TAG}, 0, 900000, true, false, false); ExtendedMockito.verify( () -> WifiStatsLog.write(WifiStatsLog.WIFI_LOCK_RELEASED, new int[]{TEST_UID}, @@ -5674,7 +5674,7 @@ public class WifiMetricsTest extends WifiBaseTest { WifiStatsLog.WIFI_LOCK_RELEASED__MODE__WIFI_MODE_FULL_LOW_LATENCY, 900000, true, false, false)); - mWifiMetrics.addWifiLockAcqSession(WifiManager.WIFI_MODE_FULL_LOW_LATENCY, + mWifiMetrics.addWifiLockManagerAcqSession(WifiManager.WIFI_MODE_FULL_LOW_LATENCY, new int[]{TEST_UID}, new String[]{TEST_TAG}, 0, 9000, true, true, false); ExtendedMockito.verify( () -> WifiStatsLog.write(WifiStatsLog.WIFI_LOCK_RELEASED, new int[]{TEST_UID}, @@ -5682,7 +5682,7 @@ public class WifiMetricsTest extends WifiBaseTest { WifiStatsLog.WIFI_LOCK_RELEASED__MODE__WIFI_MODE_FULL_LOW_LATENCY, 9000, true, true, false)); - mWifiMetrics.addWifiLockAcqSession(WifiManager.WIFI_MODE_FULL_LOW_LATENCY, + mWifiMetrics.addWifiLockManagerAcqSession(WifiManager.WIFI_MODE_FULL_LOW_LATENCY, new int[]{TEST_UID}, new String[]{TEST_TAG}, 0, 20000000, true, true, true); ExtendedMockito.verify( () -> WifiStatsLog.write(WifiStatsLog.WIFI_LOCK_RELEASED, new int[]{TEST_UID}, diff --git a/service/tests/wifitests/src/com/android/server/wifi/WifiMulticastLockManagerTest.java b/service/tests/wifitests/src/com/android/server/wifi/WifiMulticastLockManagerTest.java index f57f8c43b1..1e80cbc6b8 100644 --- a/service/tests/wifitests/src/com/android/server/wifi/WifiMulticastLockManagerTest.java +++ b/service/tests/wifitests/src/com/android/server/wifi/WifiMulticastLockManagerTest.java @@ -52,6 +52,8 @@ public class WifiMulticastLockManagerTest extends WifiBaseTest { private static final String WL_1_TAG = "Wakelock-1"; private static final String WL_2_TAG = "Wakelock-2"; private static final int TEST_UID = 123; + private static final String TEST_ATTRIBUTION_TAG = "attribution-tag"; + private static final String TEST_PACKAGE_NAME = "package-name"; private TestLooper mLooper; @Mock ConcreteClientModeManager mClientModeManager; @@ -110,7 +112,7 @@ public class WifiMulticastLockManagerTest extends WifiBaseTest { @Test public void oneLock() throws RemoteException { IBinder binder = mock(IBinder.class); - mManager.acquireLock(TEST_UID, binder, WL_1_TAG); + mManager.acquireLock(TEST_UID, binder, WL_1_TAG, TEST_ATTRIBUTION_TAG, TEST_PACKAGE_NAME); assertTrue(mManager.isMulticastEnabled()); verify(mFilterController).stopFilteringMulticastPackets(); mManager.startFilteringMulticastPackets(); @@ -160,7 +162,7 @@ public class WifiMulticastLockManagerTest extends WifiBaseTest { assertTrue(mFilterController2.isFilteringStarted()); IBinder binder = mock(IBinder.class); - mManager.acquireLock(TEST_UID, binder, WL_1_TAG); + mManager.acquireLock(TEST_UID, binder, WL_1_TAG, TEST_ATTRIBUTION_TAG, TEST_PACKAGE_NAME); assertTrue(mManager.isMulticastEnabled()); // CMM1 filtering stopped assertFalse(mFilterController.isFilteringStarted()); @@ -195,7 +197,7 @@ public class WifiMulticastLockManagerTest extends WifiBaseTest { @Test public void oneLock_wrongName() throws RemoteException { IBinder binder = mock(IBinder.class); - mManager.acquireLock(TEST_UID, binder, WL_1_TAG); + mManager.acquireLock(TEST_UID, binder, WL_1_TAG, TEST_ATTRIBUTION_TAG, TEST_PACKAGE_NAME); assertTrue(mManager.isMulticastEnabled()); verify(mFilterController).stopFilteringMulticastPackets(); mManager.startFilteringMulticastPackets(); @@ -218,12 +220,12 @@ public class WifiMulticastLockManagerTest extends WifiBaseTest { InOrder inOrderHandler = inOrder(mFilterController); InOrder inOrderBatteryStats = inOrder(mBatteryStats); - mManager.acquireLock(TEST_UID, binder, WL_1_TAG); + mManager.acquireLock(TEST_UID, binder, WL_1_TAG, TEST_ATTRIBUTION_TAG, TEST_PACKAGE_NAME); inOrderHandler.verify(mFilterController).stopFilteringMulticastPackets(); inOrderBatteryStats.verify(mBatteryStats).reportWifiMulticastEnabled(any()); assertTrue(mManager.isMulticastEnabled()); - mManager.acquireLock(TEST_UID, binder, WL_2_TAG); + mManager.acquireLock(TEST_UID, binder, WL_2_TAG, TEST_ATTRIBUTION_TAG, TEST_PACKAGE_NAME); inOrderHandler.verify(mFilterController).stopFilteringMulticastPackets(); inOrderBatteryStats.verify(mBatteryStats).reportWifiMulticastEnabled(any()); assertTrue(mManager.isMulticastEnabled()); @@ -252,12 +254,12 @@ public class WifiMulticastLockManagerTest extends WifiBaseTest { InOrder inOrderHandler = inOrder(mFilterController); InOrder inOrderBatteryStats = inOrder(mBatteryStats); - mManager.acquireLock(TEST_UID, binder, WL_1_TAG); + mManager.acquireLock(TEST_UID, binder, WL_1_TAG, TEST_ATTRIBUTION_TAG, TEST_PACKAGE_NAME); inOrderHandler.verify(mFilterController).stopFilteringMulticastPackets(); inOrderBatteryStats.verify(mBatteryStats).reportWifiMulticastEnabled(any()); assertTrue(mManager.isMulticastEnabled()); - mManager.acquireLock(TEST_UID, binder, WL_2_TAG); + mManager.acquireLock(TEST_UID, binder, WL_2_TAG, TEST_ATTRIBUTION_TAG, TEST_PACKAGE_NAME); inOrderHandler.verify(mFilterController).stopFilteringMulticastPackets(); inOrderBatteryStats.verify(mBatteryStats).reportWifiMulticastEnabled(any()); assertTrue(mManager.isMulticastEnabled()); @@ -288,8 +290,8 @@ public class WifiMulticastLockManagerTest extends WifiBaseTest { IBinder binder2 = mock(IBinder.class); // Both acquired locks have the same tag - mManager.acquireLock(TEST_UID, binder1, WL_1_TAG); - mManager.acquireLock(TEST_UID, binder2, WL_1_TAG); + mManager.acquireLock(TEST_UID, binder1, WL_1_TAG, TEST_ATTRIBUTION_TAG, TEST_PACKAGE_NAME); + mManager.acquireLock(TEST_UID, binder2, WL_1_TAG, TEST_ATTRIBUTION_TAG, TEST_PACKAGE_NAME); assertTrue(mManager.isMulticastEnabled()); mManager.releaseLock(TEST_UID, binder1, WL_1_TAG); @@ -308,7 +310,7 @@ public class WifiMulticastLockManagerTest extends WifiBaseTest { @Test public void testSingleLockActiveStateChange() { IBinder binder = mock(IBinder.class); - mManager.acquireLock(TEST_UID, binder, WL_1_TAG); + mManager.acquireLock(TEST_UID, binder, WL_1_TAG, TEST_ATTRIBUTION_TAG, TEST_PACKAGE_NAME); assertTrue(mManager.isMulticastEnabled()); verify(mFilterController).stopFilteringMulticastPackets(); @@ -339,11 +341,15 @@ public class WifiMulticastLockManagerTest extends WifiBaseTest { public void testMultipleOwnersActiveStateChange() { int uid1 = TEST_UID; int uid2 = TEST_UID + 1; + String attributionTag1 = "attribution-tag-1"; + String attributionTag2 = "attribution-tag-2"; + String packageName1 = "package-name-1"; + String packageName2 = "package-name-2"; IBinder binder1 = mock(IBinder.class); IBinder binder2 = mock(IBinder.class); - mManager.acquireLock(uid1, binder1, WL_1_TAG); - mManager.acquireLock(uid2, binder2, WL_2_TAG); + mManager.acquireLock(uid1, binder1, WL_1_TAG, attributionTag1, packageName1); + mManager.acquireLock(uid2, binder2, WL_2_TAG, attributionTag2, packageName2); assertTrue(mManager.isMulticastEnabled()); verify(mFilterController, times(2)).stopFilteringMulticastPackets(); diff --git a/service/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareStateManagerTest.java b/service/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareStateManagerTest.java index b5041c7a63..a4ebf7b185 100644 --- a/service/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareStateManagerTest.java +++ b/service/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareStateManagerTest.java @@ -3873,6 +3873,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { validateCorrectAwareStatusChangeBroadcast(inOrder); inOrder.verify(mMockNative).disable(transactionId.capture()); mDut.onDisableResponse(transactionId.getValue(), NanStatusCode.SUCCESS); + mDut.onAwareDownNotification(NanStatusCode.SUCCESS); mMockLooper.dispatchAll(); assertFalse(mDut.isDeviceAttached()); collector.checkThat("usage disabled", mDut.isUsageEnabled(), equalTo(false)); diff --git a/service/tests/wifitests/src/com/android/server/wifi/mainline_supplicant/MainlineSupplicantTest.java b/service/tests/wifitests/src/com/android/server/wifi/mainline_supplicant/MainlineSupplicantTest.java index d1c25a5078..2312fc6c33 100644 --- a/service/tests/wifitests/src/com/android/server/wifi/mainline_supplicant/MainlineSupplicantTest.java +++ b/service/tests/wifitests/src/com/android/server/wifi/mainline_supplicant/MainlineSupplicantTest.java @@ -16,7 +16,9 @@ package com.android.server.wifi.mainline_supplicant; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; import static org.mockito.ArgumentMatchers.anyInt; @@ -27,6 +29,8 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import android.net.wifi.usd.PublishConfig; +import android.net.wifi.usd.SubscribeConfig; import android.net.wifi.util.Environment; import android.os.Handler; import android.os.IBinder; @@ -48,6 +52,7 @@ import org.mockito.MockitoAnnotations; */ public class MainlineSupplicantTest { private static final String IFACE_NAME = "wlan0"; + private static final String USD_SERVICE_NAME = "usd_service"; private @Mock IMainlineSupplicant mIMainlineSupplicantMock; private @Mock IBinder mIBinderMock; @@ -176,4 +181,37 @@ public class MainlineSupplicantTest { // Only the valid remove request should reach have reached the service verify(mIMainlineSupplicantMock, times(1)).removeStaInterface(anyString()); } + + private void verifyUsdBaseConfigDefaultValues(IStaInterface.UsdBaseConfig baseConfig) { + assertNotNull(baseConfig.serviceName); + assertNotNull(baseConfig.freqsMhz); + assertNotNull(baseConfig.serviceSpecificInfo); + assertNotNull(baseConfig.rxMatchFilter); + assertNotNull(baseConfig.txMatchFilter); + assertEquals(MainlineSupplicant.DEFAULT_USD_FREQ_MHZ, baseConfig.defaultFreqMhz); + } + + /** + * Verify that the proper default values are assigned during the + * USD Publish Config conversion. + */ + @Test + public void testUsdPublishConfigConversionDefaultValues() { + PublishConfig frameworkConfig = new PublishConfig.Builder(USD_SERVICE_NAME).build(); + IStaInterface.UsdPublishConfig aidlConfig = + MainlineSupplicant.frameworkToHalUsdPublishConfig(frameworkConfig); + verifyUsdBaseConfigDefaultValues(aidlConfig.baseConfig); + } + + /** + * Verify that the proper default values are assigned during the + * USD Subscribe Config conversion. + */ + @Test + public void testUsdSubscribeConfigConversionDefaultValues() { + SubscribeConfig frameworkConfig = new SubscribeConfig.Builder(USD_SERVICE_NAME).build(); + IStaInterface.UsdSubscribeConfig aidlConfig = + MainlineSupplicant.frameworkToHalUsdSubscribeConfig(frameworkConfig); + verifyUsdBaseConfigDefaultValues(aidlConfig.baseConfig); + } } diff --git a/service/tests/wifitests/src/com/android/server/wifi/util/InformationElementUtilTest.java b/service/tests/wifitests/src/com/android/server/wifi/util/InformationElementUtilTest.java index e45b9dbf0c..0c6dfe15ce 100644 --- a/service/tests/wifitests/src/com/android/server/wifi/util/InformationElementUtilTest.java +++ b/service/tests/wifitests/src/com/android/server/wifi/util/InformationElementUtilTest.java @@ -515,7 +515,7 @@ public class InformationElementUtilTest extends WifiBaseTest { (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x0F, (byte) 0xAC, (byte) 0x02, (byte) 0x00, (byte) 0x00 }; verifyCapabilityStringFromIeWithoutOweSupported(ie, - "[WPA2-PSK-CCMP+TKIP][RSN-PSK-CCMP+TKIP]"); + "[WPA2-PSK-CCMP-128+TKIP][RSN-PSK-CCMP-128+TKIP]"); } /** @@ -537,7 +537,7 @@ public class InformationElementUtilTest extends WifiBaseTest { (byte) 0x00, (byte) 0x00 // RSN capabilities }; verifyCapabilityStringFromIeWithoutOweSupported(ie, - "[RSN-?-CCMP+TKIP]"); + "[RSN-?-CCMP-128+TKIP]"); } /** @@ -576,7 +576,7 @@ public class InformationElementUtilTest extends WifiBaseTest { (byte) 0x00, (byte) 0x0F, (byte) 0xAC, (byte) 0x0c, }; verifyCapabilityStringFromIeWithoutOweSupported(ie, - "[WPA2-EAP/SHA1-CCMP+TKIP][RSN-EAP/SHA1-CCMP+TKIP][MFPR]"); + "[WPA2-EAP/SHA1-CCMP-128+TKIP][RSN-EAP/SHA1-CCMP-128+TKIP][MFPR]"); } /** @@ -608,8 +608,8 @@ public class InformationElementUtilTest extends WifiBaseTest { (byte) 0x00, (byte) 0x0F, (byte) 0xAC, (byte) 0x0c, }; verifyCapabilityStringFromIeWithoutOweSupported(ie, - "[WPA2-EAP/SHA256-CCMP]" - + "[RSN-EAP/SHA256-CCMP][MFPR][MFPC]"); + "[WPA2-EAP/SHA256-CCMP-128]" + + "[RSN-EAP/SHA256-CCMP-128][MFPR][MFPC]"); } /** @@ -637,8 +637,8 @@ public class InformationElementUtilTest extends WifiBaseTest { (byte) 0xc0, (byte) 0x00, }; verifyCapabilityStringFromIeWithoutOweSupported(ie, - "[WPA2-EAP/SHA256-CCMP]" - + "[RSN-EAP/SHA256-CCMP][MFPR][MFPC]"); + "[WPA2-EAP/SHA256-CCMP-128]" + + "[RSN-EAP/SHA256-CCMP-128][MFPR][MFPC]"); } /** @@ -672,8 +672,8 @@ public class InformationElementUtilTest extends WifiBaseTest { (byte) 0x00, (byte) 0x0F, (byte) 0xAC, (byte) 0x0c, }; verifyCapabilityStringFromIeWithoutOweSupported(ie, - "[WPA2-EAP/SHA1+EAP/SHA256-CCMP]" - + "[RSN-EAP/SHA1+EAP/SHA256-CCMP][MFPC]"); + "[WPA2-EAP/SHA1+EAP/SHA256-CCMP-128]" + + "[RSN-EAP/SHA1+EAP/SHA256-CCMP-128][MFPC]"); } /** @@ -703,7 +703,7 @@ public class InformationElementUtilTest extends WifiBaseTest { (byte) 0x40, (byte) 0x00, }; verifyCapabilityStringFromIeWithoutOweSupported(ie, - "[WPA2-EAP/SHA1-CCMP+TKIP][RSN-EAP/SHA1-CCMP+TKIP][MFPR]"); + "[WPA2-EAP/SHA1-CCMP-128+TKIP][RSN-EAP/SHA1-CCMP-128+TKIP][MFPR]"); } /** @@ -736,7 +736,7 @@ public class InformationElementUtilTest extends WifiBaseTest { (byte) 0x00, (byte) 0x50, (byte) 0xF2, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x50, (byte) 0xF2, (byte) 0x02, (byte) 0x00, (byte) 0x00 }; - verifyCapabilityStringFromIeWithoutOweSupported(ie, "[WPA-PSK-CCMP+TKIP]"); + verifyCapabilityStringFromIeWithoutOweSupported(ie, "[WPA-PSK-CCMP-128+TKIP]"); } /** @@ -757,7 +757,7 @@ public class InformationElementUtilTest extends WifiBaseTest { (byte) 0x01, (byte) 0x00, // AKM count (byte) 0x00, (byte) 0x50, (byte) 0x99, (byte) 0x99, // Unknown AKM (byte) 0x00, (byte) 0x00}; - verifyCapabilityStringFromIeWithoutOweSupported(ie, "[WPA-?-CCMP+TKIP]"); + verifyCapabilityStringFromIeWithoutOweSupported(ie, "[WPA-?-CCMP-128+TKIP]"); } /** @@ -805,7 +805,7 @@ public class InformationElementUtilTest extends WifiBaseTest { 0x1 << 4, false, false, - "[WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][RSN-PSK-CCMP+TKIP]", + "[WPA-PSK-CCMP-128+TKIP][WPA2-PSK-CCMP-128+TKIP][RSN-PSK-CCMP-128+TKIP]", null); } @@ -835,7 +835,7 @@ public class InformationElementUtilTest extends WifiBaseTest { // Padding (byte) 0x00, (byte) 0x00 }; verifyCapabilityStringFromIeWithOweSupported( - ieRsn, "[WPA2-PSK-CCMP][RSN-PSK+SAE-CCMP]", null); + ieRsn, "[WPA2-PSK-CCMP-128][RSN-PSK+SAE-CCMP-128]", null); } /** @@ -863,7 +863,7 @@ public class InformationElementUtilTest extends WifiBaseTest { (byte) 0x00, (byte) 0x0F, (byte) 0xAC, (byte) 0x09, // Padding (byte) 0x00, (byte) 0x00 }; - verifyCapabilityStringFromIeWithOweSupported(ieRsn, "[RSN-SAE+FT/SAE-CCMP]", null); + verifyCapabilityStringFromIeWithOweSupported(ieRsn, "[RSN-SAE+FT/SAE-CCMP-128]", null); } /** @@ -891,7 +891,7 @@ public class InformationElementUtilTest extends WifiBaseTest { (byte) 0x00, (byte) 0x0F, (byte) 0xAC, (byte) 0x18, // Padding (byte) 0x00, (byte) 0x00 }; - verifyCapabilityStringFromIeWithOweSupported(ieRsn, "[RSN-SAE+SAE_EXT_KEY-CCMP]", null); + verifyCapabilityStringFromIeWithOweSupported(ieRsn, "[RSN-SAE+SAE_EXT_KEY-CCMP-128]", null); } /** @@ -921,7 +921,7 @@ public class InformationElementUtilTest extends WifiBaseTest { // Padding (byte) 0x00, (byte) 0x00 }; verifyCapabilityStringFromIeWithOweSupported( - ieRsn, "[RSN-SAE_EXT_KEY+FT/SAE_EXT_KEY-CCMP]", null); + ieRsn, "[RSN-SAE_EXT_KEY+FT/SAE_EXT_KEY-CCMP-128]", null); } /** @@ -947,7 +947,7 @@ public class InformationElementUtilTest extends WifiBaseTest { (byte) 0x00, (byte) 0x0F, (byte) 0xAC, (byte) 0x12, // Padding (byte) 0x00, (byte) 0x00 }; - verifyCapabilityStringFromIeWithOweSupported(ieRsn, "[RSN-OWE-CCMP]", null); + verifyCapabilityStringFromIeWithOweSupported(ieRsn, "[RSN-OWE-CCMP-128]", null); } /** @@ -963,7 +963,8 @@ public class InformationElementUtilTest extends WifiBaseTest { (byte) 0x50, (byte) 0x6F, (byte) 0x9A, (byte) 0x1C, // OWE IE contains BSSID, SSID and channel of other BSS, but we don't parse it. (byte) 0x00, (byte) 0x000, (byte) 0x00, (byte) 0x00 }; - verifyCapabilityStringFromIe(ieOwe, 0x1 << 0, true, "[RSN-OWE_TRANSITION-CCMP][ESS]", null); + verifyCapabilityStringFromIe(ieOwe, 0x1 << 0, true, "[RSN-OWE_TRANSITION-CCMP-128][ESS]", + null); } /** @@ -1043,7 +1044,7 @@ public class InformationElementUtilTest extends WifiBaseTest { (byte) 0x00, (byte) 0x0F, (byte) 0xAC, (byte) 0x0c, }; verifyCapabilityStringFromIeWithoutOweSupported(ieRsn, - "[RSN-EAP_SUITE_B_192-GCMP][MFPR]"); + "[RSN-EAP_SUITE_B_192-GCMP-128][MFPR]"); } /** @@ -1076,8 +1077,8 @@ public class InformationElementUtilTest extends WifiBaseTest { (byte) 0x00, (byte) 0x00 }; verifyCapabilityStringFromIeWithOweSupported( ieRsn, - "[WPA2-EAP/SHA1+EAP/SHA256+EAP-FILS-SHA256-CCMP]" - + "[RSN-EAP/SHA1+EAP/SHA256+EAP-FILS-SHA256-CCMP]", + "[WPA2-EAP/SHA1+EAP/SHA256+EAP-FILS-SHA256-CCMP-128]" + + "[RSN-EAP/SHA1+EAP/SHA256+EAP-FILS-SHA256-CCMP-128]", null); } @@ -1111,8 +1112,8 @@ public class InformationElementUtilTest extends WifiBaseTest { (byte) 0x00, (byte) 0x00 }; verifyCapabilityStringFromIeWithOweSupported( ieRsn, - "[WPA2-EAP/SHA1+EAP/SHA256+EAP-FILS-SHA384-CCMP]" - + "[RSN-EAP/SHA1+EAP/SHA256+EAP-FILS-SHA384-CCMP]", + "[WPA2-EAP/SHA1+EAP/SHA256+EAP-FILS-SHA384-CCMP-128]" + + "[RSN-EAP/SHA1+EAP/SHA256+EAP-FILS-SHA384-CCMP-128]", null); } @@ -1162,7 +1163,7 @@ public class InformationElementUtilTest extends WifiBaseTest { (byte) 0x00 }; verifyCapabilityStringFromIeWithOweSupported( - ieRsn, "[RSN-SAE_EXT_KEY-CCMP]", unknownAkmMap); + ieRsn, "[RSN-SAE_EXT_KEY-CCMP-128]", unknownAkmMap); } /** @@ -1244,7 +1245,8 @@ public class InformationElementUtilTest extends WifiBaseTest { 0x1 << 4, true, true, - "[WPA2-PSK-CCMP][RSN-PSK-CCMP][RSN-SAE-CCMP][RSN-SAE_EXT_KEY-GCMP-256][MFPC][RSNO]", + "[WPA2-PSK-CCMP-128][RSN-PSK-CCMP-128][RSN-SAE-CCMP-128][RSN-SAE_EXT_KEY-GCMP-256" + + "][MFPC][RSNO]", null); } @@ -1306,7 +1308,7 @@ public class InformationElementUtilTest extends WifiBaseTest { 0x1 << 4, true, true, - "[RSN-SAE-CCMP][RSN-SAE_EXT_KEY-GCMP-256][MFPR][MFPC][RSNO]", + "[RSN-SAE-CCMP-128][RSN-SAE_EXT_KEY-GCMP-256][MFPR][MFPC][RSNO]", null); } @@ -1365,7 +1367,7 @@ public class InformationElementUtilTest extends WifiBaseTest { 0x1 << 4, true, false, - "[WPA2-PSK-CCMP][RSN-PSK-CCMP]", + "[WPA2-PSK-CCMP-128][RSN-PSK-CCMP-128]", null); } @@ -1412,7 +1414,7 @@ public class InformationElementUtilTest extends WifiBaseTest { ieWps.bytes = new byte[] { (byte) 0x00, (byte) 0x50, (byte) 0xF2, (byte) 0x04 }; InformationElement[] ies = new InformationElement[] { ieWpa, ieWps }; - verifyCapabilityStringFromIes(ies, 0x1 << 4, false, false, "[WPA-PSK-CCMP+TKIP][WPS]", + verifyCapabilityStringFromIes(ies, 0x1 << 4, false, false, "[WPA-PSK-CCMP-128+TKIP][WPS]", null); } @@ -2893,7 +2895,7 @@ public class InformationElementUtilTest extends WifiBaseTest { (byte) 0x40, (byte) 0x00, }; verifyCapabilityStringFromIeWithoutOweSupported(ie, - "[RSN-PASN+SAE-CCMP+GCMP-256][MFPR]"); + "[RSN-PASN+SAE-CCMP-128+GCMP-256][MFPR]"); } /** |