mirror of https://github.com/BOINC/boinc.git
-android: acquisition of WakeLock to prevent CPU throttling when display is off.
This commit is contained in:
parent
5b701ef9e0
commit
96f3bdf16b
|
@ -29,6 +29,7 @@
|
|||
<uses-sdk android:minSdkVersion="9" />
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||
|
||||
<application
|
||||
android:icon="@drawable/boinc"
|
||||
|
|
|
@ -22,6 +22,8 @@ import java.util.ArrayList;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.PowerManager;
|
||||
import android.os.PowerManager.WakeLock;
|
||||
import android.util.Log;
|
||||
import edu.berkeley.boinc.rpc.CcStatus;
|
||||
import edu.berkeley.boinc.rpc.GlobalPreferences;
|
||||
|
@ -40,6 +42,9 @@ public class ClientStatus {
|
|||
private final String TAG = "BOINC Client Status";
|
||||
private Context ctx; // application context in order to fire broadcast events
|
||||
|
||||
//WakeLock
|
||||
WakeLock wakeLock;
|
||||
|
||||
//RPC wrapper
|
||||
private CcStatus status;
|
||||
private ArrayList<Result> results;
|
||||
|
@ -75,6 +80,33 @@ public class ClientStatus {
|
|||
public Integer networkSuspendReason = 0; //reason why network activity got suspended, only if NETWORK_STATUS_SUSPENDED
|
||||
private Boolean networkParseError = false; //indicates that status could not be parsed and is therefore invalid
|
||||
|
||||
public ClientStatus(Context ctx) {
|
||||
this.ctx = ctx;
|
||||
|
||||
// set up Wake Lock
|
||||
// see documentation at http://developer.android.com/reference/android/os/PowerManager.html
|
||||
PowerManager pm = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE);
|
||||
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
|
||||
wakeLock.setReferenceCounted(false); // "one call to release() is sufficient to undo the effect of all previous calls to acquire()"
|
||||
}
|
||||
|
||||
// call to acquire or release resources held by the WakeLock.
|
||||
// acquisition: every time the Monitor loop calls setClientStatus and computingStatus == COMPUTING_STATUS_COMPUTING
|
||||
// release: every time computingStatus != COMPUTING_STATUS_COMPUTING , and in Monitor.onDestroy()
|
||||
public void setWakeLock(Boolean acquire) {
|
||||
try {
|
||||
if(wakeLock.isHeld() == acquire) return; // wakeLock already in desired state
|
||||
|
||||
if(acquire) { // acquire wakeLock
|
||||
wakeLock.acquire();
|
||||
Log.d(TAG, "wakeLock acquired");
|
||||
} else { // release wakeLock
|
||||
wakeLock.release();
|
||||
Log.d(TAG, "wakeLock released");
|
||||
}
|
||||
} catch (Exception e) {Log.w(TAG, "Exception durign setWakeLock " + acquire, e);}
|
||||
}
|
||||
|
||||
/*
|
||||
* fires "clientstatuschange" broadcast, so registered Activities can update their model.
|
||||
*/
|
||||
|
@ -90,10 +122,10 @@ public class ClientStatus {
|
|||
|
||||
/*
|
||||
* Application context is required by the broadcast mechanism, reference is copied by Monitor service on start up.
|
||||
*/
|
||||
|
||||
public synchronized void setCtx(Context tctx) {
|
||||
this.ctx = tctx;
|
||||
}
|
||||
}*/
|
||||
|
||||
/*
|
||||
* called frequently by Monitor to set the RPC data. These objects are used to determine the client status and parse it in the data model of this class.
|
||||
|
@ -220,12 +252,14 @@ public class ClientStatus {
|
|||
computingStatus = COMPUTING_STATUS_NEVER;
|
||||
computingSuspendReason = status.task_suspend_reason; // = 4 - SUSPEND_REASON_USER_REQ????
|
||||
computingParseError = false;
|
||||
setWakeLock(false);
|
||||
return;
|
||||
}
|
||||
if((status.task_mode == BOINCDefs.RUN_MODE_AUTO) && (status.task_suspend_reason != BOINCDefs.SUSPEND_NOT_SUSPENDED)) {
|
||||
computingStatus = COMPUTING_STATUS_SUSPENDED;
|
||||
computingSuspendReason = status.task_suspend_reason;
|
||||
computingParseError = false;
|
||||
setWakeLock(false);
|
||||
return;
|
||||
}
|
||||
if((status.task_mode == BOINCDefs.RUN_MODE_AUTO) && (status.task_suspend_reason == BOINCDefs.SUSPEND_NOT_SUSPENDED)) {
|
||||
|
@ -244,11 +278,13 @@ public class ClientStatus {
|
|||
computingStatus = COMPUTING_STATUS_COMPUTING;
|
||||
computingSuspendReason = status.task_suspend_reason; // = 0 - SUSPEND_NOT_SUSPENDED
|
||||
computingParseError = false;
|
||||
setWakeLock(true);
|
||||
return;
|
||||
} else { // client "is able but idle"
|
||||
computingStatus = COMPUTING_STATUS_IDLE;
|
||||
computingSuspendReason = status.task_suspend_reason; // = 0 - SUSPEND_NOT_SUSPENDED
|
||||
computingParseError = false;
|
||||
setWakeLock(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ import edu.berkeley.boinc.rpc.Transfer;
|
|||
|
||||
public class Monitor extends Service {
|
||||
|
||||
private final String TAG = "BOINC Monitor Service";
|
||||
private static final String TAG = "BOINC Monitor Service";
|
||||
|
||||
private static ClientStatus clientStatus; //holds the status of the client as determined by the Monitor
|
||||
private static AppPreferences appPrefs; //hold the status of the app, controlled by AppPreferences
|
||||
|
@ -428,7 +428,7 @@ public class Monitor extends Service {
|
|||
|
||||
public static ClientStatus getClientStatus() { //singleton pattern
|
||||
if (clientStatus == null) {
|
||||
clientStatus = new ClientStatus();
|
||||
Log.d(TAG,"WARNING: clientStatus not yet initialized");
|
||||
}
|
||||
return clientStatus;
|
||||
}
|
||||
|
@ -480,7 +480,7 @@ public class Monitor extends Service {
|
|||
retryAttempts = getResources().getInteger(R.integer.monitor_setup_connection_retry_attempts);
|
||||
|
||||
// initialize singleton helper classes and provide application context
|
||||
getClientStatus().setCtx(this);
|
||||
clientStatus = new ClientStatus(this);
|
||||
getAppPrefs().readPrefs(this);
|
||||
|
||||
if(!started) {
|
||||
|
@ -508,11 +508,13 @@ public class Monitor extends Service {
|
|||
monitorRunning = false;
|
||||
monitorThread.interrupt();
|
||||
|
||||
clientStatus.setWakeLock(false); // release wakeLock, if held.
|
||||
|
||||
// Quit client here is not appropriate?!
|
||||
// Keep Client running until explecitely killed, independently from UI
|
||||
//quitClient();
|
||||
|
||||
//Toast.makeText(this, "BOINC Monitor Service Stopped", Toast.LENGTH_SHORT).show();
|
||||
//android.widget.Toast.makeText(this, "BOINC Monitor Service Stopped", android.widget.Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue