decouple SyncAdapter from ContentProvider
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 700096a..2ed8d39 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -39,6 +39,13 @@
android:syncable="true" android:multiprocess="false"
android:readPermission="android.permission.READ_CALENDAR"
android:writePermission="android.permission.WRITE_CALENDAR" />
+ <service android:name="CalendarSyncAdapterService" android:exported="true">
+ <intent-filter>
+ <action android:name="android.content.SyncAdapter" />
+ </intent-filter>
+ <meta-data android:name="android.content.SyncAdapter"
+ android:resource="@xml/syncadapter" />
+ </service>
<activity android:name="CalendarContentProviderTests" android:label="Calendar Content Provider">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
diff --git a/res/xml/syncadapter.xml b/res/xml/syncadapter.xml
new file mode 100644
index 0000000..b5f89cc
--- /dev/null
+++ b/res/xml/syncadapter.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/**
+ * Copyright (c) 2009, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+
+<!-- The attributes in this XML file provide configuration information -->
+<!-- for the SyncAdapter. -->
+
+<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
+ android:contentAuthority="calendar"
+ android:accountType="com.google.GAIA"
+/>
diff --git a/src/com/android/providers/calendar/CalendarProvider.java b/src/com/android/providers/calendar/CalendarProvider.java
index d65b4fb..7767f56 100644
--- a/src/com/android/providers/calendar/CalendarProvider.java
+++ b/src/com/android/providers/calendar/CalendarProvider.java
@@ -45,7 +45,6 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
-import android.content.SyncAdapter;
import android.content.SyncContext;
import android.content.UriMatcher;
import android.database.Cursor;
@@ -88,7 +87,6 @@
import java.util.TimeZone;
public class CalendarProvider extends AbstractSyncableContentProvider {
-
private static final boolean PROFILE = false;
private static final boolean MULTIPLE_ATTENDEES_PER_EVENT = false;
private static final String[] ACCOUNTS_PROJECTION =
@@ -273,7 +271,6 @@
private AlarmManager mAlarmManager;
- private CalendarSyncAdapter mSyncAdapter;
private CalendarAppWidgetProvider mAppWidgetProvider = CalendarAppWidgetProvider.getInstance();
/**
@@ -307,6 +304,8 @@
public boolean onCreate() {
super.onCreate();
+ setTempProviderSyncAdapter(new CalendarSyncAdapter(getContext(), this));
+
// Register for Intent broadcasts
IntentFilter filter = new IntentFilter();
@@ -3347,14 +3346,6 @@
}
@Override
- public synchronized SyncAdapter getSyncAdapter() {
- if (mSyncAdapter == null) {
- mSyncAdapter = new CalendarSyncAdapter(getContext(), this);
- }
- return mSyncAdapter;
- }
-
- @Override
public void onSyncStop(SyncContext context, boolean success) {
super.onSyncStop(context, success);
if (Log.isLoggable(TAG, Log.DEBUG)) {
diff --git a/src/com/android/providers/calendar/CalendarSyncAdapterService.java b/src/com/android/providers/calendar/CalendarSyncAdapterService.java
new file mode 100644
index 0000000..7634f2c
--- /dev/null
+++ b/src/com/android/providers/calendar/CalendarSyncAdapterService.java
@@ -0,0 +1,29 @@
+package com.android.providers.calendar;
+
+import android.app.Service;
+import android.os.IBinder;
+import android.content.Intent;
+import android.content.ContentProviderClient;
+import android.content.ContentProvider;
+import android.content.SyncableContentProvider;
+import android.provider.Calendar;
+
+public class CalendarSyncAdapterService extends Service {
+ private ContentProviderClient mContentProviderClient = null;
+
+ public void onCreate() {
+ mContentProviderClient =
+ getContentResolver().acquireContentProviderClient(Calendar.CONTENT_URI);
+ }
+
+ public void onDestroy() {
+ mContentProviderClient.release();
+ }
+
+ public IBinder onBind(Intent intent) {
+ ContentProvider contentProvider = mContentProviderClient.getLocalContentProvider();
+ if (contentProvider == null) throw new IllegalStateException();
+ SyncableContentProvider syncableContentProvider = (SyncableContentProvider)contentProvider;
+ return syncableContentProvider.getTempProviderSyncAdapter().getISyncAdapter().asBinder();
+ }
+}