Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
sm8250-common: Use MMI touchscreen class to toggle st2w/dt2w
Browse files Browse the repository at this point in the history
Change-Id: I295f5d71d7a4cb416edfc5eb9d0c043cf75f7101
  • Loading branch information
moetayuko committed Dec 23, 2023
1 parent 6e1db3f commit 30667fe
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 24 deletions.
1 change: 1 addition & 0 deletions BoardConfigCommon.mk
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ TARGET_USERIMAGES_USE_EXT4 := true
TARGET_USERIMAGES_USE_F2FS := true

# Power
TARGET_POWERHAL_MODE_EXT := $(COMMON_PATH)/lineagehw/touch/power-mode.cpp
TARGET_USES_INTERACTION_BOOST := true

# Properties
Expand Down
3 changes: 3 additions & 0 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,9 @@ PRODUCT_PACKAGES += \
PRODUCT_PACKAGES += \
[email protected]_kona

PRODUCT_COPY_FILES += \
$(LOCAL_PATH)/configs/keylayout/double-tap.kl:$(TARGET_COPY_OUT_VENDOR)/usr/keylayout/double-tap.kl

# USB HAL
PRODUCT_PACKAGES += \
[email protected] \
Expand Down
1 change: 1 addition & 0 deletions configs/keylayout/double-tap.kl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
key 62 WAKEUP
10 changes: 3 additions & 7 deletions lineagehw/touch/Android.bp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2022 The LineageOS Project
// Copyright (C) 2022-2023 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.
Expand All @@ -18,7 +18,6 @@ soong_config_module_type {
module_type: "cc_defaults",
config_namespace: "MOTO_KONA_TOUCH",
bool_variables: ["USE_TOUCH_POLLING_RATE"],
value_variables: ["SINGLE_TAP_PATH"],
properties: [
"cppflags",
"srcs",
Expand All @@ -34,11 +33,6 @@ moto_kona_touch_hal {
srcs: ["HighTouchPollingRate.cpp"],
vintf_fragments: ["[email protected]_kona.hpr.xml"],
},
SINGLE_TAP_PATH: {
cppflags: ["-DSINGLE_TAP_PATH=\"%s\""],
srcs: ["TouchscreenGesture.cpp"],
vintf_fragments: ["[email protected]_kona.gesture.xml"],
},
},
}

Expand All @@ -53,7 +47,9 @@ cc_binary {
vendor: true,
srcs: [
"service.cpp",
"TouchscreenGesture.cpp",
],
vintf_fragments: ["[email protected]_kona.gesture.xml"],
shared_libs: [
"libbase",
"libhidlbase",
Expand Down
47 changes: 47 additions & 0 deletions lineagehw/touch/MMIGesture.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2023 The LineageOS Project
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <android-base/file.h>
#include <android-base/strings.h>

namespace mmi_gesture {

constexpr auto kGestureNode = "/sys/class/touchscreen/primary/gesture";
constexpr auto kGestureModeTypeNode = "/sys/class/touchscreen/primary/gesture_mode_type";

// Keep them in sync with the kernel
enum class Gesture { kSingleTap = 0x20, kDoubleTap = 0x30 };

inline bool IsEnabled(Gesture gesture) {
std::string buf;
if (!android::base::ReadFileToString(kGestureModeTypeNode, &buf)) {
return false;
}

// Bits 0-2 correspond to zero tap, single tap, and double tap
std::bitset<3> gesture_mode_type = std::stoi(android::base::Trim(buf));
switch (gesture) {
case Gesture::kSingleTap:
return gesture_mode_type[1];
case Gesture::kDoubleTap:
return gesture_mode_type[2];
default:
return false;
}
}

inline bool SetEnabled(Gesture gesture, bool enabled) {
int code = static_cast<int>(gesture);
if (enabled) ++code;
if (!android::base::WriteStringToFile(std::to_string(code), kGestureNode)) {
return false;
}
return true;
}

} // namespace mmi_gesture
16 changes: 5 additions & 11 deletions lineagehw/touch/TouchscreenGesture.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 The LineageOS Project
* Copyright (C) 2022-2023 The LineageOS Project
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -9,17 +9,18 @@
#include <android-base/file.h>
#include <android-base/logging.h>

#include "MMIGesture.h"
#include "TouchscreenGesture.h"

namespace {
struct GestureInfo {
int32_t keycode;
const char* name;
const char* path;
const mmi_gesture::Gesture gesture;
};

constexpr GestureInfo kGestureNodes[] = {
{250, "Single Tap", SINGLE_TAP_PATH},
{59, "Single Tap", mmi_gesture::Gesture::kSingleTap},
};
} // anonymous namespace

Expand All @@ -45,14 +46,7 @@ Return<bool> TouchscreenGesture::setGestureEnabled(
if (gesture.id >= std::size(kGestureNodes)) {
return false;
}

if (!android::base::WriteStringToFile(std::to_string(enabled),
kGestureNodes[gesture.id].path)) {
LOG(ERROR) << "Wrote file " << kGestureNodes[gesture.id].path << " failed";
return false;
}

return true;
return mmi_gesture::SetEnabled(kGestureNodes[gesture.id].gesture, enabled);
}

} // namespace implementation
Expand Down
33 changes: 33 additions & 0 deletions lineagehw/touch/power-mode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2023 The LineageOS Project
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <aidl/android/hardware/power/BnPower.h>
#include "MMIGesture.h"

namespace aidl {
namespace android {
namespace hardware {
namespace power {
namespace impl {

bool isDeviceSpecificModeSupported(Mode type, bool* _aidl_return) {
if (type == Mode::DOUBLE_TAP_TO_WAKE) {
*_aidl_return = true;
return true;
}
return false;
}

bool setDeviceSpecificMode(Mode type, bool enabled) {
if (type != Mode::DOUBLE_TAP_TO_WAKE) return false;
return mmi_gesture::SetEnabled(mmi_gesture::Gesture::kDoubleTap, enabled);
}

} // namespace impl
} // namespace power
} // namespace hardware
} // namespace android
} // namespace aidl
2 changes: 0 additions & 2 deletions lineagehw/touch/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ using ::vendor::lineage::touch::V1_0::implementation::TouchscreenGesture;
int main() {
android::hardware::configureRpcThreadpool(1, true /*callerWillJoin*/);

#ifdef SINGLE_TAP_PATH
sp<ITouchscreenGesture> gesture_service = new TouchscreenGesture();
if (gesture_service->registerAsService() != OK) {
LOG(ERROR) << "Cannot register touchscreen gesture HAL service.";
return 1;
}
#endif

#ifdef USE_TOUCH_POLLING_RATE
sp<IHighTouchPollingRate> hpl_service = new HighTouchPollingRate();
Expand Down
2 changes: 2 additions & 0 deletions lineagehw/touch/[email protected]_kona.rc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
on early-boot
chown system system /sys/class/touchscreen/primary/gesture
chown system system /sys/class/touchscreen/primary/gesture_mode_type
chown system system /sys/class/touchscreen/primary/interpolation

service touch-hal-1-0 /vendor/bin/hw/[email protected]_kona
Expand Down
5 changes: 5 additions & 0 deletions modules.load.recovery
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
aw8695.ko
mmi_annotate.ko
mmi_info.ko
mmi_relay.ko
qpnp-smbcharger-mmi.ko
qpnp_adaptive_charge.ko
sensors_class.ko
touchscreen_mmi.ko
4 changes: 0 additions & 4 deletions sepolicy/vendor/genfs_contexts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ genfscon sysfs /devices/platform/soc/ae00000.qcom,mdss_mdp/drm/card0/card0-DSI-1
genfscon sysfs /devices/virtual/laser u:object_r:vendor_sysfs_laser:s0
genfscon sysfs /module/stmvl53l1 u:object_r:vendor_sysfs_laser:s0

# Touchscreen
genfscon sysfs /class/touchscreen u:object_r:vendor_sysfs_touchpanel:s0
genfscon sysfs /devices/virtual/touchscreen u:object_r:vendor_sysfs_touchpanel:s0

# Wakeup
genfscon sysfs /devices/0306_02.01.00/wakeup/wakeup u:object_r:sysfs_wakeup:s0
genfscon sysfs /devices/platform/soc/17300000.qcom,lpass/wakeup u:object_r:sysfs_wakeup:s0
Expand Down

0 comments on commit 30667fe

Please sign in to comment.