OSDN Git Service

Use myUserId() only in registerContentObserver()
authorChristopher Tate <ctate@google.com>
Thu, 4 Oct 2012 00:41:51 +0000 (17:41 -0700)
committerChristopher Tate <ctate@google.com>
Thu, 4 Oct 2012 00:41:51 +0000 (17:41 -0700)
commitafccaa84c8d1b9aa45040ddeb0edd42ba80e80d6
tree3650d663133dda528c4c426086e76b7956642cd8
parent76366938242282e37863e1fd8b7fa16e7fd554c1
Use myUserId() only in registerContentObserver()

The reason for this is a bit subtle: we want to guarantee that
when a content observer is registered using the public API, it
is *always* bound to the host user's view of the data behind the
observed Uri, never the calling user's.  Now, the reason it was
the calling user in the first place is that the Settings provider
(and potentially any singleton provider) needs the observers
underlying Cursors returned from query() to be tied to the caller's
user, not the provider's host user.

In order to accomplish that now that the public-facing behavior is
always tied to the host user, the concrete class that implements
the Cursor type handled by the Settings provider has been extended
with a new hidden API for setting a notification observer tied to
an arbitrary user; and then the provider explicitly downcasts the
query result's Cursor to that class in order to register the
notification observer.  We can do this safely because this is platform
code; if we change the way that these underlying cursors are constructed,
we can just fix this point of call to follow along.  If they get out
of sync in the future, the Settings provider will scream bloody
murder in the log and throw a crashing exception.

Bug 7231549

Change-Id: I0aaceebb8b4108c56f8b9964ca7f9e698ddd91c8
core/java/android/content/ContentResolver.java
core/java/android/database/AbstractCursor.java
packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java