summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Stephanie Bak <dasol@google.com> 2025-01-13 01:54:30 -0800
committer Stephanie Bak <dasol@google.com> 2025-01-13 20:12:36 +0000
commit8332e84391f6df6af3dd11c93a963afb2e051ce9 (patch)
tree91147865ac7d281b594866d733aadd91fc3b37dc
parent8de0f9b2010957c686e93bf508e8eaec707bd343 (diff)
Revert "P2P Ownership"
This reverts commit 5b05c686840a219068ed14c350013593c32b513f. Reason for revert: punting feature Change-Id: Ie7685410048a1850564393554245c8d78e7fe1fd Bug: 215045910 Test: atest com.android.server.wifi
-rw-r--r--flags/wifi_flags.aconfig8
-rw-r--r--service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java930
-rw-r--r--service/tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java420
3 files changed, 63 insertions, 1295 deletions
diff --git a/flags/wifi_flags.aconfig b/flags/wifi_flags.aconfig
index ae486eec0f..b198e9b06b 100644
--- a/flags/wifi_flags.aconfig
+++ b/flags/wifi_flags.aconfig
@@ -9,14 +9,6 @@ flag {
}
flag {
- name: "p2p_ownership"
- namespace: "wifi"
- description: "Control the P2P group ownership feature"
- bug: "215045910"
- is_fixed_read_only: true
-}
-
-flag {
name: "delay_save_to_store"
namespace: "wifi"
description: "Control the feature delay the save to store in batch to reduce the blocking time"
diff --git a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java
index 9f8bf56366..fcde391839 100644
--- a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java
+++ b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java
@@ -177,7 +177,6 @@ import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -355,8 +354,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
// Messages for interaction with IpClient.
private static final int IPC_PRE_DHCP_ACTION = BASE + 30;
private static final int IPC_POST_DHCP_ACTION = BASE + 31;
- @VisibleForTesting
- static final int IPC_DHCP_RESULTS = BASE + 32;
+ private static final int IPC_DHCP_RESULTS = BASE + 32;
private static final int IPC_PROVISIONING_SUCCESS = BASE + 33;
private static final int IPC_PROVISIONING_FAILURE = BASE + 34;
@VisibleForTesting
@@ -439,16 +437,6 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
private final Map<String, HashSet<ScanResult.InformationElement>> mVendorElements =
new HashMap<>();
- // client(application) P2P group info list, key = package name
- private final Map<String, WifiP2pGroupInfo> mOwnershipMap = new HashMap<>();
-
- // Max number of P2P groups supported
- private static final int MAX_NUM_GROUP = 1;
- // Package name used to represent all shared connections
- private static final String SHARED_PKG_NAME = "__SHARED_PACKAGE_NAME";
- // Ongoing connection request package name with the default value set for shared connection
- private String mConnectionPkgName = SHARED_PKG_NAME;
-
// peer authorizing timestamp which is indexed by the peer MAC address.
private final Map<String, Long> mPeerAuthorizingTimestamp = new HashMap<>();
@@ -483,8 +471,6 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
private final RemoteCallbackList<IWifiP2pListener> mWifiP2pListeners =
new RemoteCallbackList<>();
- // clients(application) P2P listener map, key = package name
- private final Map<String, IWifiP2pListener> mP2pListenerMap = new HashMap<>();
/**
* Error code definition.
@@ -602,18 +588,6 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
mP2pStateMachine.sendMessage(ENABLE_P2P);
}
- /**
- * Stores P2P group information
- */
- private static class WifiP2pGroupInfo {
- public WifiP2pGroup p2pGroup;
- public WifiP2pInfo p2pInfo;
- WifiP2pGroupInfo(WifiP2pGroup group, WifiP2pInfo info) {
- p2pGroup = group;
- p2pInfo = info;
- }
- }
-
// Tracks the ongoing Service discovery request to wpa_supplicant.
private final WifiP2pOngoingServiceDiscoveryRequestInfo mServiceDiscoveryInfo =
new WifiP2pOngoingServiceDiscoveryRequestInfo();
@@ -1137,8 +1111,6 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
AttributionSource source = mClientAttributionSource.remove(binder);
if (null != source) {
mVendorElements.remove(source.getPackageName());
- mOwnershipMap.remove(source.getPackageName());
- mP2pListenerMap.remove(source.getPackageName());
}
}
@@ -1157,24 +1129,6 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
}
}
- /**
- * Get WifiP2pGroupInfo owned by the provided package name
- */
- private WifiP2pGroupInfo getP2pGroupInfo(String packageName) {
- if (mOwnershipMap.containsKey(packageName)) {
- return mOwnershipMap.get(packageName);
- } else if (mOwnershipMap.containsKey(SHARED_PKG_NAME)) {
- return mOwnershipMap.get(SHARED_PKG_NAME);
- }
- return null;
- }
-
- private boolean checkIfPackageIsGroupOwner(String packageName) {
- return !mFeatureFlags.p2pOwnership()
- || mOwnershipMap.containsKey(packageName)
- || mOwnershipMap.containsKey(SHARED_PKG_NAME);
- }
-
/** This is used to provide information to drivers to optimize performance depending
* on the current mode of operation.
* 0 - disabled
@@ -1225,7 +1179,6 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
TAG + " registerWifiP2pListener");
Log.i(TAG, "registerWifiP2pListener uid=" + Binder.getCallingUid());
mWifiP2pListeners.register(listener);
- mP2pListenerMap.put(packageName, listener);
}
/**
@@ -1239,15 +1192,6 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
}
Log.i(TAG, "unregisterWifiP2pListener uid=" + Binder.getCallingUid());
mWifiP2pListeners.unregister(listener);
- Iterator<Map.Entry<String, IWifiP2pListener>> iterator =
- mP2pListenerMap.entrySet().iterator();
- while (iterator.hasNext()) {
- Map.Entry<String, IWifiP2pListener> entry = iterator.next();
- if (entry.getValue() == listener) {
- iterator.remove();
- break;
- }
- }
}
private void onP2pStateChanged(@WifiP2pManager.WifiP2pState int state) {
@@ -1358,57 +1302,53 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
mWifiP2pListeners.finishBroadcast();
}
- private void onGroupCreated(WifiP2pInfo p2pInfo, WifiP2pGroup p2pGroup,
- RemoteCallbackList<IWifiP2pListener> callbackList) {
- int numCallbacks = callbackList.beginBroadcast();
+ private void onGroupCreated(WifiP2pInfo p2pInfo, WifiP2pGroup p2pGroup) {
+ int numCallbacks = mWifiP2pListeners.beginBroadcast();
for (int i = 0; i < numCallbacks; i++) {
try {
- callbackList.getBroadcastItem(i).onGroupCreated(p2pInfo, p2pGroup);
+ mWifiP2pListeners.getBroadcastItem(i).onGroupCreated(p2pInfo, p2pGroup);
} catch (RemoteException e) {
Log.e(TAG, "Failure calling onGroupCreated" + e);
}
}
- callbackList.finishBroadcast();
+ mWifiP2pListeners.finishBroadcast();
}
- private void onPeerClientJoined(WifiP2pInfo p2pInfo, WifiP2pGroup p2pGroup,
- RemoteCallbackList<IWifiP2pListener> callbackList) {
- int numCallbacks = callbackList.beginBroadcast();
+ private void onPeerClientJoined(WifiP2pInfo p2pInfo, WifiP2pGroup p2pGroup) {
+ int numCallbacks = mWifiP2pListeners.beginBroadcast();
for (int i = 0; i < numCallbacks; i++) {
try {
- callbackList.getBroadcastItem(i).onPeerClientJoined(p2pInfo, p2pGroup);
+ mWifiP2pListeners.getBroadcastItem(i).onPeerClientJoined(p2pInfo, p2pGroup);
} catch (RemoteException e) {
Log.e(TAG, "Failure calling onPeerClientJoined" + e);
}
}
- callbackList.finishBroadcast();
+ mWifiP2pListeners.finishBroadcast();
}
- private void onPeerClientDisconnected(WifiP2pInfo p2pInfo, WifiP2pGroup p2pGroup,
- RemoteCallbackList<IWifiP2pListener> callbackList) {
- int numCallbacks = callbackList.beginBroadcast();
+ private void onPeerClientDisconnected(WifiP2pInfo p2pInfo, WifiP2pGroup p2pGroup) {
+ int numCallbacks = mWifiP2pListeners.beginBroadcast();
for (int i = 0; i < numCallbacks; i++) {
try {
- callbackList.getBroadcastItem(i).onPeerClientDisconnected(p2pInfo,
+ mWifiP2pListeners.getBroadcastItem(i).onPeerClientDisconnected(p2pInfo,
p2pGroup);
} catch (RemoteException e) {
Log.e(TAG, "Failure calling onPeerClientDisconnected" + e);
}
}
- callbackList.finishBroadcast();
+ mWifiP2pListeners.finishBroadcast();
}
- private void onFrequencyChanged(WifiP2pInfo p2pInfo, WifiP2pGroup p2pGroup,
- RemoteCallbackList<IWifiP2pListener> callbackList) {
- int numCallbacks = callbackList.beginBroadcast();
+ private void onFrequencyChanged(WifiP2pInfo p2pInfo, WifiP2pGroup p2pGroup) {
+ int numCallbacks = mWifiP2pListeners.beginBroadcast();
for (int i = 0; i < numCallbacks; i++) {
try {
- callbackList.getBroadcastItem(i).onFrequencyChanged(p2pInfo, p2pGroup);
+ mWifiP2pListeners.getBroadcastItem(i).onFrequencyChanged(p2pInfo, p2pGroup);
} catch (RemoteException e) {
Log.e(TAG, "Failure calling onFrequencyChanged" + e);
}
}
- callbackList.finishBroadcast();
+ mWifiP2pListeners.finishBroadcast();
}
private void onGroupRemoved() {
@@ -1495,8 +1435,6 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
new P2pEnabledState(mThreshold, mThreadLocalLog);
// Inactive is when p2p is enabled with no connectivity
private final InactiveState mInactiveState = new InactiveState(mThreshold, mThreadLocalLog);
- // Idle is when p2p is enabled and there's no ongoing connection attempt
- private final IdleState mIdleState = new IdleState(mThreshold, mThreadLocalLog);
private final GroupCreatingState mGroupCreatingState =
new GroupCreatingState(mThreshold, mThreadLocalLog);
private final UserAuthorizingInviteRequestState mUserAuthorizingInviteRequestState =
@@ -1590,7 +1528,6 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
addState(mWaitingState, mP2pDisabledContainerState);
addState(mP2pEnabledState, mDefaultState);
addState(mInactiveState, mP2pEnabledState);
- addState(mIdleState, mP2pEnabledState);
addState(mGroupCreatingState, mP2pEnabledState);
addState(mUserAuthorizingInviteRequestState, mGroupCreatingState);
addState(mUserAuthorizingNegotiationRequestState, mGroupCreatingState);
@@ -1717,25 +1654,6 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
}
}
- private RemoteCallbackList<IWifiP2pListener> generateCallbackList(WifiP2pGroup group) {
- if (!mFeatureFlags.p2pOwnership() || mOwnershipMap.containsKey(SHARED_PKG_NAME)) {
- return mWifiP2pListeners;
- }
-
- for (Map.Entry<String, WifiP2pGroupInfo> entry : mOwnershipMap.entrySet()) {
- if (entry.getValue().p2pGroup.getInterface().equals(group.getInterface())) {
- IWifiP2pListener p2pListener = mP2pListenerMap.get(entry.getKey());
- RemoteCallbackList<IWifiP2pListener> listener = new RemoteCallbackList<>();
- if (p2pListener != null) {
- listener.register(p2pListener);
- logd("WifiP2pListener callback generated for " + entry.getKey());
- }
- return listener;
- }
- }
- return mWifiP2pListeners;
- }
-
@Override
protected String getLogRecString(Message msg) {
StringBuilder sb = new StringBuilder();
@@ -2403,22 +2321,8 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
message.obj));
break;
case WifiP2pManager.REQUEST_CONNECTION_INFO:
- if (mFeatureFlags.p2pOwnership()) {
- String packageName = getCallingPkgName(
- message.sendingUid, message.replyTo);
- WifiP2pGroupInfo groupInfo = getP2pGroupInfo(packageName);
- if (groupInfo != null) {
- replyToMessage(message, WifiP2pManager.RESPONSE_CONNECTION_INFO,
- new WifiP2pInfo(groupInfo.p2pInfo));
- } else {
- logd("No group owned by caller - returning empty info");
- replyToMessage(message, WifiP2pManager.RESPONSE_CONNECTION_INFO,
- new WifiP2pInfo());
- }
- } else {
- replyToMessage(message, WifiP2pManager.RESPONSE_CONNECTION_INFO,
- new WifiP2pInfo(mWifiP2pInfo));
- }
+ replyToMessage(message, WifiP2pManager.RESPONSE_CONNECTION_INFO,
+ new WifiP2pInfo(mWifiP2pInfo));
break;
case WifiP2pManager.REQUEST_GROUP_INFO: {
String packageName = getCallingPkgName(message.sendingUid, message.replyTo);
@@ -2444,19 +2348,8 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
// remain at this state.
break;
}
- if (mFeatureFlags.p2pOwnership()) {
- WifiP2pGroupInfo groupInfo = getP2pGroupInfo(packageName);
- if (groupInfo != null) {
- replyToMessage(message, WifiP2pManager.RESPONSE_GROUP_INFO,
- maybeEraseOwnDeviceAddress(groupInfo.p2pGroup, uid));
- } else {
- logd("No group owned by caller - returning null group");
- replyToMessage(message, WifiP2pManager.RESPONSE_GROUP_INFO, null);
- }
- } else {
- replyToMessage(message, WifiP2pManager.RESPONSE_GROUP_INFO,
- maybeEraseOwnDeviceAddress(mGroup, message.sendingUid));
- }
+ replyToMessage(message, WifiP2pManager.RESPONSE_GROUP_INFO,
+ maybeEraseOwnDeviceAddress(mGroup, message.sendingUid));
break;
}
case WifiP2pManager.REQUEST_PERSISTENT_GROUP_INFO: {
@@ -3049,7 +2942,6 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
}
resetWifiP2pInfo();
mGroup = null;
- mOwnershipMap.clear();
}
@Override
@@ -3174,11 +3066,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
} else if (proceedWithOperation
== InterfaceConflictManager.ICM_EXECUTE_COMMAND) {
if (setupInterface()) {
- if (mFeatureFlags.p2pOwnership()) {
- smTransition(this, mIdleState);
- } else {
- smTransition(this, mInactiveState);
- }
+ smTransition(this, mInactiveState);
}
} // else InterfaceConflictManager.ICM_SKIP_COMMAND_WAIT_FOR_USER: nop
break;
@@ -3256,11 +3144,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
== InterfaceConflictManager.ICM_EXECUTE_COMMAND) {
if (!setupInterface()) return NOT_HANDLED;
deferMessage(message);
- if (mFeatureFlags.p2pOwnership()) {
- smTransition(this, mIdleState);
- } else {
- smTransition(this, mInactiveState);
- }
+ smTransition(this, mInactiveState);
} // else InterfaceConflictManager.ICM_SKIP_COMMAND_WAIT_FOR_USER: nop
break;
}
@@ -4402,551 +4286,6 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
}
}
- class IdleState extends RunnerState {
-
- /**
- * The Runner state Constructor
- *
- * @param threshold the running time threshold in milliseconds
- */
- IdleState(int threshold, @NonNull LocalLog localLog) {
- super(threshold, localLog);
- }
-
- @Override
- public void enterImpl() {
- logSmStateName(this.getName(),
- getCurrentState() != null ? getCurrentState().getName() : "");
- mPeerAuthorizingTimestamp.clear();
- mSavedPeerConfig.invalidate();
- mDetailedState = NetworkInfo.DetailedState.IDLE;
- mConnectionPkgName = SHARED_PKG_NAME;
- scheduleIdleShutdown();
- }
-
- @Override
- public void exitImpl() {
- cancelIdleShutdown();
- }
-
- @Override
- public boolean processMessageImpl(Message message) {
- logSmMessage(getName(), message);
- // Re-schedule the shutdown timer since we got the new operation.
- // only handle commands from clients.
- if (message.what > Protocol.BASE_WIFI_P2P_MANAGER
- && message.what < Protocol.BASE_WIFI_P2P_SERVICE) {
- scheduleIdleShutdown();
- }
- switch (message.what) {
- case WifiP2pManager.CONNECT: {
- String packageName = getCallingPkgName(message.sendingUid, message.replyTo);
- if (packageName == null) {
- replyToMessage(message, WifiP2pManager.CONNECT_FAILED);
- break;
- }
- int uid = message.sendingUid;
- String attributionTag = getCallingFeatureId(uid, message.replyTo);
- Bundle extras = message.getData()
- .getBundle(WifiP2pManager.EXTRA_PARAM_KEY_BUNDLE);
- boolean hasPermission = false;
- if (isPlatformOrTargetSdkLessThanT(packageName, uid)) {
- hasPermission = mWifiPermissionsUtil.checkCanAccessWifiDirect(
- packageName,
- attributionTag,
- uid, false);
- } else {
- hasPermission = checkNearbyDevicesPermission(uid, packageName,
- extras, "CONNECT", message.obj);
- }
- if (!hasPermission) {
- replyToMessage(message, WifiP2pManager.CONNECT_FAILED);
- // remain at this state.
- break;
- }
- mLastCallerInfoManager.put(WifiManager.API_P2P_CONNECT,
- Process.myTid(), uid, 0, packageName, true);
- if (mVerboseLoggingEnabled) logd(getName() + " sending connect");
- WifiP2pConfig config = (WifiP2pConfig)
- extras.getParcelable(WifiP2pManager.EXTRA_PARAM_KEY_CONFIG);
-
- boolean isConnectFailed = false;
- if (isConfigValidAsGroup(config)) {
- mAutonomousGroup = false;
- mWifiNative.p2pStopFind();
- if (mVerboseLoggingEnabled) {
- logd("FAST_CONNECTION GC band freq: " + getGroupOwnerBandToString(
- config.groupOwnerBand));
- }
- if (mWifiNative.p2pGroupAdd(config, true)) {
- reportConnectionEventTakeBugReportIfOverlapped(
- P2pConnectionEvent.CONNECTION_FAST,
- config, WifiMetricsProto.GroupEvent.GROUP_CLIENT, uid,
- attributionTag);
- mConnectionPkgName = packageName;
- smTransition(this, mGroupNegotiationState);
- } else {
- loge("Cannot join a group with config.");
- isConnectFailed = true;
- replyToMessage(message, WifiP2pManager.CONNECT_FAILED);
- }
- } else if (isConfigForV2Connection(config)) {
- // TODO add support for re-invoking V2 persistent connection
- if (isWifiDirect2Enabled()) {
- mAutonomousGroup = false;
- mWifiNative.p2pStopFind();
- if (isConfigForBootstrappingMethodOutOfBand(config)) {
- if (mWifiNative.p2pConnect(config, FORM_GROUP) != null) {
- smTransition(this, mGroupNegotiationState);
- } else {
- isConnectFailed = true;
- }
- } else {
- smTransition(this, mProvisionDiscoveryState);
- }
- } else {
- isConnectFailed = true;
- replyToMessage(message, WifiP2pManager.CONNECT_FAILED);
- }
- } else {
- if (isConfigInvalid(config)) {
- loge("Dropping connect request " + config);
- isConnectFailed = true;
- replyToMessage(message, WifiP2pManager.CONNECT_FAILED);
- } else {
- mAutonomousGroup = false;
- mWifiNative.p2pStopFind();
- if (reinvokePersistentGroup(config, false)) {
- mWifiP2pMetrics.startConnectionEvent(
- P2pConnectionEvent.CONNECTION_REINVOKE,
- config, GroupEvent.GROUP_UNKNOWN, uid, attributionTag);
- smTransition(this, mGroupNegotiationState);
- } else {
- mWifiP2pMetrics.startConnectionEvent(
- P2pConnectionEvent.CONNECTION_FRESH,
- config, GroupEvent.GROUP_UNKNOWN, uid, attributionTag);
- smTransition(this, mProvisionDiscoveryState);
- }
- }
- }
-
- if (!isConnectFailed) {
- mSavedPeerConfig = config;
- mPeers.updateStatus(mSavedPeerConfig.deviceAddress,
- WifiP2pDevice.INVITED);
- sendPeersChangedBroadcast();
- replyToMessage(message, WifiP2pManager.CONNECT_SUCCEEDED);
- }
- break;
- }
- case WifiP2pManager.STOP_DISCOVERY:
- mLastCallerInfoManager.put(WifiManager.API_P2P_STOP_PEER_DISCOVERY,
- Process.myTid(), message.sendingUid, 0,
- getCallingPkgName(message.sendingUid, message.replyTo), true);
- if (mWifiNative.p2pStopFind()) {
- // When discovery stops in inactive state, flush to clear
- // state peer data
- mWifiNative.p2pFlush();
- mServiceDiscoveryInfo.invalidate();
- replyToMessage(message, WifiP2pManager.STOP_DISCOVERY_SUCCEEDED);
- } else {
- replyToMessage(message, WifiP2pManager.STOP_DISCOVERY_FAILED,
- WifiP2pManager.ERROR);
- }
- break;
- case CMD_P2P_IDLE_SHUTDOWN:
- Log.d(TAG, "IdleShutDown message received");
- sendMessage(DISABLE_P2P);
- break;
- case WifiP2pMonitor.P2P_GO_NEGOTIATION_REQUEST_EVENT:
- WifiP2pConfig config = (WifiP2pConfig) message.obj;
- if (isConfigInvalid(config)) {
- loge("Dropping GO neg request " + config);
- break;
- }
- mSavedPeerConfig = config;
- mAutonomousGroup = false;
- mJoinExistingGroup = false;
- mWifiP2pMetrics.startConnectionEvent(
- P2pConnectionEvent.CONNECTION_FRESH,
- config, GroupEvent.GROUP_UNKNOWN, Process.SYSTEM_UID, null);
- smTransition(this, mUserAuthorizingNegotiationRequestState);
- break;
- case WifiP2pMonitor.P2P_INVITATION_RECEIVED_EVENT:
- if (message.obj == null) {
- Log.e(TAG, "Invalid argument(s)");
- break;
- }
- WifiP2pGroup group = (WifiP2pGroup) message.obj;
- WifiP2pDevice owner = group.getOwner();
- if (owner == null) {
- int id = group.getNetworkId();
- if (id < 0) {
- loge("Ignored invitation from null owner");
- break;
- }
-
- String addr = mGroups.getOwnerAddr(id);
- if (addr != null) {
- group.setOwner(new WifiP2pDevice(addr));
- owner = group.getOwner();
- } else {
- loge("Ignored invitation from null owner");
- break;
- }
- }
- config = new WifiP2pConfig();
- config.deviceAddress = group.getOwner().deviceAddress;
- if (isConfigInvalid(config)) {
- loge("Dropping invitation request " + config);
- break;
- }
- mSavedPeerConfig = config;
-
- // Check if we have the owner in peer list and use appropriate
- // wps method. Default is to use PBC.
- if (owner != null && ((owner = mPeers.get(owner.deviceAddress)) != null)) {
- if (owner.wpsPbcSupported()) {
- mSavedPeerConfig.wps.setup = WpsInfo.PBC;
- } else if (owner.wpsKeypadSupported()) {
- mSavedPeerConfig.wps.setup = WpsInfo.KEYPAD;
- } else if (owner.wpsDisplaySupported()) {
- mSavedPeerConfig.wps.setup = WpsInfo.DISPLAY;
- }
- }
-
- mAutonomousGroup = false;
- mJoinExistingGroup = true;
- mWifiP2pMetrics.startConnectionEvent(
- P2pConnectionEvent.CONNECTION_FRESH,
- config, GroupEvent.GROUP_UNKNOWN, Process.SYSTEM_UID, null);
- smTransition(this, mUserAuthorizingInviteRequestState);
- break;
- case WifiP2pMonitor.P2P_PROV_DISC_PBC_REQ_EVENT:
- case WifiP2pMonitor.P2P_PROV_DISC_ENTER_PIN_EVENT:
- // We let the supplicant handle the provision discovery response
- // and wait instead for the GO_NEGOTIATION_REQUEST_EVENT.
- // Handling provision discovery and issuing a p2p_connect before
- // group negotiation comes through causes issues
- break;
- case WifiP2pMonitor.P2P_PROV_DISC_SHOW_PIN_EVENT: {
- if (message.obj == null) {
- Log.e(TAG, "Illegal argument(s)");
- break;
- }
- WifiP2pProvDiscEvent provDisc = (WifiP2pProvDiscEvent) message.obj;
- WifiP2pDevice device = provDisc.device;
- if (device == null) {
- loge("Device entry is null");
- break;
- }
- mSavedPeerConfig = new WifiP2pConfig();
- mSavedPeerConfig.wps.setup = WpsInfo.DISPLAY;
- mSavedPeerConfig.deviceAddress = device.deviceAddress;
- mSavedPeerConfig.wps.pin = provDisc.wpsPin;
- if (SdkLevel.isAtLeastV() && provDisc.getVendorData() != null) {
- mSavedPeerConfig.setVendorData(provDisc.getVendorData());
- }
-
- notifyP2pProvDiscShowPinRequest(provDisc.wpsPin, device.deviceAddress);
- mPeers.updateStatus(device.deviceAddress, WifiP2pDevice.INVITED);
- sendPeersChangedBroadcast();
- smTransition(this, mUserAuthorizingNegotiationRequestState);
- break;
- }
- case WifiP2pMonitor
- .P2P_PROV_DISC_PAIRING_BOOTSTRAPPING_OPPORTUNISTIC_REQ_EVENT: {
- if (processProvDiscPairingBootstrappingOpportunisticRequestEvent(
- (WifiP2pProvDiscEvent) message.obj)) {
- mAutonomousGroup = false;
- mJoinExistingGroup = false;
- smTransition(this, mUserAuthorizingNegotiationRequestState);
- }
- break;
- }
- case WifiP2pMonitor
- .P2P_PROV_DISC_ENTER_PAIRING_BOOTSTRAPPING_PIN_OR_PASSPHRASE_EVENT: {
- if (processProvDiscEnterPairingBootstrappingPinOrPassphraseEvent(
- (WifiP2pProvDiscEvent) message.obj)) {
- mAutonomousGroup = false;
- mJoinExistingGroup = false;
- smTransition(this, mUserAuthorizingNegotiationRequestState);
- }
- break;
- }
- case WifiP2pMonitor
- .P2P_PROV_DISC_SHOW_PAIRING_BOOTSTRAPPING_PIN_OR_PASSPHRASE_EVENT: {
- if (message.obj == null) {
- Log.e(TAG, "Illegal argument(s)");
- break;
- }
- WifiP2pProvDiscEvent provDisc = (WifiP2pProvDiscEvent) message.obj;
- WifiP2pDevice device = provDisc.device;
- if (device == null) {
- loge("Device entry is null");
- break;
- }
- if (processProvDiscShowPairingBootstrappingPinOrPassphraseEvent(provDisc)) {
- mAutonomousGroup = false;
- mJoinExistingGroup = false;
- notifyP2pProvDiscShowPinRequest(provDisc.pairingPinOrPassphrase,
- device.deviceAddress);
- smTransition(this, mUserAuthorizingNegotiationRequestState);
- }
- break;
- }
- case WifiP2pManager.CREATE_GROUP: {
- String packageName = getCallingPkgName(message.sendingUid, message.replyTo);
- if (packageName == null) {
- replyToMessage(message, WifiP2pManager.CREATE_GROUP_FAILED,
- WifiP2pManager.ERROR);
- break;
- }
- int uid = message.sendingUid;
- String attributionTag = getCallingFeatureId(uid, message.replyTo);
- Bundle extras = message.getData()
- .getBundle(WifiP2pManager.EXTRA_PARAM_KEY_BUNDLE);
- boolean hasPermission;
- if (isPlatformOrTargetSdkLessThanT(packageName, uid)) {
- hasPermission = mWifiPermissionsUtil.checkCanAccessWifiDirect(
- packageName,
- attributionTag,
- uid, false);
- } else {
- hasPermission = checkNearbyDevicesPermission(uid, packageName,
- extras, "CREATE_GROUP", message.obj);
- }
- if (!hasPermission) {
- replyToMessage(message, WifiP2pManager.CREATE_GROUP_FAILED,
- WifiP2pManager.ERROR);
- // remain at this state.
- break;
- }
- mAutonomousGroup = true;
- int netId = message.arg1;
- config = extras.getParcelable(WifiP2pManager.EXTRA_PARAM_KEY_CONFIG);
- mLastCallerInfoManager.put(config == null
- ? WifiManager.API_P2P_CREATE_GROUP
- : WifiManager.API_P2P_CREATE_GROUP_P2P_CONFIG,
- Process.myTid(), uid, 0, packageName, true);
- boolean ret = false;
- if (isConfigValidAsGroup(config)) {
- mConnectionPkgName = packageName;
- if (mVerboseLoggingEnabled) {
- logd("FAST_CONNECTION GO band freq: "
- + getGroupOwnerBandToString(config.groupOwnerBand));
- }
- reportConnectionEventTakeBugReportIfOverlapped(
- P2pConnectionEvent.CONNECTION_FAST,
- config, GroupEvent.GROUP_OWNER, uid, attributionTag);
- ret = mWifiNative.p2pGroupAdd(config, false);
- } else if (isConfigForGroupOwnerV2(config)) {
- logd("Requested to create Group Owner - V2");
- // TODO check if the configuration is to start persistent connection.
- // TODO check if the persistent group is present
- if (isWifiDirect2Enabled()) {
- ret = mWifiNative.p2pGroupAdd(false, true);
- }
- } else if (netId == WifiP2pGroup.NETWORK_ID_PERSISTENT) {
- // check if the go persistent group is present.
- netId = mGroups.getNetworkId(mThisDevice.deviceAddress);
- if (netId != -1) {
- mWifiP2pMetrics.startConnectionEvent(
- P2pConnectionEvent.CONNECTION_REINVOKE,
- null, GroupEvent.GROUP_OWNER, uid, attributionTag);
- ret = mWifiNative.p2pGroupAdd(netId, false);
- } else {
- mWifiP2pMetrics.startConnectionEvent(
- P2pConnectionEvent.CONNECTION_LOCAL,
- null, GroupEvent.GROUP_OWNER, uid, attributionTag);
- ret = mWifiNative.p2pGroupAdd(true, false);
- }
- } else {
- mWifiP2pMetrics.startConnectionEvent(
- P2pConnectionEvent.CONNECTION_LOCAL,
- null, GroupEvent.GROUP_OWNER, uid, attributionTag);
- ret = mWifiNative.p2pGroupAdd(false, false);
- }
-
- if (ret) {
- replyToMessage(message, WifiP2pManager.CREATE_GROUP_SUCCEEDED);
- smTransition(this, mGroupNegotiationState);
- } else {
- mConnectionPkgName = SHARED_PKG_NAME;
- replyToMessage(message, WifiP2pManager.CREATE_GROUP_FAILED,
- WifiP2pManager.ERROR);
- // remain at this state.
- String errorMsg = "P2P group creating failed";
- if (mVerboseLoggingEnabled) logd(getName() + errorMsg);
- if (mWifiP2pMetrics.isP2pFastConnectionType()) {
- takeBugReportP2pFailureIfNeeded("Wi-Fi BugReport (P2P "
- + mWifiP2pMetrics.getP2pGroupRoleString()
- + " creation failure)", errorMsg);
- }
- mWifiP2pMetrics.endConnectionEvent(
- P2pConnectionEvent.CLF_CREATE_GROUP_FAILED);
- }
- break;
- }
- case WifiP2pMonitor.P2P_GROUP_STARTED_EVENT:
- if (message.obj == null) {
- Log.e(TAG, "Invalid argument(s)");
- break;
- }
- mGroup = (WifiP2pGroup) message.obj;
- if (mVerboseLoggingEnabled) logd(getName() + " group started");
- if (mGroup.isGroupOwner()
- && EMPTY_DEVICE_ADDRESS.equals(mGroup.getOwner().deviceAddress)) {
- // wpa_supplicant doesn't set own device address to go_dev_addr.
- mGroup.getOwner().deviceAddress = mThisDevice.deviceAddress;
- }
- // We hit this scenario when a persistent group is reinvoked
- if (mGroup.getNetworkId() == WifiP2pGroup.NETWORK_ID_PERSISTENT) {
- mAutonomousGroup = false;
- deferMessage(message);
- smTransition(this, mGroupNegotiationState);
- } else {
- loge("Unexpected group creation, remove " + mGroup);
- mWifiNative.p2pGroupRemove(mGroup.getInterface());
- mGroup = null;
- }
- break;
- case WifiP2pManager.START_LISTEN:
- String packageName = getCallingPkgName(message.sendingUid, message.replyTo);
- if (packageName == null) {
- replyToMessage(message, WifiP2pManager.START_LISTEN_FAILED);
- break;
- }
- int uid = message.sendingUid;
- int listenType = message.arg1;
- if (listenType == WifiP2pManager.WIFI_P2P_EXT_LISTEN_WITH_PARAMS
- && !SdkLevel.isAtLeastV()) {
- replyToMessage(message, WifiP2pManager.START_LISTEN_FAILED);
- break;
- }
- Bundle extras = message.getData()
- .getBundle(WifiP2pManager.EXTRA_PARAM_KEY_BUNDLE);
- WifiP2pExtListenParams extListenParams = SdkLevel.isAtLeastV()
- && (listenType == WifiP2pManager.WIFI_P2P_EXT_LISTEN_WITH_PARAMS)
- ? extras.getParcelable(
- WifiP2pManager.EXTRA_PARAM_KEY_EXT_LISTEN_PARAMS,
- WifiP2pExtListenParams.class)
- : null;
- boolean hasPermission;
- if (isPlatformOrTargetSdkLessThanT(packageName, uid)) {
- hasPermission = mWifiPermissionsUtil.checkCanAccessWifiDirect(
- packageName,
- getCallingFeatureId(message.sendingUid, message.replyTo),
- uid, true);
- } else {
- hasPermission = checkNearbyDevicesPermission(uid, packageName,
- extras, "START_LISTEN", message.obj);
- }
- if (!hasPermission) {
- replyToMessage(message, WifiP2pManager.START_LISTEN_FAILED);
- break;
- }
- mLastCallerInfoManager.put(WifiManager.API_P2P_START_LISTENING,
- Process.myTid(), uid, 0, packageName, true);
- if (mVerboseLoggingEnabled) logd(getName() + " start listen mode");
- mWifiNative.p2pStopFind();
- if (mWifiNative.p2pExtListen(true,
- mContext.getResources().getInteger(
- R.integer.config_wifiP2pExtListenPeriodMs),
- mContext.getResources().getInteger(
- R.integer.config_wifiP2pExtListenIntervalMs),
- extListenParams)) {
- replyToMessage(message, WifiP2pManager.START_LISTEN_SUCCEEDED);
- sendP2pListenChangedBroadcast(true);
- } else {
- replyToMessage(message, WifiP2pManager.START_LISTEN_FAILED);
- }
- break;
- case WifiP2pManager.STOP_LISTEN:
- mLastCallerInfoManager.put(WifiManager.API_P2P_STOP_LISTENING,
- Process.myTid(), message.sendingUid, 0,
- getCallingPkgName(message.sendingUid, message.replyTo), true);
- if (mVerboseLoggingEnabled) logd(getName() + " stop listen mode");
- if (mWifiNative.p2pExtListen(false, 0, 0, null)) {
- replyToMessage(message, WifiP2pManager.STOP_LISTEN_SUCCEEDED);
- sendP2pListenChangedBroadcast(false);
- } else {
- replyToMessage(message, WifiP2pManager.STOP_LISTEN_FAILED);
- }
- mWifiNative.p2pStopFind();
- break;
- case WifiP2pManager.SET_CHANNEL:
- if (!checkNetworkSettingsOrNetworkStackOrOverrideWifiConfigPermission(
- message.sendingUid)) {
- loge("Permission violation - none of NETWORK_SETTING, NETWORK_STACK,"
- + " or OVERRIDE_WIFI_CONFIG permission, uid = "
- + message.sendingUid);
- replyToMessage(message, WifiP2pManager.SET_CHANNEL_FAILED,
- WifiP2pManager.ERROR);
- break;
- }
- if (message.obj == null) {
- Log.e(TAG, "Illegal arguments(s)");
- break;
- }
- mLastCallerInfoManager.put(WifiManager.API_P2P_SET_CHANNELS,
- Process.myTid(), message.sendingUid, 0,
- getCallingPkgName(message.sendingUid, message.replyTo), true);
- Bundle p2pChannels = (Bundle) message.obj;
- mUserListenChannel = p2pChannels.getInt("lc", 0);
- mUserOperatingChannel = p2pChannels.getInt("oc", 0);
- if (updateP2pChannels()) {
- replyToMessage(message, WifiP2pManager.SET_CHANNEL_SUCCEEDED);
- } else {
- replyToMessage(message, WifiP2pManager.SET_CHANNEL_FAILED);
- }
- break;
- case WifiP2pManager.INITIATOR_REPORT_NFC_HANDOVER:
- String handoverSelect = null;
-
- if (message.obj != null) {
- handoverSelect = ((Bundle) message.obj)
- .getString(WifiP2pManager.EXTRA_HANDOVER_MESSAGE);
- }
-
- if (handoverSelect != null
- && mWifiNative.initiatorReportNfcHandover(handoverSelect)) {
- replyToMessage(message, WifiP2pManager.REPORT_NFC_HANDOVER_SUCCEEDED);
- smTransition(this, mGroupCreatingState);
- } else {
- replyToMessage(message, WifiP2pManager.REPORT_NFC_HANDOVER_FAILED);
- }
- break;
- case WifiP2pManager.RESPONDER_REPORT_NFC_HANDOVER:
- String handoverRequest = null;
-
- if (message.obj != null) {
- handoverRequest = ((Bundle) message.obj)
- .getString(WifiP2pManager.EXTRA_HANDOVER_MESSAGE);
- }
-
- if (handoverRequest != null
- && mWifiNative.responderReportNfcHandover(handoverRequest)) {
- replyToMessage(message, WifiP2pManager.REPORT_NFC_HANDOVER_SUCCEEDED);
- smTransition(this, mGroupCreatingState);
- } else {
- replyToMessage(message, WifiP2pManager.REPORT_NFC_HANDOVER_FAILED);
- }
- break;
- default:
- return NOT_HANDLED;
- }
- return HANDLED;
- }
-
- @Override
- public String getMessageLogRec(int what) {
- return P2pStateMachine.class.getSimpleName() + "."
- + this.getClass().getSimpleName()
- + "." + getWhatToString(what);
- }
- }
-
class P2pRejectWaitState extends RunnerState {
/**
@@ -4986,11 +4325,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
WifiP2pManager.CANCEL_CONNECT_SUCCEEDED);
}
}
- if (mFeatureFlags.p2pOwnership()) {
- smTransition(this, mIdleState);
- } else {
- smTransition(this, mInactiveState);
- }
+ transitionTo(mInactiveState);
} else {
loge(
"Stale P2p rejection resume after delay - cached index: "
@@ -5060,11 +4395,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
P2pConnectionEvent.CLF_TIMEOUT);
handleGroupCreationFailure(
WifiP2pManager.GROUP_CREATION_FAILURE_REASON_TIMED_OUT);
- if (mFeatureFlags.p2pOwnership()) {
- smTransition(this, mIdleState);
- } else {
- smTransition(this, mInactiveState);
- }
+ smTransition(this, mInactiveState);
}
break;
case WifiP2pMonitor.P2P_DEVICE_LOST_EVENT:
@@ -5116,16 +4447,6 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
// discovery or for a pending user action, but at the framework
// level, we always treat cancel as succeeded and enter
// an inactive state
- String packageName = getCallingPkgName(message.sendingUid, message.replyTo);
- if (mFeatureFlags.p2pOwnership()
- && mConnectionPkgName != packageName
- && mConnectionPkgName != SHARED_PKG_NAME) {
- replyToMessage(message, WifiP2pManager.CANCEL_CONNECT_FAILED,
- WifiP2pManager.BUSY);
- logd("Cancel connect requested by " + packageName
- + " when connection is initiated by " + mConnectionPkgName);
- break;
- }
mLastCallerInfoManager.put(WifiManager.API_P2P_CANCEL_CONNECT,
Process.myTid(), message.sendingUid, 0,
getCallingPkgName(message.sendingUid, message.replyTo), true);
@@ -5238,11 +4559,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
mWifiNative.p2pCancelConnect();
handleGroupCreationFailure(
WifiP2pManager.GROUP_CREATION_FAILURE_REASON_USER_REJECTED);
- if (mFeatureFlags.p2pOwnership()) {
- smTransition(this, mIdleState);
- } else {
- smTransition(this, mInactiveState);
- }
+ smTransition(this, mInactiveState);
}
break;
case PEER_CONNECTION_USER_CONFIRM:
@@ -5258,11 +4575,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
loge("provision discovery failed status: " + message.arg1);
handleGroupCreationFailure(WifiP2pManager
.GROUP_CREATION_FAILURE_REASON_PROVISION_DISCOVERY_FAILED);
- if (mFeatureFlags.p2pOwnership()) {
- smTransition(this, mIdleState);
- } else {
- smTransition(this, mInactiveState);
- }
+ smTransition(this, mInactiveState);
break;
case WifiP2pManager.SET_CONNECTION_REQUEST_RESULT: {
if (!handleSetConnectionResult(message,
@@ -5342,21 +4655,13 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
if (mVerboseLoggingEnabled) {
logd("User rejected invitation " + mSavedPeerConfig);
}
- if (mFeatureFlags.p2pOwnership()) {
- smTransition(this, mIdleState);
- } else {
- smTransition(this, mInactiveState);
- }
+ smTransition(this, mInactiveState);
break;
case WifiP2pMonitor.P2P_PROV_DISC_FAILURE_EVENT:
loge("provision discovery failed status: " + message.arg1);
handleGroupCreationFailure(WifiP2pManager
.GROUP_CREATION_FAILURE_REASON_PROVISION_DISCOVERY_FAILED);
- if (mFeatureFlags.p2pOwnership()) {
- smTransition(this, mIdleState);
- } else {
- smTransition(this, mInactiveState);
- }
+ smTransition(this, mInactiveState);
break;
case WifiP2pManager.SET_CONNECTION_REQUEST_RESULT:
if (!handleSetConnectionResult(message,
@@ -5590,11 +4895,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
P2pConnectionEvent.CLF_PROV_DISC_FAIL);
handleGroupCreationFailure(WifiP2pManager
.GROUP_CREATION_FAILURE_REASON_PROVISION_DISCOVERY_FAILED);
- if (mFeatureFlags.p2pOwnership()) {
- smTransition(this, mIdleState);
- } else {
- smTransition(this, mInactiveState);
- }
+ smTransition(this, mInactiveState);
break;
default:
return NOT_HANDLED;
@@ -5665,6 +4966,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
mGroup.setNetworkId(mGroups.getNetworkId(devAddr,
mGroup.getNetworkName()));
}
+
if (mGroup.isGroupOwner()) {
// Setting an idle time out on GO causes issues with certain scenarios
// on clients where it can be off-channel for longer and with the power
@@ -5694,12 +4996,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
}
break;
}
- if (mOwnershipMap.size() >= MAX_NUM_GROUP) {
- Log.wtf(TAG, "group size= " + mOwnershipMap.size()
- + " exceeds max number of p2p group supported");
- }
- mOwnershipMap.put(
- mConnectionPkgName, new WifiP2pGroupInfo(mGroup, null));
+
mWifiNative.setP2pGroupIdle(mGroup.getInterface(), GROUP_IDLE_TIME_S);
Log.d(TAG, "start Ip client with provisioning mode: "
+ mSavedPeerConfig.getGroupClientIpProvisioningMode());
@@ -5738,15 +5035,6 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
if (!interfaces.contains(mGroup.getInterface())) break;
Log.d(TAG, "tether " + mGroup.getInterface() + " ready");
- if (mOwnershipMap.size() > MAX_NUM_GROUP) {
- Log.wtf(TAG, "group size= " + mOwnershipMap.size()
- + " exceeds max number of p2p group supported");
- }
- WifiP2pGroupInfo groupInfo = mOwnershipMap.putIfAbsent(mConnectionPkgName,
- new WifiP2pGroupInfo(mGroup, null));
- if (groupInfo != null) {
- groupInfo.p2pGroup = mGroup;
- }
smTransition(this, mGroupCreatedState);
break;
case WifiP2pMonitor.P2P_GO_NEGOTIATION_FAILURE_EVENT:
@@ -5768,11 +5056,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
P2pConnectionEvent.CLF_GROUP_REMOVED);
handleGroupCreationFailure(
WifiP2pManager.GROUP_CREATION_FAILURE_REASON_GROUP_REMOVED);
- if (mFeatureFlags.p2pOwnership()) {
- smTransition(this, mIdleState);
- } else {
- smTransition(this, mInactiveState);
- }
+ smTransition(this, mInactiveState);
break;
case WifiP2pMonitor.P2P_GROUP_FORMATION_FAILURE_EVENT:
// A group formation failure is always followed by
@@ -5844,11 +5128,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
P2pConnectionEvent.CLF_INVITATION_FAIL);
handleGroupCreationFailure(
WifiP2pManager.GROUP_CREATION_FAILURE_REASON_INVITATION_FAILED);
- if (mFeatureFlags.p2pOwnership()) {
- smTransition(this, mIdleState);
- } else {
- smTransition(this, mInactiveState);
- }
+ smTransition(this, mInactiveState);
}
break;
case WifiP2pMonitor.P2P_PROV_DISC_FAILURE_EVENT:
@@ -5857,11 +5137,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
P2pConnectionEvent.CLF_GROUP_REMOVED);
handleGroupCreationFailure(WifiP2pManager
.GROUP_CREATION_FAILURE_REASON_PROVISION_DISCOVERY_FAILED);
- if (mFeatureFlags.p2pOwnership()) {
- smTransition(this, mIdleState);
- } else {
- smTransition(this, mInactiveState);
- }
+ smTransition(this, mInactiveState);
break;
case WifiP2pMonitor.AP_STA_CONNECTED_EVENT:
case WifiP2pMonitor.AP_STA_DISCONNECTED_EVENT:
@@ -6012,11 +5288,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
P2pConnectionEvent.CLF_USER_REJECT);
handleGroupCreationFailure(
WifiP2pManager.GROUP_CREATION_FAILURE_REASON_USER_REJECTED);
- if (mFeatureFlags.p2pOwnership()) {
- smTransition(this, mIdleState);
- } else {
- smTransition(this, mInactiveState);
- }
+ smTransition(this, mInactiveState);
break;
case DROP_WIFI_USER_ACCEPT:
mFrequencyConflictDialog = null;
@@ -6029,11 +5301,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
if (mVerboseLoggingEnabled) {
logd(getName() + "Wifi disconnected, retry p2p");
}
- if (mFeatureFlags.p2pOwnership()) {
- smTransition(this, mIdleState);
- } else {
- smTransition(this, mInactiveState);
- }
+ smTransition(this, mInactiveState);
p2pReconnect();
break;
default:
@@ -6095,8 +5363,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
// In case of a negotiation group, connection changed is sent
// after a client joins. For autonomous, send now
if (mAutonomousGroup) {
- onGroupCreated(new WifiP2pInfo(mWifiP2pInfo), eraseOwnDeviceAddress(mGroup),
- generateCallbackList(mGroup));
+ onGroupCreated(new WifiP2pInfo(mWifiP2pInfo), eraseOwnDeviceAddress(mGroup));
sendP2pConnectionChangedBroadcast();
}
@@ -6143,12 +5410,10 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
}
if (!mAutonomousGroup && mGroup.getClientList().size() == 1) {
onGroupCreated(new WifiP2pInfo(mWifiP2pInfo),
- eraseOwnDeviceAddress(mGroup),
- generateCallbackList(mGroup));
+ eraseOwnDeviceAddress(mGroup));
}
onPeerClientJoined(new WifiP2pInfo(mWifiP2pInfo),
- eraseOwnDeviceAddress(mGroup),
- generateCallbackList(mGroup));
+ eraseOwnDeviceAddress(mGroup));
sendP2pConnectionChangedBroadcast();
break;
}
@@ -6172,8 +5437,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
// when this happens at exit()
} else {
onPeerClientDisconnected(new WifiP2pInfo(mWifiP2pInfo),
- eraseOwnDeviceAddress(mGroup),
- generateCallbackList(mGroup));
+ eraseOwnDeviceAddress(mGroup));
// Notify when a client disconnects from group
sendP2pConnectionChangedBroadcast();
}
@@ -6264,8 +5528,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
loge("Failed to add iface to local network " + e);
}
onGroupCreated(new WifiP2pInfo(mWifiP2pInfo),
- eraseOwnDeviceAddress(mGroup),
- generateCallbackList(mGroup));
+ eraseOwnDeviceAddress(mGroup));
sendP2pConnectionChangedBroadcast();
break;
case IPC_PROVISIONING_SUCCESS:
@@ -6291,8 +5554,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
if (goInterfaceMacAddress == null) {
setWifiP2pInfoOnGroupFormationWithInetAddress(null);
onGroupCreated(new WifiP2pInfo(mWifiP2pInfo),
- eraseOwnDeviceAddress(mGroup),
- generateCallbackList(mGroup));
+ eraseOwnDeviceAddress(mGroup));
sendP2pConnectionChangedBroadcast();
break;
}
@@ -6304,8 +5566,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
NetworkInterface.getByName(mGroup.getInterface()));
setWifiP2pInfoOnGroupFormationWithInetAddress(goIp);
onGroupCreated(new WifiP2pInfo(mWifiP2pInfo),
- eraseOwnDeviceAddress(mGroup),
- generateCallbackList(mGroup));
+ eraseOwnDeviceAddress(mGroup));
sendP2pConnectionChangedBroadcast();
} catch (UnknownHostException | SocketException e) {
loge("Unable to retrieve link-local IPv6 address of group owner "
@@ -6317,32 +5578,21 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
loge("IP provisioning failed");
mWifiNative.p2pGroupRemove(mGroup.getInterface());
break;
- case WifiP2pManager.REMOVE_GROUP: {
- String packageName = getCallingPkgName(message.sendingUid, message.replyTo);
- if (!checkIfPackageIsGroupOwner(packageName)
- && message.sendingUid != Process.SYSTEM_UID) {
- replyToMessage(message, WifiP2pManager.REMOVE_GROUP_FAILED,
- WifiP2pManager.BUSY);
- break;
- }
+ case WifiP2pManager.REMOVE_GROUP:
mLastCallerInfoManager.put(WifiManager.API_P2P_REMOVE_GROUP,
- Process.myTid(), message.sendingUid, 0, packageName, true);
+ Process.myTid(), message.sendingUid, 0,
+ getCallingPkgName(message.sendingUid, message.replyTo), true);
if (mVerboseLoggingEnabled) logd(getName() + " remove group");
if (mWifiNative.p2pGroupRemove(mGroup.getInterface())) {
smTransition(this, mOngoingGroupRemovalState);
replyToMessage(message, WifiP2pManager.REMOVE_GROUP_SUCCEEDED);
} else {
- handleGroupRemoved(packageName);
- if (mFeatureFlags.p2pOwnership()) {
- smTransition(this, mIdleState);
- } else {
- smTransition(this, mInactiveState);
- }
+ handleGroupRemoved();
+ smTransition(this, mInactiveState);
replyToMessage(message, WifiP2pManager.REMOVE_GROUP_FAILED,
WifiP2pManager.ERROR);
}
break;
- }
case WifiP2pMonitor.P2P_GROUP_REMOVED_EVENT:
// We do not listen to NETWORK_DISCONNECTION_EVENT for group removal
// handling since supplicant actually tries to reconnect after a temporary
@@ -6355,26 +5605,8 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
// Treating network disconnection as group removal causes race conditions
// since supplicant would still maintain the group at that stage.
if (mVerboseLoggingEnabled) logd(getName() + " group removed");
-
- if (message.obj == null) {
- Log.e(TAG, "Illegal arguments");
- break;
- }
- String pkgName = SHARED_PKG_NAME;
- WifiP2pGroup group = (WifiP2pGroup) message.obj;
- for (Map.Entry<String, WifiP2pGroupInfo> entry : mOwnershipMap.entrySet()) {
- if (entry.getValue().p2pGroup.getInterface().equals(
- group.getInterface())) {
- pkgName = entry.getKey();
- break;
- }
- }
- handleGroupRemoved(pkgName);
- if (mFeatureFlags.p2pOwnership()) {
- smTransition(this, mIdleState);
- } else {
- smTransition(this, mInactiveState);
- }
+ handleGroupRemoved();
+ smTransition(this, mInactiveState);
break;
case WifiP2pMonitor.P2P_DEVICE_LOST_EVENT:
if (message.obj == null) {
@@ -6448,12 +5680,6 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
// remain at this state.
break;
}
- if (!checkIfPackageIsGroupOwner(packageName)) {
- replyToMessage(message, WifiP2pManager.CONNECT_FAILED,
- WifiP2pManager.BUSY);
- logd("Cannot perform invitation connection due to lack of ownership");
- break;
- }
mLastCallerInfoManager.put(WifiManager.API_P2P_CONNECT,
Process.myTid(), uid, 0, packageName, true);
WifiP2pConfig config = (WifiP2pConfig)
@@ -6469,9 +5695,6 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
mPeers.updateStatus(config.deviceAddress, WifiP2pDevice.INVITED);
sendPeersChangedBroadcast();
replyToMessage(message, WifiP2pManager.CONNECT_SUCCEEDED);
- if (mOwnershipMap.containsKey(packageName)) {
- mConnectionPkgName = packageName;
- }
} else {
replyToMessage(message, WifiP2pManager.CONNECT_FAILED,
WifiP2pManager.ERROR);
@@ -6568,17 +5791,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
case WifiP2pMonitor.P2P_GROUP_STARTED_EVENT:
loge("Duplicate group creation event notice, ignore");
break;
- case WifiP2pManager.CANCEL_CONNECT: {
- String packageName = getCallingPkgName(message.sendingUid, message.replyTo);
- if (mFeatureFlags.p2pOwnership()
- && mConnectionPkgName != packageName
- && mConnectionPkgName != SHARED_PKG_NAME) {
- replyToMessage(message, WifiP2pManager.CANCEL_CONNECT_FAILED,
- WifiP2pManager.BUSY);
- logd("Cancel invitation connect requested by " + packageName
- + " when connection is initiated by " + mConnectionPkgName);
- break;
- }
+ case WifiP2pManager.CANCEL_CONNECT:
mLastCallerInfoManager.put(WifiManager.API_P2P_CANCEL_CONNECT,
Process.myTid(), message.sendingUid, 0,
getCallingPkgName(message.sendingUid, message.replyTo), true);
@@ -6598,13 +5811,11 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
replyToMessage(message, WifiP2pManager.CANCEL_CONNECT_SUCCEEDED);
break;
- }
case WifiP2pMonitor.P2P_FREQUENCY_CHANGED_EVENT:
if (mGroup != null) {
mGroup.setFrequency(message.arg1);
onFrequencyChanged(new WifiP2pInfo(mWifiP2pInfo),
- eraseOwnDeviceAddress(mGroup),
- generateCallbackList(mGroup));
+ eraseOwnDeviceAddress(mGroup));
sendP2pConnectionChangedBroadcast();
}
break;
@@ -6731,6 +5942,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
break;
case PEER_CONNECTION_USER_REJECT:
if (mVerboseLoggingEnabled) logd("User rejected incoming request");
+ mSavedPeerConfig.invalidate();
smTransition(this, mGroupCreatedState);
break;
case WifiP2pManager.SET_CONNECTION_REQUEST_RESULT:
@@ -6935,12 +6147,6 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
broadcastOptions.setRequireNoneOfPermissions(excludedPermissionsList.toArray(
new String[0]));
}
- // remove package name from intent for ownership
- if (mFeatureFlags.p2pOwnership()
- && intent.getAction().equals(
- WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION)) {
- intent = getP2pConnectionChangedIntent(true);
- }
context.sendBroadcast(intent, null, broadcastOptions.toBundle());
}
}
@@ -6965,25 +6171,18 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
sendBroadcastWithExcludedPermissions(intent, null);
}
- private Intent getP2pConnectionChangedIntent(boolean tethering) {
+ private Intent getP2pConnectionChangedIntent() {
Intent intent = new Intent(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
intent.putExtra(WifiP2pManager.EXTRA_WIFI_P2P_INFO, new WifiP2pInfo(mWifiP2pInfo));
intent.putExtra(WifiP2pManager.EXTRA_NETWORK_INFO, makeNetworkInfo());
intent.putExtra(WifiP2pManager.EXTRA_WIFI_P2P_GROUP, eraseOwnDeviceAddress(mGroup));
- if (tethering || !mFeatureFlags.p2pOwnership()) return intent;
- if (!mOwnershipMap.containsKey(SHARED_PKG_NAME)) {
- for (String pkg : mOwnershipMap.keySet()) {
- intent.setPackage(pkg);
- logd("sending p2p connection changed broadcast to only " + pkg);
- }
- }
return intent;
}
private void sendP2pConnectionChangedBroadcast() {
if (mVerboseLoggingEnabled) logd("sending p2p connection changed broadcast");
- Intent intent = getP2pConnectionChangedIntent(false);
+ Intent intent = getP2pConnectionChangedIntent();
if (SdkLevel.isAtLeastU()) {
// First send direct foreground broadcast to Tethering package and system service
// with same android.permission.MAINLINE_NETWORK_STACK
@@ -7090,7 +6289,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
if (TextUtils.isEmpty(tetheringServicePackage)) return false;
Log.i(TAG, "sending p2p tether request broadcast to " + tetheringServicePackage
+ " with permission " + Arrays.toString(permissions));
- Intent intent = getP2pConnectionChangedIntent(true);
+ Intent intent = getP2pConnectionChangedIntent();
if (setAdditionalFlags) {
intent.addFlags(flags);
}
@@ -7102,7 +6301,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
private void sendBroadcastWithMainlineNetworkStackPermissionPostU() {
String[] receiverPermissions = RECEIVER_PERMISSIONS_MAINLINE_NETWORK_STACK;
- Intent intent = getP2pConnectionChangedIntent(true);
+ Intent intent = getP2pConnectionChangedIntent();
// Adding the flag to allow recipient to run at foreground priority with a shorter
// timeout interval.
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
@@ -8264,11 +7463,6 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
mWifiP2pInfo.groupFormed = true;
mWifiP2pInfo.isGroupOwner = mGroup.isGroupOwner();
mWifiP2pInfo.groupOwnerAddress = serverAddress;
- WifiP2pGroupInfo groupInfo = mOwnershipMap.putIfAbsent(
- mConnectionPkgName, new WifiP2pGroupInfo(null, mWifiP2pInfo));
- if (groupInfo != null) {
- groupInfo.p2pInfo = mWifiP2pInfo;
- }
}
private void resetWifiP2pInfo() {
@@ -8563,7 +7757,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
sendDisconnectWifiRequest(false);
}
- private void handleGroupRemoved(String packageName) {
+ private void handleGroupRemoved() {
if (mGroup.isGroupOwner()) {
// {@link com.android.server.connectivity.Tethering} listens to
// {@link WifiP2pManager#WIFI_P2P_CONNECTION_CHANGED_ACTION}
@@ -8601,12 +7795,6 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
sendPeersChangedBroadcast();
}
- if (mOwnershipMap.containsKey(packageName)) {
- mOwnershipMap.remove(packageName);
- } else {
- mOwnershipMap.remove(SHARED_PKG_NAME);
- }
-
mGroup = null;
mPeersLostDuringConnection.clear();
mServiceDiscoveryInfo.invalidate();
diff --git a/service/tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java b/service/tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java
index 0faa872bdf..b5509e0c2e 100644
--- a/service/tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java
+++ b/service/tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java
@@ -29,7 +29,6 @@ import static com.android.server.wifi.WifiSettingsConfigStore.WIFI_P2P_DEVICE_AD
import static com.android.server.wifi.WifiSettingsConfigStore.WIFI_P2P_DEVICE_NAME;
import static com.android.server.wifi.WifiSettingsConfigStore.WIFI_P2P_PENDING_FACTORY_RESET;
import static com.android.server.wifi.WifiSettingsConfigStore.WIFI_VERBOSE_LOGGING_ENABLED;
-import static com.android.server.wifi.p2p.WifiP2pServiceImpl.IPC_DHCP_RESULTS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -79,7 +78,6 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.location.LocationManager;
import android.net.ConnectivityManager;
-import android.net.DhcpResultsParcelable;
import android.net.InetAddresses;
import android.net.LinkAddress;
import android.net.MacAddress;
@@ -206,7 +204,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest {
private static final String thisDeviceName = "thisDeviceName";
private static final String ANONYMIZED_DEVICE_ADDRESS = "02:00:00:00:00:00";
private static final String TEST_PACKAGE_NAME = "com.p2p.test";
- private static final String TEST_PACKAGE2_NAME = "com.p2p.test2";
private static final String TEST_NETWORK_NAME = "DIRECT-xy-NEW";
private static final String TEST_ANDROID_ID = "314Deadbeef";
private static final String[] TEST_REQUIRED_PERMISSIONS_T =
@@ -238,10 +235,8 @@ public class WifiP2pServiceImplTest extends WifiBaseTest {
private BroadcastReceiver mTetherStateReceiver;
private BroadcastReceiver mUserRestrictionReceiver;
private Handler mClientHandler;
- private Handler mClient2Handler;
private Messenger mP2pStateMachineMessenger;
private Messenger mClientMessenger;
- private Messenger mClient2Messenger;
private WifiP2pServiceImpl mWifiP2pServiceImpl;
private TestLooper mClientHanderLooper;
private TestLooper mLooper;
@@ -262,7 +257,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest {
private TetheringManager.TetheringEventCallback mTetheringEventCallback;
private Bundle mExtras = new Bundle();
private IWifiP2pListener mP2pListener = mock(IWifiP2pListener.class);
- private IWifiP2pListener mP2pListener2 = mock(IWifiP2pListener.class);
private ArgumentCaptor<WifiSettingsConfigStore.OnSettingsChangedListener>
mD2DAllowedSettingsCallbackCaptor =
ArgumentCaptor.forClass(WifiSettingsConfigStore.OnSettingsChangedListener.class);
@@ -663,10 +657,9 @@ public class WifiP2pServiceImplTest extends WifiBaseTest {
/**
* Send WifiP2pMonitor.P2P_GROUP_REMOVED_EVENT.
*/
- private void sendGroupRemovedMsg(WifiP2pGroup group) throws Exception {
+ private void sendGroupRemovedMsg() throws Exception {
Message msg = Message.obtain();
msg.what = WifiP2pMonitor.P2P_GROUP_REMOVED_EVENT;
- msg.obj = group;
mP2pStateMachineMessenger.send(Message.obtain(msg));
mLooper.dispatchAll();
}
@@ -1395,9 +1388,7 @@ public class WifiP2pServiceImplTest extends WifiBaseTest {
generatorTestData();
mClientHanderLooper = new TestLooper();
mClientHandler = spy(new Handler(mClientHanderLooper.getLooper()));
- mClient2Handler = spy(new Handler(mClientHanderLooper.getLooper()));
mClientMessenger = new Messenger(mClientHandler);
- mClient2Messenger = new Messenger(mClient2Handler);
mLooper = new TestLooper();
when(mContext.getSystemService(Context.ALARM_SERVICE))
@@ -1531,7 +1522,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest {
when(mDeviceConfigFacade.isP2pFailureBugreportEnabled()).thenReturn(false);
when(mContext.getSystemService(TetheringManager.class)).thenReturn(mTetheringManager);
when(mP2pListener.asBinder()).thenReturn(mock(IBinder.class));
- when(mP2pListener2.asBinder()).thenReturn(mock(IBinder.class));
mWifiP2pServiceImpl = new WifiP2pServiceImpl(mContext, mWifiInjector);
if (supported) {
@@ -1600,7 +1590,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest {
mWifiP2pServiceImpl.handleBootCompleted();
if (SdkLevel.isAtLeastT()) {
mWifiP2pServiceImpl.registerWifiP2pListener(mP2pListener, TEST_PACKAGE_NAME, mExtras);
- mWifiP2pServiceImpl.registerWifiP2pListener(mP2pListener2, TEST_PACKAGE2_NAME, mExtras);
}
}
@@ -2978,407 +2967,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest {
anyInt(), anyInt(), anyString(), eq(true));
}
- /**
- * Sets up the environment for P2P Ownership test where Client1 is the group owner.
- */
- private void groupOwnershipConfigTestSetup() throws Exception {
- assumeTrue(SdkLevel.isAtLeastV());
- when(mFeatureFlags.p2pOwnership()).thenReturn(true);
- forceP2pEnabled(mClient1);
- sendChannelInfoUpdateMsg(TEST_PACKAGE2_NAME, "testFeature", mClient2, mClient2Messenger);
-
- // group created by client1
- when(mWifiNative.p2pGroupAdd(any(), eq(false))).thenReturn(true);
- sendCreateGroupMsgWithConfigValidAsGroup(mClientMessenger);
- verify(mWifiNative).p2pGroupAdd(any(), eq(false));
- assertTrue(mClientHandler.hasMessages(WifiP2pManager.CREATE_GROUP_SUCCEEDED));
- assertFalse(mClient2Handler.hasMessages(WifiP2pManager.CREATE_GROUP_SUCCEEDED));
-
- WifiP2pGroup group = new WifiP2pGroup();
- group.setNetworkName("DIRECT-test");
- group.setOwner(new WifiP2pDevice("thisDeviceMac"));
- group.setIsGroupOwner(true);
- group.setInterface(IFACE_NAME_P2P);
- sendGroupStartedMsg(group);
- simulateTetherReady();
- reset(mClientHandler);
- }
-
- /**
- * Sets up the environment for P2P Ownership test with WPS group.
- */
- private void groupOwnershipWpsTestSetup() throws Exception {
- assumeTrue(SdkLevel.isAtLeastV());
- mWifiP2pServiceImpl.registerWifiP2pListener(mP2pListener2, TEST_PACKAGE2_NAME, mExtras);
- forceP2pEnabled(mClient1);
- sendChannelInfoUpdateMsg(TEST_PACKAGE2_NAME, "testFeature", mClient2, mClient2Messenger);
-
- // WPS group created
- WifiP2pGroup group = new WifiP2pGroup();
- group.setNetworkId(WifiP2pGroup.NETWORK_ID_PERSISTENT);
- group.setNetworkName(TEST_NETWORK_NAME);
- group.setOwner(new WifiP2pDevice("thisDeviceMac"));
- group.setIsGroupOwner(true);
- group.setInterface(IFACE_NAME_P2P);
- sendGroupStartedMsg(group);
- simulateTetherReady();
- }
-
- /** Verify that only the group owner can send an invitation connection */
- @Test
- public void testGroupOwnershipConfigJoinInvite() throws Exception {
- groupOwnershipConfigTestSetup();
-
- // client2 cannot send an invitation to join
- sendConnectMsg(mClient2Messenger, mTestWifiP2pPeerConfig);
- verify(mClient2Handler).sendMessage(mMessageCaptor.capture());
- Message message = mMessageCaptor.getValue();
- assertEquals(WifiP2pManager.CONNECT_FAILED, message.what);
- assertEquals(WifiP2pManager.BUSY, message.arg1);
-
- // client1 can send an invitation to join
- when(mWifiNative.p2pInvite(any(), any())).thenReturn(true);
- mockPeersList();
- sendConnectMsg(mClientMessenger, mTestWifiP2pPeerConfig);
- verify(mClientHandler).sendMessage(mMessageCaptor.capture());
- message = mMessageCaptor.getValue();
- assertEquals(WifiP2pManager.CONNECT_SUCCEEDED, message.what);
- }
-
- /** Verify that any client can send an invitation connection */
- @Test
- public void testGroupOwnershipWpsJoinInvite() throws Exception {
- groupOwnershipWpsTestSetup();
-
- // client1 can send an invitation to join
- when(mWifiNative.p2pInvite(any(), any())).thenReturn(true);
- mockPeersList();
- sendConnectMsg(mClientMessenger, mTestWifiP2pPeerConfig);
- verify(mClientHandler).sendMessage(mMessageCaptor.capture());
- Message message = mMessageCaptor.getValue();
- assertEquals(WifiP2pManager.CONNECT_SUCCEEDED, message.what);
-
- // client2 can send an invitation to join
- sendConnectMsg(mClient2Messenger, mTestWifiP2pPeerConfig);
- verify(mClient2Handler).sendMessage(mMessageCaptor.capture());
- message = mMessageCaptor.getValue();
- assertEquals(WifiP2pManager.CONNECT_SUCCEEDED, message.what);
- }
-
- /** Verify that only the group owner can cancel an invitation connection */
- @Test
- public void testGroupOwnershipConfigCancelInvitationConnect() throws Exception {
- groupOwnershipConfigTestSetup();
-
- // client2 cannot cancel invitation connection
- sendSimpleMsg(mClient2Messenger, WifiP2pManager.CANCEL_CONNECT);
- verify(mClient2Handler).sendMessage(mMessageCaptor.capture());
- Message message = mMessageCaptor.getValue();
- assertEquals(WifiP2pManager.CANCEL_CONNECT_FAILED, message.what);
- assertEquals(WifiP2pManager.BUSY, message.arg1);
-
- // client1 can cancel invitation connection
- sendSimpleMsg(mClientMessenger, WifiP2pManager.CANCEL_CONNECT);
- verify(mClientHandler).sendMessage(mMessageCaptor.capture());
- message = mMessageCaptor.getValue();
- assertEquals(WifiP2pManager.CANCEL_CONNECT_SUCCEEDED, message.what);
- }
-
- /** Verify that any client can cancel an invitation connection */
- @Test
- public void testGroupOwnershipWpsCancelInvitationConnect() throws Exception {
- groupOwnershipWpsTestSetup();
-
- // client1 can cancel invitation connection
- sendSimpleMsg(mClientMessenger, WifiP2pManager.CANCEL_CONNECT);
- verify(mClientHandler).sendMessage(mMessageCaptor.capture());
- Message message = mMessageCaptor.getValue();
- assertEquals(WifiP2pManager.CANCEL_CONNECT_SUCCEEDED, message.what);
-
- // client2 can cancel invitation connection
- sendSimpleMsg(mClient2Messenger, WifiP2pManager.CANCEL_CONNECT);
- verify(mClient2Handler).sendMessage(mMessageCaptor.capture());
- message = mMessageCaptor.getValue();
- assertEquals(WifiP2pManager.CANCEL_CONNECT_SUCCEEDED, message.what);
- }
-
- /** Verify that only the client that initiated the connection can cancel it */
- @Test
- public void testGroupOwnershipConfigCancelConnect() throws Exception {
- assumeTrue(SdkLevel.isAtLeastV());
- when(mFeatureFlags.p2pOwnership()).thenReturn(true);
- forceP2pEnabled(mClient1);
- sendChannelInfoUpdateMsg(TEST_PACKAGE2_NAME, "testFeature", mClient2, mClient2Messenger);
-
- // group created by client1
- when(mWifiNative.p2pGroupAdd(any(), eq(false))).thenReturn(true);
- sendCreateGroupMsgWithConfigValidAsGroup(mClientMessenger);
- verify(mWifiNative).p2pGroupAdd(any(), eq(false));
- reset(mClientHandler);
-
- // client2 cannot cancel connection
- sendSimpleMsg(mClient2Messenger, WifiP2pManager.CANCEL_CONNECT);
- verify(mClient2Handler).sendMessage(mMessageCaptor.capture());
- Message message = mMessageCaptor.getValue();
- assertEquals(WifiP2pManager.CANCEL_CONNECT_FAILED, message.what);
- assertEquals(WifiP2pManager.BUSY, message.arg1);
-
- // client1 can cancel connection
- sendSimpleMsg(mClientMessenger, WifiP2pManager.CANCEL_CONNECT);
- verify(mClientHandler).sendMessage(mMessageCaptor.capture());
- message = mMessageCaptor.getValue();
- assertEquals(WifiP2pManager.CANCEL_CONNECT_SUCCEEDED, message.what);
- }
-
- /** Verify that any client can cancel an ongoing WPS connection */
- @Test
- public void testGroupOwnershipWpsCancelConnect() throws Exception {
- assumeTrue(SdkLevel.isAtLeastV());
- when(mFeatureFlags.p2pOwnership()).thenReturn(true);
- forceP2pEnabled(mClient1);
- sendChannelInfoUpdateMsg(TEST_PACKAGE2_NAME, "testFeature", mClient2, mClient2Messenger);
-
- // connection initiated by client1
- when(mWifiNative.p2pGroupAdd(anyBoolean(), anyBoolean())).thenReturn(true);
- mockEnterGroupNegotiationState();
-
- // client2 can cancel connection
- sendSimpleMsg(mClient2Messenger, WifiP2pManager.CANCEL_CONNECT);
- verify(mClient2Handler).sendMessage(mMessageCaptor.capture());
- Message message = mMessageCaptor.getValue();
- assertEquals(WifiP2pManager.CANCEL_CONNECT_SUCCEEDED, message.what);
- }
-
- /** Verify that only the group owner can remove the group */
- @Test
- public void testGroupOwnershipConfigRemoveGroup() throws Exception {
- groupOwnershipConfigTestSetup();
-
- // client2 cannot remove group
- sendSimpleMsg(mClient2Messenger, WifiP2pManager.REMOVE_GROUP);
- verify(mClient2Handler).sendMessage(mMessageCaptor.capture());
- Message message = mMessageCaptor.getValue();
- assertEquals(WifiP2pManager.REMOVE_GROUP_FAILED, message.what);
- assertEquals(WifiP2pManager.BUSY, message.arg1);
-
- // client1 can remove group
- when(mWifiNative.p2pGroupRemove(eq(IFACE_NAME_P2P))).thenReturn(true);
- sendSimpleMsg(mClientMessenger, WifiP2pManager.REMOVE_GROUP);
- verify(mWifiNative).p2pGroupRemove(eq(IFACE_NAME_P2P));
- verify(mClientHandler).sendMessage(mMessageCaptor.capture());
- message = mMessageCaptor.getValue();
- assertEquals(WifiP2pManager.REMOVE_GROUP_SUCCEEDED, message.what);
- }
-
- /** Verify that any client can remove the group */
- @Test
- public void testGroupOwnershipWpsRemoveGroup() throws Exception {
- groupOwnershipWpsTestSetup();
-
- // client2 can remove group
- when(mWifiNative.p2pGroupRemove(eq(IFACE_NAME_P2P))).thenReturn(true);
- sendSimpleMsg(mClient2Messenger, WifiP2pManager.REMOVE_GROUP);
- verify(mWifiNative).p2pGroupRemove(eq(IFACE_NAME_P2P));
- verify(mClient2Handler).sendMessage(mMessageCaptor.capture());
- Message message = mMessageCaptor.getValue();
- assertEquals(WifiP2pManager.REMOVE_GROUP_SUCCEEDED, message.what);
- }
-
- /** Verify that only the group owner can get group info */
- @Test
- public void testGroupOwnershipConfigGetGroupInformation() throws Exception {
- groupOwnershipConfigTestSetup();
-
- // client2 cannot get P2P group info
- sendRequestGroupInfoMsg(mClient2Messenger);
- verify(mClient2Handler).sendMessage(mMessageCaptor.capture());
- assertEquals(WifiP2pManager.RESPONSE_GROUP_INFO, mMessageCaptor.getValue().what);
- WifiP2pGroup wifiP2pGroup = (WifiP2pGroup) mMessageCaptor.getValue().obj;
- assertNull(wifiP2pGroup);
-
- // client1 can get P2P group info
- sendRequestGroupInfoMsg(mClientMessenger);
- verify(mClientHandler).sendMessage(mMessageCaptor.capture());
- assertEquals(WifiP2pManager.RESPONSE_GROUP_INFO, mMessageCaptor.getValue().what);
- wifiP2pGroup = (WifiP2pGroup) mMessageCaptor.getValue().obj;
- assertNotNull(wifiP2pGroup);
- }
-
- /** Verify that any client can get group info */
- @Test
- public void testGroupOwnershipWpsGetGroupInformation() throws Exception {
- groupOwnershipWpsTestSetup();
-
- // client1 can get P2P group info
- sendRequestGroupInfoMsg(mClientMessenger);
- verify(mClientHandler).sendMessage(mMessageCaptor.capture());
- assertEquals(WifiP2pManager.RESPONSE_GROUP_INFO, mMessageCaptor.getValue().what);
- WifiP2pGroup wifiP2pGroup = (WifiP2pGroup) mMessageCaptor.getValue().obj;
- assertNotNull(wifiP2pGroup);
-
- // client2 can get P2P group info
- sendRequestGroupInfoMsg(mClient2Messenger);
- verify(mClient2Handler).sendMessage(mMessageCaptor.capture());
- assertEquals(WifiP2pManager.RESPONSE_GROUP_INFO, mMessageCaptor.getValue().what);
- wifiP2pGroup = (WifiP2pGroup) mMessageCaptor.getValue().obj;
- assertNotNull(wifiP2pGroup);
- }
-
- /** Verify that only the group owner can get connection info */
- @Test
- public void testGroupOwnershipConfigGetConnectionInfo() throws Exception {
- groupOwnershipConfigTestSetup();
-
- // client2 cannot get P2P connection info
- sendSimpleMsg(mClient2Messenger, WifiP2pManager.REQUEST_CONNECTION_INFO);
- verify(mClient2Handler).sendMessage(mMessageCaptor.capture());
- Message message = mMessageCaptor.getValue();
- WifiP2pInfo info = (WifiP2pInfo) message.obj;
- assertEquals(WifiP2pManager.RESPONSE_CONNECTION_INFO, message.what);
- assertEquals((new WifiP2pInfo()).toString(), info.toString());
-
- // client1 can get P2P connection info
- sendSimpleMsg(mClientMessenger, WifiP2pManager.REQUEST_CONNECTION_INFO);
- verify(mClientHandler).sendMessage(mMessageCaptor.capture());
- message = mMessageCaptor.getValue();
- info = (WifiP2pInfo) message.obj;
- assertEquals(WifiP2pManager.RESPONSE_CONNECTION_INFO, mMessageCaptor.getValue().what);
- assertTrue(info.groupFormed);
- }
-
- /** Verify that any client can get connection info */
- @Test
- public void testGroupOwnershipWpsGetConnectionInfo() throws Exception {
- groupOwnershipWpsTestSetup();
-
- // client1 can get P2P connection info
- sendSimpleMsg(mClientMessenger, WifiP2pManager.REQUEST_CONNECTION_INFO);
- verify(mClientHandler).sendMessage(mMessageCaptor.capture());
- Message message = mMessageCaptor.getValue();
- WifiP2pInfo info = (WifiP2pInfo) message.obj;
- assertEquals(WifiP2pManager.RESPONSE_CONNECTION_INFO, mMessageCaptor.getValue().what);
- assertTrue(info.groupFormed);
-
- // client2 can get P2P connection info
- sendSimpleMsg(mClient2Messenger, WifiP2pManager.REQUEST_CONNECTION_INFO);
- verify(mClient2Handler).sendMessage(mMessageCaptor.capture());
- message = mMessageCaptor.getValue();
- info = (WifiP2pInfo) message.obj;
- assertEquals(WifiP2pManager.RESPONSE_CONNECTION_INFO, mMessageCaptor.getValue().what);
- assertTrue(info.groupFormed);
- }
-
- /** Verify that only the group owner receives the connection changed broadcast */
- @Test
- public void testGroupOwnershipConfigBroadcast() throws Exception {
- groupOwnershipConfigTestSetup();
-
- ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
- verify(mContext, atLeastOnce()).sendBroadcast(intentCaptor.capture(), any(), any());
-
- ArrayList<Intent> intentArrayList = new ArrayList<>();
- for (int i = 0; i < intentCaptor.getAllValues().size(); i++) {
- Intent intent = intentCaptor.getAllValues().get(i);
- if (intent.getAction().equals(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION)) {
- intentArrayList.add(intent);
- }
- }
- // Connection changed broadcast is sent 3 times:
- // 1. Entering P2pEnabledState
- // 2. Entering GroupCreatingState
- // 3. Entering GroupCreatedState
- // Each time, sendBroadcast is called twice (refer sendBroadcastWithExcludedPermissions)
- // Verify group created broadcast only sent to client1
- Intent intent = intentArrayList.get(4);
- assertEquals(TEST_PACKAGE_NAME, intent.getPackage());
- // Verify broadcast sent to NEARBY_WIFI_DEVICES apps do not have the package name set
- intent = intentArrayList.get(5);
- assertNull(intent.getPackage());
- }
-
- /** Verify that all clients receive the connection changed broadcast */
- @Test
- public void testGroupOwnershipWpsBroadcast() throws Exception {
- groupOwnershipWpsTestSetup();
-
- WifiP2pDevice connectedClientDevice = new WifiP2pDevice(mTestWifiP2pDevice);
- connectedClientDevice.setInterfaceMacAddress(MacAddress.fromString(PEER_INTERFACE_ADDRESS));
- sendApStaConnectedEvent(connectedClientDevice);
- ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
- verify(mContext, atLeastOnce()).sendBroadcast(intentCaptor.capture(), any(), any());
-
- ArrayList<Intent> intentArrayList = new ArrayList<>();
- for (int i = 0; i < intentCaptor.getAllValues().size(); i++) {
- Intent intent = intentCaptor.getAllValues().get(i);
- if (intent.getAction().equals(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION)) {
- intentArrayList.add(intent);
- }
- }
- // Connection changed broadcast is sent 3 times:
- // 1. Entering P2pEnabledState
- // 2. Entering GroupCreatingState
- // 3. Peer connection in GroupCreatedState
- // Each time, sendBroadcast is called twice (refer sendBroadcastWithExcludedPermissions)
- // Verify group created broadcast sent to all clients
- Intent intent = intentArrayList.get(4);
- assertNull(intent.getPackage());
- }
-
- /** Verify that only the group owner receives the group related callback */
- @Test
- public void testGroupOwnershipConfigP2pListener() throws Exception {
- groupOwnershipConfigTestSetup();
-
- verify(mP2pListener).onGroupCreated(any(), any());
- verify(mP2pListener2, never()).onGroupCreated(any(), any());
-
- WifiP2pDevice peerClientDevice = new WifiP2pDevice();
- peerClientDevice.deviceName = "peerClientDeviceName";
- peerClientDevice.deviceAddress = "11:22:33:aa:bb:cc";
- peerClientDevice.setInterfaceMacAddress(MacAddress.fromString(PEER_INTERFACE_ADDRESS));
- sendSimpleMsg(null, WifiP2pMonitor.AP_STA_CONNECTED_EVENT, peerClientDevice);
- verify(mP2pListener).onPeerClientJoined(any(), any());
- verify(mP2pListener2, never()).onPeerClientJoined(any(), any());
-
- sendSimpleMsg(null, WifiP2pMonitor.AP_STA_DISCONNECTED_EVENT, peerClientDevice);
- verify(mP2pListener).onPeerClientDisconnected(any(), any());
- verify(mP2pListener2, never()).onPeerClientDisconnected(any(), any());
-
- sendSimpleMsg(null, WifiP2pMonitor.P2P_FREQUENCY_CHANGED_EVENT, TEST_GROUP_FREQUENCY);
- verify(mP2pListener).onFrequencyChanged(any(), any());
- verify(mP2pListener2, never()).onFrequencyChanged(any(), any());
- }
-
- /** Verify that all clients receive the group related callback */
- @Test
- public void testGroupOwnershipWpsP2pListener() throws Exception {
- groupOwnershipWpsTestSetup();
-
- DhcpResultsParcelable dhcpResults = new DhcpResultsParcelable();
- dhcpResults.serverAddress = P2P_GO_IP;
- sendSimpleMsg(mClientMessenger, IPC_DHCP_RESULTS, dhcpResults);
- verify(mP2pListener).onGroupCreated(any(), any());
- verify(mP2pListener2).onGroupCreated(any(), any());
-
- WifiP2pDevice connectedClientDevice = new WifiP2pDevice(mTestWifiP2pDevice);
- connectedClientDevice.setInterfaceMacAddress(MacAddress.fromString(PEER_INTERFACE_ADDRESS));
- sendApStaConnectedEvent(connectedClientDevice);
- verify(mP2pListener).onPeerClientJoined(any(), any());
- verify(mP2pListener2).onPeerClientJoined(any(), any());
-
- // Need to connect a second peer device before testing disconnect to avoid removing group
- WifiP2pDevice secondPeerDevice = new WifiP2pDevice(connectedClientDevice);
- secondPeerDevice.deviceAddress = "11:22:33:aa:bb:cc";
- sendApStaConnectedEvent(secondPeerDevice);
- sendSimpleMsg(null, WifiP2pMonitor.AP_STA_DISCONNECTED_EVENT, connectedClientDevice);
- verify(mP2pListener).onPeerClientDisconnected(any(), any());
- verify(mP2pListener2).onPeerClientDisconnected(any(), any());
-
- sendSimpleMsg(null, WifiP2pMonitor.P2P_FREQUENCY_CHANGED_EVENT, TEST_GROUP_FREQUENCY);
- verify(mP2pListener).onFrequencyChanged(any(), any());
- verify(mP2pListener2).onFrequencyChanged(any(), any());
- }
-
/** Verify the p2p randomized MAC feature is enabled if OEM supports it. */
@Test
public void testP2pRandomMacWithOemSupport() throws Exception {
@@ -3591,7 +3179,7 @@ public class WifiP2pServiceImplTest extends WifiBaseTest {
WifiP2pGroup groupCaptured = groupCaptor.getValue();
assertEquals(mTestWifiP2pNewPersistentGoGroup.toString(), groupCaptured.toString());
- sendGroupRemovedMsg(groupCaptured);
+ sendGroupRemovedMsg();
verify(mWifiP2pMetrics).endGroupEvent();
}
@@ -8238,7 +7826,7 @@ public class WifiP2pServiceImplTest extends WifiBaseTest {
verify(mWifiP2pMetrics).startGroupEvent(group);
verify(mWifiNative).p2pStopFind();
verify(mWifiNative).p2pExtListen(eq(false), anyInt(), anyInt(), eq(null));
- sendGroupRemovedMsg(group);
+ sendGroupRemovedMsg();
//force to back disabled state
mockEnterDisabledState();
@@ -8578,7 +8166,7 @@ public class WifiP2pServiceImplTest extends WifiBaseTest {
p2pGroupCaptor.capture());
assertEquals(TEST_GROUP_FREQUENCY, p2pGroupCaptor.getValue().getFrequency());
- sendGroupRemovedMsg(p2pGroup);
+ sendGroupRemovedMsg();
mockEnterDisabledState();
mLooper.dispatchAll();
verify(mP2pListener).onGroupRemoved();