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

Commit

Permalink
Acquire partial wakelock for batch operations (untested)
Browse files Browse the repository at this point in the history
Refs #1683
  • Loading branch information
M66B committed May 25, 2014
1 parent 928f94f commit ffdb3aa
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 37 deletions.
1 change: 1 addition & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="biz.bokhorst.xprivacy.MANAGE_PACKAGES" />
<uses-permission android:name="biz.bokhorst.xprivacy.pro.CHECK" />

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Changelog

**Next release**

* Acquire partial wakelock for batch operations ([issue](/../../issues/1683))
* Updated Italian translation
* Updated traditional Chinese translation

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ XPrivacy asks for the following Android permissions:
* Boot: to be able to check if XPrivacy is enabled
* Internet: to be able to submit and fetch [crowd sourced restrictions](http://crowd.xprivacy.eu/)
* Storage: to be able to export XPrivacy's settings to the SD card (only [pro version](http://www.xprivacy.eu/))
* Wakelock: to keep the processor running during batch operations

If desired, you can even restrict XPrivacy from accessing any of the above,
but there are some [limitations](https://github.com/M66B/XPrivacy#limitations).
Expand Down
3 changes: 3 additions & 0 deletions lint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
<issue id="StringFormatInvalid" severity="warning" />
<issue id="TypographyQuotes" severity="warning" />
<issue id="UnusedIds" severity="warning" />
<issue id="Wakelock">
<ignore path="src/biz/bokhorst/xprivacy/ActivityShare.java" />
</issue>
</lint>
115 changes: 78 additions & 37 deletions src/biz/bokhorst/xprivacy/ActivityShare.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.PowerManager;
import android.os.Process;
import android.provider.ContactsContract;
import android.provider.Settings.Secure;
Expand Down Expand Up @@ -625,55 +626,64 @@ protected void onPostExecute(List<AppState> listApp) {
private class ToggleTask extends AsyncTask<String, Integer, Throwable> {
@Override
protected Throwable doInBackground(String... params) {
// Get data
mProgressCurrent = 0;
List<Integer> lstUid = mAppAdapter.getListUid();
final String restrictionName = params[0];
int actionId = ((RadioGroup) ActivityShare.this.findViewById(R.id.rgToggle)).getCheckedRadioButtonId();
// Get wakelock
PowerManager pm = (PowerManager) ActivityShare.this.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "XPrivacy.Fetch");
wl.acquire();
try {
// Get data
mProgressCurrent = 0;
List<Integer> lstUid = mAppAdapter.getListUid();
final String restrictionName = params[0];
int actionId = ((RadioGroup) ActivityShare.this.findViewById(R.id.rgToggle)).getCheckedRadioButtonId();

for (Integer uid : lstUid)
try {
if (mAbort)
throw new AbortException(ActivityShare.this);
for (Integer uid : lstUid)
try {
if (mAbort)
throw new AbortException(ActivityShare.this);

// Update progess
publishProgress(++mProgressCurrent, lstUid.size() + 1);
setState(uid, STATE_RUNNING, null);
// Update progess
publishProgress(++mProgressCurrent, lstUid.size() + 1);
setState(uid, STATE_RUNNING, null);

List<Boolean> oldState = PrivacyManager.getRestartStates(uid, restrictionName);
List<Boolean> oldState = PrivacyManager.getRestartStates(uid, restrictionName);

if (actionId == R.id.rbClear)
PrivacyManager.deleteRestrictions(uid, restrictionName, (restrictionName == null));
if (actionId == R.id.rbClear)
PrivacyManager.deleteRestrictions(uid, restrictionName, (restrictionName == null));

else if (actionId == R.id.rbRestrict) {
PrivacyManager.setRestriction(uid, restrictionName, null, true, false);
PrivacyManager.updateState(uid);
}
else if (actionId == R.id.rbRestrict) {
PrivacyManager.setRestriction(uid, restrictionName, null, true, false);
PrivacyManager.updateState(uid);
}

else if (actionId == R.id.rbTemplateCategory)
PrivacyManager.applyTemplate(uid, restrictionName, false);
else if (actionId == R.id.rbTemplateCategory)
PrivacyManager.applyTemplate(uid, restrictionName, false);

else if (actionId == R.id.rbTemplateFull)
PrivacyManager.applyTemplate(uid, restrictionName, true);
else if (actionId == R.id.rbTemplateFull)
PrivacyManager.applyTemplate(uid, restrictionName, true);

else if (actionId == R.id.rbEnableOndemand) {
PrivacyManager.setSetting(uid, PrivacyManager.cSettingOnDemand, Boolean.toString(true));
PrivacyManager.setSetting(uid, PrivacyManager.cSettingNotify, Boolean.toString(false));
else if (actionId == R.id.rbEnableOndemand) {
PrivacyManager.setSetting(uid, PrivacyManager.cSettingOnDemand, Boolean.toString(true));
PrivacyManager.setSetting(uid, PrivacyManager.cSettingNotify, Boolean.toString(false));

} else if (actionId == R.id.rbDisableOndemand) {
PrivacyManager.setSetting(uid, PrivacyManager.cSettingOnDemand, Boolean.toString(false));
PrivacyManager.setSetting(uid, PrivacyManager.cSettingNotify, Boolean.toString(true));
} else if (actionId == R.id.rbDisableOndemand) {
PrivacyManager.setSetting(uid, PrivacyManager.cSettingOnDemand, Boolean.toString(false));
PrivacyManager.setSetting(uid, PrivacyManager.cSettingNotify, Boolean.toString(true));

} else
Util.log(null, Log.ERROR, "Unknown action=" + actionId);
} else
Util.log(null, Log.ERROR, "Unknown action=" + actionId);

List<Boolean> newState = PrivacyManager.getRestartStates(uid, restrictionName);
List<Boolean> newState = PrivacyManager.getRestartStates(uid, restrictionName);

setState(uid, STATE_SUCCESS, !newState.equals(oldState) ? getString(R.string.msg_restart) : null);
} catch (Throwable ex) {
setState(uid, STATE_FAILURE, ex.getMessage());
return ex;
}
setState(uid, STATE_SUCCESS, !newState.equals(oldState) ? getString(R.string.msg_restart)
: null);
} catch (Throwable ex) {
setState(uid, STATE_FAILURE, ex.getMessage());
return ex;
}
} finally {
wl.release();
}

return null;
}
Expand All @@ -697,6 +707,11 @@ private class ExportTask extends AsyncTask<File, Integer, Throwable> {

@Override
protected Throwable doInBackground(File... params) {
// Get wakelock
PowerManager pm = (PowerManager) ActivityShare.this.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "XPrivacy.Fetch");
wl.acquire();

mProgressCurrent = 0;
try {
mFile = params[0];
Expand Down Expand Up @@ -815,6 +830,8 @@ protected Throwable doInBackground(File... params) {
if (mFile.exists())
mFile.delete();
return ex;
} finally {
wl.release();
}
}

Expand Down Expand Up @@ -850,6 +867,10 @@ protected void onPostExecute(Throwable result) {
private class ImportTask extends AsyncTask<Object, Integer, Throwable> {
@Override
protected Throwable doInBackground(Object... params) {
// Get wakelock
PowerManager pm = (PowerManager) ActivityShare.this.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "XPrivacy.Fetch");
wl.acquire();
try {
// Parameters
File file = (File) params[0];
Expand Down Expand Up @@ -935,6 +956,8 @@ public void run() {
return null;
} catch (Throwable ex) {
return ex;
} finally {
wl.release();
}
}

Expand Down Expand Up @@ -1182,6 +1205,10 @@ private class FetchTask extends AsyncTask<Boolean, Integer, Throwable> {
@Override
@SuppressLint("DefaultLocale")
protected Throwable doInBackground(Boolean... params) {
// Get wakelock
PowerManager pm = (PowerManager) ActivityShare.this.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "XPrivacy.Fetch");
wl.acquire();
try {
// Get data
boolean clear = params[0];
Expand Down Expand Up @@ -1331,6 +1358,8 @@ protected Throwable doInBackground(Boolean... params) {
} catch (Throwable ex) {
Util.bug(null, ex);
return ex;
} finally {
wl.release();
}
}

Expand All @@ -1352,6 +1381,10 @@ protected void onPostExecute(Throwable result) {
private class SubmitTask extends AsyncTask<Object, Integer, Throwable> {
@Override
protected Throwable doInBackground(Object... params) {
// Get wakelock
PowerManager pm = (PowerManager) ActivityShare.this.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "XPrivacy.Fetch");
wl.acquire();
try {
// Get data
List<ApplicationInfoEx> lstApp = mAppAdapter.getListAppInfo();
Expand Down Expand Up @@ -1568,6 +1601,8 @@ else if (restrictionName.equals(PrivacyManager.cContacts))
} catch (Throwable ex) {
Util.bug(null, ex);
return ex;
} finally {
wl.release();
}
}

Expand Down Expand Up @@ -1643,6 +1678,10 @@ public RegisterTask(ActivityBase context) {
}

protected Throwable doInBackground(String... params) {
// Get wakelock
PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "XPrivacy.Fetch");
wl.acquire();
try {
String android_id = Secure.getString(mContext.getContentResolver(), Secure.ANDROID_ID);

Expand Down Expand Up @@ -1701,6 +1740,8 @@ protected Throwable doInBackground(String... params) {
} catch (Throwable ex) {
Util.bug(null, ex);
return ex;
} finally {
wl.release();
}
}

Expand Down

0 comments on commit ffdb3aa

Please sign in to comment.