• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define LOG_TAG "incidentd"
18 
19 #include "IncidentService.h"
20 
21 #include <binder/IInterface.h>
22 #include <binder/IPCThreadState.h>
23 #include <binder/IServiceManager.h>
24 #include <binder/ProcessState.h>
25 #include <binder/Status.h>
26 #include <cutils/log.h>
27 #include <utils/Looper.h>
28 #include <utils/StrongPointer.h>
29 
30 #include <sys/types.h>
31 #include <sys/stat.h>
32 
33 using namespace android;
34 
35 // ================================================================================
36 int
main(int,char **)37 main(int /*argc*/, char** /*argv*/)
38 {
39     // Set up the looper
40     sp<Looper> looper(Looper::prepare(0 /* opts */));
41 
42     // Set up the binder
43     sp<ProcessState> ps(ProcessState::self());
44     ps->setThreadPoolMaxThreadCount(1); // everything is oneway, let it queue and save ram
45     ps->startThreadPool();
46     ps->giveThreadPoolName();
47     IPCThreadState::self()->disableBackgroundScheduling(true);
48 
49     // Create the service
50     android::sp<IncidentService> service = new IncidentService(looper);
51     if (defaultServiceManager()->addService(String16("incident"), service) != 0) {
52         ALOGE("Failed to add service");
53         return -1;
54     }
55 
56     // Loop forever -- the reports run on this thread in a handler, and the
57     // binder calls remain responsive in their pool of one thread.
58     while (true) {
59         looper->pollAll(-1 /* timeoutMillis */);
60     }
61     ALOGW("incidentd escaped from its loop.");
62 
63     return 1;
64 }
65