Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 20 | #include "AnomalyMonitor.h" |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 21 | #include "StatsLogProcessor.h" |
Chenjie Yu | 1a317ba | 2017-10-05 16:05:32 -0700 | [diff] [blame^] | 22 | #include "StatsPullerManager.h" |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 23 | |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 24 | #include <android/os/BnStatsManager.h> |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 25 | #include <android/os/IStatsCompanionService.h> |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 26 | #include <binder/IResultReceiver.h> |
| 27 | #include <binder/IShellCallback.h> |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 28 | #include <utils/Looper.h> |
| 29 | |
| 30 | #include <deque> |
| 31 | #include <mutex> |
| 32 | |
| 33 | using namespace android; |
| 34 | using namespace android::base; |
| 35 | using namespace android::binder; |
| 36 | using namespace android::os; |
| 37 | using namespace std; |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 38 | |
Bookatz | 906a35c | 2017-09-20 15:26:44 -0700 | [diff] [blame] | 39 | namespace android { |
| 40 | namespace os { |
| 41 | namespace statsd { |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 42 | |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 43 | class StatsService : public BnStatsManager { |
| 44 | public: |
| 45 | StatsService(const sp<Looper>& handlerLooper); |
| 46 | virtual ~StatsService(); |
| 47 | |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 48 | virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags); |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 49 | |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 50 | 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 Chen | 482d272 | 2017-09-12 13:25:43 -0700 | [diff] [blame] | 55 | |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 56 | // Inform statsd that statsCompanion is ready. |
| 57 | virtual Status statsCompanionReady(); |
| 58 | |
Bookatz | 1b0b114 | 2017-09-08 11:58:42 -0700 | [diff] [blame] | 59 | virtual Status informAnomalyAlarmFired(); |
| 60 | |
| 61 | virtual Status informPollAlarmFired(); |
| 62 | |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 63 | virtual status_t setProcessor(const sp<StatsLogProcessor>& main_processor); |
| 64 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 65 | // TODO: public for testing since statsd doesn't run when system starts. Change to private |
| 66 | // later. |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 67 | /** Inform statsCompanion that statsd is ready. */ |
| 68 | virtual void sayHiToStatsCompanion(); |
| 69 | |
Bookatz | c68a9d2 | 2017-09-27 14:09:55 -0700 | [diff] [blame] | 70 | // 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; |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 73 | |
Bookatz | c68a9d2 | 2017-09-27 14:09:55 -0700 | [diff] [blame] | 74 | /** Fetches and returns the StatsCompanionService. */ |
| 75 | static sp<IStatsCompanionService> getStatsCompanionService(); |
| 76 | |
Chenjie Yu | 1a317ba | 2017-10-05 16:05:32 -0700 | [diff] [blame^] | 77 | private: |
Bookatz | c68a9d2 | 2017-09-27 14:09:55 -0700 | [diff] [blame] | 78 | sp<StatsLogProcessor> m_processor; // Reference to the processor for updating configs. |
Bookatz | 906a35c | 2017-09-20 15:26:44 -0700 | [diff] [blame] | 79 | |
Yao Chen | 482d272 | 2017-09-12 13:25:43 -0700 | [diff] [blame] | 80 | status_t doPrintStatsLog(FILE* out, const Vector<String8>& args); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 81 | |
Yao Chen | 482d272 | 2017-09-12 13:25:43 -0700 | [diff] [blame] | 82 | void printCmdHelp(FILE* out); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 83 | |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 84 | status_t doLoadConfig(FILE* in); |
Chenjie Yu | 1a317ba | 2017-10-05 16:05:32 -0700 | [diff] [blame^] | 85 | |
| 86 | StatsPullerManager mStatsPullerManager; |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | // --- StatsdDeathRecipient --- |
| 90 | class StatsdDeathRecipient : public IBinder::DeathRecipient { |
| 91 | public: |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 92 | StatsdDeathRecipient(sp<AnomalyMonitor> anomalyMonitor) : mAnmlyMntr(anomalyMonitor) { |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | virtual void binderDied(const wp<IBinder>& who); |
| 96 | |
| 97 | private: |
| 98 | const sp<AnomalyMonitor> mAnmlyMntr; |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 101 | } // namespace statsd |
| 102 | } // namespace os |
| 103 | } // namespace android |
Bookatz | 906a35c | 2017-09-20 15:26:44 -0700 | [diff] [blame] | 104 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 105 | #endif // STATS_SERVICE_H |