Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Commit

Permalink
Allow application specific disable of globally set randomization
Browse files Browse the repository at this point in the history
Fixes #706
  • Loading branch information
M66B committed Nov 10, 2013
1 parent a8f7e73 commit e14b253
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 67 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
5 changes: 4 additions & 1 deletion src/biz/bokhorst/xprivacy/PackageChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/biz/bokhorst/xprivacy/PrivacyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -561,17 +561,17 @@ 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,
boolean useCache) {
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;
Expand Down Expand Up @@ -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
Expand Down
21 changes: 12 additions & 9 deletions src/biz/bokhorst/xprivacy/PrivacyProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
147 changes: 95 additions & 52 deletions src/biz/bokhorst/xprivacy/SettingsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit e14b253

Please sign in to comment.