1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-11 12:05:06 -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. 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 * 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. * only as long as a task is running. If a service should behave differently, disable auto-shutdown.
*/ */
private boolean mAutoShutdown = true; 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 * 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. * 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. * Adds an existing WakeLock identified by it's WakeLock-ID to the specified Intent.
* @param i * @param i
* @param wakeLockId * @param wakeLockId
@ -103,7 +100,6 @@ public abstract class CoreService extends Service {
} }
/** /**
* CK:DocAdded
* Adds a new WakeLock to the intent. * Adds a new WakeLock to the intent.
* This will add the WakeLock to the central WakeLock registry managed by this class. * 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. * @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 * Register WakeLock and returns its registry-entry-ID
* @param wakeLock * @param wakeLock
* @return * @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 * Acquires a WakeLock in a K9 standard way
* @param context * @param context
* @return * @return
@ -145,7 +139,7 @@ public abstract class CoreService extends Service {
@Override @Override
public void onStart(Intent intent, int startId) { 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. // 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 // 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; mImmediateShutdown = true;
try { try {
super.onStart(intent, startId); super.onStart(intent, startId);
@ -188,11 +182,11 @@ public abstract class CoreService extends Service {
* @param runner * @param runner
* @param wakeLockTime * @param wakeLockTime
* @param startId * @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) { 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 TracingWakeLock wakeLock = acquireWakeLock(context,"CoreService execute",wakeLockTime);
final boolean autoShutdown = mAutoShutdown; final boolean autoShutdown = mAutoShutdown;
@ -207,13 +201,13 @@ public abstract class CoreService extends Service {
MessagingController.getInstance(getApplication()).systemStatusChanged(); MessagingController.getInstance(getApplication()).systemStatusChanged();
} }
} finally { } 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) if (K9.DEBUG)
Log.d(K9.LOG_TAG, "CoreService (" + className + ") completed Runnable " + runner.hashCode() + " with startId " + startId); Log.d(K9.LOG_TAG, "CoreService (" + className + ") completed Runnable " + runner.hashCode() + " with startId " + startId);
wakeLock.release(); wakeLock.release();
} finally { } finally {
if (autoShutdown && startId != null) { 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()); Log.e(K9.LOG_TAG, "CoreService.execute (" + className + ") called with no threadPool available; running Runnable " + runner.hashCode() + " in calling thread", new Throwable());
synchronized (this) { synchronized (this) {
myRunner.run(); 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 { } else {
if (K9.DEBUG) if (K9.DEBUG)
Log.d(K9.LOG_TAG, "CoreService (" + className + ") queueing Runnable " + runner.hashCode() + " with startId " + startId); Log.d(K9.LOG_TAG, "CoreService (" + className + ") queueing Runnable " + runner.hashCode() + " with startId " + startId);
try { try {
threadPool.execute(myRunner); threadPool.execute(myRunner);
serviceShutdownScheduled = startId != null; // CK:BF:2777 serviceShutdownScheduled = startId != null;
} catch (RejectedExecutionException e) { } catch (RejectedExecutionException e) {
if (!mShutdown) { if (!mShutdown) {
throw e; 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()); Log.i(K9.LOG_TAG, "CoreService: " + className + " is shutting down, ignoring rejected execution exception: " + e.getMessage());
} }
} }
mImmediateShutdown = !serviceShutdownScheduled; // CK:BF:2777 mImmediateShutdown = !serviceShutdownScheduled;
return serviceShutdownScheduled; // CK:BF:2777 return serviceShutdownScheduled;
} }
/** /**
@ -276,7 +270,6 @@ public abstract class CoreService extends Service {
} }
/** /**
* CK:BF:2777
* @return True if auto-shutdown is enabled * @return True if auto-shutdown is enabled
*/ */
protected boolean isAutoShutdown() { protected boolean isAutoShutdown() {
@ -284,7 +277,6 @@ public abstract class CoreService extends Service {
} }
/** /**
* CK:BF:2777
* Enable of disable auto-shutdown (enabled by default). * Enable of disable auto-shutdown (enabled by default).
* See {@#mAutoShutdown} for more information. * See {@#mAutoShutdown} for more information.
* @param autoShutdown * @param autoShutdown

View File

@ -21,12 +21,6 @@ import com.fsck.k9.controller.MessagingController;
import com.fsck.k9.helper.AutoSyncHelper; import com.fsck.k9.helper.AutoSyncHelper;
import com.fsck.k9.mail.Pusher; 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 { 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_CHECK_MAIL = "com.fsck.k9.intent.action.MAIL_SERVICE_WAKEUP";
private static final String ACTION_RESET = "com.fsck.k9.intent.action.MAIL_SERVICE_RESET"; 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) { if (hasConnectivity && doBackground) {
PollService.startService(this); PollService.startService(this);
} }
reschedulePoll(hasConnectivity, doBackground, startId, false); // CK:BF:2777 reschedulePoll(hasConnectivity, doBackground, startId, false);
} else if (ACTION_CANCEL.equals(intent.getAction())) { } else if (ACTION_CANCEL.equals(intent.getAction())) {
if (K9.DEBUG) if (K9.DEBUG)
Log.v(K9.LOG_TAG, "***** MailService *****: cancel"); Log.v(K9.LOG_TAG, "***** MailService *****: cancel");
@ -152,22 +146,22 @@ public class MailService extends CoreService {
} else if (ACTION_RESET.equals(intent.getAction())) { } else if (ACTION_RESET.equals(intent.getAction())) {
if (K9.DEBUG) if (K9.DEBUG)
Log.v(K9.LOG_TAG, "***** MailService *****: reschedule"); 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())) { } else if (ACTION_RESTART_PUSHERS.equals(intent.getAction())) {
if (K9.DEBUG) if (K9.DEBUG)
Log.v(K9.LOG_TAG, "***** MailService *****: restarting pushers"); 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())) { } else if (ACTION_RESCHEDULE_POLL.equals(intent.getAction())) {
if (K9.DEBUG) if (K9.DEBUG)
Log.v(K9.LOG_TAG, "***** MailService *****: rescheduling poll"); 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())) { } else if (ACTION_REFRESH_PUSHERS.equals(intent.getAction())) {
if (hasConnectivity && doBackground) { if (hasConnectivity && doBackground) {
refreshPushers(null); refreshPushers(null);
schedulePushers(startId); // CK:BF:2777 schedulePushers(startId);
} }
} else if (CONNECTIVITY_CHANGE.equals(intent.getAction())) { } else if (CONNECTIVITY_CHANGE.equals(intent.getAction())) {
rescheduleAll(hasConnectivity, doBackground, startId); // CK:BF:2777 rescheduleAll(hasConnectivity, doBackground, startId);
if (K9.DEBUG) if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Got connectivity action with hasConnectivity = " + hasConnectivity + ", doBackground = " + doBackground); Log.i(K9.LOG_TAG, "Got connectivity action with hasConnectivity = " + hasConnectivity + ", doBackground = " + doBackground);
} else if (CANCEL_CONNECTIVITY_NOTICE.equals(intent.getAction())) { } 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) { private void rescheduleAll(final boolean hasConnectivity, final boolean doBackground, final Integer startId) {
reschedulePoll(hasConnectivity, doBackground, null, true); reschedulePoll(hasConnectivity, doBackground, null, true);
reschedulePushers(hasConnectivity, doBackground, startId); // CK:BF:2777 reschedulePushers(hasConnectivity, doBackground, startId);
} }