blob: 467c2bda8f9f30aa248ab33e2bfd599b4226a70c [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;
Bookatzb487b552017-09-18 11:26:01 -070037using namespace android::os::statsd;
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070038using namespace std;
Bookatzb487b552017-09-18 11:26:01 -070039
David Chen0656b7a2017-09-13 15:53:39 -070040using android::os::statsd::StatsdConfig;
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070041
42// ================================================================================
43class 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
Bookatzb487b552017-09-18 11:26:01 -070065 // TODO: public for testing since statsd doesn't run when system starts. Change to private later.
66 /** Inform statsCompanion that statsd is ready. */
67 virtual void sayHiToStatsCompanion();
68
Yao Chen482d2722017-09-12 13:25:43 -070069private:
David Chen0656b7a2017-09-13 15:53:39 -070070 sp<StatsLogProcessor> m_processor; // Reference to the processor for updating configs.
Bookatzb487b552017-09-18 11:26:01 -070071
Yao Chen482d2722017-09-12 13:25:43 -070072 status_t doPrintStatsLog(FILE* out, const Vector<String8>& args);
Bookatzb487b552017-09-18 11:26:01 -070073
Yao Chen482d2722017-09-12 13:25:43 -070074 void printCmdHelp(FILE* out);
Bookatzb487b552017-09-18 11:26:01 -070075
David Chen0656b7a2017-09-13 15:53:39 -070076 status_t doLoadConfig(FILE* in);
Bookatzb487b552017-09-18 11:26:01 -070077
78 const sp<AnomalyMonitor> mAnomalyMonitor; // TODO: Move this to a more logical file/class
79
80 private:
81 /** Fetches the StatsCompanionService. */
82 sp<IStatsCompanionService> getStatsCompanionService();
83};
84
85// --- StatsdDeathRecipient ---
86class StatsdDeathRecipient : public IBinder::DeathRecipient {
87public:
88 StatsdDeathRecipient(sp<AnomalyMonitor> anomalyMonitor)
89 : mAnmlyMntr(anomalyMonitor) {
90 }
91
92 virtual void binderDied(const wp<IBinder>& who);
93
94private:
95 const sp<AnomalyMonitor> mAnmlyMntr;
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070096};
97
98#endif // STATS_SERVICE_H