EmailServiceProxy.java revision f419287f22ae44f25e1ba1f757ec33c7941bbfa8
10d4fc55861ed4393aa82f124f2865695ef564641Marc Blank/*
20d4fc55861ed4393aa82f124f2865695ef564641Marc Blank * Copyright (C) 2009 The Android Open Source Project
30d4fc55861ed4393aa82f124f2865695ef564641Marc Blank *
40d4fc55861ed4393aa82f124f2865695ef564641Marc Blank * Licensed under the Apache License, Version 2.0 (the "License");
50d4fc55861ed4393aa82f124f2865695ef564641Marc Blank * you may not use this file except in compliance with the License.
60d4fc55861ed4393aa82f124f2865695ef564641Marc Blank * You may obtain a copy of the License at
70d4fc55861ed4393aa82f124f2865695ef564641Marc Blank *
80d4fc55861ed4393aa82f124f2865695ef564641Marc Blank *      http://www.apache.org/licenses/LICENSE-2.0
90d4fc55861ed4393aa82f124f2865695ef564641Marc Blank *
100d4fc55861ed4393aa82f124f2865695ef564641Marc Blank * Unless required by applicable law or agreed to in writing, software
110d4fc55861ed4393aa82f124f2865695ef564641Marc Blank * distributed under the License is distributed on an "AS IS" BASIS,
120d4fc55861ed4393aa82f124f2865695ef564641Marc Blank * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130d4fc55861ed4393aa82f124f2865695ef564641Marc Blank * See the License for the specific language governing permissions and
140d4fc55861ed4393aa82f124f2865695ef564641Marc Blank * limitations under the License.
150d4fc55861ed4393aa82f124f2865695ef564641Marc Blank */
160d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
170d4fc55861ed4393aa82f124f2865695ef564641Marc Blankpackage com.android.emailcommon.service;
180d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
190d4fc55861ed4393aa82f124f2865695ef564641Marc Blankimport android.content.Context;
200d4fc55861ed4393aa82f124f2865695ef564641Marc Blankimport android.content.Intent;
210d4fc55861ed4393aa82f124f2865695ef564641Marc Blankimport android.os.Bundle;
220d4fc55861ed4393aa82f124f2865695ef564641Marc Blankimport android.os.IBinder;
230d4fc55861ed4393aa82f124f2865695ef564641Marc Blankimport android.os.RemoteException;
240d4fc55861ed4393aa82f124f2865695ef564641Marc Blankimport android.util.Log;
250d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
26f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blankimport com.android.emailcommon.Api;
27f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blankimport com.android.emailcommon.Device;
28f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blankimport com.android.emailcommon.TempDirectory;
29f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blankimport com.android.emailcommon.mail.MessagingException;
30f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blankimport com.android.emailcommon.provider.HostAuth;
31f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blankimport com.android.emailcommon.provider.Policy;
32f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank
33dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blankimport java.io.IOException;
34dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank
350d4fc55861ed4393aa82f124f2865695ef564641Marc Blank/**
360d4fc55861ed4393aa82f124f2865695ef564641Marc Blank * The EmailServiceProxy class provides a simple interface for the UI to call into the various
370d4fc55861ed4393aa82f124f2865695ef564641Marc Blank * EmailService classes (e.g. ExchangeService for EAS).  It wraps the service connect/disconnect
380d4fc55861ed4393aa82f124f2865695ef564641Marc Blank * process so that the caller need not be concerned with it.
390d4fc55861ed4393aa82f124f2865695ef564641Marc Blank *
400d4fc55861ed4393aa82f124f2865695ef564641Marc Blank * Use the class like this:
41c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank *   new EmailServiceProxy(context, class).loadAttachment(attachmentId, callback)
420d4fc55861ed4393aa82f124f2865695ef564641Marc Blank *
430d4fc55861ed4393aa82f124f2865695ef564641Marc Blank * Methods without a return value return immediately (i.e. are asynchronous); methods with a
440d4fc55861ed4393aa82f124f2865695ef564641Marc Blank * return value wait for a result from the Service (i.e. they should not be called from the UI
450d4fc55861ed4393aa82f124f2865695ef564641Marc Blank * thread) with a default timeout of 30 seconds (settable)
460d4fc55861ed4393aa82f124f2865695ef564641Marc Blank *
470d4fc55861ed4393aa82f124f2865695ef564641Marc Blank * An EmailServiceProxy object cannot be reused (trying to do so generates a RemoteException)
480d4fc55861ed4393aa82f124f2865695ef564641Marc Blank */
490d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
500d4fc55861ed4393aa82f124f2865695ef564641Marc Blankpublic class EmailServiceProxy extends ServiceProxy implements IEmailService {
510d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    private static final String TAG = "EmailServiceProxy";
520d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
530d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public static final String AUTO_DISCOVER_BUNDLE_ERROR_CODE = "autodiscover_error_code";
540d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public static final String AUTO_DISCOVER_BUNDLE_HOST_AUTH = "autodiscover_host_auth";
550d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
560d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public static final String VALIDATE_BUNDLE_RESULT_CODE = "validate_result_code";
570d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public static final String VALIDATE_BUNDLE_POLICY_SET = "validate_policy_set";
580d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public static final String VALIDATE_BUNDLE_ERROR_MESSAGE = "validate_error_message";
59265530723b8c008f6bc23b1723f4de706a3e9556Marc Blank    public static final String VALIDATE_BUNDLE_UNSUPPORTED_POLICIES =
60265530723b8c008f6bc23b1723f4de706a3e9556Marc Blank        "validate_unsupported_policies";
610d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
620d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    private final IEmailServiceCallback mCallback;
630d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    private Object mReturn = null;
640d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    private IEmailService mService;
65f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    private final boolean isRemote;
660d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
670d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    // Standard debugging
680d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public static final int DEBUG_BIT = 1;
690d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    // Verbose (parser) logging
700d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public static final int DEBUG_VERBOSE_BIT = 2;
710d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    // File (SD card) logging
720d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public static final int DEBUG_FILE_BIT = 4;
7319b2a7ebc9cc770baace1605ff5b44b3fcb46320Makoto Onuki    // Enable strict mode
7419b2a7ebc9cc770baace1605ff5b44b3fcb46320Makoto Onuki    public static final int DEBUG_ENABLE_STRICT_MODE = 8;
750d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
760d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    // The first two constructors are used with local services that can be referenced by class
770d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public EmailServiceProxy(Context _context, Class<?> _class) {
780d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        this(_context, _class, null);
790d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    }
800d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
810d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public EmailServiceProxy(Context _context, Class<?> _class, IEmailServiceCallback _callback) {
820d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        super(_context, new Intent(_context, _class));
830d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        mCallback = _callback;
84f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank        isRemote = false;
850d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    }
860d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
870d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    // The following two constructors are used with remote services that must be referenced by
880d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    // a known action or by a prebuilt intent
890d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public EmailServiceProxy(Context _context, Intent _intent, IEmailServiceCallback _callback) {
900d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        super(_context, _intent);
91dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank        try {
92dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank            Device.getDeviceId(_context);
93f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank            TempDirectory.setTempDirectory(_context);
94dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank        } catch (IOException e) {
95dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank        }
960d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        mCallback = _callback;
97f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank        isRemote = true;
980d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    }
990d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
1000d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public EmailServiceProxy(Context _context, String _action, IEmailServiceCallback _callback) {
1010d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        super(_context, new Intent(_action));
102dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank        try {
103dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank            Device.getDeviceId(_context);
104f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank            TempDirectory.setTempDirectory(_context);
105dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank        } catch (IOException e) {
106dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank        }
1070d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        mCallback = _callback;
108f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank        isRemote = true;
1090d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    }
1100d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
1110d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    @Override
1120d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public void onConnected(IBinder binder) {
1130d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        mService = IEmailService.Stub.asInterface(binder);
1140d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    }
1150d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
116f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    public boolean isRemote() {
117f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank        return isRemote;
118f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    }
119f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank
1200d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    @Override
1210d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public int getApiLevel() {
1220d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        return Api.LEVEL;
1230d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    }
1240d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
125c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank    /**
126c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * Request an attachment to be loaded; the service MUST give higher priority to
127c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * non-background loading.  The service MUST use the loadAttachmentStatus callback when
128c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * loading has started and stopped and SHOULD send callbacks with progress information if
129c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * possible.
130c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     *
131c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @param attachmentId the id of the attachment record
132c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @param background whether or not this request corresponds to a background action (i.e.
133c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * prefetch) vs a foreground action (user request)
134c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     */
135f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    @Override
136dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank    public void loadAttachment(final long attachmentId, final boolean background)
137dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank            throws RemoteException {
1380d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        setTask(new ProxyTask() {
139f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank            @Override
1400d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            public void run() throws RemoteException {
1410d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                try {
1420d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                    if (mCallback != null) mService.setCallback(mCallback);
143dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank                    mService.loadAttachment(attachmentId, background);
1440d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                } catch (RemoteException e) {
1450d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                    try {
1460d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                        // Try to send a callback (if set)
1470d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                        if (mCallback != null) {
1480d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                            mCallback.loadAttachmentStatus(-1, attachmentId,
1490d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                                    EmailServiceStatus.REMOTE_EXCEPTION, 0);
1500d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                        }
1510d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                    } catch (RemoteException e1) {
1520d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                    }
1530d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                }
1540d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            }
1550d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        }, "loadAttachment");
1560d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    }
1570d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
158c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank    /**
159c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * Request the sync of a mailbox; the service MUST send the syncMailboxStatus callback
160c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * indicating "starting" and "finished" (or error), regardless of whether the mailbox is
161c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * actually syncable.
162c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     *
163c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @param mailboxId the id of the mailbox record
164c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @param userRequest whether or not the user specifically asked for the sync
165c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     */
166f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    @Override
1670d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public void startSync(final long mailboxId, final boolean userRequest) throws RemoteException {
1680d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        setTask(new ProxyTask() {
169f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank            @Override
1700d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            public void run() throws RemoteException {
1710d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                if (mCallback != null) mService.setCallback(mCallback);
1720d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                mService.startSync(mailboxId, userRequest);
1730d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            }
1740d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        }, "startSync");
1750d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    }
1760d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
177c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank    /**
178c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * Request the immediate termination of a mailbox sync. Although the service is not required to
179c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * acknowledge this request, it MUST send a "finished" (or error) syncMailboxStatus callback if
180c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * the sync was started via the startSync service call.
181c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     *
182c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @param mailboxId the id of the mailbox record
183c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @param userRequest whether or not the user specifically asked for the sync
184c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     */
185f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    @Override
1860d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public void stopSync(final long mailboxId) throws RemoteException {
1870d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        setTask(new ProxyTask() {
188f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank            @Override
1890d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            public void run() throws RemoteException {
1900d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                if (mCallback != null) mService.setCallback(mCallback);
1910d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                mService.stopSync(mailboxId);
1920d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            }
1930d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        }, "stopSync");
1940d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    }
1950d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
196c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank    /**
197c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * Validate a user account, given a protocol, host address, port, ssl status, and credentials.
198c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * The result of this call is returned in a Bundle which MUST include a result code and MAY
199c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * include a PolicySet that is required by the account. A successful validation implies a host
200c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * address that serves the specified protocol and credentials sufficient to be authorized
201c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * by the server to do so.
202c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     *
20322409fcffae4c6e551fb3e6ead4cdc92e33fded1Ben Komalo     * @param hostAuth the hostauth object to validate
204c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @return a Bundle as described above
205c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     */
206f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    @Override
20722409fcffae4c6e551fb3e6ead4cdc92e33fded1Ben Komalo    public Bundle validate(final HostAuth hostAuth) throws RemoteException {
2080d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        setTask(new ProxyTask() {
209f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank            @Override
2100d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            public void run() throws RemoteException{
2110d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                if (mCallback != null) mService.setCallback(mCallback);
21222409fcffae4c6e551fb3e6ead4cdc92e33fded1Ben Komalo                mReturn = mService.validate(hostAuth);
2130d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            }
2140d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        }, "validate");
2150d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        waitForCompletion();
2160d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        if (mReturn == null) {
2170d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            Bundle bundle = new Bundle();
2180d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            bundle.putInt(VALIDATE_BUNDLE_RESULT_CODE, MessagingException.UNSPECIFIED_EXCEPTION);
2190d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            return bundle;
2200d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        } else {
2210d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            Bundle bundle = (Bundle) mReturn;
222aeee10e57ef4d931e7708fde218d590453a82aeaMarc Blank            bundle.setClassLoader(Policy.class.getClassLoader());
2230d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            Log.v(TAG, "validate returns " + bundle.getInt(VALIDATE_BUNDLE_RESULT_CODE));
2240d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            return bundle;
2250d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        }
2260d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    }
2270d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
228c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank    /**
229c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * Attempt to determine a user's host address and credentials from an email address and
230c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * password. The result is returned in a Bundle which MUST include an error code and MAY (on
231c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * success) include a HostAuth record sufficient to enable the service to validate the user's
232c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * account.
233c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     *
234c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @param userName the user's email address
235c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @param password the user's password
236c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @return a Bundle as described above
237c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     */
238f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    @Override
2390d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public Bundle autoDiscover(final String userName, final String password)
2400d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            throws RemoteException {
2410d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        setTask(new ProxyTask() {
242f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank            @Override
2430d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            public void run() throws RemoteException{
2440d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                if (mCallback != null) mService.setCallback(mCallback);
2450d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                mReturn = mService.autoDiscover(userName, password);
2460d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            }
2470d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        }, "autoDiscover");
2480d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        waitForCompletion();
2490d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        if (mReturn == null) {
2500d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            return null;
2510d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        } else {
2520d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            Bundle bundle = (Bundle) mReturn;
2530d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            bundle.setClassLoader(HostAuth.class.getClassLoader());
2540d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            Log.v(TAG, "autoDiscover returns " + bundle.getInt(AUTO_DISCOVER_BUNDLE_ERROR_CODE));
2550d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            return bundle;
2560d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        }
2570d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    }
2580d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
259c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank    /**
260c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * Request that the service reload the folder list for the specified account. The service
261c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * MUST use the syncMailboxListStatus callback to indicate "starting" and "finished"
262c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     *
263c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @param accoundId the id of the account whose folder list is to be updated
264c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     */
265f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    @Override
2660d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public void updateFolderList(final long accountId) throws RemoteException {
2670d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        setTask(new ProxyTask() {
268f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank            @Override
2690d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            public void run() throws RemoteException {
2700d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                if (mCallback != null) mService.setCallback(mCallback);
2710d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                mService.updateFolderList(accountId);
2720d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            }
2730d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        }, "updateFolderList");
2740d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    }
2750d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
276c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank    /**
277c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * Specify the debug flags selected by the user.  The service SHOULD log debug information as
278c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * requested.
279c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     *
280c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @param flags an integer whose bits represent logging flags as defined in DEBUG_* flags above
281c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     */
282f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    @Override
283c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank    public void setLogging(final int flags) throws RemoteException {
2840d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        setTask(new ProxyTask() {
285f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank            @Override
2860d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            public void run() throws RemoteException {
2870d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                if (mCallback != null) mService.setCallback(mCallback);
288c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank                mService.setLogging(flags);
2890d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            }
2900d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        }, "setLogging");
2910d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    }
2920d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
293c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank    /**
294c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * Set the global callback object to be used by the service; the service MUST always use the
295c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * most recently set callback object
296c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     *
297c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @param cb a callback object through which all service callbacks are executed
298c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     */
299f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    @Override
3000d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public void setCallback(final IEmailServiceCallback cb) throws RemoteException {
3010d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        setTask(new ProxyTask() {
302f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank            @Override
3030d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            public void run() throws RemoteException {
3040d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                mService.setCallback(cb);
3050d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            }
3060d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        }, "setCallback");
3070d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    }
3080d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
309c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank    /**
310c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * Alert the sync adapter that the account's host information has (or may have) changed; the
311c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * service MUST stop all in-process or pending syncs, clear error states related to the
312c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * account and its mailboxes, and restart necessary sync adapters (e.g. pushed mailboxes)
313c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     *
314c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @param accountId the id of the account whose host information has changed
315c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     */
316f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    @Override
3170d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public void hostChanged(final long accountId) throws RemoteException {
3180d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        setTask(new ProxyTask() {
319f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank            @Override
3200d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            public void run() throws RemoteException {
3210d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                mService.hostChanged(accountId);
3220d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            }
3230d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        }, "hostChanged");
3240d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    }
3250d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
326c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank    /**
327c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * Send a meeting response for the specified message
328c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     *
329c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @param messageId the id of the message containing the meeting request
330c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @param response the response code, as defined in EmailServiceConstants
331c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     */
332f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    @Override
3330d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public void sendMeetingResponse(final long messageId, final int response)
3340d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            throws RemoteException {
3350d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        setTask(new ProxyTask() {
336f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank            @Override
3370d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            public void run() throws RemoteException {
3380d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                if (mCallback != null) mService.setCallback(mCallback);
3390d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                mService.sendMeetingResponse(messageId, response);
3400d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            }
3410d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        }, "sendMeetingResponse");
3420d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    }
3430d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
344c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank    /**
345f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank     * Request the sync adapter to load a complete message
346c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     *
347c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @param messageId the id of the message to be loaded
348c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     */
349f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    @Override
350f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    public void loadMore(final long messageId) throws RemoteException {
351f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank        setTask(new ProxyTask() {
352f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank            @Override
353f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank            public void run() throws RemoteException {
354f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank                if (mCallback != null) mService.setCallback(mCallback);
355f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank                mService.loadMore(messageId);
356f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank            }
357f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank        }, "startSync");
3580d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    }
3590d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
360c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank    /**
361c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * Not yet used
362c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     *
363c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @param accountId the account in which the folder is to be created
364c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @param name the name of the folder to be created
365c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank    */
366f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    @Override
3670d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public boolean createFolder(long accountId, String name) throws RemoteException {
3680d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        return false;
3690d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    }
3700d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
371c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank    /**
372c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * Not yet used
373c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     *
374c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @param accountId the account in which the folder resides
375c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @param name the name of the folder to be deleted
376c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     */
377f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    @Override
3780d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public boolean deleteFolder(long accountId, String name) throws RemoteException {
3790d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        return false;
3800d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    }
3810d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
382c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank    /**
383c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * Not yet used
384c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     *
385c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @param accountId the account in which the folder resides
386c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @param oldName the name of the existing folder
387c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @param newName the new name for the folder
388c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     */
389f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    @Override
3900d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public boolean renameFolder(long accountId, String oldName, String newName)
3910d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            throws RemoteException {
3920d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        return false;
3930d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    }
3940d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
395c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank    /**
396c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * Request the service to delete the account's PIM (personal information management) data. This
397c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * data includes any data that is 1) associated with the account and 2) created/stored by the
398c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * service or its sync adapters and 3) not stored in the EmailProvider database (e.g. contact
399c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * and calendar information).
400c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     *
401c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @param accountId the account whose data is to be deleted
402c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     */
403f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    @Override
4040d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public void deleteAccountPIMData(final long accountId) throws RemoteException {
4050d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        setTask(new ProxyTask() {
406f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank            @Override
4070d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            public void run() throws RemoteException {
4080d4fc55861ed4393aa82f124f2865695ef564641Marc Blank                mService.deleteAccountPIMData(accountId);
4090d4fc55861ed4393aa82f124f2865695ef564641Marc Blank            }
4100d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        }, "deleteAccountPIMData");
4110d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    }
4120d4fc55861ed4393aa82f124f2865695ef564641Marc Blank
413c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank    /**
414c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * Search for messages given a query string.  The string is interpreted as the logical AND of
415c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * terms separated by white space.  The search is performed on the specified mailbox in the
416c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * specified account (including subfolders, as specified by the includeSubfolders parameter).
417c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * At most numResults messages matching the query term(s) will be added to the mailbox specified
418c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * as destMailboxId. If mailboxId is -1, the entire account will be searched. If firstResult is
419c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * specified and non-zero, results will be added starting with the firstResult'th match (i.e.
420c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * for the continuation of a previous search)
421c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     *
422c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @param accountId the id of the account to be searched
42375a754660e33c5e18cacffff193983ba22a7b9b0Marc Blank     * @param searchParams the search specification
424c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @param destMailboxId the id of the mailbox into which search results are appended
425c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     * @return the total number of matches for this search (regardless of how many were requested)
426c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank     */
427f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    @Override
42875a754660e33c5e18cacffff193983ba22a7b9b0Marc Blank    public int searchMessages(final long accountId, final SearchParams searchParams,
42975a754660e33c5e18cacffff193983ba22a7b9b0Marc Blank            final long destMailboxId) throws RemoteException {
430c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank        setTask(new ProxyTask() {
431f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank            @Override
432c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank            public void run() throws RemoteException{
433c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank                if (mCallback != null) mService.setCallback(mCallback);
43475a754660e33c5e18cacffff193983ba22a7b9b0Marc Blank                mReturn = mService.searchMessages(accountId, searchParams, destMailboxId);
435c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank            }
436c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank        }, "searchMessages");
437c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank        waitForCompletion();
438c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank        if (mReturn == null) {
439c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank            return 0;
440c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank        } else {
441c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank            return (Integer)mReturn;
442c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank        }
443c60b8d0529168edecf2376a6f421a0ae1e10fe29Marc Blank    }
444f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank
445f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    /**
446f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank     * Request the service to send mail in the specified account's Outbox
447f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank     *
448f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank     * @param accountId the account whose outgoing mail should be sent
449f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank     */
450f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    @Override
451f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    public void sendMail(final long accountId) throws RemoteException {
452f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank        setTask(new ProxyTask() {
453f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank            @Override
454f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank            public void run() throws RemoteException{
455f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank                if (mCallback != null) mService.setCallback(mCallback);
456f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank                mService.sendMail(accountId);
457f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank            }
458f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank        }, "sendMail");
459f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    }
460f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank
461f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    @Override
462f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    public int getCapabilities(final long accountId) throws RemoteException {
463f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank        setTask(new ProxyTask() {
464f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank            @Override
465f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank            public void run() throws RemoteException{
466f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank                if (mCallback != null) mService.setCallback(mCallback);
467f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank                mReturn = mService.getCapabilities(accountId);
468f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank            }
469f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank        }, "getCapabilities");
470f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank        waitForCompletion();
471f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank        if (mReturn == null) {
472f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank            return 0;
473f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank        } else {
474f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank            return (Integer)mReturn;
475f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank        }
476f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    }
477f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank
478f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank    @Override
4790d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    public IBinder asBinder() {
4800d4fc55861ed4393aa82f124f2865695ef564641Marc Blank        return null;
4810d4fc55861ed4393aa82f124f2865695ef564641Marc Blank    }
4820d4fc55861ed4393aa82f124f2865695ef564641Marc Blank}
483