Skip to content

Commit

Permalink
porsche: Bring back screen-off touch gestures
Browse files Browse the repository at this point in the history
Introduce custom power HAL extension, inspired by LineageOS/android_hardware_oplus@ce722bd

Change-Id: Ied1f685f398a7fa739738d5e99cb9626fadd50cf
  • Loading branch information
adithya2306 authored and resist15 committed Aug 5, 2023
1 parent ba7797f commit 1b96679
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
3 changes: 3 additions & 0 deletions BoardConfig.mk
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ BOARD_VENDOR_SEPOLICY_DIRS += $(DEVICE_PATH)/sepolicy/vendor
SYSTEM_EXT_PRIVATE_SEPOLICY_DIRS += $(DEVICE_PATH)/sepolicy/private
SYSTEM_EXT_PUBLIC_SEPOLICY_DIRS += $(DEVICE_PATH)/sepolicy/public

# Touch
TARGET_POWER_FEATURE_EXT_LIB := //$(DEVICE_PATH):libpowerfeature_ext_porsche

# UFS
#namespace definition for librecovery_updater
#differentiate legacy 'sg' or 'bsg' framework
Expand Down
15 changes: 15 additions & 0 deletions power/Android.bp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Copyright (C) 2023 Paranoid Android
//
// SPDX-License-Identifier: Apache-2.0
//

cc_library_static {
name: "libpowerfeature_ext_porsche",
srcs: ["power-feature.cpp"],
shared_libs: [
"libbase",
"vendor.aospa.power-V1-ndk",
],
vendor: true,
}
66 changes: 66 additions & 0 deletions power/power-feature.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2023 Paranoid Android
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <aidl/vendor/aospa/power/BnPowerFeature.h>
#include <android-base/file.h>
#include <android-base/strings.h>
#include <unordered_map>

#define GESTURE_ENABLE_PATH "/proc/touchpanel/double_tap_enable_indep"

using ::android::base::ReadFileToString;
using ::android::base::Trim;
using ::android::base::WriteStringToFile;

namespace aidl {
namespace vendor {
namespace aospa {
namespace power {

// based on values in touchpanel_common.h
static const std::unordered_map<Feature, int> GESTURE_MAP = {
{Feature::DOUBLE_TAP, 1},
{Feature::DRAW_V, 2},
{Feature::DRAW_INVERSE_V, 3},
{Feature::DRAW_O, 6},
{Feature::DRAW_M, 12},
{Feature::DRAW_W, 13},
{Feature::DRAW_ARROW_LEFT, 5},
{Feature::DRAW_ARROW_RIGHT, 4},
{Feature::ONE_FINGER_SWIPE_UP, 11},
{Feature::ONE_FINGER_SWIPE_RIGHT, 8},
{Feature::ONE_FINGER_SWIPE_DOWN, 10},
{Feature::ONE_FINGER_SWIPE_LEFT, 9},
{Feature::TWO_FINGER_SWIPE, 7},
{Feature::DRAW_S, 18},
};

bool setDeviceSpecificFeature(Feature feature, bool enabled) {
int contents = 0;
auto gesture = GESTURE_MAP.find(feature);

if (gesture == GESTURE_MAP.end()) {
// Unsupported gesture
return false;
}

if (std::string tmp; ReadFileToString(GESTURE_ENABLE_PATH, &tmp)) {
contents = std::stoi(Trim(tmp), nullptr, 16);
}

if (enabled) {
contents |= (1 << gesture->second);
} else {
contents &= ~(1 << gesture->second);
}

return WriteStringToFile(std::to_string(contents), GESTURE_ENABLE_PATH, true);
}

} // namespace power
} // namespace aospa
} // namespace vendor
} // namespace aidl

0 comments on commit 1b96679

Please sign in to comment.