Bug 1305430 - part1 : send the notification again after tab got its favicon. draft
authorAlastor Wu <alwu@mozilla.com>
Mon, 03 Oct 2016 17:18:58 +0800
changeset 420093 ce46efc86d689e2b2481810c2bba08181491f944
parent 420017 955840bfd3c20eb24dd5a01be27bdc55c489a285
child 420094 a9f7a473e82d252c8a5ec46bd7284897d5d40493
push id31090
push useralwu@mozilla.com
push dateMon, 03 Oct 2016 09:21:57 +0000
bugs1305430
milestone52.0a1
Bug 1305430 - part1 : send the notification again after tab got its favicon. MozReview-Commit-ID: BAPPqlrIpaU
mobile/android/base/java/org/mozilla/gecko/media/MediaControlService.java
--- a/mobile/android/base/java/org/mozilla/gecko/media/MediaControlService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/MediaControlService.java
@@ -53,16 +53,17 @@ public class MediaControlService extends
 
     private boolean mInitialize = false;
     private boolean mIsMediaControlPrefOn = true;
 
     private static WeakReference<Tab> mTabReference = new WeakReference<>(null);
 
     private int minCoverSize;
     private int coverSize;
+    private boolean mUseDefaultCoverIcon;
 
     @Override
     public void onCreate() {
         initialize();
     }
 
     @Override
     public void onDestroy() {
@@ -109,19 +110,31 @@ public class MediaControlService extends
                 break;
 
             case CLOSED:
                 if (playingTab == null || playingTab == tab) {
                     // Remove the controls when the playing tab disappeared or was closed.
                     mController.getTransportControls().stop();
                 }
                 break;
+            case FAVICON:
+                if (playingTab == tab && mUseDefaultCoverIcon) {
+                    final String actionForPendingIntent = isMediaPlaying() ?
+                        ACTION_PAUSE : ACTION_RESUME;
+                    notifyControlInterfaceChanged(actionForPendingIntent);
+                }
+                break;
         }
     }
 
+   private boolean isMediaPlaying() {
+        return mActionState.equals(ACTION_RESUME) ||
+               mActionState.equals(ACTION_RESUME_BY_AUDIO_FOCUS);
+    }
+
     private void initialize() {
         if (mInitialize ||
             !isAndroidVersionLollopopOrHigher()) {
             return;
         }
 
         Log.d(LOGTAG, "initialize");
         getGeckoPreference();
@@ -378,17 +391,20 @@ public class MediaControlService extends
     }
 
     private Bitmap generateCoverArt(Tab tab) {
         final Bitmap favicon = tab.getFavicon();
 
         // If we do not have a favicon or if it's smaller than 72 pixels then just use the default icon.
         if (favicon == null || favicon.getWidth() < minCoverSize || favicon.getHeight() < minCoverSize) {
             // Use the launcher icon as fallback
+            mUseDefaultCoverIcon = true;
             return BitmapFactory.decodeResource(getResources(), R.drawable.notification_media);
+        } else {
+            mUseDefaultCoverIcon = false;
         }
 
         // Favicon should at least have half of the size of the cover
         int width = Math.max(favicon.getWidth(), coverSize / 2);
         int height = Math.max(favicon.getHeight(), coverSize / 2);
 
         final Bitmap coverArt = Bitmap.createBitmap(coverSize, coverSize, Bitmap.Config.ARGB_8888);
         final Canvas canvas = new Canvas(coverArt);