Ignore case when checking if a given path contains mount.

We used to check this on the node's build path, which should always have
the correct case (changed in I84ec47ef6c5272f476ae4c8d63d21be0aa268db9).
However, there is a small chance that path can also end up with different
lower/upper case. Having the string comparison ignore case works in all
cases.

Bug: 160853399
Test: atest FuseUtilsTest && atest --iterations 100 ScopedStorageHostTest#testCaseInsensitivity
Change-Id: I0ae1aa6b5e619ba1345442a65d15a5f3fd6b1f37
diff --git a/jni/FuseUtils.cpp b/jni/FuseUtils.cpp
index 8d6c35a..7829888 100644
--- a/jni/FuseUtils.cpp
+++ b/jni/FuseUtils.cpp
@@ -19,21 +19,35 @@
 #include <string>
 #include <vector>
 
+#include "android-base/strings.h"
+
 using std::string;
 
 namespace mediaprovider {
 namespace fuse {
 
 bool containsMount(const string& path, const string& userid) {
-    const string& prefix = "/storage/emulated/" + userid;
-    std::vector<string> suffixes = {"/Android", "/Android/data", "/Android/obb"};
+    // This method is called from lookup, so it's called rather frequently.
+    // Hence, we avoid concatenating the strings and we use 3 separate suffixes.
 
-    if (path.find(prefix) != 0) {
+    static const string prefix = "/storage/emulated/";
+    if (!android::base::StartsWithIgnoreCase(path, prefix)) {
         return false;
     }
 
-    const string& path_suffix = path.substr(prefix.length());
-    return std::find(suffixes.begin(), suffixes.end(), path_suffix) != suffixes.end();
+    const string& rest_of_path = path.substr(prefix.length());
+    if (!android::base::StartsWithIgnoreCase(rest_of_path, userid)) {
+        return false;
+    }
+
+    static const string android_suffix = "/Android";
+    static const string data_suffix = "/Android/data";
+    static const string obb_suffix = "/Android/obb";
+
+    const string& path_suffix = rest_of_path.substr(userid.length());
+    return android::base::EqualsIgnoreCase(path_suffix, android_suffix) ||
+           android::base::EqualsIgnoreCase(path_suffix, data_suffix) ||
+           android::base::EqualsIgnoreCase(path_suffix, obb_suffix);
 }
 
 }  // namespace fuse