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

Commit

Permalink
Fixed empty settings values
Browse files Browse the repository at this point in the history
Closes #1164
  • Loading branch information
M66B committed Jan 27, 2014
1 parent 8326238 commit 9e8218f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 76 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Test and beta releases will have experimental functions enabled by default.

**Next release**

* Fixed empty settings values ([issue](https://github.com/M66B/XPrivacy/issues/1164))
* Updated German translation

[Open issues](https://github.com/M66B/XPrivacy/issues?state=open)
Expand Down
34 changes: 26 additions & 8 deletions src/biz/bokhorst/xprivacy/PrivacyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class PrivacyService {
private static ExecutorService mExecutor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());

// TODO: define column names
// sqlite3 /data/data/biz.bokhorst.xprivacy/xprivacy.db

public static void register(List<String> listError, String secret) {
try {
Expand Down Expand Up @@ -544,14 +545,19 @@ public void setSetting(ParcelableSetting setting) throws RemoteException {

db.beginTransaction();
try {
// Create record
ContentValues values = new ContentValues();
values.put("uid", setting.uid);
values.put("name", setting.name);
values.put("value", setting.value);

// Insert/update record
db.insertWithOnConflict(cTableSetting, null, values, SQLiteDatabase.CONFLICT_REPLACE);
if (setting.value == null)
db.delete(cTableSetting, "uid=? AND name=?", new String[] { Integer.toString(setting.uid),
setting.name });
else {
// Create record
ContentValues values = new ContentValues();
values.put("uid", setting.uid);
values.put("name", setting.name);
values.put("value", setting.value);

// Insert/update record
db.insertWithOnConflict(cTableSetting, null, values, SQLiteDatabase.CONFLICT_REPLACE);
}

db.setTransactionSuccessful();
} finally {
Expand Down Expand Up @@ -843,6 +849,18 @@ private static SQLiteDatabase getDatabase() {
} finally {
db.endTransaction();
}

} else if (db.needUpgrade(4)) {
db.beginTransaction();
try {
db.execSQL("DELETE FROM setting WHERE value IS NULL");
db.setVersion(4);
db.setTransactionSuccessful();
} catch (Throwable ex) {
Util.bug(null, ex);
} finally {
db.endTransaction();
}
}

Util.log(null, Log.WARN, "Database version=" + db.getVersion());
Expand Down
98 changes: 30 additions & 68 deletions src/biz/bokhorst/xprivacy/SettingsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,39 +118,13 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
btnClear.setEnabled(!isChecked);

etSerial.setEnabled(!isChecked);
etLat.setEnabled(!isChecked);
etLon.setEnabled(!isChecked);
for (EditText edit : edits)
edit.setEnabled(!isChecked);
etSearch.setEnabled(!isChecked);
etMac.setEnabled(!isChecked);
etIP.setEnabled(!isChecked);
etImei.setEnabled(!isChecked);
etPhone.setEnabled(!isChecked);
etId.setEnabled(!isChecked);
etGsfId.setEnabled(!isChecked);
etAdId.setEnabled(!isChecked);
etMcc.setEnabled(!isChecked);
etMnc.setEnabled(!isChecked);
etCountry.setEnabled(!isChecked);
etOperator.setEnabled(!isChecked);
etIccId.setEnabled(!isChecked);
etSubscriber.setEnabled(!isChecked);
etSSID.setEnabled(!isChecked);
etUa.setEnabled(!isChecked);

cbSerial.setEnabled(!isChecked);
cbLat.setEnabled(!isChecked);
cbLon.setEnabled(!isChecked);
for (CheckBox box : boxes)
box.setEnabled(!isChecked);
btnSearch.setEnabled(!isChecked);
cbMac.setEnabled(!isChecked);
cbImei.setEnabled(!isChecked);
cbPhone.setEnabled(!isChecked);
cbId.setEnabled(!isChecked);
cbGsfId.setEnabled(!isChecked);
cbAdId.setEnabled(!isChecked);
cbCountry.setEnabled(!isChecked);
cbSubscriber.setEnabled(!isChecked);
cbSSID.setEnabled(!isChecked);
}
});

Expand Down Expand Up @@ -415,18 +389,8 @@ public void onClick(View view) {
edit.setText("");
etSearch.setText("");

cbSerial.setChecked(false);
cbLat.setChecked(false);
cbLon.setChecked(false);
cbMac.setChecked(false);
cbImei.setChecked(false);
cbPhone.setChecked(false);
cbId.setChecked(false);
cbGsfId.setChecked(false);
cbAdId.setChecked(false);
cbCountry.setChecked(false);
cbSubscriber.setChecked(false);
cbSSID.setChecked(false);
for (CheckBox box : boxes)
box.setChecked(false);
}
});

Expand Down Expand Up @@ -509,8 +473,7 @@ public void onClick(View view) {
Util.log(null, Log.WARN, "Cleared all settings uid=" + uid);
} else {
// Serial#
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingSerial,
cbSerial.isChecked() ? PrivacyManager.cValueRandom : etSerial.getText().toString());
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingSerial, getValue(cbSerial, etSerial));

// Set latitude
try {
Expand All @@ -537,31 +500,23 @@ public void onClick(View view) {
}

// Other settings
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingMac,
cbMac.isChecked() ? PrivacyManager.cValueRandom : etMac.getText().toString());
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingIP, etIP.getText().toString());
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingImei,
cbImei.isChecked() ? PrivacyManager.cValueRandom : etImei.getText().toString());
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingPhone,
cbPhone.isChecked() ? PrivacyManager.cValueRandom : etPhone.getText().toString());
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingId,
cbId.isChecked() ? PrivacyManager.cValueRandom : etId.getText().toString());
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingGsfId,
cbGsfId.isChecked() ? PrivacyManager.cValueRandom : etGsfId.getText().toString());
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingAdId,
cbAdId.isChecked() ? PrivacyManager.cValueRandom : etAdId.getText().toString());
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingMcc, etMcc.getText().toString());
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingMnc, etMnc.getText().toString());
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingCountry,
cbCountry.isChecked() ? PrivacyManager.cValueRandom : etCountry.getText().toString());
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingOperator, etOperator.getText()
.toString());
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingIccId, etIccId.getText().toString());
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingMac, getValue(cbMac, etMac));
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingIP, getValue(null, etIP));
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingImei, getValue(cbImei, etImei));
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingPhone, getValue(cbPhone, etPhone));
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingId, getValue(cbId, etId));
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingGsfId, getValue(cbGsfId, etGsfId));
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingAdId, getValue(cbAdId, etAdId));
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingMcc, getValue(null, etMcc));
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingMnc, getValue(null, etMnc));
PrivacyManager
.setSetting(null, uid, PrivacyManager.cSettingCountry, getValue(cbCountry, etCountry));
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingOperator, getValue(null, etOperator));
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingIccId, getValue(null, etIccId));
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingSubscriber,
cbSubscriber.isChecked() ? PrivacyManager.cValueRandom : etSubscriber.getText().toString());
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingSSID,
cbSSID.isChecked() ? PrivacyManager.cValueRandom : etSSID.getText().toString());
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingUa, etUa.getText().toString());
getValue(cbSubscriber, etSubscriber));
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingSSID, getValue(cbSSID, etSSID));
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingUa, getValue(null, etUa));
}

dlgSettings.dismiss();
Expand All @@ -580,4 +535,11 @@ public void onClick(View view) {
dlgSettings.setCancelable(true);
dlgSettings.show();
}

private static String getValue(CheckBox check, EditText edit) {
if (check != null && check.isChecked())
return PrivacyManager.cValueRandom;
String value = edit.getText().toString().trim();
return ("".equals(value) ? null : value);
}
}

0 comments on commit 9e8218f

Please sign in to comment.