blob: 7829888f4dff793dce04964f76f6bdf86acb8ebe [file] [log] [blame]
Corina633099b2020-06-17 21:55:33 +01001// 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
Corina762bb252020-07-09 10:30:33 +010022#include "android-base/strings.h"
23
Corina633099b2020-06-17 21:55:33 +010024using std::string;
25
26namespace mediaprovider {
27namespace fuse {
28
29bool containsMount(const string& path, const string& userid) {
Corina762bb252020-07-09 10:30:33 +010030 // 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.
Corina633099b2020-06-17 21:55:33 +010032
Corina762bb252020-07-09 10:30:33 +010033 static const string prefix = "/storage/emulated/";
34 if (!android::base::StartsWithIgnoreCase(path, prefix)) {
Corina633099b2020-06-17 21:55:33 +010035 return false;
36 }
37
Corina762bb252020-07-09 10:30:33 +010038 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);
Corina633099b2020-06-17 21:55:33 +010051}
52
53} // namespace fuse
54} // namespace mediaprovider