Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [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 | */ |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 16 | #include "Log.h" |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 17 | |
| 18 | #include "IncidentService.h" |
| 19 | |
| 20 | #include <binder/IInterface.h> |
| 21 | #include <binder/IPCThreadState.h> |
| 22 | #include <binder/IServiceManager.h> |
| 23 | #include <binder/ProcessState.h> |
| 24 | #include <binder/Status.h> |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 25 | #include <utils/Looper.h> |
| 26 | #include <utils/StrongPointer.h> |
| 27 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 28 | #include <sys/stat.h> |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 29 | #include <sys/types.h> |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 30 | |
| 31 | using namespace android; |
Yi Jin | 6cacbcb | 2018-03-30 14:04:52 -0700 | [diff] [blame] | 32 | using namespace android::os::incidentd; |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 33 | |
| 34 | // ================================================================================ |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 35 | int main(int /*argc*/, char** /*argv*/) { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 36 | // Set up the looper |
| 37 | sp<Looper> looper(Looper::prepare(0 /* opts */)); |
| 38 | |
| 39 | // Set up the binder |
| 40 | sp<ProcessState> ps(ProcessState::self()); |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 41 | ps->setThreadPoolMaxThreadCount(1); // everything is oneway, let it queue and save ram |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 42 | ps->startThreadPool(); |
| 43 | ps->giveThreadPoolName(); |
| 44 | IPCThreadState::self()->disableBackgroundScheduling(true); |
| 45 | |
| 46 | // Create the service |
Yi Jin | 6cacbcb | 2018-03-30 14:04:52 -0700 | [diff] [blame] | 47 | sp<IncidentService> service = new IncidentService(looper); |
Mike Ma | 85434ec | 2018-11-27 10:32:31 -0800 | [diff] [blame] | 48 | if (defaultServiceManager()->addService(String16("incident"), service, false, |
| 49 | IServiceManager::DUMP_FLAG_PRIORITY_NORMAL | IServiceManager::DUMP_FLAG_PROTO) != 0) { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 50 | ALOGE("Failed to add service"); |
| 51 | return -1; |
| 52 | } |
| 53 | |
| 54 | // Loop forever -- the reports run on this thread in a handler, and the |
| 55 | // binder calls remain responsive in their pool of one thread. |
| 56 | while (true) { |
| 57 | looper->pollAll(-1 /* timeoutMillis */); |
| 58 | } |
| 59 | ALOGW("incidentd escaped from its loop."); |
| 60 | |
| 61 | return 1; |
| 62 | } |