Chenjie Yu | 1a317ba | 2017-10-05 16:05:32 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | #include "KernelWakelockPuller.h" |
| 18 | #include <android/os/IStatsCompanionService.h> |
| 19 | #include <binder/IPCThreadState.h> |
| 20 | #include <cutils/log.h> |
| 21 | #include <private/android_filesystem_config.h> |
| 22 | #include "StatsPuller.h" |
| 23 | #include "StatsService.h" |
| 24 | |
| 25 | using namespace android; |
| 26 | using namespace android::base; |
| 27 | using namespace android::binder; |
| 28 | using namespace android::os; |
| 29 | using namespace std; |
| 30 | |
| 31 | namespace android { |
| 32 | namespace os { |
| 33 | namespace statsd { |
| 34 | |
| 35 | const int KernelWakelockPuller::PULL_CODE_KERNEL_WAKELOCKS = 20; |
| 36 | |
| 37 | // The reading and parsing are implemented in Java. It is not difficult to port over. But for now |
| 38 | // let StatsCompanionService handle that and send the data back. |
| 39 | String16 KernelWakelockPuller::pull() { |
| 40 | sp<IStatsCompanionService> statsCompanion = StatsService::getStatsCompanionService(); |
| 41 | String16 returned_value(""); |
| 42 | if (statsCompanion != NULL) { |
| 43 | Status status = statsCompanion->pullData(KernelWakelockPuller::PULL_CODE_KERNEL_WAKELOCKS, |
| 44 | &returned_value); |
| 45 | if (!status.isOk()) { |
| 46 | ALOGW("error pulling kernel wakelock"); |
| 47 | } |
| 48 | ALOGD("KernelWakelockPuller::pull succeeded!"); |
| 49 | // TODO: remove this when we integrate into aggregation chain. |
| 50 | ALOGD("%s", String8(returned_value).string()); |
| 51 | return returned_value; |
| 52 | } else { |
| 53 | ALOGW("statsCompanion not found!"); |
| 54 | return String16(); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | } // namespace statsd |
| 59 | } // namespace os |
| 60 | } // namespace android |