The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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 android.content; |
| 18 | |
| 19 | import android.os.Bundle; |
| 20 | import android.os.RemoteException; |
Fred Quintana | d9d2f11 | 2009-04-23 13:36:27 -0700 | [diff] [blame] | 21 | import android.accounts.Account; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * @hide |
| 25 | */ |
| 26 | public abstract class SyncAdapter { |
| 27 | private static final String TAG = "SyncAdapter"; |
| 28 | |
Doug Zongker | 45e6dbf | 2009-12-08 12:47:12 -0800 | [diff] [blame] | 29 | /** Kernel event log tag. */ |
| 30 | public static final int LOG_SYNC_DETAILS = EventLogTags.SYNC_DETAILS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | |
| 32 | class Transport extends ISyncAdapter.Stub { |
Fred Quintana | 21bb0de | 2009-06-16 10:24:58 -0700 | [diff] [blame] | 33 | public void startSync(ISyncContext syncContext, String authority, Account account, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | Bundle extras) throws RemoteException { |
Fred Quintana | 4a6679b | 2009-08-17 13:05:39 -0700 | [diff] [blame] | 35 | SyncAdapter.this.startSync(new SyncContext(syncContext), account, authority, extras); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | } |
| 37 | |
Fred Quintana | 21bb0de | 2009-06-16 10:24:58 -0700 | [diff] [blame] | 38 | public void cancelSync(ISyncContext syncContext) throws RemoteException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | SyncAdapter.this.cancelSync(); |
| 40 | } |
Fred Quintana | e7424ff | 2009-10-14 15:59:21 -0700 | [diff] [blame] | 41 | |
| 42 | public void initialize(Account account, String authority) throws RemoteException { |
| 43 | Bundle extras = new Bundle(); |
| 44 | extras.putBoolean(ContentResolver.SYNC_EXTRAS_INITIALIZE, true); |
| 45 | startSync(null, authority, account, extras); |
| 46 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | Transport mTransport = new Transport(); |
| 50 | |
| 51 | /** |
Fred Quintana | 718d8a2 | 2009-04-29 17:53:20 -0700 | [diff] [blame] | 52 | * Get the Transport object. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | */ |
Fred Quintana | 718d8a2 | 2009-04-29 17:53:20 -0700 | [diff] [blame] | 54 | public final ISyncAdapter getISyncAdapter() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | { |
| 56 | return mTransport; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Initiate a sync for this account. SyncAdapter-specific parameters may |
| 61 | * be specified in extras, which is guaranteed to not be null. IPC invocations |
| 62 | * of this method and cancelSync() are guaranteed to be serialized. |
| 63 | * |
| 64 | * @param syncContext the ISyncContext used to indicate the progress of the sync. When |
| 65 | * the sync is finished (successfully or not) ISyncContext.onFinished() must be called. |
| 66 | * @param account the account that should be synced |
Fred Quintana | 4a6679b | 2009-08-17 13:05:39 -0700 | [diff] [blame] | 67 | * @param authority the authority if the sync request |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | * @param extras SyncAdapter-specific parameters |
| 69 | */ |
Fred Quintana | 4a6679b | 2009-08-17 13:05:39 -0700 | [diff] [blame] | 70 | public abstract void startSync(SyncContext syncContext, Account account, String authority, |
| 71 | Bundle extras); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | |
| 73 | /** |
| 74 | * Cancel the most recently initiated sync. Due to race conditions, this may arrive |
| 75 | * after the ISyncContext.onFinished() for that sync was called. IPC invocations |
| 76 | * of this method and startSync() are guaranteed to be serialized. |
| 77 | */ |
| 78 | public abstract void cancelSync(); |
| 79 | } |