SQLite Android Bindings
Check-in [59f9c6ccd7]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add local versions of classes CancellationSignal and OperationCanceledExcecption so that this code will work with API level 15.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | api-level-15
Files: files | file ages | folders
SHA1:59f9c6ccd75272f6eae3799cb3ebe5d0a6024d33
User & Date: dan 2014-05-21 16:54:45
Context
2014-05-21
18:17
Merge documentation updates with this branch. check-in: 49c7a766e1 user: dan tags: api-level-15
16:54
Add local versions of classes CancellationSignal and OperationCanceledExcecption so that this code will work with API level 15. check-in: 59f9c6ccd7 user: dan tags: api-level-15
2014-01-07
02:22
Add the "expand" query parameter to the tree-view of the files to be copied into a new project. check-in: ed5126e673 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to AndroidManifest.xml.

     8      8                     android:label="@string/app_name">
     9      9               <intent-filter>
    10     10                   <action android:name="android.intent.action.MAIN" />
    11     11                   <category android:name="android.intent.category.LAUNCHER" />
    12     12               </intent-filter>
    13     13           </activity>
    14     14       </application>
           15  +<uses-sdk android:minSdkVersion="15"
           16  +          android:targetSdkVersion="15"
           17  +          android:maxSdkVersion="15" />
           18  +
    15     19   </manifest>

Changes to local.properties.

     3      3   #
     4      4   # This file must *NOT* be checked into Version Control Systems,
     5      5   # as it contains information specific to your local configuration.
     6      6   
     7      7   # location of the SDK. This is only used by Ant
     8      8   # For customization when using a Version Control System, please read the
     9      9   # header note.
    10         -sdk.dir=/home/dan/android2/adt-bundle-linux-x86-20131030/sdk
           10  +sdk.dir=/home/dan/adt-bundle-linux-x86-20131030/sdk

Changes to project.properties.

     7      7   # "ant.properties", and override values to adapt the script to your
     8      8   # project structure.
     9      9   #
    10     10   # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
    11     11   #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
    12     12   
    13     13   # Project target.
    14         -target=android-19
           14  +target=android-15

Changes to src/org/sqlite/database/sqlite/ExtraUtils.java.

    32     32   import org.sqlite.database.sqlite.SQLiteDatabase;
    33     33   import org.sqlite.database.sqlite.SQLiteDatabaseCorruptException;
    34     34   import org.sqlite.database.sqlite.SQLiteDiskIOException;
    35     35   import org.sqlite.database.sqlite.SQLiteException;
    36     36   import org.sqlite.database.sqlite.SQLiteFullException;
    37     37   import org.sqlite.database.sqlite.SQLiteProgram;
    38     38   import org.sqlite.database.sqlite.SQLiteStatement;
    39         -import android.os.OperationCanceledException;
           39  +import org.sqlite.os.OperationCanceledException;
    40     40   import android.os.Parcel;
    41     41   import android.os.ParcelFileDescriptor;
    42     42   import android.text.TextUtils;
    43     43   import android.util.Log;
    44     44   
    45     45   import java.io.FileNotFoundException;
    46     46   import java.io.PrintStream;

Changes to src/org/sqlite/database/sqlite/SQLiteConnection.java.

    24     24   import dalvik.system.CloseGuard;
    25     25   
    26     26   import android.database.Cursor;
    27     27   import android.database.CursorWindow;
    28     28   import android.database.DatabaseUtils;
    29     29   import org.sqlite.database.ExtraUtils;
    30     30   import org.sqlite.database.sqlite.SQLiteDebug.DbStats;
    31         -import android.os.CancellationSignal;
    32         -import android.os.OperationCanceledException;
           31  +import org.sqlite.os.CancellationSignal;
           32  +import org.sqlite.os.OperationCanceledException;
    33     33   import android.os.ParcelFileDescriptor;
    34     34   import android.util.Log;
    35     35   import android.util.LruCache;
    36     36   import android.util.Printer;
    37     37   
    38     38   import java.text.SimpleDateFormat;
    39     39   import java.util.ArrayList;

Changes to src/org/sqlite/database/sqlite/SQLiteConnectionPool.java.

    19     19   */
    20     20   
    21     21   package org.sqlite.database.sqlite;
    22     22   
    23     23   import dalvik.system.CloseGuard;
    24     24   
    25     25   import org.sqlite.database.sqlite.SQLiteDebug.DbStats;
    26         -import android.os.CancellationSignal;
    27         -import android.os.OperationCanceledException;
           26  +import org.sqlite.os.CancellationSignal;
           27  +import org.sqlite.os.OperationCanceledException;
    28     28   import android.os.SystemClock;
    29     29   import android.util.Log;
    30     30   /* import android.util.PrefixPrinter; */
    31     31   import android.util.Printer;
    32     32   
    33     33   import java.io.Closeable;
    34     34   import java.util.ArrayList;

Changes to src/org/sqlite/database/sqlite/SQLiteDatabase.java.

    24     24   import android.database.Cursor;
    25     25   import org.sqlite.database.DatabaseErrorHandler;
    26     26   import android.database.DatabaseUtils;
    27     27   import org.sqlite.database.ExtraUtils;
    28     28   import org.sqlite.database.DefaultDatabaseErrorHandler;
    29     29   import org.sqlite.database.SQLException;
    30     30   import org.sqlite.database.sqlite.SQLiteDebug.DbStats;
    31         -import android.os.CancellationSignal;
           31  +import org.sqlite.os.CancellationSignal;
    32     32   import android.os.Looper;
    33         -import android.os.OperationCanceledException;
           33  +import org.sqlite.os.OperationCanceledException;
    34     34   import android.text.TextUtils;
    35     35   import android.util.EventLog;
    36     36   import android.util.Log;
    37     37   import android.util.Pair;
    38     38   import android.util.Printer;
    39     39   
    40     40   import dalvik.system.CloseGuard;

Changes to src/org/sqlite/database/sqlite/SQLiteDirectCursorDriver.java.

    18     18   ** sqlite-dev@sqlite.org.
    19     19   */
    20     20   
    21     21   package org.sqlite.database.sqlite;
    22     22   
    23     23   import android.database.Cursor;
    24     24   import org.sqlite.database.sqlite.SQLiteDatabase.CursorFactory;
    25         -import android.os.CancellationSignal;
           25  +import org.sqlite.os.CancellationSignal;
    26     26   
    27     27   /**
    28     28    * A cursor driver that uses the given query directly.
    29     29    * 
    30     30    * @hide
    31     31    */
    32     32   public final class SQLiteDirectCursorDriver implements SQLiteCursorDriver {

Changes to src/org/sqlite/database/sqlite/SQLiteProgram.java.

    17     17   ** Modified to support SQLite extensions by the SQLite developers: 
    18     18   ** sqlite-dev@sqlite.org.
    19     19   */
    20     20   
    21     21   package org.sqlite.database.sqlite;
    22     22   
    23     23   import android.database.DatabaseUtils;
    24         -import android.os.CancellationSignal;
           24  +import org.sqlite.os.CancellationSignal;
    25     25   
    26     26   import java.util.Arrays;
    27     27   
    28     28   /**
    29     29    * A base class for compiled SQLite programs.
    30     30    * <p>
    31     31    * This class is not thread-safe.

Changes to src/org/sqlite/database/sqlite/SQLiteQuery.java.

    17     17   ** Modified to support SQLite extensions by the SQLite developers: 
    18     18   ** sqlite-dev@sqlite.org.
    19     19   */
    20     20   
    21     21   package org.sqlite.database.sqlite;
    22     22   
    23     23   import android.database.CursorWindow;
    24         -import android.os.CancellationSignal;
    25         -import android.os.OperationCanceledException;
           24  +import org.sqlite.os.CancellationSignal;
           25  +import org.sqlite.os.OperationCanceledException;
    26     26   import android.util.Log;
    27     27   
    28     28   /**
    29     29    * Represents a query that reads the resulting rows into a {@link SQLiteQuery}.
    30     30    * This class is used by {@link SQLiteCursor} and isn't useful itself.
    31     31    * <p>
    32     32    * This class is not thread-safe.

Changes to src/org/sqlite/database/sqlite/SQLiteQueryBuilder.java.

    18     18   ** sqlite-dev@sqlite.org.
    19     19   */
    20     20   
    21     21   package org.sqlite.database.sqlite;
    22     22   
    23     23   import android.database.Cursor;
    24     24   import android.database.DatabaseUtils;
    25         -import android.os.CancellationSignal;
    26         -import android.os.OperationCanceledException;
           25  +import org.sqlite.os.CancellationSignal;
           26  +import org.sqlite.os.OperationCanceledException;
    27     27   import android.provider.BaseColumns;
    28     28   import android.text.TextUtils;
    29     29   import android.util.Log;
    30     30   
    31     31   import java.util.Iterator;
    32     32   import java.util.Map;
    33     33   import java.util.Map.Entry;

Changes to src/org/sqlite/database/sqlite/SQLiteSession.java.

    18     18   ** sqlite-dev@sqlite.org.
    19     19   */
    20     20   
    21     21   package org.sqlite.database.sqlite;
    22     22   
    23     23   import android.database.CursorWindow;
    24     24   import android.database.DatabaseUtils;
    25         -import android.os.CancellationSignal;
    26         -import android.os.OperationCanceledException;
           25  +import org.sqlite.os.CancellationSignal;
           26  +import org.sqlite.os.OperationCanceledException;
    27     27   import android.os.ParcelFileDescriptor;
    28     28   
    29     29   /**
    30     30    * Provides a single client the ability to use a database.
    31     31    *
    32     32    * <h2>About database sessions</h2>
    33     33    * <p>

Added src/org/sqlite/os/CancellationSignal.java.

            1  +/*
            2  + * Copyright (C) 2012 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  +** Modified to support SQLite extensions by the SQLite developers: 
           18  +** sqlite-dev@sqlite.org.
           19  +*/
           20  +
           21  +package org.sqlite.os;
           22  +
           23  +import org.sqlite.os.ICancellationSignal;
           24  +import android.os.RemoteException;
           25  +
           26  +/**
           27  + * Provides the ability to cancel an operation in progress.
           28  + */
           29  +public final class CancellationSignal {
           30  +    private boolean mIsCanceled;
           31  +    private OnCancelListener mOnCancelListener;
           32  +    private ICancellationSignal mRemote;
           33  +    private boolean mCancelInProgress;
           34  +
           35  +    /**
           36  +     * Creates a cancellation signal, initially not canceled.
           37  +     */
           38  +    public CancellationSignal() {
           39  +    }
           40  +
           41  +    /**
           42  +     * Returns true if the operation has been canceled.
           43  +     *
           44  +     * @return True if the operation has been canceled.
           45  +     */
           46  +    public boolean isCanceled() {
           47  +        synchronized (this) {
           48  +            return mIsCanceled;
           49  +        }
           50  +    }
           51  +
           52  +    /**
           53  +     * Throws {@link OperationCanceledException} if the operation has been canceled.
           54  +     *
           55  +     * @throws OperationCanceledException if the operation has been canceled.
           56  +     */
           57  +    public void throwIfCanceled() {
           58  +        if (isCanceled()) {
           59  +            throw new OperationCanceledException();
           60  +        }
           61  +    }
           62  +
           63  +    /**
           64  +     * Cancels the operation and signals the cancellation listener.
           65  +     * If the operation has not yet started, then it will be canceled as soon as it does.
           66  +     */
           67  +    public void cancel() {
           68  +        final OnCancelListener listener;
           69  +        final ICancellationSignal remote;
           70  +        synchronized (this) {
           71  +            if (mIsCanceled) {
           72  +                return;
           73  +            }
           74  +            mIsCanceled = true;
           75  +            mCancelInProgress = true;
           76  +            listener = mOnCancelListener;
           77  +            remote = mRemote;
           78  +        }
           79  +
           80  +        try {
           81  +            if (listener != null) {
           82  +                listener.onCancel();
           83  +            }
           84  +            if (remote != null) {
           85  +                try {
           86  +                    remote.cancel();
           87  +                } catch (RemoteException ex) {
           88  +                }
           89  +            }
           90  +        } finally {
           91  +            synchronized (this) {
           92  +                mCancelInProgress = false;
           93  +                notifyAll();
           94  +            }
           95  +        }
           96  +    }
           97  +
           98  +    /**
           99  +     * Sets the cancellation listener to be called when canceled.
          100  +     *
          101  +     * This method is intended to be used by the recipient of a cancellation signal
          102  +     * such as a database or a content provider to handle cancellation requests
          103  +     * while performing a long-running operation.  This method is not intended to be
          104  +     * used by applications themselves.
          105  +     *
          106  +     * If {@link CancellationSignal#cancel} has already been called, then the provided
          107  +     * listener is invoked immediately.
          108  +     *
          109  +     * This method is guaranteed that the listener will not be called after it
          110  +     * has been removed.
          111  +     *
          112  +     * @param listener The cancellation listener, or null to remove the current listener.
          113  +     */
          114  +    public void setOnCancelListener(OnCancelListener listener) {
          115  +        synchronized (this) {
          116  +            waitForCancelFinishedLocked();
          117  +
          118  +            if (mOnCancelListener == listener) {
          119  +                return;
          120  +            }
          121  +            mOnCancelListener = listener;
          122  +            if (!mIsCanceled || listener == null) {
          123  +                return;
          124  +            }
          125  +        }
          126  +        listener.onCancel();
          127  +    }
          128  +
          129  +    /**
          130  +     * Sets the remote transport.
          131  +     *
          132  +     * If {@link CancellationSignal#cancel} has already been called, then the provided
          133  +     * remote transport is canceled immediately.
          134  +     *
          135  +     * This method is guaranteed that the remote transport will not be called after it
          136  +     * has been removed.
          137  +     *
          138  +     * @param remote The remote transport, or null to remove.
          139  +     *
          140  +     * @hide
          141  +     */
          142  +    public void setRemote(ICancellationSignal remote) {
          143  +        synchronized (this) {
          144  +            waitForCancelFinishedLocked();
          145  +
          146  +            if (mRemote == remote) {
          147  +                return;
          148  +            }
          149  +            mRemote = remote;
          150  +            if (!mIsCanceled || remote == null) {
          151  +                return;
          152  +            }
          153  +        }
          154  +        try {
          155  +            remote.cancel();
          156  +        } catch (RemoteException ex) {
          157  +        }
          158  +    }
          159  +
          160  +    private void waitForCancelFinishedLocked() {
          161  +        while (mCancelInProgress) {
          162  +            try {
          163  +                wait();
          164  +            } catch (InterruptedException ex) {
          165  +            }
          166  +        }
          167  +    }
          168  +
          169  +    /**
          170  +     * Creates a transport that can be returned back to the caller of
          171  +     * a Binder function and subsequently used to dispatch a cancellation signal.
          172  +     *
          173  +     * @return The new cancellation signal transport.
          174  +     *
          175  +     * @hide
          176  +     */
          177  +    public static ICancellationSignal createTransport() {
          178  +        return new Transport();
          179  +    }
          180  +
          181  +    /**
          182  +     * Given a locally created transport, returns its associated cancellation signal.
          183  +     *
          184  +     * @param transport The locally created transport, or null if none.
          185  +     * @return The associated cancellation signal, or null if none.
          186  +     *
          187  +     * @hide
          188  +     */
          189  +    public static CancellationSignal fromTransport(ICancellationSignal transport) {
          190  +        if (transport instanceof Transport) {
          191  +            return ((Transport)transport).mCancellationSignal;
          192  +        }
          193  +        return null;
          194  +    }
          195  +
          196  +    /**
          197  +     * Listens for cancellation.
          198  +     */
          199  +    public interface OnCancelListener {
          200  +        /**
          201  +         * Called when {@link CancellationSignal#cancel} is invoked.
          202  +         */
          203  +        void onCancel();
          204  +    }
          205  +
          206  +    private static final class Transport extends ICancellationSignal.Stub {
          207  +        final CancellationSignal mCancellationSignal = new CancellationSignal();
          208  +
          209  +        @Override
          210  +        public void cancel() throws RemoteException {
          211  +            mCancellationSignal.cancel();
          212  +        }
          213  +    }
          214  +}

Added src/org/sqlite/os/ICancellationSignal.aidl.

            1  +/*
            2  + * Copyright (C) 2012 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  +** Modified to support SQLite extensions by the SQLite developers: 
           18  +** sqlite-dev@sqlite.org.
           19  +*/
           20  +
           21  +package org.sqlite.os;
           22  +
           23  +/**
           24  + * @hide
           25  + */
           26  +interface ICancellationSignal {
           27  +    oneway void cancel();
           28  +}

Added src/org/sqlite/os/OperationCanceledException.java.

            1  +/*
            2  + * Copyright (C) 2012 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  +** Modified to support SQLite extensions by the SQLite developers: 
           18  +** sqlite-dev@sqlite.org.
           19  +*/
           20  +
           21  +package org.sqlite.os;
           22  +
           23  +
           24  +/**
           25  + * An exception type that is thrown when an operation in progress is canceled.
           26  + *
           27  + * @see CancellationSignal
           28  + */
           29  +public class OperationCanceledException extends RuntimeException {
           30  +    public OperationCanceledException() {
           31  +        this(null);
           32  +    }
           33  +
           34  +    public OperationCanceledException(String message) {
           35  +        super(message != null ? message : "The operation has been canceled.");
           36  +    }
           37  +}