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

Commit 35f41b00 authored by Weilin Xu's avatar Weilin Xu
Browse files

Expose radio metadata image query APIs as system APIs

Promote hidden APIs related to radio metadata image query,
getBitmapId and getMetadata, to system API.

Bug: 318362428
Test: atest CtsBroadcastRadioTestCases
Change-Id: I5187cf717467a7f9093ed121df52c89a9414acdf
parent eea95000
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -6124,6 +6124,7 @@ package android.hardware.radio {
    method public boolean containsKey(String);
    method public int describeContents();
    method @Deprecated public android.graphics.Bitmap getBitmap(String);
    method @FlaggedApi("android.hardware.radio.hd_radio_improved") public int getBitmapId(@NonNull String);
    method public android.hardware.radio.RadioMetadata.Clock getClock(String);
    method public int getInt(String);
    method public String getString(String);
@@ -6187,6 +6188,7 @@ package android.hardware.radio {
    method @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public abstract void close();
    method @Deprecated @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public abstract int getConfiguration(android.hardware.radio.RadioManager.BandConfig[]);
    method @Nullable @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public android.hardware.radio.ProgramList getDynamicProgramList(@Nullable android.hardware.radio.ProgramList.Filter);
    method @FlaggedApi("android.hardware.radio.hd_radio_improved") @NonNull @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public android.graphics.Bitmap getMetadataImage(int);
    method @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public abstract boolean getMute();
    method @NonNull @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public java.util.Map<java.lang.String,java.lang.String> getParameters(@NonNull java.util.List<java.lang.String>);
    method @Deprecated @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public abstract int getProgramInformation(android.hardware.radio.RadioManager.ProgramInfo[]);
+8 −2
Original line number Diff line number Diff line
@@ -507,10 +507,16 @@ public final class RadioMetadata implements Parcelable {
     *
     * @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
     * @throws NullPointerException if metadata key is {@code null}
     * @throws IllegalArgumentException if the metadata with the key is not found in
     * metadata or the key is not of bitmap-key type
     */
    @FlaggedApi(Flags.FLAG_HD_RADIO_IMPROVED)
    public int getBitmapId(@NonNull String key) {
        if (!METADATA_KEY_ICON.equals(key) && !METADATA_KEY_ART.equals(key)) return 0;
        Objects.requireNonNull(key, "Metadata key can not be null");
        if (!METADATA_KEY_ICON.equals(key) && !METADATA_KEY_ART.equals(key)) {
            throw new IllegalArgumentException("Failed to retrieve key " + key + " as bitmap key");
        }
        return getInt(key);
    }

+12 −10
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.hardware.radio;

import android.Manifest;
import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -332,29 +333,30 @@ public abstract class RadioTuner {
    public abstract int getProgramInformation(RadioManager.ProgramInfo[] info);

    /**
     * Retrieves a {@link Bitmap} for the given image ID or null,
     * Retrieves a {@link Bitmap} for the given image ID or throw {@link IllegalArgumentException},
     * if the image was missing from the tuner.
     *
     * <p>This involves doing a call to the tuner, so the bitmap should be cached
     * on the application side.
     *
     * <p>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
     * <p>If the method throws {@link IllegalArgumentException} for non-zero ID, it
     * means the image was updated on the tuner side. There is a race condition 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 Callback#onProgramInfoChanged(RadioManager.ProgramInfo)}
     * 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
     * @return A {@link Bitmap} for the given image ID.
     * @throws IllegalArgumentException if id is 0 or the referenced image id no longer exists.
     */
    @SuppressWarnings("HiddenAbstractMethod")
    @FlaggedApi(Flags.FLAG_HD_RADIO_IMPROVED)
    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
    public abstract @Nullable Bitmap getMetadataImage(int id);

    public @NonNull Bitmap getMetadataImage(int id) {
        throw new UnsupportedOperationException(
                "Getting metadata image must be implemented in child classes");
    }
    /**
     * Initiates a background scan to update internally cached program list.
     *
+11 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.hardware.radio;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.graphics.Bitmap;
import android.os.RemoteException;
@@ -251,10 +252,18 @@ final class TunerAdapter extends RadioTuner {
    }

    @Override
    @Nullable
    @NonNull
    public Bitmap getMetadataImage(int id) {
        if (id == 0) {
            throw new IllegalArgumentException("Invalid metadata image id 0");
        }
        try {
            return mTuner.getImage(id);
            Bitmap bitmap = mTuner.getImage(id);
            if (bitmap == null) {
                throw new IllegalArgumentException("Metadata image with id " + id
                        + " is not available");
            }
            return bitmap;
        } catch (RemoteException e) {
            throw new RuntimeException("Service died", e);
        }
+10 −8
Original line number Diff line number Diff line
@@ -20,8 +20,6 @@ import static com.google.common.truth.Truth.assertWithMessage;

import static org.junit.Assert.assertThrows;

import android.graphics.Bitmap;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

@@ -88,12 +86,6 @@ public final class DefaultRadioTunerTest {
            return 0;
        }

        @Nullable
        @Override
        public Bitmap getMetadataImage(int id) {
            return null;
        }

        @Override
        public boolean startBackgroundScan() {
            return false;
@@ -137,6 +129,16 @@ public final class DefaultRadioTunerTest {
                .that(thrown).hasMessageThat().contains("Seeking is not supported");
    }

    @Test
    public void getMetadataImage_forRadioTuner_throwsException() {
        UnsupportedOperationException thrown = assertThrows(UnsupportedOperationException.class,
                () -> DEFAULT_RADIO_TUNER.getMetadataImage(/* id= */ 1));

        assertWithMessage("Exception for getting metadata image from default radio tuner")
                .that(thrown).hasMessageThat()
                .contains("Getting metadata image must be implemented in child classes");
    }

    @Test
    public void getDynamicProgramList_forRadioTuner_returnsNull() {
        assertWithMessage("Dynamic program list obtained from default radio tuner")
Loading