Commit Graph

645 Commits

Author SHA1 Message Date
Tyler Gunn
dc39dc2bd4 Make docs clear that you shouldn't change an existing onUpgrade step.
Clarifying the API docs to make it clear to the developer the once a
migration step runs, any errors in that step should be corrected by adding
a new migration step instead of modifying the existing step.

Test: Docs only change
Bug: 258831395
Change-Id: I51874bc215a7edfc270eaf4893147e452beb05d3
2023-03-15 19:29:48 +00:00
Daniel Santiago Rivera
c5947e577e Revert "Clear statement cache if schema changes."
Revert submission 21849810-cherrypick-sql-cache-issue-elg7faliq8

Reason for revert: b/272303109

Reverted changes: /q/submissionid:21849810-cherrypick-sql-cache-issue-elg7faliq8

Change-Id: Ibda8e55d21308061ea3d13c918ec471a34e4e427
2023-03-09 22:12:28 +00:00
Daniel Santiago Rivera
48b72ed672 Clear statement cache if schema changes.
If DDL statement is executed then the prepared statement cache must be cleaned up on active connections, otherwise their column result information can be outdated.

Bug: 183028015
Test: atest CtsDatabaseTestCases
Change-Id: I7e51007afb029c0591e48eaa0be908bcb92df576
2023-03-07 19:25:54 +00:00
Andrew Solovay
d71e0ece64 Merge "docs: Fixing typos in SQLite...Exception docs" into tm-dev am: 3271ef39b4 am: 92cf6eaaad am: 9745cfed82 am: 8101ab912a
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20844453

Change-Id: I954cbc647fb042f7ac4b21bf514a7a604c4d79b5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-01-16 05:08:12 +00:00
Andrew Solovay
8101ab912a Merge "docs: Fixing typos in SQLite...Exception docs" into tm-dev am: 3271ef39b4 am: 92cf6eaaad am: 9745cfed82
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20844453

Change-Id: I23df3d1dfdf32f004c46e48b3c0a7b4b8a6e7ab8
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-01-16 04:17:22 +00:00
Andrew Solovay
67cb204132 docs: Fixing typos in SQLite...Exception docs
The CommonTypos linter gave a warning about typos in the
generated reference doc. While I had the files open, also
edited the summary fragments to conform to style guide.
No changes to source code.

Bug: 263824202
Change-Id: I653f7144e169cf6a3b5a38a3010c7f7973192ea1
Test: [go/abtd docs build]
2023-01-03 16:50:08 +00:00
Treehugger Robot
1bcd3a8f79 Merge "Change the default value of sync mode to NORMAL" am: 143e1c5c77 am: 6d90446570 am: 79263587a1
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2215069

Change-Id: I560a6f70f003179ee759e7a64eb92d3c378219c2
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-10-12 20:42:32 +00:00
ot905302
46edcf3be4 Change the default value of sync mode to NORMAL
When journal mode is WAL ,the default sync mode is FULL.
In Android S when journal mode is WAL,the default sync mode is NORMAL.

In the annotation of google it's said when journal mode is WAL,
the best sync mode should be NORMAL.

Incorrect sync mode cause performance drop.

Bug: 246753316
Test: run fs benchmark

Change-Id: I8110d66091cd443db9b09f6e8564f9d97f5e7297
2022-09-29 01:25:28 +00:00
Corina Grigoras
e4e3701197 Add database cts tests to presubmit
Bug: 237726334
Change-Id: I7eb684930533f5c797f0818149fb780b35f78e17
Test: presubmit
2022-08-01 10:59:13 +00:00
Edgar Arriaga
506e3f17c5 Add sql statement cache miss info and test
This patch adds a test for checking that statement cache
works and it also improves dumpsys diagnostics to include
per database stats as previously it only showed per connection
stats which could have data loss if a connection was dropped
for any reason and not put back in the pool and it also
provides the aggregated view.

Test: dumpsys meminfo
Test: atest SQLiteDatabasePerfTest#testSelectCacheMissRate
Bug: 228498581

Change-Id: Ia49264e8f0e6db83234c2ba5943fd9e25fd5d8b2
2022-06-30 18:47:06 +00:00
Edgar Arriaga
5b3d4c97d1 Fix sql connection recycling bug causing multiple connection reopens
Currently when multiple sql statements that share the same structure
are prepared they are put in a statement cache as preparing them is an
expensive operation. This patch fixes a bug where a non primary
connection would not recycle its opened connection due to it believing
that the pool did not have space caused by a one off error which in turn
caused the connection to be rebuilt every time it was requested.

Bug: 228498581
Test: Verified caching with logs and confirmed savings in traces
Change-Id: Ic7e26db77c23d8ead9565a689800cc48f158c059
2022-06-27 21:23:42 +00:00
Etienne Ruffieux
4c1c4ee37e Making CursorWindowAllocationException public
Exposing CursorWindowAllocationException to access it
from Bluetooth PBAP.

Tag: #feature
Bug: 211851706
Test: manual
Change-Id: I9a2c4217e5556f7b8ab10c3884a0d3e9b6a4fe36
2022-01-28 23:53:48 +00:00
Ioannis Ilkos
0bde67ab00 Change close guard logged messages
Unless we are looking at stack traces (e.g. from strict mode) it's not
possible to identify which type of object is not being closed (most
methods are 'close' or 'release). Change the logged text to clarify.

Change-Id: Ib90eac716f43c2c2caf8d8c6fb64a7bd90562da9
Test: manual
2021-12-21 11:46:10 +00:00
Edgar Arriaga
87e9c5da46 Make slow queries logs show only when log tag enabled
Test: Manual
Bug: 205056348
Change-Id: Ie3ef14e053381003f0c3de00b0260c7669d18c8c
2021-11-29 12:50:40 -08:00
Edgar Arriaga
2de9ed3130 Remove old and unnecessary log
Bug: 205056348
Test: Manual
Change-Id: I74e470cd8dfd9cdeb2bbc9e56af2c7e48f631acd
2021-11-29 12:50:40 -08:00
Edgar Arriaga
5eee0b59b7 Add support for normal sync mode and propagate journalMode and syncMode on database open
This fixes dumpsys dbinfo not reporting the journalMode and syncMode as
well and made flags and configuration converge to the same value which
is less bug prone.

Test: dumpsys dbinfo
Bug: 193925357
Change-Id: I9a30b64b06a94fa9bd5589eba391a561ddcfaaf0
2021-11-29 12:50:35 -08:00
Edgar Arriaga
5e28d4b59d Add total execution time and statements executed to dumpsys dbinfo
Test: dumpsys dbinfo
Bug: 193925357
Change-Id: I1b0933543b9a24f262803627097a7b8a77b5ddf5
2021-11-23 16:24:27 -08:00
Xiaoyu Jin
c06b02ddba Add @SystemApi registerContentObserverForAllUsers in ContentResolver
Also add ContentObserver#onChange(boolean, Collection, int, UserHandle) so
clients can know the corresponding UserHandle for the notification.

Bug: 203606981
Test: atest CtsContentTestCases and manual testing to verify the observer can get notifications for
all the users.

Change-Id: Icec7e70b71d7de1c15faf1736539f169856304a8
2021-11-16 02:02:16 +00:00
Makoto Onuki
4571ada203 Make robust the open failure reason detection logic
Fix: 201320458
Test: atest cts/tests/tests/database/src/android/database/sqlite/cts/SQLiteDatabaseTest.java
Change-Id: I812eb1b05ef2737f118e81cadf70ad5fc0ce2bf3
2021-09-29 10:27:22 -07:00
Daniel Santiago Rivera
1c176a9b64 Allow PRAGMA statements that change and return a result in executeNonQuery()
This fixes an issue where execPerConnectionSQL() would fail with certain
PRAGMA statements that both set a value and return a result, such as
busy_timeout, max_page_count, etc.

Bug: 197128690
Test: atest CtsDatabaseTestCases
Change-Id: I1904ccfd6795c38ce55800bdd074ffba083638af
2021-08-19 08:22:47 -07:00
Philip Cuadra
9639ce78ec Replace heavy isLoggable call
Log.isLoggable is expensive for frequent operations.  Replace with a
pre-determined check.

Bug 188428246
Test: Built

Change-Id: I77f1980c289b44c8dafd4113771fd814ff382a83
2021-06-02 21:39:17 +00:00
Daniel Santiago Rivera
b14134faf2 Merge "Added SQLite versions used on API levels 28, 30 and 31." am: 2a2aa6d3c5 am: e40b2193fe am: 1cfbf3a69e
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1688650

Change-Id: I15046e16677d49b795b8e845fd082c80c7d1cea7
2021-04-29 18:14:31 +00:00
Daniel Santiago Rivera
3771ef8d64 Added SQLite versions used on API levels 28, 30 and 31.
The android.database.sqlite package summary page now mentions the
versions of SQLite that are available on Android devices running Pie
(API level 28), Q (API level 29), R (API level 30) and S (API level 31)

Change-Id: I49c6bdd7edbaf98a62f50cb65ba00f160c800f0c
Test: make ds-docs -j16
2021-04-28 23:38:30 +00:00
Jeff Sharkey
7444e309f9 Revert "Temporarily replace "android.com" accounts."
This reverts commit 0ace970e19.

Bug: 174932174, 175111824
Exempt-From-Owner-Approval: refactoring with team leads buy-in
Change-Id: I152186408ecf6da1cb7354d14737de7cce55a34b
2020-12-09 11:06:28 -07:00
Jeff Sharkey
0ace970e19 Temporarily replace "android.com" accounts.
We're temporarily blocked on internal Gerrit tooling to support
relaxed OWNERS validation, so this change temporarily replaces all
"android.com" accounts with "google.com" equivalents.

Bug: 174932174,175111824
Exempt-From-Owner-Approval: refactoring with team leads buy-in
Change-Id: I114f2a40cee1b65e21250da7372e11c18cd73e25
2020-12-08 17:54:13 +00:00
Xin Li
d31ee38811 Merge rvc-qpr-dev-plus-aosp-without-vendor@6881855
Bug: 172690556
Merged-In: I78222391b83a4add8e964340ec08bb8a1306e1c6
Change-Id: I28bbf40820674675ccf765c912aa8140d3f74ab2
2020-12-02 00:38:58 -08:00
TreeHugger Robot
772223ccfe Merge "Use CloseGuard for cursor leak detection" 2020-11-06 00:31:32 +00:00
Li Li
be5bebafab Use CloseGuard for cursor leak detection
Protect Cursors with CloseGuard and report implicit cleanup.

By default, the leak detection code will print a one-line warning
message about failing to call the cleanup function. To report more
details like the original stacktrace and SQLite query statement, enable
the correspoinding VmPolicy flags as the example below, please.

/*
 * public void onCreate() {
 *     if (DEVELOPER_MODE) {
 *         StrictMode.setVmPolicy(new VmPolicy.Builder()
 *                 .detectLeakedSqlLiteObjects()  // for SqlLiteCursor
 *                 .detectLeakedClosableObjects() // for any Cursor
 *                 .penaltyLog()
 *                 .build());
 *     }
 *     super.onCreate();
 * }
 */

By enabling detectLeakedSqlLiteObjecs, the original SQLiteCursor query
statement is reported when close() or its equivalent cleanup function
is not called before finalize().

By enabling detectLeakedClosableObjects, the new CloseGuard report will
be provided, along with the original stack trace captured in open() or
its equivalent.

The former has better performance as it doesn't capture an original
stack trace during open() stage. Only enable the latter if performance
impact is not an issue. Both of them can be enabled at the same time.

Bug: 168639120
Test: manually test with an example SQLite Android application, with and
without calling cursor.close() after a db.rawQuery().

Change-Id: Ibe9fcdc8119c2e4651df1983e7ccd793f29e8e9d
Signed-off-by: Li Li <dualli@google.com>
2020-11-05 14:32:48 -08:00
Mathew Inwood
5d123b6775 Add maxTargetSdk restriction to unused APIs.
These are APIs that have @UnsupportedAppUsage but for which we don't
have any evidence of them currently being used, so should be safe to
remove from the unsupported list.

Bug: 170729553
Test: Treehugger
Merged-In: I626caf7c1fe46c5ab1f39c2895b42a34319f771a
Change-Id: I54e5ecd11e76ca1de3c5893e3a98b0108e735413
2020-11-04 09:45:53 +00:00
Mathew Inwood
8e742f928e Add maxTargetSdk restriction to unused APIs.
These are APIs that have @UnsupportedAppUsage but for which we don't
have any evidence of them currently being used, so should be safe to
remove from the unsupported list.

This is a resubmit of ag/12929664 with some APIs excluded that caused
test failures; see bugs 171886397, 171888296, 171864568.

APIs excluded:
Landroid/bluetooth/le/ScanRecord;->parseFromBytes([B)Landroid/bluetooth/le/ScanRecord;
Landroid/os/Process;->myPpid()I
Landroid/os/SharedMemory;->getFd()I
Landroid/hardware/input/InputManager;->INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH:I

Bug: 170729553
Test: Treehugger
Change-Id: I8285daa8530260251ecad6f3f38f98e263629ca7
2020-10-29 11:51:12 +00:00
Hongwei Wang
050275cd83 Revert "Add maxTargetSdk restriction to unused APIs."
This reverts commit 72f07d6a8a.

Reason for revert: Droidcop-triggered revert due to breakage https://android-build.googleplex.com/builds/quarterdeck?testMethod=testAppZygotePreload&testClass=android.app.cts.ServiceTest&atpConfigName=suite%2Ftest-mapping-presubmit-retry_cloud-tf&testModule=CtsAppTestCases&fkbb=6936597&lkbb=6936969&lkgb=6936551&testResults=true&branch=git_master&target=cf_x86_phone-userdebug>, bug b/171886397

Bug: 171886397
Change-Id: Ibe0f0430a3451477c1ee8ef56a596e91ea1e7672
2020-10-28 20:16:22 +00:00
Mathew Inwood
72f07d6a8a Add maxTargetSdk restriction to unused APIs.
These are APIs that have @UnsupportedAppUsage but for which we don't
have any evidence of them currently being used, so should be safe to
remove from the unsupported list.

Bug: 170729553
Test: Treehugger
Change-Id: I4c8fd0006f950de9955242e93968fb0996ceb372
2020-10-27 15:46:07 +00:00
Jeff Sharkey
f18719bb73 Apply fixes for EfficientStrings.
Refactoring to avoid paying the cost of extra StringBuilder that are
quickly disposed.

Bug: 170978902
Test: none
Exempt-From-Owner-Approval: trivial refactoring
Change-Id: Icd914a63cdadf8123c1e5a5073f85245f0791f0b
2020-10-20 22:00:18 -06:00
Jeff Sharkey
1c08f48253 Apply fixes for EfficientStringsChecker.
The recently-built Error Prone checker has found many instances where
we're always paying the cost of StringBuilder concatenation, even in
the typical cases where preconditions are successfully met.

Benchmarks have shown that even when replacing these with varargs
formatter strings, the default case is 20x faster.

Bug: 170978902
Test: none
Exempt-From-Owner-Approval: trivial refactoring
Change-Id: If8c00bc73467bfb91ec16c162969c9d26ca53646
2020-10-20 22:00:16 -06:00
Jeff Sharkey
d0c8cdd782 Add some simple annotations to Cursor.
Bug: 146778105
Test: none
Change-Id: Ifd76abd9663732a851d3dae7435d31c8380402a5
2020-10-15 12:13:27 -06:00
Xin Li
628590d7ec Merge Android R (rvc-dev-plus-aosp-without-vendor@6692709)
Bug: 166295507
Merged-In: I3d92a6de21a938f6b352ec26dc23420c0fe02b27
Change-Id: Ifdb80563ef042738778ebb8a7581a97c4e3d96e2
2020-08-31 21:21:38 -07:00
Treehugger Robot
1e637f36a4 Merge "Update language to comply with Android's inclusive language guidance" am: 4cb1ece9d1 am: 0fa2ec2c23 am: 58c0f8dbbe am: 804e59de87
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1382538

Change-Id: I6739ce2e1a10473595be0057ac327b54890d7c8d
2020-07-31 16:10:16 +00:00
Treehugger Robot
58c0f8dbbe Merge "Update language to comply with Android's inclusive language guidance" am: 4cb1ece9d1 am: 0fa2ec2c23
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1382538

Change-Id: I9a6266db3231e52a23a26a753f002068daa9d072
2020-07-31 15:33:09 +00:00
Lais Andrade
104b9949e5 Update language to comply with Android's inclusive language guidance
See https://source.android.com/setup/contribute/respectful-code for reference

#inclusivefixit

BUG=162536543

Change-Id: Ief238c704c9d44b36d2252c59bd572f9a2318307
2020-07-31 12:43:23 +00:00
Hall Liu
b7cffcab32 Allow empty tokens in strict grammar
In SQLiteQueryBuilder, allow empty tokens when checking for invalid
tokens during the strict grammar check.

Fixes: 151151800
Fixes: 161769478
Test: atest SQLiteQueryBuilderTest#testStrictQueryEmptyToken
Change-Id: Iac1cdd643253fd186a164b863d65d6e92698fd38
(cherry picked from commit e409ec2492)
2020-07-21 22:48:03 +00:00
Jeff Sharkey
0fd3e39760 Carry over bugfixes from MediaProvider.
A few months ago MediaProvider forked SQLiteQueryBuilder and we
fixed bugs in how the new insert(), update(), and delete() methods
were executed, but those fixes never made their way back upstream.

This CL is a clean cherry-pick of existing logic.

Bug: 155149941
Test: atest android.database.sqlite.cts.SQLiteQueryBuilderTest
Change-Id: I00d2ee88539b12d27a2ed99fff0546d1e3543b0e
2020-05-19 09:37:13 -06:00
Makoto Onuki
5890360562 Ignore exceptions when investigating failure reasons
Fix: 154428500
Test: boot
Test: code inspection
Change-Id: I2a69a58aaa43617f40bc52fd06cba730faa93672
2020-04-21 13:19:41 -07:00
Makoto Onuki
a868d701d7 Enhance exception message on SQLiteCantOpenDatabaseException
Bug: 150248286
Test: atest CtsDatabaseTestCases
Change-Id: I39f7a3516dfbe0198b1ef5f68af1265df98c5a0a
2020-04-08 16:19:42 -07:00
Jeff Sharkey
b36acbf6a7 Deep copy arguments to avoid accidental mutation.
Otherwise we'd risk applying different arguments to active versus
future connections.

Bug: 152005629
Test: atest CtsDatabaseTestCases:android.database.sqlite.cts.SQLiteDatabaseTest
Change-Id: I6e83a47d9874825fd14940245412372ef9227e79
2020-03-31 21:10:22 -06:00
Jeff Sharkey
62dd7c25ac Add ability to execute per-connection SQL.
Developers have been able to register custom collators using syntax
like "SELECT icu_load_collation()", but collators are registered per
database connection.

Since we don't expose any details APIs for interacting with connection
pools directly, developers can end up with flaky behavior as their
queries rotate through the pool of connections, as only a subset of
connections will have their collation registered.

This solve this, we add a new execPerConnectionSQL() method to
ensure that a given statement is executed on all current and future
database connections.

Bug: 152005629
Test: atest CtsDatabaseTestCases:android.database.sqlite.cts.SQLiteDatabaseTest
Change-Id: I459fb7b18660d2a04eec92d1e9cc410d769e361d
2020-03-27 20:47:18 -06:00
Jeff Sharkey
8b0cff7108 Give hidden API behavior to legacy apps.
Starting in R, there is a new public API overload that delivers a
flags argument.  Some apps may be relying on a previous hidden API
that delivered a userId argument, and this change is used to control
delivery of the new flags argument in its place.

There are dozens of these hidden API users are in the system UID,
either in the system process or the Settings app, so we hard-code
giving them the legacy behavior, since refactoring would be messy
between internal and AOSP branches.

Also adjust incoming and outgoing method signatures to use slightly
more flexible Collection<Uri>, which has handy methods like
contains() and isEmpty().

Bug: 150939131
Test: atest --test-mapping packages/providers/MediaProvider
Test: atest FrameworksServicesTests:com.android.server.devicepolicy.DevicePolicyManagerTest
Exempt-From-Owner-Approval: trivial refactoring
Change-Id: If6a77449e19215cf1c60d4217e62fc04b0959bfc
2020-03-10 16:36:21 -06:00
Jeff Sharkey
d70325359e Use flags to indicate reason for Uri changes.
As part of MediaProvider becoming a Mainline module, some partners
need to understand more details about what triggered a Uri change
notification.  This helps listening apps avoid making expensive and
race-condition-prone calls back into MediaProvider; typically when
they're only interested in insert and delete operations.  This change
uses the existing "flags" argument to communicate the reason.

This change adds overloads to ContentObserver for listening apps to
receive these flags.  In addition, we add overloads that deliver a
clustered set of multiple Uris together in a single Binder transaction
to improve overall efficiency.  (This matches well with the existing
CR.notifyChange() API that we added earlier this year, since they
both work with Iterable<Uri>.)

Tests to verify that we only collapse Uris together when all other
method arguments are identical.

Bug: 147778404, 144464323
Test: atest CtsDatabaseTestCases
Test: atest CtsContentTestCases:android.content.cts.ContentResolverTest
Test: atest FrameworksServicesTests:com.android.server.content.ObserverNodeTest
Test: atest --test-mapping packages/providers/MediaProvider
Change-Id: I0bbd8a8b4a898ab6f891d085de0ecb4d68cbe302
2020-03-05 11:01:23 -07:00
Sudheer Shanka
7d28b5bf81 Include pending media as well when deleting mediastore entries.
Bug: 146914674
Bug: 140565622
Bug: 137381621
Test: manual
Change-Id: I903a13deb467b45839a7d03b60754c8fc464456c
2020-02-24 05:50:33 +00:00
Jeff Sharkey
03475d9ae4 Add custom scalar/aggregate functions to SQLite.
SQLite ships with a handful of basic functions, such as UPPER() as
a scalar function and MAX() as a aggregate function.  We now have
several use-cases for adding custom functions, where it's otherwise
prohibitively expensive to perform post-processing on the returned
Cursor, as that requires copying processed data to yet another
MatrixCursor before returning to apps.

This change adds the ability for developers to register custom
scalar and aggregate functions on databases that they've opened;
some contrived examples are scalar functions like REVERSE() for
reversing a string, or aggregate functions like STDDEV().

To give developers the most flexibility, we use the Java functional
interfaces for defining these operations, as developers may already
be familiar with the contracts of those methods.  This also opens
the door to quickly adapting existing code through utility methods
like BinaryOperator.minBy(Comparator).

Bug: 142564473
Test: atest CtsDatabaseTestCases:android.database.sqlite.cts.SQLiteDatabaseTest
Change-Id: I9fa0e60ec77bab676396729cc9cb8ba8aaf56224
2020-01-17 15:57:42 -07:00
Jeff Sharkey
c192ca5a54 Respond to API council feedback.
Adjust Exception to more general Throwable, and add docs for
new ContentResolver and ContentProvider overloads.  Also add docs
for default state of strict query options.

Bug: 131598520, 141227540, 147287177
Test: atest --test-mapping packages/providers/MediaProvider
Change-Id: Icb0153b8c8a352db39de301074e948bfaa676ddb
2020-01-08 11:44:44 -07:00