Skip to content

Commit 1a2fac3

Browse files
Christopher TateAndroid (Google) Code Review
authored andcommitted
Merge "Use myUserId() only in registerContentObserver()" into jb-mr1-dev
2 parents ac2fc16 + afccaa8 commit 1a2fac3

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

core/java/android/content/ContentResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ public final ContentProviderClient acquireUnstableContentProviderClient(String n
12191219
public final void registerContentObserver(Uri uri, boolean notifyForDescendents,
12201220
ContentObserver observer)
12211221
{
1222-
registerContentObserver(uri, notifyForDescendents, observer, UserHandle.getCallingUserId());
1222+
registerContentObserver(uri, notifyForDescendents, observer, UserHandle.myUserId());
12231223
}
12241224

12251225
/** @hide - designated user version */

core/java/android/database/AbstractCursor.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import android.content.ContentResolver;
2020
import android.net.Uri;
2121
import android.os.Bundle;
22+
import android.os.UserHandle;
2223
import android.util.Log;
2324

2425
import java.lang.ref.WeakReference;
@@ -350,14 +351,19 @@ protected void onChange(boolean selfChange) {
350351
* specific row URI, or a base URI for a whole class of content.
351352
*/
352353
public void setNotificationUri(ContentResolver cr, Uri notifyUri) {
354+
setNotificationUri(cr, notifyUri, UserHandle.myUserId());
355+
}
356+
357+
/** @hide - set the notification uri but with an observer for a particular user's view */
358+
public void setNotificationUri(ContentResolver cr, Uri notifyUri, int userHandle) {
353359
synchronized (mSelfObserverLock) {
354360
mNotifyUri = notifyUri;
355361
mContentResolver = cr;
356362
if (mSelfObserver != null) {
357363
mContentResolver.unregisterContentObserver(mSelfObserver);
358364
}
359365
mSelfObserver = new SelfContentObserver(this);
360-
mContentResolver.registerContentObserver(mNotifyUri, true, mSelfObserver);
366+
mContentResolver.registerContentObserver(mNotifyUri, true, mSelfObserver, userHandle);
361367
mSelfObserverRegistered = true;
362368
}
363369
}

packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import android.content.IntentFilter;
3434
import android.content.pm.PackageManager;
3535
import android.content.res.AssetFileDescriptor;
36+
import android.database.AbstractCursor;
3637
import android.database.Cursor;
3738
import android.database.sqlite.SQLiteDatabase;
3839
import android.database.sqlite.SQLiteException;
@@ -685,7 +686,16 @@ private Cursor queryForUser(Uri url, String[] select, String where, String[] whe
685686
qb.setTables(args.table);
686687

687688
Cursor ret = qb.query(db, select, args.where, args.args, null, null, sort);
688-
ret.setNotificationUri(getContext().getContentResolver(), url);
689+
// the default Cursor interface does not support per-user observation
690+
try {
691+
AbstractCursor c = (AbstractCursor) ret;
692+
c.setNotificationUri(getContext().getContentResolver(), url, forUser);
693+
} catch (ClassCastException e) {
694+
// details of the concrete Cursor implementation have changed and this code has
695+
// not been updated to match -- complain and fail hard.
696+
Log.wtf(TAG, "Incompatible cursor derivation!");
697+
throw e;
698+
}
689699
return ret;
690700
}
691701

0 commit comments

Comments
 (0)