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

Commit 6e292694 authored by Tomasz Wasilczyk's avatar Tomasz Wasilczyk Committed by Android (Google) Code Review
Browse files

Merge "Implement out-of-band metadata images."

parents d98427b1 4482b141
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -17418,7 +17418,7 @@ package android.hardware.radio {
  public final class RadioMetadata implements android.os.Parcelable {
    method public boolean containsKey(java.lang.String);
    method public int describeContents();
    method public android.graphics.Bitmap getBitmap(java.lang.String);
    method public deprecated android.graphics.Bitmap getBitmap(java.lang.String);
    method public android.hardware.radio.RadioMetadata.Clock getClock(java.lang.String);
    method public int getInt(java.lang.String);
    method public java.lang.String getString(java.lang.String);
+3 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.hardware.radio;

import android.graphics.Bitmap;
import android.hardware.radio.ProgramSelector;
import android.hardware.radio.RadioManager;

@@ -64,6 +65,8 @@ interface ITuner {

    RadioManager.ProgramInfo getProgramInformation();

    Bitmap getImage(int id);

    /**
     * @returns {@code true} if the scan was properly scheduled,
     *          {@code false} if the scan feature is unavailable
+41 −10
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package android.hardware.radio;

import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@@ -240,6 +241,14 @@ public final class RadioMetadata implements Parcelable {
        return mBundle.getString(key);
    }

    private static void putInt(Bundle bundle, String key, int value) {
        int type = METADATA_KEYS_TYPE.getOrDefault(key, METADATA_TYPE_INVALID);
        if (type != METADATA_TYPE_INT && type != METADATA_TYPE_BITMAP) {
            throw new IllegalArgumentException("The " + key + " key cannot be used to put an int");
        }
        bundle.putInt(key, value);
    }

    /**
     * Returns the value associated with the given key,
     * or 0 if the key is not found in the meta data.
@@ -256,7 +265,9 @@ public final class RadioMetadata implements Parcelable {
     *
     * @param key The key the value is stored under
     * @return a {@link Bitmap} or null
     * @deprecated Use getBitmapId(String) instead
     */
    @Deprecated
    public Bitmap getBitmap(String key) {
        Bitmap bmp = null;
        try {
@@ -268,6 +279,30 @@ public final class RadioMetadata implements Parcelable {
        return bmp;
    }

    /**
     * Retrieves an identifier for a bitmap.
     *
     * The format of an identifier is opaque to the application,
     * with a special case of value 0 being invalid.
     * An identifier for a given image-tuner pair is unique, so an application
     * may cache images and determine if there is a necessity to fetch them
     * again - if identifier changes, it means the image has changed.
     *
     * Only bitmap keys may be used with this method:
     * <ul>
     * <li>{@link #METADATA_KEY_ICON}</li>
     * <li>{@link #METADATA_KEY_ART}</li>
     * </ul>
     *
     * @param key The key the value is stored under.
     * @return a bitmap identifier or 0 if it's missing.
     * @hide This API is not thoroughly elaborated yet
     */
    public int getBitmapId(@NonNull String key) {
        if (!METADATA_KEY_ICON.equals(key) && !METADATA_KEY_ART.equals(key)) return 0;
        return getInt(key);
    }

    public Clock getClock(String key) {
        Clock clock = null;
        try {
@@ -416,18 +451,14 @@ public final class RadioMetadata implements Parcelable {
         * <li>{@link #METADATA_KEY_RDS_PTY}</li>
         * <li>{@link #METADATA_KEY_RBDS_PTY}</li>
         * </ul>
         * or any bitmap represented by its identifier.
         *
         * @param key The key for referencing this value
         * @param value The int value to store
         * @return the same Builder instance
         */
        public Builder putInt(String key, int value) {
            if (!METADATA_KEYS_TYPE.containsKey(key) ||
                    METADATA_KEYS_TYPE.get(key) != METADATA_TYPE_INT) {
                throw new IllegalArgumentException("The " + key
                        + " key cannot be used to put a long");
            }
            mBundle.putInt(key, value);
            RadioMetadata.putInt(mBundle, key, value);
            return this;
        }

@@ -498,12 +529,12 @@ public final class RadioMetadata implements Parcelable {

    int putIntFromNative(int nativeKey, int value) {
        String key = getKeyFromNativeKey(nativeKey);
        if (!METADATA_KEYS_TYPE.containsKey(key) ||
                METADATA_KEYS_TYPE.get(key) != METADATA_TYPE_INT) {
        try {
            putInt(mBundle, key, value);
            return 0;
        } catch (IllegalArgumentException ex) {
            return -1;
        }
        mBundle.putInt(key, value);
        return 0;
    }

    int putStringFromNative(int nativeKey, String value) {
+22 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.hardware.radio;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.graphics.Bitmap;
import android.os.Handler;

import java.util.List;
@@ -229,6 +230,27 @@ public abstract class RadioTuner {
     */
    public abstract int getProgramInformation(RadioManager.ProgramInfo[] info);

    /**
     * Retrieves a {@link Bitmap} for the given image ID or null,
     * if the image was missing from the tuner.
     *
     * This involves doing a call to the tuner, so the bitmap should be cached
     * on the application side.
     *
     * If the method returns null for non-zero ID, it means the image was
     * updated on the tuner side. There is a race conditon between fetching
     * image for an old ID and tuner updating the image (and cleaning up the
     * old image). In such case, a new ProgramInfo with updated image id will
     * be sent with a {@link onProgramInfoChanged} callback.
     *
     * @param id The image identifier, retrieved with
     *           {@link RadioMetadata#getBitmapId(String)}.
     * @return A {@link Bitmap} or null.
     * @throws IllegalArgumentException if id==0
     * @hide This API is not thoroughly elaborated yet
     */
    public abstract @Nullable Bitmap getMetadataImage(int id);

    /**
     * Initiates a background scan to update internally cached program list.
     *
+10 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.hardware.radio;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.graphics.Bitmap;
import android.os.RemoteException;
import android.util.Log;

@@ -202,6 +203,15 @@ class TunerAdapter extends RadioTuner {
        }
    }

    @Override
    public @Nullable Bitmap getMetadataImage(int id) {
        try {
            return mTuner.getImage(id);
        } catch (RemoteException e) {
            throw new RuntimeException("service died", e);
        }
    }

    @Override
    public boolean startBackgroundScan() {
        try {
Loading