android/Environment: pass JNIEnv to all functions
This commit is contained in:
parent
2efc1db6a9
commit
1f4df2a64d
@ -591,12 +591,12 @@ MainConfigured(const CommandLineOptions &options,
|
|||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
|
|
||||||
static void
|
static void
|
||||||
AndroidMain()
|
AndroidMain(JNIEnv *env)
|
||||||
{
|
{
|
||||||
CommandLineOptions options;
|
CommandLineOptions options;
|
||||||
ConfigData raw_config;
|
ConfigData raw_config;
|
||||||
|
|
||||||
const auto sdcard = Environment::getExternalStorageDirectory();
|
const auto sdcard = Environment::getExternalStorageDirectory(env);
|
||||||
if (!sdcard.IsNull()) {
|
if (!sdcard.IsNull()) {
|
||||||
const auto config_path =
|
const auto config_path =
|
||||||
sdcard / Path::FromFS("mpd.conf");
|
sdcard / Path::FromFS("mpd.conf");
|
||||||
@ -625,7 +625,7 @@ Java_org_musicpd_Bridge_run(JNIEnv *env, jclass, jobject _context, jobject _logL
|
|||||||
AtScopeExit() { delete logListener; };
|
AtScopeExit() { delete logListener; };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
AndroidMain();
|
AndroidMain(env);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
LogError(std::current_exception());
|
LogError(std::current_exception());
|
||||||
}
|
}
|
||||||
|
@ -51,10 +51,8 @@ Deinitialise(JNIEnv *env) noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
AllocatedPath
|
AllocatedPath
|
||||||
getExternalStorageDirectory() noexcept
|
getExternalStorageDirectory(JNIEnv *env) noexcept
|
||||||
{
|
{
|
||||||
JNIEnv *env = Java::GetEnv();
|
|
||||||
|
|
||||||
jobject file =
|
jobject file =
|
||||||
env->CallStaticObjectMethod(cls,
|
env->CallStaticObjectMethod(cls,
|
||||||
getExternalStorageDirectory_method);
|
getExternalStorageDirectory_method);
|
||||||
@ -65,14 +63,12 @@ getExternalStorageDirectory() noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
AllocatedPath
|
AllocatedPath
|
||||||
getExternalStoragePublicDirectory(const char *type) noexcept
|
getExternalStoragePublicDirectory(JNIEnv *env, const char *type) noexcept
|
||||||
{
|
{
|
||||||
if (getExternalStoragePublicDirectory_method == nullptr)
|
if (getExternalStoragePublicDirectory_method == nullptr)
|
||||||
/* needs API level 8 */
|
/* needs API level 8 */
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
JNIEnv *env = Java::GetEnv();
|
|
||||||
|
|
||||||
Java::String type2(env, type);
|
Java::String type2(env, type);
|
||||||
jobject file = env->CallStaticObjectMethod(cls,
|
jobject file = env->CallStaticObjectMethod(cls,
|
||||||
getExternalStoragePublicDirectory_method,
|
getExternalStoragePublicDirectory_method,
|
||||||
|
@ -36,10 +36,10 @@ Deinitialise(JNIEnv *env) noexcept;
|
|||||||
*/
|
*/
|
||||||
[[gnu::pure]]
|
[[gnu::pure]]
|
||||||
AllocatedPath
|
AllocatedPath
|
||||||
getExternalStorageDirectory() noexcept;
|
getExternalStorageDirectory(JNIEnv *env) noexcept;
|
||||||
|
|
||||||
[[gnu::pure]]
|
[[gnu::pure]]
|
||||||
AllocatedPath
|
AllocatedPath
|
||||||
getExternalStoragePublicDirectory(const char *type) noexcept;
|
getExternalStoragePublicDirectory(JNIEnv *env, const char *type) noexcept;
|
||||||
|
|
||||||
} // namespace Environment
|
} // namespace Environment
|
||||||
|
@ -254,7 +254,8 @@ GetUserMusicDir() noexcept
|
|||||||
#elif defined(USE_XDG)
|
#elif defined(USE_XDG)
|
||||||
return GetUserDir("XDG_MUSIC_DIR");
|
return GetUserDir("XDG_MUSIC_DIR");
|
||||||
#elif defined(ANDROID)
|
#elif defined(ANDROID)
|
||||||
return Environment::getExternalStoragePublicDirectory("Music");
|
return Environment::getExternalStoragePublicDirectory(Java::GetEnv(),
|
||||||
|
"Music");
|
||||||
#else
|
#else
|
||||||
return nullptr;
|
return nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user