Skip the map update if not supported

for devices that does not have a bpf map on it. Skip the bpf map update
code path when update the permission information about the apps and
services. This fix will clean up the unecessary error logs on legacy
devices.

Bug: 128944261
Test: Check no error logs on legacy devices when device boot.
Change-Id: Ibb695b35305d3ad062d7f053d5be63bf75d3b689
diff --git a/server/TrafficController.cpp b/server/TrafficController.cpp
index f065e5e..548465b 100644
--- a/server/TrafficController.cpp
+++ b/server/TrafficController.cpp
@@ -837,7 +837,13 @@
             // Clean up all permission information for the related uid if all the
             // packages related to it are uninstalled.
             mPrivilegedUser.erase(uid);
-            Status ret = mUidPermissionMap.deleteValue(uid);
+            if (mBpfLevel > BpfLevel::NONE) {
+                Status ret = mUidPermissionMap.deleteValue(uid);
+                if (!isOk(ret) && ret.code() != ENONET) {
+                    ALOGE("Failed to clean up the permission for %u: %s", uid,
+                          strerror(ret.code()));
+                }
+            }
         }
         return;
     }
@@ -845,6 +851,16 @@
     bool privileged = (permission & INetd::PERMISSION_UPDATE_DEVICE_STATS);
 
     for (uid_t uid : uids) {
+        if (privileged) {
+            mPrivilegedUser.insert(uid);
+        } else {
+            mPrivilegedUser.erase(uid);
+        }
+
+        // Skip the bpf map operation if not supported.
+        if (mBpfLevel == BpfLevel::NONE) {
+            continue;
+        }
         // The map stores all the permissions that the UID has, except if the only permission
         // the UID has is the INTERNET permission, then the UID should not appear in the map.
         if (permission != INetd::PERMISSION_INTERNET) {
@@ -859,12 +875,6 @@
                 ALOGE("Failed to remove uid %u from permission map: %s", uid, strerror(ret.code()));
             }
         }
-
-        if (privileged) {
-            mPrivilegedUser.insert(uid);
-        } else {
-            mPrivilegedUser.erase(uid);
-        }
     }
 }