Skip to content
forked from BOINC/boinc

Commit

Permalink
[Android] Make BOINC always run foreground service
Browse files Browse the repository at this point in the history
On the latest Android SDKs there are a lot of restrictions for background processes.
So if the service is run in background, it could be killed too early and BOINC will not start.
Removed setting to show notification when running only because now it makes no sense since Notification should be shown always when foreground service is running.

Signed-off-by: Vitalii Koshura <[email protected]>
  • Loading branch information
AenBleidd committed Dec 9, 2019
1 parent 3fdf87d commit 61a2c3a
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,9 @@ List<ImageWrapper> getSlideshowForProject(in String url); // clientStatus.getS
////// app preference ////////////////////////////////////////////
void setAutostart(in boolean isAutoStart); // Monitor.getAppPrefs().setAutostart(boolean);
void setShowNotificationForNotices(in boolean isShow); // Monitor.getAppPrefs().setShowNotificationForNotices(boolean);
void setShowNotificationDuringSuspend(in boolean isShow); // Monitor.getAppPrefs().setShowNotificationDuringSuspend(boolean);
boolean getShowAdvanced(); // Monitor.getAppPrefs().getShowAdvanced();
boolean getAutostart(); // Monitor.getAppPrefs().getAutostart();
boolean getShowNotificationForNotices(); // Monitor.getAppPrefs().getShowNotificationForNotices();
boolean getShowNotificationDuringSuspend(); // Monitor.getAppPrefs().getShowNotificationDuringSuspend();
int getLogLevel(); // Monitor.getAppPrefs().getLogLevel();
void setLogLevel(in int level); // Monitor.getAppPrefs().setLogLevel(int);
void setPowerSourceAc(in boolean src); // Monitor.getAppPrefs().setPowerSourceAc(boolean);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ private void populateLayout() throws RemoteException {
data.add(new PrefsListItemWrapper(getActivity(), R.string.prefs_category_general, true));
data.add(new PrefsListItemWrapperBool(getActivity(), R.string.prefs_autostart_header, R.string.prefs_category_general, BOINCActivity.monitor.getAutostart()));
data.add(new PrefsListItemWrapperBool(getActivity(), R.string.prefs_show_notification_notices_header, R.string.prefs_category_general, BOINCActivity.monitor.getShowNotificationForNotices()));
data.add(new PrefsListItemWrapperBool(getActivity(), R.string.prefs_show_notification_suspended_header, R.string.prefs_category_general, BOINCActivity.monitor.getShowNotificationDuringSuspend()));
data.add(new PrefsListItemWrapperBool(getActivity(), R.string.prefs_show_advanced_header, R.string.prefs_category_general, BOINCActivity.monitor.getShowAdvanced()));
if(!stationaryDeviceMode) {
data.add(new PrefsListItemWrapperBool(getActivity(), R.string.prefs_suspend_when_screen_on, R.string.prefs_category_general, BOINCActivity.monitor.getSuspendWhenScreenOn()));
Expand Down Expand Up @@ -697,11 +696,6 @@ public void onClick(View view) {
updateBoolPreference(ID, isSet);
updateLayout();
break;
case R.string.prefs_show_notification_suspended_header: //app pref
BOINCActivity.monitor.setShowNotificationDuringSuspend(isSet);
updateBoolPreference(ID, isSet);
updateLayout();
break;
case R.string.prefs_show_advanced_header: //app pref
BOINCActivity.monitor.setShowAdvanced(isSet);
// reload complete layout to remove/add advanced elements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class AppPreferences {

private Boolean autostart;
private Boolean showNotificationForNotices;
private Boolean showNotificationDuringSuspend;
private Boolean showAdvanced;
private Integer logLevel;
private Boolean powerSourceAc;
Expand All @@ -49,8 +48,6 @@ public void readPrefs(Context ctx) {
autostart = prefs.getBoolean("autostart", ctx.getResources().getBoolean(R.bool.prefs_default_autostart));
showNotificationForNotices =
prefs.getBoolean("showNotification", ctx.getResources().getBoolean(R.bool.prefs_default_notification_notices));
showNotificationDuringSuspend =
prefs.getBoolean("showNotificationDuringSuspend", ctx.getResources().getBoolean(R.bool.prefs_default_notification_suspended));
showAdvanced = prefs.getBoolean("showAdvanced", ctx.getResources().getBoolean(R.bool.prefs_default_advanced));
logLevel = prefs.getInt("logLevel", ctx.getResources().getInteger(R.integer.prefs_default_loglevel));
Logging.setLogLevel(logLevel);
Expand Down Expand Up @@ -93,17 +90,6 @@ public Boolean getShowNotificationForNotices() {
return this.showNotificationForNotices;
}

public void setShowNotificationDuringSuspend(Boolean ns) {
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("showNotificationDuringSuspend", ns);
editor.apply();
this.showNotificationDuringSuspend = ns;
}

public Boolean getShowNotificationDuringSuspend() {
return this.showNotificationDuringSuspend;
}

public void setShowAdvanced(Boolean as) {
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("showAdvanced", as);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,9 @@ public void update(ClientStatus updatedStatus, Monitor service, Boolean active)
return;
}

// stop service foreground, if not active anymore
if(!active && foreground) {
setForegroundState(service, false);
}

// if not active, check preference whether to show notification during suspension
if(!active && !Monitor.getAppPrefs().getShowNotificationDuringSuspend()) {
// cancel notification if necessary
if(notificationShown) {
Log.d(Logging.TAG, "ClientNotification: cancel suspension notification due to preference.");
nm.cancel(notificationId);
notificationShown = false;
}
return;
}

//check if active tasks have changed to force update
Boolean activeTasksChanged = false;
if(updatedStatus.computingStatus == ClientStatus.COMPUTING_STATUS_COMPUTING) {
if(active && updatedStatus.computingStatus == ClientStatus.COMPUTING_STATUS_COMPUTING) {
ArrayList<Result> activeTasks = updatedStatus.getExecutingTasks();
if(activeTasks.size() != mOldActiveTasks.size()) {
activeTasksChanged = true;
Expand All @@ -108,6 +92,10 @@ public void update(ClientStatus updatedStatus, Monitor service, Boolean active)
mOldActiveTasks = activeTasks;
}
}
else if (!mOldActiveTasks.isEmpty()) {
mOldActiveTasks.clear();
activeTasksChanged = true;
}

// update notification, only
// if it hasn't been shown before, or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1388,17 +1388,6 @@ public void cancelNoticeNotification() throws RemoteException {
NoticeNotification.getInstance(getApplicationContext()).cancelNotification();
}

@Override
public void setShowNotificationDuringSuspend(boolean isShow) throws RemoteException {
Monitor.getAppPrefs().setShowNotificationDuringSuspend(isShow);

}

@Override
public boolean getShowNotificationDuringSuspend() throws RemoteException {
return Monitor.getAppPrefs().getShowNotificationDuringSuspend();
}

@Override
public boolean runBenchmarks() throws RemoteException {
return clientInterface.runBenchmarks();
Expand Down

0 comments on commit 61a2c3a

Please sign in to comment.