Skip to content

Commit 6b66e9e

Browse files
committed
Switch to notifications for walled garden
Also, switches the URL for browser to the actual URL used for checking walled garden Bug: 5398921 Change-Id: Ie4d4b1d47f4151d0f85975b10190bdcf5f2e7a57
1 parent 74b496d commit 6b66e9e

File tree

2 files changed

+77
-42
lines changed

2 files changed

+77
-42
lines changed

core/res/res/values/strings.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2721,6 +2721,12 @@
27212721
<item quantity="other">Open Wi-Fi networks available</item>
27222722
</plurals>
27232723

2724+
<!-- A notification is shown when a captive portal network is detected. This is the notification's title. -->
2725+
<string name="wifi_available_sign_in">Sign in to Wi-Fi network</string>
2726+
2727+
<!-- A notification is shown when a captive portal network is detected. This is the notification's message. -->
2728+
<string name="wifi_available_sign_in_detailed"><xliff:g id="wifi_network_ssid">%1$s</xliff:g></string>
2729+
27242730
<!-- A notification is shown when a user's selected SSID is later disabled due to connectivity problems. This is the notification's title / ticker. -->
27252731
<string name="wifi_watchdog_network_disabled">Couldn\'t connect to Wi-Fi</string>
27262732
<!-- A notification is shown when a user's selected SSID is later disabled due to connectivity problems. The complete alert msg is: <hotspot name> + this string, i.e. "Linksys has a poor internet connection" -->

wifi/java/android/net/wifi/WifiWatchdogStateMachine.java

Lines changed: 71 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import android.provider.Settings.Secure;
3838
import android.util.Log;
3939

40+
import com.android.internal.R;
4041
import com.android.internal.util.Protocol;
4142
import com.android.internal.util.State;
4243
import com.android.internal.util.StateMachine;
@@ -68,7 +69,8 @@ public class WifiWatchdogStateMachine extends StateMachine {
6869

6970
private static final boolean DBG = false;
7071
private static final String TAG = "WifiWatchdogStateMachine";
71-
private static final String WATCHDOG_NOTIFICATION_ID = "Android.System.WifiWatchdog";
72+
private static final String DISABLED_NETWORK_NOTIFICATION_ID = "WifiWatchdog.networkdisabled";
73+
private static final String WALLED_GARDEN_NOTIFICATION_ID = "WifiWatchdog.walledgarden";
7274

7375
private static final int WIFI_SIGNAL_LEVELS = 4;
7476
/**
@@ -185,7 +187,8 @@ public class WifiWatchdogStateMachine extends StateMachine {
185187
*/
186188
public boolean mDisableAPNextFailure = false;
187189
private static boolean sWifiOnly = false;
188-
private boolean mNotificationShown;
190+
private boolean mDisabledNotificationShown;
191+
private boolean mWalledGardenNotificationShown;
189192
public boolean mHasConnectedWifiManager = false;
190193

191194
/**
@@ -477,51 +480,76 @@ private void resetWatchdogState() {
477480
mLastWalledGardenCheckTime = null;
478481
mNumCheckFailures = 0;
479482
mBssids.clear();
480-
cancelNetworkNotification();
483+
setDisabledNetworkNotificationVisible(false);
484+
setWalledGardenNotificationVisible(false);
481485
}
482486

483-
private void popUpBrowser() {
484-
Uri uri = Uri.parse("http://www.google.com");
485-
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
486-
intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT |
487-
Intent.FLAG_ACTIVITY_NEW_TASK);
488-
mContext.startActivity(intent);
489-
}
487+
private void setWalledGardenNotificationVisible(boolean visible) {
488+
// If it should be hidden and it is already hidden, then noop
489+
if (!visible && !mWalledGardenNotificationShown) {
490+
return;
491+
}
490492

491-
private void displayDisabledNetworkNotification(String ssid) {
492493
Resources r = Resources.getSystem();
493-
CharSequence title =
494-
r.getText(com.android.internal.R.string.wifi_watchdog_network_disabled);
495-
String msg = ssid +
496-
r.getText(com.android.internal.R.string.wifi_watchdog_network_disabled_detailed);
497-
498-
Notification wifiDisabledWarning = new Notification.Builder(mContext)
499-
.setSmallIcon(com.android.internal.R.drawable.stat_sys_warning)
500-
.setDefaults(Notification.DEFAULT_ALL)
501-
.setTicker(title)
502-
.setContentTitle(title)
503-
.setContentText(msg)
504-
.setContentIntent(PendingIntent.getActivity(mContext, 0,
505-
new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK)
506-
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0))
507-
.setWhen(System.currentTimeMillis())
508-
.setAutoCancel(true)
509-
.getNotification();
510-
511494
NotificationManager notificationManager = (NotificationManager) mContext
512-
.getSystemService(Context.NOTIFICATION_SERVICE);
513-
514-
notificationManager.notify(WATCHDOG_NOTIFICATION_ID, 1, wifiDisabledWarning);
515-
mNotificationShown = true;
495+
.getSystemService(Context.NOTIFICATION_SERVICE);
496+
497+
if (visible) {
498+
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(mWalledGardenUrl));
499+
intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
500+
501+
CharSequence title = r.getString(R.string.wifi_available_sign_in, 0);
502+
CharSequence details = r.getString(R.string.wifi_available_sign_in_detailed,
503+
mConnectionInfo.getSSID());
504+
505+
Notification notification = new Notification();
506+
notification.when = 0;
507+
notification.icon = com.android.internal.R.drawable.stat_notify_wifi_in_range;
508+
notification.flags = Notification.FLAG_AUTO_CANCEL;
509+
notification.contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
510+
notification.tickerText = title;
511+
notification.setLatestEventInfo(mContext, title, details, notification.contentIntent);
512+
513+
notificationManager.notify(WALLED_GARDEN_NOTIFICATION_ID, 1, notification);
514+
} else {
515+
notificationManager.cancel(WALLED_GARDEN_NOTIFICATION_ID, 1);
516+
}
517+
mWalledGardenNotificationShown = visible;
516518
}
517519

518-
public void cancelNetworkNotification() {
519-
if (mNotificationShown) {
520-
NotificationManager notificationManager = (NotificationManager) mContext
521-
.getSystemService(Context.NOTIFICATION_SERVICE);
522-
notificationManager.cancel(WATCHDOG_NOTIFICATION_ID, 1);
523-
mNotificationShown = false;
520+
private void setDisabledNetworkNotificationVisible(boolean visible) {
521+
// If it should be hidden and it is already hidden, then noop
522+
if (!visible && !mDisabledNotificationShown) {
523+
return;
524+
}
525+
526+
Resources r = Resources.getSystem();
527+
NotificationManager notificationManager = (NotificationManager) mContext
528+
.getSystemService(Context.NOTIFICATION_SERVICE);
529+
530+
if (visible) {
531+
CharSequence title = r.getText(R.string.wifi_watchdog_network_disabled);
532+
String msg = mConnectionInfo.getSSID() +
533+
r.getText(R.string.wifi_watchdog_network_disabled_detailed);
534+
535+
Notification wifiDisabledWarning = new Notification.Builder(mContext)
536+
.setSmallIcon(R.drawable.stat_sys_warning)
537+
.setDefaults(Notification.DEFAULT_ALL)
538+
.setTicker(title)
539+
.setContentTitle(title)
540+
.setContentText(msg)
541+
.setContentIntent(PendingIntent.getActivity(mContext, 0,
542+
new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK)
543+
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0))
544+
.setWhen(System.currentTimeMillis())
545+
.setAutoCancel(true)
546+
.getNotification();
547+
548+
notificationManager.notify(DISABLED_NETWORK_NOTIFICATION_ID, 1, wifiDisabledWarning);
549+
} else {
550+
notificationManager.cancel(DISABLED_NETWORK_NOTIFICATION_ID, 1);
524551
}
552+
mDisabledNotificationShown = visible;
525553
}
526554

527555
class DefaultState extends State {
@@ -576,9 +604,10 @@ public boolean processMessage(Message msg) {
576604
NetworkInfo networkInfo = (NetworkInfo)
577605
stateChangeIntent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
578606

607+
setDisabledNetworkNotificationVisible(false);
608+
setWalledGardenNotificationVisible(false);
579609
switch (networkInfo.getState()) {
580610
case CONNECTED:
581-
cancelNetworkNotification();
582611
WifiInfo wifiInfo = (WifiInfo)
583612
stateChangeIntent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO);
584613
if (wifiInfo == null) {
@@ -974,7 +1003,7 @@ public boolean processMessage(Message msg) {
9741003
}
9751004
mWifiManager.disableNetwork(networkId, WifiConfiguration.DISABLED_DNS_FAILURE);
9761005
if (mShowDisabledNotification && mConnectionInfo.isExplicitConnect()) {
977-
displayDisabledNetworkNotification(mConnectionInfo.getSSID());
1006+
setDisabledNetworkNotificationVisible(true);
9781007
}
9791008
transitionTo(mNotConnectedState);
9801009
} else {
@@ -1007,7 +1036,7 @@ public boolean processMessage(Message msg) {
10071036
}
10081037
return HANDLED;
10091038
}
1010-
popUpBrowser();
1039+
setWalledGardenNotificationVisible(true);
10111040
transitionTo(mOnlineWatchState);
10121041
return HANDLED;
10131042
}

0 commit comments

Comments
 (0)