This repository has been archived by the owner on Jan 10, 2022. It is now read-only.
forked from LineageOS/android_packages_apps_Settings
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
9 changed files
with
228 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/com/android/settings/network/CaptivePortalModePreferenceController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/com/android/settings/network/CaptivePortalWarningDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/com/android/settings/network/CaptivePortalWarningDialogHost.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters