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

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

Snap for 6353066 from 6a33e821 to rvc-release

Change-Id: Id621597e926583266ca024871d5b51981dfa3386
parents 57183c31 6a33e821
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -514,7 +514,10 @@ public class MediaPlayerList {
        final MediaPlayerWrapper wrapper = mMediaPlayers.get(playerId);
        d("Removing media player " + wrapper.getPackageName());
        mMediaPlayerIds.remove(wrapper.getPackageName());
        if (!mBrowsablePlayers.containsKey(playerId)) {
            d(wrapper.getPackageName() + " doesn't have a browse service. Recycle player ID.");
            mMediaPlayers.remove(playerId);
        }
        wrapper.cleanup();
    }

+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;
Loading