Duty on background

pull/194/merge
M66B 3 years ago
parent 3453080f7f
commit 203e975ce6

@ -3559,7 +3559,7 @@ class Core {
} finally { } finally {
// Free memory // Free memory
isub[j] = null; isub[j] = null;
dc.stop(); dc.stop(state.getForeground());
} }
} }
} }
@ -3647,7 +3647,7 @@ class Core {
} finally { } finally {
// Free memory // Free memory
isub[j] = null; isub[j] = null;
dc.stop(); dc.stop(state.getForeground());
} }
} }
} }
@ -5625,6 +5625,7 @@ class Core {
private Thread thread = new Thread(); private Thread thread = new Thread();
private Semaphore semaphore = new Semaphore(0); private Semaphore semaphore = new Semaphore(0);
private boolean running = true; private boolean running = true;
private boolean foreground = false;
private boolean recoverable = true; private boolean recoverable = true;
private Throwable unrecoverable = null; private Throwable unrecoverable = null;
private Long lastActivity = null; private Long lastActivity = null;
@ -5809,6 +5810,14 @@ class Core {
return serial; return serial;
} }
void setForeground(boolean value) {
this.foreground = value;
}
boolean getForeground() {
return this.foreground;
}
@NonNull @NonNull
@Override @Override
public String toString() { public String toString() {

@ -48,7 +48,7 @@ public class DutyCycle {
start = new Date().getTime(); start = new Date().getTime();
} }
public void stop() { public void stop(boolean foreground) {
long end = new Date().getTime(); long end = new Date().getTime();
if (last != null) if (last != null)
@ -59,8 +59,9 @@ public class DutyCycle {
if (busy + idle > interval) { if (busy + idle > interval) {
long wait = (duration - idle); long wait = (duration - idle);
Log.i(name + " busy=" + busy + " idle=" + idle + " wait=" + wait); Log.i(name + " busy=" + busy + " idle=" + idle +
if (wait > 0) { " wait=" + wait + " foreground=" + foreground);
if (wait > 0 && foreground) {
try { try {
Thread.sleep(wait); Thread.sleep(wait);
} catch (InterruptedException ex) { } catch (InterruptedException ex) {

@ -1193,6 +1193,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
private void onState(Intent intent) { private void onState(Intent intent) {
foreground = intent.getBooleanExtra("foreground", false); foreground = intent.getBooleanExtra("foreground", false);
for (Core.State state : coreStates.values())
state.setForeground(foreground);
} }
private void onPoll(Intent intent) { private void onPoll(Intent intent) {
@ -1992,7 +1994,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
iservice, ifolder, iservice, ifolder,
state, serial); state, serial);
} finally { } finally {
dc.stop(); dc.stop(state.getForeground());
} }
} catch (Throwable ex) { } catch (Throwable ex) {

Loading…
Cancel
Save