Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ea05bd56 authored by Bookatz's avatar Bookatz
Browse files

TextClock registerContentObserver with UserHandle

When adding a widget that uses TextClock to the home screen from a work
profile, the home screen may crash due to a
android.permission.INTERACT_ACROSS_USERS permission error, due to a
mismatch between the caller's userId and the widget's userId.
This fix uses the caller's userId to register the ContentObserver.

Bug: 111627637
Test: added a widget (as specified in the bug) that uses TextClock from a work profile
Change-Id: I153e55b755d656f1d7882645df15290bf8ad56f9
parent 38cb44b8
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -610,8 +610,16 @@ public class TextClock extends TextView {
                resolver.registerContentObserver(uri, true,
                        mFormatChangeObserver, UserHandle.USER_ALL);
            } else {
                // UserHandle.myUserId() is needed. This class is supported by the
                // remote views mechanism and as a part of that the remote views
                // can be inflated by a context for another user without the app
                // having interact users permission - just for loading resources.
                // For example, when adding widgets from a managed profile to the
                // home screen. Therefore, we register the ContentObserver with the user
                // the app is running (e.g. the launcher) and not the user of the
                // context (e.g. the widget's profile).
                resolver.registerContentObserver(uri, true,
                        mFormatChangeObserver);
                        mFormatChangeObserver, UserHandle.myUserId());
            }
        }
    }