1 /*
2  * Copyright (C) 2020 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 "pixel-display.h"
18 
19 #include <utils/Errors.h>
20 #include <sys/types.h>
21 #include <hwc_session.h>
22 
23 #include <android-base/logging.h>
24 #include <android/binder_manager.h>
25 #include <android/binder_process.h>
26 
27 using ::aidl::com::google::hardware::pixel::display::Display;
28 
DisplayInit(sdm::HWCSession * hwc_session)29 void DisplayInit(sdm::HWCSession *hwc_session) {
30     ABinderProcess_setThreadPoolMaxThreadCount(0);
31 
32     std::shared_ptr<::aidl::com::google::hardware::pixel::display::Display> display =
33         ndk::SharedRefBase::make<Display>(hwc_session);
34     LOG(INFO) << "pixel display service start...";
35     const std::string instance = std::string() + Display::descriptor + "/default";
36     binder_status_t status =
37         AServiceManager_addService(display->asBinder().get(), instance.c_str());
38     CHECK(status == STATUS_OK);
39 
40     ABinderProcess_startThreadPool();
41 }
42 
43 namespace aidl {
44 namespace com {
45 namespace google {
46 namespace hardware {
47 namespace pixel {
48 namespace display {
49 
50 // ----------------------------------------------------------------------------
Display(HWCSession * hwc_session)51 Display::Display(HWCSession *hwc_session):mHWCSession(hwc_session) {
52 }
53 
isHbmSupported(bool * _aidl_return)54 ndk::ScopedAStatus Display::isHbmSupported(bool *_aidl_return) {
55     if (mHWCSession) {
56         *_aidl_return = mHWCSession->IsHbmSupported();
57 
58         return ndk::ScopedAStatus::ok();
59     }
60 
61     return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
62 }
63 
setHbmState(HbmState state)64 ndk::ScopedAStatus Display::setHbmState(HbmState state) {
65     if (mHWCSession) {
66         mHWCSession->SetHbmState(state);
67 
68         return ndk::ScopedAStatus::ok();
69     }
70 
71     return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
72 }
73 
getHbmState(HbmState * _aidl_return)74 ndk::ScopedAStatus Display::getHbmState(HbmState *_aidl_return) {
75     if (mHWCSession) {
76         *_aidl_return = mHWCSession->GetHbmState();
77 
78         return ndk::ScopedAStatus::ok();
79     }
80 
81     return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
82 }
83 
isLbeSupported(bool * _aidl_return)84 ndk::ScopedAStatus Display::isLbeSupported(bool *_aidl_return) {
85     if (mHWCSession) {
86         *_aidl_return = mHWCSession->IsLbeSupported();
87 
88         return ndk::ScopedAStatus::ok();
89     }
90 
91     return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
92 }
93 
setLbeState(LbeState state)94 ndk::ScopedAStatus Display::setLbeState(LbeState  state) {
95     if (mHWCSession) {
96         mHWCSession->SetLbeState(state);
97 
98         return ndk::ScopedAStatus::ok();
99     }
100 
101     return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
102 }
103 
setLbeAmbientLight(int ambientLux)104 ndk::ScopedAStatus Display::setLbeAmbientLight(int ambientLux) {
105     if (mHWCSession) {
106         mHWCSession->SetLbeAmbientLight(ambientLux);
107 
108         return ndk::ScopedAStatus::ok();
109     }
110 
111     return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
112 }
113 
getLbeState(LbeState * _aidl_return)114 ndk::ScopedAStatus Display::getLbeState(LbeState* _aidl_return) {
115     if (mHWCSession) {
116         *_aidl_return = mHWCSession->GetLbeState();
117 
118         return ndk::ScopedAStatus::ok();
119     }
120 
121     return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
122 }
123 }  // namespace display
124 }  // namespace pixel
125 }  // namespace hardware
126 }  // namespace google
127 }  // namespace com
128 }  // namespace aidl
129