summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorPeter Qiu <zqiu@google.com>2017-07-20 00:50:50 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-07-20 00:50:50 +0000
commit5adcd54d9534c1530a67ee14dc76737646ce5182 (patch)
tree1b3c319343655d7dc77e9caaf473ecdd936d5ce0 /service
parent7f1e7e95c81cc551d0ee1d06239a3ed0a1653a20 (diff)
parent96e29a8bc2b03c301658ce3831e64113b060c427 (diff)
Merge "Display notification when wrong password error is detected" into oc-dr1-dev
am: 96e29a8bc2 Change-Id: I5c7ad258df8918f7813602ca4d00e1251ec343cb
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/FrameworkFacade.java18
-rw-r--r--service/java/com/android/server/wifi/WifiInjector.java3
-rw-r--r--service/java/com/android/server/wifi/WifiStateMachine.java12
-rw-r--r--service/java/com/android/server/wifi/WrongPasswordNotifier.java109
4 files changed, 140 insertions, 2 deletions
diff --git a/service/java/com/android/server/wifi/FrameworkFacade.java b/service/java/com/android/server/wifi/FrameworkFacade.java
index ba114df8a..760ee697a 100644
--- a/service/java/com/android/server/wifi/FrameworkFacade.java
+++ b/service/java/com/android/server/wifi/FrameworkFacade.java
@@ -18,6 +18,7 @@ package com.android.server.wifi;
import android.app.ActivityManager;
import android.app.AppGlobals;
+import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
@@ -94,6 +95,13 @@ public class FrameworkFacade {
return PendingIntent.getBroadcast(context, requestCode, intent, flags);
}
+ /**
+ * Wrapper for {@link PendingIntent#getActivity}.
+ */
+ public PendingIntent getActivity(Context context, int requestCode, Intent intent, int flags) {
+ return PendingIntent.getActivity(context, requestCode, intent, flags);
+ }
+
public SupplicantStateTracker makeSupplicantStateTracker(Context context,
WifiConfigManager configManager, Handler handler) {
return new SupplicantStateTracker(context, configManager, this, handler);
@@ -172,4 +180,14 @@ public class FrameworkFacade {
public boolean isAppForeground(int uid) throws RemoteException {
return ActivityManager.getService().isAppForeground(uid);
}
+
+ /**
+ * Create a new instance of {@link Notification.Builder}.
+ * @param context reference to a Context
+ * @param channelId ID of the notification channel
+ * @return an instance of Notification.Builder
+ */
+ public Notification.Builder makeNotificationBuilder(Context context, String channelId) {
+ return new Notification.Builder(context, channelId);
+ }
}
diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java
index 0b0c38002..e1be8a3a9 100644
--- a/service/java/com/android/server/wifi/WifiInjector.java
+++ b/service/java/com/android/server/wifi/WifiInjector.java
@@ -224,7 +224,8 @@ public class WifiInjector {
mJavaRuntime = Runtime.getRuntime();
mWifiStateMachine = new WifiStateMachine(mContext, mFrameworkFacade,
wifiStateMachineLooper, UserManager.get(mContext),
- this, mBackupManagerProxy, mCountryCode, mWifiNative);
+ this, mBackupManagerProxy, mCountryCode, mWifiNative,
+ new WrongPasswordNotifier(mContext, mFrameworkFacade));
mCertManager = new WifiCertManager(mContext);
mNotificationController = new WifiNotificationController(mContext,
mWifiServiceHandlerThread.getLooper(), mFrameworkFacade, null, this);
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java
index b347ea322..7e625bbda 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -898,11 +898,13 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
private FrameworkFacade mFacade;
private WifiStateTracker mWifiStateTracker;
private final BackupManagerProxy mBackupManagerProxy;
+ private final WrongPasswordNotifier mWrongPasswordNotifier;
public WifiStateMachine(Context context, FrameworkFacade facade, Looper looper,
UserManager userManager, WifiInjector wifiInjector,
BackupManagerProxy backupManagerProxy, WifiCountryCode countryCode,
- WifiNative wifiNative) {
+ WifiNative wifiNative,
+ WrongPasswordNotifier wrongPasswordNotifier) {
super("WifiStateMachine", looper);
mWifiInjector = wifiInjector;
mWifiMetrics = mWifiInjector.getWifiMetrics();
@@ -913,6 +915,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
mFacade = facade;
mWifiNative = wifiNative;
mBackupManagerProxy = backupManagerProxy;
+ mWrongPasswordNotifier = wrongPasswordNotifier;
// TODO refactor WifiNative use of context out into it's own class
mInterfaceName = mWifiNative.getInterfaceName();
@@ -3409,6 +3412,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
mDiagsConnectionStartMillis = mClock.getElapsedSinceBootMillis();
mWifiDiagnostics.reportConnectionEvent(
mDiagsConnectionStartMillis, WifiDiagnostics.CONNECTION_EVENT_STARTED);
+ mWrongPasswordNotifier.onNewConnectionAttempt();
// TODO(b/35329124): Remove CMD_DIAGS_CONNECT_TIMEOUT, once WifiStateMachine
// grows a proper CONNECTING state.
sendMessageDelayed(CMD_DIAGS_CONNECT_TIMEOUT,
@@ -4952,6 +4956,12 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
if (isPermanentWrongPasswordFailure(mTargetNetworkId, message.arg2)) {
disableReason = WifiConfiguration.NetworkSelectionStatus
.DISABLED_BY_WRONG_PASSWORD;
+ WifiConfiguration targetedNetwork =
+ mWifiConfigManager.getConfiguredNetwork(mTargetNetworkId);
+ if (targetedNetwork != null) {
+ mWrongPasswordNotifier.onWrongPasswordError(
+ targetedNetwork.SSID);
+ }
}
mWifiConfigManager.updateNetworkSelectionStatus(
mTargetNetworkId, disableReason);
diff --git a/service/java/com/android/server/wifi/WrongPasswordNotifier.java b/service/java/com/android/server/wifi/WrongPasswordNotifier.java
new file mode 100644
index 000000000..5447322d3
--- /dev/null
+++ b/service/java/com/android/server/wifi/WrongPasswordNotifier.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.wifi;
+
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.net.wifi.WifiManager;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
+import com.android.internal.notification.SystemNotificationChannels;
+
+/**
+ * Responsible for notifying user for wrong password errors.
+ */
+public class WrongPasswordNotifier {
+ // Number of milliseconds to wait before automatically dismiss the notification.
+ private static final long CANCEL_TIMEOUT_MILLISECONDS = 5 * 60 * 1000;
+
+ // Unique ID associated with the notification.
+ @VisibleForTesting
+ public static final int NOTIFICATION_ID = SystemMessage.NOTE_WIFI_WRONG_PASSWORD;
+
+ // Flag indicating if a wrong password error is detected for the current connection.
+ private boolean mWrongPasswordDetected;
+
+ private final Context mContext;
+ private final NotificationManager mNotificationManager;
+ private final FrameworkFacade mFrameworkFacade;
+
+ public WrongPasswordNotifier(Context context, FrameworkFacade frameworkFacade) {
+ mContext = context;
+ mFrameworkFacade = frameworkFacade;
+ mNotificationManager =
+ (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
+ }
+
+ /**
+ * Invoked when a wrong password error for a Wi-Fi network is detected.
+ *
+ * @param ssid The SSID of the Wi-Fi network
+ */
+ public void onWrongPasswordError(String ssid) {
+ showNotification(ssid);
+ mWrongPasswordDetected = true;
+ }
+
+ /**
+ * Invoked when attempting a new Wi-Fi network connection.
+ */
+ public void onNewConnectionAttempt() {
+ if (mWrongPasswordDetected) {
+ dismissNotification();
+ mWrongPasswordDetected = false;
+ }
+ }
+
+ /**
+ * Display wrong password notification for a given Wi-Fi network (specified by its SSID).
+ *
+ * @param ssid SSID of the Wi-FI network
+ */
+ private void showNotification(String ssid) {
+ Notification.Builder builder = mFrameworkFacade.makeNotificationBuilder(mContext,
+ SystemNotificationChannels.NETWORK_ALERTS)
+ .setAutoCancel(true)
+ .setTimeoutAfter(CANCEL_TIMEOUT_MILLISECONDS)
+ // TODO(zqiu): consider creating a new icon.
+ .setSmallIcon(com.android.internal.R.drawable.stat_notify_wifi_in_range)
+ .setContentTitle(mContext.getString(
+ com.android.internal.R.string.wifi_available_title_failed_to_connect))
+ .setContentText(ssid)
+ // TODO(zqiu): update to point to the new activity when it is ready.
+ .setContentIntent(mFrameworkFacade.getActivity(
+ mContext, 0, new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK),
+ PendingIntent.FLAG_UPDATE_CURRENT))
+ .setColor(mContext.getResources().getColor(
+ com.android.internal.R.color.system_notification_accent_color));
+ mNotificationManager.notify(NOTIFICATION_ID, builder.build());
+ }
+
+ /**
+ * Dismiss the notification that was generated by {@link #showNotification}. The notification
+ * might have already been dismissed, either by user or timeout. We'll attempt to dismiss it
+ * regardless if it is been dismissed or not, to reduce code complexity.
+ */
+ private void dismissNotification() {
+ // Notification might have already been dismissed, either by user or timeout. It is
+ // still okay to cancel it if already dismissed.
+ mNotificationManager.cancel(null, NOTIFICATION_ID);
+ }
+}