summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2017-09-07 23:17:07 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-09-07 23:17:07 +0000
commit7fc4bd4bdbe70f4d1e7c471ba008c7c4f9f287e8 (patch)
treea3c29e0aac7569b18879230a5080c39576520cec /service
parentd0cafb20481fc76e546deb9d71626e79e320d440 (diff)
parent08ffa580f6756129929667785408da377b363787 (diff)
Merge "ONA: Implement connection attempt and failure callback." into oc-mr1-dev
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/OpenNetworkNotifier.java66
-rw-r--r--service/java/com/android/server/wifi/WifiConnectivityManager.java11
-rw-r--r--service/java/com/android/server/wifi/WifiInjector.java3
-rw-r--r--service/java/com/android/server/wifi/WifiStateMachine.java5
4 files changed, 78 insertions, 7 deletions
diff --git a/service/java/com/android/server/wifi/OpenNetworkNotifier.java b/service/java/com/android/server/wifi/OpenNetworkNotifier.java
index 692c8e22c..279223759 100644
--- a/service/java/com/android/server/wifi/OpenNetworkNotifier.java
+++ b/service/java/com/android/server/wifi/OpenNetworkNotifier.java
@@ -24,8 +24,12 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.database.ContentObserver;
import android.net.wifi.ScanResult;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiManager;
import android.os.Handler;
import android.os.Looper;
+import android.os.Message;
+import android.os.Messenger;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
@@ -34,6 +38,7 @@ import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
+import com.android.server.wifi.util.ScanResultUtil;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -54,6 +59,8 @@ public class OpenNetworkNotifier {
"com.android.server.wifi.OpenNetworkNotifier.USER_DISMISSED_NOTIFICATION";
static final String ACTION_USER_TAPPED_CONTENT =
"com.android.server.wifi.OpenNetworkNotifier.USER_TAPPED_CONTENT";
+ static final String ACTION_CONNECT_TO_NETWORK =
+ "com.android.server.wifi.OpenNetworkNotifier.CONNECT_TO_NETWORK";
/** Identifier of the {@link SsidSetStoreData}. */
private static final String STORE_DATA_IDENTIFIER = "OpenNetworkNotifierBlacklist";
@@ -85,6 +92,8 @@ public class OpenNetworkNotifier {
private final FrameworkFacade mFrameworkFacade;
private final Clock mClock;
private final WifiConfigManager mConfigManager;
+ private final WifiStateMachine mWifiStateMachine;
+ private final Messenger mSrcMessenger;
private final OpenNetworkRecommender mOpenNetworkRecommender;
private final OpenNetworkNotificationBuilder mOpenNetworkNotificationBuilder;
@@ -97,15 +106,18 @@ public class OpenNetworkNotifier {
Clock clock,
WifiConfigManager wifiConfigManager,
WifiConfigStore wifiConfigStore,
+ WifiStateMachine wifiStateMachine,
OpenNetworkRecommender openNetworkRecommender) {
mContext = context;
mHandler = new Handler(looper);
mFrameworkFacade = framework;
mClock = clock;
mConfigManager = wifiConfigManager;
+ mWifiStateMachine = wifiStateMachine;
mOpenNetworkRecommender = openNetworkRecommender;
mOpenNetworkNotificationBuilder = new OpenNetworkNotificationBuilder(context, framework);
mScreenOn = false;
+ mSrcMessenger = new Messenger(new Handler(looper, mConnectionStateCallback));
mBlacklistedSsids = new ArraySet<>();
wifiConfigStore.registerStoreData(new SsidSetStoreData(
@@ -122,6 +134,7 @@ public class OpenNetworkNotifier {
IntentFilter filter = new IntentFilter();
filter.addAction(ACTION_USER_DISMISSED_NOTIFICATION);
filter.addAction(ACTION_USER_TAPPED_CONTENT);
+ filter.addAction(ACTION_CONNECT_TO_NETWORK);
mContext.registerReceiver(
mBroadcastReceiver, filter, null /* broadcastPermission */, mHandler);
}
@@ -130,14 +143,38 @@ public class OpenNetworkNotifier {
new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
- if (ACTION_USER_TAPPED_CONTENT.equals(intent.getAction())) {
- handleUserClickedContentAction();
- } else if (ACTION_USER_DISMISSED_NOTIFICATION.equals(intent.getAction())) {
- handleUserDismissedAction();
+ switch (intent.getAction()) {
+ case ACTION_USER_TAPPED_CONTENT:
+ handleUserClickedContentAction();
+ break;
+ case ACTION_USER_DISMISSED_NOTIFICATION:
+ handleUserDismissedAction();
+ break;
+ case ACTION_CONNECT_TO_NETWORK:
+ handleConnectToNetworkAction();
+ break;
+ default:
+ Log.e(TAG, "Unknown action " + intent.getAction());
}
}
};
+ private final Handler.Callback mConnectionStateCallback = (Message msg) -> {
+ switch (msg.what) {
+ // Success here means that an attempt to connect to the network has been initiated.
+ // Successful connection updates are received via the
+ // WifiConnectivityManager#handleConnectionStateChanged() callback.
+ case WifiManager.CONNECT_NETWORK_SUCCEEDED:
+ break;
+ case WifiManager.CONNECT_NETWORK_FAILED:
+ handleConnectionFailure();
+ break;
+ default:
+ Log.e(TAG, "Unknown message " + msg.what);
+ }
+ return true;
+ };
+
/**
* Clears the pending notification. This is called by {@link WifiConnectivityManager} on stop.
*
@@ -213,6 +250,27 @@ public class OpenNetworkNotifier {
mNotificationRepeatTime = mClock.getWallClockMillis() + mNotificationRepeatDelay;
}
+ private void handleConnectToNetworkAction() {
+ if (mRecommendedNetwork == null) {
+ return;
+ }
+ Log.d(TAG, "User initiated connection to recommended network: " + mRecommendedNetwork.SSID);
+ WifiConfiguration network = ScanResultUtil.createNetworkFromScanResult(mRecommendedNetwork);
+ Message msg = Message.obtain();
+ msg.what = WifiManager.CONNECT_NETWORK;
+ msg.arg1 = WifiConfiguration.INVALID_NETWORK_ID;
+ msg.obj = network;
+ msg.replyTo = mSrcMessenger;
+ mWifiStateMachine.sendMessage(msg);
+ }
+
+ /**
+ * Handles when a Wi-Fi connection attempt failed.
+ */
+ public void handleConnectionFailure() {
+ // Stub. Should post connection failure notification once implemented.
+ }
+
/** Opens Wi-Fi picker. */
private void handleUserClickedContentAction() {
mNotificationShown = false;
diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java
index e417fde2c..1c5ac2821 100644
--- a/service/java/com/android/server/wifi/WifiConnectivityManager.java
+++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java
@@ -1088,6 +1088,17 @@ public class WifiConnectivityManager {
}
/**
+ * Handler when a WiFi connection attempt ended.
+ *
+ * @param failureCode {@link WifiMetrics.ConnectionEvent} failure code.
+ */
+ public void handleConnectionAttemptEnded(int failureCode) {
+ if (failureCode != WifiMetrics.ConnectionEvent.FAILURE_NONE) {
+ mOpenNetworkNotifier.handleConnectionFailure();
+ }
+ }
+
+ /**
* Handler when user toggles whether untrusted connection is allowed
*/
public void setUntrustedConnectionAllowed(boolean allowed) {
diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java
index 734c28d19..7778c2ceb 100644
--- a/service/java/com/android/server/wifi/WifiInjector.java
+++ b/service/java/com/android/server/wifi/WifiInjector.java
@@ -226,7 +226,8 @@ public class WifiInjector {
mCertManager = new WifiCertManager(mContext);
mOpenNetworkNotifier = new OpenNetworkNotifier(mContext,
mWifiStateMachineHandlerThread.getLooper(), mFrameworkFacade, mClock,
- mWifiConfigManager, mWifiConfigStore, new OpenNetworkRecommender());
+ mWifiConfigManager, mWifiConfigStore, mWifiStateMachine,
+ new OpenNetworkRecommender());
mLockManager = new WifiLockManager(mContext, BatteryStatsService.getService());
mWifiController = new WifiController(mContext, mWifiStateMachine, mSettingsStore,
mLockManager, mWifiServiceHandlerThread.getLooper(), mFrameworkFacade);
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java
index 38c767f94..41a599451 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -3429,11 +3429,12 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
}
/**
- * Inform other components (WifiMetrics, WifiDiagnostics, etc.) that the current connection attempt
- * has concluded.
+ * Inform other components (WifiMetrics, WifiDiagnostics, WifiConnectivityManager, etc.) that
+ * the current connection attempt has concluded.
*/
private void reportConnectionAttemptEnd(int level2FailureCode, int connectivityFailureCode) {
mWifiMetrics.endConnectionEvent(level2FailureCode, connectivityFailureCode);
+ mWifiConnectivityManager.handleConnectionAttemptEnded(level2FailureCode);
switch (level2FailureCode) {
case WifiMetrics.ConnectionEvent.FAILURE_NONE:
// Ideally, we'd wait until IP reachability has been confirmed. this code falls