Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 231cc608 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Rewrite SyncStorageEngine to use flat files and in-memory data structures.

The previous implementation used a database for storing all of its state, which could cause
a significant amount of IO activity as its tables were updated through the stages of a sync.
This new implementation replaces that in-memory data structures, with hand-written code
for writing them to persistent storage.

There are now 4 files associated with this class, holding various pieces of its state that
should be consistent.  These are everything from a main XML file of account information that
must always be retained, to a binary file of per-day statistics that can be thrown away at
any time.  Writes of these files as scheduled at various times based on their importance of
the frequency at which they change.

Because the database no longer exists, there needs to be a new explicit interface for
interacting with the sync manager database.  This is provided by new APIs on IContentService,
with a hidden method on ContentResolver to retrieve the IContentService so that various
system entities can use it.  Other changes in other projects are required to update to the
new API.

The goal here is to have as little an impact on the code and functionality outside of
SyncStorageEngine, though due to the necessary change in API it is still somewhat extensive.
parent 06d96020
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -85,8 +85,10 @@ LOCAL_SRC_FILES += \
	core/java/android/bluetooth/IBluetoothDevice.aidl \
	core/java/android/bluetooth/IBluetoothDeviceCallback.aidl \
	core/java/android/bluetooth/IBluetoothHeadset.aidl \
    core/java/android/content/IContentService.aidl \
	core/java/android/content/ISyncAdapter.aidl \
	core/java/android/content/ISyncContext.aidl \
    core/java/android/content/ISyncStatusObserver.aidl \
	core/java/android/content/pm/IPackageDataObserver.aidl \
	core/java/android/content/pm/IPackageDeleteObserver.aidl \
	core/java/android/content/pm/IPackageInstallObserver.aidl \
+43 −0
Original line number Diff line number Diff line
@@ -92268,6 +92268,19 @@
 visibility="public"
>
</method>
<method name="getBroadcastCookie"
 return="java.lang.Object"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="index" type="int">
</parameter>
</method>
<method name="getBroadcastItem"
 return="E"
 abstract="false"
@@ -92305,6 +92318,21 @@
<parameter name="callback" type="E">
</parameter>
</method>
<method name="onCallbackDied"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="callback" type="E">
</parameter>
<parameter name="cookie" type="java.lang.Object">
</parameter>
</method>
<method name="register"
 return="boolean"
 abstract="false"
@@ -92318,6 +92346,21 @@
<parameter name="callback" type="E">
</parameter>
</method>
<method name="register"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="callback" type="E">
</parameter>
<parameter name="cookie" type="java.lang.Object">
</parameter>
</method>
<method name="unregister"
 return="boolean"
 abstract="false"
+19 −0
Original line number Diff line number Diff line
/*
 * 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.
 */

package android.content;

parcelable ActiveSyncInfo;
+64 −0
Original line number Diff line number Diff line
/*
 * 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.
 */

package android.content;

import android.os.Parcel;
import android.os.Parcelable.Creator;

/** @hide */
public class ActiveSyncInfo {
    public final int authorityId;
    public final String account;
    public final String authority;
    public final long startTime;
    
    ActiveSyncInfo(int authorityId, String account, String authority,
            long startTime) {
        this.authorityId = authorityId;
        this.account = account;
        this.authority = authority;
        this.startTime = startTime;
    }
    
    public int describeContents() {
        return 0;
    }

    public void writeToParcel(Parcel parcel, int flags) {
        parcel.writeInt(authorityId);
        parcel.writeString(account);
        parcel.writeString(authority);
        parcel.writeLong(startTime);
    }

    ActiveSyncInfo(Parcel parcel) {
        authorityId = parcel.readInt();
        account = parcel.readString();
        authority = parcel.readString();
        startTime = parcel.readLong();
    }
    
    public static final Creator<ActiveSyncInfo> CREATOR = new Creator<ActiveSyncInfo>() {
        public ActiveSyncInfo createFromParcel(Parcel in) {
            return new ActiveSyncInfo(in);
        }

        public ActiveSyncInfo[] newArray(int size) {
            return new ActiveSyncInfo[size];
        }
    };
}
 No newline at end of file
+26 −7
Original line number Diff line number Diff line
@@ -25,9 +25,13 @@ import android.database.CursorWrapper;
import android.database.IContentObserver;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.text.TextUtils;
import android.util.Config;
import android.util.Log;

import java.io.File;
import java.io.FileInputStream;
@@ -85,8 +89,7 @@ public abstract class ContentResolver {
     */
    public static final String CURSOR_DIR_BASE_TYPE = "vnd.android.cursor.dir";
    
    public ContentResolver(Context context)
    {
    public ContentResolver(Context context) {
        mContext = context;
    }

@@ -605,7 +608,7 @@ public abstract class ContentResolver {
            ContentObserver observer)
    {
        try {
            ContentServiceNative.getDefault().registerContentObserver(uri, notifyForDescendents,
            getContentService().registerContentObserver(uri, notifyForDescendents,
                    observer.getContentObserver());
        } catch (RemoteException e) {
        }
@@ -621,7 +624,7 @@ public abstract class ContentResolver {
        try {
            IContentObserver contentObserver = observer.releaseContentObserver();
            if (contentObserver != null) {
                ContentServiceNative.getDefault().unregisterContentObserver(
                getContentService().unregisterContentObserver(
                        contentObserver);
            }
        } catch (RemoteException e) {
@@ -651,7 +654,7 @@ public abstract class ContentResolver {
     */
    public void notifyChange(Uri uri, ContentObserver observer, boolean syncToNetwork) {
        try {
            ContentServiceNative.getDefault().notifyChange(
            getContentService().notifyChange(
                    uri, observer == null ? null : observer.getContentObserver(),
                    observer != null && observer.deliverSelfNotifications(), syncToNetwork);
        } catch (RemoteException e) {
@@ -677,7 +680,7 @@ public abstract class ContentResolver {
    public void startSync(Uri uri, Bundle extras) {
        validateSyncExtrasBundle(extras);
        try {
            ContentServiceNative.getDefault().startSync(uri, extras);
            getContentService().startSync(uri, extras);
        } catch (RemoteException e) {
        }
    }
@@ -718,7 +721,7 @@ public abstract class ContentResolver {

    public void cancelSync(Uri uri) {
        try {
            ContentServiceNative.getDefault().cancelSync(uri);
            getContentService().cancelSync(uri);
        } catch (RemoteException e) {
        }
    }
@@ -779,6 +782,22 @@ public abstract class ContentResolver {
        }
    }

    /** @hide */
    public static final String CONTENT_SERVICE_NAME = "content";
    
    /** @hide */
    public static IContentService getContentService() {
        if (sContentService != null) {
            return sContentService;
        }
        IBinder b = ServiceManager.getService(CONTENT_SERVICE_NAME);
        if (Config.LOGV) Log.v("ContentService", "default service binder = " + b);
        sContentService = IContentService.Stub.asInterface(b);
        if (Config.LOGV) Log.v("ContentService", "default service = " + sContentService);
        return sContentService;
    }
    
    private static IContentService sContentService;
    private final Context mContext;
    private static final String TAG = "ContentResolver";
}
Loading