21.0: more work

packages/apps/Settings done

Signed-off-by: Tavi <tavi@divested.dev>
This commit is contained in:
Tavi 2024-05-20 13:39:54 -04:00
parent afe1135384
commit 26f1ce99a9
No known key found for this signature in database
GPG Key ID: E599F62ECBAEAF2E
17 changed files with 3133 additions and 20 deletions

View File

@ -0,0 +1,438 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tad <tad@spotco.us>
Date: Mon, 24 Jun 2019 21:27:26 +0530
Subject: [PATCH] Add more 'Private DNS' options
This adds fifteen DNS providers as available presets.
Credit: CalyxOS
- Chirayu Desai <chirayudesai1@gmail.com>
https://review.calyxos.org/c/CalyxOS/platform_packages_apps_Settings/+/17176
Change-Id: I7e8a320d47e7c5ddbcb9acfaf23032ae92d5d70d
---
res/layout/private_dns_mode_dialog.xml | 60 ++++++
res/values/cm_strings.xml | 46 +++++
.../PrivateDnsModeDialogPreference.java | 192 +++++++++++++++++-
.../PrivateDnsPreferenceController.java | 40 +++-
4 files changed, 333 insertions(+), 5 deletions(-)
diff --git a/res/layout/private_dns_mode_dialog.xml b/res/layout/private_dns_mode_dialog.xml
index 12e29e693b7..b264bef20a9 100644
--- a/res/layout/private_dns_mode_dialog.xml
+++ b/res/layout/private_dns_mode_dialog.xml
@@ -35,6 +35,66 @@
android:id="@+id/private_dns_mode_off"
layout="@layout/preference_widget_dialog_radiobutton"/>
+ <include
+ android:id="@+id/private_dns_mode_adguard"
+ layout="@layout/preference_widget_dialog_radiobutton"/>
+
+ <include
+ android:id="@+id/private_dns_mode_appliedprivacy"
+ layout="@layout/preference_widget_dialog_radiobutton"/>
+
+ <include
+ android:id="@+id/private_dns_mode_cira"
+ layout="@layout/preference_widget_dialog_radiobutton"/>
+
+ <include
+ android:id="@+id/private_dns_mode_controld"
+ layout="@layout/preference_widget_dialog_radiobutton"/>
+
+ <include
+ android:id="@+id/private_dns_mode_cleanbrowsing"
+ layout="@layout/preference_widget_dialog_radiobutton"/>
+
+ <include
+ android:id="@+id/private_dns_mode_cznic"
+ layout="@layout/preference_widget_dialog_radiobutton"/>
+
+ <include
+ android:id="@+id/private_dns_mode_cloudflare"
+ layout="@layout/preference_widget_dialog_radiobutton"/>
+
+ <include
+ android:id="@+id/private_dns_mode_dnszero"
+ layout="@layout/preference_widget_dialog_radiobutton"/>
+
+ <include
+ android:id="@+id/private_dns_mode_dnssb"
+ layout="@layout/preference_widget_dialog_radiobutton"/>
+
+ <include
+ android:id="@+id/private_dns_mode_google"
+ layout="@layout/preference_widget_dialog_radiobutton"/>
+
+ <include
+ android:id="@+id/private_dns_mode_mullvad"
+ layout="@layout/preference_widget_dialog_radiobutton"/>
+
+ <include
+ android:id="@+id/private_dns_mode_quadnine"
+ layout="@layout/preference_widget_dialog_radiobutton"/>
+
+ <include
+ android:id="@+id/private_dns_mode_restena"
+ layout="@layout/preference_widget_dialog_radiobutton"/>
+
+ <include
+ android:id="@+id/private_dns_mode_switch"
+ layout="@layout/preference_widget_dialog_radiobutton"/>
+
+ <include
+ android:id="@+id/private_dns_mode_uncensoreddns"
+ layout="@layout/preference_widget_dialog_radiobutton"/>
+
<include
android:id="@+id/private_dns_mode_opportunistic"
layout="@layout/preference_widget_dialog_radiobutton"/>
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
index aa89f73f47c..f0dd5226d1c 100644
--- a/res/values/cm_strings.xml
+++ b/res/values/cm_strings.xml
@@ -15,6 +15,52 @@
limitations under the License.
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- Private DNS -->
+ <string name="private_dns_mode_adguard" translatable="false">AdGuard (CT)</string>
+ <string name="private_dns_hostname_adguard" translatable="false">dns.adguard.com</string>
+
+ <string name="private_dns_mode_appliedprivacy" translatable="false">AppliedPrivacy (AT)</string>
+ <string name="private_dns_hostname_appliedprivacy" translatable="false">dot1.applied-privacy.net</string>
+
+ <string name="private_dns_mode_cira" translatable="false">CIRA (CA)</string>
+ <string name="private_dns_hostname_cira" translatable="false">protected.canadianshield.cira.ca</string>
+
+ <string name="private_dns_mode_cleanbrowsing" translatable="false">CleanBrowsing (US)</string>
+ <string name="private_dns_hostname_cleanbrowsing" translatable="false">security-filter-dns.cleanbrowsing.org</string>
+
+ <string name="private_dns_mode_cloudflare" translatable="false">Cloudflare (US)</string>
+ <string name="private_dns_hostname_cloudflare" translatable="false">security.cloudflare-dns.com</string>
+
+ <string name="private_dns_mode_controld" translatable="false">Control D (CA)</string>
+ <string name="private_dns_hostname_controld" translatable="false">p2.freedns.controld.com</string>
+
+ <string name="private_dns_mode_cznic" translatable="false">CZ.NIC (CZ)</string>
+ <string name="private_dns_hostname_cznic" translatable="false">odvr.nic.cz</string>
+
+ <string name="private_dns_mode_dnszero" translatable="false">DNS0 (FR)</string>
+ <string name="private_dns_hostname_dnszero" translatable="false">zero.dns0.eu</string>
+
+ <string name="private_dns_mode_dnssb" translatable="false">DNS.SB (DE)</string>
+ <string name="private_dns_hostname_dnssb" translatable="false">dot.sb</string>
+
+ <string name="private_dns_mode_google" translatable="false">Google (US)</string>
+ <string name="private_dns_hostname_google" translatable="false">dns.google</string>
+
+ <string name="private_dns_mode_mullvad" translatable="false">Mullvad (SE)</string>
+ <string name="private_dns_hostname_mullvad" translatable="false">adblock.dns.mullvad.net</string>
+
+ <string name="private_dns_mode_quadnine" translatable="false">Quad9 (CH)</string>
+ <string name="private_dns_hostname_quadnine" translatable="false">dns.quad9.net</string>
+
+ <string name="private_dns_mode_restena" translatable="false">Restena (LU)</string>
+ <string name="private_dns_hostname_restena" translatable="false">kaitain.restena.lu</string>
+
+ <string name="private_dns_mode_switch" translatable="false">SWITCH (CH)</string>
+ <string name="private_dns_hostname_switch" translatable="false">dns.switch.ch</string>
+
+ <string name="private_dns_mode_uncensoreddns" translatable="false">UncensoredDNS (DK)</string>
+ <string name="private_dns_hostname_uncensoreddns" translatable="false">anycast.censurfridns.dk</string>
+
<!-- Advanced keyboard settings -->
<string name="keyboard_extras_title">Extras</string>
<string name="advanced_keyboard_settings_title">Advanced settings</string>
diff --git a/src/com/android/settings/network/PrivateDnsModeDialogPreference.java b/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
index b1985ab0182..a0fa2e93113 100644
--- a/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
+++ b/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
@@ -72,9 +72,41 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
// DNS_MODE -> RadioButton id
private static final Map<Integer, Integer> PRIVATE_DNS_MAP;
+ // Only used in Settings
+ private static final int PRIVATE_DNS_MODE_ADGUARD = 4;
+ private static final int PRIVATE_DNS_MODE_APPLIEDPRIVACY = 5;
+ private static final int PRIVATE_DNS_MODE_CIRA = 6;
+ private static final int PRIVATE_DNS_MODE_CLEANBROWSING = 7;
+ private static final int PRIVATE_DNS_MODE_CLOUDFLARE = 8;
+ private static final int PRIVATE_DNS_MODE_CONTROLD = 9;
+ private static final int PRIVATE_DNS_MODE_CZNIC = 10;
+ private static final int PRIVATE_DNS_MODE_DNSZERO = 11;
+ private static final int PRIVATE_DNS_MODE_GOOGLE = 12;
+ private static final int PRIVATE_DNS_MODE_MULLVAD = 13;
+ private static final int PRIVATE_DNS_MODE_QUADNINE = 14;
+ private static final int PRIVATE_DNS_MODE_RESTENA = 15;
+ private static final int PRIVATE_DNS_MODE_SWITCH = 16;
+ private static final int PRIVATE_DNS_MODE_UNCENSOREDDNS = 17;
+ private static final int PRIVATE_DNS_MODE_DNSSB = 18;
+
static {
PRIVATE_DNS_MAP = new HashMap<>();
PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_OFF, R.id.private_dns_mode_off);
+ PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_ADGUARD, R.id.private_dns_mode_adguard);
+ PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_APPLIEDPRIVACY, R.id.private_dns_mode_appliedprivacy);
+ PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_CIRA, R.id.private_dns_mode_cira);
+ PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_CLEANBROWSING, R.id.private_dns_mode_cleanbrowsing);
+ PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_CLOUDFLARE, R.id.private_dns_mode_cloudflare);
+ PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_CONTROLD, R.id.private_dns_mode_controld);
+ PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_CZNIC, R.id.private_dns_mode_cznic);
+ PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_DNSZERO, R.id.private_dns_mode_dnszero);
+ PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_DNSSB, R.id.private_dns_mode_dnssb);
+ PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_GOOGLE, R.id.private_dns_mode_google);
+ PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_MULLVAD, R.id.private_dns_mode_mullvad);
+ PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_QUADNINE, R.id.private_dns_mode_quadnine);
+ PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_RESTENA, R.id.private_dns_mode_restena);
+ PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_SWITCH, R.id.private_dns_mode_switch);
+ PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_UNCENSOREDDNS, R.id.private_dns_mode_uncensoreddns);
PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_OPPORTUNISTIC, R.id.private_dns_mode_opportunistic);
PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_PROVIDER_HOSTNAME, R.id.private_dns_mode_provider);
}
@@ -144,6 +176,41 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
final ContentResolver contentResolver = context.getContentResolver();
mMode = ConnectivitySettingsManager.getPrivateDnsMode(context);
+ if (mMode == PRIVATE_DNS_MODE_PROVIDER_HOSTNAME) {
+ final String privateDnsHostname =
+ ConnectivitySettingsManager.getPrivateDnsHostname(context);
+ if (privateDnsHostname.equals(context.getString(R.string.private_dns_hostname_adguard))) {
+ mMode = PRIVATE_DNS_MODE_ADGUARD;
+ } else if (privateDnsHostname.equals(context.getString(R.string.private_dns_hostname_appliedprivacy))) {
+ mMode = PRIVATE_DNS_MODE_APPLIEDPRIVACY;
+ } else if (privateDnsHostname.equals(context.getString(R.string.private_dns_hostname_cira))) {
+ mMode = PRIVATE_DNS_MODE_CIRA;
+ } else if (privateDnsHostname.equals(context.getString(R.string.private_dns_hostname_cleanbrowsing))) {
+ mMode = PRIVATE_DNS_MODE_CLEANBROWSING;
+ } else if (privateDnsHostname.equals(context.getString(R.string.private_dns_hostname_cloudflare))) {
+ mMode = PRIVATE_DNS_MODE_CLOUDFLARE;
+ } else if (privateDnsHostname.equals(context.getString(R.string.private_dns_hostname_controld))) {
+ mMode = PRIVATE_DNS_MODE_CONTROLD;
+ } else if (privateDnsHostname.equals(context.getString(R.string.private_dns_hostname_cznic))) {
+ mMode = PRIVATE_DNS_MODE_CZNIC;
+ } else if (privateDnsHostname.equals(context.getString(R.string.private_dns_hostname_dnszero))) {
+ mMode = PRIVATE_DNS_MODE_DNSZERO;
+ } else if (privateDnsHostname.equals(context.getString(R.string.private_dns_hostname_dnssb))) {
+ mMode = PRIVATE_DNS_MODE_DNSSB;
+ } else if (privateDnsHostname.equals(context.getString(R.string.private_dns_hostname_google))) {
+ mMode = PRIVATE_DNS_MODE_GOOGLE;
+ } else if (privateDnsHostname.equals(context.getString(R.string.private_dns_hostname_mullvad))) {
+ mMode = PRIVATE_DNS_MODE_MULLVAD;
+ } else if (privateDnsHostname.equals(context.getString(R.string.private_dns_hostname_quadnine))) {
+ mMode = PRIVATE_DNS_MODE_QUADNINE;
+ } else if (privateDnsHostname.equals(context.getString(R.string.private_dns_hostname_restena))) {
+ mMode = PRIVATE_DNS_MODE_RESTENA;
+ } else if (privateDnsHostname.equals(context.getString(R.string.private_dns_hostname_switch))) {
+ mMode = PRIVATE_DNS_MODE_SWITCH;
+ } else if (privateDnsHostname.equals(context.getString(R.string.private_dns_hostname_uncensoreddns))) {
+ mMode = PRIVATE_DNS_MODE_UNCENSOREDDNS;
+ }
+ }
mEditText = view.findViewById(R.id.private_dns_mode_provider_hostname);
mEditText.addTextChangedListener(this);
@@ -156,6 +223,51 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
// Initial radio button text
final RadioButton offRadioButton = view.findViewById(R.id.private_dns_mode_off);
offRadioButton.setText(com.android.settingslib.R.string.private_dns_mode_off);
+ final RadioButton adguardRadioButton =
+ view.findViewById(R.id.private_dns_mode_adguard);
+ adguardRadioButton.setText(R.string.private_dns_mode_adguard);
+ final RadioButton appliedprivacyRadioButton =
+ view.findViewById(R.id.private_dns_mode_appliedprivacy);
+ appliedprivacyRadioButton.setText(R.string.private_dns_mode_appliedprivacy);
+ final RadioButton ciraRadioButton =
+ view.findViewById(R.id.private_dns_mode_cira);
+ ciraRadioButton.setText(R.string.private_dns_mode_cira);
+ final RadioButton cleanbrowsingRadioButton =
+ view.findViewById(R.id.private_dns_mode_cleanbrowsing);
+ cleanbrowsingRadioButton.setText(R.string.private_dns_mode_cleanbrowsing);
+ final RadioButton cloudflareRadioButton =
+ view.findViewById(R.id.private_dns_mode_cloudflare);
+ cloudflareRadioButton.setText(R.string.private_dns_mode_cloudflare);
+ final RadioButton controldRadioButton =
+ view.findViewById(R.id.private_dns_mode_controld);
+ controldRadioButton.setText(R.string.private_dns_mode_controld);
+ final RadioButton cznicRadioButton =
+ view.findViewById(R.id.private_dns_mode_cznic);
+ cznicRadioButton.setText(R.string.private_dns_mode_cznic);
+ final RadioButton dnszeroRadioButton =
+ view.findViewById(R.id.private_dns_mode_dnszero);
+ dnszeroRadioButton.setText(R.string.private_dns_mode_dnszero);
+ final RadioButton dnssbRadioButton =
+ view.findViewById(R.id.private_dns_mode_dnssb);
+ dnssbRadioButton.setText(R.string.private_dns_mode_dnssb);
+ final RadioButton googleRadioButton =
+ view.findViewById(R.id.private_dns_mode_google);
+ googleRadioButton.setText(R.string.private_dns_mode_google);
+ final RadioButton mullvadRadioButton =
+ view.findViewById(R.id.private_dns_mode_mullvad);
+ mullvadRadioButton.setText(R.string.private_dns_mode_mullvad);
+ final RadioButton quadnineRadioButton =
+ view.findViewById(R.id.private_dns_mode_quadnine);
+ quadnineRadioButton.setText(R.string.private_dns_mode_quadnine);
+ final RadioButton restenaRadioButton =
+ view.findViewById(R.id.private_dns_mode_restena);
+ restenaRadioButton.setText(R.string.private_dns_mode_restena);
+ final RadioButton switchRadioButton =
+ view.findViewById(R.id.private_dns_mode_switch);
+ switchRadioButton.setText(R.string.private_dns_mode_switch);
+ final RadioButton uncensoreddnsRadioButton =
+ view.findViewById(R.id.private_dns_mode_uncensoreddns);
+ uncensoreddnsRadioButton.setText(R.string.private_dns_mode_uncensoreddns);
final RadioButton opportunisticRadioButton =
view.findViewById(R.id.private_dns_mode_opportunistic);
opportunisticRadioButton.setText(
@@ -182,14 +294,60 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) {
final Context context = getContext();
+ int modeToSet = mMode;
if (mMode == PRIVATE_DNS_MODE_PROVIDER_HOSTNAME) {
// Only clickable if hostname is valid, so we could save it safely
ConnectivitySettingsManager.setPrivateDnsHostname(context,
mEditText.getText().toString());
+ } else if (mMode == PRIVATE_DNS_MODE_ADGUARD) {
+ ConnectivitySettingsManager.setPrivateDnsHostname(context, context.getString(R.string.private_dns_hostname_adguard));
+ modeToSet = PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
+ } else if (mMode == PRIVATE_DNS_MODE_APPLIEDPRIVACY) {
+ ConnectivitySettingsManager.setPrivateDnsHostname(context, context.getString(R.string.private_dns_hostname_appliedprivacy));
+ modeToSet = PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
+ } else if (mMode == PRIVATE_DNS_MODE_CIRA) {
+ ConnectivitySettingsManager.setPrivateDnsHostname(context, context.getString(R.string.private_dns_hostname_cira));
+ modeToSet = PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
+ } else if (mMode == PRIVATE_DNS_MODE_CLEANBROWSING) {
+ ConnectivitySettingsManager.setPrivateDnsHostname(context, context.getString(R.string.private_dns_hostname_cleanbrowsing));
+ modeToSet = PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
+ } else if (mMode == PRIVATE_DNS_MODE_CLOUDFLARE) {
+ ConnectivitySettingsManager.setPrivateDnsHostname(context, context.getString(R.string.private_dns_hostname_cloudflare));
+ modeToSet = PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
+ } else if (mMode == PRIVATE_DNS_MODE_CONTROLD) {
+ ConnectivitySettingsManager.setPrivateDnsHostname(context, context.getString(R.string.private_dns_hostname_controld));
+ modeToSet = PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
+ } else if (mMode == PRIVATE_DNS_MODE_CZNIC) {
+ ConnectivitySettingsManager.setPrivateDnsHostname(context, context.getString(R.string.private_dns_hostname_cznic));
+ modeToSet = PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
+ } else if (mMode == PRIVATE_DNS_MODE_DNSZERO) {
+ ConnectivitySettingsManager.setPrivateDnsHostname(context, context.getString(R.string.private_dns_hostname_dnszero));
+ modeToSet = PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
+ } else if (mMode == PRIVATE_DNS_MODE_DNSSB) {
+ ConnectivitySettingsManager.setPrivateDnsHostname(context, context.getString(R.string.private_dns_hostname_dnssb));
+ modeToSet = PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
+ } else if (mMode == PRIVATE_DNS_MODE_GOOGLE) {
+ ConnectivitySettingsManager.setPrivateDnsHostname(context, context.getString(R.string.private_dns_hostname_google));
+ modeToSet = PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
+ } else if (mMode == PRIVATE_DNS_MODE_MULLVAD) {
+ ConnectivitySettingsManager.setPrivateDnsHostname(context, context.getString(R.string.private_dns_hostname_mullvad));
+ modeToSet = PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
+ } else if (mMode == PRIVATE_DNS_MODE_QUADNINE) {
+ ConnectivitySettingsManager.setPrivateDnsHostname(context, context.getString(R.string.private_dns_hostname_quadnine));
+ modeToSet = PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
+ } else if (mMode == PRIVATE_DNS_MODE_RESTENA) {
+ ConnectivitySettingsManager.setPrivateDnsHostname(context, context.getString(R.string.private_dns_hostname_restena));
+ modeToSet = PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
+ } else if (mMode == PRIVATE_DNS_MODE_SWITCH) {
+ ConnectivitySettingsManager.setPrivateDnsHostname(context, context.getString(R.string.private_dns_hostname_switch));
+ modeToSet = PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
+ } else if (mMode == PRIVATE_DNS_MODE_UNCENSOREDDNS) {
+ ConnectivitySettingsManager.setPrivateDnsHostname(context, context.getString(R.string.private_dns_hostname_uncensoreddns));
+ modeToSet = PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
}
FeatureFactory.getFeatureFactory().getMetricsFeatureProvider().action(context,
- SettingsEnums.ACTION_PRIVATE_DNS_MODE, mMode);
- ConnectivitySettingsManager.setPrivateDnsMode(context, mMode);
+ SettingsEnums.ACTION_PRIVATE_DNS_MODE, modeToSet);
+ ConnectivitySettingsManager.setPrivateDnsMode(context, modeToSet);
}
}
@@ -197,6 +355,36 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.private_dns_mode_off) {
mMode = PRIVATE_DNS_MODE_OFF;
+ } else if (checkedId == R.id.private_dns_mode_adguard) {
+ mMode = PRIVATE_DNS_MODE_ADGUARD;
+ } else if (checkedId == R.id.private_dns_mode_appliedprivacy) {
+ mMode = PRIVATE_DNS_MODE_APPLIEDPRIVACY;
+ } else if (checkedId == R.id.private_dns_mode_cira) {
+ mMode = PRIVATE_DNS_MODE_CIRA;
+ } else if (checkedId == R.id.private_dns_mode_cleanbrowsing) {
+ mMode = PRIVATE_DNS_MODE_CLEANBROWSING;
+ } else if (checkedId == R.id.private_dns_mode_cloudflare) {
+ mMode = PRIVATE_DNS_MODE_CLOUDFLARE;
+ } else if (checkedId == R.id.private_dns_mode_controld) {
+ mMode = PRIVATE_DNS_MODE_CONTROLD;
+ } else if (checkedId == R.id.private_dns_mode_cznic) {
+ mMode = PRIVATE_DNS_MODE_CZNIC;
+ } else if (checkedId == R.id.private_dns_mode_dnszero) {
+ mMode = PRIVATE_DNS_MODE_DNSZERO;
+ } else if (checkedId == R.id.private_dns_mode_dnssb) {
+ mMode = PRIVATE_DNS_MODE_DNSSB;
+ } else if (checkedId == R.id.private_dns_mode_google) {
+ mMode = PRIVATE_DNS_MODE_GOOGLE;
+ } else if (checkedId == R.id.private_dns_mode_mullvad) {
+ mMode = PRIVATE_DNS_MODE_MULLVAD;
+ } else if (checkedId == R.id.private_dns_mode_quadnine) {
+ mMode = PRIVATE_DNS_MODE_QUADNINE;
+ } else if (checkedId == R.id.private_dns_mode_restena) {
+ mMode = PRIVATE_DNS_MODE_RESTENA;
+ } else if (checkedId == R.id.private_dns_mode_switch) {
+ mMode = PRIVATE_DNS_MODE_SWITCH;
+ } else if (checkedId == R.id.private_dns_mode_uncensoreddns) {
+ mMode = PRIVATE_DNS_MODE_UNCENSOREDDNS;
} else if (checkedId == R.id.private_dns_mode_opportunistic) {
mMode = PRIVATE_DNS_MODE_OPPORTUNISTIC;
} else if (checkedId == R.id.private_dns_mode_provider) {
diff --git a/src/com/android/settings/network/PrivateDnsPreferenceController.java b/src/com/android/settings/network/PrivateDnsPreferenceController.java
index 26091599893..6183303aa23 100644
--- a/src/com/android/settings/network/PrivateDnsPreferenceController.java
+++ b/src/com/android/settings/network/PrivateDnsPreferenceController.java
@@ -134,9 +134,43 @@ public class PrivateDnsPreferenceController extends BasePreferenceController
: res.getString(
com.android.settingslib.R.string.private_dns_mode_opportunistic);
case PRIVATE_DNS_MODE_PROVIDER_HOSTNAME:
- return dnsesResolved
- ? PrivateDnsModeDialogPreference.getHostnameFromSettings(cr)
- : res.getString(com.android.settingslib.R.string.private_dns_mode_provider_failure);
+ if (!dnsesResolved) {
+ return res.getString(com.android.settingslib.R.string.private_dns_mode_provider_failure);
+ }
+ final String privateDnsHostname =
+ ConnectivitySettingsManager.getPrivateDnsHostname(mContext);
+ if (privateDnsHostname.equals(res.getString(R.string.private_dns_hostname_adguard))) {
+ return res.getString(R.string.private_dns_mode_adguard);
+ } else if (privateDnsHostname.equals(res.getString(R.string.private_dns_hostname_appliedprivacy))) {
+ return res.getString(R.string.private_dns_mode_appliedprivacy);
+ } else if (privateDnsHostname.equals(res.getString(R.string.private_dns_hostname_cira))) {
+ return res.getString(R.string.private_dns_mode_cira);
+ } else if (privateDnsHostname.equals(res.getString(R.string.private_dns_hostname_cleanbrowsing))) {
+ return res.getString(R.string.private_dns_mode_cleanbrowsing);
+ } else if (privateDnsHostname.equals(res.getString(R.string.private_dns_hostname_cloudflare))) {
+ return res.getString(R.string.private_dns_mode_cloudflare);
+ } else if (privateDnsHostname.equals(res.getString(R.string.private_dns_hostname_controld))) {
+ return res.getString(R.string.private_dns_mode_controld);
+ } else if (privateDnsHostname.equals(res.getString(R.string.private_dns_hostname_cznic))) {
+ return res.getString(R.string.private_dns_mode_cznic);
+ } else if (privateDnsHostname.equals(res.getString(R.string.private_dns_hostname_dnszero))) {
+ return res.getString(R.string.private_dns_mode_dnszero);
+ } else if (privateDnsHostname.equals(res.getString(R.string.private_dns_hostname_dnssb))) {
+ return res.getString(R.string.private_dns_mode_dnssb);
+ } else if (privateDnsHostname.equals(res.getString(R.string.private_dns_hostname_google))) {
+ return res.getString(R.string.private_dns_mode_google);
+ } else if (privateDnsHostname.equals(res.getString(R.string.private_dns_hostname_mullvad))) {
+ return res.getString(R.string.private_dns_mode_mullvad);
+ } else if (privateDnsHostname.equals(res.getString(R.string.private_dns_hostname_quadnine))) {
+ return res.getString(R.string.private_dns_mode_quadnine);
+ } else if (privateDnsHostname.equals(res.getString(R.string.private_dns_hostname_restena))) {
+ return res.getString(R.string.private_dns_mode_restena);
+ } else if (privateDnsHostname.equals(res.getString(R.string.private_dns_hostname_switch))) {
+ return res.getString(R.string.private_dns_mode_switch);
+ } else if (privateDnsHostname.equals(res.getString(R.string.private_dns_hostname_uncensoreddns))) {
+ return res.getString(R.string.private_dns_mode_uncensoreddns);
+ }
+ return PrivateDnsModeDialogPreference.getHostnameFromSettings(cr);
}
return "";
}

View File

@ -0,0 +1,165 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tavi <tavi@divested.dev>
Date: Mon, 20 May 2024 13:55:34 -0400
Subject: [PATCH] Revert "Add Cloudflare DNS as a private DNS provider"
This reverts commit 0dfbfff41cc28699c1e218e20b10d9d42688f950.
Change-Id: I2d713cc74d34c65b77e7664fd3f5615d3ab6ac6a
---
res/layout/private_dns_mode_dialog.xml | 4 ---
res/values/cm_strings.xml | 5 ----
.../PrivateDnsModeDialogPreference.java | 29 ++-----------------
.../PrivateDnsPreferenceController.java | 19 ++----------
4 files changed, 5 insertions(+), 52 deletions(-)
diff --git a/res/layout/private_dns_mode_dialog.xml b/res/layout/private_dns_mode_dialog.xml
index 7c765d5a22f..12e29e693b7 100644
--- a/res/layout/private_dns_mode_dialog.xml
+++ b/res/layout/private_dns_mode_dialog.xml
@@ -35,10 +35,6 @@
android:id="@+id/private_dns_mode_off"
layout="@layout/preference_widget_dialog_radiobutton"/>
- <include
- android:id="@+id/private_dns_mode_cloudflare"
- layout="@layout/preference_widget_dialog_radiobutton"/>
-
<include
android:id="@+id/private_dns_mode_opportunistic"
layout="@layout/preference_widget_dialog_radiobutton"/>
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
index d5c162e6650..aa89f73f47c 100644
--- a/res/values/cm_strings.xml
+++ b/res/values/cm_strings.xml
@@ -15,11 +15,6 @@
limitations under the License.
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
- <!-- Private DNS -->
- <string name="private_dns_mode_cloudflare" translatable="false">Cloudflare DNS</string>
- <!-- Alternative: 1dot1dot1dot1.cloudflare-dns.com -->
- <string name="private_dns_hostname_cloudflare" translatable="false">one.one.one.one</string>
-
<!-- Advanced keyboard settings -->
<string name="keyboard_extras_title">Extras</string>
<string name="advanced_keyboard_settings_title">Advanced settings</string>
diff --git a/src/com/android/settings/network/PrivateDnsModeDialogPreference.java b/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
index a5317ff4909..b1985ab0182 100644
--- a/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
+++ b/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
@@ -72,13 +72,9 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
// DNS_MODE -> RadioButton id
private static final Map<Integer, Integer> PRIVATE_DNS_MAP;
- // Only used in Settings, update on additions to ConnectivitySettingsUtils
- private static final int PRIVATE_DNS_MODE_CLOUDFLARE = 4;
-
static {
PRIVATE_DNS_MAP = new HashMap<>();
PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_OFF, R.id.private_dns_mode_off);
- PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_CLOUDFLARE, R.id.private_dns_mode_cloudflare);
PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_OPPORTUNISTIC, R.id.private_dns_mode_opportunistic);
PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_PROVIDER_HOSTNAME, R.id.private_dns_mode_provider);
}
@@ -148,15 +144,6 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
final ContentResolver contentResolver = context.getContentResolver();
mMode = ConnectivitySettingsManager.getPrivateDnsMode(context);
- if (mMode == PRIVATE_DNS_MODE_PROVIDER_HOSTNAME) {
- final String privateDnsHostname =
- ConnectivitySettingsManager.getPrivateDnsHostname(context);
- final String cloudflareHostname =
- context.getString(R.string.private_dns_hostname_cloudflare);
- if (privateDnsHostname.equals(cloudflareHostname)) {
- mMode = PRIVATE_DNS_MODE_CLOUDFLARE;
- }
- }
mEditText = view.findViewById(R.id.private_dns_mode_provider_hostname);
mEditText.addTextChangedListener(this);
@@ -169,9 +156,6 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
// Initial radio button text
final RadioButton offRadioButton = view.findViewById(R.id.private_dns_mode_off);
offRadioButton.setText(com.android.settingslib.R.string.private_dns_mode_off);
- final RadioButton cloudflareRadioButton =
- view.findViewById(R.id.private_dns_mode_cloudflare);
- cloudflareRadioButton.setText(R.string.private_dns_mode_cloudflare);
final RadioButton opportunisticRadioButton =
view.findViewById(R.id.private_dns_mode_opportunistic);
opportunisticRadioButton.setText(
@@ -198,21 +182,14 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) {
final Context context = getContext();
- int modeToSet = mMode;
if (mMode == PRIVATE_DNS_MODE_PROVIDER_HOSTNAME) {
// Only clickable if hostname is valid, so we could save it safely
ConnectivitySettingsManager.setPrivateDnsHostname(context,
mEditText.getText().toString());
- } else if (mMode == PRIVATE_DNS_MODE_CLOUDFLARE) {
- final String cloudflareHostname =
- context.getString(R.string.private_dns_hostname_cloudflare);
- ConnectivitySettingsManager.setPrivateDnsHostname(context, cloudflareHostname);
- modeToSet = PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
}
-
FeatureFactory.getFeatureFactory().getMetricsFeatureProvider().action(context,
- SettingsEnums.ACTION_PRIVATE_DNS_MODE, modeToSet);
- ConnectivitySettingsManager.setPrivateDnsMode(context, modeToSet);
+ SettingsEnums.ACTION_PRIVATE_DNS_MODE, mMode);
+ ConnectivitySettingsManager.setPrivateDnsMode(context, mMode);
}
}
@@ -220,8 +197,6 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.private_dns_mode_off) {
mMode = PRIVATE_DNS_MODE_OFF;
- } else if (checkedId == R.id.private_dns_mode_cloudflare) {
- mMode = PRIVATE_DNS_MODE_CLOUDFLARE;
} else if (checkedId == R.id.private_dns_mode_opportunistic) {
mMode = PRIVATE_DNS_MODE_OPPORTUNISTIC;
} else if (checkedId == R.id.private_dns_mode_provider) {
diff --git a/src/com/android/settings/network/PrivateDnsPreferenceController.java b/src/com/android/settings/network/PrivateDnsPreferenceController.java
index 17aaaeb869a..26091599893 100644
--- a/src/com/android/settings/network/PrivateDnsPreferenceController.java
+++ b/src/com/android/settings/network/PrivateDnsPreferenceController.java
@@ -65,9 +65,6 @@ public class PrivateDnsPreferenceController extends BasePreferenceController
Settings.Global.getUriFor(PRIVATE_DNS_SPECIFIER),
};
- // Only used in Settings, update on additions to ConnectivitySettingsUtils
- private static final int PRIVATE_DNS_MODE_CLOUDFLARE = 4;
-
private final Handler mHandler;
private final ContentObserver mSettingsObserver;
private final ConnectivityManager mConnectivityManager;
@@ -132,24 +129,14 @@ public class PrivateDnsPreferenceController extends BasePreferenceController
switch (mode) {
case PRIVATE_DNS_MODE_OFF:
return res.getString(com.android.settingslib.R.string.private_dns_mode_off);
- case PRIVATE_DNS_MODE_CLOUDFLARE:
case PRIVATE_DNS_MODE_OPPORTUNISTIC:
return dnsesResolved ? res.getString(R.string.private_dns_mode_on)
: res.getString(
com.android.settingslib.R.string.private_dns_mode_opportunistic);
case PRIVATE_DNS_MODE_PROVIDER_HOSTNAME:
- if (!dnsesResolved) {
- return res.getString(
- com.android.settingslib.R.string.private_dns_mode_provider_failure);
- }
- final String privateDnsHostname =
- ConnectivitySettingsManager.getPrivateDnsHostname(mContext);
- final String cloudflareHostname =
- res.getString(R.string.private_dns_hostname_cloudflare);
- if (privateDnsHostname.equals(cloudflareHostname)) {
- return res.getString(R.string.private_dns_mode_cloudflare);
- }
- return PrivateDnsModeDialogPreference.getHostnameFromSettings(cr);
+ return dnsesResolved
+ ? PrivateDnsModeDialogPreference.getHostnameFromSettings(cr)
+ : res.getString(com.android.settingslib.R.string.private_dns_mode_provider_failure);
}
return "";
}

View File

@ -0,0 +1,196 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: pratyush <codelab@pratyush.dev>
Date: Mon, 7 Jun 2021 22:15:59 +0100
Subject: [PATCH] add auto-reboot setting
---
res/values/arrays.xml | 31 +++++++
res/values/strings.xml | 3 +
res/xml/security_dashboard_settings.xml | 10 ++-
.../AutoRebootPreferenceController.java | 82 +++++++++++++++++++
.../settings/security/SecuritySettings.java | 1 +
5 files changed, 126 insertions(+), 1 deletion(-)
create mode 100644 src/com/android/settings/security/AutoRebootPreferenceController.java
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index f84afec09fc..954e3047f57 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -105,6 +105,37 @@
<item>1800000</item>
</string-array>
+ <!-- Auto reboot settings -->
+ <string-array name="auto_reboot_entries">
+ <item>Off</item>
+ <item>10 minutes</item>
+ <item>30 minutes</item>
+ <item>1 hour</item>
+ <item>2 hours</item>
+ <item>4 hours</item>
+ <item>8 hours</item>
+ <item>12 hours</item>
+ <item>24 hours</item>
+ <item>36 hours</item>
+ <item>48 hours</item>
+ <item>72 hours</item>
+ </string-array>
+
+ <string-array name="auto_reboot_values" translatable="false">
+ <item>0</item> <!-- Disabled -->
+ <item>600000</item>
+ <item>1800000</item>
+ <item>3600000</item>
+ <item>7200000</item>
+ <item>14400000</item>
+ <item>28800000</item>
+ <item>43200000</item>
+ <item>86400000</item>
+ <item>129600000</item>
+ <item>172800000</item>
+ <item>259200000</item>
+ </string-array>
+
<!-- Wi-Fi settings -->
<!-- Match this with the order of NetworkInfo.DetailedState. --> <skip />
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 8fcbcbf6b49..9713adcc767 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -627,6 +627,9 @@
<!-- Text shown for title of owner info setting [CHAR LIMIT=30]-->
<string name="owner_info_settings_title">Add text on lock screen</string>
+ <string name="auto_reboot_title">Auto reboot</string>
+ <string name="auto_reboot_summary">Automatically reboot the device, if the phone hasn\'t been unlocked within the selected number of hours.</string>
+
<!-- Text shown for summary of owner info setting (if none set) [CHAR LIMIT=40]-->
<string name="owner_info_settings_summary">None</string>
<!-- Hint text shown in owner info edit text [CHAR LIMIT=50] -->
diff --git a/res/xml/security_dashboard_settings.xml b/res/xml/security_dashboard_settings.xml
index 0550441d3f2..d0aeb27fe53 100644
--- a/res/xml/security_dashboard_settings.xml
+++ b/res/xml/security_dashboard_settings.xml
@@ -60,6 +60,14 @@
android:title="@string/security_settings_biometric_preference_title"
android:summary="@string/summary_placeholder"
settings:keywords="@string/keywords_biometric_settings" />
+
+ <ListPreference
+ android:key="auto_reboot"
+ android:title="@string/auto_reboot_title"
+ android:summary="@string/auto_reboot_summary"
+ android:persistent="false"
+ android:entries="@array/auto_reboot_entries"
+ android:entryValues="@array/auto_reboot_values" />
</PreferenceCategory>
<Preference
@@ -71,4 +79,4 @@
settings:controller="com.android.settings.security.SecurityAdvancedSettingsController"
settings:keywords="@string/security_advanced_settings_keywords" />
-</PreferenceScreen>
\ No newline at end of file
+</PreferenceScreen>
diff --git a/src/com/android/settings/security/AutoRebootPreferenceController.java b/src/com/android/settings/security/AutoRebootPreferenceController.java
new file mode 100644
index 00000000000..c7a75219a5e
--- /dev/null
+++ b/src/com/android/settings/security/AutoRebootPreferenceController.java
@@ -0,0 +1,82 @@
+package com.android.settings.security;
+
+import android.content.Context;
+import android.os.UserManager;
+import android.provider.Settings;
+import android.util.Log;
+
+import androidx.preference.ListPreference;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceCategory;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.core.lifecycle.events.OnResume;
+
+public class AutoRebootPreferenceController extends AbstractPreferenceController
+ implements PreferenceControllerMixin, OnResume,
+ Preference.OnPreferenceChangeListener {
+
+ private static final String KEY_AUTO_REBOOT = "auto_reboot";
+ private static final String PREF_KEY_SECURITY_CATEGORY = "security_category";
+
+ private PreferenceCategory mSecurityCategory;
+ private boolean mIsAdmin;
+ private final UserManager mUm;
+
+ public AutoRebootPreferenceController(Context context) {
+ super(context);
+ mUm = UserManager.get(context);
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mSecurityCategory = screen.findPreference(PREF_KEY_SECURITY_CATEGORY);
+ updatePreferenceState();
+ }
+
+ @Override
+ public boolean isAvailable() {
+ mIsAdmin = mUm.isAdminUser();
+ return mIsAdmin;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_AUTO_REBOOT;
+ }
+
+ // TODO: should we use onCreatePreferences() instead?
+ private void updatePreferenceState() {
+ if (mSecurityCategory == null) {
+ return;
+ }
+
+ if (mIsAdmin) {
+ ListPreference autoReboot =
+ (ListPreference) mSecurityCategory.findPreference(KEY_AUTO_REBOOT);
+ autoReboot.setValue(Long.toString(Settings.Global.getLong(
+ mContext.getContentResolver(), Settings.Global.SETTINGS_REBOOT_AFTER_TIMEOUT, 0)));
+ } else {
+ mSecurityCategory.removePreference(
+ mSecurityCategory.findPreference(KEY_AUTO_REBOOT));
+ }
+ }
+
+ @Override
+ public void onResume() {
+ updatePreferenceState();
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object value) {
+ final String key = preference.getKey();
+ if (KEY_AUTO_REBOOT.equals(key) && mIsAdmin) {
+ long timeout = Long.parseLong((String) value);
+ Settings.Global.putLong(mContext.getContentResolver(), Settings.Global.SETTINGS_REBOOT_AFTER_TIMEOUT, timeout);
+ }
+ return true;
+ }
+}
diff --git a/src/com/android/settings/security/SecuritySettings.java b/src/com/android/settings/security/SecuritySettings.java
index 6d987f34c1f..7aaa1b1e58f 100644
--- a/src/com/android/settings/security/SecuritySettings.java
+++ b/src/com/android/settings/security/SecuritySettings.java
@@ -105,6 +105,7 @@ public class SecuritySettings extends DashboardFragment {
securityPreferenceControllers.add(new CombinedBiometricStatusPreferenceController(
context, lifecycle));
securityPreferenceControllers.add(new ChangeScreenLockPreferenceController(context, host));
+ securityPreferenceControllers.add(new AutoRebootPreferenceController(context));
controllers.add(new PreferenceCategoryController(context, SECURITY_CATEGORY)
.setChildren(securityPreferenceControllers));
controllers.addAll(securityPreferenceControllers);

View File

@ -0,0 +1,238 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Oliver Scott <olivercscott@gmail.com>
Date: Fri, 2 Oct 2020 12:37:30 -0400
Subject: [PATCH] add bluetooth auto-turn-off setting
---
res/values/arrays.xml | 44 +++++++
res/values/strings.xml | 19 +++
res/xml/connected_devices.xml | 8 ++
.../BluetoothTimeoutPreferenceController.java | 115 ++++++++++++++++++
4 files changed, 186 insertions(+)
create mode 100644 src/com/android/settings/bluetooth/BluetoothTimeoutPreferenceController.java
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 954e3047f57..8982867bb0e 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -18,6 +18,50 @@
*/
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- Bluetooth settings. The delay in inactivity before bluetooth is turned off. These are shown in a list dialog. -->
+ <string-array name="bluetooth_timeout_entries">
+ <item>@string/bluetooth_timeout_summary_never</item>
+ <item>@string/bluetooth_timeout_summary_15secs</item>
+ <item>@string/bluetooth_timeout_summary_30secs</item>
+ <item>@string/bluetooth_timeout_summary_1min</item>
+ <item>@string/bluetooth_timeout_summary_2mins</item>
+ <item>@string/bluetooth_timeout_summary_5mins</item>
+ <item>@string/bluetooth_timeout_summary_10mins</item>
+ <item>@string/bluetooth_timeout_summary_30mins</item>
+ <item>@string/bluetooth_timeout_summary_1hour</item>
+ <item>@string/bluetooth_timeout_summary_2hours</item>
+ <item>@string/bluetooth_timeout_summary_4hours</item>
+ <item>@string/bluetooth_timeout_summary_8hours</item>
+ </string-array>
+
+ <!-- Do not translate. -->
+ <string-array name="bluetooth_timeout_values" translatable="false">
+ <!-- Do not translate. -->
+ <item>0</item>
+ <!-- Do not translate. -->
+ <item>15000</item>
+ <!-- Do not translate. -->
+ <item>30000</item>
+ <!-- Do not translate. -->
+ <item>60000</item>
+ <!-- Do not translate. -->
+ <item>120000</item>
+ <!-- Do not translate. -->
+ <item>300000</item>
+ <!-- Do not translate. -->
+ <item>600000</item>
+ <!-- Do not translate. -->
+ <item>1800000</item>
+ <!-- Do not translate. -->
+ <item>3600000</item>
+ <!-- Do not translate. -->
+ <item>7200000</item>
+ <!-- Do not translate. -->
+ <item>14400000</item>
+ <!-- Do not translate. -->
+ <item>28800000</item>
+ </string-array>
+
<!-- Display settings. The delay in inactivity before the screen is turned off. These are shown in a list dialog. -->
<string-array name="screen_timeout_entries">
<item>15 seconds</item>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 9713adcc767..48b67197e77 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -27,6 +27,25 @@
<!-- Used in confirmation dialogs as the action that the user will tap to turn on the feature. [CHAR LIMIT=40]-->
<string name="confirmation_turn_on">Turn on</string>
+ <!-- Connected devices screen, setting option name to change bluetooth timeout -->
+ <string name="bluetooth_timeout">Bluetooth timeout</string>
+
+ <!-- Connected devices screen, setting option summary to change bluetooth timeout -->
+ <string name="bluetooth_timeout_summary">Bluetooth will turn off after <xliff:g id="timeout_description">%1$s</xliff:g> if no devices connected</string>
+ <string name="bluetooth_timeout_summary2">Do not automatically turn off Bluetooth</string>
+ <string name="bluetooth_timeout_summary_never">Never</string>
+ <string name="bluetooth_timeout_summary_15secs">15 seconds</string>
+ <string name="bluetooth_timeout_summary_30secs">30 seconds</string>
+ <string name="bluetooth_timeout_summary_1min">1 minute</string>
+ <string name="bluetooth_timeout_summary_2mins">2 minutes</string>
+ <string name="bluetooth_timeout_summary_5mins">5 minutes</string>
+ <string name="bluetooth_timeout_summary_10mins">10 minutes</string>
+ <string name="bluetooth_timeout_summary_30mins">30 minutes</string>
+ <string name="bluetooth_timeout_summary_1hour">1 hour</string>
+ <string name="bluetooth_timeout_summary_2hours">2 hours</string>
+ <string name="bluetooth_timeout_summary_4hours">4 hours</string>
+ <string name="bluetooth_timeout_summary_8hours">8 hours</string>
+
<!-- Device Info screen. Used for a status item's value when the proper value is not known -->
<string name="device_info_default">Unknown</string>
<!-- String for removal of sensitive info on about, depending on tap -->
diff --git a/res/xml/connected_devices.xml b/res/xml/connected_devices.xml
index 1d2dd24e26c..24ba25f536e 100644
--- a/res/xml/connected_devices.xml
+++ b/res/xml/connected_devices.xml
@@ -60,6 +60,14 @@
settings:useAdminDisabledSummary="true"
settings:controller="com.android.settings.connecteddevice.AddDevicePreferenceController"/>
+ <androidx.preference.ListPreference
+ android:key="bluetooth_timeout"
+ android:title="@string/bluetooth_timeout"
+ android:summary="@string/summary_placeholder"
+ android:entries="@array/bluetooth_timeout_entries"
+ android:entryValues="@array/bluetooth_timeout_values"
+ settings:controller="com.android.settings.bluetooth.BluetoothTimeoutPreferenceController"/>
+
<PreferenceCategory
android:key="previously_connected_devices"
android:title="@string/connected_device_saved_title"
diff --git a/src/com/android/settings/bluetooth/BluetoothTimeoutPreferenceController.java b/src/com/android/settings/bluetooth/BluetoothTimeoutPreferenceController.java
new file mode 100644
index 00000000000..244147948aa
--- /dev/null
+++ b/src/com/android/settings/bluetooth/BluetoothTimeoutPreferenceController.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2020 The Calyx Institute
+ *
+ * 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.bluetooth;
+
+import android.bluetooth.BluetoothAdapter;
+import android.content.Context;
+import android.provider.Settings;
+import android.util.Log;
+
+import androidx.preference.ListPreference;
+import androidx.preference.Preference;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.core.PreferenceControllerMixin;
+
+public class BluetoothTimeoutPreferenceController extends BasePreferenceController implements
+ PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
+ private static final String TAG = "BluetoothTimeoutPrefCtrl";
+
+ public static final int FALLBACK_BLUETOOTH_TIMEOUT_VALUE = 0;
+
+ private final String mBluetoothTimeoutKey;
+
+ protected BluetoothAdapter mBluetoothAdapter;
+
+ public BluetoothTimeoutPreferenceController(Context context, String key) {
+ super(context, key);
+ mBluetoothTimeoutKey = key;
+
+ mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+ if (mBluetoothAdapter == null) {
+ Log.e(TAG, "Bluetooth is not supported on this device");
+ return;
+ }
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return mBluetoothAdapter != null ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return mBluetoothTimeoutKey;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ final ListPreference timeoutListPreference = (ListPreference) preference;
+ final long currentTimeout = Settings.Global.getLong(mContext.getContentResolver(),
+ Settings.Global.BLUETOOTH_OFF_TIMEOUT, FALLBACK_BLUETOOTH_TIMEOUT_VALUE);
+ timeoutListPreference.setValue(String.valueOf(currentTimeout));
+ updateTimeoutPreferenceDescription(timeoutListPreference,
+ Long.parseLong(timeoutListPreference.getValue()));
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ try {
+ long value = Long.parseLong((String) newValue);
+ Settings.Global.putLong(mContext.getContentResolver(), Settings.Global.BLUETOOTH_OFF_TIMEOUT, value);
+ updateTimeoutPreferenceDescription((ListPreference) preference, value);
+ } catch (NumberFormatException e) {
+ Log.e(TAG, "could not persist bluetooth timeout setting", e);
+ }
+ return true;
+ }
+
+ public static CharSequence getTimeoutDescription(
+ long currentTimeout, CharSequence[] entries, CharSequence[] values) {
+ if (currentTimeout < 0 || entries == null || values == null
+ || values.length != entries.length) {
+ return null;
+ }
+
+ for (int i = 0; i < values.length; i++) {
+ long timeout = Long.parseLong(values[i].toString());
+ if (currentTimeout == timeout) {
+ return entries[i];
+ }
+ }
+ return null;
+ }
+
+ private void updateTimeoutPreferenceDescription(ListPreference preference,
+ long currentTimeout) {
+ final CharSequence[] entries = preference.getEntries();
+ final CharSequence[] values = preference.getEntryValues();
+ final CharSequence timeoutDescription = getTimeoutDescription(
+ currentTimeout, entries, values);
+ String summary = "";
+ if (timeoutDescription != null) {
+ if (currentTimeout != 0)
+ summary = mContext.getString(R.string.bluetooth_timeout_summary, timeoutDescription);
+ else
+ summary = mContext.getString(R.string.bluetooth_timeout_summary2);
+ }
+ preference.setSummary(summary);
+ }
+}

View File

@ -0,0 +1,238 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Oliver Scott <olivercscott@gmail.com>
Date: Thu, 25 Feb 2021 11:31:14 -0500
Subject: [PATCH] add Wi-Fi timeout feature
---
res/values/arrays.xml | 44 +++++++
res/values/strings.xml | 19 +++
res/xml/wifi_configure_settings.xml | 8 ++
.../wifi/WifiTimeoutPreferenceController.java | 115 ++++++++++++++++++
4 files changed, 186 insertions(+)
create mode 100644 src/com/android/settings/wifi/WifiTimeoutPreferenceController.java
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 8982867bb0e..085a33bc53f 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -62,6 +62,50 @@
<item>28800000</item>
</string-array>
+ <!-- Wifi settings. The delay in inactivity before wifi is turned off. These are shown in a list dialog. -->
+ <string-array name="wifi_timeout_entries">
+ <item>@string/wifi_timeout_summary_never</item>
+ <item>@string/wifi_timeout_summary_15secs</item>
+ <item>@string/wifi_timeout_summary_30secs</item>
+ <item>@string/wifi_timeout_summary_1min</item>
+ <item>@string/wifi_timeout_summary_2mins</item>
+ <item>@string/wifi_timeout_summary_5mins</item>
+ <item>@string/wifi_timeout_summary_10mins</item>
+ <item>@string/wifi_timeout_summary_30mins</item>
+ <item>@string/wifi_timeout_summary_1hour</item>
+ <item>@string/wifi_timeout_summary_2hours</item>
+ <item>@string/wifi_timeout_summary_4hours</item>
+ <item>@string/wifi_timeout_summary_8hours</item>
+ </string-array>
+
+ <!-- Do not translate. -->
+ <string-array name="wifi_timeout_values" translatable="false">
+ <!-- Do not translate. -->
+ <item>0</item>
+ <!-- Do not translate. -->
+ <item>15000</item>
+ <!-- Do not translate. -->
+ <item>30000</item>
+ <!-- Do not translate. -->
+ <item>60000</item>
+ <!-- Do not translate. -->
+ <item>120000</item>
+ <!-- Do not translate. -->
+ <item>300000</item>
+ <!-- Do not translate. -->
+ <item>600000</item>
+ <!-- Do not translate. -->
+ <item>1800000</item>
+ <!-- Do not translate. -->
+ <item>3600000</item>
+ <!-- Do not translate. -->
+ <item>7200000</item>
+ <!-- Do not translate. -->
+ <item>14400000</item>
+ <!-- Do not translate. -->
+ <item>28800000</item>
+ </string-array>
+
<!-- Display settings. The delay in inactivity before the screen is turned off. These are shown in a list dialog. -->
<string-array name="screen_timeout_entries">
<item>15 seconds</item>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 48b67197e77..de8ed4718e4 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -46,6 +46,25 @@
<string name="bluetooth_timeout_summary_4hours">4 hours</string>
<string name="bluetooth_timeout_summary_8hours">8 hours</string>
+ <!-- screen, setting option name to change wifi timeout -->
+ <string name="wifi_timeout">Turn off Wi-Fi automatically</string>
+
+ <!-- screen, setting option summary to change wifi timeout -->
+ <string name="wifi_timeout_summary">Wi-Fi will turn off after <xliff:g id="timeout_description">%1$s</xliff:g> if no network connected</string>
+ <string name="wifi_timeout_summary2">Disabled</string>
+ <string name="wifi_timeout_summary_never">Never</string>
+ <string name="wifi_timeout_summary_15secs">15 seconds</string>
+ <string name="wifi_timeout_summary_30secs">30 seconds</string>
+ <string name="wifi_timeout_summary_1min">1 minute</string>
+ <string name="wifi_timeout_summary_2mins">2 minutes</string>
+ <string name="wifi_timeout_summary_5mins">5 minutes</string>
+ <string name="wifi_timeout_summary_10mins">10 minutes</string>
+ <string name="wifi_timeout_summary_30mins">30 minutes</string>
+ <string name="wifi_timeout_summary_1hour">1 hour</string>
+ <string name="wifi_timeout_summary_2hours">2 hours</string>
+ <string name="wifi_timeout_summary_4hours">4 hours</string>
+ <string name="wifi_timeout_summary_8hours">8 hours</string>
+
<!-- Device Info screen. Used for a status item's value when the proper value is not known -->
<string name="device_info_default">Unknown</string>
<!-- String for removal of sensitive info on about, depending on tap -->
diff --git a/res/xml/wifi_configure_settings.xml b/res/xml/wifi_configure_settings.xml
index bf795d057d1..63ad940984f 100644
--- a/res/xml/wifi_configure_settings.xml
+++ b/res/xml/wifi_configure_settings.xml
@@ -26,6 +26,14 @@
android:summary="@string/wifi_wakeup_summary"
settings:controller="com.android.settings.wifi.WifiWakeupPreferenceController"/>
+ <ListPreference
+ android:key="wifi_timeout"
+ android:title="@string/wifi_timeout"
+ android:summary="@string/wifi_timeout_summary"
+ android:entries="@array/wifi_timeout_entries"
+ android:entryValues="@array/wifi_timeout_values"
+ settings:controller="com.android.settings.wifi.WifiTimeoutPreferenceController"/>
+
<SwitchPreferenceCompat
android:key="notify_open_networks"
android:title="@string/wifi_notify_open_networks"
diff --git a/src/com/android/settings/wifi/WifiTimeoutPreferenceController.java b/src/com/android/settings/wifi/WifiTimeoutPreferenceController.java
new file mode 100644
index 00000000000..7116c905190
--- /dev/null
+++ b/src/com/android/settings/wifi/WifiTimeoutPreferenceController.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2020 The Calyx Institute
+ *
+ * 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.net.wifi.WifiManager;
+import android.provider.Settings;
+import android.util.Log;
+
+import androidx.preference.ListPreference;
+import androidx.preference.Preference;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.core.PreferenceControllerMixin;
+
+public class WifiTimeoutPreferenceController extends BasePreferenceController implements
+ PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
+ private static final String TAG = "WifiTimeoutPrefCtrl";
+
+ public static final int FALLBACK_WIFI_TIMEOUT_VALUE = 0;
+
+ private final String mWifiTimeoutKey;
+
+ protected WifiManager mWifiManager;
+
+ public WifiTimeoutPreferenceController(Context context, String key) {
+ super(context, key);
+ mWifiTimeoutKey = key;
+
+ mWifiManager = context.getSystemService(WifiManager.class);
+ if (mWifiManager == null) {
+ Log.e(TAG, "Wifi is not supported on this device");
+ return;
+ }
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return mWifiManager != null ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return mWifiTimeoutKey;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ final ListPreference timeoutListPreference = (ListPreference) preference;
+ final long currentTimeout = Settings.Global.getLong(mContext.getContentResolver(),
+ Settings.Global.WIFI_OFF_TIMEOUT, FALLBACK_WIFI_TIMEOUT_VALUE);
+ timeoutListPreference.setValue(String.valueOf(currentTimeout));
+ updateTimeoutPreferenceDescription(timeoutListPreference,
+ Long.parseLong(timeoutListPreference.getValue()));
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ try {
+ long value = Long.parseLong((String) newValue);
+ Settings.Global.putLong(mContext.getContentResolver(), Settings.Global.WIFI_OFF_TIMEOUT, value);
+ updateTimeoutPreferenceDescription((ListPreference) preference, value);
+ } catch (NumberFormatException e) {
+ Log.e(TAG, "could not persist wifi timeout setting", e);
+ }
+ return true;
+ }
+
+ public static CharSequence getTimeoutDescription(
+ long currentTimeout, CharSequence[] entries, CharSequence[] values) {
+ if (currentTimeout < 0 || entries == null || values == null
+ || values.length != entries.length) {
+ return null;
+ }
+
+ for (int i = 0; i < values.length; i++) {
+ long timeout = Long.parseLong(values[i].toString());
+ if (currentTimeout == timeout) {
+ return entries[i];
+ }
+ }
+ return null;
+ }
+
+ private void updateTimeoutPreferenceDescription(ListPreference preference,
+ long currentTimeout) {
+ final CharSequence[] entries = preference.getEntries();
+ final CharSequence[] values = preference.getEntryValues();
+ final CharSequence timeoutDescription = getTimeoutDescription(
+ currentTimeout, entries, values);
+ String summary = "";
+ if (timeoutDescription != null) {
+ if (currentTimeout != 0)
+ summary = mContext.getString(R.string.wifi_timeout_summary, timeoutDescription);
+ else
+ summary = mContext.getString(R.string.wifi_timeout_summary2);
+ }
+ preference.setSummary(summary);
+ }
+}

View File

@ -0,0 +1,168 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: flawedworld <38294951+flawedworld@users.noreply.github.com>
Date: Tue, 6 Apr 2021 01:15:32 +0100
Subject: [PATCH] add native debugging setting
---
res/values/strings.xml | 3 +
res/xml/security_dashboard_settings.xml | 6 +
.../NativeDebugPreferenceController.java | 106 ++++++++++++++++++
.../settings/security/SecuritySettings.java | 1 +
4 files changed, 116 insertions(+)
create mode 100644 src/com/android/settings/security/NativeDebugPreferenceController.java
diff --git a/res/values/strings.xml b/res/values/strings.xml
index de8ed4718e4..8ad86f32445 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -668,6 +668,9 @@
<string name="auto_reboot_title">Auto reboot</string>
<string name="auto_reboot_summary">Automatically reboot the device, if the phone hasn\'t been unlocked within the selected number of hours.</string>
+ <string name="native_debug_title">Enable native code debugging</string>
+ <string name="native_debug_summary">Generate useful logs / bug reports from crashes and permit debugging native code.</string>
+
<!-- Text shown for summary of owner info setting (if none set) [CHAR LIMIT=40]-->
<string name="owner_info_settings_summary">None</string>
<!-- Hint text shown in owner info edit text [CHAR LIMIT=50] -->
diff --git a/res/xml/security_dashboard_settings.xml b/res/xml/security_dashboard_settings.xml
index d0aeb27fe53..61e2db495a0 100644
--- a/res/xml/security_dashboard_settings.xml
+++ b/res/xml/security_dashboard_settings.xml
@@ -68,6 +68,12 @@
android:persistent="false"
android:entries="@array/auto_reboot_entries"
android:entryValues="@array/auto_reboot_values" />
+
+ <SwitchPreference
+ android:key="native_debug"
+ android:title="@string/native_debug_title"
+ android:summary="@string/native_debug_summary"
+ android:persistent="false" />
</PreferenceCategory>
<Preference
diff --git a/src/com/android/settings/security/NativeDebugPreferenceController.java b/src/com/android/settings/security/NativeDebugPreferenceController.java
new file mode 100644
index 00000000000..9271e6e21cf
--- /dev/null
+++ b/src/com/android/settings/security/NativeDebugPreferenceController.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2020 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.security;
+
+import android.content.Context;
+
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.os.SystemProperties;
+
+import android.provider.Settings;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceCategory;
+import androidx.preference.PreferenceGroup;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.TwoStatePreference;
+import androidx.preference.SwitchPreference;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.core.lifecycle.events.OnResume;
+
+public class NativeDebugPreferenceController extends AbstractPreferenceController
+ implements PreferenceControllerMixin, OnResume, Preference.OnPreferenceChangeListener {
+
+ private static final String SYS_KEY_NATIVE_DEBUG = "persist.native_debug";
+ private static final String PREF_KEY_NATIVE_DEBUG = "native_debug";
+ private static final String PREF_KEY_SECURITY_CATEGORY = "security_category";
+
+ private PreferenceCategory mSecurityCategory;
+ private SwitchPreference mNativeDebug;
+ private boolean mIsAdmin;
+ private UserManager mUm;
+
+ public NativeDebugPreferenceController(Context context) {
+ super(context);
+ mUm = UserManager.get(context);
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mSecurityCategory = screen.findPreference(PREF_KEY_SECURITY_CATEGORY);
+ updatePreferenceState();
+ }
+
+ @Override
+ public boolean isAvailable() {
+ mIsAdmin = mUm.isAdminUser();
+ return mIsAdmin;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return PREF_KEY_NATIVE_DEBUG;
+ }
+
+ // TODO: should we use onCreatePreferences() instead?
+ private void updatePreferenceState() {
+ if (mSecurityCategory == null) {
+ return;
+ }
+
+ if (mIsAdmin) {
+ mNativeDebug = (SwitchPreference) mSecurityCategory.findPreference(PREF_KEY_NATIVE_DEBUG);
+ mNativeDebug.setChecked(SystemProperties.getBoolean(SYS_KEY_NATIVE_DEBUG, true));
+ } else {
+ mSecurityCategory.removePreference(mSecurityCategory.findPreference(PREF_KEY_NATIVE_DEBUG));
+ }
+ }
+
+ @Override
+ public void onResume() {
+ updatePreferenceState();
+ if (mNativeDebug != null) {
+ boolean mode = mNativeDebug.isChecked();
+ SystemProperties.set(SYS_KEY_NATIVE_DEBUG, Boolean.toString(mode));
+ }
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object value) {
+ final String key = preference.getKey();
+ if (PREF_KEY_NATIVE_DEBUG.equals(key)) {
+ final boolean mode = !mNativeDebug.isChecked();
+ SystemProperties.set(SYS_KEY_NATIVE_DEBUG, Boolean.toString(mode));
+ }
+ return true;
+ }
+}
diff --git a/src/com/android/settings/security/SecuritySettings.java b/src/com/android/settings/security/SecuritySettings.java
index 7aaa1b1e58f..d29325d0fbc 100644
--- a/src/com/android/settings/security/SecuritySettings.java
+++ b/src/com/android/settings/security/SecuritySettings.java
@@ -106,6 +106,7 @@ public class SecuritySettings extends DashboardFragment {
context, lifecycle));
securityPreferenceControllers.add(new ChangeScreenLockPreferenceController(context, host));
securityPreferenceControllers.add(new AutoRebootPreferenceController(context));
+ securityPreferenceControllers.add(new NativeDebugPreferenceController(context));
controllers.add(new PreferenceCategoryController(context, SECURITY_CATEGORY)
.setChildren(securityPreferenceControllers));
controllers.addAll(securityPreferenceControllers);

View File

@ -0,0 +1,168 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Sat, 26 Mar 2022 20:35:37 -0400
Subject: [PATCH] add exec spawning toggle
---
res/values/strings.xml | 3 +
res/xml/security_dashboard_settings.xml | 6 +
.../ExecSpawnPreferenceController.java | 106 ++++++++++++++++++
.../settings/security/SecuritySettings.java | 1 +
4 files changed, 116 insertions(+)
create mode 100644 src/com/android/settings/security/ExecSpawnPreferenceController.java
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 553d210a17..e090ad8a05 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -747,6 +747,9 @@
<string name="auto_reboot_title">Auto reboot</string>
<string name="auto_reboot_summary">Automatically reboot the device, if the phone hasn\'t been unlocked within the selected number of hours.</string>
+ <string name="exec_spawn_title">Enable secure app spawning</string>
+ <string name="exec_spawn_summary">Launch apps in a more secure way than Android which takes slightly longer and increases memory usage by app processes.</string>
+
<string name="native_debug_title">Enable native code debugging</string>
<string name="native_debug_summary">Generate useful logs / bug reports from crashes and permit debugging native code.</string>
diff --git a/res/xml/security_dashboard_settings.xml b/res/xml/security_dashboard_settings.xml
index 61e2db495a..3a06288497 100644
--- a/res/xml/security_dashboard_settings.xml
+++ b/res/xml/security_dashboard_settings.xml
@@ -69,6 +69,12 @@
android:entries="@array/auto_reboot_entries"
android:entryValues="@array/auto_reboot_values" />
+ <SwitchPreference
+ android:key="exec_spawn"
+ android:title="@string/exec_spawn_title"
+ android:summary="@string/exec_spawn_summary"
+ android:persistent="false" />
+
<SwitchPreference
android:key="native_debug"
android:title="@string/native_debug_title"
diff --git a/src/com/android/settings/security/ExecSpawnPreferenceController.java b/src/com/android/settings/security/ExecSpawnPreferenceController.java
new file mode 100644
index 0000000000..98cc3c29e1
--- /dev/null
+++ b/src/com/android/settings/security/ExecSpawnPreferenceController.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2022 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.security;
+
+import android.content.Context;
+
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.os.SystemProperties;
+
+import android.provider.Settings;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceCategory;
+import androidx.preference.PreferenceGroup;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.TwoStatePreference;
+import androidx.preference.SwitchPreference;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.core.lifecycle.events.OnResume;
+
+public class ExecSpawnPreferenceController extends AbstractPreferenceController
+ implements PreferenceControllerMixin, OnResume, Preference.OnPreferenceChangeListener {
+
+ private static final String SYS_KEY_EXEC_SPAWN = "persist.security.exec_spawn_new";
+ private static final String PREF_KEY_EXEC_SPAWN = "exec_spawn";
+ private static final String PREF_KEY_SECURITY_CATEGORY = "security_category";
+
+ private PreferenceCategory mSecurityCategory;
+ private SwitchPreference mExecSpawn;
+ private boolean mIsAdmin;
+ private UserManager mUm;
+
+ public ExecSpawnPreferenceController(Context context) {
+ super(context);
+ mUm = UserManager.get(context);
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mSecurityCategory = screen.findPreference(PREF_KEY_SECURITY_CATEGORY);
+ updatePreferenceState();
+ }
+
+ @Override
+ public boolean isAvailable() {
+ mIsAdmin = mUm.isAdminUser();
+ return mIsAdmin;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return PREF_KEY_EXEC_SPAWN;
+ }
+
+ // TODO: should we use onCreatePreferences() instead?
+ private void updatePreferenceState() {
+ if (mSecurityCategory == null) {
+ return;
+ }
+
+ if (mIsAdmin) {
+ mExecSpawn = (SwitchPreference) mSecurityCategory.findPreference(PREF_KEY_EXEC_SPAWN);
+ mExecSpawn.setChecked(SystemProperties.getBoolean(SYS_KEY_EXEC_SPAWN, false));
+ } else {
+ mSecurityCategory.removePreference(mSecurityCategory.findPreference(PREF_KEY_EXEC_SPAWN));
+ }
+ }
+
+ @Override
+ public void onResume() {
+ updatePreferenceState();
+ if (mExecSpawn != null) {
+ boolean mode = mExecSpawn.isChecked();
+ SystemProperties.set(SYS_KEY_EXEC_SPAWN, Boolean.toString(mode));
+ }
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object value) {
+ final String key = preference.getKey();
+ if (PREF_KEY_EXEC_SPAWN.equals(key)) {
+ final boolean mode = !mExecSpawn.isChecked();
+ SystemProperties.set(SYS_KEY_EXEC_SPAWN, Boolean.toString(mode));
+ }
+ return true;
+ }
+}
diff --git a/src/com/android/settings/security/SecuritySettings.java b/src/com/android/settings/security/SecuritySettings.java
index ecf8f02e9d..e48164ae62 100644
--- a/src/com/android/settings/security/SecuritySettings.java
+++ b/src/com/android/settings/security/SecuritySettings.java
@@ -106,6 +106,7 @@ public class SecuritySettings extends DashboardFragment {
context, lifecycle));
securityPreferenceControllers.add(new ChangeScreenLockPreferenceController(context, host));
securityPreferenceControllers.add(new AutoRebootPreferenceController(context));
+ securityPreferenceControllers.add(new ExecSpawnPreferenceController(context));
securityPreferenceControllers.add(new NativeDebugPreferenceController(context));
controllers.add(new PreferenceCategoryController(context, SECURITY_CATEGORY)
.setChildren(securityPreferenceControllers));

View File

@ -0,0 +1,144 @@
From 6510b84f39264c63deb1c89ee72798da611acdd1 Mon Sep 17 00:00:00 2001
From: renlord <me@renlord.com>
Date: Fri, 15 Oct 2021 20:02:51 +0530
Subject: [PATCH] add option to always randomize MAC
RANDOMIZATION_ALWAYS is set as the default option
---
res/layout/wifi_network_config.xml | 2 +-
res/values/arrays.xml | 7 +++++
res/xml/wifi_network_details_fragment2.xml | 2 +-
.../WifiDetailPreferenceController2.java | 2 +-
.../WifiPrivacyPreferenceController2.java | 27 ++++++++++++++-----
5 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/res/layout/wifi_network_config.xml b/res/layout/wifi_network_config.xml
index 77afedc3042..075b751e710 100644
--- a/res/layout/wifi_network_config.xml
+++ b/res/layout/wifi_network_config.xml
@@ -694,7 +694,7 @@
android:layout_height="wrap_content"
style="@style/wifi_item_spinner"
android:prompt="@string/wifi_privacy_settings"
- android:entries="@array/wifi_privacy_entries"/>
+ android:entries="@array/wifi_privacy_entries_extended"/>
</LinearLayout>
<LinearLayout
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index f84afec09fc..1ca428bc8c3 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -1053,6 +1053,12 @@
<item>Treat as unmetered</item>
</string-array>
+ <string-array name="wifi_privacy_entries_extended">
+ <item>Use per-connection randomized MAC (default)</item>
+ <item>Use per-network randomized MAC</item>
+ <item>Use device MAC</item>
+ </string-array>
+
<string-array name="wifi_privacy_entries">
<item>Use randomized MAC (default)</item>
<item>Use device MAC</item>
@@ -1070,6 +1076,7 @@
</string-array>
<string-array name="wifi_privacy_values" translatable="false">
+ <item>100</item>
<item>1</item>
<item>0</item>
</string-array>
diff --git a/res/xml/wifi_network_details_fragment2.xml b/res/xml/wifi_network_details_fragment2.xml
index daff20f5a28..7c54ee1fc1d 100644
--- a/res/xml/wifi_network_details_fragment2.xml
+++ b/res/xml/wifi_network_details_fragment2.xml
@@ -94,7 +94,7 @@
android:key="privacy"
android:icon="@drawable/ic_wifi_privacy_24dp"
android:title="@string/wifi_privacy_settings"
- android:entries="@array/wifi_privacy_entries"
+ android:entries="@array/wifi_privacy_entries_extended"
android:entryValues="@array/wifi_privacy_values"/>
<Preference
diff --git a/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java b/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
index b67c84832fb..e0c9ba89ab7 100644
--- a/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
+++ b/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
@@ -747,7 +747,7 @@ private void refreshWifiType() {
}
private int getMacAddressTitle() {
- if (mWifiEntry.getPrivacy() == WifiEntry.PRIVACY_RANDOMIZED_MAC) {
+ if (mWifiEntry.getPrivacy() != WifiEntry.PRIVACY_DEVICE_MAC) {
return mWifiEntry.getConnectedState() == WifiEntry.CONNECTED_STATE_CONNECTED
? R.string.wifi_advanced_randomized_mac_address_title
: R.string.wifi_advanced_randomized_mac_address_disconnected_title;
diff --git a/src/com/android/settings/wifi/details2/WifiPrivacyPreferenceController2.java b/src/com/android/settings/wifi/details2/WifiPrivacyPreferenceController2.java
index 8c78e805d69..4ec97ba5f42 100644
--- a/src/com/android/settings/wifi/details2/WifiPrivacyPreferenceController2.java
+++ b/src/com/android/settings/wifi/details2/WifiPrivacyPreferenceController2.java
@@ -17,6 +17,7 @@
package com.android.settings.wifi.details2;
import android.content.Context;
+import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import androidx.annotation.NonNull;
@@ -38,6 +39,10 @@ public class WifiPrivacyPreferenceController2 extends BasePreferenceController i
private final WifiManager mWifiManager;
private WifiEntry mWifiEntry;
+ private static final int PREF_RANDOMIZATION_ALWAYS = 0;
+ private static final int PREF_RANDOMIZATION_PERSISTENT = 1;
+ private static final int PREF_RANDOMIZATION_NONE = 2;
+
public WifiPrivacyPreferenceController2(Context context) {
super(context, KEY_WIFI_PRIVACY);
@@ -93,8 +98,6 @@ int getRandomizationValue() {
return mWifiEntry.getPrivacy();
}
- private static final int PREF_RANDOMIZATION_PERSISTENT = 0;
- private static final int PREF_RANDOMIZATION_NONE = 1;
/**
* Returns preference index value.
@@ -103,8 +106,14 @@ int getRandomizationValue() {
* @return index value of preference
*/
public static int translateMacRandomizedValueToPrefValue(int macRandomized) {
- return (macRandomized == WifiEntry.PRIVACY_RANDOMIZED_MAC)
- ? PREF_RANDOMIZATION_PERSISTENT : PREF_RANDOMIZATION_NONE;
+ switch (macRandomized) {
+ case WifiEntry.PRIVACY_RANDOMIZED_MAC:
+ return PREF_RANDOMIZATION_PERSISTENT;
+ case WifiEntry.PRIVACY_DEVICE_MAC:
+ return PREF_RANDOMIZATION_NONE;
+ default:
+ return PREF_RANDOMIZATION_ALWAYS;
+ }
}
/**
@@ -114,8 +123,14 @@ public static int translateMacRandomizedValueToPrefValue(int macRandomized) {
* @return mac randomized value
*/
public static int translatePrefValueToMacRandomizedValue(int prefMacRandomized) {
- return (prefMacRandomized == PREF_RANDOMIZATION_PERSISTENT)
- ? WifiEntry.PRIVACY_RANDOMIZED_MAC : WifiEntry.PRIVACY_DEVICE_MAC;
+ switch (prefMacRandomized) {
+ case PREF_RANDOMIZATION_PERSISTENT:
+ return WifiEntry.PRIVACY_RANDOMIZED_MAC;
+ case PREF_RANDOMIZATION_NONE:
+ return WifiEntry.PRIVACY_DEVICE_MAC;
+ default:
+ return WifiEntry.PRIVACY_RANDOMIZATION_ALWAYS;
+ }
}
private void updateSummary(ListPreference preference, int macRandomized) {

View File

@ -0,0 +1,172 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tad <tad@spotco.us>
Date: Wed, 20 Apr 2022 01:04:27 -0400
Subject: [PATCH] Add a toggle to disable /etc/hosts lookup
Copy and pasted from the GrapheneOS exec spawning toggle patch
Signed-off-by: Tad <tad@spotco.us>
Change-Id: Ic01a142722372d9d57f52947025cd9db23e58ef4
---
res/values/strings.xml | 3 +
res/xml/security_dashboard_settings.xml | 6 +
.../security/HostsPreferenceController.java | 106 ++++++++++++++++++
.../settings/security/SecuritySettings.java | 1 +
4 files changed, 116 insertions(+)
create mode 100644 src/com/android/settings/security/HostsPreferenceController.java
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2905e96d006..1ad831e1b7e 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -674,6 +674,9 @@
<string name="native_debug_title">Enable native code debugging</string>
<string name="native_debug_summary">Generate useful logs / bug reports from crashes and permit debugging native code.</string>
+ <string name="hosts_disable_title">Disable DNS content blocker</string>
+ <string name="hosts_disable_summary">Disables use of the included /etc/hosts database for data collection and malware blocking.</string>
+
<!-- Text shown for summary of owner info setting (if none set) [CHAR LIMIT=40]-->
<string name="owner_info_settings_summary">None</string>
<!-- Hint text shown in owner info edit text [CHAR LIMIT=50] -->
diff --git a/res/xml/security_dashboard_settings.xml b/res/xml/security_dashboard_settings.xml
index 3a062884976..db158b72433 100644
--- a/res/xml/security_dashboard_settings.xml
+++ b/res/xml/security_dashboard_settings.xml
@@ -80,6 +80,12 @@
android:title="@string/native_debug_title"
android:summary="@string/native_debug_summary"
android:persistent="false" />
+
+ <SwitchPreference
+ android:key="hosts_disable"
+ android:title="@string/hosts_disable_title"
+ android:summary="@string/hosts_disable_summary"
+ android:persistent="false" />
</PreferenceCategory>
<Preference
diff --git a/src/com/android/settings/security/HostsPreferenceController.java b/src/com/android/settings/security/HostsPreferenceController.java
new file mode 100644
index 00000000000..d8af6d26490
--- /dev/null
+++ b/src/com/android/settings/security/HostsPreferenceController.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2022 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.security;
+
+import android.content.Context;
+
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.os.SystemProperties;
+
+import android.provider.Settings;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceCategory;
+import androidx.preference.PreferenceGroup;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.TwoStatePreference;
+import androidx.preference.SwitchPreference;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.core.lifecycle.events.OnResume;
+
+public class HostsPreferenceController extends AbstractPreferenceController
+ implements PreferenceControllerMixin, OnResume, Preference.OnPreferenceChangeListener {
+
+ private static final String SYS_KEY_HOSTS_DISABLE = "persist.security.hosts_disable";
+ private static final String PREF_KEY_HOSTS_DISABLE = "hosts_disable";
+ private static final String PREF_KEY_SECURITY_CATEGORY = "security_category";
+
+ private PreferenceCategory mSecurityCategory;
+ private SwitchPreference mHostsDisable;
+ private boolean mIsAdmin;
+ private UserManager mUm;
+
+ public HostsPreferenceController(Context context) {
+ super(context);
+ mUm = UserManager.get(context);
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mSecurityCategory = screen.findPreference(PREF_KEY_SECURITY_CATEGORY);
+ updatePreferenceState();
+ }
+
+ @Override
+ public boolean isAvailable() {
+ mIsAdmin = mUm.isAdminUser();
+ return mIsAdmin;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return PREF_KEY_HOSTS_DISABLE;
+ }
+
+ // TODO: should we use onCreatePreferences() instead?
+ private void updatePreferenceState() {
+ if (mSecurityCategory == null) {
+ return;
+ }
+
+ if (mIsAdmin) {
+ mHostsDisable = (SwitchPreference) mSecurityCategory.findPreference(PREF_KEY_HOSTS_DISABLE);
+ mHostsDisable.setChecked(SystemProperties.getInt(SYS_KEY_HOSTS_DISABLE, 0) == 1);
+ } else {
+ mSecurityCategory.removePreference(mSecurityCategory.findPreference(PREF_KEY_HOSTS_DISABLE));
+ }
+ }
+
+ @Override
+ public void onResume() {
+ updatePreferenceState();
+ if (mHostsDisable != null) {
+ boolean mode = mHostsDisable.isChecked();
+ SystemProperties.set(SYS_KEY_HOSTS_DISABLE, mode ? "1" : "0");
+ }
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object value) {
+ final String key = preference.getKey();
+ if (PREF_KEY_HOSTS_DISABLE.equals(key)) {
+ final boolean mode = !mHostsDisable.isChecked();
+ SystemProperties.set(SYS_KEY_HOSTS_DISABLE, mode ? "1" : "0");
+ }
+ return true;
+ }
+}
diff --git a/src/com/android/settings/security/SecuritySettings.java b/src/com/android/settings/security/SecuritySettings.java
index 4c6e1c99815..8079cd5067d 100644
--- a/src/com/android/settings/security/SecuritySettings.java
+++ b/src/com/android/settings/security/SecuritySettings.java
@@ -108,6 +108,7 @@ public class SecuritySettings extends DashboardFragment {
securityPreferenceControllers.add(new AutoRebootPreferenceController(context));
securityPreferenceControllers.add(new ExecSpawnPreferenceController(context));
securityPreferenceControllers.add(new NativeDebugPreferenceController(context));
+ securityPreferenceControllers.add(new HostsPreferenceController(context));
controllers.add(new PreferenceCategoryController(context, SECURITY_CATEGORY)
.setChildren(securityPreferenceControllers));
controllers.addAll(securityPreferenceControllers);

View File

@ -0,0 +1,512 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Pratyush <codelab@pratyush.dev>
Date: Wed, 20 Oct 2021 05:40:11 +0530
Subject: [PATCH] add toggle to set captiveportal settings
Access is disallowed for users that are disallowed from configuring
Private DNS settings. This restriction provides administrative control
over this feature in a way that's compatible with existing device
manager implementations. Private DNS is the closest fit from the
existing user management restrictions that are available.
Co-authored-by: stuux <stuux@posteo.net>
Co-authored-by: Renlord <me@renlord.com>
Co-authored-by: Danny Lin <danny@kdrag0n.dev>
Co-authored-by: anupritaisno1 <www.anuprita804@gmail.com>
Signed-off-by: empratyush <codelab@pratyush.dev>
[tad@spotco.us]: add multiple other server options
Change-Id: I8a762d0f29ac42fce3dcfc7189e8ff216a8f8d1a
---
res/values/arrays.xml | 30 ++
res/values/strings.xml | 3 +
...ConnectivityCheckPreferenceController.java | 410 ++++++++++++++++++
.../network/NetworkDashboardFragment.java | 4 +
4 files changed, 447 insertions(+)
create mode 100644 src/com/android/settings/network/ConnectivityCheckPreferenceController.java
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index b3511593319..bd9f5f06ae0 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -157,6 +157,36 @@
<item>@string/dark_ui_auto_mode_custom_bedtime</item>
</string-array>
+ <string-array name="connectivity_check_entries">
+ <item>Disabled</item>
+ <item>Amazon Fire OS (US)</item>
+ <item>Cloudflare (US)</item>
+ <item>DivestOS (US)</item>
+ <item>Google (US) [default]</item>
+ <item>Huawei (CN)</item>
+ <item>Kuketz (DE)</item>
+ <item>Microsoft Edge (US)</item>
+ <item>openSUSE (DE)</item>
+ <item>Ubuntu (UK)</item>
+ <!--<item>Xiaomi (CN)</item>-->
+ <!--<item>GrapheneOS (CA)</item>-->
+ </string-array>
+
+ <string-array name="connectivity_check_values" translatable="false">
+ <item>0</item>
+ <item>1</item>
+ <item>2</item>
+ <item>3</item>
+ <item>4</item>
+ <item>5</item>
+ <item>6</item>
+ <item>7</item>
+ <item>8</item>
+ <item>9</item>
+ <!--<item>10</item>-->
+ <!--<item>11</item>-->
+ </string-array>
+
<!-- Security settings. The delay after screen is turned off until device locks.
These are shown in a list dialog. -->
<string-array name="lock_after_timeout_entries">
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 1ad831e1b7e..04722ef295b 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -12461,6 +12461,9 @@
<!-- [CHAR LIMIT=NONE] Hint for QR code process failure -->
<string name="bt_le_audio_qr_code_is_not_valid_format">QR code isn\u0027t a valid format</string>
+ <string name="connectivity_check_title">Internet connectivity check</string>
+ <string name="connectivity_check_summary">HTTP endpoints to use for performing internet connectivity checks.</string>
+
<!-- Accessibility Software Cursor -->
<!-- [CHAR LIMIT=NONE] Title for Accessibility Software Cursor setting for trigger hints. -->
diff --git a/src/com/android/settings/network/ConnectivityCheckPreferenceController.java b/src/com/android/settings/network/ConnectivityCheckPreferenceController.java
new file mode 100644
index 00000000000..72d61defc30
--- /dev/null
+++ b/src/com/android/settings/network/ConnectivityCheckPreferenceController.java
@@ -0,0 +1,410 @@
+/*
+ * Copyright (C) 2020 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.network;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.res.Resources;
+import android.database.ContentObserver;
+import android.net.LinkProperties;
+import android.net.Network;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.provider.Settings;
+import androidx.preference.ListPreference;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+import com.android.internal.util.ArrayUtils;
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+import com.android.settingslib.RestrictedLockUtilsInternal;
+import com.android.settingslib.core.lifecycle.events.OnResume;
+
+public class ConnectivityCheckPreferenceController
+ extends BasePreferenceController
+ implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener,
+ OnResume {
+
+ // imported defaults from AOSP NetworkStack
+ private static final String STANDARD_HTTPS_URL =
+ "https://www.google.com/generate_204";
+ private static final String STANDARD_HTTP_URL =
+ "http://connectivitycheck.gstatic.com/generate_204";
+ private static final String STANDARD_FALLBACK_URL =
+ "http://www.google.com/gen_204";
+ private static final String STANDARD_OTHER_FALLBACK_URLS =
+ "http://play.googleapis.com/generate_204";
+
+ // GrapheneOS
+ private static final String GRAPHENEOS_CAPTIVE_PORTAL_HTTPS_URL =
+ "https://connectivitycheck.grapheneos.network/generate_204";
+ private static final String GRAPHENEOS_CAPTIVE_PORTAL_HTTP_URL =
+ "http://connectivitycheck.grapheneos.network/generate_204";
+ private static final String GRAPHENEOS_CAPTIVE_PORTAL_FALLBACK_URL =
+ "http://grapheneos.online/gen_204";
+ private static final String GRAPHENEOS_CAPTIVE_PORTAL_OTHER_FALLBACK_URL =
+ "http://grapheneos.online/generate_204";
+
+ // DivestOS
+ private static final String DIVESTOS_HTTPS_URL =
+ "https://divestos.org/generate_204";
+ private static final String DIVESTOS_HTTP_URL =
+ "http://divestos.org/generate_204";
+
+ // openSUSE
+ private static final String OPENSUSE_HTTPS_URL =
+ "https://conncheck.opensuse.org";
+ private static final String OPENSUSE_HTTP_URL =
+ "http://conncheck.opensuse.org";
+
+ // Ubuntu
+ private static final String UBUNTU_HTTPS_URL =
+ "https://connectivity-check.ubuntu.com";
+ private static final String UBUNTU_HTTP_URL =
+ "http://connectivity-check.ubuntu.com";
+
+ // Amazon Fire OS
+ private static final String AMAZON_HTTPS_URL =
+ "https://fireoscaptiveportal.com/generate_204";
+ private static final String AMAZON_HTTP_URL =
+ "http://fireoscaptiveportal.com/generate_204";
+
+ // Microsoft Edge
+ private static final String MICROSOFT_HTTP_URL =
+ "http://edge-http.microsoft.com/captiveportal/generate_204";
+
+ // Kuketz, https://www.kuketz-blog.de/android-captive-portal-check-204-http-antwort-von-captiveportal-kuketz-de/
+ private static final String KUKETZ_HTTPS_URL =
+ "https://captiveportal.kuketz.de";
+ private static final String KUKETZ_HTTP_URL =
+ "http://captiveportal.kuketz.de";
+
+ // Cloudflare
+ private static final String CLOUDFLARE_HTTPS_URL =
+ "https://cp.cloudflare.com";
+ private static final String CLOUDFLARE_HTTP_URL =
+ "http://cp.cloudflare.com";
+
+ // Huawei
+ private static final String HUAWEI_HTTPS_URL =
+ "https://connectivitycheck.platform.hicloud.com/generate_204";
+ private static final String HUAWEI_HTTP_URL =
+ "http://connectivitycheck.platform.hicloud.com/generate_204";
+
+ // Xiaomi
+ private static final String XIAOMI_HTTPS_URL =
+ "https://connect.rom.miui.com/generate_204";
+ private static final String XIAOMI_HTTP_URL =
+ "http://connect.rom.miui.com/generate_204";
+
+ // Keep this in sync! Commented options must be very last!
+ private static final int DISABLED_CAPTIVE_PORTAL_INTVAL = 0;
+ private static final int AMAZON_CAPTIVE_PORTAL_HTTP_URL_INTVAL = 1;
+ private static final int CLOUDFLARE_CAPTIVE_PORTAL_HTTP_URL_INTVAL = 2;
+ private static final int DIVESTOS_CAPTIVE_PORTAL_HTTP_URL_INTVAL = 3;
+ private static final int STANDARD_CAPTIVE_PORTAL_HTTP_URL_INTVAL = 4;
+ private static final int HUAWEI_CAPTIVE_PORTAL_HTTP_URL_INTVAL = 5;
+ private static final int KUKETZ_CAPTIVE_PORTAL_HTTP_URL_INTVAL = 6;
+ private static final int MICROSOFT_CAPTIVE_PORTAL_HTTP_URL_INTVAL = 7;
+ private static final int OPENSUSE_CAPTIVE_PORTAL_HTTP_URL_INTVAL = 8;
+ private static final int UBUNTU_CAPTIVE_PORTAL_HTTP_URL_INTVAL = 9;
+ private static final int XIAOMI_CAPTIVE_PORTAL_HTTP_URL_INTVAL = 10;
+ private static final int GRAPHENEOS_CAPTIVE_PORTAL_HTTP_URL_INTVAL = 11;
+
+ private static final String KEY_CONNECTIVITY_CHECK_SETTINGS =
+ "connectivity_check_settings";
+
+ private ListPreference mConnectivityPreference;
+
+ public ConnectivityCheckPreferenceController(Context context) {
+ super(context, KEY_CONNECTIVITY_CHECK_SETTINGS);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ if (isDisabledByAdmin()) {
+ return BasePreferenceController.DISABLED_FOR_USER;
+ }
+ return BasePreferenceController.AVAILABLE;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ ListPreference captiveList = new ListPreference(screen.getContext());
+ captiveList.setKey(KEY_CONNECTIVITY_CHECK_SETTINGS);
+ captiveList.setOrder(30);
+ captiveList.setIcon(R.drawable.ic_settings_language);
+ captiveList.setTitle(R.string.connectivity_check_title);
+ captiveList.setSummary(R.string.connectivity_check_summary);
+ captiveList.setEntries(R.array.connectivity_check_entries);
+ captiveList.setEntryValues(R.array.connectivity_check_values);
+
+ if (mConnectivityPreference == null) {
+ screen.addPreference(captiveList);
+ mConnectivityPreference = captiveList;
+ }
+ super.displayPreference(screen);
+ updatePreferenceState();
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_CONNECTIVITY_CHECK_SETTINGS;
+ }
+
+ private void updatePreferenceState() {
+ if (Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.CAPTIVE_PORTAL_MODE, Settings.Global.CAPTIVE_PORTAL_MODE_PROMPT)
+ == Settings.Global.CAPTIVE_PORTAL_MODE_IGNORE) {
+ mConnectivityPreference.setValueIndex(DISABLED_CAPTIVE_PORTAL_INTVAL);
+ return;
+ }
+
+ String pref = Settings.Global.getString(
+ mContext.getContentResolver(), Settings.Global.CAPTIVE_PORTAL_HTTP_URL);
+ if (STANDARD_HTTP_URL.equals(pref)) {
+ mConnectivityPreference.setValueIndex(
+ STANDARD_CAPTIVE_PORTAL_HTTP_URL_INTVAL);
+ } else if (GRAPHENEOS_CAPTIVE_PORTAL_HTTP_URL.equals(pref)) {
+ mConnectivityPreference.setValueIndex(
+ GRAPHENEOS_CAPTIVE_PORTAL_HTTP_URL_INTVAL);
+ } else if (DIVESTOS_HTTP_URL.equals(pref)) {
+ mConnectivityPreference.setValueIndex(
+ DIVESTOS_CAPTIVE_PORTAL_HTTP_URL_INTVAL);
+ } else if (OPENSUSE_HTTP_URL.equals(pref)) {
+ mConnectivityPreference.setValueIndex(
+ OPENSUSE_CAPTIVE_PORTAL_HTTP_URL_INTVAL);
+ } else if (UBUNTU_HTTP_URL.equals(pref)) {
+ mConnectivityPreference.setValueIndex(
+ UBUNTU_CAPTIVE_PORTAL_HTTP_URL_INTVAL);
+ } else if (AMAZON_HTTP_URL.equals(pref)) {
+ mConnectivityPreference.setValueIndex(
+ AMAZON_CAPTIVE_PORTAL_HTTP_URL_INTVAL);
+ } else if (MICROSOFT_HTTP_URL.equals(pref)) {
+ mConnectivityPreference.setValueIndex(
+ MICROSOFT_CAPTIVE_PORTAL_HTTP_URL_INTVAL);
+ } else if (KUKETZ_HTTP_URL.equals(pref)) {
+ mConnectivityPreference.setValueIndex(
+ KUKETZ_CAPTIVE_PORTAL_HTTP_URL_INTVAL);
+ } else if (CLOUDFLARE_HTTP_URL.equals(pref)) {
+ mConnectivityPreference.setValueIndex(
+ CLOUDFLARE_CAPTIVE_PORTAL_HTTP_URL_INTVAL);
+ } else if (HUAWEI_HTTP_URL.equals(pref)) {
+ mConnectivityPreference.setValueIndex(
+ HUAWEI_CAPTIVE_PORTAL_HTTP_URL_INTVAL);
+ } else if (XIAOMI_HTTP_URL.equals(pref)) {
+ mConnectivityPreference.setValueIndex(
+ XIAOMI_CAPTIVE_PORTAL_HTTP_URL_INTVAL);
+ }
+
+ }
+
+ @Override
+ public void onResume() {
+ updatePreferenceState();
+ if (mConnectivityPreference != null) {
+ setCaptivePortalURLs(
+ mContext.getContentResolver(),
+ Integer.parseInt(mConnectivityPreference.getValue()));
+ }
+ }
+
+ private void setCaptivePortalURLs(ContentResolver cr, int mode) {
+ switch (mode) {
+ case STANDARD_CAPTIVE_PORTAL_HTTP_URL_INTVAL:
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_HTTP_URL,
+ STANDARD_HTTP_URL);
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_HTTPS_URL,
+ STANDARD_HTTPS_URL);
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_FALLBACK_URL,
+ STANDARD_FALLBACK_URL);
+ Settings.Global.putString(
+ cr, Settings.Global.CAPTIVE_PORTAL_OTHER_FALLBACK_URLS,
+ STANDARD_OTHER_FALLBACK_URLS);
+ Settings.Global.putInt(cr, Settings.Global.CAPTIVE_PORTAL_MODE,
+ Settings.Global.CAPTIVE_PORTAL_MODE_PROMPT);
+ break;
+ case GRAPHENEOS_CAPTIVE_PORTAL_HTTP_URL_INTVAL:
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_HTTP_URL,
+ GRAPHENEOS_CAPTIVE_PORTAL_HTTP_URL);
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_HTTPS_URL,
+ GRAPHENEOS_CAPTIVE_PORTAL_HTTPS_URL);
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_FALLBACK_URL,
+ GRAPHENEOS_CAPTIVE_PORTAL_FALLBACK_URL);
+ Settings.Global.putString(
+ cr, Settings.Global.CAPTIVE_PORTAL_OTHER_FALLBACK_URLS,
+ GRAPHENEOS_CAPTIVE_PORTAL_OTHER_FALLBACK_URL);
+ Settings.Global.putInt(cr, Settings.Global.CAPTIVE_PORTAL_MODE,
+ Settings.Global.CAPTIVE_PORTAL_MODE_PROMPT);
+ break;
+ case DIVESTOS_CAPTIVE_PORTAL_HTTP_URL_INTVAL:
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_HTTP_URL,
+ DIVESTOS_HTTP_URL);
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_HTTPS_URL,
+ DIVESTOS_HTTPS_URL);
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_FALLBACK_URL,
+ DIVESTOS_HTTP_URL);
+ Settings.Global.putString(
+ cr, Settings.Global.CAPTIVE_PORTAL_OTHER_FALLBACK_URLS,
+ DIVESTOS_HTTP_URL);
+ Settings.Global.putInt(cr, Settings.Global.CAPTIVE_PORTAL_MODE,
+ Settings.Global.CAPTIVE_PORTAL_MODE_PROMPT);
+ break;
+ case OPENSUSE_CAPTIVE_PORTAL_HTTP_URL_INTVAL:
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_HTTP_URL,
+ OPENSUSE_HTTP_URL);
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_HTTPS_URL,
+ OPENSUSE_HTTPS_URL);
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_FALLBACK_URL,
+ OPENSUSE_HTTP_URL);
+ Settings.Global.putString(
+ cr, Settings.Global.CAPTIVE_PORTAL_OTHER_FALLBACK_URLS,
+ OPENSUSE_HTTP_URL);
+ Settings.Global.putInt(cr, Settings.Global.CAPTIVE_PORTAL_MODE,
+ Settings.Global.CAPTIVE_PORTAL_MODE_PROMPT);
+ break;
+ case UBUNTU_CAPTIVE_PORTAL_HTTP_URL_INTVAL:
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_HTTP_URL,
+ UBUNTU_HTTP_URL);
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_HTTPS_URL,
+ UBUNTU_HTTPS_URL);
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_FALLBACK_URL,
+ UBUNTU_HTTP_URL);
+ Settings.Global.putString(
+ cr, Settings.Global.CAPTIVE_PORTAL_OTHER_FALLBACK_URLS,
+ UBUNTU_HTTP_URL);
+ Settings.Global.putInt(cr, Settings.Global.CAPTIVE_PORTAL_MODE,
+ Settings.Global.CAPTIVE_PORTAL_MODE_PROMPT);
+ break;
+ case AMAZON_CAPTIVE_PORTAL_HTTP_URL_INTVAL:
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_HTTP_URL,
+ AMAZON_HTTP_URL);
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_HTTPS_URL,
+ AMAZON_HTTPS_URL);
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_FALLBACK_URL,
+ AMAZON_HTTP_URL);
+ Settings.Global.putString(
+ cr, Settings.Global.CAPTIVE_PORTAL_OTHER_FALLBACK_URLS,
+ AMAZON_HTTP_URL);
+ Settings.Global.putInt(cr, Settings.Global.CAPTIVE_PORTAL_MODE,
+ Settings.Global.CAPTIVE_PORTAL_MODE_PROMPT);
+ break;
+ case MICROSOFT_CAPTIVE_PORTAL_HTTP_URL_INTVAL:
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_HTTP_URL,
+ MICROSOFT_HTTP_URL);
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_HTTPS_URL,
+ MICROSOFT_HTTP_URL);
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_FALLBACK_URL,
+ MICROSOFT_HTTP_URL);
+ Settings.Global.putString(
+ cr, Settings.Global.CAPTIVE_PORTAL_OTHER_FALLBACK_URLS,
+ MICROSOFT_HTTP_URL);
+ Settings.Global.putInt(cr, Settings.Global.CAPTIVE_PORTAL_MODE,
+ Settings.Global.CAPTIVE_PORTAL_MODE_PROMPT);
+ break;
+ case KUKETZ_CAPTIVE_PORTAL_HTTP_URL_INTVAL:
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_HTTP_URL,
+ KUKETZ_HTTP_URL);
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_HTTPS_URL,
+ KUKETZ_HTTPS_URL);
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_FALLBACK_URL,
+ KUKETZ_HTTP_URL);
+ Settings.Global.putString(
+ cr, Settings.Global.CAPTIVE_PORTAL_OTHER_FALLBACK_URLS,
+ KUKETZ_HTTP_URL);
+ Settings.Global.putInt(cr, Settings.Global.CAPTIVE_PORTAL_MODE,
+ Settings.Global.CAPTIVE_PORTAL_MODE_PROMPT);
+ break;
+ case CLOUDFLARE_CAPTIVE_PORTAL_HTTP_URL_INTVAL:
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_HTTP_URL,
+ CLOUDFLARE_HTTP_URL);
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_HTTPS_URL,
+ CLOUDFLARE_HTTPS_URL);
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_FALLBACK_URL,
+ CLOUDFLARE_HTTP_URL);
+ Settings.Global.putString(
+ cr, Settings.Global.CAPTIVE_PORTAL_OTHER_FALLBACK_URLS,
+ CLOUDFLARE_HTTP_URL);
+ Settings.Global.putInt(cr, Settings.Global.CAPTIVE_PORTAL_MODE,
+ Settings.Global.CAPTIVE_PORTAL_MODE_PROMPT);
+ break;
+ case HUAWEI_CAPTIVE_PORTAL_HTTP_URL_INTVAL:
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_HTTP_URL,
+ HUAWEI_HTTP_URL);
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_HTTPS_URL,
+ HUAWEI_HTTPS_URL);
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_FALLBACK_URL,
+ HUAWEI_HTTP_URL);
+ Settings.Global.putString(
+ cr, Settings.Global.CAPTIVE_PORTAL_OTHER_FALLBACK_URLS,
+ HUAWEI_HTTP_URL);
+ Settings.Global.putInt(cr, Settings.Global.CAPTIVE_PORTAL_MODE,
+ Settings.Global.CAPTIVE_PORTAL_MODE_PROMPT);
+ break;
+ case XIAOMI_CAPTIVE_PORTAL_HTTP_URL_INTVAL:
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_HTTP_URL,
+ XIAOMI_HTTP_URL);
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_HTTPS_URL,
+ XIAOMI_HTTPS_URL);
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_FALLBACK_URL,
+ XIAOMI_HTTP_URL);
+ Settings.Global.putString(
+ cr, Settings.Global.CAPTIVE_PORTAL_OTHER_FALLBACK_URLS,
+ XIAOMI_HTTP_URL);
+ Settings.Global.putInt(cr, Settings.Global.CAPTIVE_PORTAL_MODE,
+ Settings.Global.CAPTIVE_PORTAL_MODE_PROMPT);
+ break;
+ default:
+ // Default URLs as placeholder
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_HTTP_URL,
+ STANDARD_HTTP_URL);
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_HTTPS_URL,
+ STANDARD_HTTPS_URL);
+ Settings.Global.putString(cr, Settings.Global.CAPTIVE_PORTAL_FALLBACK_URL,
+ STANDARD_FALLBACK_URL);
+ Settings.Global.putString(
+ cr, Settings.Global.CAPTIVE_PORTAL_OTHER_FALLBACK_URLS,
+ STANDARD_OTHER_FALLBACK_URLS);
+ Settings.Global.putInt(cr, Settings.Global.CAPTIVE_PORTAL_MODE,
+ Settings.Global.CAPTIVE_PORTAL_MODE_IGNORE);
+ }
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object value) {
+ final String key = preference.getKey();
+ if (KEY_CONNECTIVITY_CHECK_SETTINGS.equals(key)) {
+ setCaptivePortalURLs(mContext.getContentResolver(),
+ Integer.parseInt((String)value));
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ private EnforcedAdmin getEnforcedAdmin() {
+ return RestrictedLockUtilsInternal.checkIfRestrictionEnforced(
+ mContext, UserManager.DISALLOW_CONFIG_PRIVATE_DNS,
+ UserHandle.myUserId());
+ }
+
+ private boolean isDisabledByAdmin() { return getEnforcedAdmin() != null; }
+}
diff --git a/src/com/android/settings/network/NetworkDashboardFragment.java b/src/com/android/settings/network/NetworkDashboardFragment.java
index 323d9354bd2..f74edd807e6 100644
--- a/src/com/android/settings/network/NetworkDashboardFragment.java
+++ b/src/com/android/settings/network/NetworkDashboardFragment.java
@@ -97,6 +97,10 @@ public class NetworkDashboardFragment extends DashboardFragment implements
}
controllers.add(privateDnsPreferenceController);
+ ConnectivityCheckPreferenceController connectivityCheck =
+ new ConnectivityCheckPreferenceController(context);
+ controllers.add(connectivityCheck);
+
// Start SettingsDumpService after the MobileNetworkRepository is created.
Intent intent = new Intent(context, SettingsDumpService.class);
intent.putExtra(SettingsDumpService.EXTRA_KEY_SHOW_NETWORK_DUMP, true);

View File

@ -0,0 +1,138 @@
From a701093b129688269e41b2ab7d2706344225e94e Mon Sep 17 00:00:00 2001
From: Pratyush <codelab@pratyush.dev>
Date: Fri, 19 Aug 2022 11:05:36 +0530
Subject: [PATCH] LTE Only Mode
Co-authored-by: inthewaves <inthewaves@pm.me>
Squashed with: Fix LTE Only mode on World Mode
Co-authored-by: flawedworld <flawedworld@flawed.world>
---
res/values/strings.xml | 6 +++++
...nabledNetworkModePreferenceController.java | 24 ++++++++++++++++++-
...ferredNetworkModePreferenceController.java | 2 +-
3 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 716302483e0..5acbef2c09a 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -11065,6 +11065,8 @@
<string name="preferred_network_mode_cdma_evdo_gsm_wcdma_summary">Preferred network mode: CDMA/EvDo/GSM/WCDMA</string>
<!-- LTE [CHAR LIMIT=NONE] -->
<string name="preferred_network_mode_lte_summary">Preferred network mode: LTE </string>
+ <!-- LTE only [CHAR LIMIT=100] -->
+ <string name="preferred_network_mode_lte_only_summary">Preferred network mode: LTE only</string>
<!-- GSM/WCDMA/LTE [CHAR LIMIT=NONE] -->
<string name="preferred_network_mode_lte_gsm_wcdma_summary">Preferred network mode: GSM/WCDMA/LTE</string>
<!-- CDMA+LTE/EVDO [CHAR LIMIT=NONE] -->
@@ -11130,8 +11132,12 @@
<string name="network_4G_pure" translatable="false">4G</string>
<!-- Text for Network lte [CHAR LIMIT=NONE] -->
<string name="network_lte">LTE (recommended)</string>
+ <!-- Text for Network lte only [CHAR LIMIT=NONE] -->
+ <string name="network_lte_only">LTE only</string>
<!-- Text for Network 4g [CHAR LIMIT=NONE] -->
<string name="network_4G">4G (recommended)</string>
+ <!-- Text for Network 4g only [CHAR LIMIT=NONE] -->
+ <string name="network_4G_only">4G only</string>
<!-- Text for Network 3g [CHAR LIMIT=NONE] -->
<string name="network_3G" translatable="false">3G</string>
<!-- Text for Network 2g [CHAR LIMIT=NONE] -->
diff --git a/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java b/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
index 2a355adaae4..03d5f20f16f 100644
--- a/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
+++ b/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
@@ -95,7 +95,7 @@ public int getAvailabilityStatus(int subId) {
CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)
|| carrierConfig.getBoolean(
CarrierConfigManager.KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL)) {
- visible = false;
+ visible = true;
} else if (carrierConfig.getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL)) {
visible = false;
} else if (!isCallStateIdle()) {
@@ -290,6 +290,7 @@ public void updateConfig() {
}
void setPreferenceEntries() {
+ boolean lteOnlyUnsupported = false;
mTelephonyManager = mTelephonyManager.createForSubscriptionId(mSubId);
clearAllEntries();
@@ -305,6 +306,7 @@ void setPreferenceEntries() {
.addFormat(UiOptions.PresentFormat.addGlobalEntry);
break;
case ENABLED_NETWORKS_CDMA_NO_LTE_CHOICES:
+ lteOnlyUnsupported = true;
uiOptions = uiOptions
.setChoices(R.array.enabled_networks_cdma_no_lte_values)
.addFormat(UiOptions.PresentFormat.add3gEntry)
@@ -324,6 +326,7 @@ void setPreferenceEntries() {
.addFormat(UiOptions.PresentFormat.add2gEntry);
break;
case ENABLED_NETWORKS_EXCEPT_GSM_LTE_CHOICES:
+ lteOnlyUnsupported = true;
uiOptions = uiOptions
.setChoices(R.array.enabled_networks_except_gsm_lte_values)
.addFormat(UiOptions.PresentFormat.add3gEntry);
@@ -341,6 +344,7 @@ void setPreferenceEntries() {
.addFormat(UiOptions.PresentFormat.add3gEntry);
break;
case ENABLED_NETWORKS_EXCEPT_LTE_CHOICES:
+ lteOnlyUnsupported = true;
uiOptions = uiOptions
.setChoices(R.array.enabled_networks_except_lte_values)
.addFormat(UiOptions.PresentFormat.add3gEntry)
@@ -389,6 +393,11 @@ void setPreferenceEntries() {
throw new IllegalArgumentException(
uiOptions.getType().name() + " index error.");
}
+
+ if (!lteOnlyUnsupported){
+ addLteOnlyEntry();
+ }
+
// Compose options based on given values and formats.
IntStream.range(0, formatList.size()).forEach(entryIndex -> {
switch (formatList.get(entryIndex)) {
@@ -575,6 +584,9 @@ void setPreferenceValueAndSummary(int networkMode) {
break;
}
case TelephonyManagerConstants.NETWORK_MODE_LTE_ONLY:
+ setSummary(mShow4gForLTE
+ ? R.string.network_4G_only : R.string.network_lte_only);
+ break;
case TelephonyManagerConstants.NETWORK_MODE_LTE_WCDMA:
if (!mIsGlobalCdma) {
setSelectedEntry(
@@ -840,6 +852,16 @@ private void add1xEntry(int value) {
mEntriesValue.add(value);
}
+ private void addLteOnlyEntry() {
+ if (mShow4gForLTE) {
+ mEntries.add(mContext.getString(R.string.network_4G_only));
+ mEntriesValue.add(TelephonyManagerConstants.NETWORK_MODE_LTE_ONLY);
+ } else {
+ mEntries.add(mContext.getString(R.string.network_lte_only));
+ mEntriesValue.add(TelephonyManagerConstants.NETWORK_MODE_LTE_ONLY);
+ }
+ }
+
private void addCustomEntry(String name, int value) {
mEntries.add(name);
mEntriesValue.add(value);
diff --git a/src/com/android/settings/network/telephony/PreferredNetworkModePreferenceController.java b/src/com/android/settings/network/telephony/PreferredNetworkModePreferenceController.java
index bdfeace1be6..535645a8647 100644
--- a/src/com/android/settings/network/telephony/PreferredNetworkModePreferenceController.java
+++ b/src/com/android/settings/network/telephony/PreferredNetworkModePreferenceController.java
@@ -137,7 +137,7 @@ private int getPreferredNetworkModeSummaryResId(int NetworkMode) {
case TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA:
return R.string.preferred_network_mode_lte_tdscdma_summary;
case TelephonyManagerConstants.NETWORK_MODE_LTE_ONLY:
- return R.string.preferred_network_mode_lte_summary;
+ return R.string.preferred_network_mode_lte_only_summary;
case TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_GSM:
return R.string.preferred_network_mode_lte_tdscdma_gsm_summary;
case TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA:

View File

@ -0,0 +1,95 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dmitry Muhomor <muhomor.dmitry@gmail.com>
Date: Fri, 10 Feb 2023 12:44:30 +0200
Subject: [PATCH] add a toggle for forcibly disabling SUPL
---
res/values/strings.xml | 3 ++
res/xml/location_settings.xml | 7 +++
.../ForceDisableSuplPrefController.java | 45 +++++++++++++++++++
3 files changed, 55 insertions(+)
create mode 100644 src/com/android/settings/location/ForceDisableSuplPrefController.java
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 980ecbdbd9a..6b86c5a12bc 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -12470,6 +12470,9 @@
<string name="connectivity_check_title">Internet connectivity check</string>
<string name="connectivity_check_summary">HTTP endpoints to use for performing internet connectivity checks.</string>
+ <string name="force_disable_supl_title">Force disable Secure User Plane Location (SUPL)</string>
+ <string name="force_disable_supl_summary">Always disable SUPL assisted location support regardless of carrier configuration or emergency call status (does not disable control plane A-GNSS and DivestOS does not send IMSI to the SUPL)</string>
+
<!-- Accessibility Software Cursor -->
<!-- [CHAR LIMIT=NONE] Title for Accessibility Software Cursor setting for trigger hints. -->
diff --git a/res/xml/location_settings.xml b/res/xml/location_settings.xml
index 6e105046582..85a64098ea7 100644
--- a/res/xml/location_settings.xml
+++ b/res/xml/location_settings.xml
@@ -72,6 +72,13 @@
android:title="@string/location_services_preference_title"
settings:controller="com.android.settings.location.LocationServicesPreferenceController"/>
+
+ <com.android.settingslib.RestrictedSwitchPreference
+ android:key="force_disable_supl"
+ android:title="@string/force_disable_supl_title"
+ android:summary="@string/force_disable_supl_summary"
+ settings:controller="com.android.settings.location.ForceDisableSuplPrefController"/>
+
</PreferenceCategory>
<com.android.settingslib.widget.FooterPreference
diff --git a/src/com/android/settings/location/ForceDisableSuplPrefController.java b/src/com/android/settings/location/ForceDisableSuplPrefController.java
new file mode 100644
index 00000000000..3a44261cc5d
--- /dev/null
+++ b/src/com/android/settings/location/ForceDisableSuplPrefController.java
@@ -0,0 +1,45 @@
+package com.android.settings.location;
+
+import android.content.Context;
+import android.os.Process;
+import android.provider.Settings;
+
+import com.android.settings.core.TogglePreferenceController;
+
+public class ForceDisableSuplPrefController extends TogglePreferenceController {
+
+ public ForceDisableSuplPrefController(Context ctx, String key) {
+ super(ctx, key);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ if (!Process.myUserHandle().isSystem()) {
+ return DISABLED_FOR_USER;
+ }
+
+ return AVAILABLE;
+ }
+
+ @Override
+ public boolean isChecked() {
+ var cr = mContext.getContentResolver();
+ String key = Settings.Global.FORCE_DISABLE_SUPL;
+ int def = Settings.Global.FORCE_DISABLE_SUPL_DEFAULT;
+
+ return Settings.Global.getInt(cr, key, def) == 1;
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ var cr = mContext.getContentResolver();
+ String key = Settings.Global.FORCE_DISABLE_SUPL;
+
+ return Settings.Global.putInt(cr, key, isChecked ? 1 : 0);
+ }
+
+ @Override
+ public int getSliceHighlightMenuRes() {
+ return NO_RES;
+ }
+}

View File

@ -0,0 +1,172 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tad <tad@spotco.us>
Date: Wed, 20 Apr 2022 01:04:27 -0400
Subject: [PATCH] Add a toggle for microG enablement
Copy and pasted from the GrapheneOS exec spawning toggle patch
Change-Id: Ibea6ea9bed1c2ae3491f403d9e5c17c1d1c403f1
Signed-off-by: Tad <tad@spotco.us>
---
res/values/strings.xml | 3 +
res/xml/security_dashboard_settings.xml | 6 +
.../settings/security/SecuritySettings.java | 1 +
.../SigSpoofPreferenceController.java | 106 ++++++++++++++++++
4 files changed, 116 insertions(+)
create mode 100644 src/com/android/settings/security/SigSpoofPreferenceController.java
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 6b86c5a12bc..06ab1e345df 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -677,6 +677,9 @@
<string name="hosts_disable_title">Disable DNS content blocker</string>
<string name="hosts_disable_summary">Disables use of the included /etc/hosts database for data collection and malware blocking.</string>
+ <string name="sig_spoof_title">Unprivileged microG enablement</string>
+ <string name="sig_spoof_summary">Allows official builds of microG apps to function. Not supported, not recommended. May break apps and/or degrade their security model. Notes: 1) microG connects directly to Google, 2) apps talking to microG do so using proprietary Google libraries, 3) microG can download/execute proprietary code from Google.</string>
+
<!-- Text shown for summary of owner info setting (if none set) [CHAR LIMIT=40]-->
<string name="owner_info_settings_summary">None</string>
<!-- Hint text shown in owner info edit text [CHAR LIMIT=50] -->
diff --git a/res/xml/security_dashboard_settings.xml b/res/xml/security_dashboard_settings.xml
index db158b72433..604e8720e6f 100644
--- a/res/xml/security_dashboard_settings.xml
+++ b/res/xml/security_dashboard_settings.xml
@@ -86,6 +86,12 @@
android:title="@string/hosts_disable_title"
android:summary="@string/hosts_disable_summary"
android:persistent="false" />
+
+ <SwitchPreference
+ android:key="sig_spoof"
+ android:title="@string/sig_spoof_title"
+ android:summary="@string/sig_spoof_summary"
+ android:persistent="false" />
</PreferenceCategory>
<Preference
diff --git a/src/com/android/settings/security/SecuritySettings.java b/src/com/android/settings/security/SecuritySettings.java
index 8079cd5067d..f009703ed24 100644
--- a/src/com/android/settings/security/SecuritySettings.java
+++ b/src/com/android/settings/security/SecuritySettings.java
@@ -109,6 +109,7 @@ public class SecuritySettings extends DashboardFragment {
securityPreferenceControllers.add(new ExecSpawnPreferenceController(context));
securityPreferenceControllers.add(new NativeDebugPreferenceController(context));
securityPreferenceControllers.add(new HostsPreferenceController(context));
+ securityPreferenceControllers.add(new SigSpoofPreferenceController(context));
controllers.add(new PreferenceCategoryController(context, SECURITY_CATEGORY)
.setChildren(securityPreferenceControllers));
controllers.addAll(securityPreferenceControllers);
diff --git a/src/com/android/settings/security/SigSpoofPreferenceController.java b/src/com/android/settings/security/SigSpoofPreferenceController.java
new file mode 100644
index 00000000000..258b59b0b07
--- /dev/null
+++ b/src/com/android/settings/security/SigSpoofPreferenceController.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2022 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.security;
+
+import android.content.Context;
+
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.os.SystemProperties;
+
+import android.provider.Settings;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceCategory;
+import androidx.preference.PreferenceGroup;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.TwoStatePreference;
+import androidx.preference.SwitchPreference;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.core.lifecycle.events.OnResume;
+
+public class SigSpoofPreferenceController extends AbstractPreferenceController
+ implements PreferenceControllerMixin, OnResume, Preference.OnPreferenceChangeListener {
+
+ private static final String SYS_KEY_SIG_SPOOF_ENABLE = "persist.security.sigspoof";
+ private static final String PREF_KEY_SIG_SPOOF_ENABLE = "sig_spoof";
+ private static final String PREF_KEY_SECURITY_CATEGORY = "security_category";
+
+ private PreferenceCategory mSecurityCategory;
+ private SwitchPreference mSigSpoofEnable;
+ private boolean mIsAdmin;
+ private UserManager mUm;
+
+ public SigSpoofPreferenceController(Context context) {
+ super(context);
+ mUm = UserManager.get(context);
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mSecurityCategory = screen.findPreference(PREF_KEY_SECURITY_CATEGORY);
+ updatePreferenceState();
+ }
+
+ @Override
+ public boolean isAvailable() {
+ mIsAdmin = mUm.isAdminUser();
+ return mIsAdmin;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return PREF_KEY_SIG_SPOOF_ENABLE;
+ }
+
+ // TODO: should we use onCreatePreferences() instead?
+ private void updatePreferenceState() {
+ if (mSecurityCategory == null) {
+ return;
+ }
+
+ if (mIsAdmin) {
+ mSigSpoofEnable = (SwitchPreference) mSecurityCategory.findPreference(PREF_KEY_SIG_SPOOF_ENABLE);
+ mSigSpoofEnable.setChecked(SystemProperties.getInt(SYS_KEY_SIG_SPOOF_ENABLE, 0) == 1);
+ } else {
+ mSecurityCategory.removePreference(mSecurityCategory.findPreference(PREF_KEY_SIG_SPOOF_ENABLE));
+ }
+ }
+
+ @Override
+ public void onResume() {
+ updatePreferenceState();
+ if (mSigSpoofEnable != null) {
+ boolean mode = mSigSpoofEnable.isChecked();
+ SystemProperties.set(SYS_KEY_SIG_SPOOF_ENABLE, mode ? "1" : "0");
+ }
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object value) {
+ final String key = preference.getKey();
+ if (PREF_KEY_SIG_SPOOF_ENABLE.equals(key)) {
+ final boolean mode = !mSigSpoofEnable.isChecked();
+ SystemProperties.set(SYS_KEY_SIG_SPOOF_ENABLE, mode ? "1" : "0");
+ }
+ return true;
+ }
+}

View File

@ -0,0 +1,172 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tad <tad@spotco.us>
Date: Wed, 20 Apr 2022 01:04:27 -0400
Subject: [PATCH] Add a toggle for OpenEUICC enablement
Copy and pasted from the GrapheneOS exec spawning toggle patch
Change-Id: Ibea6ea9bed1c2ae3491f403d9e5c17c1d1c403f1
Signed-off-by: Tad <tad@spotco.us>
---
res/values/strings.xml | 3 +
res/xml/security_dashboard_settings.xml | 6 +
.../OpenEuiccPreferenceController.java | 106 ++++++++++++++++++
.../settings/security/SecuritySettings.java | 1 +
4 files changed, 116 insertions(+)
create mode 100644 src/com/android/settings/security/OpenEuiccPreferenceController.java
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 06ab1e345df..2cfe705e467 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -680,6 +680,9 @@
<string name="sig_spoof_title">Unprivileged microG enablement</string>
<string name="sig_spoof_summary">Allows official builds of microG apps to function. Not supported, not recommended. May break apps and/or degrade their security model. Notes: 1) microG connects directly to Google, 2) apps talking to microG do so using proprietary Google libraries, 3) microG can download/execute proprietary code from Google.</string>
+ <string name="openeuicc_title">Enable eUICC management</string>
+ <string name="openeuicc_summary">Enables the OpenEUICC app to allow management of virtual (eSIM) and physical eUICC cards. Reboot required after toggling.</string>
+
<!-- Text shown for summary of owner info setting (if none set) [CHAR LIMIT=40]-->
<string name="owner_info_settings_summary">None</string>
<!-- Hint text shown in owner info edit text [CHAR LIMIT=50] -->
diff --git a/res/xml/security_dashboard_settings.xml b/res/xml/security_dashboard_settings.xml
index 604e8720e6f..de90cec5bcc 100644
--- a/res/xml/security_dashboard_settings.xml
+++ b/res/xml/security_dashboard_settings.xml
@@ -92,6 +92,12 @@
android:title="@string/sig_spoof_title"
android:summary="@string/sig_spoof_summary"
android:persistent="false" />
+
+ <SwitchPreference
+ android:key="openeuicc"
+ android:title="@string/openeuicc_title"
+ android:summary="@string/openeuicc_summary"
+ android:persistent="false" />
</PreferenceCategory>
<Preference
diff --git a/src/com/android/settings/security/OpenEuiccPreferenceController.java b/src/com/android/settings/security/OpenEuiccPreferenceController.java
new file mode 100644
index 00000000000..9ecfa96bfd5
--- /dev/null
+++ b/src/com/android/settings/security/OpenEuiccPreferenceController.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2022 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.security;
+
+import android.content.Context;
+
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.os.SystemProperties;
+
+import android.provider.Settings;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceCategory;
+import androidx.preference.PreferenceGroup;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.TwoStatePreference;
+import androidx.preference.SwitchPreference;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.core.lifecycle.events.OnResume;
+
+public class OpenEuiccPreferenceController extends AbstractPreferenceController
+ implements PreferenceControllerMixin, OnResume, Preference.OnPreferenceChangeListener {
+
+ private static final String SYS_KEY_OPENEUICC_ENABLE = "persist.security.openeuicc";
+ private static final String PREF_KEY_OPENEUICC_ENABLE = "openeuicc";
+ private static final String PREF_KEY_SECURITY_CATEGORY = "security_category";
+
+ private PreferenceCategory mSecurityCategory;
+ private SwitchPreference mOpenEuiccEnable;
+ private boolean mIsAdmin;
+ private UserManager mUm;
+
+ public OpenEuiccPreferenceController(Context context) {
+ super(context);
+ mUm = UserManager.get(context);
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mSecurityCategory = screen.findPreference(PREF_KEY_SECURITY_CATEGORY);
+ updatePreferenceState();
+ }
+
+ @Override
+ public boolean isAvailable() {
+ mIsAdmin = mUm.isAdminUser();
+ return mIsAdmin;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return PREF_KEY_OPENEUICC_ENABLE;
+ }
+
+ // TODO: should we use onCreatePreferences() instead?
+ private void updatePreferenceState() {
+ if (mSecurityCategory == null) {
+ return;
+ }
+
+ if (mIsAdmin) {
+ mOpenEuiccEnable = (SwitchPreference) mSecurityCategory.findPreference(PREF_KEY_OPENEUICC_ENABLE);
+ mOpenEuiccEnable.setChecked(SystemProperties.getInt(SYS_KEY_OPENEUICC_ENABLE, 0) == 1);
+ } else {
+ mSecurityCategory.removePreference(mSecurityCategory.findPreference(PREF_KEY_OPENEUICC_ENABLE));
+ }
+ }
+
+ @Override
+ public void onResume() {
+ updatePreferenceState();
+ if (mOpenEuiccEnable != null) {
+ boolean mode = mOpenEuiccEnable.isChecked();
+ SystemProperties.set(SYS_KEY_OPENEUICC_ENABLE, mode ? "1" : "0");
+ }
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object value) {
+ final String key = preference.getKey();
+ if (PREF_KEY_OPENEUICC_ENABLE.equals(key)) {
+ final boolean mode = !mOpenEuiccEnable.isChecked();
+ SystemProperties.set(SYS_KEY_OPENEUICC_ENABLE, mode ? "1" : "0");
+ }
+ return true;
+ }
+}
diff --git a/src/com/android/settings/security/SecuritySettings.java b/src/com/android/settings/security/SecuritySettings.java
index f009703ed24..ee9acc01f6b 100644
--- a/src/com/android/settings/security/SecuritySettings.java
+++ b/src/com/android/settings/security/SecuritySettings.java
@@ -110,6 +110,7 @@ public class SecuritySettings extends DashboardFragment {
securityPreferenceControllers.add(new NativeDebugPreferenceController(context));
securityPreferenceControllers.add(new HostsPreferenceController(context));
securityPreferenceControllers.add(new SigSpoofPreferenceController(context));
+ securityPreferenceControllers.add(new OpenEuiccPreferenceController(context));
controllers.add(new PreferenceCategoryController(context, SECURITY_CATEGORY)
.setChildren(securityPreferenceControllers));
controllers.addAll(securityPreferenceControllers);

View File

@ -0,0 +1,98 @@
From 4a4a7301a534fa2c54f12c9f93a3832105b36967 Mon Sep 17 00:00:00 2001
From: Dmitry Muhomor <muhomor.dmitry@gmail.com>
Date: Sun, 17 Apr 2022 18:00:53 +0300
Subject: [PATCH] add an ability to disable non-system apps from the "App info"
screen
---
.../AppButtonsPreferenceController.java | 41 ++++++++++++++++++-
1 file changed, 39 insertions(+), 2 deletions(-)
diff --git a/src/com/android/settings/applications/appinfo/AppButtonsPreferenceController.java b/src/com/android/settings/applications/appinfo/AppButtonsPreferenceController.java
index 03053fdeeb6..e0d2d2ee61c 100644
--- a/src/com/android/settings/applications/appinfo/AppButtonsPreferenceController.java
+++ b/src/com/android/settings/applications/appinfo/AppButtonsPreferenceController.java
@@ -205,6 +205,15 @@ public void onDestroy() {
}
private class UninstallAndDisableButtonListener implements View.OnClickListener {
+ private boolean mChangeEnabledStateOfUserApp;
+
+ UninstallAndDisableButtonListener() {
+ this(false);
+ }
+
+ UninstallAndDisableButtonListener(boolean changeEnabledStateOfUserApp) {
+ mChangeEnabledStateOfUserApp = changeEnabledStateOfUserApp;
+ }
@Override
public void onClick(View v) {
@@ -236,8 +245,13 @@ public void onClick(View v) {
mUserId);
if (admin != null && !uninstallBlockedBySystem) {
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(mActivity, admin);
- } else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
+ } else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0 || mChangeEnabledStateOfUserApp) {
if (mAppEntry.info.enabled && !isDisabledUntilUsed()) {
+ if (mChangeEnabledStateOfUserApp) {
+ handleDialogClick(ButtonActionDialogFragment.DialogType.DISABLE);
+ return;
+ }
+
showDialogInner(ButtonActionDialogFragment.DialogType.DISABLE);
} else {
mMetricsFeatureProvider.action(
@@ -468,6 +482,25 @@ void updateUninstallButton() {
}
mButtonsPref.setButton2Enabled(enabled);
+
+ if (enabled && !isBundled) {
+ // "enabled" means "show uninstall button" in this context
+ int text;
+ int icon;
+ if (mAppEntry.info.enabled) {
+ text = R.string.disable_text;
+ icon = R.drawable.ic_settings_disable;
+ } else {
+ text = R.string.enable_text;
+ icon = R.drawable.ic_settings_enable;
+ }
+ mButtonsPref
+ .setButton4Text(text)
+ .setButton4Icon(icon)
+ .setButton4Visible(true)
+ .setButton4OnClickListener(new UninstallAndDisableButtonListener(true))
+ ;
+ }
}
/**
@@ -491,7 +524,9 @@ private void refreshAndFinishIfPossible(boolean removeTaskWhenFinishing) {
@VisibleForTesting
void updateForceStopButton() {
- if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
+ if (!mPackageInfo.applicationInfo.enabled) {
+ mButtonsPref.setButton3Visible(false);
+ } else if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
// User can't force stop device admin.
Log.w(TAG, "User can't force stop device admin");
updateForceStopButtonInner(false /* enabled */);
@@ -516,6 +551,7 @@ void updateForceStopButton() {
@VisibleForTesting
void updateForceStopButtonInner(boolean enabled) {
+ mButtonsPref.setButton3Visible(true);
if (mAppsControlDisallowedBySystem) {
mButtonsPref.setButton3Enabled(false);
} else {
@@ -530,6 +566,7 @@ void uninstallPkg(String packageName, boolean allUsers) {
Uri packageUri = Uri.parse("package:" + packageName);
Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri);
uninstallIntent.putExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, allUsers);
+ uninstallIntent.putExtra(Intent.EXTRA_UNINSTALL_SHOW_MORE_OPTIONS_BUTTON, false);
mMetricsFeatureProvider.action(mActivity, SettingsEnums.ACTION_SETTINGS_UNINSTALL_APP);
mFragment.startActivityForResult(uninstallIntent, mRequestUninstall);

@ -1 +1 @@
Subproject commit e9dd9574ed900e690423336aa27f4085afc08dde
Subproject commit fd69b2f74a0a3952ee22337f91af69ef4bf68990

View File

@ -296,25 +296,24 @@ if enterAndClear "packages/apps/Nfc"; then
applyPatch "$DOS_PATCHES/android_packages_apps_Nfc/0001-constify_JNINativeMethod.patch"; #Constify JNINativeMethod tables (GrapheneOS)
fi;
#if enterAndClear "packages/apps/Settings"; then #TODO: 21REBASE
#git revert --no-edit 41b4ed345a91da1dd46c00ee11a151c2b5ff4f43;
#applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0004-Private_DNS.patch"; #More 'Private DNS' options (heavily based off of a CalyxOS patch)
#applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0005-Automatic_Reboot.patch"; #Timeout for reboot (GrapheneOS)
#applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0006-Bluetooth_Timeout.patch"; #Timeout for Bluetooth (CalyxOS)
#applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0007-WiFi_Timeout.patch"; #Timeout for Wi-Fi (CalyxOS)
#applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0008-ptrace_scope.patch"; #Add native debugging setting (GrapheneOS)
#applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0010-exec_spawning_toggle.patch"; #Add exec spawning toggle (GrapheneOS)
#applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0011-Random_MAC.patch"; #Add option to always randomize MAC (GrapheneOS)
#applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0009-Install_Restrictions.patch"; #UserManager app installation restrictions (GrapheneOS)
#applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0012-hosts_toggle.patch"; #Add a toggle to disable /etc/hosts lookup (heavily based off of a GrapheneOS patch)
#applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0013-Captive_Portal_Toggle.patch"; #Add option to disable captive portal checks (GrapheneOS)
#applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0014-LTE_Only_Mode-1.patch"; #LTE Only Mode (GrapheneOS)
#applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0014-LTE_Only_Mode-2.patch"; #Fix LTE Only mode on World Mode (GrapheneOS)
#applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0015-SUPL_Toggle.patch"; #Add a toggle for forcibly disabling SUPL (GrapheneOS)
#applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0016-microG_Toggle.patch"; #Add a toggle for microG enablement (heavily based off of a GrapheneOS patch)
#if [ "$DOS_DEBLOBBER_REMOVE_EUICC_FULL" = false ]; then applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0017-OpenEUICC_Toggle.patch"; fi; #Add a toggle for OpenEUICC enablement (heavily based off of a GrapheneOS patch)
#applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Settings/0001-disable_apps.patch"; #Add an ability to disable non-system apps from the "App info" screen (GrapheneOS)
#fi;
if enterAndClear "packages/apps/Settings"; then
applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0004-prereq.patch"; #Revert 0dfbfff41cc28699c1e218e20b10d9d42688f950
applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0004-Private_DNS.patch"; #More 'Private DNS' options (heavily based off of a CalyxOS patch)
applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0005-Automatic_Reboot.patch"; #Timeout for reboot (GrapheneOS)
applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0006-Bluetooth_Timeout.patch"; #Timeout for Bluetooth (CalyxOS)
applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0007-WiFi_Timeout.patch"; #Timeout for Wi-Fi (CalyxOS)
applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0008-ptrace_scope.patch"; #Add native debugging setting (GrapheneOS)
applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0010-exec_spawning_toggle.patch"; #Add exec spawning toggle (GrapheneOS)
applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0011-Random_MAC.patch"; #Add option to always randomize MAC (GrapheneOS)
#applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0009-Install_Restrictions.patch"; #UserManager app installation restrictions (GrapheneOS) #TODO: 21REBASE
applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0012-hosts_toggle.patch"; #Add a toggle to disable /etc/hosts lookup (heavily based off of a GrapheneOS patch)
applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0013-Captive_Portal_Toggle.patch"; #Add option to disable captive portal checks (GrapheneOS)
applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0014-LTE_Only_Mode.patch"; #LTE Only Mode (GrapheneOS)
applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0015-SUPL_Toggle.patch"; #Add a toggle for forcibly disabling SUPL (GrapheneOS)
applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0016-microG_Toggle.patch"; #Add a toggle for microG enablement (heavily based off of a GrapheneOS patch)
if [ "$DOS_DEBLOBBER_REMOVE_EUICC_FULL" = false ]; then applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0017-OpenEUICC_Toggle.patch"; fi; #Add a toggle for OpenEUICC enablement (heavily based off of a GrapheneOS patch)
applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0018-disable_apps.patch"; #Add an ability to disable non-system apps from the "App info" screen (GrapheneOS)
fi;
if enterAndClear "packages/apps/SetupWizard"; then
applyPatch "$DOS_PATCHES/android_packages_apps_SetupWizard/0001-Remove_Analytics.patch"; #Remove analytics (DivestOS)