diff options
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/ClientModeImpl.java | 67 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/WifiServiceImpl.java | 2 |
2 files changed, 41 insertions, 28 deletions
diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java index 10a41f5dc..6b718bb32 100644 --- a/service/java/com/android/server/wifi/ClientModeImpl.java +++ b/service/java/com/android/server/wifi/ClientModeImpl.java @@ -107,7 +107,6 @@ import android.util.Log; import android.util.Pair; import android.util.SparseArray; -import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.AsyncChannel; import com.android.internal.util.MessageUtils; @@ -445,9 +444,7 @@ public class ClientModeImpl extends StateMachine { private WifiNetworkFactory mNetworkFactory; private UntrustedWifiNetworkFactory mUntrustedNetworkFactory; - @GuardedBy("mNetworkAgentLock") private WifiNetworkAgent mNetworkAgent; - private final Object mNetworkAgentLock = new Object(); private byte[] mRssiRanges; @@ -630,6 +627,9 @@ public class ClientModeImpl extends StateMachine { /* Start connection to FILS AP*/ static final int CMD_START_FILS_CONNECTION = BASE + 262; + + private static final int CMD_GET_CURRENT_NETWORK = BASE + 263; + // For message logging. private static final Class[] sMessageClasses = { AsyncChannel.class, ClientModeImpl.class }; @@ -1785,20 +1785,30 @@ public class ClientModeImpl extends StateMachine { } /** - * Get Network object of current wifi network - * @return Network object of current wifi network + * Should only be used internally. + * External callers should use {@link #syncGetCurrentNetwork(AsyncChannel)}. */ - public Network getCurrentNetwork() { - synchronized (mNetworkAgentLock) { - if (mNetworkAgent != null) { - return mNetworkAgent.getNetwork(); - } else { - return null; - } + private Network getCurrentNetwork() { + if (mNetworkAgent != null) { + return mNetworkAgent.getNetwork(); + } else { + return null; } } /** + * Get Network object of currently connected wifi network, or null if not connected. + * @return Network object of current wifi network + */ + public Network syncGetCurrentNetwork(AsyncChannel channel) { + Message resultMsg = channel.sendMessageSynchronously(CMD_GET_CURRENT_NETWORK); + if (messageIsNull(resultMsg)) return null; + Network network = (Network) resultMsg.obj; + resultMsg.recycle(); + return network; + } + + /** * Enable TDLS for a specific MAC address */ public void enableTdls(String remoteMacAddress, boolean enable) { @@ -2757,11 +2767,9 @@ public class ClientModeImpl extends StateMachine { mIsAutoRoaming = false; sendNetworkChangeBroadcast(DetailedState.DISCONNECTED); - synchronized (mNetworkAgentLock) { - if (mNetworkAgent != null) { - mNetworkAgent.unregister(); - mNetworkAgent = null; - } + if (mNetworkAgent != null) { + mNetworkAgent.unregister(); + mNetworkAgent = null; } /* Clear network properties */ @@ -3492,7 +3500,8 @@ public class ClientModeImpl extends StateMachine { replyToMessage(message, message.what, Long.valueOf(featureSet)); break; case CMD_GET_LINK_LAYER_STATS: - // Not supported hence reply with error message + case CMD_GET_CURRENT_NETWORK: + // Not supported hence reply with null message.obj replyToMessage(message, message.what, null); break; case WifiP2pServiceImpl.P2P_CONNECTION_CHANGED: @@ -4752,16 +4761,14 @@ public class ClientModeImpl extends StateMachine { .setPartialConnectivityAcceptable(config.noInternetAccessExpected) .build(); final NetworkCapabilities nc = getCapabilities(getCurrentWifiConfiguration()); - synchronized (mNetworkAgentLock) { - // This should never happen. - if (mNetworkAgent != null) { - Log.wtf(TAG, "mNetworkAgent is not null: " + mNetworkAgent); - mNetworkAgent.unregister(); - } - mNetworkAgent = new WifiNetworkAgent(mContext, getHandler().getLooper(), - "WifiNetworkAgent", nc, mLinkProperties, 60, naConfig, - mNetworkFactory.getProvider()); + // This should never happen. + if (mNetworkAgent != null) { + Log.wtf(TAG, "mNetworkAgent is not null: " + mNetworkAgent); + mNetworkAgent.unregister(); } + mNetworkAgent = new WifiNetworkAgent(mContext, getHandler().getLooper(), + "WifiNetworkAgent", nc, mLinkProperties, 60, naConfig, + mNetworkFactory.getProvider()); mWifiScoreReport.setNetworkAgent(mNetworkAgent); // We must clear the config BSSID, as the wifi chipset may decide to roam @@ -5317,6 +5324,9 @@ public class ClientModeImpl extends StateMachine { transitionTo(mDisconnectedState); } break; + case CMD_GET_CURRENT_NETWORK: + replyToMessage(message, message.what, getCurrentNetwork()); + break; default: handleStatus = NOT_HANDLED; break; @@ -5541,6 +5551,9 @@ public class ClientModeImpl extends StateMachine { mWifiMetrics.incrementIpRenewalFailure(); handleStatus = NOT_HANDLED; break; + case CMD_GET_CURRENT_NETWORK: + replyToMessage(message, message.what, getCurrentNetwork()); + break; default: handleStatus = NOT_HANDLED; break; diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index 52fb61fdb..070422775 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -3497,7 +3497,7 @@ public class WifiServiceImpl extends BaseWifiService { if (mVerboseLoggingEnabled) { mLog.info("getCurrentNetwork uid=%").c(Binder.getCallingUid()).flush(); } - return mClientModeImpl.getCurrentNetwork(); + return mClientModeImpl.syncGetCurrentNetwork(mClientModeImplChannel); } public static String toHexString(String s) { |