From ffdb3aace9da1ce4f66d073b894686bbe4e94daf Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 25 May 2014 09:25:49 +0200 Subject: [PATCH] Acquire partial wakelock for batch operations (untested) Refs #1683 --- AndroidManifest.xml | 1 + CHANGELOG.md | 1 + README.md | 1 + lint.xml | 3 + src/biz/bokhorst/xprivacy/ActivityShare.java | 115 +++++++++++++------ 5 files changed, 84 insertions(+), 37 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index acb694fc3..62f6a9ab2 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -24,6 +24,7 @@ + diff --git a/CHANGELOG.md b/CHANGELOG.md index 5efe01d30..b05d16a43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Changelog **Next release** +* Acquire partial wakelock for batch operations ([issue](/../../issues/1683)) * Updated Italian translation * Updated traditional Chinese translation diff --git a/README.md b/README.md index 81bc40364..6ea6bf658 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/lint.xml b/lint.xml index 41c93a932..bd125201c 100644 --- a/lint.xml +++ b/lint.xml @@ -10,4 +10,7 @@ + + + \ No newline at end of file diff --git a/src/biz/bokhorst/xprivacy/ActivityShare.java b/src/biz/bokhorst/xprivacy/ActivityShare.java index 07efcd7ae..04489bd79 100644 --- a/src/biz/bokhorst/xprivacy/ActivityShare.java +++ b/src/biz/bokhorst/xprivacy/ActivityShare.java @@ -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; @@ -625,55 +626,64 @@ protected void onPostExecute(List listApp) { private class ToggleTask extends AsyncTask { @Override protected Throwable doInBackground(String... params) { - // Get data - mProgressCurrent = 0; - List 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 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 oldState = PrivacyManager.getRestartStates(uid, restrictionName); + List 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 newState = PrivacyManager.getRestartStates(uid, restrictionName); + List 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; } @@ -697,6 +707,11 @@ private class ExportTask extends AsyncTask { @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]; @@ -815,6 +830,8 @@ protected Throwable doInBackground(File... params) { if (mFile.exists()) mFile.delete(); return ex; + } finally { + wl.release(); } } @@ -850,6 +867,10 @@ protected void onPostExecute(Throwable result) { private class ImportTask extends AsyncTask { @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]; @@ -935,6 +956,8 @@ public void run() { return null; } catch (Throwable ex) { return ex; + } finally { + wl.release(); } } @@ -1182,6 +1205,10 @@ private class FetchTask extends AsyncTask { @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]; @@ -1331,6 +1358,8 @@ protected Throwable doInBackground(Boolean... params) { } catch (Throwable ex) { Util.bug(null, ex); return ex; + } finally { + wl.release(); } } @@ -1352,6 +1381,10 @@ protected void onPostExecute(Throwable result) { private class SubmitTask extends AsyncTask { @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 lstApp = mAppAdapter.getListAppInfo(); @@ -1568,6 +1601,8 @@ else if (restrictionName.equals(PrivacyManager.cContacts)) } catch (Throwable ex) { Util.bug(null, ex); return ex; + } finally { + wl.release(); } } @@ -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); @@ -1701,6 +1740,8 @@ protected Throwable doInBackground(String... params) { } catch (Throwable ex) { Util.bug(null, ex); return ex; + } finally { + wl.release(); } }