Commit Graph

297 Commits

Author SHA1 Message Date
Jeff Brown
825c5132bf Add a CrossProcessCursorWrapper.
Bug: 5220669

The CrossProcessCursorWrapper is a useful building block
for wrapping cursors that will be sent to processes remotely.
It can also transform normal Cursors into CrossProcessCursors
transparently.

The new class fixes common performance problems and bugs
that applications have encountered when implementing
ContentProviders.

Change-Id: Icc59fec10add3f7d8cfbd0495447860c1872c752
2011-10-13 14:24:26 -07:00
Jeff Brown
b4009c7381 AbstractWindowedCursor is not special.
Use the CrossProcessCursor interface in the way it was intended
without introducing special cases for AbstractWindowedCursor.
This is possible now that we do not distinguish between local-only
and remotable CursorWindows so we don't need to provide a window
to the AbstractWindowedCursor for it to fill; it can provide one
for itself if it wants one.

This logic makes it possible to create CrossProcessCursor
implementations that perform just as well as AbstractWindowedCursors.

Change-Id: I764b25ee6311d28c50d1930705346b265faec86a
2011-10-13 14:17:24 -07:00
Jeff Brown
80e7b80fa6 Make default implementation of fillWindow typesafe.
Bug: 5218310

This change fixes problems calling the default fillWindow
on Cursors that contain BLOBs.  It should also be more efficient
by avoiding redundant string conversions for numeric datatypes.

Change-Id: Ied515bf6299bc8d3c14e76055d85fd35e7c05952
2011-10-12 22:19:42 -07:00
Jeff Brown
5e5d6d8ba0 Deprecate local-only CursorWindows.
There is no difference and has never really been a difference
between local-only and remotable CursorWindows.  By removing the
distinction officially in the API, we will make it easier to
implement CrossProcessCursor correctly.  CrossProcessCursor
is problematic currently because it's not clear whether a call
to getWindow() will return a local-only window or a remotable window.
As a result, the bulk cursor adaptor has special case handling
for AbstractWindowedCursors vs. ordinary CrossProcessCursors
so that it can set a remotable window before the cursor fills it.
All these problems go away if we just forget about local-only
windows being special in any way.

Change-Id: Ie59f517968e33d0ecb239c3c4f60206495e8f376
2011-10-12 22:19:41 -07:00
Jeff Brown
0cde89f5f0 Use ashmem for CursorWindows.
Bug: 5332296

The memory dealer introduces additional delays for reclaiming
the memory owned by CursorWindows because the Binder object must
be finalized.  Using ashmem instead gives CursorWindow more
direct control over the lifetime of the shared memory region.

The provider now allocates the CursorWindows and returns them
to clients with a read-only protection bit set on the ashmem
region.

Improved the encapsulation of CursorWindow.  Callers shouldn't
need to care about details like how string fields are allocated.

Removed the compile-time configuration of string and numeric
storage modes to remove some dead weight.

Change-Id: I07c2bc2a9c573d7e435dcaecd269d25ea9807acd
2011-10-11 11:03:19 -07:00
Jeff Brown
d2183654e0 Fix ownership of CursorWindows across processes.
Bug: 5332296

Ensure that there is always an owner for each CursorWindow
and that references to each window are acquired/released
appropriately at all times.

Added synchronization to CursorToBulkCursorAdaptor to
prevent the underlying Cursor and CursorWindow from being
remotely accessed in ways that might violate invariants,
resulting in leaks or other problems.

Ensured that CursorToBulkCursorAdaptor promptly releases
its references to the Cursor and CursorWindow when closed
so they don't stick around longer than they should, even
if the remote end hangs onto the IBulkCursor for some reason.

CursorWindow respects Parcelable.FLAG_WRITE_RETURN_VALUE
as an indication that one reference to the CursorWindow is
being released.  Correspondingly, CursorToBulkCursorAdaptor
acquires a reference to the CursorWindow before returning
it to the caller.  This change also prevents races from
resulting in the transfer of an invalid CursorWindow over
the wire.

Ensured that BulkCursorToCursorAdaptor promptly releases
its reference to the IBulkCursor when closed and throws
on attempts to access the cursor while closed.

Modified ContentProviderNative to handle both parts of
the wrapping and unwrapping of Cursors into IBulkCursors.
This makes it a lot easier to ensure that the right
things happen on both ends.  Also, it turns out that
the only caller of IContentProvider.bulkQuery was
ContentProviderNative itself so there was no need
to support bulkQuery on ContentProviderProxy and it was
just getting in the way.

Implement CloseGuard on CursorWindow.

Change-Id: Ib3c8305d3cc62322f38a06698d404a2989bb6ef9
2011-10-09 22:10:36 -07:00
Jeff Brown
df6611d8c0 Clean up handrolled Binder proxies.
Bug: 5332296

We can't replace these with AIDL generated proxies just yet, but
at least we can make them a little more conformant.

Change-Id: I1814f76d0f9c5e44a7fd85a12b2e3c2b7e3c9daa
2011-10-09 13:00:35 -07:00
Jeff Brown
270928bd4a Merge changes Idbfeb3cc,I03e8e2e7,Iff9eed78
* changes:
  Fix regression in CursorWindow.getString() Bug: 5332296
  Clean up CursorWindow lifetime. Bug: 5332296
  Fix regression in CursorWindow.copyStingToBuffer. Bug: 5332296
2011-10-07 15:08:24 -07:00
Jeff Brown
7ce745248d Clean up CursorWindow lifetime.
Bug: 5332296

Removed dead code in SQLiteCursor related to the use of a background
query thread.  This code could result in CursorWindows being modified
concurrently or used after free.  This code is broken, unused and
is just in the way.

Added comments to explain how CursorWindow ownership is
supposed to work for AbstractWindowedCursors.  (There are still cases
where cursor windows get dropped on the floor without being closed.
Those will be taken care of in a subsequent patch.)

Cleaned up SQLiteQuery.fillWindow to eliminate duplicate code and
remove bits that were only needed for background loading, like
returning -1.

Change-Id: I03e8e2e73ff0c11df76d63f57df4c5ada06ae1cb
2011-10-07 13:31:00 -07:00
Jeff Brown
f0a9181d09 Merge "Clean up CursorWindow code. Bug: 5332296" 2011-10-06 16:28:15 -07:00
Jeff Brown
3bc6bbc92c Clean up CursorWindow code.
Bug: 5332296

The code is functionally equivalent, but a little more efficient
and much easier to maintain.

Change-Id: I90670a13799df05831843a5137ab234929281b7c
2011-10-06 14:40:13 -07:00
Christopher Tate
ad9e8b1a87 Disable db_sample logging
db_sample logging is thrashing the event log hard, and is currently
neither maintained nor heeded by anybody on the current release.  It
can be re-enabled simply by throwing the appropriate static boolean
to 'true', but for now this should greatly improve the utility of our
event logs.  (We were seeing a rollover period of 20 minutes or less;
ideally we want to see the event log run at least half a day before
rolling.)

Bug 5419627
Bug 5104300

Change-Id: I2125544130aae142974102dbad3b557e49fcd494
2011-10-05 17:49:26 -07:00
Makoto Onuki
630f6b1cf8 Add AbstractCursor.setExtras()
This allows providers to return SQLiteCursor with a bundle, without wrapping
it in a CursorWrapper, which has performance penalty on cross-process
queries.

Bug 5220669

Change-Id: I46b9dfb3d8e01e9caf080bb24acfd97551441e25
2011-08-31 14:17:55 -07:00
Dianne Hackborn
661cd52e0e Add progress dialog for booting after an upgrade.
This introduces a new facility for code during the boot process
to display messages to the user through a progress dialog.  This
is only for use when performing longer-than-usual post-upgrade
operations such as running dexopt on applications or upgrading
databases.

Change-Id: I0e78439ccec3850fb67872c22f235bf12a158dae
2011-08-22 13:42:05 -07:00
Todd Kennedy
783123f79d Add getBlob() to MatrixCursor
Change-Id: I1abfd2fd117a2a31f99e77bd0b395c4ad0cfc6d2
2011-07-19 10:33:41 -07:00
Daniel Lehmann
9f66c650b0 Remove the obsolete function that is not used anymore
Change-Id: I749d4bdba68edb87fe7eb24095e70b544da00c71
2011-06-01 20:40:50 -07:00
Daniel Lehmann
50b1f8d3fc Enable strict mode as a public api to catch sql injections
Bug: 4368912
Change-Id: Ia4919f58cc5264da8758d6cd61d93e031676b74a
2011-06-01 15:24:23 -07:00
Joe Onorato
43a17654cf Remove the deprecated things from Config.java. These haven't been working since before 1.0.
Change-Id: Ic2e8fa68797ea9d486f4117f3d82c98233cdab1e
2011-04-07 19:23:05 -07:00
Vasu Nori
cc1eaf6f7b bug:4090903 allow bindargs on attach database statement
code incorrectly assumed that certain statements (like ATTACH DATABASE)
will never have bindargs.

Change-Id: I62eddbdf8e15947e8debf5052c7248113a3b9b57
2011-03-21 16:02:25 -07:00
Vasu Nori
16057fad00 fix broken logTimeStat stuff
log time in the following 2 situations
1. all transactions. time measured = wall time between begin-commit
2. queries (which are not in tranactions)

Change-Id: I67be9487a96072695aff3529ba4a257f4c8ec596
2011-03-18 16:10:39 -07:00
Vasu Nori
d6c367f424 cosmetic fixes: removing unused members/imports
Change-Id: I307e5d5c7c1270d2590ba66f4c3d3b1a96646344
2011-03-01 18:37:52 -08:00
Vasu Nori
8a358a7eed bug:3497143 don't print warning if it is a bug in platform - not in app.
fixing a couple of very confusing warnings..

Change-Id: I3c91fa53fc73a2fb4bee213e33af56c4bdb75fd8
2011-03-01 18:22:31 -08:00
Jesse Wilson
32c80a27da Handle rename of LruCache.entryEvicted to entryRemoved
Change-Id: I50e5a8d8c35c4431f42c7483172447ba0e4e125b
http://b/3461302
2011-02-25 17:28:41 -08:00
Paul Westbrook
dae6d3705d Revert "turn off sqlite WAL until bugs bug:3024421 and bug:3353077 are fixed"
This reverts commit d67dbeeb32.

This reenables WAL in the framework.  We are tracking down the cause of
the problems with WAL
2011-02-17 10:59:56 -08:00
Dmitri Plotnikov
06f992c6b0 Merge "Setting copiedSize to 0 when value is null" 2011-02-16 13:15:15 -08:00
Dmitri Plotnikov
9480efeff7 Setting copiedSize to 0 when value is null
Bug: 3457998
Change-Id: I01f6d02e76884639600c679518c5817ce73e0f23
2011-02-16 12:03:10 -08:00
Vasu Nori
c5d0fbbfdf Merge "add more debug info to help (bug:3446432)" 2011-02-11 16:57:40 -08:00
Vasu Nori
e9714e6c74 add more debug info to help (bug:3446432)
Change-Id: I4a690297ae7f18d5f6928ac5c67d8d4164453fa0
2011-02-11 16:50:51 -08:00
Jesse Wilson
dfe515e49a Remove LruCache.setMaxSize().
Dynamically changing a max cache size is clumsy; almost everyone
should set this when they create the cache.

Fix SQLiteDatabase to copy entries into a new cache when the size
is changed. In pratice this will always be immediately after the
SQLiteDatabase is created. Since the cache field is no longer
final, change the guard on the cache field to the SQLiteDatabase
instance itself.

Change-Id: I4e325f06edc551636723568a52770c0982e2d945
2011-02-11 11:35:22 -08:00
Jesse Wilson
c2c9a2492c Don't add setMaxSize() to the LruCache API. But do add maxSize().
Change-Id: I9697ab29491dabe85c2400defdde16b9abcd003a
2011-02-10 19:20:31 -08:00
Jesse Wilson
9b5a93550f Adopt LRU cache in SQLite.
Change-Id: I6b43dd8843d41726254bea3a175fe28f5f061ed7
http://b/3184897
2011-02-10 18:26:39 -08:00
Vasu Nori
d67dbeeb32 turn off sqlite WAL until bugs bug:3024421 and bug:3353077 are fixed
they are becoming pretty disruptive bugs.
many more instances of gmail crashing with locking protocol error.
and a positive identification of WAL as the problem in Music app
AND one instance of gmail crash that I know of.
who knows how many folks are NOT reporting the gmail crash.

too bad we relied on pre-released version sqlite feature
without seeing it complettly tested in the field.

not a safe feature to turn on at this point in time.
maybe more testing and debugging in Ice timeframe.

Change-Id: I283ad26ba7e1793772a372aa8e24df0cb96ce2ef
2011-02-09 10:52:51 -08:00
Vasu Nori
d4608a35e8 while waiting for lock, try in 30sec intervals and print warnings if no lock
should help a little bit in debugging deadlocks in the process.
especially when the an application does this:
  thread1: begin transaction
  thread2: synchronized void blahMethod { do some code; begintransaction;}
  thread1: with lock ion the database, it now tries to get into the above
           synchronized method
   thread2 has synchronized monitor and thred1 has db lock.
   each wants the other lock
 deadlock.
and our stacktraces will not tell us that thread1 has the database lock.

with this CL, we will know WHO owns the database lock and which thread
dies waiting for the lock.

Change-Id: If51578e7fa0a70ee3d762eb2233d1fddd98a2e86
2011-02-07 11:08:41 -08:00
Vasu Nori
83ff97d840 bug:3385018 don't print finalizer warnings under certain conditions
Change-Id: I06c49a464f61c26d3e6645a95f2dd38d444bf384
2011-01-30 14:42:36 -08:00
Vasu Nori
a017edace7 bug:3398527 return List insttead of ArrayList from public API
Change-Id: Idbdcb59fe860a9168c9ef6c00eb128b05fce84ff
2011-01-27 11:47:28 -08:00
Vasu Nori
4b92aeec3f bug:3396894 (HC branch) remove STOPSHIP code
Change-Id: Iad8790b7c2efa3a9b35e07429ea47d4e9f72081b
2011-01-26 23:24:05 -08:00
Vasu Nori
4caaf2aeca bug:3362394 better documentation for DefaultDatabaseErrorHandler class
Change-Id: I85a278183eda297f72a740c9d23efa4aca58d2d3
2011-01-17 15:35:28 -08:00
Vasu Nori
3045bbaf58 bug:3330569 print better message to help debug the problem
methods such as SQLiteStatement.simpleQueryForString() expect
one and only row to be returned when the query is executed.
if the application provides a query that doesn't return any data,
then the error message printed is pretty confusing.

make it less confusing and print the query itself to help debug
the error.

Change-Id: Ife2066f3a3eab0b98845a49e8f72b518458a7757
2011-01-10 15:37:47 -08:00
Dianne Hackborn
247fe74c93 Implement issue # 3255887 could CursorLoader offer...
...to throttle contentobserver-based requeries

Why yes, I guess it could.

This also reworks AsyncTaskLoader to not generate multiple
concurrent tasks if it is getting change notifications before
the last background task is complete.

And removes some of the old APIs that had been deprecated but
need to be gone for final release.

And fixes a few little problems with applying the wrong theme
in system code.

Change-Id: Ic7a665b666d0fb9d348e5f23595532191065884f
2011-01-08 18:25:30 -08:00
Vasu Nori
324dbe508e in requery(), when exception is caught, print warning + stacktrace
Change-Id: Ifa03e2c4bcf09fbba5ac028d4c7a74e092450612
2011-01-06 17:45:32 -08:00
Vasu Nori
ca74897b24 in GB requery() didn't throw exceptions (mostly). replicate that in HC
bug:3302851
Change-Id: I56e0bd178b200472cb1dbcbd2e80b844690b8964
2011-01-06 16:35:37 -08:00
Vasu Nori
42edf0f8cf Merge "requery() should close cursorwindow insead of setting it to null." into honeycomb 2011-01-06 11:37:00 -08:00
Vasu Nori
0e453d1115 requery() should close cursorwindow insead of setting it to null.
just in case GC takes a while to kick in.

Change-Id: I3a00b52afe1303be0c7d6bb561e5c07734e4dcb3
2011-01-06 09:52:51 -08:00
Vasu Nori
a22d88493e set default mode of WAL to be off.
apps will have to enable WAL explicitly.

Change-Id: Iba5c47a40f465e668ef0d538282230e99fe04ce6
2011-01-06 09:18:47 -08:00
Vasu Nori
6a904bc65e Revert "treat 'can't open database file error' as 'database corruption error'"
This reverts commit c7fe777d63.

Change-Id: I9992d404394917537d5c22470efbd970605976ed
2011-01-05 18:38:15 -08:00
Brad Fitzpatrick
70588bf864 resolved conflicts for merge of 3a2c6bf0 to master
Change-Id: I1963d8fc391bb84de1054f2b20ce4e082d764cbe
2011-01-05 14:04:06 -08:00
Brad Fitzpatrick
3a2c6bf0fc am 69ea4e15: Documentation fixes found over vacation hacking.
* commit '69ea4e15e52c456537575d21443ac1efdb03a902':
  Documentation fixes found over vacation hacking.
2011-01-05 13:52:53 -08:00
Brad Fitzpatrick
69ea4e15e5 Documentation fixes found over vacation hacking.
Change-Id: I28900026465d66d950cf4f05f0c202b46c3c2d43
2011-01-05 13:07:34 -08:00
Eric Hassold
a5af5d6b12 Add support for downgrading database version in SQLiteOpenHelper
Provide an API to allow application to support downgrade in databases
managed with SQLiteOpenHelper. Since onUpgrade() is now called only
if requested version is newer than current one, this adds support for
a similar onDowngrade() method, so customers can implement graceful
downgrading. If no downgrade method is implemented by caller, this
fallback to current behavior by throwing an exception.

Bug: 1609474
Change-Id: I0e0166984d4a700b1c43ce780b91244bc2fc87a6
2011-01-04 16:55:27 -08:00
Vasu Nori
c7fe777d63 treat "can't open database file error" as "database corruption error"
bug:3083665
if sqlite can't open the database, delete it and create a new one.
what else is sqlite supposed to do?

Change-Id: I8b7c3b051fd1a146e4026f8f8acfdd099f9a70cf
2011-01-04 14:36:16 -08:00