diff options
-rw-r--r-- | core/java/android/app/Notification.java | 43 | ||||
-rwxr-xr-x | core/java/android/text/format/DateFormat.java | 21 | ||||
-rw-r--r-- | core/java/android/widget/DateTimeView.java | 26 | ||||
-rw-r--r-- | core/java/android/widget/RemoteViews.java | 4 | ||||
-rw-r--r-- | core/java/android/widget/TextClock.java | 21 | ||||
-rw-r--r-- | core/java/android/widget/TextView.java | 12 |
6 files changed, 87 insertions, 40 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index ebeaf34..6bc860c 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -21,6 +21,7 @@ import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; import android.content.Context; import android.content.Intent; +import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.graphics.Bitmap; import android.graphics.Canvas; @@ -816,13 +817,6 @@ public class Notification implements Parcelable public static final String EXTRA_COMPACT_ACTIONS = "android.compactActions"; /** - * {@link #extras} key: the user that built the notification. - * - * @hide - */ - public static final String EXTRA_ORIGINATING_USERID = "android.originatingUserId"; - - /** * Value for {@link #EXTRA_AS_HEADS_UP} that indicates this notification should not be * displayed in the heads up space. * @@ -1801,10 +1795,12 @@ public class Notification implements Parcelable = "android.rebuild.hudViewActionCount"; /** - * The package name of the context used to create the notification via a Builder. + * The ApplicationInfo of the package that created the notification, used to create + * a context to rebuild the notification via a Builder. + * @hide */ - private static final String EXTRA_REBUILD_CONTEXT_PACKAGE = - "android.rebuild.contextPackage"; + private static final String EXTRA_REBUILD_CONTEXT_APPLICATION_INFO = + "android.rebuild.applicationInfo"; // Whether to enable stripping (at post time) & rebuilding (at listener receive time) of // memory intensive resources. @@ -1855,11 +1851,6 @@ public class Notification implements Parcelable private int mColor = COLOR_DEFAULT; /** - * The user that built the notification originally. - */ - private int mOriginatingUserId; - - /** * Contains extras related to rebuilding during the build phase. */ private Bundle mRebuildBundle = new Bundle(); @@ -2579,7 +2570,7 @@ public class Notification implements Parcelable // Note: This assumes that the current user can read the profile badge of the // originating user. UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); - return userManager.getBadgeForUser(new UserHandle(mOriginatingUserId), 0); + return userManager.getBadgeForUser(new UserHandle(mContext.getUserId()), 0); } private Bitmap getProfileBadge() { @@ -2658,8 +2649,7 @@ public class Notification implements Parcelable * @param hasProgress whether the progress bar should be shown and set */ private RemoteViews applyStandardTemplate(int resId, boolean hasProgress) { - RemoteViews contentView = new BuilderRemoteViews(mContext.getPackageName(), - mOriginatingUserId, resId); + RemoteViews contentView = new BuilderRemoteViews(mContext.getApplicationInfo(), resId); resetStandardTemplate(contentView); @@ -3051,8 +3041,8 @@ public class Notification implements Parcelable */ public void populateExtras(Bundle extras) { // Store original information used in the construction of this object - extras.putInt(EXTRA_ORIGINATING_USERID, mOriginatingUserId); - extras.putString(EXTRA_REBUILD_CONTEXT_PACKAGE, mContext.getPackageName()); + extras.putParcelable(EXTRA_REBUILD_CONTEXT_APPLICATION_INFO, + mContext.getApplicationInfo()); extras.putCharSequence(EXTRA_TITLE, mContentTitle); extras.putCharSequence(EXTRA_TEXT, mContentText); extras.putCharSequence(EXTRA_SUB_TEXT, mSubText); @@ -3140,13 +3130,14 @@ public class Notification implements Parcelable extras.remove(EXTRA_NEEDS_REBUILD); // Re-create notification context so we can access app resources. - String packageName = extras.getString(EXTRA_REBUILD_CONTEXT_PACKAGE); + ApplicationInfo applicationInfo = extras.getParcelable( + EXTRA_REBUILD_CONTEXT_APPLICATION_INFO); Context builderContext; try { - builderContext = context.createPackageContext(packageName, + builderContext = context.createApplicationContext(applicationInfo, Context.CONTEXT_RESTRICTED); } catch (NameNotFoundException e) { - Log.e(TAG, "Package name " + packageName + " not found"); + Log.e(TAG, "ApplicationInfo " + applicationInfo + " not found"); builderContext = context; // try with our context } @@ -3281,7 +3272,6 @@ public class Notification implements Parcelable // Extras. Bundle extras = n.extras; - mOriginatingUserId = extras.getInt(EXTRA_ORIGINATING_USERID); mContentTitle = extras.getCharSequence(EXTRA_TITLE); mContentText = extras.getCharSequence(EXTRA_TEXT); mSubText = extras.getCharSequence(EXTRA_SUB_TEXT); @@ -3314,7 +3304,6 @@ public class Notification implements Parcelable * object. */ public Notification build() { - mOriginatingUserId = mContext.getUserId(); mHasThreeLines = hasThreeLines(); Notification n = buildUnstyled(); @@ -4814,8 +4803,8 @@ public class Notification implements Parcelable super(parcel); } - public BuilderRemoteViews(String packageName, int userId, int layoutId) { - super(packageName, userId, layoutId); + public BuilderRemoteViews(ApplicationInfo appInfo, int layoutId) { + super(appInfo, layoutId); } @Override diff --git a/core/java/android/text/format/DateFormat.java b/core/java/android/text/format/DateFormat.java index 9fec9a1..1e411b4 100755 --- a/core/java/android/text/format/DateFormat.java +++ b/core/java/android/text/format/DateFormat.java @@ -17,6 +17,7 @@ package android.text.format; import android.content.Context; +import android.os.UserHandle; import android.provider.Settings; import android.text.SpannableStringBuilder; import android.text.Spanned; @@ -128,8 +129,14 @@ public class DateFormat { * @return true if 24 hour time format is selected, false otherwise. */ public static boolean is24HourFormat(Context context) { - String value = Settings.System.getString(context.getContentResolver(), - Settings.System.TIME_12_24); + // This method is called by View classes that can be used by RemoteViews + // and rendered in another user. The context therefore may reference + // a user that would require interact accross users to access. So + // use the user id we are running as. + // This is the case when we have widgets from a user profile added + // to the homescreen. + String value = Settings.System.getStringForUser(context.getContentResolver(), + Settings.System.TIME_12_24, UserHandle.myUserId()); if (value == null) { Locale locale = context.getResources().getConfiguration().locale; @@ -227,8 +234,14 @@ public class DateFormat { * @return the {@link java.text.DateFormat} object that properly formats the date. */ public static java.text.DateFormat getDateFormat(Context context) { - String value = Settings.System.getString(context.getContentResolver(), - Settings.System.DATE_FORMAT); + // This method is called by View classes that can be used by RemoteViews + // and rendered in another user. The context therefore may reference + // a user that would require interact accross users to access. So + // use the user id we are running as. + // This is the case when we have widgets from a user profile added + // to the homescreen. + String value = Settings.System.getStringForUser(context.getContentResolver(), + Settings.System.DATE_FORMAT, UserHandle.myUserId()); return getDateFormatForSetting(context, value); } 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() { diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java index 69d5f40..9de69f2 100644 --- a/core/java/android/widget/RemoteViews.java +++ b/core/java/android/widget/RemoteViews.java @@ -1653,8 +1653,10 @@ public class RemoteViews implements Parcelable, Filter { * * @param application The application whose content is shown by the views. * @param layoutId The id of the layout resource. + * + * @hide */ - private RemoteViews(ApplicationInfo application, int layoutId) { + protected RemoteViews(ApplicationInfo application, int layoutId) { mApplication = application; mLayoutId = layoutId; mBitmapCache = new BitmapCache(); diff --git a/core/java/android/widget/TextClock.java b/core/java/android/widget/TextClock.java index 4c5c71d..acfc543 100644 --- a/core/java/android/widget/TextClock.java +++ b/core/java/android/widget/TextClock.java @@ -26,6 +26,7 @@ import android.database.ContentObserver; import android.net.Uri; import android.os.Handler; import android.os.SystemClock; +import android.os.UserHandle; import android.provider.Settings; import android.text.format.DateFormat; import android.util.AttributeSet; @@ -495,12 +496,28 @@ 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 user 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() { final ContentResolver resolver = getContext().getContentResolver(); - resolver.registerContentObserver(Settings.System.CONTENT_URI, true, mFormatChangeObserver); + // 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 content observer + // as the user the app is running as not the one the context is for. + resolver.registerContentObserver(Settings.System.CONTENT_URI, true, + mFormatChangeObserver, UserHandle.myUserId()); } private void unregisterReceiver() { diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 3e1b674..188a3e9 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -41,6 +41,7 @@ import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; import android.os.SystemClock; +import android.os.UserHandle; import android.provider.Settings; import android.text.BoringLayout; import android.text.DynamicLayout; @@ -8337,8 +8338,15 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener * to speak passwords. */ private boolean shouldSpeakPasswordsForAccessibility() { - return (Settings.Secure.getInt(mContext.getContentResolver(), - Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD, 0) == 1); + // 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 user the app is + // running as not the one the context is for. + return (Settings.Secure.getIntForUser(mContext.getContentResolver(), + Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD, 0, UserHandle.myUserId()) == 1); } @Override |