DivestOS/Patches/CyanogenMod-13.0/android_packages_apps_Settings/Hostname_Rand.patch
2016-12-21 19:30:02 -05:00

232 lines
10 KiB
Diff

From ef32dacb30b5c938d48ba294ff660b0cd5777dd6 Mon Sep 17 00:00:00 2001
From: Tad <tad@spotco.us>
Date: Mon, 18 Apr 2016 09:27:27 -0400
Subject: [PATCH] Implement hostname Randomization
Change-Id: I00bfb9235979c2c80191cb0871716adaa3583e06
---
MAC_Rand.patch | 120 +++++++++++++++++++++++++
res/values/cm_strings.xml | 4 +
res/xml/wireless_settings.xml | 6 ++
src/com/android/settings/WirelessSettings.java | 14 +++
4 files changed, 144 insertions(+)
create mode 100644 MAC_Rand.patch
diff --git a/MAC_Rand.patch b/MAC_Rand.patch
new file mode 100644
index 0000000..48ad1ec
--- /dev/null
+++ b/MAC_Rand.patch
@@ -0,0 +1,120 @@
+From e84a1e030313cbc2875c9d3ee1f016808d33dab3 Mon Sep 17 00:00:00 2001
+From: Tad <tad@spotco.us>
+Date: Mon, 18 Apr 2016 08:53:03 -0400
+Subject: [PATCH] Implement MAC Randomization
+
+Change-Id: Id074d011eac7c33af267de4c1649670c32770cb5
+---
+ res/values/cm_strings.xml | 4 ++++
+ res/xml/wireless_settings.xml | 6 ++++++
+ src/com/android/settings/WirelessSettings.java | 24 +++++++++++++++++++++++-
+ 3 files changed, 33 insertions(+), 1 deletion(-)
+
+diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
+index 128660e..8aa4785 100644
+--- a/res/values/cm_strings.xml
++++ b/res/values/cm_strings.xml
+@@ -1187,4 +1187,8 @@
+
+ <!-- Label for settings shortcut: carrier selection -->
+ <string name="shortcut_carrier_title">Network operators</string>
++
++ <!-- randomize MAC addresses -->
++ <string name="randomize_mac_title">Randomize MAC addresses</string>
++ <string name="randomize_mac_summary">Assign random MAC addresses when network devices are enabled</string>
+ </resources>
+diff --git a/res/xml/wireless_settings.xml b/res/xml/wireless_settings.xml
+index 8882003..4a2d5d0 100644
+--- a/res/xml/wireless_settings.xml
++++ b/res/xml/wireless_settings.xml
+@@ -19,6 +19,12 @@
+ android:title="@string/radio_controls_title">
+
+ <SwitchPreference
++ android:key="randomize_mac"
++ android:title="@string/randomize_mac_title"
++ android:summary="@string/randomize_mac_summary"
++ android:persistent="false" />
++
++ <SwitchPreference
+ android:key="toggle_airplane"
+ android:title="@string/airplane_mode"
+ android:persistent="false"
+diff --git a/src/com/android/settings/WirelessSettings.java b/src/com/android/settings/WirelessSettings.java
+index 4a0c9e3..4432940 100644
+--- a/src/com/android/settings/WirelessSettings.java
++++ b/src/com/android/settings/WirelessSettings.java
+@@ -37,6 +37,7 @@ import android.os.SystemProperties;
+ import android.os.UserHandle;
+ import android.os.UserManager;
+ import android.preference.Preference;
++import android.preference.Preference.OnPreferenceChangeListener;
+ import android.preference.PreferenceCategory;
+ import android.preference.PreferenceScreen;
+ import android.preference.SwitchPreference;
+@@ -58,9 +59,11 @@ import java.util.ArrayList;
+ import java.util.Arrays;
+ import java.util.List;
+
+-public class WirelessSettings extends SettingsPreferenceFragment implements Indexable {
++public class WirelessSettings extends SettingsPreferenceFragment
++ implements OnPreferenceChangeListener, Indexable {
+ private static final String TAG = "WirelessSettings";
+
++ private static final String KEY_RANDOMIZE_MAC = "randomize_mac";
+ private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
+ private static final String KEY_NFC_CATEGORY_SETTINGS = "nfc_category_settings";
+ private static final String KEY_TOGGLE_NFC = "toggle_nfc";
+@@ -76,9 +79,12 @@ public class WirelessSettings extends SettingsPreferenceFragment implements Inde
+ private static final String KEY_WFC_SETTINGS = "wifi_calling_settings";
+ private static final String KEY_NFC_PAYMENT_SETTINGS = "nfc_payment_settings";
+
++ private static final String RANDOMIZE_PERSIST_PROP = "persist.privacy.randomize_mac";
++
+ public static final String EXIT_ECM_RESULT = "exit_ecm_result";
+ public static final int REQUEST_CODE_EXIT_ECM = 1;
+
++ private SwitchPreference mRandomizeMac;
+ private AirplaneModeEnabler mAirplaneModeEnabler;
+ private SwitchPreference mAirplaneModePreference;
+ private NfcEnabler mNfcEnabler;
+@@ -232,6 +238,8 @@ public class WirelessSettings extends SettingsPreferenceFragment implements Inde
+ final boolean isSecondaryUser = myUserId != UserHandle.USER_OWNER;
+
+ final Activity activity = getActivity();
++ mRandomizeMac = (SwitchPreference) findPreference(KEY_RANDOMIZE_MAC);
++ mRandomizeMac.setOnPreferenceChangeListener(this);
+ mAirplaneModePreference = (SwitchPreference) findPreference(KEY_TOGGLE_AIRPLANE);
+ SwitchPreference nfc = (SwitchPreference) findPreference(KEY_TOGGLE_NFC);
+ PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS);
+@@ -370,6 +378,10 @@ public class WirelessSettings extends SettingsPreferenceFragment implements Inde
+ public void onResume() {
+ super.onResume();
+
++ if (mRandomizeMac != null) {
++ mRandomizeMac.setChecked(SystemProperties.getBoolean(RANDOMIZE_PERSIST_PROP, true));
++ }
++
+ mAirplaneModeEnabler.resume();
+ if (mNfcEnabler != null) {
+ mNfcEnabler.resume();
+@@ -390,6 +402,16 @@ public class WirelessSettings extends SettingsPreferenceFragment implements Inde
+ }
+ }
+
++ @Override
++ public boolean onPreferenceChange(Preference preference, Object newValue) {
++ if (preference == mRandomizeMac) {
++ SystemProperties.set(RANDOMIZE_PERSIST_PROP, (Boolean) newValue ? "1" : "0");
++ return true;
++ }
++
++ return false;
++ }
++
+ @Override
+ public void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+--
+2.8.0
+
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
index 8aa4785..cb825c2 100644
--- a/res/values/cm_strings.xml
+++ b/res/values/cm_strings.xml
@@ -1191,4 +1191,8 @@
<!-- randomize MAC addresses -->
<string name="randomize_mac_title">Randomize MAC addresses</string>
<string name="randomize_mac_summary">Assign random MAC addresses when network devices are enabled</string>
+
+ <!-- randomize hostname -->
+ <string name="randomize_hostname_title">Randomize network hostname</string>
+ <string name="randomize_hostname_summary">Assign random network hostname on boot</string>
</resources>
diff --git a/res/xml/wireless_settings.xml b/res/xml/wireless_settings.xml
index 4a2d5d0..905e8de 100644
--- a/res/xml/wireless_settings.xml
+++ b/res/xml/wireless_settings.xml
@@ -25,6 +25,12 @@
android:persistent="false" />
<SwitchPreference
+ android:key="randomize_hostname"
+ android:title="@string/randomize_hostname_title"
+ android:summary="@string/randomize_hostname_summary"
+ android:persistent="false" />
+
+ <SwitchPreference
android:key="toggle_airplane"
android:title="@string/airplane_mode"
android:persistent="false"
diff --git a/src/com/android/settings/WirelessSettings.java b/src/com/android/settings/WirelessSettings.java
index 4432940..6ce772e 100644
--- a/src/com/android/settings/WirelessSettings.java
+++ b/src/com/android/settings/WirelessSettings.java
@@ -64,6 +64,7 @@ public class WirelessSettings extends SettingsPreferenceFragment
private static final String TAG = "WirelessSettings";
private static final String KEY_RANDOMIZE_MAC = "randomize_mac";
+ private static final String KEY_RANDOMIZE_HOST = "randomize_hostname";
private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
private static final String KEY_NFC_CATEGORY_SETTINGS = "nfc_category_settings";
private static final String KEY_TOGGLE_NFC = "toggle_nfc";
@@ -80,11 +81,13 @@ public class WirelessSettings extends SettingsPreferenceFragment
private static final String KEY_NFC_PAYMENT_SETTINGS = "nfc_payment_settings";
private static final String RANDOMIZE_PERSIST_PROP = "persist.privacy.randomize_mac";
+ private static final String RANDOMIZE_HOST_PERSIST_PROP = "persist.privacy.randomize_host";
public static final String EXIT_ECM_RESULT = "exit_ecm_result";
public static final int REQUEST_CODE_EXIT_ECM = 1;
private SwitchPreference mRandomizeMac;
+ private SwitchPreference mRandomizeHost;
private AirplaneModeEnabler mAirplaneModeEnabler;
private SwitchPreference mAirplaneModePreference;
private NfcEnabler mNfcEnabler;
@@ -240,6 +243,8 @@ public class WirelessSettings extends SettingsPreferenceFragment
final Activity activity = getActivity();
mRandomizeMac = (SwitchPreference) findPreference(KEY_RANDOMIZE_MAC);
mRandomizeMac.setOnPreferenceChangeListener(this);
+ mRandomizeHost = (SwitchPreference) findPreference(KEY_RANDOMIZE_HOST);
+ mRandomizeHost.setOnPreferenceChangeListener(this);
mAirplaneModePreference = (SwitchPreference) findPreference(KEY_TOGGLE_AIRPLANE);
SwitchPreference nfc = (SwitchPreference) findPreference(KEY_TOGGLE_NFC);
PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS);
@@ -382,6 +387,10 @@ public class WirelessSettings extends SettingsPreferenceFragment
mRandomizeMac.setChecked(SystemProperties.getBoolean(RANDOMIZE_PERSIST_PROP, true));
}
+ if (mRandomizeHost != null) {
+ mRandomizeHost.setChecked(SystemProperties.getBoolean(RANDOMIZE_HOST_PERSIST_PROP, true));
+ }
+
mAirplaneModeEnabler.resume();
if (mNfcEnabler != null) {
mNfcEnabler.resume();
@@ -409,6 +418,11 @@ public class WirelessSettings extends SettingsPreferenceFragment
return true;
}
+ if (preference == mRandomizeHost) {
+ SystemProperties.set(RANDOMIZE_HOST_PERSIST_PROP, (Boolean) newValue ? "1" : "0");
+ return true;
+ }
+
return false;
}
--
2.8.0