summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorDan Sandler <dsandler@android.com>2015-06-17 15:09:48 -0400
committerDan Sandler <dsandler@android.com>2015-06-18 15:12:44 -0400
commit4e78706f439d318ae7a78927d98f734351a89f64 (patch)
tree3035a9fcf4416407a288b21b798789ddc277720a /graphics
parente6ba94ce022a60b5225ee54cf2cc710633441d87 (diff)
downloadframeworks_base-4e78706f439d318ae7a78927d98f734351a89f64.zip
frameworks_base-4e78706f439d318ae7a78927d98f734351a89f64.tar.gz
frameworks_base-4e78706f439d318ae7a78927d98f734351a89f64.tar.bz2
Patch up certain kinds of broken notifications.
Notifications in which the icon resource ID is changed after Builder.build() is called (even, and particularly, as the last step in the current implementation of setLatestEventInfo()) were not having their icons properly parceled. In these cases we now attempt to catch this at parcel time and construct the necessary Icon object. But wait! Parceling does not require a Context. So we don't actually know which package to load the resource from. Therefore we now allow an Icon to be constructed with an empty ("") package name, which allows us to complete this parceling task despite the fact that a Notification does not know its own package name. (In case you attempt to load a drawable for such an Icon, loadDrawable will spot the "" package and instead substitute the Context from its parameters to try to load the resource.) As it happens, even though the Notification does not know its own package name, BaseStatusBar does, because it was provided at NM.notify() time and is therefore included in the StatusBarNotification structure. So we can actually patch up the Icon (if it is TYPE_RESOURCE) and be sure to get the icon loaded out of the correct package. While we've got the hood open, this change fixes a couple of related problems: • Foreground service notifications synthetically constructed for naughty icon==0 notifications (which we are still allowing...FOR NOW) were losing the FLAG_FOREGROUND_SERVICE flag (because we're re-build()-ing them from scratch rather than rewriting the provided Notification object). Now we set the flag and hang onto the new notification for next time setForeground() is called. • We now allow media notifications to avoid getting bumped to the top of the notification list if they're PRIORITY_MIN. You might want to do that, I guess? Bug: 21333763 Change-Id: Ia5d1f1acb594c7677bcc75ee3d624da4ffca671f
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/graphics/drawable/Icon.java30
1 files changed, 21 insertions, 9 deletions
diff --git a/graphics/java/android/graphics/drawable/Icon.java b/graphics/java/android/graphics/drawable/Icon.java
index 7b4329a..85db6a1 100644
--- a/graphics/java/android/graphics/drawable/Icon.java
+++ b/graphics/java/android/graphics/drawable/Icon.java
@@ -29,6 +29,7 @@ import android.os.Handler;
import android.os.Message;
import android.os.Parcel;
import android.os.Parcelable;
+import android.text.TextUtils;
import android.util.Log;
import java.io.DataInputStream;
@@ -258,16 +259,21 @@ public final class Icon implements Parcelable {
return new BitmapDrawable(context.getResources(), getBitmap());
case TYPE_RESOURCE:
if (getResources() == null) {
- if (getResPackage() == null || "android".equals(getResPackage())) {
+ // figure out where to load resources from
+ String resPackage = getResPackage();
+ if (TextUtils.isEmpty(resPackage)) {
+ // if none is specified, try the given context
+ resPackage = context.getPackageName();
+ }
+ if ("android".equals(resPackage)) {
mObj1 = Resources.getSystem();
} else {
final PackageManager pm = context.getPackageManager();
try {
- mObj1 = pm.getResourcesForApplication(getResPackage());
+ mObj1 = pm.getResourcesForApplication(resPackage);
} catch (PackageManager.NameNotFoundException e) {
- Log.e(TAG, String.format("Unable to find pkg=%s",
- getResPackage()),
- e);
+ Log.e(TAG, String.format("Unable to find pkg=%s for icon %s",
+ resPackage, this), e);
break;
}
}
@@ -320,12 +326,15 @@ public final class Icon implements Parcelable {
*/
public Drawable loadDrawableAsUser(Context context, int userId) {
if (mType == TYPE_RESOURCE) {
- if (getResources() == null
- && getResPackage() != null
- && !(getResPackage().equals("android"))) {
+ String resPackage = getResPackage();
+ if (TextUtils.isEmpty(resPackage)) {
+ resPackage = context.getPackageName();
+ }
+ if (getResources() == null && !(getResPackage().equals("android"))) {
final PackageManager pm = context.getPackageManager();
try {
- mObj1 = pm.getResourcesForApplicationAsUser(getResPackage(), userId);
+ // assign getResources() as the correct user
+ mObj1 = pm.getResourcesForApplicationAsUser(resPackage, userId);
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, String.format("Unable to find pkg=%s user=%d",
getResPackage(),
@@ -410,6 +419,9 @@ public final class Icon implements Parcelable {
* @param resId ID of the drawable resource
*/
public static Icon createWithResource(Context context, @DrawableRes int resId) {
+ if (context == null) {
+ throw new IllegalArgumentException("Context must not be null.");
+ }
final Icon rep = new Icon(TYPE_RESOURCE);
rep.mInt1 = resId;
rep.mString1 = context.getPackageName();