am 0e51f73d: am 8c1ce34b: am 50ec9b1b: Merge "Patch up certain kinds of broken notifications." into mnc-dev

* commit '0e51f73d9e8b7d0c731163411f74c74a697a4ed3':
  Patch up certain kinds of broken notifications.
This commit is contained in:
Dan Sandler
2015-06-18 20:55:57 +00:00
committed by Android Git Automerger
7 changed files with 94 additions and 27 deletions

View File

@@ -1371,6 +1371,9 @@ public class Notification implements Parcelable
when = parcel.readLong();
if (parcel.readInt() != 0) {
mSmallIcon = Icon.CREATOR.createFromParcel(parcel);
if (mSmallIcon.getType() == Icon.TYPE_RESOURCE) {
icon = mSmallIcon.getResId();
}
}
number = parcel.readInt();
if (parcel.readInt() != 0) {
@@ -1588,13 +1591,17 @@ public class Notification implements Parcelable
}
/**
* Flatten this notification from a parcel.
* Flatten this notification into a parcel.
*/
public void writeToParcel(Parcel parcel, int flags)
{
parcel.writeInt(1);
parcel.writeLong(when);
if (mSmallIcon == null && icon != 0) {
// you snuck an icon in here without using the builder; let's try to keep it
mSmallIcon = Icon.createWithResource("", icon);
}
if (mSmallIcon != null) {
parcel.writeInt(1);
mSmallIcon.writeToParcel(parcel, 0);
@@ -2791,7 +2798,10 @@ public class Notification implements Parcelable
return this;
}
private void setFlag(int mask, boolean value) {
/**
* @hide
*/
public void setFlag(int mask, boolean value) {
if (value) {
mFlags |= mask;
} else {

View File

@@ -25,6 +25,7 @@ import android.content.Context;
import android.content.pm.ParceledListSlice;
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
@@ -216,6 +217,12 @@ public class NotificationManager
}
}
fixLegacySmallIcon(notification, pkg);
if (mContext.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.LOLLIPOP_MR1) {
if (notification.getSmallIcon() == null) {
throw new IllegalArgumentException("Invalid notification (no valid small icon): "
+ notification);
}
}
if (localLOGV) Log.v(TAG, pkg + ": notify(" + id + ", " + notification + ")");
Notification stripped = notification.clone();
Builder.stripForDelivery(stripped);

View File

@@ -20,17 +20,27 @@ import android.graphics.drawable.Icon;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.UserHandle;
import android.text.TextUtils;
public class StatusBarIcon implements Parcelable {
public UserHandle user;
public String pkg;
public Icon icon;
public int iconLevel;
public boolean visible = true;
public int number;
public CharSequence contentDescription;
public StatusBarIcon(UserHandle user, Icon icon, int iconLevel, int number,
public StatusBarIcon(UserHandle user, String resPackage, Icon icon, int iconLevel, int number,
CharSequence contentDescription) {
if (icon.getType() == Icon.TYPE_RESOURCE
&& TextUtils.isEmpty(icon.getResPackage())) {
// This is an odd situation where someone's managed to hand us an icon without a
// package inside, probably by mashing an int res into a Notification object.
// Now that we have the correct package name handy, let's fix it.
icon = Icon.createWithResource(resPackage, icon.getResId());
}
this.pkg = resPackage;
this.user = user;
this.icon = icon;
this.iconLevel = iconLevel;
@@ -41,21 +51,23 @@ public class StatusBarIcon implements Parcelable {
public StatusBarIcon(String iconPackage, UserHandle user,
int iconId, int iconLevel, int number,
CharSequence contentDescription) {
this(user, Icon.createWithResource(iconPackage, iconId),
this(user, iconPackage, Icon.createWithResource(iconPackage, iconId),
iconLevel, number, contentDescription);
}
@Override
public String toString() {
return "StatusBarIcon(icon=" + this.icon
return "StatusBarIcon(icon=" + icon
+ ((iconLevel != 0)?(" level=" + iconLevel):"")
+ (visible?" visible":"")
+ " user=" + user.getIdentifier()
+ " level=" + this.iconLevel + " visible=" + visible
+ " num=" + this.number + " )";
+ ((number != 0)?(" num=" + number):"")
+ " )";
}
@Override
public StatusBarIcon clone() {
StatusBarIcon that = new StatusBarIcon(this.user, this.icon,
StatusBarIcon that = new StatusBarIcon(this.user, this.pkg, this.icon,
this.iconLevel, this.number, this.contentDescription);
that.visible = this.visible;
return that;
@@ -70,6 +82,7 @@ public class StatusBarIcon implements Parcelable {
public void readFromParcel(Parcel in) {
this.icon = (Icon) in.readParcelable(null);
this.pkg = in.readString();
this.user = (UserHandle) in.readParcelable(null);
this.iconLevel = in.readInt();
this.visible = in.readInt() != 0;
@@ -79,6 +92,7 @@ public class StatusBarIcon implements Parcelable {
public void writeToParcel(Parcel out, int flags) {
out.writeParcelable(this.icon, 0);
out.writeString(this.pkg);
out.writeParcelable(this.user, 0);
out.writeInt(this.iconLevel);
out.writeInt(this.visible ? 1 : 0);