blob: a956cbf83fd4f704b735f3dd49456db574a05c6e [file] [log] [blame]
Joe Onorato5dcbc6c2017-08-29 15:13:58 -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#ifndef STATS_SERVICE_H
18#define STATS_SERVICE_H
19
Bookatzb487b552017-09-18 11:26:01 -070020#include "AnomalyMonitor.h"
David Chen0656b7a2017-09-13 15:53:39 -070021#include "StatsLogProcessor.h"
22
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070023#include <android/os/BnStatsManager.h>
Bookatzb487b552017-09-18 11:26:01 -070024#include <android/os/IStatsCompanionService.h>
Joe Onorato2cbc2cc2017-08-30 17:03:23 -070025#include <binder/IResultReceiver.h>
26#include <binder/IShellCallback.h>
David Chen0656b7a2017-09-13 15:53:39 -070027#include <frameworks/base/cmds/statsd/src/statsd_config.pb.h>
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070028#include <utils/Looper.h>
29
30#include <deque>
31#include <mutex>
32
33using namespace android;
34using namespace android::base;
35using namespace android::binder;
36using namespace android::os;
37using namespace std;
Bookatzb487b552017-09-18 11:26:01 -070038
Bookatz906a35c2017-09-20 15:26:44 -070039namespace android {
40namespace os {
41namespace statsd {
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070042
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070043class StatsService : public BnStatsManager {
44public:
45 StatsService(const sp<Looper>& handlerLooper);
46 virtual ~StatsService();
47
Joe Onorato2cbc2cc2017-08-30 17:03:23 -070048 virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags);
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070049
Joe Onorato2cbc2cc2017-08-30 17:03:23 -070050 virtual status_t dump(int fd, const Vector<String16>& args);
51
52 virtual status_t command(FILE* in, FILE* out, FILE* err, Vector<String8>& args);
53
54 virtual Status systemRunning();
Yao Chen482d2722017-09-12 13:25:43 -070055
Bookatzb487b552017-09-18 11:26:01 -070056 // Inform statsd that statsCompanion is ready.
57 virtual Status statsCompanionReady();
58
Bookatz1b0b1142017-09-08 11:58:42 -070059 virtual Status informAnomalyAlarmFired();
60
61 virtual Status informPollAlarmFired();
62
David Chen0656b7a2017-09-13 15:53:39 -070063 virtual status_t setProcessor(const sp<StatsLogProcessor>& main_processor);
64
Yao Chenef99c4f2017-09-22 16:26:54 -070065 // TODO: public for testing since statsd doesn't run when system starts. Change to private
66 // later.
Bookatzb487b552017-09-18 11:26:01 -070067 /** Inform statsCompanion that statsd is ready. */
68 virtual void sayHiToStatsCompanion();
69
Yao Chen482d2722017-09-12 13:25:43 -070070private:
Yao Chenef99c4f2017-09-22 16:26:54 -070071 sp<StatsLogProcessor> m_processor; // Reference to the processor for updating configs.
Bookatzb487b552017-09-18 11:26:01 -070072
Bookatz906a35c2017-09-20 15:26:44 -070073 const sp<AnomalyMonitor> mAnomalyMonitor; // TODO: Move this to a more logical file/class
74
Yao Chen482d2722017-09-12 13:25:43 -070075 status_t doPrintStatsLog(FILE* out, const Vector<String8>& args);
Bookatzb487b552017-09-18 11:26:01 -070076
Yao Chen482d2722017-09-12 13:25:43 -070077 void printCmdHelp(FILE* out);
Bookatzb487b552017-09-18 11:26:01 -070078
David Chen0656b7a2017-09-13 15:53:39 -070079 status_t doLoadConfig(FILE* in);
Bookatzb487b552017-09-18 11:26:01 -070080
Bookatzb487b552017-09-18 11:26:01 -070081 /** Fetches the StatsCompanionService. */
82 sp<IStatsCompanionService> getStatsCompanionService();
83};
84
85// --- StatsdDeathRecipient ---
86class StatsdDeathRecipient : public IBinder::DeathRecipient {
87public:
Yao Chenef99c4f2017-09-22 16:26:54 -070088 StatsdDeathRecipient(sp<AnomalyMonitor> anomalyMonitor) : mAnmlyMntr(anomalyMonitor) {
Bookatzb487b552017-09-18 11:26:01 -070089 }
90
91 virtual void binderDied(const wp<IBinder>& who);
92
93private:
94 const sp<AnomalyMonitor> mAnmlyMntr;
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070095};
96
Yao Chenef99c4f2017-09-22 16:26:54 -070097} // namespace statsd
98} // namespace os
99} // namespace android
Bookatz906a35c2017-09-20 15:26:44 -0700100
Yao Chenef99c4f2017-09-22 16:26:54 -0700101#endif // STATS_SERVICE_H