summaryrefslogtreecommitdiff
path: root/Source/Android/jni/AndroidCommon/AndroidCommon.cpp
diff options
context:
space:
mode:
authorJMC47 <JMC4789@gmail.com>2020-12-10 16:32:43 -0500
committerGitHub <noreply@github.com>2020-12-10 16:32:43 -0500
commit75899b0e1121f01afdd606e1dd3a5822fa408530 (patch)
tree53f8c2ef2a5b61248f588aae625181233e487e1a /Source/Android/jni/AndroidCommon/AndroidCommon.cpp
parentcca04d36e21377f3292dbceb05f4768523f17df4 (diff)
parent161f8c3fad9df97ae4f97b7f45125e5e4c9608a7 (diff)
Merge pull request #9221 from JosJuice/android-saf-sd-card
Android: Use storage access framework for custom SD card paths
Diffstat (limited to 'Source/Android/jni/AndroidCommon/AndroidCommon.cpp')
-rw-r--r--Source/Android/jni/AndroidCommon/AndroidCommon.cpp39
1 files changed, 27 insertions, 12 deletions
diff --git a/Source/Android/jni/AndroidCommon/AndroidCommon.cpp b/Source/Android/jni/AndroidCommon/AndroidCommon.cpp
index 887ae4deab..310db6b1f7 100644
--- a/Source/Android/jni/AndroidCommon/AndroidCommon.cpp
+++ b/Source/Android/jni/AndroidCommon/AndroidCommon.cpp
@@ -10,6 +10,7 @@
#include <jni.h>
+#include "Common/Assert.h"
#include "Common/StringUtil.h"
#include "jni/AndroidCommon/IDCache.h"
@@ -42,21 +43,35 @@ std::vector<std::string> JStringArrayToVector(JNIEnv* env, jobjectArray array)
return result;
}
+bool IsPathAndroidContent(const std::string& uri)
+{
+ return StringBeginsWith(uri, "content://");
+}
+
+std::string OpenModeToAndroid(std::string mode)
+{
+ // The 'b' specifier is not supported. Since we're on POSIX, it's fine to just skip it.
+ if (!mode.empty() && mode.back() == 'b')
+ mode.pop_back();
+
+ if (mode == "r+")
+ mode = "rw";
+ else if (mode == "w+")
+ mode = "rwt";
+ else if (mode == "a+")
+ mode = "rwa";
+ else if (mode == "a")
+ mode = "wa";
+
+ return mode;
+}
+
int OpenAndroidContent(const std::string& uri, const std::string& mode)
{
JNIEnv* env = IDCache::GetEnvForThread();
- const jint fd = env->CallStaticIntMethod(IDCache::GetContentHandlerClass(),
- IDCache::GetContentHandlerOpenFd(), ToJString(env, uri),
- ToJString(env, mode));
-
- // We can get an IllegalArgumentException when passing an invalid mode
- if (env->ExceptionCheck())
- {
- env->ExceptionDescribe();
- abort();
- }
-
- return fd;
+ return env->CallStaticIntMethod(IDCache::GetContentHandlerClass(),
+ IDCache::GetContentHandlerOpenFd(), ToJString(env, uri),
+ ToJString(env, mode));
}
bool DeleteAndroidContent(const std::string& uri)