aboutsummaryrefslogtreecommitdiffstats
path: root/src/android/Environment.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-03-01 20:53:39 +0100
committerMax Kellermann <max@duempel.org>2014-03-01 20:53:39 +0100
commit5268f55344229f70e3565f63671eb582eaff733f (patch)
treef16f39a0847ea56b03db8892c3368251e4f2b3bf /src/android/Environment.cxx
parente44c9a000d477ba9fd24bd77ab4b529001dd3bde (diff)
downloadmpd-5268f55344229f70e3565f63671eb582eaff733f.tar.gz
mpd-5268f55344229f70e3565f63671eb582eaff733f.tar.xz
mpd-5268f55344229f70e3565f63671eb582eaff733f.zip
java/File: add method ToAbsolutePath() returning AllocatedPath
Diffstat (limited to 'src/android/Environment.cxx')
-rw-r--r--src/android/Environment.cxx66
1 files changed, 19 insertions, 47 deletions
diff --git a/src/android/Environment.cxx b/src/android/Environment.cxx
index 7cebb57ca..9813b0b79 100644
--- a/src/android/Environment.cxx
+++ b/src/android/Environment.cxx
@@ -17,18 +17,18 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "config.h"
#include "Environment.hxx"
#include "java/Class.hxx"
#include "java/String.hxx"
#include "java/File.hxx"
#include "util/StringUtil.hxx"
+#include "fs/AllocatedPath.hxx"
namespace Environment {
static Java::TrivialClass cls;
static jmethodID getExternalStorageDirectory_method;
static jmethodID getExternalStoragePublicDirectory_method;
-
- static jstring getExternalStorageDirectory(JNIEnv *env);
};
void
@@ -51,63 +51,35 @@ Environment::Deinitialise(JNIEnv *env)
cls.Clear(env);
}
-static jstring
-ToAbsolutePathChecked(JNIEnv *env, jobject file)
-{
- if (file == nullptr)
- return nullptr;
-
- jstring path = Java::File::getAbsolutePath(env, file);
- env->DeleteLocalRef(file);
- return path;
-}
-
-static jstring
-Environment::getExternalStorageDirectory(JNIEnv *env)
-{
- jobject file = env->CallStaticObjectMethod(cls,
- getExternalStorageDirectory_method);
- return ToAbsolutePathChecked(env, file);
-}
-
-char *
-Environment::getExternalStorageDirectory(char *buffer, size_t max_size)
+AllocatedPath
+Environment::getExternalStorageDirectory()
{
JNIEnv *env = Java::GetEnv();
- jstring value = getExternalStorageDirectory(env);
- if (value == nullptr)
- return nullptr;
+ jobject file =
+ env->CallStaticObjectMethod(cls,
+ getExternalStorageDirectory_method);
+ if (file == nullptr)
+ return AllocatedPath::Null();
- Java::String value2(env, value);
- value2.CopyTo(env, buffer, max_size);
- return buffer;
+ return Java::File::ToAbsolutePath(env, file);
}
-static jstring
-getExternalStoragePublicDirectory(JNIEnv *env, const char *type)
+AllocatedPath
+Environment::getExternalStoragePublicDirectory(const char *type)
{
- if (Environment::getExternalStoragePublicDirectory_method == nullptr)
+ if (getExternalStoragePublicDirectory_method == nullptr)
/* needs API level 8 */
- return nullptr;
+ return AllocatedPath::Null();
+
+ JNIEnv *env = Java::GetEnv();
Java::String type2(env, type);
jobject file = env->CallStaticObjectMethod(Environment::cls,
Environment::getExternalStoragePublicDirectory_method,
type2.Get());
- return ToAbsolutePathChecked(env, file);
-}
-
-char *
-Environment::getExternalStoragePublicDirectory(char *buffer, size_t max_size,
- const char *type)
-{
- JNIEnv *env = Java::GetEnv();
- jstring path = ::getExternalStoragePublicDirectory(env, type);
- if (path == nullptr)
- return nullptr;
+ if (file == nullptr)
+ return AllocatedPath::Null();
- Java::String path2(env, path);
- path2.CopyTo(env, buffer, max_size);
- return buffer;
+ return Java::File::ToAbsolutePath(env, file);
}