1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-23 18:02:15 -05:00

Removed some doc annotations from chrisk's fix for the service stopping

issue (2777)
This commit is contained in:
Jesse Vincent 2011-09-04 16:05:13 -04:00
parent 7cd6334c64
commit 8223e4d4bf
2 changed files with 17 additions and 31 deletions

View File

@ -65,14 +65,12 @@ public abstract class CoreService extends Service {
private volatile boolean mShutdown = false; // CK:A:Seems to be used only when the service is "officially" shutdown to make sure that an exception raise because of the shutdown gets ignored.
/**
* CK:BF:2777
* Controls the auto-shutdown mechanism of the service. The default service life-cycle model is that the service should run
* only as long as a task is running. If a service should behave differently, disable auto-shutdown.
*/
private boolean mAutoShutdown = true;
/**
* CK:BF:2777
* This variable is part of the auto-shutdown feature and determines whether the service has to be shutdown at the
* end of the onStart() method or not.
*/
@ -88,7 +86,6 @@ public abstract class CoreService extends Service {
}
/**
* CK:DocAdded,Refactored without change of logic
* Adds an existing WakeLock identified by it's WakeLock-ID to the specified Intent.
* @param i
* @param wakeLockId
@ -103,7 +100,6 @@ public abstract class CoreService extends Service {
}
/**
* CK:DocAdded
* Adds a new WakeLock to the intent.
* This will add the WakeLock to the central WakeLock registry managed by this class.
* @param context Required to be able to create a new wake-lock.
@ -116,7 +112,6 @@ public abstract class CoreService extends Service {
}
/**
* CK:Added as result of refactoring; logic is unchanged
* Register WakeLock and returns its registry-entry-ID
* @param wakeLock
* @return
@ -129,7 +124,6 @@ public abstract class CoreService extends Service {
}
/**
* CK:Added as result of refactoring; logic is unchanged
* Acquires a WakeLock in a K9 standard way
* @param context
* @return
@ -145,7 +139,7 @@ public abstract class CoreService extends Service {
@Override
public void onStart(Intent intent, int startId) {
// CK:DocAdded:deprecated method but still used for backwards compatibility with Android version <2.0
// deprecated method but still used for backwards compatibility with Android version <2.0
// CK:DocAdded: Manage wake-locks, especially, release any wake-locks held so far and define a new "local" wake lock.
// Also, because we create a new wakelock, we re-initialize the wakelock timeout and give
@ -171,7 +165,7 @@ public abstract class CoreService extends Service {
}
}
// CK:DocAdded: Run the actual start-code of the service
// Run the actual start-code of the service
mImmediateShutdown = true;
try {
super.onStart(intent, startId);
@ -188,11 +182,11 @@ public abstract class CoreService extends Service {
* @param runner
* @param wakeLockTime
* @param startId
* @return CK:BF:2777: returns whether service-shutdown will actually happen after the task has been executed (or has already been done).
* @return returns whether service-shutdown will actually happen after the task has been executed (or has already been done).
*/
public boolean execute(Context context, final Runnable runner, int wakeLockTime, final Integer startId) {
boolean serviceShutdownScheduled = false; // CK:BF:2777
boolean serviceShutdownScheduled = false;
final TracingWakeLock wakeLock = acquireWakeLock(context,"CoreService execute",wakeLockTime);
final boolean autoShutdown = mAutoShutdown;
@ -207,13 +201,13 @@ public abstract class CoreService extends Service {
MessagingController.getInstance(getApplication()).systemStatusChanged();
}
} finally {
try { // CK:BF:2777:Making absolutely sure the service stopping command will be executed
try { // Making absolutely sure the service stopping command will be executed
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "CoreService (" + className + ") completed Runnable " + runner.hashCode() + " with startId " + startId);
wakeLock.release();
} finally {
if (autoShutdown && startId != null) {
stopSelf(startId); // CK:BF:2777<-- this is what is meant with "serviceShutdownScheduled"; execution of this line assures proper shutdown of the service once finished
stopSelf(startId); // <-- this is what is meant with "serviceShutdownScheduled"; execution of this line assures proper shutdown of the service once finished
}
}
}
@ -224,14 +218,14 @@ public abstract class CoreService extends Service {
Log.e(K9.LOG_TAG, "CoreService.execute (" + className + ") called with no threadPool available; running Runnable " + runner.hashCode() + " in calling thread", new Throwable());
synchronized (this) {
myRunner.run();
serviceShutdownScheduled = startId != null; // CK:BF:2777; In this case it's not actually scheduled, it's already done, but that should never happen anyway
serviceShutdownScheduled = startId != null; // In this case it's not actually scheduled, it's already done, but that should never happen anyway
}
} else {
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "CoreService (" + className + ") queueing Runnable " + runner.hashCode() + " with startId " + startId);
try {
threadPool.execute(myRunner);
serviceShutdownScheduled = startId != null; // CK:BF:2777
serviceShutdownScheduled = startId != null;
} catch (RejectedExecutionException e) {
if (!mShutdown) {
throw e;
@ -239,8 +233,8 @@ public abstract class CoreService extends Service {
Log.i(K9.LOG_TAG, "CoreService: " + className + " is shutting down, ignoring rejected execution exception: " + e.getMessage());
}
}
mImmediateShutdown = !serviceShutdownScheduled; // CK:BF:2777
return serviceShutdownScheduled; // CK:BF:2777
mImmediateShutdown = !serviceShutdownScheduled;
return serviceShutdownScheduled;
}
/**
@ -276,7 +270,6 @@ public abstract class CoreService extends Service {
}
/**
* CK:BF:2777
* @return True if auto-shutdown is enabled
*/
protected boolean isAutoShutdown() {
@ -284,7 +277,6 @@ public abstract class CoreService extends Service {
}
/**
* CK:BF:2777
* Enable of disable auto-shutdown (enabled by default).
* See {@#mAutoShutdown} for more information.
* @param autoShutdown

View File

@ -21,12 +21,6 @@ import com.fsck.k9.controller.MessagingController;
import com.fsck.k9.helper.AutoSyncHelper;
import com.fsck.k9.mail.Pusher;
/**
* Bug-fix 2777:
* MailService was not properly shutting down when not needed anymore.
* Flawed shutdown logic has been removed and consolidated into CoreService
* as the auto-shutdown feature.
*/
public class MailService extends CoreService {
private static final String ACTION_CHECK_MAIL = "com.fsck.k9.intent.action.MAIL_SERVICE_WAKEUP";
private static final String ACTION_RESET = "com.fsck.k9.intent.action.MAIL_SERVICE_RESET";
@ -144,7 +138,7 @@ public class MailService extends CoreService {
if (hasConnectivity && doBackground) {
PollService.startService(this);
}
reschedulePoll(hasConnectivity, doBackground, startId, false); // CK:BF:2777
reschedulePoll(hasConnectivity, doBackground, startId, false);
} else if (ACTION_CANCEL.equals(intent.getAction())) {
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "***** MailService *****: cancel");
@ -152,22 +146,22 @@ public class MailService extends CoreService {
} else if (ACTION_RESET.equals(intent.getAction())) {
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "***** MailService *****: reschedule");
rescheduleAll(hasConnectivity, doBackground, startId); // CK:BF:2777
rescheduleAll(hasConnectivity, doBackground, startId);
} else if (ACTION_RESTART_PUSHERS.equals(intent.getAction())) {
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "***** MailService *****: restarting pushers");
reschedulePushers(hasConnectivity, doBackground, startId); // CK:BF:2777
reschedulePushers(hasConnectivity, doBackground, startId);
} else if (ACTION_RESCHEDULE_POLL.equals(intent.getAction())) {
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "***** MailService *****: rescheduling poll");
reschedulePoll(hasConnectivity, doBackground, startId, true); // CK:BF:2777
reschedulePoll(hasConnectivity, doBackground, startId, true);
} else if (ACTION_REFRESH_PUSHERS.equals(intent.getAction())) {
if (hasConnectivity && doBackground) {
refreshPushers(null);
schedulePushers(startId); // CK:BF:2777
schedulePushers(startId);
}
} else if (CONNECTIVITY_CHANGE.equals(intent.getAction())) {
rescheduleAll(hasConnectivity, doBackground, startId); // CK:BF:2777
rescheduleAll(hasConnectivity, doBackground, startId);
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Got connectivity action with hasConnectivity = " + hasConnectivity + ", doBackground = " + doBackground);
} else if (CANCEL_CONNECTIVITY_NOTICE.equals(intent.getAction())) {
@ -184,7 +178,7 @@ public class MailService extends CoreService {
private void rescheduleAll(final boolean hasConnectivity, final boolean doBackground, final Integer startId) {
reschedulePoll(hasConnectivity, doBackground, null, true);
reschedulePushers(hasConnectivity, doBackground, startId); // CK:BF:2777
reschedulePushers(hasConnectivity, doBackground, startId);
}