12 Commits

Author SHA1 Message Date
Svet Ganov
8d2ed50604 Runtime permission attribution improvements
When an app is proxying access to runtime permission protected
data it needs to check whether the calling app has a permission
to the data it is about to proxy which leaves a trace in app ops
that the requesting app perofmed a data access. However, then the
app doing the work needs to get the protected data itself from the
OS which access gets attributed only to itself. As a result there
are two data accesses in app ops where only the first one is a
proxy one that app A got access to Foo through app B - that is the
one we want to show in the permission tracking UIs - and one
for the data access - that is the one we would want to blame on
the calling app, and in fact, these two accesses should be one -
that app A accessed Foo though B. This limitation requires fragile
one off workarounds where both accesses use the same attribution
tag and sys UI has hardcoded rules to dedupe. Since this is not
documented we cannot expect that the ecosystem would reliably
do this workaround in apps that that the workaround in the OS
would be respected by every OEM.

This change adds a mechaism to resolve this issue. It allows for
an app to create an attribution context for another app and then
any private data access thorugh this context would result in a
single app op blame that A accessed Foo though B, i.e. we no longer
have double accounting. Also this can be nested through apps, e.g.
app A asks app B which asks app C for contacts. In this case app
B creates an attribution context for app A and calls into app C
which creates an attribution context for app B. When app C gets
contacts the entire attribution chain would get a porper, single
blame: that C accessed the data, that B got the data from C, and
that A got the data form B. Furthermore, this mechanism ensures
that apps cannot forget to check permissions for the caller
before proxying private data. In our example B and C don't need
to check the permisisons for A and B, respectively, since the
permisisons for the entire attribution chain are checked before
data delivery. Attribution chains are not forgeable preventing
a bad actor to create an arbitrary one - each attribution is
created by the app it refers to and points to a chain of
attributions created by their corresponding apps.

This change also fixes a bug where all content provider accesses
were double counted in app ops due to double noting. While at
this it also fixes that apps can now access their own last ops.
There was a bug where one could not pass null getting the attributed
ops from a historical package ops while this is a valid use case
since if there is no attribution everything is mapped to the null
tag. There were some app op APIs not being piped thorough the app
ops delegate and by extension through the app ops policy. Also
now that we have nice way to express the permission chain in a
call we no longer need the special casing in activity manager to
handle content provider accesses through the OS. Fixed a bug
where we don't properly handle the android.os.shell calls with
an invlaid tag which was failing while the shell can do any tag.

Finally, to ensure the mechanims is validated and works end-to-end
we are adding support for a voice recognizer to blame the client
app for the mic access. The recognition service can create a blaming
context when opening the mic and if the mic is open, which would
do all permission checks, we would not do so again. Since changes
to PermissionChercker for handling attribution sources were made
the CL also hooks up renounced permissoins in the request permission
flow and in the permission checks.

bug:158792096
bug:180647319

Test:atest CtsPermissionsTestCases
     atest CtsPermissions2TestCases
     atest CtsPermissions3TestCases
     atest CtsPermissions4TestCases
     atest CtsPermissions5TestCases
     atest CtsAppOpsTestCases
     atest CtsAppOps2TestCases

Change-Id: Ib04585515d3dc3956966005ae9d94955b2f3ee08
2021-03-29 16:49:33 +00:00
Dmitri Plotnikov
ec2bc8d99f Add async version of "uncanonicalize"
This CL is basically identical to http://ag/10353234, which
did the same with the sister method, "canonicalize".

Fixes: b/147705670
Test: atest FrameworksCoreTests:android.content.ContentResolverTest
Change-Id: Ide93850f225cdd61779a62fc2c4666efe438b536
2020-10-28 17:27:27 -07:00
Jiyong Park
b4e458d106 Don't use impl lib of android.test.[mock|base|runners]
The java_sdk_library modules are now added with 'default_to_stubs: true'
so that their impl libraries are not used even when the clients don't
have sdk_version property set.

This will allow us to replace the direct references to the stub
libraries of the java_sdk_library modules with the references to the
modules themselves (e.g. android.test.base.stubs -> android.test.base)
in many of the CTS tests without unintentionally exposing the private
APIs in the impl lib.

As part of the change, MockContentProvider.getIContentProviderBinder()
now returns an anonymous Binder object instead of throwing an exception.
This is to eliminate the need for clients to override the now
inaccessible method to escape from the exception.

Also, InstrumentationTestRunner.addTestListener method is added to the
stub because it is used by several tests (MtpServiceTests, etc.)

Bug: 157007292
Test: m
Change-Id: I14cf217f21fd3534c920c3a6336cf2d14c02e60c
2020-06-25 08:08:40 +09:00
Dmitri Plotnikov
7a223fbcf1 Add async version of "canonicalize"
Fixes: b/147699082
Test: atest FrameworksCoreTests:android.content.ContentResolverTest
Change-Id: I2e851839a454ad5eabc981c76774d03b57a1aa09
2020-02-19 11:58:26 -08:00
Dmitri Plotnikov
d55a387f78 Add async version of getProviderMimeType
Fixes: b/147646960
Test: atest FrameworksCoreTests:android.content.ContentResolverTest

Change-Id: I04c15ac008fe14b215f954af150226dc94f22232
2020-01-28 17:35:45 -08:00
Jeff Sharkey
e9fe152f31 Extend insert/update/delete to provide extras.
A few releases ago we added ContentResolver.QUERY_ARG_* constants
to query() as a new best-practice that will help wean us off raw
SQL arguments.  (For example, a provider could add their own
custom arguments like QUERY_ARG_INCLUDE_PENDING to cause the query
to reveal pending items that would otherwise be hidden.)  This
change expands update() and delete() to accept those arguments.

This change also expand insert() to accept extras too, as part of
preparing to support an upcoming MediaProvider feature that will let
apps place new media "adjacent" to an existing media item.  (Sending
that adjacent item through extras is cleaner than trying to send it
through escaped query parameters.)

Bug: 131643582
Test: atest CtsContentTestCases
Change-Id: I436296155b9b5f371b4cbe661feaf42070285fcc
2019-11-15 13:46:31 -07:00
Philip P. Moltmann
128b70364e Note with featureId from ContentProvider
This takes the Context#getFeatureId from the calling context and pipes
it all way through to the noteOp calls done by the content provider.

Bug: 136595429
Test: atest CtsAppOpsTestCases (new test added to capture this case)
            TelecomUnitTests:CallLogManagerTest
	    ContentProviderClientTest
	    TelecomUnitTests:MissedCallNotifierImplTest
	    TelecomUnitTests:BasicCallTests
	    MediaInserterTest
	    PreferencesHelperTest
	    RankingHelperTest
	    PinnedSliceStateTest
	    FrameworksCoreTests:ContentResolverTest
Change-Id: I53b1035626229c920b353509a5bece157b52fb51
2019-10-29 15:41:28 -07:00
Jeff Sharkey
9edef25ede Detailed ContentProvider permissions checks.
The new MediaProvider design has an internal dynamic security model
based on the value stored in OWNER_PACKAGE_NAME, so the OS always
needs to consult the provider when resolving Uri permission grants.

Blocking calls from the system process like this are typically
discouraged, but this is the best we can do with the limited time
left, and there is existing precident with getType().

For now, use "forceUriPermissions" as a proxy for determining when
we need to consult the provider directly.

Bug: 115619667
Test: atest --test-mapping packages/providers/MediaProvider
Test: atest android.appsecurity.cts.ExternalStorageHostTest
Change-Id: I1d54feeec93fbb4cf5ff55240ef4eae3a35ed068
2019-07-12 09:27:41 -06:00
Sudheer Shanka
fe7668ab4d Add Downloads.Impl.COLUMN_MEDIASTORE_URI & DownloadColumns.Description.
Entries from DownloadProvider are added to MediaStore Downloads
collection. COLUMN_MEDIASTORE_URI will be used to track corresponding
entries in MediaProvider. We can't re-use COLUMN_MEDIAPROVIDER_URI
for this purpose because it is updateable by apps.

Bug: 120876251
Test: atest DownloadProviderTests
Test: atest cts/tests/app/src/android/app/cts/DownloadManagerTest.java
Test: atest MediaProviderTests
Test: atest cts/tests/tests/provider/src/android/provider/cts/MediaStore*
Change-Id: Ifd252c54f4ee739a31be2866896efac6696a088e
2019-01-05 19:01:40 -08:00
Jeff Sharkey
633a13e2fa Extract common methods into ContentInterface.
Existing APIs that accept a ContentResolver are too restrictive when
the caller has their own ContentProviderClient already bound and
configured, so we're in the market for a solution to open those
existing APIs to accept a wider range of inputs.

The solution we've come up with is to introduce a super-interface
which contains the common ContentProvider APIs, and then make
ContentProvider, ContentResolver, and ContentProviderClient all
implement that interface for consistency.

After this change lands, we can then safely relax existing APIs to
accept this new ContentInterface, offering a clean path to solving
the problem outlined above.

Bug: 117635768
Test: atest android.content.cts
Test: atest android.provider.cts
Change-Id: Ic5ae08107f7dd3dd23dcaec2df40c16543e0d86e
Exempted-From-Owner-Approval: keep tests working
2018-12-08 11:25:13 -07:00
Paul Duffin
772b692320 Add apis needed for android.test.legacy
The long term goal of removing junit and dependent android.test classes
from the android.jar is the removal of the runtime libraries that
provide those classes. A key part of the strategy for migrating APKs off
the runtime libraries is the android.test.legacy library which APKs can
statically include in place of the runtime dependencies without having
to change their source code.

The longer term goal is for all tests to migrate from these classes
altogther and to use the Android Test Support Library instead but that
will require significant changes to the test source code.

In order for it to be safe to statically include android.test.legacy in
an APK it cannot use any internal APIs. This change adds the additional
classes and methods needed to the android.test.mock API library. The
additions are all marked as deprecated to try and avoid developers
from using them in new tests.

It also marks the AccountManager constructor used by MockAccountManager
with the android.annotation.MockApi so that it is included in the mock
stubs libraries against which the android.test.mock.stubs[-system]
libraries build.

Bug: 30188076
Test: make checkbuild
Change-Id: I85417cc328cab898ab93b9b726648f4232555324
2018-01-09 14:38:38 +00:00
Paul Duffin
e254526f0f Separate android.test.mock from test-runner source
Extracts the source for the android.test.mock library from the
frameworks/base/test-runner directory into its own
frameworks/base/test-mock directory. They are already treated separately
at runtime and compile time so this just makes the separation complete.

Bug: 30188076
Test: make checkbuild
Change-Id: I20e5b06ba79677e76117c82e9f9e2ecd15e5fed6
2017-11-16 13:15:29 +00:00