Fix the UPDATE_DEVICE_STATS permission for multiuser
When an additional user is using the device, netd should filter out the
userId prefix when checking the UPDATE_DEVICE_STATS permission.
Bug: 111560570
Test: run NetStatsHostTest#testASetThreadStatsUid on a non-default
user profile.
Change-Id: I4353a383bd898340489e7dd70374a63b2ca0938b
diff --git a/server/TrafficController.cpp b/server/TrafficController.cpp
index 74a80fe..9902874 100644
--- a/server/TrafficController.cpp
+++ b/server/TrafficController.cpp
@@ -95,8 +95,11 @@
}
bool TrafficController::hasUpdateDeviceStatsPermission(uid_t uid) {
- return ((uid == AID_ROOT) || (uid == AID_SYSTEM) ||
- mPrivilegedUser.find(uid) != mPrivilegedUser.end());
+ // This implementation is the same logic as method ActivityManager#checkComponentPermission.
+ // It implies that the calling uid can never be the same as PER_USER_RANGE.
+ uint32_t appId = uid % PER_USER_RANGE;
+ return ((appId == AID_ROOT) || (appId == AID_SYSTEM) ||
+ mPrivilegedUser.find(appId) != mPrivilegedUser.end());
}
const std::string UidPermissionTypeToString(uint8_t permission) {