Commit Graph

458 Commits

Author SHA1 Message Date
Fyodor Kupolov
45be5633e9 Make SQLiteDirectCursorDriver @TestApi
Test: cts/SQLiteDatabaseTest+SQLiteOpenHelperTest
Bug: 64228388
Change-Id: Ic711069cfdc7df1affaecf26a3d01539f1a8e821
2017-08-08 16:55:03 -07:00
Fyodor Kupolov
76436c04a4 API Review update for SQLiteDatabase
SQLiteDatabase openDatabase -- should take File for first parameter
  instead of a String path

SQLiteDatabase.OpenParams.Builder -- make sure the javadocs says what
  the default openFlags is and default idle connection timeout

SQLiteDatabase createInMemory -- throw if it has trouble instead of
  returning null.

Test: cts/SQLiteDatabaseTest
Bug: 64331777
Bug: 64331778
Bug: 64330914

Change-Id: Ibecf4f4a6498795f9a5d12b94b77481e5745b523
2017-08-07 11:12:38 -07:00
TreeHugger Robot
2729912a35 Merge "List column names in the error message" into oc-mr1-dev 2017-08-01 00:36:49 +00:00
Fyodor Kupolov
82f289a4b4 Merge "Added setIdleConnectionTimeout method" into oc-mr1-dev 2017-07-31 23:56:02 +00:00
Fyodor Kupolov
cf97b6b7f7 Added setIdleConnectionTimeout method
It allows apps to set time SQLite connection is allowed to be idle
before it is closed and removed from the pool.

Test: manual + DatabaseGeneralTest
Bug: 63398887
Change-Id: Ie09eeb4dc2b9e52ba67d9355b1f9bd869b148613
2017-07-31 11:05:57 -07:00
Fyodor Kupolov
848485bb1c List column names in the error message
Otherwise it's not clear what is causing the issue (e.g. no columns,
case sensitivity issue or a table prefix etc.)

Bug: 62431773
Test: manual
Change-Id: I81d1f420b70a2248a9b132147cda72c2417dc46b
2017-07-28 15:46:17 -07:00
Fyodor Kupolov
0ee7495b54 Merge "Limit number of in-memory db connections to 1 per pool" into oc-mr1-dev 2017-07-27 23:20:34 +00:00
Fyodor Kupolov
3a6cded002 Limit number of in-memory db connections to 1 per pool
We should always keep pool size of 1 for in-memory databases since every
:memory: db is separate from another.

Test: com.android.providers.contacts.util.UserUtilsTest
Bug: 64039907
Change-Id: If85af3eacfb5625036e29d44f88c1bebb338f46b
2017-07-26 16:07:09 -07:00
Fyodor Kupolov
b773312982 Tests for lookaside configuration
Test: android.database.sqlite.cts.SQLiteDatabaseTest
Test: android.database.sqlite.cts.SQLiteOpenHelperTest
Bug: 63998707
Change-Id: I2e84a6e98baf889001ef7537a290f7e2aa2d709a
2017-07-24 23:33:00 +00:00
Fyodor Kupolov
fd9c4a54cf Close idle sqlite connections
Idle connections are now closed 30 seconds after being returned to the
pool. In-memory databases and databased with attached databases
 are exempt from closing idle connections.

The new behavior is enabled on all devices (temporarily).
Use "setprop persist.debug.sqlite.close_idle_connections 0" to disable

Test: manual - devices boots, no app crashes, auth(accounts.db) works
Test: database CTS tests + SQLiteConnectionPoolTest + run_newdb_perf_test.sh
Bug: 63398887
Change-Id: Idc11e49149292d219a15502c1707c40ef27e3ddb
2017-07-18 18:21:10 -07:00
Fyodor Kupolov
54538b0f85 Merge "Revert "Fix ContentObserver unregister issue"" am: 31419a4ad4 am: 8625194c19 am: cd816c1853
am: c2a76d16f0

Change-Id: I6916fbf80f86419a264b4645d29c9167777543e8
2017-07-13 04:07:09 +00:00
Fyodor Kupolov
8625194c19 Merge "Revert "Fix ContentObserver unregister issue""
am: 31419a4ad4

Change-Id: I455be72533c24ceb5ea352774ded30d0c0a2367f
2017-07-13 03:49:36 +00:00
Fyodor Kupolov
5d5f04b004 Revert "Fix ContentObserver unregister issue"
This reverts commit 2df4e144a9. 
It was causing failures in packages/apps/DocumentsUI tests

Bug: 63638102
Bug: 63154326
Change-Id: I51fb54f705f58f159f4fcc30bfed41ababcba950
2017-07-13 01:46:23 +00:00
Fyodor Kupolov
05a0f0fa4d Disable lookaside allocator on low-RAM devices
Also dump lookaside config if it's different from the default.

Test: adb shell setprop debug.force_low_ram 1
      adb shell stop/start
      adb shell dumpsys meminfo system  // no lookaside allocations
Bug: 62877322

Change-Id: I152dae9714e7e55f93af3311b7387a6ac816e8f6
2017-07-06 17:38:08 -07:00
Fyodor Kupolov
1a84ad9eda Merge "Fix ContentObserver unregister issue" am: 09b6988e27 am: 481d92c517 am: aee5787b48
am: 16ff7bc82a

Change-Id: Icf006b580ff47125e992fd208a89b909dd53e639
2017-07-06 18:46:54 +00:00
Fyodor Kupolov
481d92c517 Merge "Fix ContentObserver unregister issue"
am: 09b6988e27

Change-Id: I242e87b53f603a05ba7c4069662456457a3d980a
2017-07-06 18:21:54 +00:00
daqi
2df4e144a9 Fix ContentObserver unregister issue
[Cause of Defect]
In the ContentObserver callback procedure, the binder thread
has no sync mechanism with handler thread.
The ContentObserver#onChange method can get called after
ContentResolver#unregisterContentObserver called in the
very low probability.

Bug: https://issuetracker.google.com/issues/63154326
Test: manual - check https://github.com/nanjingdaqi/ContentObserverDemo
Change-Id: I0e3831eba7a9cc1a5bf0d30abe5dd0ec8259b0d4
Signed-off-by: daqi <daqi@xiaomi.com>
2017-07-06 10:09:21 +08:00
Fyodor Kupolov
d3b0c7e7e2 Support for lookaside configuration params
Modified SQLiteDatabase to allow passing lookaside configuration to its
static initializer. Encapsulated config in OpenParams and added an
overloaded version of openDatabase with the new parameter.

Configuration is changed in SQLiteConnection::nativeOpen, immediately
after opening the database since lookaside memory configuration can only
be changed when no connection is using it.

Added SQLiteOpenHelper.setLookasideConfig method that is called from
the constructor of the subclass.

Test: bit FrameworksCoreTests:android.database.DatabaseGeneralTest
Test: bit FrameworksCoreTests:android.database.SQLiteOpenHelperTest
Bug: 38499845
Change-Id: Ifb761229b43c89c090939030fc25b8c480b9b9e2
2017-06-28 14:07:53 -07:00
Steve McKay
0b28e794de Merge "Remove support for auto-paging of cursors." into oc-dev
am: 7f0d8c8076

Change-Id: Ice100c419ce6d53721d6bbec1147bb1cc1bb7b4d
2017-04-13 18:26:43 +00:00
Steve McKay
927b01371b Remove support for auto-paging of cursors.
Auto-paging of cursors is being removed in favor of a support lib component.
Rationale:
    1) Auto-paging as implemented has potential to negatively impact system health.
    2) Similar functionality w/o system health concerns can be provided
       specific to RecyclerView.

Test: Removed. CTS coverage updated.
Bug: 30927484
Change-Id: I43e62181d8ceeeba6265d44536967a2102751320
(cherry picked from commit 4677c2b7f0)
2017-04-13 00:35:42 +00:00
Steve McKay
4677c2b7f0 Remove support for auto-paging of cursors.
Auto-paging of cursors is being removed in favor of a support lib component.
Rationale:
    1) Auto-paging as implemented has potential to negatively impact system health.
    2) Similar functionality w/o system health concerns can be provided
       specific to RecyclerView.

Test: Removed. CTS coverage updated.
Bug: 30927484
Change-Id: I43e62181d8ceeeba6265d44536967a2102751320
2017-04-12 13:51:50 -07:00
Tobias Thierer
8283da42a4 Merge "Document the fact that StatFs.restat() and ctor can throw." am: 183c93f6a0 am: e11ed001dd
am: a426851da0

Change-Id: Ife49443ed8e5e4e90723e4e46c0e8c48a6ee5547
2017-04-05 21:14:46 +00:00
Tobias Thierer
0ad48dc8aa Document the fact that StatFs.restat() and ctor can throw.
StatFs.restat() and the StatFs constructor can throw
IllegalArgumentException. This was not previously documented;
not all callers took this into account, for example:
   http://r.android.com/251290

This CL adds documentation to those methods. It also adds
comments to two of the callers.

Separately from this CL, we may in addition consider adding
new API StatFs.checkedRestat() and StatFs.checkedCreate()
or similar that throw IOException; we cannot change the
existing constructor and method since they are public.

Test: Checked that "make" still completed successfully.

Change-Id: I6a0b3cb7718939408937c61de7c3b000b948fa59
2017-04-05 20:52:04 +00:00
TreeHugger Robot
9a8eb3db62 Merge "Add honored args when auto-paging." 2017-03-28 03:26:01 +00:00
Steve McKay
d39da943da Add honored args when auto-paging.
Increase test coverage.

Test: Improved!
Change-Id: Icba97c5e821e6cb60157e0c8a5b204d0d2813bc8
2017-03-25 07:43:37 -07:00
Mike Tsao
c74ee2f8d3 Replace possibly-expensive size() == 0 with isEmpty()
Bug: 36596458
Change-Id: Ieb0ea65be056bb8ce0613280e6213c330fbf783c
Test: added ContentValuesTest
2017-03-24 15:10:41 -07:00
Steve McKay
57b0fe44e0 Verify paging is by auto-pager in CTS.
Remove VisibleForTesting (even though already committed)
  but oh well.

Test: CTS coverage expanded (in topic).
Change-Id: Ife75260dca298aea880f1c02a9578e691455fd91
2017-03-23 12:58:23 -07:00
Steve McKay
f3be60a6b3 Update PageViewCursor to correctly load window.
Bug: 36485764
Test: CTS updated and passing.
Change-Id: I2b615d97fdaedef441065889ce3a2988b718795c
2017-03-21 15:33:38 -07:00
Steve McKay
e5f868fd31 Adapt unpaged cursors to paged requests.
Allow all client targeting Android O to assume paging
    support for any provider.
Adds a new PageViewCursor that adapts an unpaged cursor
    to a paged request.
Updates ContentProviderNative to perform wrapping on
    unpaged results.

Bug: 30927484
Change-Id: I4e225dc16761793c85ef8a195bf049113c79cd20
Test: Added for new class. Run info @ frameworks/base/core/tests/coretests/README
2017-03-15 15:29:52 -07:00
Michael Wright
794cf190aa Also parse "1" as true for ContentValues#getAsBoolean
SQLite's internal representation for booleans is an integer with a value
of 0 or 1, so without this check, boolean values obtained via
DatabaseUtils#cursorRowToContentValues will always return false.

Bug: 34365384
Test: demo app, cts
Change-Id: I6c0829c992252ca5ee16bd5eac48668507fd4089
2017-01-19 16:19:28 +00:00
Suprabh Shukla
6222176963 Added minimum supported version in SQLiteOpenHelper
Added a convenience mechanism to delete the whole database if it is of
a version that is so old that the application does not want to support
upgrading it. SQLiteOpenHelper now automatically deletes such a database
and creates a fresh one with the newest version provided. A callback
onBeforeDelete is added if the application wants to collect some data
from the db before it is deleted.

Test: Tested by upgrading contacts database using ContactsDatabaseHelper

Bug: 31559016
Change-Id: I3f924d247cdca2015c4244cc987de2538a086651
2016-10-07 13:23:31 -07:00
Mark Lu
b920dc4968 docs: improve docs for sqlite package summary am: 59640a9f1c am: 195099dc32
am: 2f90f2c53a

Change-Id: I2f7c459d979e802996e60611c678c3dbf9ab2b3f
2016-09-26 17:53:18 +00:00
Mark Lu
1289f9919c docs: Update docs for SQLiteDatabase replace methods am: 1e20208d90 am: 5dc8052df6
am: 901e97e133

Change-Id: Ife8ddd36653e9e336b7bcd3f2e6bab251f015021
2016-09-26 17:46:25 +00:00
Hemal Patel
94f938a56f Fixed a typo in the code sample am: 247d1c9ea8 am: 9fa6e02d2d
am: 7829ef7cf0

Change-Id: Ic82a377c8d517c35697c1d27e038bbaec82c6598
2016-09-26 17:34:20 +00:00
Mark Lu
195099dc32 docs: improve docs for sqlite package summary
am: 59640a9f1c

Change-Id: I9ec1851274071cb1882839df68e27d1c9b98f8f7
2016-09-26 17:24:06 +00:00
Mark Lu
5dc8052df6 docs: Update docs for SQLiteDatabase replace methods
am: 1e20208d90

Change-Id: I8222fae7025d5a546b0b3d6b0ebbb7abae66ba8b
2016-09-26 17:22:45 +00:00
Hemal Patel
247d1c9ea8 Fixed a typo in the code sample
Bug: 6062536
Change-Id: I1f6a91534cf18b9fba4e00f3a4b84983f2c223a3
2016-09-16 15:28:42 -07:00
Mark Lu
1e20208d90 docs: Update docs for SQLiteDatabase replace methods
- Mention that if the row does not exist, the method performs insert
- Add parameter info for initialValues. It was incomplete

Bug: 2321632
2016-08-30 17:41:25 -07:00
Mark Lu
59640a9f1c docs: improve docs for sqlite package summary
- Update the sqlite version info
- Describe how to get sqlite version info
- Remove reference to out-of-date Notepad sample
- Update sqlite3 folder location and add link to relevant documentation

Bug: 30833403
Bug: 17393931
Change-Id: Ic58e88a119919f43ed90a70c559da8eacef4ebe0
2016-08-30 13:15:55 -07:00
Aurimas Liutikas
514c5ef8d5 Add missing @Deprecated annotations.
Add missing @Deprecated annotations for methods with @deprecated tag
in javadoc.

Change-Id: I35b78ccb97832d86b914c21a300444ba29e33844
2016-05-24 15:22:55 -07:00
Steve Pomeroy
c240b607f7 Fix documentation bug in SQLiteDatabase
The documentation incorrectly states that, "[insertWithOnConflict
returns] the primary key of the existing row if the input param
'conflictAlgorithm' = CONFLICT_IGNORE". Unfortunately, SQLite does
not provide such functionality.

Close: https://code.google.com/p/android/issues/detail?id=13045

Signed-off-by: Steve Pomeroy <steve@staticfree.info>

(cherry picked from commit 8fc3144fa5)

Change-Id: I89e56428e612d667259744e2bc3df124e5a2aa0e
2016-05-12 16:53:10 -07:00
Steve Pomeroy
88968cc3ba Merge "Fix documentation bug in SQLiteDatabase" am: 21d061ec2e
am: b654fae4db

* commit 'b654fae4dbff8b384ef3074ff762f0ed5b8b1034':
  Fix documentation bug in SQLiteDatabase

Change-Id: I8917758d9d0a41105be1adc596d3468cff22c739
2016-05-12 22:31:52 +00:00
Steve Pomeroy
8fc3144fa5 Fix documentation bug in SQLiteDatabase
The documentation incorrectly states that, "[insertWithOnConflict
returns] the primary key of the existing row if the input param
'conflictAlgorithm' = CONFLICT_IGNORE". Unfortunately, SQLite does
not provide such functionality.

Close: https://code.google.com/p/android/issues/detail?id=13045

Change-Id: Ife919c4dcf7bf703b692d338d1fb5844a532dd39
Signed-off-by: Steve Pomeroy <steve@staticfree.info>
2016-05-12 21:16:55 +00:00
Makoto Onuki
3443670828 Fix sqlite time measurement.
SystemClock.uptimeMillis() should be used to calculate duration.

Bug 28054535

Change-Id: Idadee1ee47cea22d58dba2163cb843402e39b196
2016-04-07 09:42:17 -07:00
Makoto Onuki
60df01c522 Merge "Add SQLiteDatabase.validateSql()" 2015-12-16 22:31:44 +00:00
Makoto Onuki
17aa1b7ac7 Add SQLiteDatabase.validateSql()
This API checks the SQL syntax by compiling it.  This is useful to
detect SQL injection, for example.

Change-Id: I956548a34f664950246856966e5601dcac3daf00
2015-12-16 14:18:28 -08:00
Greg Hackmann
e12350faf7 Trace SQLite operations
Inefficient SQLite use can have non-obvious effects on performance.  For
example, insert and update operations can trigger a surprising number of
fsync() calls, especially if they're not grouped together into
transactions.

Add tracepoints around SQLite operations, to make it easier to pinpoint
their effects on the rest of the system.

Change-Id: I30cc3d02eca264e46dcc09ca7512a32519543834
Signed-off-by: Greg Hackmann <ghackmann@google.com>
2015-12-14 12:32:26 -08:00
Jeff Brown
bb8c841e90 Terminate loop properly when cursor window is full.
The existing code exits the column-filling loop immediately but
may continue to try to fill rows.  Ordinarily this should fail
too but it's possible for the process to continue and then
blow up a little later.  Fixed this problem by exiting the row-
filling loop promptly.

Bug: 21406130
Change-Id: Ifab59188d5d1b40f3c1f5c97604dd48da71bf37b
2015-06-01 16:33:24 -07:00
Andreas Gampe
0db3cdc59a am 5b0c0964: am fb861b6c: am 31fb202e: Merge "Frameworks/base: Compile-time optimize SQLiteConnection"
* commit '5b0c0964d843319b1b89767cd3d3f1daa984df51':
  Frameworks/base: Compile-time optimize SQLiteConnection
2015-04-22 00:23:51 +00:00
Andreas Gampe
4f47b40e05 Frameworks/base: Compile-time optimize SQLiteConnection
Do not cache compiled regular expression and date formatter. Both
cannot be compile-time created, are expensive at preloading time,
and only used in the rare case of dumping the connection (mainly
on errors).

Bug: 19498458
Bug: 19542228
Change-Id: Ia38491a3f852ccf699b815ff05289b338e932f2a
2015-04-21 16:01:00 -07:00