Andy Hung | 06f3aba | 2019-12-03 16:36:42 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | |
| 17 | //#define LOG_NDEBUG 0 |
| 18 | #define LOG_TAG "AudioAnalytics" |
| 19 | #include <utils/Log.h> |
| 20 | |
| 21 | #include "AudioAnalytics.h" |
| 22 | |
| 23 | #include <audio_utils/clock.h> // clock conversions |
| 24 | |
| 25 | namespace android::mediametrics { |
| 26 | |
| 27 | AudioAnalytics::AudioAnalytics() |
| 28 | { |
| 29 | ALOGD("%s", __func__); |
| 30 | } |
| 31 | |
| 32 | AudioAnalytics::~AudioAnalytics() |
| 33 | { |
| 34 | ALOGD("%s", __func__); |
| 35 | } |
| 36 | |
| 37 | status_t AudioAnalytics::submit( |
| 38 | const std::shared_ptr<const MediaAnalyticsItem>& item, bool isTrusted) |
| 39 | { |
| 40 | if (startsWith(item->getKey(), "audio.")) { |
| 41 | return mTimeMachine.put(item, isTrusted) |
| 42 | ?: mTransactionLog.put(item); |
| 43 | } |
| 44 | return BAD_VALUE; |
| 45 | } |
| 46 | |
| 47 | std::pair<std::string, int32_t> AudioAnalytics::dump(int32_t lines) const |
| 48 | { |
| 49 | std::stringstream ss; |
| 50 | int32_t ll = lines; |
| 51 | |
| 52 | if (ll > 0) { |
| 53 | ss << "TransactionLog:\n"; |
| 54 | --ll; |
| 55 | } |
| 56 | if (ll > 0) { |
| 57 | auto [s, l] = mTransactionLog.dump(ll); |
| 58 | ss << s; |
| 59 | ll -= l; |
| 60 | } |
| 61 | if (ll > 0) { |
| 62 | ss << "TimeMachine:\n"; |
| 63 | --ll; |
| 64 | } |
| 65 | if (ll > 0) { |
| 66 | auto [s, l] = mTimeMachine.dump(ll); |
| 67 | ss << s; |
| 68 | ll -= l; |
| 69 | } |
| 70 | return { ss.str(), lines - ll }; |
| 71 | } |
| 72 | |
| 73 | } // namespace android |