blob: b9312586f82ab0f640ccbe30154f72578c67de46 [file] [log] [blame]
Andy Hung06f3aba2019-12-03 16:36:42 -08001/*
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
19#include "TimeMachine.h"
20#include "TransactionLog.h"
21
22namespace android::mediametrics {
23
24class AudioAnalytics
25{
26public:
27 AudioAnalytics();
28 ~AudioAnalytics();
29
30 // TODO: update with conditions for keys.
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!
45 */
Ray Essickf27e9872019-12-07 06:28:46 -080046 status_t submit(const std::shared_ptr<const mediametrics::Item>& item, bool isTrusted);
Andy Hung06f3aba2019-12-03 16:36:42 -080047
48 /**
49 * Returns a pair consisting of the dump string, and the number of lines in the string.
50 *
51 * The number of lines in the returned pair is used as an optimization
52 * for subsequent line limiting.
53 *
54 * The TimeMachine and the TransactionLog are dumped separately under
55 * different locks, so may not be 100% consistent with the last data
56 * delivered.
57 *
58 * \param lines the maximum number of lines in the string returned.
59 */
60 std::pair<std::string, int32_t> dump(int32_t lines = INT32_MAX) const;
61
62private:
63 // The following are locked internally
64 TimeMachine mTimeMachine;
65 TransactionLog mTransactionLog;
66};
67
68} // namespace android::mediametrics