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

Commit adec8b8f authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 6349563 from 9295b533 to mainline-release

Change-Id: I0473f201af70bea3201b6b2496b121ebc2a5c624
parents d9afe451 9295b533
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -502,7 +502,7 @@ class AvrcpControllerStateMachine extends StateMachine {
                    // Let the addressed player know we got an image so it can see if the current
                    // track now has cover artwork
                    boolean addedArtwork = mAddressedPlayer.notifyImageDownload(handle, uri);
                    if (addedArtwork) {
                    if (addedArtwork && isActive()) {
                        BluetoothMediaBrowserService.trackChanged(
                                mAddressedPlayer.getCurrentTrack());
                    }
+2 −0
Original line number Diff line number Diff line
@@ -77,6 +77,7 @@ public class AvrcpCoverArtManager {
        mContext = context;
        mCoverArtStorage = new AvrcpCoverArtStorage(mContext);
        mCallback = callback;
        mCoverArtStorage.clear();
    }

    /**
@@ -123,6 +124,7 @@ public class AvrcpCoverArtManager {
        for (BluetoothDevice device : mClients.keySet()) {
            disconnect(device);
        }
        mCoverArtStorage.clear();
    }

    /**
+49 −10
Original line number Diff line number Diff line
@@ -88,12 +88,17 @@ public class AvrcpCoverArtStorage {

        String path = getImagePath(device, imageHandle);
        if (path == null) {
            debug("Cannot store image. Cannot provide a valid path to storage");
            error("Cannot store image. Cannot provide a valid path to storage");
            return null;
        }

        try {
            File deviceDirectory = new File(getDevicePath(device));
            String deviceDirectoryPath = getDevicePath(device);
            if (deviceDirectoryPath == null) {
                error("Cannot store image. Cannot get a valid path to per-device storage");
                return null;
            }
            File deviceDirectory = new File(deviceDirectoryPath);
            if (!deviceDirectory.exists()) {
                deviceDirectory.mkdirs();
            }
@@ -122,6 +127,10 @@ public class AvrcpCoverArtStorage {
        debug("Removing image '" + imageHandle + "' from device " + device);
        if (device == null || imageHandle == null || "".equals(imageHandle)) return;
        String path = getImagePath(device, imageHandle);
        if (path == null) {
            error("Cannot remove image. Cannot get a valid path to storage");
            return;
        }
        File file = new File(path);
        if (!file.exists()) return;
        file.delete();
@@ -136,17 +145,26 @@ public class AvrcpCoverArtStorage {
    public void removeImagesForDevice(BluetoothDevice device) {
        if (device == null) return;
        debug("Remove cover art for device " + device.getAddress());
        File deviceDirectory = new File(getDevicePath(device));
        File[] files = deviceDirectory.listFiles();
        if (files == null) {
            debug("No cover art files to delete");
        String deviceDirectoryPath = getDevicePath(device);
        if (deviceDirectoryPath == null) {
            error("Cannot remove images for device. Cannot get a valid path to storage");
            return;
        }
        for (int i = 0; i < files.length; i++) {
            debug("Deleted " + files[i].getAbsolutePath());
            files[i].delete();
        File deviceDirectory = new File(deviceDirectoryPath);
        deleteStorageDirectory(deviceDirectory);
    }

    /**
     * Clear the entirety of storage
     */
    public void clear() {
        String storageDirectoryPath = getStorageDirectory();
        if (storageDirectoryPath == null) {
            error("Cannot remove images, cannot get a valid path to storage. Is it mounted?");
            return;
        }
        deviceDirectory.delete();
        File storageDirectory = new File(storageDirectoryPath);
        deleteStorageDirectory(storageDirectory);
    }

    private String getStorageDirectory() {
@@ -171,6 +189,27 @@ public class AvrcpCoverArtStorage {
        return deviceDir + "/" + imageHandle + ".png";
    }

    private void deleteStorageDirectory(File directory) {
        if (directory == null) {
            error("Cannot delete directory, file is null");
            return;
        }
        if (!directory.exists()) return;
        File[] files = directory.listFiles();
        if (files == null) {
            return;
        }
        for (int i = 0; i < files.length; i++) {
            debug("Deleting " + files[i].getAbsolutePath());
            if (files[i].isDirectory()) {
                deleteStorageDirectory(files[i]);
            } else {
                files[i].delete();
            }
        }
        directory.delete();
    }

    @Override
    public String toString() {
        String s = "CoverArtStorage:\n";
+3 −1
Original line number Diff line number Diff line
@@ -187,8 +187,10 @@ class AvrcpPlayer {

    public synchronized boolean notifyImageDownload(String handle, Uri imageUri) {
        if (DBG) Log.d(TAG, "Got an image download -- handle=" + handle + ", uri=" + imageUri);
        if (mCurrentTrack != null && mCurrentTrack.getCoverArtHandle() == handle) {
        if (handle == null || imageUri == null || mCurrentTrack == null) return false;
        if (handle.equals(mCurrentTrack.getCoverArtHandle())) {
            mCurrentTrack.setCoverArtLocation(imageUri);
            if (DBG) Log.d(TAG, "Handle '" + handle + "' was added to current track.");
            return true;
        }
        return false;
+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;
Loading