Merge "Revert "Ensure all RemoteViews use myUserId rather than context."" into lmp-dev

This commit is contained in:
Kenny Guy
2014-09-04 19:14:24 +00:00
committed by Android (Google) Code Review
6 changed files with 40 additions and 87 deletions

View File

@@ -21,7 +21,6 @@ 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;
@@ -824,6 +823,13 @@ 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.
@@ -1807,12 +1813,10 @@ public class Notification implements Parcelable
= "android.rebuild.hudViewActionCount";
/**
* The ApplicationInfo of the package that created the notification, used to create
* a context to rebuild the notification via a Builder.
* @hide
* The package name of the context used to create the notification via a Builder.
*/
private static final String EXTRA_REBUILD_CONTEXT_APPLICATION_INFO =
"android.rebuild.applicationInfo";
private static final String EXTRA_REBUILD_CONTEXT_PACKAGE =
"android.rebuild.contextPackage";
// Whether to enable stripping (at post time) & rebuilding (at listener receive time) of
// memory intensive resources.
@@ -1862,6 +1866,11 @@ public class Notification implements Parcelable
private ArrayList<String> mPeople;
private int mColor = COLOR_DEFAULT;
/**
* The user that built the notification originally.
*/
private int mOriginatingUserId;
/**
* Contains extras related to rebuilding during the build phase.
*/
@@ -2582,7 +2591,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(mContext.getUserId()), 0);
return userManager.getBadgeForUser(new UserHandle(mOriginatingUserId), 0);
}
private Bitmap getProfileBadge() {
@@ -2661,7 +2670,8 @@ 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.getApplicationInfo(), resId);
RemoteViews contentView = new BuilderRemoteViews(mContext.getPackageName(),
mOriginatingUserId, resId);
resetStandardTemplate(contentView);
@@ -3053,8 +3063,8 @@ public class Notification implements Parcelable
*/
public void populateExtras(Bundle extras) {
// Store original information used in the construction of this object
extras.putParcelable(EXTRA_REBUILD_CONTEXT_APPLICATION_INFO,
mContext.getApplicationInfo());
extras.putInt(EXTRA_ORIGINATING_USERID, mOriginatingUserId);
extras.putString(EXTRA_REBUILD_CONTEXT_PACKAGE, mContext.getPackageName());
extras.putCharSequence(EXTRA_TITLE, mContentTitle);
extras.putCharSequence(EXTRA_TEXT, mContentText);
extras.putCharSequence(EXTRA_SUB_TEXT, mSubText);
@@ -3142,14 +3152,13 @@ public class Notification implements Parcelable
extras.remove(EXTRA_NEEDS_REBUILD);
// Re-create notification context so we can access app resources.
ApplicationInfo applicationInfo = extras.getParcelable(
EXTRA_REBUILD_CONTEXT_APPLICATION_INFO);
String packageName = extras.getString(EXTRA_REBUILD_CONTEXT_PACKAGE);
Context builderContext;
try {
builderContext = context.createApplicationContext(applicationInfo,
builderContext = context.createPackageContext(packageName,
Context.CONTEXT_RESTRICTED);
} catch (NameNotFoundException e) {
Log.e(TAG, "ApplicationInfo " + applicationInfo + " not found");
Log.e(TAG, "Package name " + packageName + " not found");
builderContext = context; // try with our context
}
@@ -3284,6 +3293,7 @@ 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);
@@ -3316,6 +3326,7 @@ public class Notification implements Parcelable
* object.
*/
public Notification build() {
mOriginatingUserId = mContext.getUserId();
mHasThreeLines = hasThreeLines();
Notification n = buildUnstyled();
@@ -4815,8 +4826,8 @@ public class Notification implements Parcelable
super(parcel);
}
public BuilderRemoteViews(ApplicationInfo appInfo, int layoutId) {
super(appInfo, layoutId);
public BuilderRemoteViews(String packageName, int userId, int layoutId) {
super(packageName, userId, layoutId);
}
@Override

View File

@@ -17,7 +17,6 @@
package android.text.format;
import android.content.Context;
import android.os.UserHandle;
import android.provider.Settings;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
@@ -129,14 +128,8 @@ public class DateFormat {
* @return true if 24 hour time format is selected, false otherwise.
*/
public static boolean is24HourFormat(Context context) {
// 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());
String value = Settings.System.getString(context.getContentResolver(),
Settings.System.TIME_12_24);
if (value == null) {
Locale locale = context.getResources().getConfiguration().locale;
@@ -234,14 +227,8 @@ public class DateFormat {
* @return the {@link java.text.DateFormat} object that properly formats the date.
*/
public static java.text.DateFormat getDateFormat(Context context) {
// 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());
String value = Settings.System.getString(context.getContentResolver(),
Settings.System.DATE_FORMAT);
return getDateFormatForSetting(context, value);
}

View File

@@ -29,7 +29,6 @@ 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;
@@ -191,15 +190,8 @@ public class DateTimeView extends TextView {
}
private DateFormat getDateFormat() {
// 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());
String format = Settings.System.getString(getContext().getContentResolver(),
Settings.System.DATE_FORMAT);
if (format == null || "".equals(format)) {
return DateFormat.getDateInstance(DateFormat.SHORT);
} else {
@@ -220,20 +212,10 @@ public class DateTimeView extends TextView {
filter.addAction(Intent.ACTION_TIME_CHANGED);
filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
// 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);
context.registerReceiver(mBroadcastReceiver, filter);
Uri uri = Settings.System.getUriFor(Settings.System.DATE_FORMAT);
context.getContentResolver().registerContentObserver(uri, true, mContentObserver,
UserHandle.myUserId());
context.getContentResolver().registerContentObserver(uri, true, mContentObserver);
}
private void unregisterReceivers() {

View File

@@ -1653,10 +1653,8 @@ 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
*/
protected RemoteViews(ApplicationInfo application, int layoutId) {
private RemoteViews(ApplicationInfo application, int layoutId) {
mApplication = application;
mLayoutId = layoutId;
mBitmapCache = new BitmapCache();

View File

@@ -26,7 +26,6 @@ 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;
@@ -496,28 +495,12 @@ public class TextClock extends TextView {
filter.addAction(Intent.ACTION_TIME_CHANGED);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
// 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());
getContext().registerReceiver(mIntentReceiver, filter, null, getHandler());
}
private void registerObserver() {
final ContentResolver resolver = getContext().getContentResolver();
// 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());
resolver.registerContentObserver(Settings.System.CONTENT_URI, true, mFormatChangeObserver);
}
private void unregisterReceiver() {

View File

@@ -41,7 +41,6 @@ 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;
@@ -8338,15 +8337,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
* to speak passwords.
*/
private boolean shouldSpeakPasswordsForAccessibility() {
// 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);
return (Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD, 0) == 1);
}
@Override