diff options
| author | Daniel Sandler <dsandler@android.com> | 2015-05-18 20:21:23 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-05-18 20:21:24 +0000 |
| commit | 4d19a8606346cdc22dfba4d5468e3111ad13518f (patch) | |
| tree | 5021e487e7a9af50fd4109a3b3d94f7390096c89 | |
| parent | 95ba62f8d0e753bc7905b915d0b2b510d09c320c (diff) | |
| parent | f5a7838e19c1cb6437a8b32ba9980ac1ce8804e2 (diff) | |
| download | frameworks_base-4d19a8606346cdc22dfba4d5468e3111ad13518f.zip frameworks_base-4d19a8606346cdc22dfba4d5468e3111ad13518f.tar.gz frameworks_base-4d19a8606346cdc22dfba4d5468e3111ad13518f.tar.bz2 | |
Merge "Make all icon fields & extras sent to listeners backward-compatible." into mnc-dev
| -rw-r--r-- | core/java/android/service/notification/NotificationListenerService.java | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/core/java/android/service/notification/NotificationListenerService.java b/core/java/android/service/notification/NotificationListenerService.java index 7956a3f..e4cdc97 100644 --- a/core/java/android/service/notification/NotificationListenerService.java +++ b/core/java/android/service/notification/NotificationListenerService.java @@ -27,6 +27,10 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.ParceledListSlice; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.graphics.drawable.Icon; +import android.graphics.Bitmap; import android.os.Bundle; import android.os.IBinder; import android.os.Parcel; @@ -322,7 +326,7 @@ public abstract class NotificationListenerService extends Service { if (!isBound()) return; try { getNotificationInterface().cancelNotificationsFromListener(mWrapper, - new String[] {key}); + new String[] { key }); } catch (android.os.RemoteException ex) { Log.v(TAG, "Unable to contact notification manager", ex); } @@ -636,6 +640,24 @@ public abstract class NotificationListenerService extends Service { } } + /** Convert new-style Icons to legacy representations for pre-M clients. */ + private void createLegacyIconExtras(Notification n) { + Icon smallIcon = n.getSmallIcon(); + Icon largeIcon = n.getLargeIcon(); + if (smallIcon.getType() == Icon.TYPE_RESOURCE) { + n.extras.putInt(Notification.EXTRA_SMALL_ICON, smallIcon.getResId()); + n.icon = smallIcon.getResId(); + } + if (largeIcon != null) { + Drawable d = largeIcon.loadDrawable(getContext()); + if (d != null && d instanceof BitmapDrawable) { + final Bitmap largeIconBits = ((BitmapDrawable) d).getBitmap(); + n.extras.putParcelable(Notification.EXTRA_LARGE_ICON, largeIconBits); + n.largeIcon = largeIconBits; + } + } + } + private class INotificationListenerWrapper extends INotificationListener.Stub { @Override public void onNotificationPosted(IStatusBarNotificationHolder sbnHolder, @@ -649,6 +671,9 @@ public abstract class NotificationListenerService extends Service { } Notification.Builder.rebuild(getContext(), sbn.getNotification()); + // convert icon metadata to legacy format for older clients + createLegacyIconExtras(sbn.getNotification()); + // protect subclass from concurrent modifications of (@link mNotificationKeys}. synchronized (mWrapper) { applyUpdate(update); |
