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

Commit 328c0e79 authored by Fred Quintana's avatar Fred Quintana
Browse files

- removed the concept of Entity from the ContentProvider APIs

- removed the parcelling ability from Entity and EntityIterator and made them public
- added an EntityIterator abstract implementation that allow easy wrapping of a Cursor
- changed the VCard code to use the new APIs
parent a50d4508
Loading
Loading
Loading
Loading
+283 −0
Original line number Diff line number Diff line
@@ -33868,6 +33868,161 @@
</parameter>
</method>
</interface>
<class name="Entity"
 extends="java.lang.Object"
 abstract="false"
 static="false"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
<constructor name="Entity"
 type="android.content.Entity"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="values" type="android.content.ContentValues">
</parameter>
</constructor>
<method name="addSubValue"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="uri" type="android.net.Uri">
</parameter>
<parameter name="values" type="android.content.ContentValues">
</parameter>
</method>
<method name="getEntityValues"
 return="android.content.ContentValues"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getSubValues"
 return="java.util.ArrayList&lt;android.content.Entity.NamedContentValues&gt;"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
</class>
<class name="Entity.NamedContentValues"
 extends="java.lang.Object"
 abstract="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<constructor name="Entity.NamedContentValues"
 type="android.content.Entity.NamedContentValues"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="uri" type="android.net.Uri">
</parameter>
<parameter name="values" type="android.content.ContentValues">
</parameter>
</constructor>
<field name="uri"
 type="android.net.Uri"
 transient="false"
 volatile="false"
 static="false"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="values"
 type="android.content.ContentValues"
 transient="false"
 volatile="false"
 static="false"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
</class>
<interface name="EntityIterator"
 abstract="true"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<method name="close"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="hasNext"
 return="boolean"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<exception name="RemoteException" type="android.os.RemoteException">
</exception>
</method>
<method name="next"
 return="android.content.Entity"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<exception name="RemoteException" type="android.os.RemoteException">
</exception>
</method>
<method name="reset"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<exception name="RemoteException" type="android.os.RemoteException">
</exception>
</method>
</interface>
<class name="Intent"
 extends="java.lang.Object"
 abstract="false"
@@ -49340,6 +49495,23 @@
<parameter name="key" type="java.lang.String">
</parameter>
</method>
<method name="cursorDoubleToContentValuesIfPresent"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="cursor" type="android.database.Cursor">
</parameter>
<parameter name="values" type="android.content.ContentValues">
</parameter>
<parameter name="column" type="java.lang.String">
</parameter>
</method>
<method name="cursorDoubleToCursorValues"
 return="void"
 abstract="false"
@@ -49357,6 +49529,23 @@
<parameter name="values" type="android.content.ContentValues">
</parameter>
</method>
<method name="cursorFloatToContentValuesIfPresent"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="cursor" type="android.database.Cursor">
</parameter>
<parameter name="values" type="android.content.ContentValues">
</parameter>
<parameter name="column" type="java.lang.String">
</parameter>
</method>
<method name="cursorIntToContentValues"
 return="void"
 abstract="false"
@@ -49393,6 +49582,23 @@
<parameter name="key" type="java.lang.String">
</parameter>
</method>
<method name="cursorIntToContentValuesIfPresent"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="cursor" type="android.database.Cursor">
</parameter>
<parameter name="values" type="android.content.ContentValues">
</parameter>
<parameter name="column" type="java.lang.String">
</parameter>
</method>
<method name="cursorLongToContentValues"
 return="void"
 abstract="false"
@@ -49429,6 +49635,23 @@
<parameter name="key" type="java.lang.String">
</parameter>
</method>
<method name="cursorLongToContentValuesIfPresent"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="cursor" type="android.database.Cursor">
</parameter>
<parameter name="values" type="android.content.ContentValues">
</parameter>
<parameter name="column" type="java.lang.String">
</parameter>
</method>
<method name="cursorRowToContentValues"
 return="void"
 abstract="false"
@@ -49444,6 +49667,23 @@
<parameter name="values" type="android.content.ContentValues">
</parameter>
</method>
<method name="cursorShortToContentValuesIfPresent"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="cursor" type="android.database.Cursor">
</parameter>
<parameter name="values" type="android.content.ContentValues">
</parameter>
<parameter name="column" type="java.lang.String">
</parameter>
</method>
<method name="cursorStringToContentValues"
 return="void"
 abstract="false"
@@ -49480,6 +49720,23 @@
<parameter name="key" type="java.lang.String">
</parameter>
</method>
<method name="cursorStringToContentValuesIfPresent"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="cursor" type="android.database.Cursor">
</parameter>
<parameter name="values" type="android.content.ContentValues">
</parameter>
<parameter name="column" type="java.lang.String">
</parameter>
</method>
<method name="cursorStringToInsertHelper"
 return="void"
 abstract="false"
@@ -123844,6 +124101,19 @@
</implements>
<implements name="android.provider.ContactsContract.SyncColumns">
</implements>
<method name="newEntityIterator"
 return="android.content.EntityIterator"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="cursor" type="android.database.Cursor">
</parameter>
</method>
<field name="CONTENT_ITEM_TYPE"
 type="java.lang.String"
 transient="false"
@@ -124662,6 +124932,19 @@
<parameter name="rawContactUri" type="android.net.Uri">
</parameter>
</method>
<method name="newEntityIterator"
 return="android.content.EntityIterator"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="cursor" type="android.database.Cursor">
</parameter>
</method>
<field name="AGGREGATION_MODE_DEFAULT"
 type="int"
 transient="false"
+0 −121
Original line number Diff line number Diff line
package android.content;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.RemoteException;

/**
 * An abstract class that makes it easy to implement an EntityIterator over a cursor.
 * The user must implement {@link #newEntityFromCursorLocked}, which runs inside of a
 * database transaction.
 * @hide
 */
public abstract class AbstractCursorEntityIterator implements EntityIterator {
    private final Cursor mEntityCursor;
    private final SQLiteDatabase mDb;
    private volatile Entity mNextEntity;
    private volatile boolean mIsClosed;

    public AbstractCursorEntityIterator(SQLiteDatabase db, Cursor entityCursor) {
        mEntityCursor = entityCursor;
        mDb = db;
        mNextEntity = null;
        mIsClosed = false;
    }

    /**
     * If there are entries left in the cursor then advance the cursor and use the new row to
     * populate mNextEntity. If the cursor is at the end or if advancing it causes the cursor
     * to become at the end then set mEntityCursor to null. If newEntityFromCursor returns null
     * then continue advancing until it either returns a non-null Entity or the cursor reaches
     * the end.
     */
    private void fillEntityIfAvailable() {
        while (mNextEntity == null) {
            if (!mEntityCursor.moveToNext()) {
                // the cursor is at then end, bail out
                return;
            }
            // This may return null if newEntityFromCursor is not able to create an entity
            // from the current cursor position. In that case this method will loop and try
            // the next cursor position
            mNextEntity = newEntityFromCursorLocked(mEntityCursor);
        }
        mDb.beginTransaction();
        try {
            int position = mEntityCursor.getPosition();
            mNextEntity = newEntityFromCursorLocked(mEntityCursor);
            int newPosition = mEntityCursor.getPosition();
            if (newPosition != position) {
                throw new IllegalStateException("the cursor position changed during the call to"
                        + "newEntityFromCursorLocked, from " + position + " to " + newPosition);
            }
        } finally {
            mDb.endTransaction();
        }
    }

    /**
     * Checks if there are more Entities accessible via this iterator. This may not be called
     * if the iterator is already closed.
     * @return true if the call to next() will return an Entity.
     */
    public boolean hasNext() {
        if (mIsClosed) {
            throw new IllegalStateException("calling hasNext() when the iterator is closed");
        }
        fillEntityIfAvailable();
        return mNextEntity != null;
    }

    /**
     * Returns the next Entity that is accessible via this iterator. This may not be called
     * if the iterator is already closed.
     * @return the next Entity that is accessible via this iterator
     */
    public Entity next() {
        if (mIsClosed) {
            throw new IllegalStateException("calling next() when the iterator is closed");
        }
        if (!hasNext()) {
            throw new IllegalStateException("you may only call next() if hasNext() is true");
        }

        try {
            return mNextEntity;
        } finally {
            mNextEntity = null;
        }
    }

    public void reset() throws RemoteException {
        if (mIsClosed) {
            throw new IllegalStateException("calling reset() when the iterator is closed");
        }
        mEntityCursor.moveToPosition(-1);
        mNextEntity = null;
    }

    /**
     * Closes this iterator making it invalid. If is invalid for the user to call any public
     * method on the iterator once it has been closed.
     */
    public void close() {
        if (mIsClosed) {
            throw new IllegalStateException("closing when already closed");
        }
        mIsClosed = true;
        mEntityCursor.close();
    }

    /**
     * Returns a new Entity from the current cursor position. This is called from within a
     * database transaction. If a new entity cannot be created from this cursor position (e.g.
     * if the row that is referred to no longer exists) then this may return null. The cursor
     * is guaranteed to be pointing to a valid row when this call is made. The implementation
     * of newEntityFromCursorLocked is not allowed to change the position of the cursor.
     * @param cursor from where to read the data for the Entity
     * @return an Entity that corresponds to the current cursor position or null
     */
    public abstract Entity newEntityFromCursorLocked(Cursor cursor);
}
+0 −68
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ public abstract class AsyncQueryHandler extends Handler {
    private static final int EVENT_ARG_INSERT = 2;
    private static final int EVENT_ARG_UPDATE = 3;
    private static final int EVENT_ARG_DELETE = 4;
    private static final int EVENT_ARG_QUERY_ENTITIES = 5;

    /* package */ final WeakReference<ContentResolver> mResolver;

@@ -93,18 +92,6 @@ public abstract class AsyncQueryHandler extends Handler {
                    args.result = cursor;
                    break;

                case EVENT_ARG_QUERY_ENTITIES:
                    EntityIterator iterator = null;
                    try {
                        iterator = resolver.queryEntities(args.uri, args.selection,
                                args.selectionArgs, args.orderBy);
                    } catch (Exception e) {
                        Log.w(TAG, e.toString());
                    }

                    args.result = iterator;
                    break;

                case EVENT_ARG_INSERT:
                    args.result = resolver.insert(args.uri, args.values);
                    break;
@@ -194,45 +181,6 @@ public abstract class AsyncQueryHandler extends Handler {
        mWorkerThreadHandler.sendMessage(msg);
    }

    /**
     * This method begins an asynchronous query for an {@link EntityIterator}.
     * When the query is done {@link #onQueryEntitiesComplete} is called.
     *
     * @param token A token passed into {@link #onQueryComplete} to identify the
     *            query.
     * @param cookie An object that gets passed into {@link #onQueryComplete}
     * @param uri The URI, using the content:// scheme, for the content to
     *            retrieve.
     * @param selection A filter declaring which rows to return, formatted as an
     *            SQL WHERE clause (excluding the WHERE itself). Passing null
     *            will return all rows for the given URI.
     * @param selectionArgs You may include ?s in selection, which will be
     *            replaced by the values from selectionArgs, in the order that
     *            they appear in the selection. The values will be bound as
     *            Strings.
     * @param orderBy How to order the rows, formatted as an SQL ORDER BY clause
     *            (excluding the ORDER BY itself). Passing null will use the
     *            default sort order, which may be unordered.
     * @hide
     */
    public void startQueryEntities(int token, Object cookie, Uri uri, String selection,
            String[] selectionArgs, String orderBy) {
        // Use the token as what so cancelOperations works properly
        Message msg = mWorkerThreadHandler.obtainMessage(token);
        msg.arg1 = EVENT_ARG_QUERY_ENTITIES;

        WorkerArgs args = new WorkerArgs();
        args.handler = this;
        args.uri = uri;
        args.selection = selection;
        args.selectionArgs = selectionArgs;
        args.orderBy = orderBy;
        args.cookie = cookie;
        msg.obj = args;

        mWorkerThreadHandler.sendMessage(msg);
    }

    /**
     * Attempts to cancel operation that has not already started. Note that
     * there is no guarantee that the operation will be canceled. They still may
@@ -339,18 +287,6 @@ public abstract class AsyncQueryHandler extends Handler {
        // Empty
    }

    /**
     * Called when an asynchronous query is completed.
     *
     * @param token The token to identify the query.
     * @param cookie The cookie object.
     * @param iterator The iterator holding the query results.
     * @hide
     */
    protected void onQueryEntitiesComplete(int token, Object cookie, EntityIterator iterator) {
        // Empty
    }

    /**
     * Called when an asynchronous insert is completed.
     *
@@ -408,10 +344,6 @@ public abstract class AsyncQueryHandler extends Handler {
                onQueryComplete(token, args.cookie, (Cursor) args.result);
                break;

            case EVENT_ARG_QUERY_ENTITIES:
                onQueryEntitiesComplete(token, args.cookie, (EntityIterator)args.result);
                break;

            case EVENT_ARG_INSERT:
                onInsertComplete(token, args.cookie, (Uri) args.result);
                break;
+1 −18
Original line number Diff line number Diff line
@@ -163,15 +163,6 @@ public abstract class ContentProvider implements ComponentCallbacks {
                    selectionArgs, sortOrder);
        }

        /**
         * @hide
         */
        public EntityIterator queryEntities(Uri uri, String selection, String[] selectionArgs,
                String sortOrder) {
            enforceReadPermission(uri);
            return ContentProvider.this.queryEntities(uri, selection, selectionArgs, sortOrder);
        }

        public String getType(Uri uri) {
            return ContentProvider.this.getType(uri);
        }
@@ -476,14 +467,6 @@ public abstract class ContentProvider implements ComponentCallbacks {
    public abstract Cursor query(Uri uri, String[] projection,
            String selection, String[] selectionArgs, String sortOrder);

    /**
     * @hide
     */
    public EntityIterator queryEntities(Uri uri, String selection, String[] selectionArgs,
            String sortOrder) {
        throw new UnsupportedOperationException();
    }

    /**
     * Return the MIME type of the data at the given URI. This should start with
     * <code>vnd.android.cursor.item</code> for a single record,
@@ -581,7 +564,7 @@ public abstract class ContentProvider implements ComponentCallbacks {
    /**
     * Open a file blob associated with a content URI.
     * This method can be called from multiple
     * threads, as described inentity
     * threads, as described in
     * <a href="{@docRoot}guide/topics/fundamentals.html#procthread">Application Fundamentals:
     * Processes and Threads</a>.
     * 
+1 −10
Original line number Diff line number Diff line
@@ -89,15 +89,6 @@ public class ContentProviderClient {
        return mContentProvider.openAssetFile(url, mode);
    }

    /**
     * see {@link ContentProvider#queryEntities}
     * @hide
     */
    public EntityIterator queryEntities(Uri uri, String selection, String[] selectionArgs,
            String sortOrder) throws RemoteException {
        return mContentProvider.queryEntities(uri, selection, selectionArgs, sortOrder);
    }

     /** see {@link ContentProvider#applyBatch} */
    public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
            throws RemoteException, OperationApplicationException {
Loading