Move onStartCommand processing to worker thread
* Also, reduce service logging Bug: 3133763 Change-Id: Icc09ddb5966b78350b4485e52a3d8e1f92d9c576
This commit is contained in:
parent
d23c361ff1
commit
6f2c724f2f
@ -1197,7 +1197,7 @@ public class ExchangeService extends Service implements Runnable {
|
|||||||
|
|
||||||
static private synchronized void shutdownConnectionManager() {
|
static private synchronized void shutdownConnectionManager() {
|
||||||
if (sClientConnectionManager != null) {
|
if (sClientConnectionManager != null) {
|
||||||
alwaysLog("Shutting down ClientConnectionManager");
|
log("Shutting down ClientConnectionManager");
|
||||||
sClientConnectionManager.shutdown();
|
sClientConnectionManager.shutdown();
|
||||||
sClientConnectionManagerShutdownCount++;
|
sClientConnectionManagerShutdownCount++;
|
||||||
sClientConnectionManager = null;
|
sClientConnectionManager = null;
|
||||||
@ -1753,7 +1753,7 @@ public class ExchangeService extends Service implements Runnable {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
synchronized (sSyncLock) {
|
synchronized (sSyncLock) {
|
||||||
alwaysLog("!!! EAS ExchangeService, onCreate");
|
log("!!! EAS ExchangeService, onCreate");
|
||||||
if (sStop) {
|
if (sStop) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1765,49 +1765,44 @@ public class ExchangeService extends Service implements Runnable {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Finally, run some setup activities off the UI thread
|
|
||||||
Utility.runAsync(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
// Run the reconciler and clean up any mismatched accounts - if we weren't
|
|
||||||
// running when accounts were deleted, it won't have been called.
|
|
||||||
runAccountReconcilerSync(ExchangeService.this);
|
|
||||||
// Update other services depending on final account configuration
|
|
||||||
Email.setServicesEnabledSync(ExchangeService.this);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
synchronized (sSyncLock) {
|
log("!!! EAS ExchangeService, onStartCommand");
|
||||||
alwaysLog("!!! EAS ExchangeService, onStartCommand");
|
Utility.runAsync(new Runnable() {
|
||||||
// Restore accounts, if it has not happened already
|
@Override
|
||||||
AccountBackupRestore.restoreAccountsIfNeeded(this);
|
public void run() {
|
||||||
maybeStartExchangeServiceThread();
|
synchronized (sSyncLock) {
|
||||||
if (sServiceThread == null) {
|
// Restore accounts, if it has not happened already
|
||||||
alwaysLog("!!! EAS ExchangeService, stopping self");
|
AccountBackupRestore.restoreAccountsIfNeeded(ExchangeService.this);
|
||||||
stopSelf();
|
// Run the reconciler and clean up any mismatched accounts - if we weren't
|
||||||
} else if (sStop) {
|
// running when accounts were deleted, it won't have been called.
|
||||||
// If we were in the middle of trying to stop, attempt a restart in 5 seconds
|
runAccountReconcilerSync(ExchangeService.this);
|
||||||
setAlarm(EXCHANGE_SERVICE_MAILBOX_ID, 5*SECONDS);
|
// Update other services depending on final account configuration
|
||||||
}
|
Email.setServicesEnabledSync(ExchangeService.this);
|
||||||
// If we're running, we want the download service running
|
maybeStartExchangeServiceThread();
|
||||||
return Service.START_STICKY;
|
if (sServiceThread == null) {
|
||||||
}
|
log("!!! EAS ExchangeService, stopping self");
|
||||||
|
stopSelf();
|
||||||
|
} else if (sStop) {
|
||||||
|
// If we were in the middle of trying to stop, attempt a restart in 5 secs
|
||||||
|
setAlarm(EXCHANGE_SERVICE_MAILBOX_ID, 5*SECONDS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}});
|
||||||
|
return Service.START_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
|
log("!!! EAS ExchangeService, onDestroy");
|
||||||
synchronized(sSyncLock) {
|
synchronized(sSyncLock) {
|
||||||
alwaysLog("!!! EAS ExchangeService, onDestroy");
|
|
||||||
// Stop the sync manager thread and return
|
// Stop the sync manager thread and return
|
||||||
synchronized (sSyncLock) {
|
if (sServiceThread != null) {
|
||||||
if (sServiceThread != null) {
|
sStop = true;
|
||||||
sStop = true;
|
sServiceThread.interrupt();
|
||||||
sServiceThread.interrupt();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1834,14 +1829,14 @@ public class ExchangeService extends Service implements Runnable {
|
|||||||
ExchangeService exchangeService = INSTANCE;
|
ExchangeService exchangeService = INSTANCE;
|
||||||
if (exchangeService == null) return;
|
if (exchangeService == null) return;
|
||||||
if (sServiceThread == null) {
|
if (sServiceThread == null) {
|
||||||
alwaysLog("!!! checkExchangeServiceServiceRunning; starting service...");
|
log("!!! checkExchangeServiceServiceRunning; starting service...");
|
||||||
exchangeService.startService(new Intent(exchangeService, ExchangeService.class));
|
exchangeService.startService(new Intent(exchangeService, ExchangeService.class));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
sStop = false;
|
sStop = false;
|
||||||
alwaysLog("!!! ExchangeService thread running");
|
alwaysLog("ExchangeService thread running");
|
||||||
// If we're really debugging, turn on all logging
|
// If we're really debugging, turn on all logging
|
||||||
if (Eas.DEBUG) {
|
if (Eas.DEBUG) {
|
||||||
Eas.USER_LOG = true;
|
Eas.USER_LOG = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user