power: Ignore system hint sessions for universal boost

Currently PowerHAL does not distinguish between system processes and
apps when deciding whether to apply universal boost. This patch
distinguishes system sessions and app sessions and ignores system ones,
making the disabling of universal boost dependent on the presence of app
hint sessions.

Bug: b/230511824
Test: manual
Change-Id: I08dea29b3a45f2ba69ed99a9f188fa83ba143423
diff --git a/aidl/power-libperfmgr/PowerHintSession.cpp b/aidl/power-libperfmgr/PowerHintSession.cpp
index deb5ebd..c562b06 100644
--- a/aidl/power-libperfmgr/PowerHintSession.cpp
+++ b/aidl/power-libperfmgr/PowerHintSession.cpp
@@ -24,6 +24,7 @@
 #include <android-base/properties.h>
 #include <android-base/stringprintf.h>
 #include <perfmgr/AdpfConfig.h>
+#include <private/android_filesystem_config.h>
 #include <sys/syscall.h>
 #include <time.h>
 #include <utils/Trace.h>
@@ -183,7 +184,15 @@
     return idstr;
 }
 
+bool PowerHintSession::isAppSession() {
+    // Check if uid is in range reserved for applications
+    return mDescriptor->uid >= AID_APP_START;
+}
+
 void PowerHintSession::updateUniveralBoostMode() {
+    if (!isAppSession()) {
+        return;
+    }
     if (ATRACE_ENABLED()) {
         const std::string tag = StringPrintf("%s:updateUniveralBoostMode()", getIdString().c_str());
         ATRACE_BEGIN(tag.c_str());
diff --git a/aidl/power-libperfmgr/PowerHintSession.h b/aidl/power-libperfmgr/PowerHintSession.h
index bd5882c..4b28457 100644
--- a/aidl/power-libperfmgr/PowerHintSession.h
+++ b/aidl/power-libperfmgr/PowerHintSession.h
@@ -87,6 +87,8 @@
             const std::vector<WorkDuration> &actualDurations) override;
     bool isActive();
     bool isStale();
+    // Is this hint session for a user application
+    bool isAppSession();
     const std::vector<int> &getTidList() const;
     int restoreUclamp();
 
diff --git a/aidl/power-libperfmgr/PowerSessionManager.cpp b/aidl/power-libperfmgr/PowerSessionManager.cpp
index 7877a6a..be03e44 100644
--- a/aidl/power-libperfmgr/PowerSessionManager.cpp
+++ b/aidl/power-libperfmgr/PowerSessionManager.cpp
@@ -91,12 +91,12 @@
     mSessions.erase(session);
 }
 
-std::optional<bool> PowerSessionManager::isAnySessionActive() {
+std::optional<bool> PowerSessionManager::isAnyAppSessionActive() {
     std::lock_guard<std::mutex> guard(mLock);
     bool active = false;
     for (PowerHintSession *s : mSessions) {
         // session active and not stale is actually active.
-        if (s->isActive() && !s->isStale()) {
+        if (s->isActive() && !s->isStale() && s->isAppSession()) {
             active = true;
             break;
         }
@@ -111,7 +111,7 @@
 }
 
 void PowerSessionManager::handleMessage(const Message &) {
-    auto active = isAnySessionActive();
+    auto active = isAnyAppSessionActive();
     if (!active.has_value()) {
         return;
     }
diff --git a/aidl/power-libperfmgr/PowerSessionManager.h b/aidl/power-libperfmgr/PowerSessionManager.h
index 4559e0e..375f0ea 100644
--- a/aidl/power-libperfmgr/PowerSessionManager.h
+++ b/aidl/power-libperfmgr/PowerSessionManager.h
@@ -59,7 +59,7 @@
     }
 
   private:
-    std::optional<bool> isAnySessionActive();
+    std::optional<bool> isAnyAppSessionActive();
     void disableSystemTopAppBoost();
     void enableSystemTopAppBoost();
     const std::string kDisableBoostHintName;