summaryrefslogtreecommitdiffstats
path: root/core/java/android/widget/DateTimeView.java
diff options
context:
space:
mode:
authorKenny Guy <kennyguy@google.com>2014-09-02 12:11:07 +0100
committerKenny Guy <kennyguy@google.com>2014-09-04 12:40:24 +0100
commit879ebec4e2a12a802339549cb4fefa32b5368379 (patch)
tree3b1faad86fa14b93253aa1ffc5a5176f072d95bc /core/java/android/widget/DateTimeView.java
parent52c0f04cbcd9cb0d98d40b504256e2b3b110e6fc (diff)
downloadframeworks_base-879ebec4e2a12a802339549cb4fefa32b5368379.zip
frameworks_base-879ebec4e2a12a802339549cb4fefa32b5368379.tar.gz
frameworks_base-879ebec4e2a12a802339549cb4fefa32b5368379.tar.bz2
Ensure all RemoteViews use myUserId rather than context.
Remote views may be inflated in another user so explicitly use processes user id rather than the user id of the context. Bug: 17302505 Change-Id: I985c91745f03dd7e6b2ab6357600077664d8e6be
Diffstat (limited to 'core/java/android/widget/DateTimeView.java')
-rw-r--r--core/java/android/widget/DateTimeView.java26
1 files changed, 22 insertions, 4 deletions
diff --git a/core/java/android/widget/DateTimeView.java b/core/java/android/widget/DateTimeView.java
index 45d1403..b3ff88b 100644
--- a/core/java/android/widget/DateTimeView.java
+++ b/core/java/android/widget/DateTimeView.java
@@ -29,6 +29,7 @@ import android.util.Log;
import android.provider.Settings;
import android.widget.TextView;
import android.widget.RemoteViews.RemoteView;
+import android.os.UserHandle;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
@@ -190,8 +191,15 @@ public class DateTimeView extends TextView {
}
private DateFormat getDateFormat() {
- String format = Settings.System.getString(getContext().getContentResolver(),
- Settings.System.DATE_FORMAT);
+ // 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 user profile to the
+ // home screen. Therefore, we access settings as the user the app
+ // is running as not the one the context is for.
+ String format = Settings.System.getStringForUser(getContext().getContentResolver(),
+ Settings.System.DATE_FORMAT, UserHandle.myUserId());
if (format == null || "".equals(format)) {
return DateFormat.getDateInstance(DateFormat.SHORT);
} else {
@@ -212,10 +220,20 @@ public class DateTimeView extends TextView {
filter.addAction(Intent.ACTION_TIME_CHANGED);
filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
- context.registerReceiver(mBroadcastReceiver, filter);
+
+ // 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 user profile to the
+ // home screen. Therefore, we register the receiver and content
+ // observer as the user the app is running as not the one the context is for.
+ context.registerReceiverAsUser(mBroadcastReceiver, android.os.Process.myUserHandle(),
+ filter, null, null);
Uri uri = Settings.System.getUriFor(Settings.System.DATE_FORMAT);
- context.getContentResolver().registerContentObserver(uri, true, mContentObserver);
+ context.getContentResolver().registerContentObserver(uri, true, mContentObserver,
+ UserHandle.myUserId());
}
private void unregisterReceivers() {