diff options
| author | Dianne Hackborn <hackbod@google.com> | 2009-04-27 17:10:36 -0700 | 
|---|---|---|
| committer | Dianne Hackborn <hackbod@google.com> | 2009-05-05 15:40:53 -0700 | 
| commit | 231cc608d06ffc31c24bf8aa8c8275bdd2636581 (patch) | |
| tree | 9b435c670f0f16751a21ae4678bfbed7d8e159b4 /core/java/android/os | |
| parent | 06d96020c35dac2bf1651cb8bd4cfced911f1142 (diff) | |
| download | frameworks_base-231cc608d06ffc31c24bf8aa8c8275bdd2636581.zip frameworks_base-231cc608d06ffc31c24bf8aa8c8275bdd2636581.tar.gz frameworks_base-231cc608d06ffc31c24bf8aa8c8275bdd2636581.tar.bz2 | |
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.
Diffstat (limited to 'core/java/android/os')
| -rw-r--r-- | core/java/android/os/RemoteCallbackList.java | 57 | 
1 files changed, 45 insertions, 12 deletions
| diff --git a/core/java/android/os/RemoteCallbackList.java b/core/java/android/os/RemoteCallbackList.java index 63f6dff..23c0a7b 100644 --- a/core/java/android/os/RemoteCallbackList.java +++ b/core/java/android/os/RemoteCallbackList.java @@ -49,25 +49,35 @@ import java.util.HashMap;  public class RemoteCallbackList<E extends IInterface> {      /*package*/ HashMap<IBinder, Callback> mCallbacks              = new HashMap<IBinder, Callback>(); -    private IInterface[] mActiveBroadcast; +    private Object[] mActiveBroadcast;      private boolean mKilled = false;      private final class Callback implements IBinder.DeathRecipient {          final E mCallback; +        final Object mCookie; -        Callback(E callback) { +        Callback(E callback, Object cookie) {              mCallback = callback; +            mCookie = cookie;          }          public void binderDied() {              synchronized (mCallbacks) {                  mCallbacks.remove(mCallback.asBinder());              } -            onCallbackDied(mCallback); +            onCallbackDied(mCallback, mCookie);          }      }      /** +     * Simple version of {@link RemoteCallbackList#register(E, Object)} +     * that does not take a cookie object. +     */ +    public boolean register(E callback) { +        return register(callback, null); +    } +     +    /**       * Add a new callback to the list.  This callback will remain in the list       * until a corresponding call to {@link #unregister} or its hosting process       * goes away.  If the callback was already registered (determined by @@ -81,6 +91,8 @@ public class RemoteCallbackList<E extends IInterface> {       * Most services will want to check for null before calling this with       * an object given from a client, so that clients can't crash the       * service with bad data. +     * @param cookie Optional additional data to be associated with this +     * callback.       *        * @return Returns true if the callback was successfully added to the list.       * Returns false if it was not added, either because {@link #kill} had @@ -90,14 +102,14 @@ public class RemoteCallbackList<E extends IInterface> {       * @see #kill       * @see #onCallbackDied       */ -    public boolean register(E callback) { +    public boolean register(E callback, Object cookie) {          synchronized (mCallbacks) {              if (mKilled) {                  return false;              }              IBinder binder = callback.asBinder();              try { -                Callback cb = new Callback(callback); +                Callback cb = new Callback(callback, cookie);                  binder.linkToDeath(cb, 0);                  mCallbacks.put(binder, cb);                  return true; @@ -154,17 +166,28 @@ public class RemoteCallbackList<E extends IInterface> {      }      /** +     * Old version of {@link #onCallbackDied(E, Object)} that +     * does not provide a cookie. +     */ +    public void onCallbackDied(E callback) { +    } +     +    /**       * Called when the process hosting a callback in the list has gone away. -     * The default implementation does nothing. +     * The default implementation calls {@link #onCallbackDied(E)} +     * for backwards compatibility.       *        * @param callback The callback whose process has died.  Note that, since       * its process has died, you can not make any calls on to this interface.       * You can, however, retrieve its IBinder and compare it with another       * IBinder to see if it is the same object. +     * @param cookie The cookie object original provided to +     * {@link #register(E, Object)}.       *        * @see #register       */ -    public void onCallbackDied(E callback) { +    public void onCallbackDied(E callback, Object cookie) { +        onCallbackDied(callback);      }      /** @@ -203,13 +226,13 @@ public class RemoteCallbackList<E extends IInterface> {              if (N <= 0) {                  return 0;              } -            IInterface[] active = mActiveBroadcast; +            Object[] active = mActiveBroadcast;              if (active == null || active.length < N) { -                mActiveBroadcast = active = new IInterface[N]; +                mActiveBroadcast = active = new Object[N];              }              int i=0;              for (Callback cb : mCallbacks.values()) { -                active[i++] = cb.mCallback; +                active[i++] = cb;              }              return i;          } @@ -237,7 +260,17 @@ public class RemoteCallbackList<E extends IInterface> {       * @see #beginBroadcast       */      public E getBroadcastItem(int index) { -        return (E)mActiveBroadcast[index]; +        return ((Callback)mActiveBroadcast[index]).mCallback; +    } +     +    /** +     * Retrieve the cookie associated with the item +     * returned by {@link #getBroadcastItem(int)}. +     *  +     * @see #getBroadcastItem +     */ +    public Object getBroadcastCookie(int index) { +        return ((Callback)mActiveBroadcast[index]).mCookie;      }      /** @@ -248,7 +281,7 @@ public class RemoteCallbackList<E extends IInterface> {       * @see #beginBroadcast       */      public void finishBroadcast() { -        IInterface[] active = mActiveBroadcast; +        Object[] active = mActiveBroadcast;          if (active != null) {              final int N = active.length;              for (int i=0; i<N; i++) { | 
