16.0+: Add captive portal toggle from @MSe1969

Source:
0045a97cb4
b483b4e9ab
18.1 is the 17.1 patch rebased

Wording was altered.

Already included in 14.1+15.1
This commit is contained in:
Tad 2021-07-10 21:11:33 -04:00
parent a43601e77b
commit c2b2aa5830
7 changed files with 1033 additions and 2 deletions

View File

@ -0,0 +1,333 @@
From 691104a3ab5f51328008ce579465859fea2a4a2c Mon Sep 17 00:00:00 2001
From: MSe1969 <mse1969@posteo.de>
Date: Mon, 10 Sep 2018 12:05:40 +0200
Subject: [PATCH] Network & Internet Settings: Add option to switch off Captive
portal check
* Option added in Network & Internet Settings, which is equivalent to
the adb shell command 'settings put global captive_portal_mode [1/0]'
* Will be reset to default, if 'Reset network settings' is chosen (menu)
* Warning dialog is shown, when captive portal check is switched off
* Hidden under 'advanced'
Change-Id: Ibbffdb5f3930df74ca8b4ba93d451f7fad086989
---
res/values-de/cm_strings.xml | 3 +
res/values/cm_strings.xml | 5 ++
res/xml/network_and_internet.xml | 6 ++
.../android/settings/ResetNetworkConfirm.java | 5 ++
...CaptivePortalModePreferenceController.java | 81 +++++++++++++++++++
.../network/CaptivePortalWarningDialog.java | 73 +++++++++++++++++
.../CaptivePortalWarningDialogHost.java | 32 ++++++++
.../network/NetworkDashboardFragment.java | 17 +++-
8 files changed, 221 insertions(+), 1 deletion(-)
create mode 100644 src/com/android/settings/network/CaptivePortalModePreferenceController.java
create mode 100644 src/com/android/settings/network/CaptivePortalWarningDialog.java
create mode 100644 src/com/android/settings/network/CaptivePortalWarningDialogHost.java
diff --git a/res/values-de/cm_strings.xml b/res/values-de/cm_strings.xml
index 53dca0e6e7..6389546594 100644
--- a/res/values-de/cm_strings.xml
+++ b/res/values-de/cm_strings.xml
@@ -308,4 +308,7 @@
<string name="tethering_allow_vpn_upstreams_title">Clients erlauben VPN zu verwenden</string>
<string name="tethering_allow_vpn_upstreams_summary">Erlaubt Hotspot-Clients die VPN-Verbindungen dieses Gerätes für die Upstream-Konnektivität zu verwenden</string>
<string name="network_settings_shortcut_title">Mobilfunknetz</string>
+ <string name="captive_portal_switch_title">Captive Portal Erkennung</string>
+ <string name="captive_portal_switch_summary">Ein-/Ausschalten der Captive-Portal-Erkennung (Vorgabe EIN).</string>
+ <string name="captive_portal_switch_warning">Nach dem Ausschalten der Captive-Portal-Erkennung empfangen Sie keine Verbindungs-Rückmeldung mehr. Wirklich fortfahren?</string>
</resources>
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
index 7d0b80d3c0..0a67cbe8ad 100644
--- a/res/values/cm_strings.xml
+++ b/res/values/cm_strings.xml
@@ -398,4 +398,9 @@
<!-- Label for settings shortcut: mobile network -->
<string name="network_settings_shortcut_title">Mobile network</string>
+
+ <!-- Captive Portal -->
+ <string name="captive_portal_switch_title">Captive portal mode</string>
+ <string name="captive_portal_switch_summary">Enable or disable the captive portal probing for connection attempts (default ON).</string>
+ <string name="captive_portal_switch_warning">If you switch off the captive portal, you will not receive connectivity informations any longer. Really switch off?</string>
</resources>
diff --git a/res/xml/network_and_internet.xml b/res/xml/network_and_internet.xml
index 6eda0b0966..899bc41dd2 100644
--- a/res/xml/network_and_internet.xml
+++ b/res/xml/network_and_internet.xml
@@ -101,4 +101,10 @@
android:positiveButtonText="@string/save"
android:negativeButtonText="@android:string/cancel" />
+ <SwitchPreference
+ android:key="captive_portal_switch"
+ android:title="@string/captive_portal_switch_title"
+ android:summary="@string/captive_portal_switch_summary"
+ android:order="20"/>
+
</PreferenceScreen>
--- a/src/com/android/settings/ResetNetworkConfirm.java
+++ b/src/com/android/settings/ResetNetworkConfirm.java
@@ -32,6 +32,7 @@ import android.os.Bundle;
import android.os.RecoverySystem;
import android.os.UserHandle;
import android.os.UserManager;
+import android.provider.Settings;
import android.provider.Telephony;
import android.support.annotation.VisibleForTesting;
import android.telephony.SubscriptionManager;
@@ -152,6 +153,10 @@ public class ResetNetworkConfirm extends InstrumentedFragment {
ImsManager.factoryReset(context);
restoreDefaultApn(context);
+
+ Settings.Global.putInt(context.getContentResolver(),
+ Settings.Global.CAPTIVE_PORTAL_MODE, 1);
+
esimFactoryReset(context, context.getPackageName());
// There has been issues when Sms raw table somehow stores orphan
// fragments. They lead to garbled message when new fragments come
diff --git a/src/com/android/settings/network/CaptivePortalModePreferenceController.java b/src/com/android/settings/network/CaptivePortalModePreferenceController.java
--- /dev/null
+++ b/src/com/android/settings/network/CaptivePortalModePreferenceController.java
@@ -0,0 +1,81 @@
+/*
+ * 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.Fragment;
+import android.content.Context;
+import android.provider.Settings;
+import android.support.v14.preference.SwitchPreference;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.AbstractPreferenceController;
+
+public class CaptivePortalModePreferenceController extends AbstractPreferenceController
+ implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
+
+ private static final String TAG = "CaptivePortalModePreferenceController";
+ private static final String CAPTIVE_PORTAL_SWITCH_KEY = "captive_portal_switch";
+
+ private SwitchPreference mCaptivePortalMode;
+ private Preference mPreference;
+ private final Fragment mFragment;
+
+ public CaptivePortalModePreferenceController(Context context, Fragment hostFragment) {
+ super(context);
+
+ mFragment = hostFragment;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ boolean value = (Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.CAPTIVE_PORTAL_MODE,
+ Settings.Global.CAPTIVE_PORTAL_MODE_PROMPT) != 0);
+ ((SwitchPreference) preference).setChecked(value);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ mPreference = preference;
+ if ((Boolean) newValue) {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.CAPTIVE_PORTAL_MODE, 1);
+ } else {
+ CaptivePortalWarningDialog.show(mFragment);
+ }
+ return true;
+ }
+
+ public void onCaptivePortalSwitchOffDialogConfirmed() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.CAPTIVE_PORTAL_MODE, 0);
+ }
+
+ public void onCaptivePortalSwitchOffDialogDismissed() {
+ updateState(mPreference);
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return true;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return CAPTIVE_PORTAL_SWITCH_KEY;
+ }
+}
diff --git a/src/com/android/settings/network/CaptivePortalWarningDialog.java b/src/com/android/settings/network/CaptivePortalWarningDialog.java
--- /dev/null
+++ b/src/com/android/settings/network/CaptivePortalWarningDialog.java
@@ -0,0 +1,73 @@
+/*
+ * 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(android.R.string.yes, this /* onClickListener */)
+ .setNegativeButton(android.R.string.no, this /* onClickListener */)
+ .create();
+ }
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ final CaptivePortalWarningDialogHost host = (CaptivePortalWarningDialogHost) getTargetFragment();
+ if (host == null) {
+ return;
+ }
+ if (which == DialogInterface.BUTTON_POSITIVE) {
+ host.onCaptivePortalSwitchOffDialogConfirmed();
+ } else {
+ host.onCaptivePortalSwitchOffDialogDismissed();
+ }
+ }
+}
diff --git a/src/com/android/settings/network/CaptivePortalWarningDialogHost.java b/src/com/android/settings/network/CaptivePortalWarningDialogHost.java
--- /dev/null
+++ b/src/com/android/settings/network/CaptivePortalWarningDialogHost.java
@@ -0,0 +1,32 @@
+/*
+ * 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 presses YES/ok on the warning dialog.
+ */
+ void onCaptivePortalSwitchOffDialogConfirmed();
+
+ /**
+ * Called when the user presses NO/cancel on the warning dialog.
+ */
+ void onCaptivePortalSwitchOffDialogDismissed();
+}
--- a/src/com/android/settings/network/NetworkDashboardFragment.java
+++ b/src/com/android/settings/network/NetworkDashboardFragment.java
@@ -44,7 +44,7 @@ import java.util.Arrays;
import java.util.List;
public class NetworkDashboardFragment extends DashboardFragment implements
- MobilePlanPreferenceHost {
+ MobilePlanPreferenceHost, CaptivePortalWarningDialogHost {
private static final String TAG = "NetworkDashboardFrag";
@@ -95,6 +95,8 @@ public class NetworkDashboardFragment extends DashboardFragment implements
new VpnPreferenceController(context);
final PrivateDnsPreferenceController privateDnsPreferenceController =
new PrivateDnsPreferenceController(context);
+ final CaptivePortalModePreferenceController captiveportalModePreferenceController =
+ new CaptivePortalModePreferenceController(context, fragment);
if (lifecycle != null) {
lifecycle.addObserver(mobilePlanPreferenceController);
@@ -112,9 +114,22 @@ public class NetworkDashboardFragment extends DashboardFragment implements
controllers.add(mobilePlanPreferenceController);
controllers.add(wifiPreferenceController);
controllers.add(privateDnsPreferenceController);
+ controllers.add(captiveportalModePreferenceController);
return controllers;
}
+ public void onCaptivePortalSwitchOffDialogConfirmed() {
+ final CaptivePortalModePreferenceController controller =
+ use(CaptivePortalModePreferenceController.class);
+ controller.onCaptivePortalSwitchOffDialogConfirmed();
+ }
+
+ public void onCaptivePortalSwitchOffDialogDismissed() {
+ final CaptivePortalModePreferenceController controller =
+ use(CaptivePortalModePreferenceController.class);
+ controller.onCaptivePortalSwitchOffDialogDismissed();
+ }
+
@Override
public void showMobilePlanMessageDialog() {
showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID);
--
2.31.1

View File

@ -0,0 +1,350 @@
From cc4ce5ddadd7eae71be49f505378dd81c59cd9da Mon Sep 17 00:00:00 2001
From: MSe1969 <mse1969@posteo.de>
Date: Mon, 10 Sep 2018 12:05:40 +0200
Subject: [PATCH] Network & Internet Settings: Add option to switch off Captive
portal check
* Option added in Network & Internet Settings, which is equivalent to
the adb shell command 'settings put global captive_portal_mode [1/0]'
* Will be reset to default, if 'Reset network settings' is chosen (menu)
* Warning dialog is shown, when captive portal check is switched off
* Hidden under 'advanced'
Cherry-picked from lin16-microG repo and adapted to Q (e.g. androidx pref.)
Change-Id: Ibbffdb5f3930df74ca8b4ba93d451f7fad086989
---
res/values-de/cm_strings.xml | 3 +
res/values/cm_strings.xml | 5 ++
res/xml/network_and_internet.xml | 6 ++
res/xml/network_and_internet_v2.xml | 6 ++
.../android/settings/ResetNetworkConfirm.java | 4 +
...CaptivePortalModePreferenceController.java | 82 +++++++++++++++++++
.../network/CaptivePortalWarningDialog.java | 74 +++++++++++++++++
.../CaptivePortalWarningDialogHost.java | 32 ++++++++
.../network/NetworkDashboardFragment.java | 17 +++-
9 files changed, 228 insertions(+), 1 deletion(-)
create mode 100644 src/com/android/settings/network/CaptivePortalModePreferenceController.java
create mode 100644 src/com/android/settings/network/CaptivePortalWarningDialog.java
create mode 100644 src/com/android/settings/network/CaptivePortalWarningDialogHost.java
diff --git a/res/values-de/cm_strings.xml b/res/values-de/cm_strings.xml
index ebb53e1237..f788f15ca4 100644
--- a/res/values-de/cm_strings.xml
+++ b/res/values-de/cm_strings.xml
@@ -112,4 +112,7 @@
<string name="backup_transport_title">Backup-Anbieter auswählen</string>
<string name="fast_charging_title">Schnelles Laden</string>
<string name="fast_charging_summary">Deaktivieren, um die vom Gerät beim Laden erzeugte Wärme zu reduzieren oder die Lebensdauer des Akkus zu verlängern</string>
+ <string name="captive_portal_switch_title">Captive Portal Erkennung</string>
+ <string name="captive_portal_switch_summary">Ein-/Ausschalten der Captive Portal Erkennung (Vorgabe EIN).</string>
+ <string name="captive_portal_switch_warning">Nach dem Ausschalten der Captive-Portal-Erkennung empfangen Sie keine Verbindungs-Rückmeldung mehr. Wirklich fortfahren?</string>
</resources>
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
index 12ad48e683..7d07c6dbe5 100644
--- a/res/values/cm_strings.xml
+++ b/res/values/cm_strings.xml
@@ -197,4 +197,9 @@
<!-- FastCharge feature -->
<string name="fast_charging_title">Fast charging</string>
<string name="fast_charging_summary">Disable to reduce the heat produced by the device while charging or to extend the lifespan of the battery</string>
+
+ <!-- Captive Portal -->
+ <string name="captive_portal_switch_title">Captive portal mode</string>
+ <string name="captive_portal_switch_summary">Enable or disable the captive portal probing for connection attempts (default ON).</string>
+ <string name="captive_portal_switch_warning">If you switch off the captive portal, you will not receive connectivity informations any longer. Really switch off?</string>
</resources>
diff --git a/res/xml/network_and_internet.xml b/res/xml/network_and_internet.xml
index 32b51d48fc..456f169e8f 100644
--- a/res/xml/network_and_internet.xml
+++ b/res/xml/network_and_internet.xml
@@ -97,4 +97,10 @@
android:positiveButtonText="@string/save"
android:negativeButtonText="@android:string/cancel" />
+ <SwitchPreference
+ android:key="captive_portal_switch"
+ android:title="@string/captive_portal_switch_title"
+ android:summary="@string/captive_portal_switch_summary"
+ android:order="20" />
+
</PreferenceScreen>
--- a/res/xml/network_and_internet_v2.xml
+++ b/res/xml/network_and_internet_v2.xml
@@ -107,4 +107,10 @@
android:positiveButtonText="@string/save"
android:negativeButtonText="@android:string/cancel" />
+ <SwitchPreference
+ android:key="captive_portal_switch"
+ android:title="@string/captive_portal_switch_title"
+ android:summary="@string/captive_portal_switch_summary"
+ android:order="25" />
+
</PreferenceScreen>
--- a/src/com/android/settings/ResetNetworkConfirm.java
+++ b/src/com/android/settings/ResetNetworkConfirm.java
@@ -35,6 +35,7 @@ import android.os.Bundle;
import android.os.RecoverySystem;
import android.os.UserHandle;
import android.os.UserManager;
+import android.provider.Settings;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.view.LayoutInflater;
@@ -125,6 +126,9 @@ public class ResetNetworkConfirm extends InstrumentedFragment {
}
}
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.CAPTIVE_PORTAL_MODE, 1);
+
ImsManager.getInstance(mContext,
SubscriptionManager.getPhoneId(mSubId)).factoryReset();
restoreDefaultApn(mContext);
diff --git a/src/com/android/settings/network/CaptivePortalModePreferenceController.java b/src/com/android/settings/network/CaptivePortalModePreferenceController.java
--- /dev/null
+++ b/src/com/android/settings/network/CaptivePortalModePreferenceController.java
@@ -0,0 +1,82 @@
+/*
+ * 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.content.Context;
+import android.provider.Settings;
+
+import androidx.fragment.app.Fragment;
+import androidx.preference.Preference;
+import androidx.preference.SwitchPreference;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.AbstractPreferenceController;
+
+public class CaptivePortalModePreferenceController extends AbstractPreferenceController
+ implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
+
+ private static final String TAG = "CaptivePortalModePreferenceController";
+ private static final String CAPTIVE_PORTAL_SWITCH_KEY = "captive_portal_switch";
+
+ private SwitchPreference mCaptivePortalMode;
+ private Preference mPreference;
+ private final Fragment mFragment;
+
+ public CaptivePortalModePreferenceController(Context context, Fragment hostFragment) {
+ super(context);
+
+ mFragment = hostFragment;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ boolean value = (Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.CAPTIVE_PORTAL_MODE,
+ Settings.Global.CAPTIVE_PORTAL_MODE_PROMPT) != 0);
+ ((SwitchPreference) preference).setChecked(value);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ mPreference = preference;
+ if ((Boolean) newValue) {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.CAPTIVE_PORTAL_MODE, 1);
+ } else {
+ CaptivePortalWarningDialog.show(mFragment);
+ }
+ return true;
+ }
+
+ public void onCaptivePortalSwitchOffDialogConfirmed() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.CAPTIVE_PORTAL_MODE, 0);
+ }
+
+ public void onCaptivePortalSwitchOffDialogDismissed() {
+ updateState(mPreference);
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return true;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return CAPTIVE_PORTAL_SWITCH_KEY;
+ }
+}
diff --git a/src/com/android/settings/network/CaptivePortalWarningDialog.java b/src/com/android/settings/network/CaptivePortalWarningDialog.java
--- /dev/null
+++ b/src/com/android/settings/network/CaptivePortalWarningDialog.java
@@ -0,0 +1,74 @@
+/*
+ * 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.Dialog;
+import android.content.DialogInterface;
+import android.os.Bundle;
+
+import androidx.appcompat.app.AlertDialog;
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentManager;
+
+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().getSupportFragmentManager();
+ 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(android.R.string.yes, this /* onClickListener */)
+ .setNegativeButton(android.R.string.no, this /* onClickListener */)
+ .create();
+ }
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ final CaptivePortalWarningDialogHost host = (CaptivePortalWarningDialogHost) getTargetFragment();
+ if (host == null) {
+ return;
+ }
+ if (which == DialogInterface.BUTTON_POSITIVE) {
+ host.onCaptivePortalSwitchOffDialogConfirmed();
+ } else {
+ host.onCaptivePortalSwitchOffDialogDismissed();
+ }
+ }
+}
diff --git a/src/com/android/settings/network/CaptivePortalWarningDialogHost.java b/src/com/android/settings/network/CaptivePortalWarningDialogHost.java
--- /dev/null
+++ b/src/com/android/settings/network/CaptivePortalWarningDialogHost.java
@@ -0,0 +1,32 @@
+/*
+ * 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 presses YES/ok on the warning dialog.
+ */
+ void onCaptivePortalSwitchOffDialogConfirmed();
+
+ /**
+ * Called when the user presses NO/cancel on the warning dialog.
+ */
+ void onCaptivePortalSwitchOffDialogDismissed();
+}
--- a/src/com/android/settings/network/NetworkDashboardFragment.java
+++ b/src/com/android/settings/network/NetworkDashboardFragment.java
@@ -44,7 +44,7 @@ import java.util.List;
@SearchIndexable
public class NetworkDashboardFragment extends DashboardFragment implements
- MobilePlanPreferenceHost {
+ MobilePlanPreferenceHost, CaptivePortalWarningDialogHost {
private static final String TAG = "NetworkDashboardFrag";
@@ -104,6 +104,8 @@ public class NetworkDashboardFragment extends DashboardFragment implements
new VpnPreferenceController(context);
final PrivateDnsPreferenceController privateDnsPreferenceController =
new PrivateDnsPreferenceController(context);
+ final CaptivePortalModePreferenceController captiveportalModePreferenceController =
+ new CaptivePortalModePreferenceController(context, fragment);
if (lifecycle != null) {
lifecycle.addObserver(mobilePlanPreferenceController);
@@ -129,9 +131,22 @@ public class NetworkDashboardFragment extends DashboardFragment implements
controllers.add(mobilePlanPreferenceController);
controllers.add(wifiPreferenceController);
controllers.add(privateDnsPreferenceController);
+ controllers.add(captiveportalModePreferenceController);
return controllers;
}
+ public void onCaptivePortalSwitchOffDialogConfirmed() {
+ final CaptivePortalModePreferenceController controller =
+ use(CaptivePortalModePreferenceController.class);
+ controller.onCaptivePortalSwitchOffDialogConfirmed();
+ }
+
+ public void onCaptivePortalSwitchOffDialogDismissed() {
+ final CaptivePortalModePreferenceController controller =
+ use(CaptivePortalModePreferenceController.class);
+ controller.onCaptivePortalSwitchOffDialogDismissed();
+ }
+
@Override
public void showMobilePlanMessageDialog() {
showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID);
--
2.31.1

View File

@ -0,0 +1,345 @@
From f5e94f458e2496c4b5bb6d4a1b239ce24b84d898 Mon Sep 17 00:00:00 2001
From: MSe1969 <mse1969@posteo.de>
Date: Mon, 10 Sep 2018 12:05:40 +0200
Subject: [PATCH] Network & Internet Settings: Add option to switch off Captive
portal check
* Option added in Network & Internet Settings, which is equivalent to
the adb shell command 'settings put global captive_portal_mode [1/0]'
* Will be reset to default, if 'Reset network settings' is chosen (menu)
* Warning dialog is shown, when captive portal check is switched off
* Hidden under 'advanced'
Cherry-picked from lin16-microG repo and adapted to Q (e.g. androidx pref.)
Change-Id: Ibbffdb5f3930df74ca8b4ba93d451f7fad086989
---
res/values-de/cm_strings.xml | 3 +
res/values/cm_strings.xml | 5 ++
res/xml/network_and_internet.xml | 6 ++
.../android/settings/ResetNetworkConfirm.java | 1 +
.../settings/ResetNetworkConfirm.java.rej | 11 +++
...CaptivePortalModePreferenceController.java | 82 +++++++++++++++++++
.../network/CaptivePortalWarningDialog.java | 74 +++++++++++++++++
.../CaptivePortalWarningDialogHost.java | 32 ++++++++
.../network/NetworkDashboardFragment.java | 17 +++-
9 files changed, 230 insertions(+), 1 deletion(-)
create mode 100644 src/com/android/settings/ResetNetworkConfirm.java.rej
create mode 100644 src/com/android/settings/network/CaptivePortalModePreferenceController.java
create mode 100644 src/com/android/settings/network/CaptivePortalWarningDialog.java
create mode 100644 src/com/android/settings/network/CaptivePortalWarningDialogHost.java
diff --git a/res/values-de/cm_strings.xml b/res/values-de/cm_strings.xml
index b21028ad93..f74eccd3d8 100644
--- a/res/values-de/cm_strings.xml
+++ b/res/values-de/cm_strings.xml
@@ -92,4 +92,7 @@
<string name="connected_tws_device_saved_title">Gespeicherte Kopfhörer</string>
<string name="fast_charging_title">Schnelles Laden</string>
<string name="fast_charging_summary">Deaktivieren, um die vom Gerät beim Laden erzeugte Wärme zu reduzieren oder die Lebensdauer des Akkus zu verlängern</string>
+ <string name="captive_portal_switch_title">Captive Portal Erkennung</string>
+ <string name="captive_portal_switch_summary">Ein-/Ausschalten der Captive Portal Erkennung (Vorgabe EIN).</string>
+ <string name="captive_portal_switch_warning">Nach dem Ausschalten der Captive-Portal-Erkennung empfangen Sie keine Verbindungs-Rückmeldung mehr. Wirklich fortfahren?</string>
</resources>
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
index c93c6e9959..cb46aff0ce 100644
--- a/res/values/cm_strings.xml
+++ b/res/values/cm_strings.xml
@@ -159,4 +159,9 @@
<!-- FastCharge feature -->
<string name="fast_charging_title">Fast charging</string>
<string name="fast_charging_summary">Disable to reduce the heat produced by the device while charging or to extend the lifespan of the battery</string>
+
+ <!-- Captive Portal -->
+ <string name="captive_portal_switch_title">Captive portal mode</string>
+ <string name="captive_portal_switch_summary">Enable or disable the captive portal probing for connection attempts (default ON).</string>
+ <string name="captive_portal_switch_warning">If you switch off the captive portal, you will not receive connectivity informations any longer. Really switch off?</string>
</resources>
diff --git a/res/xml/network_and_internet.xml b/res/xml/network_and_internet.xml
index 6bf6dbaccf..5773f6d2da 100644
--- a/res/xml/network_and_internet.xml
+++ b/res/xml/network_and_internet.xml
@@ -118,6 +118,12 @@
android:positiveButtonText="@string/save"
android:negativeButtonText="@android:string/cancel" />
+ <SwitchPreference
+ android:key="captive_portal_switch"
+ android:title="@string/captive_portal_switch_title"
+ android:summary="@string/captive_portal_switch_summary"
+ android:order="20" />
+
<Preference
android:fragment="com.android.settings.network.AdaptiveConnectivitySettings"
android:key="adaptive_connectivity"
--- a/src/com/android/settings/ResetNetworkConfirm.java
+++ b/src/com/android/settings/ResetNetworkConfirm.java
@@ -35,6 +35,7 @@ import android.os.Bundle;
import android.os.RecoverySystem;
import android.os.UserHandle;
import android.os.UserManager;
+import android.provider.Settings;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.view.LayoutInflater;
diff --git a/src/com/android/settings/ResetNetworkConfirm.java.rej b/src/com/android/settings/ResetNetworkConfirm.java.rej
--- /dev/null
+++ b/src/com/android/settings/ResetNetworkConfirm.java.rej
@@ -0,0 +1,11 @@
+diff a/src/com/android/settings/ResetNetworkConfirm.java b/src/com/android/settings/ResetNetworkConfirm.java (rejected hunks)
+@@ -125,6 +126,9 @@ public class ResetNetworkConfirm extends InstrumentedFragment {
+ }
+ }
+
++ Settings.Global.putInt(mContext.getContentResolver(),
++ Settings.Global.CAPTIVE_PORTAL_MODE, 1);
++
+ ImsManager.getInstance(mContext,
+ SubscriptionManager.getPhoneId(mSubId)).factoryReset();
+ restoreDefaultApn(mContext);
diff --git a/src/com/android/settings/network/CaptivePortalModePreferenceController.java b/src/com/android/settings/network/CaptivePortalModePreferenceController.java
--- /dev/null
+++ b/src/com/android/settings/network/CaptivePortalModePreferenceController.java
@@ -0,0 +1,82 @@
+/*
+ * 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.content.Context;
+import android.provider.Settings;
+
+import androidx.fragment.app.Fragment;
+import androidx.preference.Preference;
+import androidx.preference.SwitchPreference;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.AbstractPreferenceController;
+
+public class CaptivePortalModePreferenceController extends AbstractPreferenceController
+ implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
+
+ private static final String TAG = "CaptivePortalModePreferenceController";
+ private static final String CAPTIVE_PORTAL_SWITCH_KEY = "captive_portal_switch";
+
+ private SwitchPreference mCaptivePortalMode;
+ private Preference mPreference;
+ private final Fragment mFragment;
+
+ public CaptivePortalModePreferenceController(Context context, Fragment hostFragment) {
+ super(context);
+
+ mFragment = hostFragment;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ boolean value = (Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.CAPTIVE_PORTAL_MODE,
+ Settings.Global.CAPTIVE_PORTAL_MODE_PROMPT) != 0);
+ ((SwitchPreference) preference).setChecked(value);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ mPreference = preference;
+ if ((Boolean) newValue) {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.CAPTIVE_PORTAL_MODE, 1);
+ } else {
+ CaptivePortalWarningDialog.show(mFragment);
+ }
+ return true;
+ }
+
+ public void onCaptivePortalSwitchOffDialogConfirmed() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.CAPTIVE_PORTAL_MODE, 0);
+ }
+
+ public void onCaptivePortalSwitchOffDialogDismissed() {
+ updateState(mPreference);
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return true;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return CAPTIVE_PORTAL_SWITCH_KEY;
+ }
+}
diff --git a/src/com/android/settings/network/CaptivePortalWarningDialog.java b/src/com/android/settings/network/CaptivePortalWarningDialog.java
--- /dev/null
+++ b/src/com/android/settings/network/CaptivePortalWarningDialog.java
@@ -0,0 +1,74 @@
+/*
+ * 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.Dialog;
+import android.content.DialogInterface;
+import android.os.Bundle;
+
+import androidx.appcompat.app.AlertDialog;
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentManager;
+
+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().getSupportFragmentManager();
+ 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(android.R.string.yes, this /* onClickListener */)
+ .setNegativeButton(android.R.string.no, this /* onClickListener */)
+ .create();
+ }
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ final CaptivePortalWarningDialogHost host = (CaptivePortalWarningDialogHost) getTargetFragment();
+ if (host == null) {
+ return;
+ }
+ if (which == DialogInterface.BUTTON_POSITIVE) {
+ host.onCaptivePortalSwitchOffDialogConfirmed();
+ } else {
+ host.onCaptivePortalSwitchOffDialogDismissed();
+ }
+ }
+}
diff --git a/src/com/android/settings/network/CaptivePortalWarningDialogHost.java b/src/com/android/settings/network/CaptivePortalWarningDialogHost.java
--- /dev/null
+++ b/src/com/android/settings/network/CaptivePortalWarningDialogHost.java
@@ -0,0 +1,32 @@
+/*
+ * 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 presses YES/ok on the warning dialog.
+ */
+ void onCaptivePortalSwitchOffDialogConfirmed();
+
+ /**
+ * Called when the user presses NO/cancel on the warning dialog.
+ */
+ void onCaptivePortalSwitchOffDialogDismissed();
+}
--- a/src/com/android/settings/network/NetworkDashboardFragment.java
+++ b/src/com/android/settings/network/NetworkDashboardFragment.java
@@ -41,7 +41,7 @@ import java.util.List;
@SearchIndexable
public class NetworkDashboardFragment extends DashboardFragment implements
- MobilePlanPreferenceHost {
+ MobilePlanPreferenceHost, CaptivePortalWarningDialogHost {
private static final String TAG = "NetworkDashboardFrag";
@@ -103,6 +103,8 @@ public class NetworkDashboardFragment extends DashboardFragment implements
new VpnPreferenceController(context);
final PrivateDnsPreferenceController privateDnsPreferenceController =
new PrivateDnsPreferenceController(context);
+ final CaptivePortalModePreferenceController captiveportalModePreferenceController =
+ new CaptivePortalModePreferenceController(context, fragment);
if (lifecycle != null) {
lifecycle.addObserver(mobilePlanPreferenceController);
@@ -120,9 +122,22 @@ public class NetworkDashboardFragment extends DashboardFragment implements
controllers.add(mobilePlanPreferenceController);
controllers.add(wifiPreferenceController);
controllers.add(privateDnsPreferenceController);
+ controllers.add(captiveportalModePreferenceController);
return controllers;
}
+ public void onCaptivePortalSwitchOffDialogConfirmed() {
+ final CaptivePortalModePreferenceController controller =
+ use(CaptivePortalModePreferenceController.class);
+ controller.onCaptivePortalSwitchOffDialogConfirmed();
+ }
+
+ public void onCaptivePortalSwitchOffDialogDismissed() {
+ final CaptivePortalModePreferenceController controller =
+ use(CaptivePortalModePreferenceController.class);
+ controller.onCaptivePortalSwitchOffDialogDismissed();
+ }
+
@Override
public void showMobilePlanMessageDialog() {
showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID);
--
2.31.1

View File

@ -198,6 +198,7 @@ fi;
if enterAndClear "packages/apps/Settings"; then
git revert --no-edit c240992b4c86c7f226290807a2f41f2619e7e5e8; #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 (MSe)
sed -i 's/private int mPasswordMaxLength = 16;/private int mPasswordMaxLength = 48;/' src/com/android/settings/password/ChooseLockPassword.java; #Increase max password length (GrapheneOS)
sed -i 's/if (isFullDiskEncrypted()) {/if (false) {/' src/com/android/settings/accessibility/*AccessibilityService*.java; #Never disable secure start-up when enabling an accessibility service
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

@ -193,6 +193,7 @@ fi;
if enterAndClear "packages/apps/Settings"; then
git revert --no-edit 486980cfecce2ca64267f41462f9371486308e9d; #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 (MSe)
sed -i 's/private int mPasswordMaxLength = 16;/private int mPasswordMaxLength = 48;/' src/com/android/settings/password/ChooseLockPassword.java; #Increase max password length (GrapheneOS)
sed -i 's/if (isFullDiskEncrypted()) {/if (false) {/' src/com/android/settings/accessibility/*AccessibilityService*.java; #Never disable secure start-up when enabling an accessibility service
if [ "$DOS_MICROG_INCLUDED" = "FULL" ]; then sed -i 's/GSETTINGS_PROVIDER = "com.google.settings";/GSETTINGS_PROVIDER = "com.google.oQuae4av";/' src/com/android/settings/backup/PrivacySettingsUtils.java; fi; #microG doesn't support Backup, hide the options

View File

@ -109,9 +109,9 @@ patchWorkspace() {
umask 0022;
if [ "$DOS_MALWARE_SCAN_ENABLED" = true ]; then scanForMalware false "$DOS_PREBUILT_APPS $DOS_BUILD_BASE/build $DOS_BUILD_BASE/device $DOS_BUILD_BASE/vendor/lineage"; fi;
#source build/envsetup.sh;
source build/envsetup.sh;
#repopick -i 312861; #recorder intent improvement
#repopick -it android-11.0.0_r39;
repopick -it android-11.0.0_r39; #XXX: manifests change must be manually picked
source "$DOS_SCRIPTS/Patch.sh";
source "$DOS_SCRIPTS_COMMON/Copy_Keys.sh";

View File

@ -168,6 +168,7 @@ if [ "$DOS_MICROG_INCLUDED" = "FULL" ]; then patch -p1 < "$DOS_PATCHES/android_p
fi;
if enterAndClear "packages/apps/Settings"; then
patch -p1 < "$DOS_PATCHES/android_packages_apps_Settings/0001-Captive_Portal_Toggle.patch"; #Add option to disable captive portal checks (MSe)
sed -i 's/if (isFullDiskEncrypted()) {/if (false) {/' src/com/android/settings/accessibility/*AccessibilityService*.java; #Never disable secure start-up when enabling an accessibility service
if [ "$DOS_MICROG_INCLUDED" = "FULL" ]; then sed -i 's/GSETTINGS_PROVIDER = "com.google.settings";/GSETTINGS_PROVIDER = "com.google.oQuae4av";/' src/com/android/settings/backup/PrivacySettingsUtils.java; fi; #microG doesn't support Backup, hide the options
fi;