blob: b02579d35eef968d771c9debae6b1416db1d9260 [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>
David Chen0656b7a2017-09-13 15:53:39 -070028#include <frameworks/base/cmds/statsd/src/statsd_config.pb.h>
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070029#include <utils/Looper.h>
30
31#include <deque>
32#include <mutex>
33
34using namespace android;
35using namespace android::base;
36using namespace android::binder;
37using namespace android::os;
38using namespace std;
Bookatzb487b552017-09-18 11:26:01 -070039
Bookatz906a35c2017-09-20 15:26:44 -070040namespace android {
41namespace os {
42namespace statsd {
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070043
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070044class StatsService : public BnStatsManager {
45public:
46 StatsService(const sp<Looper>& handlerLooper);
47 virtual ~StatsService();
48
Joe Onorato2cbc2cc2017-08-30 17:03:23 -070049 virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags);
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070050
Joe Onorato2cbc2cc2017-08-30 17:03:23 -070051 virtual status_t dump(int fd, const Vector<String16>& args);
52
53 virtual status_t command(FILE* in, FILE* out, FILE* err, Vector<String8>& args);
54
55 virtual Status systemRunning();
Yao Chen482d2722017-09-12 13:25:43 -070056
Bookatzb487b552017-09-18 11:26:01 -070057 // Inform statsd that statsCompanion is ready.
58 virtual Status statsCompanionReady();
59
Bookatz1b0b1142017-09-08 11:58:42 -070060 virtual Status informAnomalyAlarmFired();
61
62 virtual Status informPollAlarmFired();
63
David Chen0656b7a2017-09-13 15:53:39 -070064 virtual status_t setProcessor(const sp<StatsLogProcessor>& main_processor);
65
Yao Chenef99c4f2017-09-22 16:26:54 -070066 // TODO: public for testing since statsd doesn't run when system starts. Change to private
67 // later.
Bookatzb487b552017-09-18 11:26:01 -070068 /** Inform statsCompanion that statsd is ready. */
69 virtual void sayHiToStatsCompanion();
70
Bookatzc68a9d22017-09-27 14:09:55 -070071 // TODO: Move this to a more logical file/class
72 // TODO: Should be private. Temporarily public for testing purposes only.
73 const sp<AnomalyMonitor> mAnomalyMonitor;
Bookatzb487b552017-09-18 11:26:01 -070074
Bookatzc68a9d22017-09-27 14:09:55 -070075 /** Fetches and returns the StatsCompanionService. */
76 static sp<IStatsCompanionService> getStatsCompanionService();
77
78 private:
79 sp<StatsLogProcessor> m_processor; // Reference to the processor for updating configs.
Bookatz906a35c2017-09-20 15:26:44 -070080
Yao Chen482d2722017-09-12 13:25:43 -070081 status_t doPrintStatsLog(FILE* out, const Vector<String8>& args);
Bookatzb487b552017-09-18 11:26:01 -070082
Yao Chen482d2722017-09-12 13:25:43 -070083 void printCmdHelp(FILE* out);
Bookatzb487b552017-09-18 11:26:01 -070084
David Chen0656b7a2017-09-13 15:53:39 -070085 status_t doLoadConfig(FILE* in);
Bookatzb487b552017-09-18 11:26:01 -070086};
87
88// --- StatsdDeathRecipient ---
89class StatsdDeathRecipient : public IBinder::DeathRecipient {
90public:
Yao Chenef99c4f2017-09-22 16:26:54 -070091 StatsdDeathRecipient(sp<AnomalyMonitor> anomalyMonitor) : mAnmlyMntr(anomalyMonitor) {
Bookatzb487b552017-09-18 11:26:01 -070092 }
93
94 virtual void binderDied(const wp<IBinder>& who);
95
96private:
97 const sp<AnomalyMonitor> mAnmlyMntr;
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070098};
99
Yao Chenef99c4f2017-09-22 16:26:54 -0700100} // namespace statsd
101} // namespace os
102} // namespace android
Bookatz906a35c2017-09-20 15:26:44 -0700103
Yao Chenef99c4f2017-09-22 16:26:54 -0700104#endif // STATS_SERVICE_H