blob: a16b115baf8e2edadcfedbee622a1c9110f58533 [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"
Bookatzc68a9d22017-09-27 14:09:55 -070022#include "StatsPuller.h"
David Chen0656b7a2017-09-13 15:53:39 -070023
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070024#include <android/os/BnStatsManager.h>
Bookatzb487b552017-09-18 11:26:01 -070025#include <android/os/IStatsCompanionService.h>
Joe Onorato2cbc2cc2017-08-30 17:03:23 -070026#include <binder/IResultReceiver.h>
27#include <binder/IShellCallback.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
Bookatzc68a9d22017-09-27 14:09:55 -070070 // TODO: Move this to a more logical file/class
71 // TODO: Should be private. Temporarily public for testing purposes only.
72 const sp<AnomalyMonitor> mAnomalyMonitor;
Bookatzb487b552017-09-18 11:26:01 -070073
Bookatzc68a9d22017-09-27 14:09:55 -070074 /** Fetches and returns the StatsCompanionService. */
75 static sp<IStatsCompanionService> getStatsCompanionService();
76
77 private:
78 sp<StatsLogProcessor> m_processor; // Reference to the processor for updating configs.
Bookatz906a35c2017-09-20 15:26:44 -070079
Yao Chen482d2722017-09-12 13:25:43 -070080 status_t doPrintStatsLog(FILE* out, const Vector<String8>& args);
Bookatzb487b552017-09-18 11:26:01 -070081
Yao Chen482d2722017-09-12 13:25:43 -070082 void printCmdHelp(FILE* out);
Bookatzb487b552017-09-18 11:26:01 -070083
David Chen0656b7a2017-09-13 15:53:39 -070084 status_t doLoadConfig(FILE* in);
Bookatzb487b552017-09-18 11:26:01 -070085};
86
87// --- StatsdDeathRecipient ---
88class StatsdDeathRecipient : public IBinder::DeathRecipient {
89public:
Yao Chenef99c4f2017-09-22 16:26:54 -070090 StatsdDeathRecipient(sp<AnomalyMonitor> anomalyMonitor) : mAnmlyMntr(anomalyMonitor) {
Bookatzb487b552017-09-18 11:26:01 -070091 }
92
93 virtual void binderDied(const wp<IBinder>& who);
94
95private:
96 const sp<AnomalyMonitor> mAnmlyMntr;
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070097};
98
Yao Chenef99c4f2017-09-22 16:26:54 -070099} // namespace statsd
100} // namespace os
101} // namespace android
Bookatz906a35c2017-09-20 15:26:44 -0700102
Yao Chenef99c4f2017-09-22 16:26:54 -0700103#endif // STATS_SERVICE_H