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