• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 constexpr char kTouchVRModeSysfs[] = "/sys/devices/virtual/input/ftm4_touch/vrmode";
33 
VrDevice()34 VrDevice::VrDevice() : mVRmode(false) {
35     std::string hardware = android::base::GetProperty("ro.hardware", "");
36     if (hardware == "taimen") {
37         mFtm4Touch = true;
38     } else {
39         mFtm4Touch = false;
40     }
41 }
42 
init()43 Return<void> VrDevice::init() {
44     // NOOP
45     return Void();
46 }
47 
setVrMode(bool enabled)48 Return<void> VrDevice::setVrMode(bool enabled) {
49     mVRmode = enabled;
50     if (enabled) {
51         if (!android::base::SetProperty("sys.qcom.thermalcfg",
52                                         "/vendor/etc/thermal-engine-vr.conf")) {
53             LOG(ERROR) << "Couldn't set thermal_engine enable property";
54             return Void();
55         }
56     } else {
57         if (!android::base::SetProperty("sys.qcom.thermalcfg",
58                                         "/vendor/etc/thermal-engine.conf")) {
59             LOG(ERROR) << "Couldn't set thermal_engine disable property";
60             return Void();
61         }
62     }
63     if (!android::base::SetProperty("ctl.restart", "vendor.thermal-engine")) {
64         LOG(ERROR) << "Couldn't set thermal_engine restart property";
65     }
66 
67     if (mFtm4Touch &&
68         !android::base::WriteStringToFile((enabled ? "1" : "0"), kTouchVRModeSysfs)) {
69         PLOG(ERROR) <<  "Failed to write to vrmode sysfs node with :" << enabled;
70     }
71 
72     return Void();
73 }
74 
debug(const hidl_handle & handle,const hidl_vec<hidl_string> &)75 Return<void> VrDevice::debug(const hidl_handle& handle, const hidl_vec<hidl_string>&) {
76     if (handle != nullptr && handle->numFds >= 1) {
77         int fd = handle->data[0];
78         std::string buf(android::base::StringPrintf("VRMode: %s\n",
79                                                     (mVRmode ? "true" : "false")));
80         if (!android::base::WriteStringToFd(buf, fd)) {
81             PLOG(ERROR) << "Failed to dump state to fd";
82         }
83         fsync(fd);
84     }
85     return Void();
86 }
87 
88 }  // namespace implementation
89 }  // namespace V1_0
90 }  // namespace vr
91 }  // namespace hardware
92 }  // namespace android
93