diff --git a/emailcommon/src/com/android/emailcommon/provider/Account.aidl b/emailcommon/src/com/android/emailcommon/provider/Account.aidl new file mode 100644 index 000000000..06bac3447 --- /dev/null +++ b/emailcommon/src/com/android/emailcommon/provider/Account.aidl @@ -0,0 +1,18 @@ +/* Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.emailcommon.provider; + +parcelable Account; \ No newline at end of file diff --git a/emailcommon/src/com/android/emailcommon/service/EmailServiceProxy.java b/emailcommon/src/com/android/emailcommon/service/EmailServiceProxy.java index 2ec8d6b90..36d3b77e9 100644 --- a/emailcommon/src/com/android/emailcommon/service/EmailServiceProxy.java +++ b/emailcommon/src/com/android/emailcommon/service/EmailServiceProxy.java @@ -27,6 +27,7 @@ import com.android.emailcommon.Api; import com.android.emailcommon.Device; import com.android.emailcommon.TempDirectory; import com.android.emailcommon.mail.MessagingException; +import com.android.emailcommon.provider.Account; import com.android.emailcommon.provider.HostAuth; import com.android.emailcommon.provider.Policy; @@ -459,12 +460,12 @@ public class EmailServiceProxy extends ServiceProxy implements IEmailService { } @Override - public int getCapabilities(final long accountId) throws RemoteException { + public int getCapabilities(final Account acct) throws RemoteException { setTask(new ProxyTask() { @Override public void run() throws RemoteException{ if (mCallback != null) mService.setCallback(mCallback); - mReturn = mService.getCapabilities(accountId); + mReturn = mService.getCapabilities(acct); } }, "getCapabilities"); waitForCompletion(); diff --git a/emailcommon/src/com/android/emailcommon/service/IEmailService.aidl b/emailcommon/src/com/android/emailcommon/service/IEmailService.aidl index ad21ecdee..5c48c0fb1 100644 --- a/emailcommon/src/com/android/emailcommon/service/IEmailService.aidl +++ b/emailcommon/src/com/android/emailcommon/service/IEmailService.aidl @@ -18,6 +18,7 @@ package com.android.emailcommon.service; import com.android.emailcommon.provider.HostAuth; +import com.android.emailcommon.provider.Account; import com.android.emailcommon.service.IEmailServiceCallback; import com.android.emailcommon.service.SearchParams; import android.os.Bundle; @@ -61,5 +62,5 @@ interface IEmailService { void sendMail(long accountId); // API level 3 - int getCapabilities(long accountId); + int getCapabilities(in Account acct); } diff --git a/emailcommon/src/com/android/emailcommon/service/ServiceProxy.java b/emailcommon/src/com/android/emailcommon/service/ServiceProxy.java index 8e3bcffb8..4d8b81217 100644 --- a/emailcommon/src/com/android/emailcommon/service/ServiceProxy.java +++ b/emailcommon/src/com/android/emailcommon/service/ServiceProxy.java @@ -71,7 +71,8 @@ public abstract class ServiceProxy { public void onServiceConnected(ComponentName name, IBinder binder) { onConnected(binder); if (DEBUG_PROXY) { - Log.v(mTag, "Connected: " + name.getShortClassName()); + Log.v(mTag, "Connected: " + name.getShortClassName() + " at " + + (System.currentTimeMillis() - mStartTime) + "ms"); } // Run our task on a new thread new Thread(new Runnable() { @@ -86,7 +87,8 @@ public abstract class ServiceProxy { public void onServiceDisconnected(ComponentName name) { if (DEBUG_PROXY) { - Log.v(mTag, "Disconnected: " + name.getShortClassName()); + Log.v(mTag, "Disconnected: " + name.getShortClassName() + " at " + + (System.currentTimeMillis() - mStartTime) + "ms"); } } } @@ -169,8 +171,9 @@ public abstract class ServiceProxy { // Can be ignored safely } if (DEBUG_PROXY) { - Log.v(mTag, "Wait for " + mName + " finished in " + + Log.v(mTag, "Wait for " + mName + (mDead ? " finished in " : " timed out in ") + (System.currentTimeMillis() - time) + "ms"); + mDead = true; } } } diff --git a/imap2/src/com/android/imap2/Imap2SyncManager.java b/imap2/src/com/android/imap2/Imap2SyncManager.java index 62c25395c..2535475c6 100644 --- a/imap2/src/com/android/imap2/Imap2SyncManager.java +++ b/imap2/src/com/android/imap2/Imap2SyncManager.java @@ -16,24 +16,23 @@ package com.android.imap2; -import android.os.Bundle; -import android.os.Handler; -import android.os.IBinder; -import android.os.RemoteCallbackList; -import android.os.RemoteException; - import android.content.ContentResolver; import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.database.Cursor; +import android.os.Bundle; +import android.os.Handler; +import android.os.IBinder; +import android.os.RemoteCallbackList; +import android.os.RemoteException; import com.android.emailcommon.Api; +import com.android.emailcommon.provider.Account; import com.android.emailcommon.provider.EmailContent; import com.android.emailcommon.provider.EmailContent.Attachment; import com.android.emailcommon.provider.EmailContent.MailboxColumns; -import com.android.emailcommon.provider.Account; import com.android.emailcommon.provider.HostAuth; import com.android.emailcommon.provider.Mailbox; import com.android.emailcommon.provider.ProviderUnavailableException; @@ -194,7 +193,7 @@ public class Imap2SyncManager extends SyncManager { } @Override - public int getCapabilities(long accountId) throws RemoteException { + public int getCapabilities(Account acct) throws RemoteException { return AccountCapabilities.SYNCABLE_FOLDERS | //AccountCapabilities.FOLDER_SERVER_SEARCH | AccountCapabilities.UNDO; diff --git a/src/com/android/email/provider/EmailProvider.java b/src/com/android/email/provider/EmailProvider.java index e87207f12..528a63486 100644 --- a/src/com/android/email/provider/EmailProvider.java +++ b/src/com/android/email/provider/EmailProvider.java @@ -2665,6 +2665,21 @@ outer: .appendQueryParameter("account", account).build().toString(); } + private int getCapabilities(Context context, long accountId) { + EmailServiceProxy service = EmailServiceUtils.getServiceForAccount(context, + mServiceCallback, accountId); + int capabilities = 0; + try { + service.setTimeout(10); + Account acct = Account.restoreAccountWithId(context, accountId); + if (acct == null) return 0; + capabilities = service.getCapabilities(acct); + } catch (RemoteException e) { + // Nothing to do + } + return capabilities; + } + /** * Generate a "single account" SQLite query, given a projection from UnifiedEmail * @@ -2674,19 +2689,13 @@ outer: private String genQueryAccount(String[] uiProjection, String id) { final ContentValues values = new ContentValues(); final long accountId = Long.parseLong(id); + final Context context = getContext(); final Set projectionColumns = ImmutableSet.copyOf(uiProjection); if (projectionColumns.contains(UIProvider.AccountColumns.CAPABILITIES)) { // Get account capabilities from the service - EmailServiceProxy service = EmailServiceUtils.getServiceForAccount(getContext(), - mServiceCallback, accountId); - int capabilities = 0; - try { - capabilities = service.getCapabilities(accountId); - } catch (RemoteException e) { - } - values.put(UIProvider.AccountColumns.CAPABILITIES, capabilities); + values.put(UIProvider.AccountColumns.CAPABILITIES, getCapabilities(context, accountId)); } if (projectionColumns.contains(UIProvider.AccountColumns.SETTINGS_INTENT_URI)) { values.put(UIProvider.AccountColumns.SETTINGS_INTENT_URI, @@ -2729,7 +2738,6 @@ outer: textZoomToUiValue(textZoom)); } // Set default inbox, if we've got an inbox; otherwise, say initial sync needed - final Context context = getContext(); long mailboxId = Mailbox.findMailboxOfType(context, accountId, Mailbox.TYPE_INBOX); if (projectionColumns.contains(UIProvider.AccountColumns.SettingsColumns.DEFAULT_INBOX) && mailboxId != Mailbox.NO_MAILBOX) { diff --git a/src/com/android/email/service/EmailServiceUtils.java b/src/com/android/email/service/EmailServiceUtils.java index 3fb3e6b85..e0d857ab0 100644 --- a/src/com/android/email/service/EmailServiceUtils.java +++ b/src/com/android/email/service/EmailServiceUtils.java @@ -372,7 +372,7 @@ public class EmailServiceUtils { } @Override - public int getCapabilities(long accountId) throws RemoteException { + public int getCapabilities(Account acct) throws RemoteException { return 0; } } diff --git a/src/com/android/email/service/ImapService.java b/src/com/android/email/service/ImapService.java index 1debd4104..a08936f69 100644 --- a/src/com/android/email/service/ImapService.java +++ b/src/com/android/email/service/ImapService.java @@ -136,7 +136,7 @@ public class ImapService extends Service { } @Override - public int getCapabilities(long accountId) throws RemoteException { + public int getCapabilities(Account acct) throws RemoteException { return AccountCapabilities.SYNCABLE_FOLDERS | AccountCapabilities.FOLDER_SERVER_SEARCH | AccountCapabilities.UNDO; diff --git a/src/com/android/email/service/Pop3Service.java b/src/com/android/email/service/Pop3Service.java index 404ef8779..d8fc206ba 100644 --- a/src/com/android/email/service/Pop3Service.java +++ b/src/com/android/email/service/Pop3Service.java @@ -184,7 +184,7 @@ public class Pop3Service extends Service { } @Override - public int getCapabilities(long accountId) throws RemoteException { + public int getCapabilities(Account acct) throws RemoteException { return AccountCapabilities.UNDO; } };