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.exchange.service; 18 19 import android.app.Service; 20 import android.content.AbstractThreadedSyncAdapter; 21 import android.content.Intent; 22 import android.os.IBinder; 23 24 import com.android.emailcommon.provider.EmailContent; 25 26 /** 27 * Base class for services that handle sync requests from the system SyncManager. 28 * This class covers the boilerplate for using an {@link AbstractThreadedSyncAdapter}. Subclasses 29 * should just implement their sync adapter, and override {@link #getSyncAdapter}. 30 */ 31 public abstract class AbstractSyncAdapterService extends Service { 32 public AbstractSyncAdapterService() { 33 super(); 34 } 35 36 @Override 37 public void onCreate() { 38 super.onCreate(); 39 // Make sure EmailContent is initialized in Exchange app 40 EmailContent.init(this); 41 } 42 43 @Override 44 public IBinder onBind(Intent intent) { 45 return getSyncAdapter().getSyncAdapterBinder(); 46 } 47 48 /** 49 * Subclasses should override this to supply an instance of its sync adapter. Best practice is 50 * to create a singleton and return that. 51 * @return An instance of the sync adapter. 52 */ 53 protected abstract AbstractThreadedSyncAdapter getSyncAdapter(); 54 } 55