Commit Graph

634 Commits

Author SHA1 Message Date
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
Jeff Sharkey
197fe1f90f Final push to build against SDK.
The bulk of the work needed to get MediaProvider building against
the "system_current" SDK surface has been slowly merged over the
last few months, and this change makes the last few adjustments.

This adds a new StorageVolumeCallback which is simpler version of
StorageEventListener that simply delivers the changed StorageVolume.

Move DownloadManager logic into a onMediaStoreDownloadsDeleted()
method which hides the implementation details of how the OS connects
with that implementation.

Make local copies of some ExifInterface parsing logic; they could
be added to the androidx version in an unbundled release.  Make a
local copy of RedactingFileDescriptor, since it's only needed for
the next few weeks until FUSE is globally enabled.

Bug: 137890034
Test: atest --test-mapping packages/providers/MediaProvider
Change-Id: Ib416eb8724781bdd234c8b7d728dee8b695ad6ac
2020-01-08 11:44:28 -07:00
Artur Satayev
33f9217695 Use new UnsupportedAppUsage annotation.
Existing annotations in libcore/ and frameworks/ will deleted after the migration. This also means that any java library that compiles @UnsupportedAppUsage requires a direct dependency on "unsupportedappusage" java_library.

Bug: 145132366
Test: m && diff unsupportedappusage_index.csv
Change-Id: I0c336de56bc4a041dc97ff9b7927f62f0b44b457
Merged-In: I0c336de56bc4a041dc97ff9b7927f62f0b44b457
2020-01-08 14:04:40 +00:00
Artur Satayev
269580069b Use new UnsupportedAppUsage annotation.
Existing annotations in libcore/ and frameworks/ will deleted after the migration. This also means that any java library that compiles @UnsupportedAppUsage requires a direct dependency on "unsupportedappusage" java_library.

Bug: 145132366
Test: m && diff unsupportedappusage_index.csv
Change-Id: I0c336de56bc4a041dc97ff9b7927f62f0b44b457
2020-01-06 16:47:35 +00:00
Daulet Zhanguzin
b7ac8d3e1b Replace com.android.internal.util.Preconditions.checkNotNull with
java.util.Objects.requireNonNull

Bug: 126528330

Test: Treehugger
Exempt-From-Owner-Approval: Global refactoring.
Change-Id: Iade27d6d66794f0598ee233dc069ab5a306826d5
2020-01-03 18:09:26 +00:00
Jeff Sharkey
19491026ca We can't be as clever as we'd like.
We had hoped that SQLiteQueryBuilder could enforce some pretty strict
grammar rules, but there are apps depending on the full quirkiness
of what SQLite will allow, which is pretty much "expr" everywhere.

So we shift our strategy from a whitelist-style approach to a
blacklist-style one, where we're willing to let any valid keyword
be used _except_ for ones we know are rooted in abuse, such as
performing SELECT subqueries or relying on SQL injection to blur
the lines between well-defined clauses.

Bug: 146478800, 146482076
Test: atest --test-mapping packages/providers/MediaProvider
Change-Id: Ib57ceab0e229e01177cabd8277f3c989c817b10c
2019-12-18 17:55:42 -07:00
Jeff Sharkey
71c694aa38 Allow "LOCALIZED" and "UNICODE" collators.
These custom collators are added by ./android/sqlite3_android.cpp,
so let callers use them.

Bug: 140666363
Test: atest android.database.sqlite.cts.SQLiteQueryBuilderTest
Change-Id: I6674b04afb5bbb5f9870329431549eca8e4f5bc6
2019-12-17 16:15:52 -07:00
Artur Satayev
59318bab67 Merge "Add @UnsupportedAppUsage to test apis that are known to be used by apps."
am: a98026f7aa

Change-Id: Ia39fbc2200aa7262e4a05b0710b7a382bb01b276
2019-11-13 10:33:06 -08:00
Artur Satayev
5a525851a8 Add @UnsupportedAppUsage to test apis that are known to be used by apps.
go/testapi-enforcement

Bug: 133832325
Test: m
Change-Id: Ifc8db120640a1554dcbf1722e61e09c7ddc65dd6
Merged-In: Ifc8db120640a1554dcbf1722e61e09c7ddc65dd6
2019-11-13 15:05:56 +00:00
Artur Satayev
f0b7d0ba51 Add @UnsupportedAppUsage to test apis that are known to be used by apps.
go/testapi-enforcement

Bug: 133832325
Test: m
Change-Id: Ifc8db120640a1554dcbf1722e61e09c7ddc65dd6
Merged-In: Ifc8db120640a1554dcbf1722e61e09c7ddc65dd6
2019-11-13 12:58:29 +00:00
Artur Satayev
7a565c45b1 Merge "Add @UnsupportedAppUsage annotations for greylist."
am: 423c3a32d6

Change-Id: I5387b4742fdaf67ad3189356f2361f73969b53a8
2019-11-11 09:13:24 -08:00
Artur Satayev
fc46be7dbd Add @UnsupportedAppUsage annotations for greylist.
go/cleanup-greylist-txt

These have already been greylisted, however due to bugs/omissions in the tooling have been kept in go/greylist-txt instead of being annotated in the code.

Bug: 137350495
Test: m

Change-Id: Id6c1f5e403a0e66edb1102ee45f3bf19f244fb09
Merged-In: Id6c1f5e403a0e66edb1102ee45f3bf19f244fb09
2019-11-08 16:17:13 +00:00