|
37 | 37 | import android.provider.Settings.Secure; |
38 | 38 | import android.util.Log; |
39 | 39 |
|
| 40 | +import com.android.internal.R; |
40 | 41 | import com.android.internal.util.Protocol; |
41 | 42 | import com.android.internal.util.State; |
42 | 43 | import com.android.internal.util.StateMachine; |
@@ -68,7 +69,8 @@ public class WifiWatchdogStateMachine extends StateMachine { |
68 | 69 |
|
69 | 70 | private static final boolean DBG = false; |
70 | 71 | 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"; |
72 | 74 |
|
73 | 75 | private static final int WIFI_SIGNAL_LEVELS = 4; |
74 | 76 | /** |
@@ -185,7 +187,8 @@ public class WifiWatchdogStateMachine extends StateMachine { |
185 | 187 | */ |
186 | 188 | public boolean mDisableAPNextFailure = false; |
187 | 189 | private static boolean sWifiOnly = false; |
188 | | - private boolean mNotificationShown; |
| 190 | + private boolean mDisabledNotificationShown; |
| 191 | + private boolean mWalledGardenNotificationShown; |
189 | 192 | public boolean mHasConnectedWifiManager = false; |
190 | 193 |
|
191 | 194 | /** |
@@ -477,51 +480,76 @@ private void resetWatchdogState() { |
477 | 480 | mLastWalledGardenCheckTime = null; |
478 | 481 | mNumCheckFailures = 0; |
479 | 482 | mBssids.clear(); |
480 | | - cancelNetworkNotification(); |
| 483 | + setDisabledNetworkNotificationVisible(false); |
| 484 | + setWalledGardenNotificationVisible(false); |
481 | 485 | } |
482 | 486 |
|
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 | + } |
490 | 492 |
|
491 | | - private void displayDisabledNetworkNotification(String ssid) { |
492 | 493 | 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 | | - |
511 | 494 | 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; |
516 | 518 | } |
517 | 519 |
|
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); |
524 | 551 | } |
| 552 | + mDisabledNotificationShown = visible; |
525 | 553 | } |
526 | 554 |
|
527 | 555 | class DefaultState extends State { |
@@ -576,9 +604,10 @@ public boolean processMessage(Message msg) { |
576 | 604 | NetworkInfo networkInfo = (NetworkInfo) |
577 | 605 | stateChangeIntent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); |
578 | 606 |
|
| 607 | + setDisabledNetworkNotificationVisible(false); |
| 608 | + setWalledGardenNotificationVisible(false); |
579 | 609 | switch (networkInfo.getState()) { |
580 | 610 | case CONNECTED: |
581 | | - cancelNetworkNotification(); |
582 | 611 | WifiInfo wifiInfo = (WifiInfo) |
583 | 612 | stateChangeIntent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO); |
584 | 613 | if (wifiInfo == null) { |
@@ -974,7 +1003,7 @@ public boolean processMessage(Message msg) { |
974 | 1003 | } |
975 | 1004 | mWifiManager.disableNetwork(networkId, WifiConfiguration.DISABLED_DNS_FAILURE); |
976 | 1005 | if (mShowDisabledNotification && mConnectionInfo.isExplicitConnect()) { |
977 | | - displayDisabledNetworkNotification(mConnectionInfo.getSSID()); |
| 1006 | + setDisabledNetworkNotificationVisible(true); |
978 | 1007 | } |
979 | 1008 | transitionTo(mNotConnectedState); |
980 | 1009 | } else { |
@@ -1007,7 +1036,7 @@ public boolean processMessage(Message msg) { |
1007 | 1036 | } |
1008 | 1037 | return HANDLED; |
1009 | 1038 | } |
1010 | | - popUpBrowser(); |
| 1039 | + setWalledGardenNotificationVisible(true); |
1011 | 1040 | transitionTo(mOnlineWatchState); |
1012 | 1041 | return HANDLED; |
1013 | 1042 | } |
|
0 commit comments