summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorStephen Chen <stewchen@google.com>2017-09-08 17:49:14 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-09-08 17:49:14 +0000
commitf0653448fc27d0f73d58a3abf948ef38609331e4 (patch)
tree0618c4c1fc1d262b2638210df87732f57e662953 /service
parentf0e94d946bdeb7c784a5c4a07b6d23de402958b3 (diff)
parentb6103294dc1e6785c8ba236582e53801e1f9f2cd (diff)
Merge "ONA: Enable new UI and connection flow." into oc-mr1-dev
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/ConnectToNetworkNotificationBuilder.java33
-rw-r--r--service/java/com/android/server/wifi/OpenNetworkNotifier.java53
-rw-r--r--service/java/com/android/server/wifi/WifiConnectivityManager.java2
3 files changed, 43 insertions, 45 deletions
diff --git a/service/java/com/android/server/wifi/ConnectToNetworkNotificationBuilder.java b/service/java/com/android/server/wifi/ConnectToNetworkNotificationBuilder.java
index c0960d405..38c0ad058 100644
--- a/service/java/com/android/server/wifi/ConnectToNetworkNotificationBuilder.java
+++ b/service/java/com/android/server/wifi/ConnectToNetworkNotificationBuilder.java
@@ -35,10 +35,6 @@ public class ConnectToNetworkNotificationBuilder {
public static final String ACTION_USER_DISMISSED_NOTIFICATION =
"com.android.server.wifi.ConnectToNetworkNotification.USER_DISMISSED_NOTIFICATION";
- /** Intent when user tapped the "Connect to Network" notification. */
- public static final String ACTION_USER_TAPPED_CONTENT =
- "com.android.server.wifi.ConnectToNetworkNotification.USER_TAPPED_CONTENT";
-
/** Intent when user tapped action button to connect to recommended network. */
public static final String ACTION_CONNECT_TO_NETWORK =
"com.android.server.wifi.ConnectToNetworkNotification.CONNECT_TO_NETWORK";
@@ -67,17 +63,24 @@ public class ConnectToNetworkNotificationBuilder {
* Creates the connect to network notification that alerts users of a recommended connectable
* network.
*
- * @param numNetworks Number of available open networks nearby
+ * There are two actions - "Options" link to the Wi-Fi picker activity, and "Connect" prompts
+ * the connection to the recommended network.
+ *
+ * @param network The network to be recommended
*/
- public Notification createConnectToNetworkNotification(int numNetworks) {
-
- CharSequence title = mResources.getQuantityText(
- com.android.internal.R.plurals.wifi_available, numNetworks);
- CharSequence content = mResources.getQuantityText(
- com.android.internal.R.plurals.wifi_available_detailed, numNetworks);
-
- return createNotificationBuilder(title, content)
- .setContentIntent(getPrivateBroadcast(ACTION_USER_TAPPED_CONTENT))
+ public Notification createConnectToNetworkNotification(ScanResult network) {
+ Notification.Action connectAction = new Notification.Action.Builder(
+ null /* icon */,
+ mResources.getText(R.string.wifi_available_action_connect),
+ getPrivateBroadcast(ACTION_CONNECT_TO_NETWORK)).build();
+ Notification.Action allNetworksAction = new Notification.Action.Builder(
+ null /* icon */,
+ mResources.getText(R.string.wifi_available_action_all_networks),
+ getPrivateBroadcast(ACTION_PICK_WIFI_NETWORK)).build();
+ return createNotificationBuilder(
+ mContext.getText(R.string.wifi_available_title), network.SSID)
+ .addAction(connectAction)
+ .addAction(allNetworksAction)
.build();
}
@@ -116,6 +119,7 @@ public class ConnectToNetworkNotificationBuilder {
mContext.getText(R.string.wifi_available_content_failed_to_connect))
.setContentIntent(
getPrivateBroadcast(ACTION_PICK_WIFI_NETWORK_AFTER_CONNECT_FAILURE))
+ .setAutoCancel(true)
.build();
}
@@ -124,7 +128,6 @@ public class ConnectToNetworkNotificationBuilder {
return mFrameworkFacade.makeNotificationBuilder(mContext,
SystemNotificationChannels.NETWORK_AVAILABLE)
.setSmallIcon(R.drawable.stat_notify_wifi_in_range)
- .setAutoCancel(true)
.setTicker(title)
.setContentTitle(title)
.setContentText(content)
diff --git a/service/java/com/android/server/wifi/OpenNetworkNotifier.java b/service/java/com/android/server/wifi/OpenNetworkNotifier.java
index d2d45c37c..31ff44b72 100644
--- a/service/java/com/android/server/wifi/OpenNetworkNotifier.java
+++ b/service/java/com/android/server/wifi/OpenNetworkNotifier.java
@@ -20,7 +20,6 @@ import static com.android.server.wifi.ConnectToNetworkNotificationBuilder.ACTION
import static com.android.server.wifi.ConnectToNetworkNotificationBuilder.ACTION_PICK_WIFI_NETWORK;
import static com.android.server.wifi.ConnectToNetworkNotificationBuilder.ACTION_PICK_WIFI_NETWORK_AFTER_CONNECT_FAILURE;
import static com.android.server.wifi.ConnectToNetworkNotificationBuilder.ACTION_USER_DISMISSED_NOTIFICATION;
-import static com.android.server.wifi.ConnectToNetworkNotificationBuilder.ACTION_USER_TAPPED_CONTENT;
import android.annotation.IntDef;
import android.annotation.NonNull;
@@ -169,7 +168,6 @@ 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);
filter.addAction(ACTION_PICK_WIFI_NETWORK);
filter.addAction(ACTION_PICK_WIFI_NETWORK_AFTER_CONNECT_FAILURE);
@@ -182,9 +180,6 @@ public class OpenNetworkNotifier {
@Override
public void onReceive(Context context, Intent intent) {
switch (intent.getAction()) {
- case ACTION_USER_TAPPED_CONTENT:
- handleUserClickedContentAction();
- break;
case ACTION_USER_DISMISSED_NOTIFICATION:
handleUserDismissedAction();
break;
@@ -257,18 +252,29 @@ public class OpenNetworkNotifier {
return;
}
- // Do not show or update the notification if screen is off. We want to avoid a race that
- // could occur between a user picking a network in settings and a network candidate picked
- // through network selection, which will happen because screen on triggers a new
- // connectivity scan.
- if (mState != STATE_NO_NOTIFICATION || !mScreenOn) {
+ // Not enough time has passed to show a recommendation notification again
+ if (mState == STATE_NO_NOTIFICATION
+ && mClock.getWallClockMillis() < mNotificationRepeatTime) {
return;
}
- mRecommendedNetwork = mOpenNetworkRecommender.recommendNetwork(
- availableNetworks, new ArraySet<>(mBlacklistedSsids));
+ // Do nothing when the screen is off and no notification is showing.
+ if (mState == STATE_NO_NOTIFICATION && !mScreenOn) {
+ return;
+ }
- postInitialNotification(availableNetworks.size());
+ // Only show a new or update an existing recommendation notification.
+ if (mState == STATE_NO_NOTIFICATION
+ || mState == STATE_SHOWING_RECOMMENDATION_NOTIFICATION) {
+ ScanResult recommendation = mOpenNetworkRecommender.recommendNetwork(
+ availableNetworks, new ArraySet<>(mBlacklistedSsids));
+
+ if (recommendation != null) {
+ postInitialNotification(recommendation);
+ } else {
+ clearPendingNotification(false /* resetRepeatTime */);
+ }
+ }
}
/** Handles screen state changes. */
@@ -321,19 +327,11 @@ public class OpenNetworkNotifier {
return (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
}
- private void postInitialNotification(int numNetworks) {
- if (mState != STATE_NO_NOTIFICATION
- && mState != STATE_SHOWING_RECOMMENDATION_NOTIFICATION) {
- return;
- }
- // Not enough time has passed to show the notification again
- if (mClock.getWallClockMillis() < mNotificationRepeatTime) {
- return;
- }
-
+ private void postInitialNotification(ScanResult recommendedNetwork) {
postNotification(mNotificationBuilder.createConnectToNetworkNotification(
- numNetworks));
+ recommendedNetwork));
mState = STATE_SHOWING_RECOMMENDATION_NOTIFICATION;
+ mRecommendedNetwork = recommendedNetwork;
mNotificationRepeatTime = mClock.getWallClockMillis() + mNotificationRepeatDelay;
}
@@ -372,6 +370,8 @@ public class OpenNetworkNotifier {
}
private void startWifiSettings() {
+ // Close notification drawer before opening the picker.
+ mContext.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
mContext.startActivity(
new Intent(Settings.ACTION_WIFI_SETTINGS)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
@@ -382,11 +382,6 @@ public class OpenNetworkNotifier {
startWifiSettings();
}
- private void handleUserClickedContentAction() {
- startWifiSettings();
- resetStateAndDelayNotification();
- }
-
private void handleUserDismissedAction() {
if (mState == STATE_SHOWING_RECOMMENDATION_NOTIFICATION) {
// blacklist dismissed network
diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java
index 1c5ac2821..7e730c838 100644
--- a/service/java/com/android/server/wifi/WifiConnectivityManager.java
+++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java
@@ -1073,7 +1073,7 @@ public class WifiConnectivityManager {
mWifiState = state;
if (mWifiState == WIFI_STATE_CONNECTED) {
- mOpenNetworkNotifier.clearPendingNotification(false /* resetRepeatDelay */);
+ mOpenNetworkNotifier.handleWifiConnected();
}
// Reset BSSID of last connection attempt and kick off