Patches to add captive portal check toggle from @MSe1969

This commit is contained in:
Tad 2018-09-22 21:05:41 -04:00
parent 137c8d992d
commit 08c65c8334
4 changed files with 467 additions and 0 deletions

View File

@ -0,0 +1,189 @@
From d6e3b804873c9bdfb4126a9bf9a56f2b7da88ffe Mon Sep 17 00:00:00 2001
From: MSe <mse1969@posteo.de>
Date: Sat, 22 Sep 2018 16:20:36 +0200
Subject: [PATCH] Settings / Data usage: Add menu option to switch off captive
portal
* Extend menu in 'Data usage' to show a Checkbox with option to
switch off/on the captive portal, which is equivalent
to adb command 'settings put global captive_portal_mode [1|0]'
* Warning dialog is shown, when captive portal check is switched off
* Will be reset to default, if 'Reset network settings' is chosen
from the 'Network & Internet' menu
Change-Id: Ibbffdb5f3930df74ca8b4ba93d451f7fad086989
---
res/menu/data_usage.xml | 4 ++
res/values/cm_strings.xml | 5 ++
.../android/settings/ResetNetworkConfirm.java | 4 ++
.../settings/datausage/DataUsageSummary.java | 57 ++++++++++++++++++-
4 files changed, 69 insertions(+), 1 deletion(-)
diff --git a/res/menu/data_usage.xml b/res/menu/data_usage.xml
index f4c207b767..e47c3b25fc 100644
--- a/res/menu/data_usage.xml
+++ b/res/menu/data_usage.xml
@@ -21,4 +21,8 @@
<item
android:id="@+id/data_usage_menu_app_network_access"
android:title="@string/app_ops_permiss_name" />
+ <item
+ android:id="@+id/captive_portal_switch"
+ android:title="@string/captive_portal_switch_title"
+ android:checkable="true" />
</menu>
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
index f18d6d2c47..1039ea4e19 100644
--- a/res/values/cm_strings.xml
+++ b/res/values/cm_strings.xml
@@ -511,4 +511,9 @@
<!-- Burn in protection -->
<string name="burnin_protection_title">Display burn-in protection</string>
<string name="burnin_protection_summary">Periodically move items that are permanently shown on screen to avoid excessive screen wear in that area</string>
+
+ <!-- Captive Portal -->
+ <string name="captive_portal_switch_title">Disable Captive Portal</string>
+ <string name="captive_portal_switch_warning">Captive portal allows you to get information regarding the connection status. Are you sure you want to disable it?</string>
+ <string name="captive_portal_warning_positive">Disable</string>
</resources>
diff --git a/src/com/android/settings/ResetNetworkConfirm.java b/src/com/android/settings/ResetNetworkConfirm.java
index ece64b4310..cd4579a487 100644
--- a/src/com/android/settings/ResetNetworkConfirm.java
+++ b/src/com/android/settings/ResetNetworkConfirm.java
@@ -25,6 +25,7 @@
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
+import android.provider.Settings;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.view.LayoutInflater;
@@ -105,6 +106,9 @@ public void onClick(View v) {
ImsManager.factoryReset(context);
+ Settings.Global.putInt(context.getContentResolver(),
+ Settings.Global.CAPTIVE_PORTAL_MODE, 1);
+
Toast.makeText(context, R.string.reset_network_complete_toast, Toast.LENGTH_SHORT)
.show();
}
diff --git a/src/com/android/settings/datausage/DataUsageSummary.java b/src/com/android/settings/datausage/DataUsageSummary.java
index 702e6db0ae..98df2759b2 100644
--- a/src/com/android/settings/datausage/DataUsageSummary.java
+++ b/src/com/android/settings/datausage/DataUsageSummary.java
@@ -15,8 +15,11 @@
package com.android.settings.datausage;
import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
import android.content.ComponentName;
import android.content.Context;
+import android.content.DialogInterface;
import android.content.Intent;
import android.content.ActivityNotFoundException;
import android.net.ConnectivityManager;
@@ -28,6 +31,7 @@
import android.os.SystemProperties;
import android.os.UserManager;
import android.provider.SearchIndexableResource;
+import android.provider.Settings;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.telephony.SubscriptionInfo;
@@ -59,7 +63,9 @@
import static android.net.ConnectivityManager.TYPE_ETHERNET;
import static android.net.ConnectivityManager.TYPE_WIFI;
-public class DataUsageSummary extends DataUsageBase implements Indexable, DataUsageEditController {
+public class DataUsageSummary extends DataUsageBase
+ implements Indexable, DataUsageEditController,
+ DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
private static final String TAG = "DataUsageSummary";
static final boolean LOGD = false;
@@ -77,6 +83,7 @@
private Preference mLimitPreference;
private NetworkTemplate mDefaultTemplate;
private int mDataUsageTemplate;
+ private Dialog mCaptivePortalWarningDialog;
@Override
protected int getHelpResource() {
@@ -135,6 +142,7 @@ public void onCreate(Bundle icicle) {
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
if (UserManager.get(getContext()).isAdminUser()) {
inflater.inflate(R.menu.data_usage, menu);
+ menu.findItem(R.id.captive_portal_switch).setChecked(isCaptivePortalDisabled());
}
super.onCreateOptionsMenu(menu, inflater);
}
@@ -143,6 +151,8 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
public void onPrepareOptionsMenu(Menu menu) {
final Context context = getActivity();
final MenuItem networkaccess = menu.findItem(R.id.data_usage_menu_app_network_access);
+ final MenuItem captiveportal = menu.findItem(R.id.captive_portal_switch);
+ captiveportal.setChecked(isCaptivePortalDisabled());
if (networkaccess == null) {
return;
}
@@ -177,6 +187,22 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
return true;
}
+ case R.id.captive_portal_switch: {
+ if (isCaptivePortalDisabled()) {
+ setCaptivePortalMode(1);
+ } else {
+ if (mCaptivePortalWarningDialog != null) dismissDialogs();
+ mCaptivePortalWarningDialog = new AlertDialog.Builder(getActivity())
+ .setMessage(getActivity().getResources()
+ .getString(R.string.captive_portal_switch_warning))
+ .setTitle(R.string.captive_portal_switch_title)
+ .setPositiveButton(R.string.captive_portal_warning_positive, this)
+ .setNegativeButton(android.R.string.no, this)
+ .show();
+ mCaptivePortalWarningDialog.setOnDismissListener(this);
+ }
+ return true;
+ }
}
return false;
}
@@ -190,6 +216,35 @@ public boolean onPreferenceTreeClick(Preference preference) {
return super.onPreferenceTreeClick(preference);
}
+ public void onClick(DialogInterface dialog, int which) {
+ if (dialog == mCaptivePortalWarningDialog)
+ if (which == DialogInterface.BUTTON_POSITIVE)
+ setCaptivePortalMode(0);
+ }
+
+ public void onDismiss(DialogInterface dialog) {
+ if (dialog == mCaptivePortalWarningDialog)
+ mCaptivePortalWarningDialog = null;
+ }
+
+ private void dismissDialogs() {
+ if (mCaptivePortalWarningDialog != null) {
+ mCaptivePortalWarningDialog.dismiss();
+ mCaptivePortalWarningDialog = null;
+ }
+ }
+
+ private boolean isCaptivePortalDisabled() {
+ return (Settings.Global.getInt(getContext().getContentResolver(),
+ Settings.Global.CAPTIVE_PORTAL_MODE,
+ Settings.Global.CAPTIVE_PORTAL_MODE_PROMPT) == 0);
+ }
+
+ private void setCaptivePortalMode(int mode) {
+ Settings.Global.putInt(getContext().getContentResolver(),
+ Settings.Global.CAPTIVE_PORTAL_MODE, mode);
+ }
+
private void addMobileSection(int subId) {
TemplatePreferenceCategory category = (TemplatePreferenceCategory)
inflatePreferences(R.xml.data_usage_cellular);

View File

@ -0,0 +1,276 @@
From b4ea75129c4e6d54059011e27c34a1e90bbd7f07 Mon Sep 17 00:00:00 2001
From: MSe1969 <mse1969@posteo.de>
Date: Wed, 12 Sep 2018 19:37:38 +0200
Subject: [PATCH] Settings / Data usage: Add menu option to switch off captive
portal
* Extend menu in 'Data usage' to show a Checkbox with option to
switch off/on the captive portal, which is equivalent
to adb command 'settings put global captive_portal_mode [1|0]'
* Warning dialog is shown, when captive portal check is switched off
* Will be reset to default, if 'Reset network settings' is chosen
from the 'Network & Internet' menu
Change-Id: Ibbffdb5f3930df74ca8b4ba93d451f7fad086989
---
res/menu/data_usage.xml | 4 ++
res/values/cm_strings.xml | 5 ++
.../android/settings/ResetNetworkConfirm.java | 4 ++
.../settings/datausage/DataUsageSummary.java | 33 ++++++++-
.../network/CaptivePortalWarningDialog.java | 69 +++++++++++++++++++
.../CaptivePortalWarningDialogHost.java | 28 ++++++++
6 files changed, 142 insertions(+), 1 deletion(-)
create mode 100644 src/com/android/settings/network/CaptivePortalWarningDialog.java
create mode 100644 src/com/android/settings/network/CaptivePortalWarningDialogHost.java
diff --git a/res/menu/data_usage.xml b/res/menu/data_usage.xml
index 9fe6b60118..b8be11adbf 100644
--- a/res/menu/data_usage.xml
+++ b/res/menu/data_usage.xml
@@ -18,4 +18,8 @@
<item
android:id="@+id/data_usage_menu_cellular_networks"
android:title="@string/data_usage_menu_cellular_networks" />
+ <item
+ android:id="@+id/captive_portal_switch"
+ android:title="@string/captive_portal_switch_title"
+ android:checkable="true" />
</menu>
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
index 91238336d9..314074eff0 100644
--- a/res/values/cm_strings.xml
+++ b/res/values/cm_strings.xml
@@ -374,4 +374,9 @@
<string name="data_usage_app_restrict_data_summary">Enable usage of cellular data</string>
<string name="data_usage_app_restrict_wifi">Wi\u2011Fi data</string>
<string name="data_usage_app_restrict_wifi_summary">Enable usage of Wi\u2011Fi data</string>
+
+ <!-- Captive Portal -->
+ <string name="captive_portal_switch_title">Disable Captive Portal</string>
+ <string name="captive_portal_switch_warning">Captive portal allows you to get information regarding the connection status. Are you sure you want to disable it?</string>
+ <string name="captive_portal_warning_positive">Disable</string>
</resources>
diff --git a/src/com/android/settings/ResetNetworkConfirm.java b/src/com/android/settings/ResetNetworkConfirm.java
index f70d3c27ef..37dae5aa6c 100644
--- a/src/com/android/settings/ResetNetworkConfirm.java
+++ b/src/com/android/settings/ResetNetworkConfirm.java
@@ -27,6 +27,7 @@
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
+import android.provider.Settings;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.view.LayoutInflater;
@@ -108,6 +109,9 @@ public void onClick(View v) {
ImsManager.factoryReset(context);
restoreDefaultApn(context);
+ Settings.Global.putInt(context.getContentResolver(),
+ Settings.Global.CAPTIVE_PORTAL_MODE, 1);
+
Toast.makeText(context, R.string.reset_network_complete_toast, Toast.LENGTH_SHORT)
.show();
}
diff --git a/src/com/android/settings/datausage/DataUsageSummary.java b/src/com/android/settings/datausage/DataUsageSummary.java
index e37cc4a6c6..f5aba01b9c 100644
--- a/src/com/android/settings/datausage/DataUsageSummary.java
+++ b/src/com/android/settings/datausage/DataUsageSummary.java
@@ -32,6 +32,7 @@
import android.os.SystemProperties;
import android.os.UserManager;
import android.provider.SearchIndexableResource;
+import android.provider.Settings;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
@@ -47,6 +48,8 @@
import android.view.MenuInflater;
import android.view.MenuItem;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settings.network.CaptivePortalWarningDialog;
+import com.android.settings.network.CaptivePortalWarningDialogHost;
import com.android.settings.R;
import com.android.settings.SummaryPreference;
import com.android.settings.Utils;
@@ -64,7 +67,8 @@
* This class in deprecated use {@link DataPlanUsageSummary}.
*/
@Deprecated
-public class DataUsageSummary extends DataUsageBase implements Indexable, DataUsageEditController {
+public class DataUsageSummary extends DataUsageBase implements Indexable,
+ DataUsageEditController, CaptivePortalWarningDialogHost {
static final boolean LOGD = false;
@@ -94,6 +98,7 @@
private NetworkRestrictionsPreference mNetworkRestrictionPreference;
private WifiManager mWifiManager;
private NetworkPolicyEditor mPolicyEditor;
+ private Context mContext;
@Override
protected int getHelpResource() {
@@ -105,6 +110,7 @@ public void onCreate(Bundle icicle) {
super.onCreate(icicle);
final Context context = getContext();
+ mContext = context;
NetworkPolicyManager policyManager = NetworkPolicyManager.from(context);
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
mPolicyEditor = new NetworkPolicyEditor(policyManager);
@@ -162,6 +168,7 @@ public void onCreate(Bundle icicle) {
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
if (UserManager.get(getContext()).isAdminUser()) {
inflater.inflate(R.menu.data_usage, menu);
+ menu.findItem(R.id.captive_portal_switch).setChecked(isCaptivePortalDisabled());
}
super.onCreateOptionsMenu(menu, inflater);
}
@@ -176,6 +183,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
startActivity(intent);
return true;
}
+ case R.id.captive_portal_switch: {
+ if (isCaptivePortalDisabled()) {
+ setCaptivePortalMode(1);
+ } else {
+ CaptivePortalWarningDialog.show(this);
+ }
+ item.setChecked(isCaptivePortalDisabled());
+ return true;
+ }
}
return false;
}
@@ -189,6 +205,21 @@ public boolean onPreferenceTreeClick(Preference preference) {
return super.onPreferenceTreeClick(preference);
}
+ public void onCaptivePortalSwitchOffDialogConfirmed() {
+ setCaptivePortalMode(0);
+ }
+
+ private boolean isCaptivePortalDisabled() {
+ return (Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.CAPTIVE_PORTAL_MODE,
+ Settings.Global.CAPTIVE_PORTAL_MODE_PROMPT) == 0);
+ }
+
+ private void setCaptivePortalMode(int mode) {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.CAPTIVE_PORTAL_MODE, mode);
+ }
+
private void addMobileSection(int subId) {
addMobileSection(subId, null);
}
diff --git a/src/com/android/settings/network/CaptivePortalWarningDialog.java b/src/com/android/settings/network/CaptivePortalWarningDialog.java
new file mode 100644
index 0000000000..b274d6b9f5
--- /dev/null
+++ b/src/com/android/settings/network/CaptivePortalWarningDialog.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2018 The LineageOS 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.network;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.Fragment;
+import android.app.FragmentManager;
+import android.content.DialogInterface;
+import android.os.Bundle;
+
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.R;
+import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
+
+public class CaptivePortalWarningDialog extends InstrumentedDialogFragment implements
+ DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
+
+ public static final String TAG = "CaptivePortalWarningDialog";
+
+ public static void show(Fragment host) {
+ final FragmentManager manager = host.getActivity().getFragmentManager();
+ if (manager.findFragmentByTag(TAG) == null) {
+ final CaptivePortalWarningDialog dialog =
+ new CaptivePortalWarningDialog();
+ dialog.setTargetFragment(host, 0 /* requestCode */);
+ dialog.show(manager, TAG);
+ }
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ return MetricsProto.MetricsEvent.TYPE_UNKNOWN;
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ return new AlertDialog.Builder(getActivity())
+ .setTitle(R.string.captive_portal_switch_title)
+ .setMessage(R.string.captive_portal_switch_warning)
+ .setIconAttribute(android.R.attr.alertDialogIcon)
+ .setPositiveButton(R.string.captive_portal_warning_positive, this /* onClickListener */)
+ .setNegativeButton(android.R.string.no, null /* onClickListener */)
+ .create();
+ }
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ final CaptivePortalWarningDialogHost host = (CaptivePortalWarningDialogHost) getTargetFragment();
+ if (host == null) {
+ return;
+ }
+ host.onCaptivePortalSwitchOffDialogConfirmed();
+ }
+}
diff --git a/src/com/android/settings/network/CaptivePortalWarningDialogHost.java b/src/com/android/settings/network/CaptivePortalWarningDialogHost.java
new file mode 100644
index 0000000000..208042ad73
--- /dev/null
+++ b/src/com/android/settings/network/CaptivePortalWarningDialogHost.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2018 The LineageOS 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.network;
+
+/**
+ * Interface for CaptivePortalWarningDialogHost callbacks.
+ */
+public interface CaptivePortalWarningDialogHost {
+
+ /**
+ * Called when the user chooses 'Disable' on the warning dialog.
+ */
+ void onCaptivePortalSwitchOffDialogConfirmed();
+}

View File

@ -125,6 +125,7 @@ patch -p1 < "$DOS_PATCHES/android_packages_apps_PackageInstaller/64d8b44.diff";
enterAndClear "packages/apps/Settings";
git revert 2ebe6058c546194a301c1fd22963d6be4adbf961; #don't hide oem unlock
patch -p1 < "$DOS_PATCHES/android_packages_apps_Settings/0001-Captive_Portal_Toggle.patch"; #Add option to disable captive portal checks, credit @MSe1969
sed -i 's/private int mPasswordMaxLength = 16;/private int mPasswordMaxLength = 48;/' src/com/android/settings/ChooseLockPassword.java; #Increase max password length
if [ "$DOS_MICROG_INCLUDED" = "FULL" ]; then sed -i 's/GSETTINGS_PROVIDER = "com.google.settings";/GSETTINGS_PROVIDER = "com.google.oQuae4av";/' src/com/android/settings/PrivacySettings.java; fi; #microG doesn't support Backup, hide the options

View File

@ -127,6 +127,7 @@ rm -f AndroidManifest.xml.orig res/*/*.orig;
enterAndClear "packages/apps/Settings";
git revert a96df110e84123fe1273bff54feca3b4ca484dcd; #don't hide oem unlock
patch -p1 < "$DOS_PATCHES/android_packages_apps_Settings/0001-Captive_Portal_Toggle.patch"; #Add option to disable captive portal checks, credit @MSe1969
patch -p1 < "$DOS_PATCHES/android_packages_apps_Settings/0004-PDB_Fixes.patch"; #Fix crashes when the PersistentDataBlockManager service isn't available
sed -i 's/private int mPasswordMaxLength = 16;/private int mPasswordMaxLength = 48;/' src/com/android/settings/password/ChooseLockPassword.java; #Increase max password length
if [ "$DOS_MICROG_INCLUDED" = "FULL" ]; then sed -i 's/GSETTINGS_PROVIDER = "com.google.settings";/GSETTINGS_PROVIDER = "com.google.oQuae4av";/' src/com/android/settings/PrivacySettings.java; fi; #microG doesn't support Backup, hide the options