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 <android/binder_manager.h>
18 #include <android/binder_process.h>
19 #include <log/log.h>
20 
21 #include "CameraProvider.h"
22 #include "service_entry.h"
23 #include "utils.h"
24 
25 namespace android {
26 namespace hardware {
27 namespace camera {
28 namespace provider {
29 namespace implementation {
30 
serviceEntry(const int deviceIdBase,const Span<const hw::HwCameraFactory> availableCameras,const unsigned binderMaxThreads)31 int serviceEntry(const int deviceIdBase,
32                  const Span<const hw::HwCameraFactory> availableCameras,
33                  const unsigned binderMaxThreads) {
34     ABinderProcess_setThreadPoolMaxThreadCount(binderMaxThreads);
35     ABinderProcess_startThreadPool();
36 
37     std::shared_ptr<CameraProvider> hal = ndk::SharedRefBase::make<CameraProvider>(
38         deviceIdBase, availableCameras);
39 
40     const std::string instance = std::string(CameraProvider::descriptor) + "/internal/1";
41 
42     if (AServiceManager_addService(hal->asBinder().get(),
43                                    instance.c_str()) == STATUS_OK) {
44         ABinderProcess_joinThreadPool();
45         return EXIT_FAILURE;
46     } else {
47         ALOGE("Failed to register '%s'", instance.c_str());
48         return android::NO_INIT;
49     }
50 }
51 
52 }  // namespace implementation
53 }  // namespace provider
54 }  // namespace camera
55 }  // namespace hardware
56 }  // namespace android
57