Temporarily open BPF maps with no access flags.

Some device kernels have not yet picked up the commit that adds
support for BPF file open flags. Make userspace always use 0
until the kernels are fixed.

Also fix the log tag (it's currently empty).

Bug: 30950746
Test: "adb shell dumpsys netstats detail" returns data on device with 4.9 kernel
Change-Id: Icbab37e0bc9376d2c23e70eaa290a367bc804498
diff --git a/libbpf/BpfNetworkStats.cpp b/libbpf/BpfNetworkStats.cpp
index bbe4c30..31ba606 100644
--- a/libbpf/BpfNetworkStats.cpp
+++ b/libbpf/BpfNetworkStats.cpp
@@ -28,11 +28,20 @@
 #include "bpf/BpfNetworkStats.h"
 #include "bpf/BpfUtils.h"
 
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "BpfNetworkStats"
+
 namespace android {
 namespace bpf {
 
 static const char* BPF_IFACE_STATS = "/proc/net/dev";
 
+// TODO: change this to BPF_F_RDONLY as soon as device kernels have been updated.
+static constexpr uint32_t BPF_OPEN_FLAGS = 0;
+
 int bpfGetUidStatsInternal(uid_t uid, Stats* stats, const base::unique_fd& map_fd) {
     struct StatsKey curKey, nextKey;
     curKey = NONEXISTENT_STATSKEY;
@@ -55,10 +64,10 @@
 }
 
 int bpfGetUidStats(uid_t uid, Stats* stats) {
-    base::unique_fd uidStatsMap(bpf::mapRetrieve(UID_STATS_MAP_PATH, BPF_F_RDONLY));
+    base::unique_fd uidStatsMap(bpf::mapRetrieve(UID_STATS_MAP_PATH, BPF_OPEN_FLAGS));
     if (uidStatsMap < 0) {
         int ret = -errno;
-        ALOGE("get map fd failed from %s: %s", UID_STATS_MAP_PATH, strerror(errno));
+        ALOGE("Opening map fd from %s failed: %s", UID_STATS_MAP_PATH, strerror(errno));
         return ret;
     }
     return bpfGetUidStatsInternal(uid, stats, uidStatsMap);
@@ -184,7 +193,7 @@
 int parseBpfNetworkStatsDetail(std::vector<stats_line>* lines,
                                const std::vector<std::string>& limitIfaces, int limitTag,
                                int limitUid) {
-    base::unique_fd tagStatsMap(bpf::mapRetrieve(TAG_STATS_MAP_PATH, 0));
+    base::unique_fd tagStatsMap(bpf::mapRetrieve(TAG_STATS_MAP_PATH, BPF_OPEN_FLAGS));
     int ret = 0;
     if (tagStatsMap < 0) {
         ret = -errno;
@@ -195,10 +204,10 @@
     if (ret) return ret;
 
     if (limitTag == TAG_ALL) {
-        base::unique_fd uidStatsMap(bpf::mapRetrieve(UID_STATS_MAP_PATH, BPF_F_RDONLY));
+        base::unique_fd uidStatsMap(bpf::mapRetrieve(UID_STATS_MAP_PATH, BPF_OPEN_FLAGS));
         if (uidStatsMap < 0) {
             ret = -errno;
-            ALOGE("get map fd failed: %s", strerror(errno));
+            ALOGE("Opening map fd from %s failed: %s", UID_STATS_MAP_PATH, strerror(errno));
             return ret;
         }
         ret = parseBpfUidStatsDetail(lines, limitIfaces, limitUid, uidStatsMap);
@@ -263,7 +272,7 @@
 }
 
 int cleanStatsMap() {
-    base::unique_fd cookieTagMap(bpf::mapRetrieve(COOKIE_UID_MAP_PATH, BPF_F_RDONLY));
+    base::unique_fd cookieTagMap(bpf::mapRetrieve(COOKIE_UID_MAP_PATH, BPF_OPEN_FLAGS));
     int ret = 0;
     if (cookieTagMap < 0) {
         ret = -errno;
@@ -271,7 +280,7 @@
         return ret;
     }
 
-    base::unique_fd tagStatsMap(bpf::mapRetrieve(TAG_STATS_MAP_PATH, 0));
+    base::unique_fd tagStatsMap(bpf::mapRetrieve(TAG_STATS_MAP_PATH, BPF_OPEN_FLAGS));
     if (tagStatsMap < 0) {
         ret = -errno;
         ALOGE("get tagStats map fd failed: %s", strerror(errno));