diff --git a/CHANGELOG.md b/CHANGELOG.md index 30094a6b9..0c95746d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Changelog * Show location for license file in about dialog * Fix up navigation (again) ([issue](https://github.com/M66B/XPrivacy/issues/681)) * Auto import pro license file ([issue](https://github.com/M66B/XPrivacy/issues/703)) +* Allow application specific disable of globally set randomization ([issue](https://github.com/M66B/XPrivacy/issues/706)) * Restrict */sys/block/.../cid* and */sys/class/.../cid* ([issue](https://github.com/M66B/XPrivacy/issues/734)) * Restrict system properties ending with *cid* ([issue](https://github.com/M66B/XPrivacy/issues/734)) diff --git a/src/biz/bokhorst/xprivacy/PackageChange.java b/src/biz/bokhorst/xprivacy/PackageChange.java index 9765d7167..eda470027 100644 --- a/src/biz/bokhorst/xprivacy/PackageChange.java +++ b/src/biz/bokhorst/xprivacy/PackageChange.java @@ -156,7 +156,10 @@ public void onReceive(Context context, Intent intent) { PrivacyManager.cIdentification, "/system/build.prop", false); // Select user applications - PrivacyManager.setSetting(null, context, 0, PrivacyManager.cSettingFSystem, "U"); + PrivacyManager.setSetting(null, context, 0, PrivacyManager.cSettingFSystem, + Boolean.toString(false)); + PrivacyManager.setSetting(null, context, 0, PrivacyManager.cSettingFUser, + Boolean.toString(true)); } } diff --git a/src/biz/bokhorst/xprivacy/PrivacyManager.java b/src/biz/bokhorst/xprivacy/PrivacyManager.java index 9a05fc992..df5df9314 100644 --- a/src/biz/bokhorst/xprivacy/PrivacyManager.java +++ b/src/biz/bokhorst/xprivacy/PrivacyManager.java @@ -561,8 +561,8 @@ public static void deleteUsage(Context context, int uid) { public static boolean getSettingBool(XHook hook, Context context, int uid, String settingName, boolean defaultValue, boolean useCache) { - return Boolean.parseBoolean(getSetting(hook, context, uid, settingName, Boolean.toString(defaultValue) - .toString(), useCache)); + return Boolean.parseBoolean(getSetting(hook, context, uid, settingName, Boolean.toString(defaultValue), + useCache)); } public static String getSetting(XHook hook, Context context, int uid, String settingName, String defaultValue, @@ -570,8 +570,8 @@ public static String getSetting(XHook hook, Context context, int uid, String set if (uid == 0) return getSetting(hook, context, settingName, defaultValue, useCache); else { - String setting = getSetting(hook, context, String.format("%s.%d", settingName, uid), defaultValue, useCache); - if (setting == null ? setting == defaultValue : setting.equals(defaultValue)) + String setting = getSetting(hook, context, String.format("%s.%d", settingName, uid), null, useCache); + if (setting == null) return getSetting(hook, context, settingName, defaultValue, useCache); else return setting; @@ -635,7 +635,7 @@ private static String getSetting(XHook hook, Context context, String name, Strin value = PrivacyProvider.getSettingFallback(name, defaultValue); // Default value - if (value == null || value.equals("")) + if (value == null) value = defaultValue; // Add to cache diff --git a/src/biz/bokhorst/xprivacy/PrivacyProvider.java b/src/biz/bokhorst/xprivacy/PrivacyProvider.java index 413796e51..01eba4d40 100644 --- a/src/biz/bokhorst/xprivacy/PrivacyProvider.java +++ b/src/biz/bokhorst/xprivacy/PrivacyProvider.java @@ -32,13 +32,14 @@ @SuppressWarnings("deprecation") @SuppressLint({ "DefaultLocale", "WorldReadableFiles" }) public class PrivacyProvider extends ContentProvider { - public static final String AUTHORITY = "biz.bokhorst.xprivacy.provider"; - public static final String PREF_RESTRICTION = AUTHORITY; - public static final String PREF_USAGE = AUTHORITY + ".usage"; - public static final String PREF_SETTINGS = AUTHORITY + ".settings"; - public static final String PATH_RESTRICTION = "restriction"; - public static final String PATH_USAGE = "usage"; - public static final String PATH_SETTINGS = "settings"; + private static final String AUTHORITY = "biz.bokhorst.xprivacy.provider"; + private static final String PREF_RESTRICTION = AUTHORITY; + private static final String PREF_USAGE = AUTHORITY + ".usage"; + private static final String PREF_SETTINGS = AUTHORITY + ".settings"; + private static final String PATH_RESTRICTION = "restriction"; + private static final String PATH_USAGE = "usage"; + private static final String PATH_SETTINGS = "settings"; + public static final Uri URI_RESTRICTION = Uri.parse("content://" + AUTHORITY + "/" + PATH_RESTRICTION); public static final Uri URI_USAGE = Uri.parse("content://" + AUTHORITY + "/" + PATH_USAGE); public static final Uri URI_SETTING = Uri.parse("content://" + AUTHORITY + "/" + PATH_SETTINGS); @@ -340,7 +341,10 @@ private void updateUsage(final int uid, final String restrictionName, final Stri private void updateSetting(String name, String value) { SharedPreferences prefs = getContext().getSharedPreferences(PREF_SETTINGS, Context.MODE_WORLD_READABLE); SharedPreferences.Editor editor = prefs.edit(); - editor.putString(getSettingPref(name), value); + if (value == null) + editor.remove(getSettingPref(name)); + else + editor.putString(getSettingPref(name), value); editor.apply(); setPrefFileReadable(PREF_SETTINGS); } @@ -599,7 +603,6 @@ private void convertSettings() throws IOException { if (PrivacyManager.cValueRandomLegacy.equals(value)) editor.putString(key, PrivacyManager.cValueRandom); } catch (Throwable ex) { - } editor.apply(); setPrefFileReadable(PREF_SETTINGS); diff --git a/src/biz/bokhorst/xprivacy/SettingsDialog.java b/src/biz/bokhorst/xprivacy/SettingsDialog.java index 1082c8002..716faa672 100644 --- a/src/biz/bokhorst/xprivacy/SettingsDialog.java +++ b/src/biz/bokhorst/xprivacy/SettingsDialog.java @@ -7,6 +7,7 @@ import android.content.Context; import android.location.Address; import android.location.Geocoder; +import android.util.Log; import android.util.TypedValue; import android.view.View; import android.view.Window; @@ -246,61 +247,103 @@ public void onClick(View view) { btnOk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - // Serial# - PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingSerial, - cbSerial.isChecked() ? PrivacyManager.cValueRandom : etSerial.getText().toString()); - - // Set location - try { - float lat = Float.parseFloat(etLat.getText().toString().replace(',', '.')); - float lon = Float.parseFloat(etLon.getText().toString().replace(',', '.')); - if (lat < -90 || lat > 90 || lon < -180 || lon > 180) - throw new InvalidParameterException(); - - PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingLatitude, - cbLat.isChecked() ? PrivacyManager.cValueRandom : Float.toString(lat)); - PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingLongitude, - cbLon.isChecked() ? PrivacyManager.cValueRandom : Float.toString(lon)); - - } catch (Throwable ex) { - PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingLatitude, - cbLat.isChecked() ? PrivacyManager.cValueRandom : ""); - PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingLongitude, - cbLon.isChecked() ? PrivacyManager.cValueRandom : ""); - } + // @formatter:off + if (!cbSerial.isChecked() && etSerial.getText().toString().equals("") && + !cbLat.isChecked() && etLat.getText().toString().equals("") && + !cbLon.isChecked() && etLon.getText().toString().equals("") && + !cbMac.isChecked() && etMac.getText().toString().equals("") && + etIP.getText().toString().equals("") && + !cbImei.isChecked() && etImei.getText().toString().equals("") && + !cbPhone.isChecked() && etPhone.getText().toString().equals("") && + !cbId.isChecked() && etId.getText().toString().equals("") && + !cbGsfId.isChecked() && etGsfId.getText().toString().equals("") && + etMcc.getText().toString().equals("") && + etMnc.getText().toString().equals("") && + !cbCountry.isChecked() && etCountry.getText().toString().equals("") && + etOperator.getText().toString().equals("") && + etIccId.getText().toString().equals("") && + etSubscriber.getText().toString().equals("") && + etUa.getText().toString().equals("")) { + // @formatter:on + + // Clear all settings + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingSerial, null); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingLatitude, null); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingLongitude, null); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingMac, null); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingIP, null); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingImei, null); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingPhone, null); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingId, null); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingGsfId, null); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingMcc, null); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingMnc, null); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingCountry, null); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingOperator, null); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingIccId, null); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingSubscriber, null); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingUa, null); + Util.log(null, Log.WARN, "Cleared all settings uid=" + uid); + } else { + // Serial# + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingSerial, + cbSerial.isChecked() ? PrivacyManager.cValueRandom : etSerial.getText().toString()); + + // Set location + try { + float lat = Float.parseFloat(etLat.getText().toString().replace(',', '.')); + float lon = Float.parseFloat(etLon.getText().toString().replace(',', '.')); + if (lat < -90 || lat > 90 || lon < -180 || lon > 180) + throw new InvalidParameterException(); + + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingLatitude, + cbLat.isChecked() ? PrivacyManager.cValueRandom : Float.toString(lat)); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingLongitude, + cbLon.isChecked() ? PrivacyManager.cValueRandom : Float.toString(lon)); + + } catch (Throwable ex) { + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingLatitude, + cbLat.isChecked() ? PrivacyManager.cValueRandom : ""); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingLongitude, + cbLon.isChecked() ? PrivacyManager.cValueRandom : ""); + } - // Other settings - PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingMac, - cbMac.isChecked() ? PrivacyManager.cValueRandom : etMac.getText().toString()); - PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingIP, etIP.getText().toString()); - PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingImei, - cbImei.isChecked() ? PrivacyManager.cValueRandom : etImei.getText().toString()); - PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingPhone, - cbPhone.isChecked() ? PrivacyManager.cValueRandom : etPhone.getText().toString()); - PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingId, - cbId.isChecked() ? PrivacyManager.cValueRandom : etId.getText().toString()); - PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingGsfId, - cbGsfId.isChecked() ? PrivacyManager.cValueRandom : etGsfId.getText().toString()); - PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingMcc, etMcc.getText().toString()); - PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingMnc, etMnc.getText().toString()); - PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingCountry, - cbCountry.isChecked() ? PrivacyManager.cValueRandom : etCountry.getText().toString()); - PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingOperator, etOperator.getText() - .toString()); - PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingIccId, etIccId.getText() - .toString()); - PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingSubscriber, etSubscriber.getText() - .toString()); - PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingUa, etUa.getText().toString()); + // Other settings + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingMac, + cbMac.isChecked() ? PrivacyManager.cValueRandom : etMac.getText().toString()); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingIP, etIP.getText().toString()); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingImei, + cbImei.isChecked() ? PrivacyManager.cValueRandom : etImei.getText().toString()); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingPhone, + cbPhone.isChecked() ? PrivacyManager.cValueRandom : etPhone.getText().toString()); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingId, + cbId.isChecked() ? PrivacyManager.cValueRandom : etId.getText().toString()); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingGsfId, + cbGsfId.isChecked() ? PrivacyManager.cValueRandom : etGsfId.getText().toString()); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingMcc, etMcc.getText() + .toString()); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingMnc, etMnc.getText() + .toString()); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingCountry, + cbCountry.isChecked() ? PrivacyManager.cValueRandom : etCountry.getText().toString()); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingOperator, etOperator.getText() + .toString()); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingIccId, etIccId.getText() + .toString()); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingSubscriber, etSubscriber + .getText().toString()); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingUa, etUa.getText().toString()); + + if (uid == 0) { + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingAndroidUsage, + Boolean.toString(cbUsage.isChecked())); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingLog, + Boolean.toString(cbLog.isChecked())); + } - if (uid == 0) { - PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingAndroidUsage, - Boolean.toString(cbUsage.isChecked())); - PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingLog, - Boolean.toString(cbLog.isChecked())); + PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingRandom, + Boolean.toString(cbRandom.isChecked())); } - PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingRandom, - Boolean.toString(cbRandom.isChecked())); // Done dlgSettings.dismiss();