From 5a33106d7eb1a7fd22eaa6bdaace25aa09af7b61 Mon Sep 17 00:00:00 2001 From: Oleksandr Peletskyi Date: Mon, 11 Apr 2016 12:27:51 +0200 Subject: [PATCH] Fixed cross profile usage of TextClock. Fixed crash of a widget that uses TextClock and belongs to a work profile when is being added to the dash board. BUG:27035203 Change-Id: I70c66cb792d159d2527050db820e7154784148a2 --- core/java/android/widget/TextClock.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/java/android/widget/TextClock.java b/core/java/android/widget/TextClock.java index ff10287f3f891..a585d75e5d7ab 100644 --- a/core/java/android/widget/TextClock.java +++ b/core/java/android/widget/TextClock.java @@ -555,7 +555,15 @@ public class TextClock extends TextView { filter.addAction(Intent.ACTION_TIME_CHANGED); filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); - getContext().registerReceiver(mIntentReceiver, filter, null, getHandler()); + // OK, this is gross but 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 receiver as the user + // the app is running as not the one the context is for. + getContext().registerReceiverAsUser(mIntentReceiver, android.os.Process.myUserHandle(), + filter, null, getHandler()); } private void registerObserver() {