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 android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.app.Service;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
|
@ -47,28 +43,10 @@ public class AttachProjectListActivity extends Activity implements android.view.
|
|||
|
||||
private final String TAG = "BOINC AttachProjectListActivity";
|
||||
|
||||
private Monitor monitor;
|
||||
private Boolean mIsBound;
|
||||
|
||||
private ListView lv;
|
||||
private AttachProjectListAdapter listAdapter;
|
||||
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
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -76,33 +54,8 @@ public class AttachProjectListActivity extends Activity implements android.view.
|
|||
|
||||
Log.d(TAG, "onCreate");
|
||||
|
||||
//bind monitor service
|
||||
doBindService();
|
||||
}
|
||||
|
||||
@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();
|
||||
//get supported projects
|
||||
ArrayList<ProjectInfo> data = Monitor.getClientStatus().supportedProjects;
|
||||
Log.d(TAG,"monitor.getAndroidProjectsList returned with " + data.size() + " elements");
|
||||
|
||||
// setup layout
|
||||
|
@ -115,6 +68,12 @@ public class AttachProjectListActivity extends Activity implements android.view.
|
|||
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
|
||||
// as needed for AttachProjectLoginActivity (retrieval of ProjectConfig)
|
||||
// note: available internet does not imply connection to project server
|
||||
|
|
|
@ -363,8 +363,15 @@ public class ProjectsActivity extends FragmentActivity {
|
|||
|
||||
private final String TAG = "ProjectOperationAsync";
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
Log.d(TAG,"onPreExecute");
|
||||
super.onPreExecute();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(String... params) {
|
||||
Log.d(TAG,"doInBackground");
|
||||
try{
|
||||
String url = params[0];
|
||||
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.GlobalPreferences;
|
||||
import edu.berkeley.boinc.rpc.Project;
|
||||
import edu.berkeley.boinc.rpc.ProjectInfo;
|
||||
import edu.berkeley.boinc.rpc.Result;
|
||||
import edu.berkeley.boinc.rpc.Transfer;
|
||||
import edu.berkeley.boinc.utils.BOINCDefs;
|
||||
|
@ -93,6 +94,9 @@ 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
|
||||
|
||||
// supported projects
|
||||
public ArrayList<ProjectInfo> supportedProjects;
|
||||
|
||||
public ClientStatus(Context ctx) {
|
||||
this.ctx = ctx;
|
||||
|
||||
|
@ -190,6 +194,10 @@ public class ClientStatus {
|
|||
this.prefs = prefs;
|
||||
}
|
||||
|
||||
public synchronized ArrayList<ProjectInfo> getSupprtedProjects () {
|
||||
return supportedProjects;
|
||||
}
|
||||
|
||||
public synchronized CcStatus getClientStatus() {
|
||||
if(results == null) { //check in case monitor is not set up yet (e.g. while logging in)
|
||||
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
|
||||
GlobalPreferences clientPrefs = rpc.getGlobalPrefsWorkingStruct();
|
||||
Monitor.getClientStatus().setPrefs(clientPrefs);
|
||||
// read supported projects
|
||||
readAndroidProjectsList();
|
||||
}
|
||||
|
||||
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
|
||||
if (clientStatus == null) {
|
||||
Log.d(TAG,"WARNING: clientStatus not yet initialized");
|
||||
|
@ -465,7 +487,6 @@ public class Monitor extends Service {
|
|||
return appPrefs;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* returns this class, allows clients to access this service's functions and attributes.
|
||||
*/
|
||||
|
@ -661,20 +682,6 @@ public class Monitor extends Service {
|
|||
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) {
|
||||
ProjectConfig config = null;
|
||||
|
||||
|
|
Loading…
Reference in New Issue