1 /*
2 * Copyright (C) 2018 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 "binder/iiorap_impl.h"
18 #include "common/debug.h"
19 #include "common/loggers.h"
20 #include "db/models.h"
21 #include "manager/event_manager.h"
22
23 #include <android-base/logging.h>
24 #include <android-base/properties.h>
25 #include <binder/IPCThreadState.h>
26 #include <utils/Trace.h>
27
28 #include <stdio.h>
29
30 static constexpr const char* kServiceName = iorap::binder::IIorapImpl::getServiceName();
31
main(int,char ** argv)32 int main(int /*argc*/, char** argv) {
33 if (android::base::GetBoolProperty("iorapd.log.verbose", iorap::kIsDebugBuild)) {
34 // Show verbose logs if the property is enabled or if we are a debug build.
35 setenv("ANDROID_LOG_TAGS", "*:v", /*overwrite*/ 1);
36 }
37
38 // Logs go to system logcat.
39 android::base::InitLogging(argv, iorap::common::StderrAndLogdLogger{android::base::SYSTEM});
40
41 LOG(INFO) << kServiceName << " (the prefetchening) firing up";
42 {
43 android::ScopedTrace trace_db_init{ATRACE_TAG_ACTIVITY_MANAGER, "IorapNativeService::db_init"};
44 iorap::db::SchemaModel db_schema =
45 iorap::db::SchemaModel::GetOrCreate(
46 android::base::GetProperty("iorapd.db.location",
47 "/data/misc/iorapd/sqlite.db"));
48 db_schema.MarkSingleton();
49 }
50
51 std::shared_ptr<iorap::manager::EventManager> event_manager;
52 {
53 android::ScopedTrace trace_start{ATRACE_TAG_ACTIVITY_MANAGER, "IorapNativeService::start"};
54
55 // TODO: use fruit for this DI.
56 event_manager =
57 iorap::manager::EventManager::Create();
58 if (!iorap::binder::IIorapImpl::Start(event_manager)) {
59 LOG(ERROR) << "Unable to start IorapNativeService";
60 exit(1);
61 }
62 }
63
64 // This must be logged after all other initialization has finished.
65 LOG(INFO) << kServiceName << " (the prefetchening) readied up";
66
67 event_manager->Join(); // TODO: shutdown somewhere?
68 // Block until something else shuts down the binder service.
69 android::IPCThreadState::self()->joinThreadPool();
70 LOG(INFO) << kServiceName << " shutting down";
71
72 return 0;
73 }
74