forked from kmiit/FakeOmapi
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cpp
More file actions
37 lines (29 loc) · 1.25 KB
/
main.cpp
File metadata and controls
37 lines (29 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "Service.h"
#include <android-base/logging.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>
#include <csignal>
#include <cstdlib>
using aidl::android::se::omapi::SecureElementService;
namespace {
// Async-signal-safe termination without logging/allocation.
void handleTerminationSignal(int sig) {
(void)sig;
std::_Exit(0);
}
} // namespace
int main() {
std::signal(SIGTERM, handleTerminationSignal);
std::signal(SIGINT, handleTerminationSignal);
// One extra worker thread lets death-recipient / onStateChange callbacks
// be dispatched while the main thread is busy with a client transaction.
ABinderProcess_setThreadPoolMaxThreadCount(1);
ABinderProcess_startThreadPool();
std::shared_ptr<SecureElementService> hal = ndk::SharedRefBase::make<SecureElementService>();
const std::string instance = std::string(SecureElementService::descriptor) + "/default";
auto status = AServiceManager_addService(hal->asBinder().get(), instance.c_str());
CHECK_EQ(status, STATUS_OK) << "Failed to add service " << instance << " " << status;
LOG(INFO) << "SecureElementService AIDL service(omapi) running...";
ABinderProcess_joinThreadPool();
return EXIT_FAILURE; // should not reach
}