Commit Graph

609 Commits

Author SHA1 Message Date
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
Jeff Sharkey
0e66ea6f32 RESTRICT AUTOMERGE Strict SQLiteQueryBuilder needs to be stricter.
Malicious callers can leak side-channel information by using
subqueries in any untrusted inputs where SQLite allows "expr" values.

This change offers setStrictGrammar() to prevent this by outright
blocking subqueries in WHERE and HAVING clauses, and by requiring
that GROUP BY and ORDER BY clauses be composed only of valid columns.

This change also offers setStrictColumns() to require that all
untrusted column names are valid, such as those in ContentValues.

Relaxes to always allow aggregation operators on returned columns,
since untrusted callers can always calculate these manually.

Bug: 135270103, 135269143
Test: atest android.database.sqlite.cts.SQLiteQueryBuilderTest
Test: atest FrameworksCoreTests:android.database.sqlite.SQLiteTokenizerTest
Change-Id: I0dacb53170ce573a2fe103cbff455782bfdb5d41
2019-09-10 21:16:10 +00:00
Artur Satayev
fa05ca260a Add @UnsupportedAppUsage annotations.
This is an automatically generated CL. See go/UnsupportedAppUsage
for more details.

Exempted-From-Owner-Approval: Mechanical changes to the codebase
which have been approved by Android API council and announced on
android-eng@

Bug: 137350495
Test: m
Change-Id: I55c7845cb7c22808a85dd5185eccfe93c2064b76
2019-08-01 13:44:37 +01:00
Jeff Sharkey
ae6a466668 Strict SQLiteQueryBuilder needs to be stricter.
Malicious callers can leak side-channel information by using
subqueries in any untrusted inputs where SQLite allows "expr" values.

This change offers setStrictGrammar() to prevent this by outright
blocking subqueries in WHERE and HAVING clauses, and by requiring
that GROUP BY and ORDER BY clauses be composed only of valid columns.

This change also offers setStrictColumns() to require that all
untrusted column names are valid, such as those in ContentValues.

Relaxes to always allow aggregation operators on returned columns,
since untrusted callers can always calculate these manually.

Bug: 135270103, 135269143
Test: atest android.database.sqlite.cts.SQLiteQueryBuilderTest
Test: atest FrameworksCoreTests:android.database.sqlite.SQLiteTokenizerTest
Change-Id: I109fbb51e4bd2ed3c3b23a7c5f0cb795f7d8b984
2019-07-18 16:09:01 -06:00
Makoto Onuki
a9be33f7cf Fix slow query log.
SQLiteDebug.Const isn't supposed to be preloaded.

Fix: 134176355
Test: "setprop db.log.slow_query_threshold.10045 0" and make sure ...
it works for UID 10045

Change-Id: I06ca1531e968faa2378d0cb7f627e2c6a87cf502
2019-06-03 10:39:30 -07:00
Anton Hansson
d79473f881 Make DocumentCursor opt-out of having a self-observer
A content observer is registered by default when setting a notification
uri for a Cursor, in order to make the Cursor correctly notify listeners
of all changes to its URI, not just the ones made locally.

This is not required for DocumentCursor, because it already has a
separate mechanism for watching for all changes made to the data backed
by the cursor.

This avoids DocumentProviders having to call into system_server to
answer queries about directory trees, which can otherwise add up to
significant amounts of time for large directory trees. In my tests,
this improves the performance of iterating through a directory by
roughly 20%. This number is likely to be higher on non-test devices,
that probably see more binder contention, and will also depend on the
structure of the file tree.

Bug: 130276310
Test: SAF test app
Change-Id: I386363b0608c420e9847caf6fbf6686641c955e2
2019-05-03 13:33:57 +01:00
Anton Hansson
788ec75be5 Optimize FileSystemProvider.includeFile
When traversing a file tree using SAF, this method is called for
every file in the tree, so wasted cycles add up to quite a lot
of total time for large trees.

Optimizations:
- don't look up info not necessary by the cursor, by inspecting
  the projection columns
- remove a few redundant double-lookups, of e.g. the File path
- mark variables final where possible

On my device/file tree, this reduces the total time spent in includeFile
from ~33 seconds to ~22 seconds. This is where the majority of cycles
are spent when traversing a dir with SAF.

Bug: 130276310
Test: SAF test app
Change-Id: Ibdfc335253a90eb87795a7a4eecb8b7b89601f09
2019-04-30 15:49:33 +01:00
Jeff Sharkey
0ab6feb7c8 People might want GROUP_CONCAT.
Bug: 129890881
Test: none
Change-Id: I24b6cc3c65e7a25b34c57f17584ba75c40be38ab
2019-04-10 10:27:19 -06:00
Makoto Onuki
58d5470580 Change ISE to AssertException, which is more suitable.
Bug: 129139241
Bug: 129721058
Test: Treehugger
Change-Id: I12e97f37a58e1d88731a9bddd933abeb8c1169c1
2019-04-04 13:42:47 -07:00
Makoto Onuki
2276ceacb3 Improve CursorWindow failure message
Bug: 129139241
Bug: 129721058
Test: atest CursorWindowTest
Change-Id: Iac1c5ec6f999dadd638fc5ab47c69d13f60ea467
2019-04-03 16:01:33 +00:00
Jeff Sharkey
82d783c417 Support optional use of aggregation functions.
As long as the column being aggregated is valid with respect to
all existing projection checks, then we're willing to apply an
aggregation function on it.

Bug: 129220616
Test: atest --test-mapping packages/providers/MediaProvider
Change-Id: I8e4b665f5abd6553939a35d9f46247cc63c4c25f
2019-03-29 15:46:38 -06:00
Anton Hansson
a04d81ef47 Make TranslatingCursor deal with dupe column names
TranslatingCursor previously assumed each column name appeared
only once in the base cursor and used getColumIndex(String) to
find the index of it. It would then translate only that single
index.

Instead, maintain a set of column indices that need translating.

Also add a unit test.

Bug: 125467331
Test: atest FrameworksCoreTests:TranslatingCursorTest
Test: verified broken app in bug report is working correctly
Change-Id: I33a24bf6474338210ec7b9c6b54912ed49f23cb3
2019-03-27 17:29:59 +00:00
Jeff Sharkey
aa28dff4cb Respond to API council feedback.
Naming tweaks and hide API that should move to androidx.

Bug: 128427993
Test: none
Change-Id: Ic54452fdedbe72e5fa71897cc2b22e9598664c02
2019-03-25 18:01:10 -06:00
Makoto Onuki
55e9970511 Disable DB wipe check
We stopped using WAL, so let's just disable it

Change-Id: I14f4f3ca6521db12a2fbde8c20122bb4b2cc8186
Fix: 118613196
Test: Manual test with removing DB files
2019-03-19 14:04:56 -07:00
Makoto Onuki
42f353eb28 Merge "Update the deprecation description per API review" 2019-03-01 23:56:57 +00:00
Makoto Onuki
1a904797b9 Update the deprecation description per API review
Change-Id: If79ed1263aae5fc7db6e951051ebb6db20d971f5
Fix: 124882352
Test: build (tree hugger)
2019-03-01 13:34:30 -08:00
Jeff Sharkey
9e8f83db6d All Parcelable CREATOR fields are @NonNull.
If they were null, then the Parcelable would fail to work.

Bug: 126726802
Test: manual
Change-Id: I7929ffa2f20e5de1c8e68e8263cca99496e9d014
Exempt-From-Owner-Approval: Trivial API annotations
2019-02-28 23:29:04 -07:00
Jeff Sharkey
a30e5c389f To be @Nullable or @NonNull, that is the question.
Bug: 126699288, 126699496, 126700389
Bug: 126700085, 126701638, 126702005, 126700497
Test: manual
Change-Id: Idcbc2722ddcf014a9e5cef14321b4e2ce30adf9c
2019-03-01 06:26:39 +00:00
Sudheer Shanka
d5f4165e97 Merge "Address API feedback." 2019-02-28 23:24:45 +00:00
Sudheer Shanka
0f6069e666 Address API feedback.
Fixes: 126699828
Fixes: 126700458
Fixes: 126702364
Test: n/a
Change-Id: I20d415ee4fdcce97054f3b68986a65500e64fb2d
2019-02-28 12:18:11 -08:00
Andrei-Valentin Onea
94bd7aac42 Merge "Add @UnsupportedAppUsage annotations" 2019-02-28 15:21:13 +00:00
Andrei Onea
da6e570f1e Add @UnsupportedAppUsage annotations
For packages:
  android.database
  android.hardware
  android.hardware.display
  android.hardware.input
  android.hardware.location
  android.location
  android.media
  android.media.tv
  android.media.projection

This is an automatically generated CL. See go/UnsupportedAppUsage
for more details.

Exempted-From-Owner-Approval: Mechanical changes to the codebase
which have been approved by Android API council and announced on
android-eng@

Bug: 110868826
Test: m
Change-Id: I570c08292f8a9f512c96f9dce13f5337718f112c
2019-02-27 13:31:11 +00:00
Narayan Kamath
b8280438d8 Drop support for device configurable "compatibility WAL".
WAL as a journaling mode is no longer configurable on a
per-device basis. We preserve support for changing this value
via phenotype for now, but this will likely be removed in a
follow up once this change has been vetted.

Test: atest FrameworksCoreTests:android.database
Test: atest CtsDatabaseTestCases
Bug: 123352172
Change-Id: I163bad836b71770946ce12a8bfd19f362033ea83
2019-02-25 13:00:14 +00:00
Jeff Sharkey
b91eaa54a8 Respond to various API council feedback.
Handle many simple, smaller changes in a single CL.  Hide
CPC.closeQuietly(), now that it implements AutoCloseable.  Add more
details to CR.set/getCache() docs.  Add many @Nullable/@NonNull
annotations.

Bug: 124507578, 124447751, 124302519, 123697622
Bug: 123661322, 122887179, 122528742, 122527812, 116224797
Test: manual
Change-Id: Icee556a6ed76bbdf4c8e42b59d69d5580d461b95
2019-02-19 11:09:22 -07:00
Jeff Sharkey
0ec586b9d5 Add accessor methods to aid testing.
If you can set things, you should be able to read them back.

Bug: 123601452
Test: manual
Change-Id: I3a842aa873f96872581ec49523e9a3cc1d7dbb50
2019-02-14 15:29:28 -07:00
Makoto Onuki
7a8261dce2 Better handling of DB corruption in SQLiteDatabase.open()
Bug: 123750718
Test: manual test with test code
Change-Id: I80a9d35f7ad6589b3de0a506780cfe956295dcda
2019-02-01 12:54:55 -08:00