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

Commit

Permalink
Selectable clear for import
Browse files Browse the repository at this point in the history
Refs #1119
  • Loading branch information
M66B committed Feb 25, 2014
1 parent 16cd93f commit 3c05c13
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Changelog
**Next release**

* Toggle restriction will allow to choose between, clear, restrict and template ([issue](/../../issues/1319))
* Option to select if existing restrictions should be deleted on fetch ([issue](/../../issues/1119))
* Option to select if existing restrictions should be deleted on import or fetch ([issue](/../../issues/1119))
* Move database to /data/system/xprivacy ([issue](/../../issues/1437))
* Submit functions with a white/blacklist as having an exception ([issue](/../../issues/1438))
* Always ask on demand for dangerous functions (was dependent on setting)
Expand Down
32 changes: 19 additions & 13 deletions src/biz/bokhorst/xprivacy/ActivityShare.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ protected void onCreate(Bundle savedInstanceState) {
else
showFileName();

if (action.equals(ACTION_IMPORT))
cbClear.setVisibility(View.VISIBLE);

} else if (action.equals(ACTION_FETCH)) {
tvDescription.setText(getBaseURL(ActivityShare.this));
cbClear.setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -269,7 +272,7 @@ public void onClick(View v) {
// Import
else if (action.equals(ACTION_IMPORT)) {
mRunning = true;
new ImportTask().executeOnExecutor(mExecutor, new File(mFileName));
new ImportTask().executeOnExecutor(mExecutor, new File(mFileName), cbClear.isChecked());
}

// Export
Expand Down Expand Up @@ -766,14 +769,13 @@ protected void onPostExecute(Throwable result) {
}
}

private class ImportTask extends AsyncTask<File, Integer, Throwable> {
private File mFile;

private class ImportTask extends AsyncTask<Object, Integer, Throwable> {
@Override
protected Throwable doInBackground(File... params) {
protected Throwable doInBackground(Object... params) {
try {
mFile = (File) params[0];

// Parameters
File file = (File) params[0];
boolean clear = (Boolean) params[1];
List<Integer> listUidSelected = mAppAdapter.getListUid();

// Progress
Expand All @@ -787,13 +789,13 @@ public void run() {
};

// Parse XML
Util.log(null, Log.INFO, "Importing " + mFile);
Util.log(null, Log.INFO, "Importing " + file);
FileInputStream fis = null;
Map<String, Map<String, List<ImportHandler.MethodDescription>>> mapPackage;
try {
fis = new FileInputStream(mFile);
fis = new FileInputStream(file);
XMLReader xmlReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
ImportHandler importHandler = new ImportHandler(listUidSelected, progress);
ImportHandler importHandler = new ImportHandler(clear, listUidSelected, progress);
xmlReader.setContentHandler(importHandler);
xmlReader.parse(new InputSource(fis));
mapPackage = importHandler.getPackageMap();
Expand Down Expand Up @@ -872,6 +874,7 @@ protected void onPostExecute(Throwable result) {
}

private class ImportHandler extends DefaultHandler {
private boolean mClear;
private List<Integer> mListUidSelected;
private List<Integer> mListUidSettings = new ArrayList<Integer>();
private List<Integer> mListUidRestrictions = new ArrayList<Integer>();
Expand All @@ -886,7 +889,8 @@ private class ImportHandler extends DefaultHandler {
private Runnable mProgress;
private String android_id = Secure.getString(getContentResolver(), Secure.ANDROID_ID);

public ImportHandler(List<Integer> listUidSelected, Runnable progress) {
public ImportHandler(boolean clear, List<Integer> listUidSelected, Runnable progress) {
mClear = clear;
mListUidSelected = listUidSelected;
mProgress = progress;
}
Expand Down Expand Up @@ -957,7 +961,8 @@ public void startElement(String uri, String localName, String qName, Attributes
setState(uid, STATE_RUNNING, null);

// Clear settings
PrivacyManager.deleteSettings(uid);
if (mClear)
PrivacyManager.deleteSettings(uid);
}

PrivacyManager.setSetting(uid, type, name, value);
Expand Down Expand Up @@ -1019,7 +1024,8 @@ public void startElement(String uri, String localName, String qName, Attributes
runOnUiThread(mProgress);

// Clear restrictions
PrivacyManager.deleteRestrictions(uid, null);
if (mClear)
PrivacyManager.deleteRestrictions(uid, null);
}

// Set restriction
Expand Down

0 comments on commit 3c05c13

Please sign in to comment.