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,52 +1765,47 @@ 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) {
|
||||||
|
log("!!! EAS ExchangeService, onStartCommand");
|
||||||
|
Utility.runAsync(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
synchronized (sSyncLock) {
|
synchronized (sSyncLock) {
|
||||||
alwaysLog("!!! EAS ExchangeService, onStartCommand");
|
|
||||||
// Restore accounts, if it has not happened already
|
// Restore accounts, if it has not happened already
|
||||||
AccountBackupRestore.restoreAccountsIfNeeded(this);
|
AccountBackupRestore.restoreAccountsIfNeeded(ExchangeService.this);
|
||||||
|
// 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);
|
||||||
maybeStartExchangeServiceThread();
|
maybeStartExchangeServiceThread();
|
||||||
if (sServiceThread == null) {
|
if (sServiceThread == null) {
|
||||||
alwaysLog("!!! EAS ExchangeService, stopping self");
|
log("!!! EAS ExchangeService, stopping self");
|
||||||
stopSelf();
|
stopSelf();
|
||||||
} else if (sStop) {
|
} else if (sStop) {
|
||||||
// If we were in the middle of trying to stop, attempt a restart in 5 seconds
|
// If we were in the middle of trying to stop, attempt a restart in 5 secs
|
||||||
setAlarm(EXCHANGE_SERVICE_MAILBOX_ID, 5*SECONDS);
|
setAlarm(EXCHANGE_SERVICE_MAILBOX_ID, 5*SECONDS);
|
||||||
}
|
}
|
||||||
// If we're running, we want the download service running
|
|
||||||
return Service.START_STICKY;
|
|
||||||
}
|
}
|
||||||
|
}});
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void maybeStartExchangeServiceThread() {
|
void maybeStartExchangeServiceThread() {
|
||||||
// Start our thread...
|
// Start our thread...
|
||||||
@ -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