1 /* 2 * Copyright (C) 2016 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.cts.content; 18 19 import android.accounts.Account; 20 import android.content.AbstractThreadedSyncAdapter; 21 import android.content.ContentProviderClient; 22 import android.content.Context; 23 import android.content.SyncResult; 24 import android.os.Bundle; 25 26 public class SyncAdapter extends AbstractThreadedSyncAdapter { 27 private static final Object sLock = new Object(); 28 29 private static OnPerformSyncDelegate sOnPerformSyncDelegate; 30 31 public interface OnPerformSyncDelegate { onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult)32 void onPerformSync(Account account, Bundle extras, String authority, 33 ContentProviderClient provider, SyncResult syncResult); 34 } 35 setOnPerformSyncDelegate(OnPerformSyncDelegate delegate)36 public static void setOnPerformSyncDelegate(OnPerformSyncDelegate delegate) { 37 synchronized (sLock) { 38 sOnPerformSyncDelegate = delegate; 39 } 40 } 41 SyncAdapter(Context context, boolean autoInitialize)42 public SyncAdapter(Context context, boolean autoInitialize) { 43 super(context, autoInitialize); 44 } 45 46 @Override onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult)47 public void onPerformSync(Account account, Bundle extras, String authority, 48 ContentProviderClient provider, SyncResult syncResult) { 49 OnPerformSyncDelegate delegate; 50 synchronized (sLock) { 51 delegate = sOnPerformSyncDelegate; 52 } 53 if (delegate != null) { 54 delegate.onPerformSync(account, extras, authority, provider, syncResult); 55 } 56 } 57 } 58