sdm710-common: Implement SunlightEnhancement LiveDisplay HAL

* Add LiveDisplay HAL and SunlightEnhancement using 'hbm' sysfs knob

Change-Id: I4583e45427d689827b020ca960f37f6fa92e3d11
This commit is contained in:
Ivan Vecera
2022-08-05 18:57:16 +02:00
committed by Ivan Večeřa
parent 76cb1d6e42
commit e607977d60
9 changed files with 207 additions and 0 deletions

35
livedisplay/Android.bp Normal file
View File

@@ -0,0 +1,35 @@
//
// Copyright (C) 2022 The LineageOS Project
//
// Licensed under the Apache License, Version 2.1 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.1
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
cc_binary {
name: "vendor.lineage.livedisplay@2.1-service.sdm710",
defaults: ["hidl_defaults"],
vintf_fragments: ["vendor.lineage.livedisplay@2.1-service.sdm710.xml"],
init_rc: ["vendor.lineage.livedisplay@2.1-service.sdm710.rc"],
relative_install_path: "hw",
srcs: [
"SunlightEnhancement.cpp",
"service.cpp",
],
vendor: true,
shared_libs: [
"libbase",
"libbinder",
"libhidlbase",
"libutils",
"vendor.lineage.livedisplay@2.0",
"vendor.lineage.livedisplay@2.1",
],
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright (C) 2022 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "SunlightEnhancementService"
#include <fstream>
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/strings.h>
#include "SunlightEnhancement.h"
namespace vendor {
namespace lineage {
namespace livedisplay {
namespace V2_1 {
namespace implementation {
static constexpr const char* kHbmPath = "/sys/devices/platform/soc/soc:qcom,dsi-display-primary/hbm";
bool SunlightEnhancement::isSupported() {
std::ofstream hbm_file(kHbmPath);
if (!hbm_file.is_open()) {
LOG(ERROR) << "Failed to open " << kHbmPath << ", error=" << errno
<< " (" << strerror(errno) << ")";
}
return !hbm_file.fail();
}
Return<bool> SunlightEnhancement::isEnabled() {
std::ifstream hbm_file(kHbmPath);
int result = -1;
hbm_file >> result;
return !hbm_file.fail() && result > 0;
}
Return<bool> SunlightEnhancement::setEnabled(bool enabled) {
std::ofstream hbm_file(kHbmPath);
hbm_file << (enabled ? '1' : '0');
if (hbm_file.fail())
LOG(ERROR) << "Failed to write " << kHbmPath;
return !hbm_file.fail();
}
} // namespace implementation
} // namespace V2_1
} // namespace livedisplay
} // namespace lineage
} // namespace vendor

View File

@@ -0,0 +1,44 @@
/*
* Copyright (C) 2022 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <hidl/MQDescriptor.h>
#include <hidl/Status.h>
#include <vendor/lineage/livedisplay/2.1/ISunlightEnhancement.h>
namespace vendor {
namespace lineage {
namespace livedisplay {
namespace V2_1 {
namespace implementation {
using ::android::hardware::Return;
class SunlightEnhancement : public ISunlightEnhancement {
public:
bool isSupported();
// Methods from ::vendor::lineage::livedisplay::V2_1::ISunlightEnhancement follow.
Return<bool> isEnabled() override;
Return<bool> setEnabled(bool enabled) override;
};
} // namespace implementation
} // namespace V2_1
} // namespace livedisplay
} // namespace lineage
} // namespace vendor

45
livedisplay/service.cpp Normal file
View File

@@ -0,0 +1,45 @@
/*
* Copyright (C) 2022 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "vendor.lineage.livedisplay@2.1-service.sdm710"
#include <android-base/logging.h>
#include <binder/ProcessState.h>
#include <hidl/HidlTransportSupport.h>
#include "SunlightEnhancement.h"
using ::vendor::lineage::livedisplay::V2_1::implementation::SunlightEnhancement;
int main() {
android::sp<SunlightEnhancement> sunlightEnhancement = new SunlightEnhancement();
android::hardware::configureRpcThreadpool(1, true /*callerWillJoin*/);
if (sunlightEnhancement->isSupported()) {
if (sunlightEnhancement->registerAsService() != android::OK) {
LOG(ERROR) << "Cannot register sunlight enhancement HAL service.";
return 1;
}
}
LOG(INFO) << "LiveDisplay HAL service is ready.";
android::hardware::joinRpcThreadpool();
LOG(ERROR) << "LiveDisplay HAL service failed to join thread pool.";
return 1;
}

View File

@@ -0,0 +1,7 @@
on boot
chown system system /sys/devices/platform/soc/soc:qcom,dsi-display-primary/hbm
service vendor.livedisplay-hal-2-1 /vendor/bin/hw/vendor.lineage.livedisplay@2.1-service.sdm710
class late_start
user system
group system

View File

@@ -0,0 +1,7 @@
<manifest version="1.0" type="device">
<hal format="hidl">
<name>vendor.lineage.livedisplay</name>
<transport>hwbinder</transport>
<fqname>@2.1::ISunlightEnhancement/default</fqname>
</hal>
</manifest>

View File

@@ -220,6 +220,10 @@ PRODUCT_PACKAGES += \
PRODUCT_PACKAGES += \
android.hardware.light-service.xiaomi
# LiveDisplay
PRODUCT_PACKAGES += \
vendor.lineage.livedisplay@2.1-service.sdm710
# Media
PRODUCT_PACKAGES += \
libavservices_minijail \

View File

@@ -16,6 +16,7 @@
/sys/devices/platform/soc/[a-z0-9]+.qcom,mdss_mdp/drm/card([0-3])+/card([0-3])+-DSI-1/hbm_status u:object_r:sysfs_graphics:s0
/sys/devices/platform/soc/[a-z0-9]+.qcom,mdss_mdp/drm/card([0-3])+/card([0-3])+-DSI-1/panel_info u:object_r:sysfs_graphics:s0
/sys/devices/platform/soc/[a-z0-9]+.qcom,mdss_mdp/drm/card([0-3])+/card([0-3])+-DSI-1/smart_fps_value u:object_r:sysfs_graphics:s0
/vendor/bin/hw/vendor\.lineage\.livedisplay@2\.1-service\.sdm710 u:object_r:hal_lineage_livedisplay_qti_exec:s0
# Fingerprint
/vendor/bin/hw/android\.hardware\.biometrics\.fingerprint@2\.3-service\.xiaomi u:object_r:hal_fingerprint_default_exec:s0

View File

@@ -0,0 +1,2 @@
allow hal_lineage_livedisplay_qti sysfs_graphics:dir search;
allow hal_lineage_livedisplay_qti sysfs_graphics:file rw_file_perms;