1 /*
2 * Copyright (C) 2019 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 #ifdef LAZY_SERVICE
18 #define LOG_TAG "android.hardware.pixel.camera.provider@2.7-service-lazy"
19 #else
20 #define LOG_TAG "android.hardware.pixel.camera.provider@2.7-service"
21 #endif
22
23 #include <android/hardware/camera/provider/2.7/ICameraProvider.h>
24 #include <apex_update_listener.h>
25 #include <binder/ProcessState.h>
26 #include <cutils/properties.h>
27 #include <hidl/HidlLazyUtils.h>
28 #include <hidl/HidlTransportSupport.h>
29 #include <malloc.h>
30 #include <utils/Errors.h>
31
32 #include "hidl_camera_build_version.h"
33 #include "hidl_camera_provider.h"
34
35 using ::android::hardware::camera::provider::V2_7::ICameraProvider;
36 using ::android::hardware::camera::provider::V2_7::implementation::HidlCameraProvider;
37
38 #ifdef LAZY_SERVICE
39 const bool kLazyService = true;
40 #else
41 const bool kLazyService = false;
42 #endif
43
main()44 int main() {
45 ALOGI("Google camera provider service is starting.");
46 // The camera HAL may communicate to other vendor components via
47 // /dev/vndbinder
48 mallopt(M_DECAY_TIME, 1);
49 android::ProcessState::initWithDriver("/dev/vndbinder");
50 android::hardware::configureRpcThreadpool(/*maxThreads=*/6,
51 /*callerWillJoin=*/true);
52
53 #ifdef __ANDROID_APEX__
54 int start_count = property_get_int32("vendor.camera.hal.start.count", 0);
55 property_set("vendor.camera.hal.start.count",
56 std::to_string(++start_count).c_str());
57 property_set("vendor.camera.hal.version",
58 std::to_string(kHalManifestBuildNumber).c_str());
59 property_set("vendor.camera.hal.build_id", kAndroidBuildId);
60 auto start_on_update =
61 ApexUpdateListener::Make("com.google.pixel.camera.hal", [](auto, auto) {
62 ALOGI("APEX version updated. starting.");
63 exit(0);
64 });
65 ALOGI(
66 "Using ApexUpdateListener: %p Start Count: %d Current Version: %s "
67 "(%ld)",
68 start_on_update.get(), start_count, kAndroidBuildId,
69 kHalManifestBuildNumber);
70 #else
71 ALOGI("Not using ApexUpdateListener since not running in an apex.");
72 #endif
73
74 android::sp<ICameraProvider> camera_provider = HidlCameraProvider::Create();
75 if (camera_provider == nullptr) {
76 return android::NO_INIT;
77 }
78 if (kLazyService) {
79 android::hardware::LazyServiceRegistrar& lazy_registrar =
80 android::hardware::LazyServiceRegistrar::getInstance();
81 if (lazy_registrar.registerService(camera_provider, "internal/0") !=
82 android::OK) {
83 ALOGE("Cannot register Google camera provider lazy service");
84 return android::NO_INIT;
85 }
86 } else {
87 if (camera_provider->registerAsService("internal/0") != android::OK) {
88 ALOGE("Cannot register Google camera provider service");
89 return android::NO_INIT;
90 }
91 }
92 android::hardware::joinRpcThreadpool();
93
94 // In normal operation, the threadpool should never return.
95 return EXIT_FAILURE;
96 }
97