• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 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 const bool kLazyService = true;
19 #define LOG_TAG "android.hardware.cas-service.example-lazy"
20 #else
21 const bool kLazyService = false;
22 #define LOG_TAG "android.hardware.cas-service.example"
23 #endif
24 
25 #include <android/binder_manager.h>
26 #include <android/binder_process.h>
27 
28 #include "MediaCasService.h"
29 
30 using aidl::android::hardware::cas::MediaCasService;
31 
main()32 int main() {
33     ABinderProcess_setThreadPoolMaxThreadCount(8);
34 
35     // Setup hwbinder service
36     std::shared_ptr<MediaCasService> service = ::ndk::SharedRefBase::make<MediaCasService>();
37 
38     const std::string instance = std::string() + MediaCasService::descriptor + "/default";
39     binder_status_t status;
40 
41     if (kLazyService) {
42         status = AServiceManager_registerLazyService(service->asBinder().get(), instance.c_str());
43     } else {
44         status = AServiceManager_addService(service->asBinder().get(), instance.c_str());
45     }
46     LOG_ALWAYS_FATAL_IF(status != STATUS_OK, "Error while registering cas service: %d", status);
47 
48     ABinderProcess_joinThreadPool();
49     return 0;
50 }
51