1 /* 2 * Copyright (C) 2017 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 #define LOG_TAG "VrDevice" 18 19 #include <android-base/file.h> 20 #include <android-base/logging.h> 21 #include <android-base/properties.h> 22 #include <android-base/stringprintf.h> 23 24 #include "VrDevice.h" 25 26 namespace android { 27 namespace hardware { 28 namespace vr { 29 namespace V1_0 { 30 namespace implementation { 31 32 VrDevice::VrDevice() : mVRmode(false) {} 33 34 Return<void> VrDevice::init() { 35 // NOOP 36 return Void(); 37 } 38 39 Return<void> VrDevice::setVrMode(bool enabled) { 40 std::string hwProp = android::base::GetProperty("ro.hardware", "default"); 41 std::string vrMode = enabled ? "-vr" : ""; 42 std::string thermalConf = "/vendor/etc/thermal-engine-" + hwProp + vrMode + ".conf"; 43 mVRmode = enabled; 44 45 if (!android::base::SetProperty("vendor.sys.qcom.thermalcfg", thermalConf)) { 46 LOG(ERROR) << "Couldn't set vendor.sys.qcom.thermalcfg to " << thermalConf; 47 return Void(); 48 } 49 if (!android::base::SetProperty("ctl.restart", "vendor.thermal-engine")) { 50 LOG(ERROR) << "Couldn't set thermal_engine restart property"; 51 } 52 return Void(); 53 } 54 55 Return<void> VrDevice::debug(const hidl_handle& handle, const hidl_vec<hidl_string>&) { 56 if (handle != nullptr && handle->numFds >= 1) { 57 int fd = handle->data[0]; 58 std::string buf(android::base::StringPrintf("VRMode: %s\n", 59 (mVRmode ? "true" : "false"))); 60 if (!android::base::WriteStringToFd(buf, fd)) { 61 PLOG(ERROR) << "Failed to dump state to fd"; 62 } 63 fsync(fd); 64 } 65 return Void(); 66 } 67 68 } // namespace implementation 69 } // namespace V1_0 70 } // namespace vr 71 } // namespace hardware 72 } // namespace android 73