• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_ANDROID_CONTENT_URI_UTILS_H_
6 #define BASE_ANDROID_CONTENT_URI_UTILS_H_
7 
8 #include <jni.h>
9 
10 #include <string>
11 #include <vector>
12 
13 #include "base/base_export.h"
14 #include "base/files/file.h"
15 #include "base/files/file_enumerator.h"
16 #include "base/files/file_path.h"
17 
18 namespace base {
19 namespace internal {
20 
21 // Check whether a content URI exists.
22 BASE_EXPORT bool ContentUriExists(const FilePath& content_uri);
23 
24 // Translates File::FLAG_* `open_flags` bitset to Java mode from
25 // ParcelFileDescriptor#parseMode(): ("r", "w", "wt", "wa", "rw" or "rwt").
26 // Disallows "w" which has been the source of android security issues.
27 // Returns nullopt if `open_flags` are not supported.
28 BASE_EXPORT std::optional<std::string> TranslateOpenFlagsToJavaMode(
29     uint32_t open_flags);
30 
31 // Opens a content URI and returns the file descriptor to the caller.
32 // `open_flags` is a bitmap of File::FLAG_* values.
33 // Returns -1 if the URI is invalid.
34 int OpenContentUri(const FilePath& content_uri, uint32_t open_flags);
35 
36 // Returns true if file exists and results are populated, else returns false.
37 bool ContentUriGetFileInfo(const FilePath& content_uri,
38                            FileEnumerator::FileInfo* results);
39 
40 // Returns list of files in `content_uri` directory.
41 std::vector<FileEnumerator::FileInfo> ListContentUriDirectory(
42     const FilePath& content_uri);
43 
44 // Deletes a content URI.
45 bool DeleteContentUri(const FilePath& content_uri);
46 
47 // Returns whether `content_uri` is a Document URI.
48 bool IsDocumentUri(const FilePath& content_uri);
49 
50 }  // namespace internal
51 
52 // Gets MIME type from a content URI. Returns an empty string if the URI is
53 // invalid.
54 BASE_EXPORT std::string GetContentUriMimeType(const FilePath& content_uri);
55 
56 // Gets the display name from a content URI. Returns true if the name was found.
57 BASE_EXPORT bool MaybeGetFileDisplayName(const FilePath& content_uri,
58                                          std::u16string* file_display_name);
59 
60 // Build URI using tree_uri and encoded_document_id.
61 BASE_EXPORT FilePath
62 ContentUriBuildDocumentUriUsingTree(const FilePath& tree_uri,
63                                     const std::string& encoded_document_id);
64 
65 // Returns the URI of the matching document, or if document does not exist and
66 // `create` is true then returns a URI that can be used with
67 // ContentUriGetDocumentFromQuery() to create the specified document under
68 // `parent` directory with the specified `display_name` and `mime_type`.
69 BASE_EXPORT FilePath
70 ContentUriGetChildDocumentOrQuery(const FilePath& parent,
71                                   const std::string& display_name,
72                                   const std::string& mime_type,
73                                   bool is_directory,
74                                   bool create);
75 
76 // Returns whether this is a create-child-document query returned by
77 // ContentUriGetChildDocumentOrQuery().
78 BASE_EXPORT bool ContentUriIsCreateChildDocumentQuery(
79     const FilePath& content_uri);
80 
81 // Gets a document with the details encoded in `document_query` which must be
82 // the result of calling ContentUriGetChildDocumentOrQuery(). If `create` is
83 // true, the document will be created if it does not exist.
84 BASE_EXPORT FilePath
85 ContentUriGetDocumentFromQuery(const FilePath& document_query, bool create);
86 
87 }  // namespace base
88 
89 #endif  // BASE_ANDROID_CONTENT_URI_UTILS_H_
90