mirror of
				https://github.com/oplus-giulia-dev/android_hardware_oplus
				synced 2025-11-04 13:55:35 +08:00 
			
		
		
		
	power: Implement DT2W through OplusTouch
Co-authored-by: Maitreya25 <maitreyapatni25@gmail.com> Co-authored-by: Mashopy <eliasgheeraert@gmail.com> Co-authored-by: Bruno Martins <bgcngm@gmail.com> Change-Id: I5ad57428aeefe68c8a188aa1e445f4091cbc0d8a
This commit is contained in:
		
							
								
								
									
										26
									
								
								power/Android.bp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								power/Android.bp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
//
 | 
			
		||||
// SPDX-FileCopyrightText: 2024-2025 The LineageOS Project
 | 
			
		||||
// SPDX-License-Identifier: Apache-2.0
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
cc_library_static {
 | 
			
		||||
    name: "power-ext-oplus",
 | 
			
		||||
    defaults: ["android.hardware.power-ndk_shared"],
 | 
			
		||||
    vendor: true,
 | 
			
		||||
    srcs: [
 | 
			
		||||
        "power-mode.cpp",
 | 
			
		||||
    ],
 | 
			
		||||
    cppflags: select(soong_config_variable("power_libperfmgr", "mode_extension_lib"), {
 | 
			
		||||
        any: ["-DLIBPERFMGR_EXT"],
 | 
			
		||||
        default: [],
 | 
			
		||||
    }),
 | 
			
		||||
    header_libs: [
 | 
			
		||||
        "vendor.oplus.hardware.touch-headers",
 | 
			
		||||
    ],
 | 
			
		||||
    shared_libs: [
 | 
			
		||||
        "libbase",
 | 
			
		||||
    ],
 | 
			
		||||
    whole_static_libs: [
 | 
			
		||||
        "vendor.oplus.hardware.touch-V2-ndk",
 | 
			
		||||
    ],
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										66
									
								
								power/power-mode.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								power/power-mode.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,66 @@
 | 
			
		||||
/*
 | 
			
		||||
 * SPDX-FileCopyrightText: 2024-2025 The LineageOS Project
 | 
			
		||||
 * SPDX-License-Identifier: Apache-2.0
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <aidl/android/hardware/power/BnPower.h>
 | 
			
		||||
#include <aidl/vendor/oplus/hardware/touch/IOplusTouch.h>
 | 
			
		||||
 | 
			
		||||
#include <android-base/logging.h>
 | 
			
		||||
#include <android/binder_manager.h>
 | 
			
		||||
 | 
			
		||||
#include <OplusTouchConstants.h>
 | 
			
		||||
 | 
			
		||||
using aidl::android::hardware::power::Mode;
 | 
			
		||||
using aidl::vendor::oplus::hardware::touch::IOplusTouch;
 | 
			
		||||
 | 
			
		||||
#ifdef LIBPERFMGR_EXT
 | 
			
		||||
namespace aidl::google::hardware::power::impl::pixel {
 | 
			
		||||
#else
 | 
			
		||||
namespace aidl::android::hardware::power::impl {
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
bool isDeviceSpecificModeSupported(Mode type, bool* _aidl_return) {
 | 
			
		||||
    switch (type) {
 | 
			
		||||
        case Mode::DOUBLE_TAP_TO_WAKE:
 | 
			
		||||
            *_aidl_return = true;
 | 
			
		||||
            return true;
 | 
			
		||||
        default:
 | 
			
		||||
            return false;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool setDeviceSpecificMode(Mode type, bool enabled) {
 | 
			
		||||
    switch (type) {
 | 
			
		||||
        case Mode::DOUBLE_TAP_TO_WAKE: {
 | 
			
		||||
            std::string tmp;
 | 
			
		||||
            int contents = 0;
 | 
			
		||||
 | 
			
		||||
            const std::string instance = std::string() + IOplusTouch::descriptor + "/default";
 | 
			
		||||
            std::shared_ptr<IOplusTouch> oplusTouch = IOplusTouch::fromBinder(
 | 
			
		||||
                    ndk::SpAIBinder(AServiceManager_waitForService(instance.c_str())));
 | 
			
		||||
            LOG(INFO) << "Power mode: " << toString(type) << " isDoubleTapEnabled: " << enabled;
 | 
			
		||||
 | 
			
		||||
            oplusTouch->touchReadNodeFile(OplusTouchConstants::DEFAULT_TP_IC_ID,
 | 
			
		||||
                                          OplusTouchConstants::DOUBLE_TAP_INDEP_NODE, &tmp);
 | 
			
		||||
            contents = std::stoi(tmp, nullptr, 16);
 | 
			
		||||
 | 
			
		||||
            if (enabled) {
 | 
			
		||||
                contents |= OplusTouchConstants::DOUBLE_TAP_GESTURE;
 | 
			
		||||
            } else {
 | 
			
		||||
                contents &= ~OplusTouchConstants::DOUBLE_TAP_GESTURE;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            oplusTouch->touchWriteNodeFileOneWay(OplusTouchConstants::DEFAULT_TP_IC_ID,
 | 
			
		||||
                                                 OplusTouchConstants::DOUBLE_TAP_ENABLE_NODE, "1");
 | 
			
		||||
            oplusTouch->touchWriteNodeFileOneWay(OplusTouchConstants::DEFAULT_TP_IC_ID,
 | 
			
		||||
                                                 OplusTouchConstants::DOUBLE_TAP_INDEP_NODE,
 | 
			
		||||
                                                 std::to_string(contents));
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        default:
 | 
			
		||||
            return false;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}  // namespace
 | 
			
		||||
		Reference in New Issue
	
	Block a user