Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ea3aa801 authored by Sal Savage's avatar Sal Savage
Browse files

Notify on parents of nodes that have newly downloaded art

The BrowseTree code currently does a notifyChanged on the node itself
that had cover art added to it. This actually makes no sense at all, as
notifyChanged actually translates (a few levels of indirection later) to
a notifyCHILDRENchanged.

What we really want to do it notify on the parent folder that a child
has changed. This patch does that.

Bug: b/152444243
Test: build, flash, interop with cover devices, atest
BluetoothInstrumentationTests

Change-Id: I3d35368d5856cd3eb3865070bfedf3f863e4ccab
Merged-In: I3d35368d5856cd3eb3865070bfedf3f863e4ccab
parent a85834bf
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.util.Log;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;

@@ -197,6 +198,13 @@ public class BrowseTree {
                }
                mChildren.add(node);
                mBrowseMap.put(node.getID(), node);

                // Each time we add a node to the tree, check for an image handle so we can add
                // the artwork URI once it has been downloaded
                String imageHandle = node.getCoverArtHandle();
                if (imageHandle != null) {
                    indicateCoverArtUsed(node.getID(), imageHandle);
                }
                return true;
            }
            return false;
@@ -447,6 +455,7 @@ public class BrowseTree {
    synchronized void notifyImageDownload(String handle, Uri uri) {
        if (DBG) Log.d(TAG, "Received downloaded image handle to cascade to BrowseNodes using it");
        ArrayList<String> nodes = getNodesUsingCoverArt(handle);
        HashSet<BrowseNode> parents = new HashSet<BrowseNode>();
        for (String nodeId : nodes) {
            BrowseNode node = findBrowseNodeByID(nodeId);
            if (node == null) {
@@ -455,7 +464,14 @@ public class BrowseTree {
                continue;
            }
            node.setCoverArtUri(uri);
            indicateCoverArtUsed(nodeId, handle);
            if (node.mParent != null) {
                parents.add(node.mParent);
            }
        }

        // Update *parents* of changed nodes so applications will re-grab this node, now with art
        for (BrowseNode node : parents) {
            if (DBG) Log.d(TAG, "Notify node '" + node.getID() + "' that child has cover art now");
            BluetoothMediaBrowserService.notifyChanged(node);
        }
    }
@@ -468,7 +484,7 @@ public class BrowseTree {
            serialized += mRootNode.toString();
            serialized += "\n  Image handles in use (" + mCoverArtMap.size() + "):";
            for (String handle : mCoverArtMap.keySet()) {
                serialized += "    " + handle + "\n";
                serialized += "\n    " + handle + "\n";
            }
        }
        return serialized;