Tomasz Wasilczyk | a02b6ef | 2017-07-05 11:23:30 -0700 | [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 | #ifndef ANDROID_HARDWARE_BROADCASTRADIO_V1_1_UTILS_H |
| 17 | #define ANDROID_HARDWARE_BROADCASTRADIO_V1_1_UTILS_H |
| 18 | |
| 19 | #include <android/hardware/broadcastradio/1.1/types.h> |
| 20 | #include <chrono> |
| 21 | #include <queue> |
| 22 | #include <thread> |
| 23 | |
| 24 | namespace android { |
| 25 | namespace hardware { |
| 26 | namespace broadcastradio { |
| 27 | namespace V1_1 { |
Tomasz Wasilczyk | a02b6ef | 2017-07-05 11:23:30 -0700 | [diff] [blame] | 28 | namespace utils { |
| 29 | |
Tomasz Wasilczyk | 5be4c2b | 2017-07-27 13:17:07 -0700 | [diff] [blame^] | 30 | // TODO(b/64115813): move it out from frameworks/base/services/core/jni/BroadcastRadio/types.h |
| 31 | enum class HalRevision : uint32_t { |
| 32 | V1_0 = 1, |
| 33 | V1_1, |
| 34 | }; |
| 35 | |
Tomasz Wasilczyk | a02b6ef | 2017-07-05 11:23:30 -0700 | [diff] [blame] | 36 | /** |
| 37 | * Checks, if {@code pointer} tunes to {@channel}. |
| 38 | * |
| 39 | * For example, having a channel {AMFM_FREQUENCY = 103.3}: |
| 40 | * - selector {AMFM_FREQUENCY = 103.3, HD_SUBCHANNEL = 0} can tune to this channel; |
| 41 | * - selector {AMFM_FREQUENCY = 103.3, HD_SUBCHANNEL = 1} can't. |
| 42 | * |
| 43 | * @param pointer selector we're trying to match against channel. |
| 44 | * @param channel existing channel. |
| 45 | */ |
| 46 | bool tunesTo(const ProgramSelector& pointer, const ProgramSelector& channel); |
| 47 | |
| 48 | ProgramType getType(const ProgramSelector& sel); |
| 49 | bool isAmFm(const ProgramType type); |
| 50 | |
| 51 | bool hasId(const ProgramSelector& sel, const IdentifierType type); |
| 52 | |
| 53 | /** |
| 54 | * Returns ID (either primary or secondary) for a given program selector. |
| 55 | * |
| 56 | * If the selector does not contain given type, returns 0 and emits a warning. |
| 57 | */ |
| 58 | uint64_t getId(const ProgramSelector& sel, const IdentifierType type); |
| 59 | |
| 60 | /** |
| 61 | * Returns ID (either primary or secondary) for a given program selector. |
| 62 | * |
| 63 | * If the selector does not contain given type, returns default value. |
| 64 | */ |
| 65 | uint64_t getId(const ProgramSelector& sel, const IdentifierType type, uint64_t defval); |
| 66 | |
| 67 | ProgramSelector make_selector(V1_0::Band band, uint32_t channel, uint32_t subChannel = 0); |
| 68 | |
Tomasz Wasilczyk | 2834b95 | 2017-07-12 14:17:09 -0700 | [diff] [blame] | 69 | bool getLegacyChannel(const ProgramSelector& sel, uint32_t* channelOut, uint32_t* subChannelOut); |
Tomasz Wasilczyk | a02b6ef | 2017-07-05 11:23:30 -0700 | [diff] [blame] | 70 | |
| 71 | bool isDigital(const ProgramSelector& sel); |
| 72 | |
| 73 | } // namespace utils |
Tomasz Wasilczyk | a02b6ef | 2017-07-05 11:23:30 -0700 | [diff] [blame] | 74 | } // namespace V1_1 |
Tomasz Wasilczyk | c1763a6 | 2017-07-25 10:01:17 -0700 | [diff] [blame] | 75 | |
| 76 | namespace V1_0 { |
| 77 | |
| 78 | bool operator==(const BandConfig& l, const BandConfig& r); |
| 79 | |
| 80 | } // namespace V1_0 |
| 81 | |
Tomasz Wasilczyk | a02b6ef | 2017-07-05 11:23:30 -0700 | [diff] [blame] | 82 | } // namespace broadcastradio |
| 83 | } // namespace hardware |
| 84 | } // namespace android |
| 85 | |
| 86 | #endif // ANDROID_HARDWARE_BROADCASTRADIO_V1_1_UTILS_H |