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 #ifndef HARDWARE_GOOGLE_LIGHT_V1_1_LIGHT_H
17 #define HARDWARE_GOOGLE_LIGHT_V1_1_LIGHT_H
18 
19 #include <hidl/Status.h>
20 #include <string>
21 
22 #include <hidl/MQDescriptor.h>
23 #include <hardware/google/light/1.1/ILight.h>
24 #include "Light.h"
25 
26 namespace hardware {
27 namespace google {
28 namespace light {
29 namespace V1_1 {
30 namespace implementation {
31 
32 using ::android::hardware::Return;
33 using ::android::hardware::light::V2_0::LightState;
34 using ::android::hardware::light::V2_0::Status;
35 using ::android::hardware::light::V2_0::Type;
36 using HwILight = ::android::hardware::light::V2_0::ILight;
37 
38 constexpr const char kHighBrightnessModeNode[] =
39     "/sys/class/backlight/panel0-backlight/hbm_mode";
40 
41 struct LightExt : public ::hardware::google::light::V1_1::ILight {
LightExtLightExt42   LightExt(HwILight*&& light) : mLight(light) {
43     mHasHbmNode = !access(kHighBrightnessModeNode, F_OK);
44     if (mHasHbmNode) {
45         // In case this service is crashed/restarted and leaves hbm on.
46         setHbm(false);
47         setHbmSv(false);
48     }
49   };
50 
51   // Methods from ::android::hardware::light::V2_0::ILight follow.
52   Return<Status> setLight(Type type, const LightState& state) override;
getSupportedTypesLightExt53   Return<void> getSupportedTypes(getSupportedTypes_cb _hidl_cb) override {
54     return mLight->getSupportedTypes(_hidl_cb);
55   }
56 
57   // Methods from ::hardware::google::light::V1_0::ILight follow.
58   Return<Status> setHbm(bool on) override;
59   // Methods from ::hardware::google::light::V1_1::ILight follow.
60   Return<Status> setHbmSv(bool on) override;
61   Return<bool> getHbmSv() override;
62 
63  private:
64   std::unique_ptr<HwILight> mLight;
65   Return<Status> applyHBM();
66   bool mVRMode = 0;
67   bool mRegHBM = 0;
68   bool mRegHBMSV = 0;
69   bool mCurHBM = 0;
70   bool mCurHBMSV = 0;
71   bool mHasHbmNode = false;
72 };
73 }  // namespace implementation
74 }  // namespace V1_1
75 }  // namespace light
76 }  // namespace google
77 }  // namespace hardware
78 
79 #endif  // HARDWARD_GOOGLE_LIGHT_V1_1_LIGHT_H
80