blob: 3e2298fd17ee49c7b8d036071da74e66817d7e93 [file] [log] [blame]
Ray Essick3938dc62016-11-01 08:56:56 -07001/*
2 * Copyright (C) 2016 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
18#ifndef ANDROID_MEDIAANALYTICSSERVICE_H
19#define ANDROID_MEDIAANALYTICSSERVICE_H
20
21#include <arpa/inet.h>
22
23#include <utils/threads.h>
24#include <utils/Errors.h>
25#include <utils/KeyedVector.h>
26#include <utils/String8.h>
27#include <utils/List.h>
28
29#include <media/IMediaAnalyticsService.h>
30
31
32namespace android {
33
34class MediaAnalyticsService : public BnMediaAnalyticsService
35{
36
37 public:
38
Ray Essickb5fac8e2016-12-12 11:33:56 -080039 // on this side, caller surrenders ownership
40 virtual int64_t submit(MediaAnalyticsItem *item, bool forcenew);
Ray Essick3938dc62016-11-01 08:56:56 -070041
Ray Essickb5fac8e2016-12-12 11:33:56 -080042 virtual List<MediaAnalyticsItem *>
Ray Essick3938dc62016-11-01 08:56:56 -070043 *getMediaAnalyticsItemList(bool finished, int64_t ts);
Ray Essickb5fac8e2016-12-12 11:33:56 -080044 virtual List<MediaAnalyticsItem *>
Ray Essick3938dc62016-11-01 08:56:56 -070045 *getMediaAnalyticsItemList(bool finished, int64_t ts, MediaAnalyticsItem::Key key);
46
47
48 static void instantiate();
49 virtual status_t dump(int fd, const Vector<String16>& args);
50
51 MediaAnalyticsService();
52 virtual ~MediaAnalyticsService();
53
54 private:
55 MediaAnalyticsItem::SessionID_t generateUniqueSessionID();
56
57 // statistics about our analytics
58 int64_t mItemsSubmitted;
59 int64_t mItemsFinalized;
60 int64_t mItemsDiscarded;
61 MediaAnalyticsItem::SessionID_t mLastSessionID;
62
63 // partitioned a bit so we don't over serialize
64 mutable Mutex mLock;
65 mutable Mutex mLock_ids;
66
67 // the most we hold in memory
68 // up to this many in each queue (open, finalized)
69 int32_t mMaxRecords;
70
71 // input validation after arrival from client
Ray Essickb5fac8e2016-12-12 11:33:56 -080072 bool contentValid(MediaAnalyticsItem *);
73 bool rateLimited(MediaAnalyticsItem *);
Ray Essick3938dc62016-11-01 08:56:56 -070074
75 // the ones that are still open
76 // (newest at front) since we keep looking for them
Ray Essickb5fac8e2016-12-12 11:33:56 -080077 List<MediaAnalyticsItem *> *mOpen;
Ray Essick3938dc62016-11-01 08:56:56 -070078 // the ones we've finalized
79 // (oldest at front) so it prints nicely for dumpsys
Ray Essickb5fac8e2016-12-12 11:33:56 -080080 List<MediaAnalyticsItem *> *mFinalized;
Ray Essick3938dc62016-11-01 08:56:56 -070081 // searching within these queues: queue, key
Ray Essickb5fac8e2016-12-12 11:33:56 -080082 MediaAnalyticsItem *findItem(List<MediaAnalyticsItem *> *,
83 MediaAnalyticsItem *, bool removeit);
Ray Essick3938dc62016-11-01 08:56:56 -070084
Ray Essickb5fac8e2016-12-12 11:33:56 -080085 void saveItem(MediaAnalyticsItem);
86 void saveItem(List<MediaAnalyticsItem *> *, MediaAnalyticsItem *, int);
87 void deleteItem(List<MediaAnalyticsItem *> *, MediaAnalyticsItem *);
Ray Essick3938dc62016-11-01 08:56:56 -070088
Ray Essickb5fac8e2016-12-12 11:33:56 -080089 String8 dumpQueue(List<MediaAnalyticsItem*> *);
90 String8 dumpQueue(List<MediaAnalyticsItem*> *, nsecs_t);
Ray Essick3938dc62016-11-01 08:56:56 -070091
92};
93
94// ----------------------------------------------------------------------------
95
96}; // namespace android
97
98#endif // ANDROID_MEDIAANALYTICSSERVICE_H