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

Commit ba3e2544 authored by Tomasz Wasilczyk's avatar Tomasz Wasilczyk
Browse files

Implement out-of-band metadata images.

This saves a lot of HIDL bandwidth, by not including raw image data in
metadata vector.

Bug: b/63702941
Test: VTS
Change-Id: I73d5218095e4af34c58da8dcfc520abd4cb46c26
parent 9400122c
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -146,8 +146,11 @@ enum MetadataType : int32_t {
    /** String */
    TEXT       = 1,
    /**
     * Raw binary data (icon or art)
       This data must be transparent to the android framework */
     * Raw binary data (icon or art).
     *
     * The data should be a valid PNG, JPEG, GIF or BMP file.
     * Invalid format must be handled gracefully as if the field was missing.
     */
    RAW        = 2,
    /** clock data, see MetaDataClock */
    CLOCK      = 3,
@@ -173,9 +176,9 @@ enum MetadataKey : int32_t {
    ALBUM        = 7,
    /** Musical genre          - string  */
    GENRE        = 8,
    /** Station icon           - raw  */
    /** Station icon           - raw (int32_t for HAL 1.1) */
    ICON         = 9,
    /** Album art              - raw  */
    /** Album art              - raw (int32_t for HAL 1.1) */
    ART          = 10,
    /** Clock                  - MetaDataClock */
    CLOCK        = 11,
+48 −1
Original line number Diff line number Diff line
@@ -46,7 +46,8 @@ using ::android::hardware::broadcastradio::V1_0::BandConfig;
using ::android::hardware::broadcastradio::V1_0::Direction;
using ::android::hardware::broadcastradio::V1_0::ProgramInfo;
using ::android::hardware::broadcastradio::V1_0::MetaData;

using ::android::hardware::broadcastradio::V1_0::MetadataKey;
using ::android::hardware::broadcastradio::V1_0::MetadataType;

#define RETURN_IF_SKIPPED \
    if (skipped) { \
@@ -648,6 +649,52 @@ TEST_P(BroadcastRadioHidlTest, TuneFailsOutOfBounds) {
    EXPECT_TRUE(waitForCallback(kTuneCallbacktimeoutNs));
}

/**
 * Test proper image format in metadata.
 *
 * Verifies that:
 * - all images in metadata are provided in-band (as a binary blob, not by id)
 *
 * This is a counter-test for OobImagesOnly from 1.1 VTS.
 */
TEST_P(BroadcastRadioHidlTest, IbImagesOnly) {
    RETURN_IF_SKIPPED;
    ASSERT_TRUE(openTuner());
    ASSERT_TRUE(checkAntenna());

    bool firstScan = true;
    uint32_t firstChannel, prevChannel;
    while (true) {
        mCallbackCalled = false;
        auto hidlResult = mTuner->scan(Direction::UP, true);
        ASSERT_TRUE(hidlResult.isOk());
        if (hidlResult == Result::TIMEOUT) {
            ALOGI("Got timeout on scan operation");
            break;
        }
        ASSERT_EQ(Result::OK, hidlResult);
        ASSERT_EQ(true, waitForCallback(kTuneCallbacktimeoutNs));

        if (firstScan) {
            firstScan = false;
            firstChannel = mProgramInfoCallbackData.channel;
        } else {
            // scanned the whole band
            if (mProgramInfoCallbackData.channel >= firstChannel && prevChannel <= firstChannel) {
                break;
            }
        }
        prevChannel = mProgramInfoCallbackData.channel;

        for (auto&& entry : mProgramInfoCallbackData.metadata) {
            if (entry.key != MetadataKey::ICON && entry.key != MetadataKey::ART) continue;
            EXPECT_EQ(MetadataType::RAW, entry.type);
            EXPECT_EQ(0, entry.intValue);
            EXPECT_GT(entry.rawValue.size(), 0u);
        }
    }
}

INSTANTIATE_TEST_CASE_P(
    BroadcastRadioHidlTestCases,
    BroadcastRadioHidlTest,
+19 −0
Original line number Diff line number Diff line
@@ -27,4 +27,23 @@ interface IBroadcastRadio extends @1.0::IBroadcastRadio {
     */
    getProperties_1_1() generates (Properties properties);

    /**
     * Fetch image from radio module.
     *
     * This call is meant to make V1_0::MetaData lightweight - instead of
     * passing image data blob in MetadataType.RAW field, only identifier is
     * passed, so the client may cache images or even not fetch them.
     *
     * Identifier may be any arbitrary number - sequential, sha256 prefix,
     * or any other unique value selected by the vendor.
     *
     * The data should be a valid PNG, JPEG, GIF or BMP file.
     * Invalid format must be handled gracefully as if the image was missing.
     *
     * @param id Identifier of an image;
     *           value of 0 is reserved and should be treated as invalid image.
     * @return image A binary blob with image data
     *               or zero-length vector if identifier doesn't exists.
     */
    getImage(int32_t id) generates (vec<uint8_t> image);
};
+15 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@

#include <log/log.h>

#include "resources.h"

namespace android {
namespace hardware {
namespace broadcastradio {
@@ -155,6 +157,19 @@ Return<void> BroadcastRadio::openTuner(const BandConfig& config, bool audio __un
    return Void();
}

Return<void> BroadcastRadio::getImage(int32_t id, getImage_cb _hidl_cb) {
    ALOGV("%s(%x)", __func__, id);

    if (id == resources::demoPngId) {
        _hidl_cb(std::vector<uint8_t>(resources::demoPng, std::end(resources::demoPng)));
        return {};
    }

    ALOGI("Image %x doesn't exists", id);
    _hidl_cb({});
    return Void();
}

}  // namespace implementation
}  // namespace V1_1
}  // namespace broadcastradio
+1 −0
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ struct BroadcastRadio : public V1_1::IBroadcastRadio {
    Return<void> openTuner(const V1_0::BandConfig& config, bool audio,
                           const sp<V1_0::ITunerCallback>& callback,
                           openTuner_cb _hidl_cb) override;
    Return<void> getImage(int32_t id, getImage_cb _hidl_cb);

   private:
    std::mutex mMut;
Loading