From 5d0d5b5d97426b7234b57c431ccb05f58137a3c1 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 18 Aug 2022 16:49:02 +0200 Subject: [PATCH] Android/Context: allow type=nullptr in GetExternalFilesDir() --- src/android/Context.cxx | 7 +++---- src/android/Context.hxx | 5 ++++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/android/Context.cxx b/src/android/Context.cxx index f86f26bdf..ebeda6ec4 100644 --- a/src/android/Context.cxx +++ b/src/android/Context.cxx @@ -44,13 +44,12 @@ Context::Initialise(JNIEnv *env) noexcept } AllocatedPath -Context::GetExternalFilesDir(JNIEnv *env, const char *_type) noexcept +Context::GetExternalFilesDir(JNIEnv *env, const char *type) noexcept { assert(_type != nullptr); - Java::String type{env, _type}; - - jobject file = env->CallObjectMethod(Get(), getExternalFilesDir_method, type.Get()); + jobject file = env->CallObjectMethod(Get(), getExternalFilesDir_method, + Java::String::Optional(env, type).Get()); if (Java::DiscardException(env) || file == nullptr) return nullptr; diff --git a/src/android/Context.hxx b/src/android/Context.hxx index b771bc69a..ae451e230 100644 --- a/src/android/Context.hxx +++ b/src/android/Context.hxx @@ -36,9 +36,12 @@ public: Context(JNIEnv *env, jobject obj) noexcept :Java::GlobalObject(env, obj) {} + /** + * @param type the subdirectory name; may be nullptr + */ [[gnu::pure]] AllocatedPath GetExternalFilesDir(JNIEnv *env, - const char *type) noexcept; + const char *type=nullptr) noexcept; [[gnu::pure]] AllocatedPath GetCacheDir(JNIEnv *env) const noexcept;