mirror of https://github.com/BOINC/boinc.git
android: polling all_projects_list moved into client startup routing to avoid network on UI thread
This commit is contained in:
parent
a05a3fec05
commit
14fa4dc708
|
@ -25,15 +25,11 @@ import edu.berkeley.boinc.client.Monitor;
|
||||||
import edu.berkeley.boinc.rpc.ProjectInfo;
|
import edu.berkeley.boinc.rpc.ProjectInfo;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.Service;
|
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.ServiceConnection;
|
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
|
@ -46,29 +42,11 @@ import android.widget.Toast;
|
||||||
public class AttachProjectListActivity extends Activity implements android.view.View.OnClickListener{
|
public class AttachProjectListActivity extends Activity implements android.view.View.OnClickListener{
|
||||||
|
|
||||||
private final String TAG = "BOINC AttachProjectListActivity";
|
private final String TAG = "BOINC AttachProjectListActivity";
|
||||||
|
|
||||||
private Monitor monitor;
|
|
||||||
private Boolean mIsBound;
|
|
||||||
|
|
||||||
private ListView lv;
|
private ListView lv;
|
||||||
private AttachProjectListAdapter listAdapter;
|
private AttachProjectListAdapter listAdapter;
|
||||||
private Dialog manualUrlInputDialog;
|
private Dialog manualUrlInputDialog;
|
||||||
|
|
||||||
private ServiceConnection mConnection = new ServiceConnection() {
|
|
||||||
public void onServiceConnected(ComponentName className, IBinder service) {
|
|
||||||
// This is called when the connection with the service has been established, getService returns the Monitor object that is needed to call functions.
|
|
||||||
monitor = ((Monitor.LocalBinder)service).getService();
|
|
||||||
mIsBound = true;
|
|
||||||
|
|
||||||
populateView();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onServiceDisconnected(ComponentName className) { // This should not happen
|
|
||||||
monitor = null;
|
|
||||||
mIsBound = false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -76,33 +54,8 @@ public class AttachProjectListActivity extends Activity implements android.view.
|
||||||
|
|
||||||
Log.d(TAG, "onCreate");
|
Log.d(TAG, "onCreate");
|
||||||
|
|
||||||
//bind monitor service
|
//get supported projects
|
||||||
doBindService();
|
ArrayList<ProjectInfo> data = Monitor.getClientStatus().supportedProjects;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDestroy() {
|
|
||||||
Log.d(TAG, "onDestroy");
|
|
||||||
doUnbindService();
|
|
||||||
super.onDestroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doBindService() {
|
|
||||||
// Establish a connection with the service, onServiceConnected gets called when
|
|
||||||
bindService(new Intent(this, Monitor.class), mConnection, Service.BIND_AUTO_CREATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doUnbindService() {
|
|
||||||
if (mIsBound) {
|
|
||||||
// Detach existing connection.
|
|
||||||
unbindService(mConnection);
|
|
||||||
mIsBound = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void populateView(){
|
|
||||||
//retrieve projects from monitor
|
|
||||||
ArrayList<ProjectInfo> data = monitor.getAndroidProjectsList();
|
|
||||||
Log.d(TAG,"monitor.getAndroidProjectsList returned with " + data.size() + " elements");
|
Log.d(TAG,"monitor.getAndroidProjectsList returned with " + data.size() + " elements");
|
||||||
|
|
||||||
// setup layout
|
// setup layout
|
||||||
|
@ -113,6 +66,12 @@ public class AttachProjectListActivity extends Activity implements android.view.
|
||||||
|
|
||||||
// set title bar
|
// set title bar
|
||||||
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
|
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
Log.d(TAG, "onDestroy");
|
||||||
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
// check whether device is online before starting connection attempt
|
// check whether device is online before starting connection attempt
|
||||||
|
|
|
@ -363,8 +363,15 @@ public class ProjectsActivity extends FragmentActivity {
|
||||||
|
|
||||||
private final String TAG = "ProjectOperationAsync";
|
private final String TAG = "ProjectOperationAsync";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute() {
|
||||||
|
Log.d(TAG,"onPreExecute");
|
||||||
|
super.onPreExecute();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Boolean doInBackground(String... params) {
|
protected Boolean doInBackground(String... params) {
|
||||||
|
Log.d(TAG,"doInBackground");
|
||||||
try{
|
try{
|
||||||
String url = params[0];
|
String url = params[0];
|
||||||
Integer operation = Integer.parseInt(params[1]);
|
Integer operation = Integer.parseInt(params[1]);
|
||||||
|
|
|
@ -41,6 +41,7 @@ import edu.berkeley.boinc.R;
|
||||||
import edu.berkeley.boinc.rpc.CcStatus;
|
import edu.berkeley.boinc.rpc.CcStatus;
|
||||||
import edu.berkeley.boinc.rpc.GlobalPreferences;
|
import edu.berkeley.boinc.rpc.GlobalPreferences;
|
||||||
import edu.berkeley.boinc.rpc.Project;
|
import edu.berkeley.boinc.rpc.Project;
|
||||||
|
import edu.berkeley.boinc.rpc.ProjectInfo;
|
||||||
import edu.berkeley.boinc.rpc.Result;
|
import edu.berkeley.boinc.rpc.Result;
|
||||||
import edu.berkeley.boinc.rpc.Transfer;
|
import edu.berkeley.boinc.rpc.Transfer;
|
||||||
import edu.berkeley.boinc.utils.BOINCDefs;
|
import edu.berkeley.boinc.utils.BOINCDefs;
|
||||||
|
@ -85,7 +86,7 @@ public class ClientStatus {
|
||||||
public Integer computingSuspendReason = 0; //reason why computing got suspended, only if COMPUTING_STATUS_SUSPENDED
|
public Integer computingSuspendReason = 0; //reason why computing got suspended, only if COMPUTING_STATUS_SUSPENDED
|
||||||
private Boolean computingParseError = false; //indicates that status could not be parsed and is therefore invalid
|
private Boolean computingParseError = false; //indicates that status could not be parsed and is therefore invalid
|
||||||
|
|
||||||
//network status
|
// network status
|
||||||
public Integer networkStatus = 2;
|
public Integer networkStatus = 2;
|
||||||
public static final int NETWORK_STATUS_NEVER = 0;
|
public static final int NETWORK_STATUS_NEVER = 0;
|
||||||
public static final int NETWORK_STATUS_SUSPENDED = 1;
|
public static final int NETWORK_STATUS_SUSPENDED = 1;
|
||||||
|
@ -93,6 +94,9 @@ public class ClientStatus {
|
||||||
public Integer networkSuspendReason = 0; //reason why network activity got suspended, only if NETWORK_STATUS_SUSPENDED
|
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
|
private Boolean networkParseError = false; //indicates that status could not be parsed and is therefore invalid
|
||||||
|
|
||||||
|
// supported projects
|
||||||
|
public ArrayList<ProjectInfo> supportedProjects;
|
||||||
|
|
||||||
public ClientStatus(Context ctx) {
|
public ClientStatus(Context ctx) {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
|
|
||||||
|
@ -190,6 +194,10 @@ public class ClientStatus {
|
||||||
this.prefs = prefs;
|
this.prefs = prefs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized ArrayList<ProjectInfo> getSupprtedProjects () {
|
||||||
|
return supportedProjects;
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized CcStatus getClientStatus() {
|
public synchronized CcStatus getClientStatus() {
|
||||||
if(results == null) { //check in case monitor is not set up yet (e.g. while logging in)
|
if(results == null) { //check in case monitor is not set up yet (e.g. while logging in)
|
||||||
Log.d(TAG, "state is null");
|
Log.d(TAG, "state is null");
|
||||||
|
|
|
@ -165,6 +165,8 @@ public class Monitor extends Service {
|
||||||
// read preferences for GUI to be able to display data
|
// read preferences for GUI to be able to display data
|
||||||
GlobalPreferences clientPrefs = rpc.getGlobalPrefsWorkingStruct();
|
GlobalPreferences clientPrefs = rpc.getGlobalPrefsWorkingStruct();
|
||||||
Monitor.getClientStatus().setPrefs(clientPrefs);
|
Monitor.getClientStatus().setPrefs(clientPrefs);
|
||||||
|
// read supported projects
|
||||||
|
readAndroidProjectsList();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(connected) {
|
if(connected) {
|
||||||
|
@ -451,6 +453,26 @@ public class Monitor extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reads all_project_list.xml from Client and filters
|
||||||
|
// projects not supporting Android. List does not change
|
||||||
|
// during run-time. Called once during setup.
|
||||||
|
// Stored in ClientStatus.
|
||||||
|
private void readAndroidProjectsList() {
|
||||||
|
ArrayList<ProjectInfo> allProjects = rpc.getAllProjectsList();
|
||||||
|
ArrayList<ProjectInfo> androidProjects = new ArrayList<ProjectInfo>();
|
||||||
|
|
||||||
|
//filter projects that do not support Android
|
||||||
|
for (ProjectInfo project: allProjects) {
|
||||||
|
if(project.platforms.contains(getString(R.string.boinc_platform_name))) {
|
||||||
|
Log.d(TAG, project.name + " supports " + getString(R.string.boinc_platform_name));
|
||||||
|
androidProjects.add(project);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set list in ClientStatus
|
||||||
|
getClientStatus().supportedProjects = androidProjects;
|
||||||
|
}
|
||||||
|
|
||||||
public static ClientStatus getClientStatus() { //singleton pattern
|
public static ClientStatus getClientStatus() { //singleton pattern
|
||||||
if (clientStatus == null) {
|
if (clientStatus == null) {
|
||||||
Log.d(TAG,"WARNING: clientStatus not yet initialized");
|
Log.d(TAG,"WARNING: clientStatus not yet initialized");
|
||||||
|
@ -465,7 +487,6 @@ public class Monitor extends Service {
|
||||||
return appPrefs;
|
return appPrefs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* returns this class, allows clients to access this service's functions and attributes.
|
* returns this class, allows clients to access this service's functions and attributes.
|
||||||
*/
|
*/
|
||||||
|
@ -661,20 +682,6 @@ public class Monitor extends Service {
|
||||||
return authKey;
|
return authKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<ProjectInfo> getAndroidProjectsList() {
|
|
||||||
ArrayList<ProjectInfo> allProjects = rpc.getAllProjectsList();
|
|
||||||
ArrayList<ProjectInfo> androidProjects = new ArrayList<ProjectInfo>();
|
|
||||||
|
|
||||||
//filter projects that do not support Android
|
|
||||||
for (ProjectInfo project: allProjects) {
|
|
||||||
if(project.platforms.contains(getString(R.string.boinc_platform_name))) {
|
|
||||||
Log.d(TAG, project.name + " supports " + getString(R.string.boinc_platform_name));
|
|
||||||
androidProjects.add(project);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return androidProjects;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProjectConfig getProjectConfig(String url) {
|
public ProjectConfig getProjectConfig(String url) {
|
||||||
ProjectConfig config = null;
|
ProjectConfig config = null;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue