Tomasz Wasilczyk | 06100b3 | 2017-12-04 09:53:32 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #define LOG_TAG "BcRadioDef.module" |
| 17 | #define LOG_NDEBUG 0 |
| 18 | |
| 19 | #include "BroadcastRadio.h" |
| 20 | |
| 21 | #include <log/log.h> |
| 22 | |
| 23 | #include "resources.h" |
| 24 | |
| 25 | namespace android { |
| 26 | namespace hardware { |
| 27 | namespace broadcastradio { |
| 28 | namespace V2_0 { |
| 29 | namespace implementation { |
| 30 | |
| 31 | using std::lock_guard; |
| 32 | using std::map; |
| 33 | using std::mutex; |
| 34 | using std::vector; |
| 35 | |
| 36 | static Properties initProperties(const VirtualRadio& virtualRadio) { |
| 37 | Properties prop = {}; |
| 38 | |
| 39 | prop.maker = "Google"; |
| 40 | prop.product = virtualRadio.getName(); |
| 41 | prop.supportedIdentifierTypes = hidl_vec<uint32_t>({ |
| 42 | static_cast<uint32_t>(IdentifierType::AMFM_FREQUENCY), |
| 43 | static_cast<uint32_t>(IdentifierType::RDS_PI), |
| 44 | static_cast<uint32_t>(IdentifierType::HD_STATION_ID_EXT), |
| 45 | }); |
| 46 | prop.vendorInfo = hidl_vec<VendorKeyValue>({ |
| 47 | {"com.google.dummy", "dummy"}, |
| 48 | }); |
| 49 | |
| 50 | return prop; |
| 51 | } |
| 52 | |
| 53 | BroadcastRadio::BroadcastRadio(const VirtualRadio& virtualRadio) |
| 54 | : mVirtualRadio(virtualRadio), mProperties(initProperties(virtualRadio)) {} |
| 55 | |
| 56 | Return<void> BroadcastRadio::getProperties(getProperties_cb _hidl_cb) { |
| 57 | ALOGV("%s", __func__); |
| 58 | _hidl_cb(mProperties); |
| 59 | return {}; |
| 60 | } |
| 61 | |
| 62 | Return<void> BroadcastRadio::openSession(const sp<ITunerCallback>& callback, |
| 63 | openSession_cb _hidl_cb) { |
| 64 | ALOGV("%s", __func__); |
| 65 | lock_guard<mutex> lk(mMut); |
| 66 | |
| 67 | auto oldSession = mSession.promote(); |
| 68 | if (oldSession != nullptr) { |
| 69 | ALOGI("Closing previously opened tuner"); |
| 70 | oldSession->close(); |
| 71 | mSession = nullptr; |
| 72 | } |
| 73 | |
| 74 | sp<TunerSession> newSession = new TunerSession(*this, callback); |
| 75 | mSession = newSession; |
| 76 | |
| 77 | _hidl_cb(Result::OK, newSession); |
| 78 | return {}; |
| 79 | } |
| 80 | |
| 81 | Return<void> BroadcastRadio::getImage(uint32_t id, getImage_cb _hidl_cb) { |
| 82 | ALOGV("%s(%x)", __func__, id); |
| 83 | |
| 84 | if (id == resources::demoPngId) { |
| 85 | _hidl_cb(std::vector<uint8_t>(resources::demoPng, std::end(resources::demoPng))); |
| 86 | return {}; |
| 87 | } |
| 88 | |
| 89 | ALOGI("Image %x doesn't exists", id); |
| 90 | _hidl_cb({}); |
| 91 | return {}; |
| 92 | } |
| 93 | |
| 94 | } // namespace implementation |
| 95 | } // namespace V2_0 |
| 96 | } // namespace broadcastradio |
| 97 | } // namespace hardware |
| 98 | } // namespace android |