Home | History | Annotate | Download | only in email
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.email;
     18 
     19 import com.android.email.mail.MessagingException;
     20 import com.android.email.service.EmailServiceProxy;
     21 import com.android.email.service.IEmailService;
     22 import com.android.email.service.IEmailServiceCallback;
     23 import com.android.exchange.CalendarSyncEnabler;
     24 import com.android.exchange.SyncManager;
     25 
     26 import android.content.Context;
     27 import android.content.Intent;
     28 import android.os.Bundle;
     29 import android.os.IBinder;
     30 import android.os.RemoteException;
     31 
     32 /**
     33  * Utility functions for Exchange support.
     34  */
     35 public class ExchangeUtils {
     36     /**
     37      * Starts the service for Exchange, if supported.
     38      */
     39     public static void startExchangeService(Context context) {
     40         //EXCHANGE-REMOVE-SECTION-START
     41         context.startService(new Intent(context, SyncManager.class));
     42         //EXCHANGE-REMOVE-SECTION-END
     43     }
     44 
     45     /**
     46      * Returns an {@link IEmailService} for the Exchange service, if supported.  Otherwise it'll
     47      * return an empty {@link IEmailService} implementation.
     48      *
     49      * @param context
     50      * @param callback Object to get callback, or can be null
     51      */
     52     public static IEmailService getExchangeEmailService(Context context,
     53             IEmailServiceCallback callback) {
     54         IEmailService ret = null;
     55         //EXCHANGE-REMOVE-SECTION-START
     56         ret = new EmailServiceProxy(context, SyncManager.class, callback);
     57         //EXCHANGE-REMOVE-SECTION-END
     58         if (ret == null) {
     59             ret = NullEmailService.INSTANCE;
     60         }
     61         return ret;
     62     }
     63 
     64     /**
     65      * Enable calendar sync for all the existing exchange accounts, and post a notification if any.
     66      */
     67     public static void enableEasCalendarSync(Context context) {
     68         //EXCHANGE-REMOVE-SECTION-START
     69         new CalendarSyncEnabler(context).enableEasCalendarSync();
     70         //EXCHANGE-REMOVE-SECTION-END
     71     }
     72 
     73     /**
     74      * An empty {@link IEmailService} implementation which is used instead of
     75      * {@link com.android.exchange.SyncManager} on the build with no exchange support.
     76      *
     77      * <p>In theory, the service in question isn't used on the no-exchange-support build,
     78      * because we won't have any exchange accounts in that case, so we wouldn't have to have this
     79      * class.  However, there are a few places we do use the service even if there's no exchange
     80      * accounts (e.g. setLogging), so this class is added for safety and simplicity.
     81      */
     82     private static class NullEmailService implements IEmailService {
     83         public static final NullEmailService INSTANCE = new NullEmailService();
     84 
     85         public Bundle autoDiscover(String userName, String password) throws RemoteException {
     86             return Bundle.EMPTY;
     87         }
     88 
     89         public boolean createFolder(long accountId, String name) throws RemoteException {
     90             return false;
     91         }
     92 
     93         public boolean deleteFolder(long accountId, String name) throws RemoteException {
     94             return false;
     95         }
     96 
     97         public void hostChanged(long accountId) throws RemoteException {
     98         }
     99 
    100         public void loadAttachment(long attachmentId, String destinationFile,
    101                 String contentUriString) throws RemoteException {
    102         }
    103 
    104         public void loadMore(long messageId) throws RemoteException {
    105         }
    106 
    107         public boolean renameFolder(long accountId, String oldName, String newName)
    108                 throws RemoteException {
    109             return false;
    110         }
    111 
    112         public void sendMeetingResponse(long messageId, int response) throws RemoteException {
    113         }
    114 
    115         public void setCallback(IEmailServiceCallback cb) throws RemoteException {
    116         }
    117 
    118         public void setLogging(int on) throws RemoteException {
    119         }
    120 
    121         public void startSync(long mailboxId) throws RemoteException {
    122         }
    123 
    124         public void stopSync(long mailboxId) throws RemoteException {
    125         }
    126 
    127         public void updateFolderList(long accountId) throws RemoteException {
    128         }
    129 
    130         public int validate(String protocol, String host, String userName, String password,
    131                 int port, boolean ssl, boolean trustCertificates) throws RemoteException {
    132             return MessagingException.UNSPECIFIED_EXCEPTION;
    133         }
    134 
    135         public IBinder asBinder() {
    136             return null;
    137         }
    138     }
    139 }
    140