VRR: Use appId to replace uid mapping
Uid is combination of user id and app id. Because the allowlist
is recored by pkg for each users. We could ignore the user id part
and it also could solve the issue we didn't update the mapping
when user added case.
Bug: 298722189
Test: atest SmallAreaDetectionAllowMappingsTest
Test: atest SmallAreaDetectionControllerTest
Test: Add new user and open Youtube short to check refresh rate
Change-Id: Ic80be38ebc19938bc061bf6121c68efc4ff9ac4c
diff --git a/services/surfaceflinger/Scheduler/Scheduler.cpp b/services/surfaceflinger/Scheduler/Scheduler.cpp
index 27c96f7..09ce9a6 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.cpp
+++ b/services/surfaceflinger/Scheduler/Scheduler.cpp
@@ -1180,18 +1180,19 @@
}
void Scheduler::updateSmallAreaDetection(
- std::vector<std::pair<uid_t, float>>& uidThresholdMappings) {
+ std::vector<std::pair<int32_t, float>>& uidThresholdMappings) {
mSmallAreaDetectionAllowMappings.update(uidThresholdMappings);
}
-void Scheduler::setSmallAreaDetectionThreshold(uid_t uid, float threshold) {
- mSmallAreaDetectionAllowMappings.setThesholdForUid(uid, threshold);
+void Scheduler::setSmallAreaDetectionThreshold(int32_t appId, float threshold) {
+ mSmallAreaDetectionAllowMappings.setThesholdForAppId(appId, threshold);
}
-bool Scheduler::isSmallDirtyArea(uid_t uid, uint32_t dirtyArea) {
- std::optional<float> oThreshold = mSmallAreaDetectionAllowMappings.getThresholdForUid(uid);
- if (oThreshold) return mLayerHistory.isSmallDirtyArea(dirtyArea, oThreshold.value());
-
+bool Scheduler::isSmallDirtyArea(int32_t appId, uint32_t dirtyArea) {
+ std::optional<float> oThreshold = mSmallAreaDetectionAllowMappings.getThresholdForAppId(appId);
+ if (oThreshold) {
+ return mLayerHistory.isSmallDirtyArea(dirtyArea, oThreshold.value());
+ }
return false;
}
diff --git a/services/surfaceflinger/Scheduler/Scheduler.h b/services/surfaceflinger/Scheduler/Scheduler.h
index d65df2a..23a21e8 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.h
+++ b/services/surfaceflinger/Scheduler/Scheduler.h
@@ -292,12 +292,12 @@
void setGameModeRefreshRateForUid(FrameRateOverride);
- void updateSmallAreaDetection(std::vector<std::pair<uid_t, float>>& uidThresholdMappings);
+ void updateSmallAreaDetection(std::vector<std::pair<int32_t, float>>& uidThresholdMappings);
- void setSmallAreaDetectionThreshold(uid_t uid, float threshold);
+ void setSmallAreaDetectionThreshold(int32_t appId, float threshold);
// Returns true if the dirty area is less than threshold.
- bool isSmallDirtyArea(uid_t uid, uint32_t dirtyArea);
+ bool isSmallDirtyArea(int32_t appId, uint32_t dirtyArea);
// Retrieves the overridden refresh rate for a given uid.
std::optional<Fps> getFrameRateOverride(uid_t) const EXCLUDES(mDisplayLock);
diff --git a/services/surfaceflinger/Scheduler/SmallAreaDetectionAllowMappings.cpp b/services/surfaceflinger/Scheduler/SmallAreaDetectionAllowMappings.cpp
index 95cd5d1..38c6da4 100644
--- a/services/surfaceflinger/Scheduler/SmallAreaDetectionAllowMappings.cpp
+++ b/services/surfaceflinger/Scheduler/SmallAreaDetectionAllowMappings.cpp
@@ -19,26 +19,26 @@
namespace android::scheduler {
void SmallAreaDetectionAllowMappings::update(
- std::vector<std::pair<uid_t, float>>& uidThresholdMappings) {
+ std::vector<std::pair<int32_t, float>>& appIdThresholdMappings) {
std::lock_guard lock(mLock);
mMap.clear();
- for (std::pair<uid_t, float> row : uidThresholdMappings) {
+ for (std::pair<int32_t, float> row : appIdThresholdMappings) {
if (!isValidThreshold(row.second)) continue;
mMap.emplace(row.first, row.second);
}
}
-void SmallAreaDetectionAllowMappings::setThesholdForUid(uid_t uid, float threshold) {
+void SmallAreaDetectionAllowMappings::setThesholdForAppId(int32_t appId, float threshold) {
if (!isValidThreshold(threshold)) return;
std::lock_guard lock(mLock);
- mMap.emplace(uid, threshold);
+ mMap.emplace(appId, threshold);
}
-std::optional<float> SmallAreaDetectionAllowMappings::getThresholdForUid(uid_t uid) {
+std::optional<float> SmallAreaDetectionAllowMappings::getThresholdForAppId(int32_t appId) {
std::lock_guard lock(mLock);
- const auto iter = mMap.find(uid);
+ const auto iter = mMap.find(appId);
if (iter != mMap.end()) {
return iter->second;
}
diff --git a/services/surfaceflinger/Scheduler/SmallAreaDetectionAllowMappings.h b/services/surfaceflinger/Scheduler/SmallAreaDetectionAllowMappings.h
index cbab690..e10301c 100644
--- a/services/surfaceflinger/Scheduler/SmallAreaDetectionAllowMappings.h
+++ b/services/surfaceflinger/Scheduler/SmallAreaDetectionAllowMappings.h
@@ -24,16 +24,16 @@
namespace android::scheduler {
class SmallAreaDetectionAllowMappings {
- using UidThresholdMap = std::unordered_map<uid_t, float>;
+ using AppIdThresholdMap = std::unordered_map<int32_t, float>;
public:
- void update(std::vector<std::pair<uid_t, float>>& uidThresholdMappings);
- void setThesholdForUid(uid_t uid, float threshold) EXCLUDES(mLock);
- std::optional<float> getThresholdForUid(uid_t uid) EXCLUDES(mLock);
+ void update(std::vector<std::pair<int32_t, float>>& appIdThresholdMappings);
+ void setThesholdForAppId(int32_t appId, float threshold) EXCLUDES(mLock);
+ std::optional<float> getThresholdForAppId(int32_t uid) EXCLUDES(mLock);
private:
static bool isValidThreshold(float threshold) { return threshold >= 0.0f && threshold <= 1.0f; }
mutable std::mutex mLock;
- UidThresholdMap mMap GUARDED_BY(mLock);
+ AppIdThresholdMap mMap GUARDED_BY(mLock);
};
} // namespace android::scheduler