Android: Add content provider support to File::IOFile

Taking the hit now to prepare us for when Google Play will
force us to use scoped storage...
This commit is contained in:
JosJuice 2020-06-26 17:52:31 +02:00
parent d9f3e382fe
commit 6e1e6d2311
10 changed files with 114 additions and 5 deletions

View file

@ -11,6 +11,7 @@
#include <jni.h>
#include "Common/StringUtil.h"
#include "jni/AndroidCommon/IDCache.h"
std::string GetJString(JNIEnv* env, jstring jstr)
{
@ -40,3 +41,20 @@ std::vector<std::string> JStringArrayToVector(JNIEnv* env, jobjectArray array)
return result;
}
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;
}