mirror of
https://github.com/Divested-Mobile/DivestOS-Build.git
synced 2024-10-01 01:35:54 -04:00
8a45dc4696
h910 lavender pioneer, voyager, discovery akari, aurora, xz2c Signed-off-by: Tad <tad@spotco.us>
345 lines
14 KiB
Diff
345 lines
14 KiB
Diff
From 0000000000000000000000000000000000000000 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 lin17-microG repo
|
||
|
||
Change-Id: Ibbffdb5f3930df74ca8b4ba93d451f7fad086989
|
||
---
|
||
res/values-de/cm_strings.xml | 3 +
|
||
res/values/cm_strings.xml | 5 ++
|
||
res/xml/network_and_internet.xml | 7 ++
|
||
.../android/settings/ResetNetworkConfirm.java | 4 +
|
||
...CaptivePortalModePreferenceController.java | 82 +++++++++++++++++++
|
||
.../network/CaptivePortalWarningDialog.java | 74 +++++++++++++++++
|
||
.../CaptivePortalWarningDialogHost.java | 32 ++++++++
|
||
.../network/NetworkDashboardFragment.java | 17 +++-
|
||
8 files changed, 223 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 ce8ba8c6eb..96223a68ce 100644
|
||
--- a/res/values-de/cm_strings.xml
|
||
+++ b/res/values-de/cm_strings.xml
|
||
@@ -92,4 +92,7 @@
|
||
<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="peak_refresh_rate_summary_custom">Setzt die Aktualisierungsrate für einige Inhalte automatisch von 60 auf %1$d Hz herauf. Erhöhter Akkuverbrauch.</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 ab38dec706..6c81254ce2 100644
|
||
--- a/res/values/cm_strings.xml
|
||
+++ b/res/values/cm_strings.xml
|
||
@@ -175,4 +175,9 @@
|
||
|
||
<!-- Display settings screen, peak refresh rate settings summary [CHAR LIMIT=NONE] -->
|
||
<string name="peak_refresh_rate_summary_custom">Automatically raises the refresh rate from 60 to %1$d Hz for some content. Increases battery usage.</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..38535bb4ba 100644
|
||
--- a/res/xml/network_and_internet.xml
|
||
+++ b/res/xml/network_and_internet.xml
|
||
@@ -125,4 +125,11 @@
|
||
android:summary="@string/summary_placeholder"
|
||
android:order="25"
|
||
settings:controller="com.android.settings.network.AdaptiveConnectivityPreferenceController"/>
|
||
+
|
||
+ <SwitchPreference
|
||
+ android:key="captive_portal_switch"
|
||
+ android:title="@string/captive_portal_switch_title"
|
||
+ android:summary="@string/captive_portal_switch_summary"
|
||
+ android:order="30" />
|
||
+
|
||
</PreferenceScreen>
|
||
diff --git a/src/com/android/settings/ResetNetworkConfirm.java b/src/com/android/settings/ResetNetworkConfirm.java
|
||
index 784ffa7719..b503298ad6 100644
|
||
--- 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;
|
||
@@ -129,6 +130,9 @@ public class ResetNetworkConfirm extends InstrumentedFragment {
|
||
}
|
||
}
|
||
|
||
+ Settings.Global.putInt(mContext.getContentResolver(),
|
||
+ Settings.Global.CAPTIVE_PORTAL_MODE, 1);
|
||
+
|
||
restoreDefaultApn(mContext);
|
||
return isResetSucceed;
|
||
}
|
||
diff --git a/src/com/android/settings/network/CaptivePortalModePreferenceController.java b/src/com/android/settings/network/CaptivePortalModePreferenceController.java
|
||
new file mode 100644
|
||
index 0000000000..ae21b29292
|
||
--- /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
|
||
new file mode 100644
|
||
index 0000000000..d27bd7d2f0
|
||
--- /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
|
||
new file mode 100644
|
||
index 0000000000..7a04d1f831
|
||
--- /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();
|
||
+}
|
||
diff --git a/src/com/android/settings/network/NetworkDashboardFragment.java b/src/com/android/settings/network/NetworkDashboardFragment.java
|
||
index db704ae850..f4c5363d80 100644
|
||
--- 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);
|