• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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,const string & userid)29 bool containsMount(const string& path, const string& userid) {
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     const string& rest_of_path = path.substr(prefix.length());
39     if (!android::base::StartsWithIgnoreCase(rest_of_path, userid)) {
40         return false;
41     }
42 
43     static const string android_suffix = "/Android";
44     static const string data_suffix = "/Android/data";
45     static const string obb_suffix = "/Android/obb";
46 
47     const string& path_suffix = rest_of_path.substr(userid.length());
48     return android::base::EqualsIgnoreCase(path_suffix, android_suffix) ||
49            android::base::EqualsIgnoreCase(path_suffix, data_suffix) ||
50            android::base::EqualsIgnoreCase(path_suffix, obb_suffix);
51 }
52 
53 }  // namespace fuse
54 }  // namespace mediaprovider
55