diff options
author | Stephen Chen <stewchen@google.com> | 2017-09-07 15:27:27 -0700 |
---|---|---|
committer | Stephen Chen <stewchen@google.com> | 2017-09-07 15:27:27 -0700 |
commit | b6103294dc1e6785c8ba236582e53801e1f9f2cd (patch) | |
tree | 0fa20231d3b2abb2e0b8d05ab807c162b49bb97c /service | |
parent | 20361dcf2d45262685c8dec334c11f0b2c987702 (diff) |
ONA: Enable new UI and connection flow.
The new Open Network Available notification UI introduces a connection
flow in which users can connect to a recommended open network directly
by interacting with the notification. "Connect" and "See all" action
buttons are introduced to initiate the flow, and once a connection
attempt is made, the connection status will be reflected on the
notification.
Bug: 37357441
Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Change-Id: I30231c4f71476a7417a3b423848575d5488f51f7
Diffstat (limited to 'service')
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 a21c8473c..a98377620 100644 --- a/service/java/com/android/server/wifi/WifiConnectivityManager.java +++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java @@ -1071,7 +1071,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 |