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 | #pragma once |
| 18 | |
Andy Hung | 0f7ad8c | 2020-01-03 13:24:34 -0800 | [diff] [blame] | 19 | #include "AnalyticsActions.h" |
| 20 | #include "AnalyticsState.h" |
| 21 | #include "Wrap.h" |
Andy Hung | 06f3aba | 2019-12-03 16:36:42 -0800 | [diff] [blame] | 22 | |
| 23 | namespace android::mediametrics { |
| 24 | |
| 25 | class AudioAnalytics |
| 26 | { |
| 27 | public: |
| 28 | AudioAnalytics(); |
| 29 | ~AudioAnalytics(); |
| 30 | |
Andy Hung | 06f3aba | 2019-12-03 16:36:42 -0800 | [diff] [blame] | 31 | /** |
| 32 | * Returns success if AudioAnalytics recognizes item. |
| 33 | * |
| 34 | * AudioAnalytics requires the item key to start with "audio.". |
| 35 | * |
| 36 | * A trusted source can create a new key, an untrusted source |
| 37 | * can only modify the key if the uid will match that authorized |
| 38 | * on the existing key. |
| 39 | * |
| 40 | * \param item the item to be submitted. |
| 41 | * \param isTrusted whether the transaction comes from a trusted source. |
| 42 | * In this case, a trusted source is verified by binder |
| 43 | * UID to be a system service by MediaMetrics service. |
| 44 | * Do not use true if you haven't really checked! |
Andy Hung | 0f7ad8c | 2020-01-03 13:24:34 -0800 | [diff] [blame] | 45 | * |
| 46 | * \return NO_ERROR on success, |
| 47 | * PERMISSION_DENIED if the item cannot be put into the AnalyticsState, |
| 48 | * BAD_VALUE if the item key does not start with "audio.". |
Andy Hung | 06f3aba | 2019-12-03 16:36:42 -0800 | [diff] [blame] | 49 | */ |
Ray Essick | f27e987 | 2019-12-07 06:28:46 -0800 | [diff] [blame] | 50 | status_t submit(const std::shared_ptr<const mediametrics::Item>& item, bool isTrusted); |
Andy Hung | 06f3aba | 2019-12-03 16:36:42 -0800 | [diff] [blame] | 51 | |
| 52 | /** |
| 53 | * Returns a pair consisting of the dump string, and the number of lines in the string. |
| 54 | * |
| 55 | * The number of lines in the returned pair is used as an optimization |
| 56 | * for subsequent line limiting. |
| 57 | * |
| 58 | * The TimeMachine and the TransactionLog are dumped separately under |
| 59 | * different locks, so may not be 100% consistent with the last data |
| 60 | * delivered. |
| 61 | * |
| 62 | * \param lines the maximum number of lines in the string returned. |
| 63 | */ |
| 64 | std::pair<std::string, int32_t> dump(int32_t lines = INT32_MAX) const; |
| 65 | |
| 66 | private: |
Andy Hung | 0f7ad8c | 2020-01-03 13:24:34 -0800 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * Checks for any pending actions for a particular item. |
| 70 | * |
| 71 | * \param item to check against the current AnalyticsActions. |
| 72 | */ |
| 73 | void checkActions(const std::shared_ptr<const mediametrics::Item>& item); |
| 74 | |
Andy Hung | ea186fa | 2020-01-09 18:13:15 -0800 | [diff] [blame^] | 75 | // HELPER METHODS |
| 76 | /** |
| 77 | * Return the audio thread associated with an audio track name. |
| 78 | * e.g. "audio.track.32" -> "audio.thread.10" if the associated |
| 79 | * threadId for the audio track is 10. |
| 80 | */ |
| 81 | std::string getThreadFromTrack(const std::string& track) const; |
| 82 | |
Andy Hung | 0f7ad8c | 2020-01-03 13:24:34 -0800 | [diff] [blame] | 83 | // Actions is individually locked |
| 84 | AnalyticsActions mActions; |
| 85 | |
| 86 | // AnalyticsState is individually locked, and we use SharedPtrWrap |
| 87 | // to allow safe access even if the shared pointer changes underneath. |
| 88 | |
| 89 | SharedPtrWrap<AnalyticsState> mAnalyticsState; |
| 90 | SharedPtrWrap<AnalyticsState> mPreviousAnalyticsState; |
Andy Hung | 06f3aba | 2019-12-03 16:36:42 -0800 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | } // namespace android::mediametrics |