1 /* 2 * Copyright (C) 2018 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 #include <android-base/file.h> 17 #include <hardware/lights.h> 18 #include <log/log.h> 19 20 #include "LightExt.h" 21 22 namespace hardware { 23 namespace google { 24 namespace light { 25 namespace V1_0 { 26 namespace implementation { 27 using ::android::hardware::light::V2_0::Brightness; 28 applyHBM(bool on)29Return<Status> LightExt::applyHBM(bool on) { 30 if (!mHasHbmNode) return Status::UNKNOWN; 31 32 /* skip if no change */ 33 if (mRegHBM == mCurHBM) return Status::SUCCESS; 34 35 if (!android::base::WriteStringToFile((on ? "1" : "0"), 36 kHighBrightnessModeNode)) { 37 ALOGE("write HBM failed!"); 38 return Status::UNKNOWN; 39 } 40 41 mCurHBM = on; 42 ALOGI("Set HBM to %d", on); 43 return Status::SUCCESS; 44 } 45 46 // Methods from ::android::hardware::light::V2_0::ILight follow. setLight(Type type,const LightState & state)47Return<Status> LightExt::setLight(Type type, const LightState& state) { 48 if (type == Type::BACKLIGHT) { 49 if (state.brightnessMode == Brightness::LOW_PERSISTENCE) { 50 applyHBM(false); 51 mVRMode = true; 52 } else { 53 applyHBM(mRegHBM); 54 mVRMode = false; 55 } 56 } 57 return mLight->setLight(type, state); 58 } 59 60 // Methods from ::hardware::google::light::V1_0::ILight follow. setHbm(bool on)61Return<Status> LightExt::setHbm(bool on) { 62 /* save the request state */ 63 mRegHBM = on; 64 65 if (mVRMode) return Status::UNKNOWN; 66 67 Status status = applyHBM(mRegHBM); 68 69 return status; 70 } 71 72 } // namespace implementation 73 } // namespace V1_0 74 } // namespace light 75 } // namespace google 76 } // namespace hardware 77