am 6b66e9e4: Switch to notifications for walled garden
* commit '6b66e9e4c95b1c866ea63a0122fc199994fd7053': Switch to notifications for walled garden
This commit is contained in:
@@ -2721,6 +2721,12 @@
|
|||||||
<item quantity="other">Open Wi-Fi networks available</item>
|
<item quantity="other">Open Wi-Fi networks available</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
|
|
||||||
|
<!-- A notification is shown when a captive portal network is detected. This is the notification's title. -->
|
||||||
|
<string name="wifi_available_sign_in">Sign in to Wi-Fi network</string>
|
||||||
|
|
||||||
|
<!-- A notification is shown when a captive portal network is detected. This is the notification's message. -->
|
||||||
|
<string name="wifi_available_sign_in_detailed"><xliff:g id="wifi_network_ssid">%1$s</xliff:g></string>
|
||||||
|
|
||||||
<!-- A notification is shown when a user's selected SSID is later disabled due to connectivity problems. This is the notification's title / ticker. -->
|
<!-- A notification is shown when a user's selected SSID is later disabled due to connectivity problems. This is the notification's title / ticker. -->
|
||||||
<string name="wifi_watchdog_network_disabled">Couldn\'t connect to Wi-Fi</string>
|
<string name="wifi_watchdog_network_disabled">Couldn\'t connect to Wi-Fi</string>
|
||||||
<!-- 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" -->
|
<!-- 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" -->
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import android.provider.Settings;
|
|||||||
import android.provider.Settings.Secure;
|
import android.provider.Settings.Secure;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.internal.R;
|
||||||
import com.android.internal.util.Protocol;
|
import com.android.internal.util.Protocol;
|
||||||
import com.android.internal.util.State;
|
import com.android.internal.util.State;
|
||||||
import com.android.internal.util.StateMachine;
|
import com.android.internal.util.StateMachine;
|
||||||
@@ -68,7 +69,8 @@ public class WifiWatchdogStateMachine extends StateMachine {
|
|||||||
|
|
||||||
private static final boolean DBG = false;
|
private static final boolean DBG = false;
|
||||||
private static final String TAG = "WifiWatchdogStateMachine";
|
private static final String TAG = "WifiWatchdogStateMachine";
|
||||||
private static final String WATCHDOG_NOTIFICATION_ID = "Android.System.WifiWatchdog";
|
private static final String DISABLED_NETWORK_NOTIFICATION_ID = "WifiWatchdog.networkdisabled";
|
||||||
|
private static final String WALLED_GARDEN_NOTIFICATION_ID = "WifiWatchdog.walledgarden";
|
||||||
|
|
||||||
private static final int WIFI_SIGNAL_LEVELS = 4;
|
private static final int WIFI_SIGNAL_LEVELS = 4;
|
||||||
/**
|
/**
|
||||||
@@ -185,7 +187,8 @@ public class WifiWatchdogStateMachine extends StateMachine {
|
|||||||
*/
|
*/
|
||||||
public boolean mDisableAPNextFailure = false;
|
public boolean mDisableAPNextFailure = false;
|
||||||
private static boolean sWifiOnly = false;
|
private static boolean sWifiOnly = false;
|
||||||
private boolean mNotificationShown;
|
private boolean mDisabledNotificationShown;
|
||||||
|
private boolean mWalledGardenNotificationShown;
|
||||||
public boolean mHasConnectedWifiManager = false;
|
public boolean mHasConnectedWifiManager = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -477,51 +480,76 @@ public class WifiWatchdogStateMachine extends StateMachine {
|
|||||||
mLastWalledGardenCheckTime = null;
|
mLastWalledGardenCheckTime = null;
|
||||||
mNumCheckFailures = 0;
|
mNumCheckFailures = 0;
|
||||||
mBssids.clear();
|
mBssids.clear();
|
||||||
cancelNetworkNotification();
|
setDisabledNetworkNotificationVisible(false);
|
||||||
|
setWalledGardenNotificationVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void popUpBrowser() {
|
private void setWalledGardenNotificationVisible(boolean visible) {
|
||||||
Uri uri = Uri.parse("http://www.google.com");
|
// If it should be hidden and it is already hidden, then noop
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
if (!visible && !mWalledGardenNotificationShown) {
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT |
|
return;
|
||||||
Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
mContext.startActivity(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void displayDisabledNetworkNotification(String ssid) {
|
|
||||||
Resources r = Resources.getSystem();
|
|
||||||
CharSequence title =
|
|
||||||
r.getText(com.android.internal.R.string.wifi_watchdog_network_disabled);
|
|
||||||
String msg = ssid +
|
|
||||||
r.getText(com.android.internal.R.string.wifi_watchdog_network_disabled_detailed);
|
|
||||||
|
|
||||||
Notification wifiDisabledWarning = new Notification.Builder(mContext)
|
|
||||||
.setSmallIcon(com.android.internal.R.drawable.stat_sys_warning)
|
|
||||||
.setDefaults(Notification.DEFAULT_ALL)
|
|
||||||
.setTicker(title)
|
|
||||||
.setContentTitle(title)
|
|
||||||
.setContentText(msg)
|
|
||||||
.setContentIntent(PendingIntent.getActivity(mContext, 0,
|
|
||||||
new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK)
|
|
||||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0))
|
|
||||||
.setWhen(System.currentTimeMillis())
|
|
||||||
.setAutoCancel(true)
|
|
||||||
.getNotification();
|
|
||||||
|
|
||||||
NotificationManager notificationManager = (NotificationManager) mContext
|
|
||||||
.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
||||||
|
|
||||||
notificationManager.notify(WATCHDOG_NOTIFICATION_ID, 1, wifiDisabledWarning);
|
|
||||||
mNotificationShown = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cancelNetworkNotification() {
|
|
||||||
if (mNotificationShown) {
|
|
||||||
NotificationManager notificationManager = (NotificationManager) mContext
|
|
||||||
.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
||||||
notificationManager.cancel(WATCHDOG_NOTIFICATION_ID, 1);
|
|
||||||
mNotificationShown = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Resources r = Resources.getSystem();
|
||||||
|
NotificationManager notificationManager = (NotificationManager) mContext
|
||||||
|
.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
|
||||||
|
if (visible) {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(mWalledGardenUrl));
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
|
||||||
|
CharSequence title = r.getString(R.string.wifi_available_sign_in, 0);
|
||||||
|
CharSequence details = r.getString(R.string.wifi_available_sign_in_detailed,
|
||||||
|
mConnectionInfo.getSSID());
|
||||||
|
|
||||||
|
Notification notification = new Notification();
|
||||||
|
notification.when = 0;
|
||||||
|
notification.icon = com.android.internal.R.drawable.stat_notify_wifi_in_range;
|
||||||
|
notification.flags = Notification.FLAG_AUTO_CANCEL;
|
||||||
|
notification.contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
|
||||||
|
notification.tickerText = title;
|
||||||
|
notification.setLatestEventInfo(mContext, title, details, notification.contentIntent);
|
||||||
|
|
||||||
|
notificationManager.notify(WALLED_GARDEN_NOTIFICATION_ID, 1, notification);
|
||||||
|
} else {
|
||||||
|
notificationManager.cancel(WALLED_GARDEN_NOTIFICATION_ID, 1);
|
||||||
|
}
|
||||||
|
mWalledGardenNotificationShown = visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setDisabledNetworkNotificationVisible(boolean visible) {
|
||||||
|
// If it should be hidden and it is already hidden, then noop
|
||||||
|
if (!visible && !mDisabledNotificationShown) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Resources r = Resources.getSystem();
|
||||||
|
NotificationManager notificationManager = (NotificationManager) mContext
|
||||||
|
.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
|
||||||
|
if (visible) {
|
||||||
|
CharSequence title = r.getText(R.string.wifi_watchdog_network_disabled);
|
||||||
|
String msg = mConnectionInfo.getSSID() +
|
||||||
|
r.getText(R.string.wifi_watchdog_network_disabled_detailed);
|
||||||
|
|
||||||
|
Notification wifiDisabledWarning = new Notification.Builder(mContext)
|
||||||
|
.setSmallIcon(R.drawable.stat_sys_warning)
|
||||||
|
.setDefaults(Notification.DEFAULT_ALL)
|
||||||
|
.setTicker(title)
|
||||||
|
.setContentTitle(title)
|
||||||
|
.setContentText(msg)
|
||||||
|
.setContentIntent(PendingIntent.getActivity(mContext, 0,
|
||||||
|
new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK)
|
||||||
|
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0))
|
||||||
|
.setWhen(System.currentTimeMillis())
|
||||||
|
.setAutoCancel(true)
|
||||||
|
.getNotification();
|
||||||
|
|
||||||
|
notificationManager.notify(DISABLED_NETWORK_NOTIFICATION_ID, 1, wifiDisabledWarning);
|
||||||
|
} else {
|
||||||
|
notificationManager.cancel(DISABLED_NETWORK_NOTIFICATION_ID, 1);
|
||||||
|
}
|
||||||
|
mDisabledNotificationShown = visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
class DefaultState extends State {
|
class DefaultState extends State {
|
||||||
@@ -576,9 +604,10 @@ public class WifiWatchdogStateMachine extends StateMachine {
|
|||||||
NetworkInfo networkInfo = (NetworkInfo)
|
NetworkInfo networkInfo = (NetworkInfo)
|
||||||
stateChangeIntent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
|
stateChangeIntent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
|
||||||
|
|
||||||
|
setDisabledNetworkNotificationVisible(false);
|
||||||
|
setWalledGardenNotificationVisible(false);
|
||||||
switch (networkInfo.getState()) {
|
switch (networkInfo.getState()) {
|
||||||
case CONNECTED:
|
case CONNECTED:
|
||||||
cancelNetworkNotification();
|
|
||||||
WifiInfo wifiInfo = (WifiInfo)
|
WifiInfo wifiInfo = (WifiInfo)
|
||||||
stateChangeIntent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO);
|
stateChangeIntent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO);
|
||||||
if (wifiInfo == null) {
|
if (wifiInfo == null) {
|
||||||
@@ -974,7 +1003,7 @@ public class WifiWatchdogStateMachine extends StateMachine {
|
|||||||
}
|
}
|
||||||
mWifiManager.disableNetwork(networkId, WifiConfiguration.DISABLED_DNS_FAILURE);
|
mWifiManager.disableNetwork(networkId, WifiConfiguration.DISABLED_DNS_FAILURE);
|
||||||
if (mShowDisabledNotification && mConnectionInfo.isExplicitConnect()) {
|
if (mShowDisabledNotification && mConnectionInfo.isExplicitConnect()) {
|
||||||
displayDisabledNetworkNotification(mConnectionInfo.getSSID());
|
setDisabledNetworkNotificationVisible(true);
|
||||||
}
|
}
|
||||||
transitionTo(mNotConnectedState);
|
transitionTo(mNotConnectedState);
|
||||||
} else {
|
} else {
|
||||||
@@ -1007,7 +1036,7 @@ public class WifiWatchdogStateMachine extends StateMachine {
|
|||||||
}
|
}
|
||||||
return HANDLED;
|
return HANDLED;
|
||||||
}
|
}
|
||||||
popUpBrowser();
|
setWalledGardenNotificationVisible(true);
|
||||||
transitionTo(mOnlineWatchState);
|
transitionTo(mOnlineWatchState);
|
||||||
return HANDLED;
|
return HANDLED;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user