power-libperfmgr: Correctly implement DT2W support
authorAndreas Schneider <asn@cryptomilk.org>
Wed, 1 Jul 2020 06:23:57 +0000 (08:23 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Fri, 3 Jul 2020 06:24:19 +0000 (08:24 +0200)
Change-Id: I9ed6e8886322c787ae69f2f79eb7c9b664ce08d7

hidl/power-libperfmgr/Power.cpp
hidl/power-libperfmgr/Power.h
hidl/power-libperfmgr/powerhint.json.template

index a7d8842c7e0621701c69a72acd311cb2badcb835..08c0a7480eef0fd8ccf2799909c971fc6af912cf 100644 (file)
@@ -41,6 +41,7 @@ using ::android::hardware::Return;
 using ::android::hardware::Void;
 using ::android::hardware::power::V1_0::Feature;
 using ::android::hardware::power::V1_0::Status;
+using namespace std::chrono_literals;
 
 constexpr char kPowerHalStateProp[] = "vendor.powerhal.state";
 constexpr char kPowerHalAudioProp[] = "vendor.powerhal.audio";
@@ -119,6 +120,8 @@ Power::Power()
             setProfile(PowerProfile::HIGH_PERFORMANCE);
             mCurrentPerfProfile = PowerProfile::HIGH_PERFORMANCE;
         }
+        mDoubleTapEnabled = false;
+
         // Now start to take powerhint
         mReady.store(true);
         ALOGI("PowerHAL ready to process hints");
@@ -185,7 +188,23 @@ Return<void> Power::setProfile(PowerProfile profile) {
 
 // Methods from ::android::hardware::power::V1_0::IPower follow.
 Return<void> Power::setInteractive(bool interactive) {
-    return updateHint("NOT_INTERACTIVE", !interactive);
+    // Enable dt2w before turning TSP off
+    if (mDoubleTapEnabled && !interactive) {
+       updateHint("DOUBLE_TAP_TO_WAKE", true);
+       // It takes some time till the cmd is executed in the Kernel, there
+       // is an interface to check that. To avoid that just wait for 25ms
+       // till we turn off the touchscreen and lcd.
+       std::this_thread::sleep_for(25ms);
+    }
+
+    updateHint("NOT_INTERACTIVE", !interactive);
+
+    // Disable dt2w after turning TSP back on
+    if (mDoubleTapEnabled && interactive) {
+       updateHint("DOUBLE_TAP_TO_WAKE", false);
+    }
+
+    return Void();
 }
 
 Return<void> Power::powerHint(PowerHint_1_0 hint, int32_t data) {
@@ -262,7 +281,7 @@ Return<void> Power::powerHint(PowerHint_1_0 hint, int32_t data) {
 Return<void> Power::setFeature(Feature feature, bool activate) {
     switch (feature) {
         case Feature::POWER_FEATURE_DOUBLE_TAP_TO_WAKE:
-            updateHint("DOUBLE_TAP_TO_WAKE", activate);
+            mDoubleTapEnabled = activate;
             break;
         default:
             break;
index 81687b2c9e21816260f461fca160e665f1da94dd..8ff4aea4a9102dacdbf62db3bd334044e34417fa 100644 (file)
@@ -95,6 +95,8 @@ class Power : public IPower, public ILineagePower {
     std::atomic<bool> mReady;
     std::thread mInitThread;
 
+    std::atomic<bool> mDoubleTapEnabled;
+
     int32_t mNumPerfProfiles;
     std::atomic<PowerProfile> mCurrentPerfProfile;
 
index 878713197b8b29ee1e17b107b9b57cbbab24c2d3..359dad8245a5f9f937dc304bc8084944743a391f 100644 (file)
         },
         {
             "Name": "DoubleTapToWakeEnable",
-            "Path": "/sys/class/sec/tsp/dt2w_enable",
+            "Path": "/sys/class/sec/tsp/cmd",
             "Values": [
-                "0",
-                "1"
+                "aot_enable,0",
+                "aot_enable,1"
             ],
             "DefaultIndex": 0,
-            "ResetOnInit": true
         },
         {
             "Name": "PowerHALMainState",
             "PowerHint": "DOUBLE_TAP_TO_WAKE",
             "Node": "DoubleTapToWakeEnable",
             "Duration": 0,
-            "Value": "1"
+            "Value": "aot_enable,1"
         },
         {
             "PowerHint": "PROFILE_POWER_SAVE",