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

Commit 48e500e3 authored by Sal Savage's avatar Sal Savage Committed by Gerrit Code Review
Browse files

Merge "Keep Media Framework/Bitmap exceptions from crashing Bluetooth"

parents 4db40c52 2fe3af04
Loading
Loading
Loading
Loading
+6 −1
Original line number Original line Diff line number Diff line
@@ -429,7 +429,12 @@ class BrowsedPlayerWrapper {
                    Folder f = new Folder(item.getMediaId(), false, title);
                    Folder f = new Folder(item.getMediaId(), false, title);
                    return_list.add(new ListItem(f));
                    return_list.add(new ListItem(f));
                } else {
                } else {
                    return_list.add(new ListItem(Util.toMetadata(mContext, item)));
                    Metadata data = Util.toMetadata(mContext, item);
                    if (Util.isEmptyData(data)) {
                        Log.e(TAG, "Received empty Metadata, ignoring browsed item");
                        continue;
                    }
                    return_list.add(new ListItem(data));
                }
                }
            }
            }


+49 −18
Original line number Original line Diff line number Diff line
@@ -43,17 +43,16 @@ class Util {
     * Get an empty set of Metadata
     * Get an empty set of Metadata
     */
     */
    public static final Metadata empty_data() {
    public static final Metadata empty_data() {
        Metadata ret = new Metadata();
        Metadata.Builder builder = new Metadata.Builder();
        ret.mediaId = "Not Provided";
        return builder.useDefaults().build();
        ret.title = "Not Provided";
    }
        ret.artist = "";

        ret.album = "";
    /**
        ret.genre = "";
     * Determine if a set of Metadata is "empty" as defined by audio_util.
        ret.trackNum = "1";
     */
        ret.numTracks = "1";
    public static final boolean isEmptyData(Metadata data) {
        ret.duration = "0";
        if (data == null) return true;
        ret.image = null;
        return (empty_data().equals(data) && data.mediaId.equals("Not Provided"));
        return ret;
    }
    }


    /**
    /**
@@ -71,7 +70,12 @@ class Util {
     */
     */
    public static Metadata toMetadata(Context context, Bundle bundle) {
    public static Metadata toMetadata(Context context, Bundle bundle) {
        Metadata.Builder builder = new Metadata.Builder();
        Metadata.Builder builder = new Metadata.Builder();
        try {
            return builder.useContext(context).useDefaults().fromBundle(bundle).build();
            return builder.useContext(context).useDefaults().fromBundle(bundle).build();
        } catch (Exception e) {
            Log.e(TAG, "Failed to build Metadata from Bundle, returning empty data", e);
            return empty_data();
        }
    }
    }


    /**
    /**
@@ -86,8 +90,13 @@ class Util {
        }
        }


        Metadata.Builder builder = new Metadata.Builder();
        Metadata.Builder builder = new Metadata.Builder();
        try {
            return builder.useContext(context).useDefaults().fromMediaDescription(desc)
            return builder.useContext(context).useDefaults().fromMediaDescription(desc)
                    .fromMediaMetadata(data).build();
                    .fromMediaMetadata(data).build();
        } catch (Exception e) {
            Log.e(TAG, "Failed to build Metadata from MediaDescription, returning empty data", e);
            return empty_data();
        }
    }
    }


    /**
    /**
@@ -95,14 +104,27 @@ class Util {
     */
     */
    public static Metadata toMetadata(Context context, MediaItem item) {
    public static Metadata toMetadata(Context context, MediaItem item) {
        Metadata.Builder builder = new Metadata.Builder();
        Metadata.Builder builder = new Metadata.Builder();
        try {
            return builder.useContext(context).useDefaults().fromMediaItem(item).build();
            return builder.useContext(context).useDefaults().fromMediaItem(item).build();
        } catch (Exception e) {
            Log.e(TAG, "Failed to build Metadata from MediaItem, returning empty data", e);
            return empty_data();
        }
    }
    }


    /**
    /**
     * Translate a MediaSession.QueueItem to audio_util's Metadata
     * Translate a MediaSession.QueueItem to audio_util's Metadata
     */
     */
    public static Metadata toMetadata(Context context, MediaSession.QueueItem item) {
    public static Metadata toMetadata(Context context, MediaSession.QueueItem item) {
        Metadata.Builder builder = new Metadata.Builder().useDefaults().fromQueueItem(item);
        Metadata.Builder builder = new Metadata.Builder();

        try {
            builder.useDefaults().fromQueueItem(item);
        } catch (Exception e) {
            Log.e(TAG, "Failed to build Metadata from QueueItem, returning empty data", e);
            return empty_data();
        }

        // For Queue Items, the Media Id will always be just its Queue ID
        // For Queue Items, the Media Id will always be just its Queue ID
        // We don't need to use its actual ID since we don't promise UIDS being valid
        // We don't need to use its actual ID since we don't promise UIDS being valid
        // between a file system and it's now playing list.
        // between a file system and it's now playing list.
@@ -118,8 +140,13 @@ class Util {
        // This will always be currsong. The AVRCP service will overwrite the mediaId if it needs to
        // This will always be currsong. The AVRCP service will overwrite the mediaId if it needs to
        // TODO (apanicke): Remove when the service is ready, right now it makes debugging much more
        // TODO (apanicke): Remove when the service is ready, right now it makes debugging much more
        // convenient
        // convenient
        try {
            return builder.useContext(context).useDefaults().fromMediaMetadata(data)
            return builder.useContext(context).useDefaults().fromMediaMetadata(data)
                    .setMediaId("currsong").build();
                    .setMediaId("currsong").build();
        } catch (Exception e) {
            Log.e(TAG, "Failed to build Metadata from MediaMetadata, returning empty data", e);
            return empty_data();
        }
    }
    }


    /**
    /**
@@ -133,6 +160,10 @@ class Util {


        for (int i = 0; i < items.size(); i++) {
        for (int i = 0; i < items.size(); i++) {
            Metadata data = toMetadata(context, items.get(i));
            Metadata data = toMetadata(context, items.get(i));
            if (isEmptyData(data)) {
                Log.e(TAG, "Received an empty Metadata item in list. Returning an empty queue");
                return new ArrayList<Metadata>();
            }
            data.trackNum = "" + (i + 1);
            data.trackNum = "" + (i + 1);
            data.numTracks = "" + items.size();
            data.numTracks = "" + items.size();
            list.add(data);
            list.add(data);