Pawan Wagh | c5c0c30 | 2023-04-21 22:04:31 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2023 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/IPCThreadState.h> |
| 18 | #include <binder/IServiceManager.h> |
| 19 | |
| 20 | #include <log/log.h> |
| 21 | |
| 22 | #include "gatekeeperd.h" |
| 23 | |
| 24 | int main(int argc, char* argv[]) { |
| 25 | ALOGI("Starting gatekeeperd..."); |
| 26 | if (argc < 2) { |
| 27 | ALOGE("A directory must be specified!"); |
| 28 | return 1; |
| 29 | } |
| 30 | if (chdir(argv[1]) == -1) { |
| 31 | ALOGE("chdir: %s: %s", argv[1], strerror(errno)); |
| 32 | return 1; |
| 33 | } |
| 34 | |
| 35 | android::sp<android::IServiceManager> sm = android::defaultServiceManager(); |
| 36 | android::sp<android::GateKeeperProxy> proxy = new android::GateKeeperProxy(); |
| 37 | android::status_t ret = sm->addService( |
| 38 | android::String16("android.service.gatekeeper.IGateKeeperService"), proxy); |
| 39 | if (ret != android::OK) { |
| 40 | ALOGE("Couldn't register binder service!"); |
| 41 | return -1; |
| 42 | } |
| 43 | |
| 44 | /* |
| 45 | * We're the only thread in existence, so we're just going to process |
| 46 | * Binder transaction as a single-threaded program. |
| 47 | */ |
| 48 | android::IPCThreadState::self()->joinThreadPool(); |
| 49 | return 0; |
| 50 | } |