FUSE-BPF: Unify matching of data and obb paths

The operations to perform on a matching Android/data or Android/obb
paths are the same, so there's no need for having two equivalent regular
expressions for the two different cases, which for matching Android/obb
paths would be both executed.
Thus, merge the two regexes in one that matches both the cases to make
the code cleaner and reduce one regex matching.

Bug: 214034634
Test: ScopedStorageDeviceTest
Signed-off-by: Alessio Balsini <balsini@google.com>
Change-Id: If3d1095e3e96f1c9f02f81e5cd6a12261901195e
diff --git a/jni/FuseDaemon.cpp b/jni/FuseDaemon.cpp
index e1e8ae8..a7a7ac0 100644
--- a/jni/FuseDaemon.cpp
+++ b/jni/FuseDaemon.cpp
@@ -117,10 +117,8 @@
 const std::regex PATTERN_OWNED_PATH(
         "^/storage/[^/]+/(?:[0-9]+/)?Android/(?:data|obb)/([^/]+)(/?.*)?",
         std::regex_constants::icase);
-const std::regex PATTERN_DATA_PATH("^/storage/[^/]+/(?:[0-9]+/)?Android/data$",
-                                   std::regex_constants::icase);
-const std::regex PATTERN_OBB_PATH("^/storage/[^/]+/(?:[0-9]+/)?Android/obb$",
-                                  std::regex_constants::icase);
+const std::regex PATTERN_BPF_BACKING_PATH("^/storage/[^/]+/[0-9]+/Android/(data|obb)$",
+                                          std::regex_constants::icase);
 
 static constexpr char TRANSFORM_SYNTHETIC_DIR[] = "synthetic";
 static constexpr char TRANSFORM_TRANSCODE_DIR[] = "transcode";
@@ -478,12 +476,8 @@
     return std::regex_match(path, PATTERN_OWNED_PATH);
 }
 
-static bool is_data_path(const string& path) {
-    return std::regex_match(path, PATTERN_DATA_PATH);
-}
-
-static bool is_obb_path(const string& path) {
-    return std::regex_match(path, PATTERN_OBB_PATH);
+static bool is_bpf_backing_path(const string& path) {
+    return std::regex_match(path, PATTERN_BPF_BACKING_PATH);
 }
 
 // See fuse_lowlevel.h fuse_lowlevel_notify_inval_entry for how to call this safetly without
@@ -696,7 +690,7 @@
     // introduce a performance regression.
     // Currently FUSE BPF is limited to the Android/data and Android/obb
     // directories.
-    if (!fuse->bpf || !(is_data_path(path) || is_obb_path(path))) {
+    if (!fuse->bpf || !is_bpf_backing_path(path)) {
         e->entry_timeout = get_entry_timeout(path, should_invalidate, fuse);
         e->attr_timeout = std::numeric_limits<double>::max();
     }
@@ -836,7 +830,7 @@
     // TODO(b/211873756) Enable only for the primary volume. Must be
     // extended for other media devices.
     if (android::base::StartsWith(child_path, PRIMARY_VOLUME_PREFIX)) {
-        if (is_data_path(child_path) || is_obb_path(child_path)) {
+        if (is_bpf_backing_path(child_path)) {
             fuse_bpf_fill_entries(child_path, fuse->bpf_fd, e);
         } else if (is_package_owned_path(child_path, fuse->path)) {
             fuse_bpf_fill_entries(child_path, static_cast<int>(BpfFd::REMOVE), e);