summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2015-04-03 17:31:19 +0900
committerLorenzo Colitti <lorenzo@google.com>2015-04-15 15:24:20 +0900
commit877b054bfe4d27862165246d46f3cfda13bd4fe4 (patch)
tree396c7a46ff5c382783afc5c73c378611eb3d2a39
parent2949a4ab4d342a315420ccda07c02075edccd4f0 (diff)
downloadpackages_apps_Settings-877b054bfe4d27862165246d46f3cfda13bd4fe4.tar.gz
packages_apps_Settings-877b054bfe4d27862165246d46f3cfda13bd4fe4.tar.bz2
packages_apps_Settings-877b054bfe4d27862165246d46f3cfda13bd4fe4.zip
Dialog box for networks without an Internet connection
Bug: 20081183 Change-Id: If4866a341382fa37745ae5aa2d10372f052d5dd6
-rw-r--r--AndroidManifest.xml13
-rw-r--r--res/values/strings.xml4
-rw-r--r--src/com/android/settings/wifi/WifiNoInternetDialog.java152
3 files changed, 169 insertions, 0 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 9ed8fabba..a8f285ea7 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -309,6 +309,19 @@
</intent-filter>
</activity>
+ <activity android:name=".wifi.WifiNoInternetDialog"
+ android:clearTaskOnLaunch="true"
+ android:excludeFromRecents="true"
+ android:exported="true"
+ android:permission="android.permission.CONNECTIVITY_INTERNAL"
+ android:taskAffinity=""
+ android:theme="@*android:style/Theme.Material.Light.Dialog.Alert">
+ <intent-filter>
+ <action android:name="android.net.conn.PROMPT_UNVALIDATED" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ </activity>
+
<!-- Suspect activity alias: targetActivity is Settings itself, does not define a name. Remove? -->
<activity-alias android:name=".wifi.WifiApSettings"
android:targetActivity="Settings">
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b31ab8e9e..4c9ce79d1 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1568,6 +1568,10 @@
<!-- Wifi settings button to connect in to a Hotspot. [CHAR LIMIT=50]-->
<string name="wifi_hotspot_connect">CONNECT</string>
+ <!-- Dialog text to tell the user that the selected network does not have Internet access. -->
+ <string name="no_internet_access_text">This network has no Internet access. Use this network anyway?</string>
+ <string name="no_internet_access_remember">Don\'t ask again for this network</string>
+
<!-- Button label to connect to a Wi-Fi network -->
<string name="wifi_connect">Connect</string>
<!-- Failured notification for connect -->
diff --git a/src/com/android/settings/wifi/WifiNoInternetDialog.java b/src/com/android/settings/wifi/WifiNoInternetDialog.java
new file mode 100644
index 000000000..a45d6a274
--- /dev/null
+++ b/src/com/android/settings/wifi/WifiNoInternetDialog.java
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.wifi;
+
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.net.ConnectivityManager;
+import android.net.ConnectivityManager.NetworkCallback;
+import android.net.Network;
+import android.net.NetworkInfo;
+import android.net.NetworkCapabilities;
+import android.net.NetworkRequest;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.CheckBox;
+import android.widget.TextView;
+
+import com.android.internal.app.AlertActivity;
+import com.android.internal.app.AlertController;
+import com.android.settings.R;
+
+public final class WifiNoInternetDialog extends AlertActivity implements
+ DialogInterface.OnClickListener {
+ private static final String TAG = "WifiNoInternetDialog";
+
+ private ConnectivityManager mCM;
+ private Network mNetwork;
+ private String mNetworkName;
+ private ConnectivityManager.NetworkCallback mNetworkCallback;
+ private CheckBox mAlwaysAllow;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ final Intent intent = getIntent();
+ if (intent == null ||
+ !intent.getAction().equals(ConnectivityManager.ACTION_PROMPT_UNVALIDATED)) {
+ Log.e(TAG, "Unexpected intent " + intent + ", exiting");
+ finish();
+ return;
+ }
+
+ mNetwork = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK);
+ if (mNetwork == null) {
+ Log.e(TAG, "ACTION_PROMPT_UNVALIDATED for null network, exiting");
+ finish();
+ return;
+ }
+
+ // TODO: add a registerNetworkCallback(Network network, NetworkCallback networkCallback) and
+ // simplify this.
+ final NetworkRequest.Builder builder = new NetworkRequest.Builder();
+ for (int i = 0; i < 256; i++) {
+ try {
+ builder.removeCapability(i);
+ } catch (IllegalArgumentException e) {}
+ }
+ final NetworkRequest request = builder.build();
+ mNetworkCallback = new NetworkCallback() {
+ public void onLost(Network network) {
+ // Close the dialog if the network disconnects.
+ if (mNetwork.equals(network)) {
+ Log.d(TAG, "Network " + mNetwork + " disconnected");
+ finish();
+ }
+ }
+ // TODO: implement onNetworkCapabilitiesChanged so we can close the dialog if the
+ // network is now validated.
+ };
+
+ mCM = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
+ mCM.registerNetworkCallback(request, mNetworkCallback);
+
+ final NetworkInfo ni = mCM.getNetworkInfo(mNetwork);
+ if (ni == null || !ni.isConnectedOrConnecting()) {
+ Log.d(TAG, "Network " + mNetwork + " is not connected: " + ni);
+ finish();
+ return;
+ }
+ mNetworkName = ni.getExtraInfo();
+ if (mNetworkName != null) {
+ mNetworkName = mNetworkName.replaceAll("^\"|\"$", ""); // Remove double quotes
+ }
+
+ createDialog();
+ }
+
+ private void createDialog() {
+ mAlert.setIcon(R.drawable.ic_settings_wireless);
+
+ final AlertController.AlertParams ap = mAlertParams;
+ ap.mTitle = mNetworkName;
+ ap.mMessage = getString(R.string.no_internet_access_text);
+ ap.mPositiveButtonText = getString(android.R.string.ok);
+ ap.mNegativeButtonText = getString(android.R.string.cancel);
+ ap.mPositiveButtonListener = this;
+ ap.mNegativeButtonListener = this;
+
+ final LayoutInflater inflater = LayoutInflater.from(ap.mContext);
+ final View checkbox = inflater.inflate(
+ com.android.internal.R.layout.always_use_checkbox, null);
+ ap.mView = checkbox;
+
+ mAlwaysAllow = (CheckBox) checkbox.findViewById(com.android.internal.R.id.alwaysUse);
+ mAlwaysAllow.setText(getString(R.string.no_internet_access_remember));
+
+ setupAlert();
+ }
+
+ @Override
+ protected void onDestroy() {
+ if (mNetworkCallback != null) {
+ mCM.unregisterNetworkCallback(mNetworkCallback);
+ mNetworkCallback = null;
+ }
+ super.onDestroy();
+ }
+
+ public void onClick(DialogInterface dialog, int which) {
+ final boolean accept = (which == BUTTON_POSITIVE);
+ final String action = (accept ? "Connect" : "Ignore");
+ final boolean always = mAlwaysAllow.isChecked();
+
+ switch (which) {
+ case BUTTON_POSITIVE:
+ case BUTTON_NEGATIVE:
+ mCM.setAcceptUnvalidated(mNetwork, accept, always);
+ Log.d(TAG, action + " network=" + mNetwork + (always ? " and remember" : ""));
+ break;
+ default:
+ break;
+ }
+ }
+}