1 // Copyright (C) 2019 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #define LOG_TAG "FuseUtils"
16 
17 #include "include/libfuse_jni/FuseUtils.h"
18 
19 #include <string>
20 #include <vector>
21 
22 #include "android-base/strings.h"
23 
24 using std::string;
25 
26 namespace mediaprovider {
27 namespace fuse {
28 
containsMount(const string & path)29 bool containsMount(const string& path) {
30     // This method is called from lookup, so it's called rather frequently.
31     // Hence, we avoid concatenating the strings and we use 3 separate suffixes.
32 
33     static const string prefix = "/storage/emulated/";
34     if (!android::base::StartsWithIgnoreCase(path, prefix)) {
35         return false;
36     }
37 
38     size_t pos = path.find_first_of('/', prefix.length());
39     if (pos == std::string::npos) {
40         return false;
41     }
42 
43     const string& path_suffix = path.substr(pos);
44 
45     static const string android_suffix = "/Android";
46     static const string data_suffix = "/Android/data";
47     static const string obb_suffix = "/Android/obb";
48 
49     return android::base::EqualsIgnoreCase(path_suffix, android_suffix) ||
50            android::base::EqualsIgnoreCase(path_suffix, data_suffix) ||
51            android::base::EqualsIgnoreCase(path_suffix, obb_suffix);
52 }
53 
54 }  // namespace fuse
55 }  // namespace mediaprovider
56