From b8f1850bba98685e978025041e495198627b57f5 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 1 Mar 2014 20:20:29 +0100 Subject: db/Configured: store database file in cache directory Add class Context which wraps the Android/Java Context class and add a JNI wrapper for method Context.getCacheDir(). --- src/db/Configured.cxx | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/db') diff --git a/src/db/Configured.cxx b/src/db/Configured.cxx index 14471402a..78be3e999 100644 --- a/src/db/Configured.cxx +++ b/src/db/Configured.cxx @@ -26,6 +26,13 @@ #include "util/Error.hxx" #include "Log.hxx" +#ifdef ANDROID +#include "Main.hxx" +#include "android/Context.hxx" +#include "fs/AllocatedPath.hxx" +#include "plugins/simple/SimpleDatabasePlugin.hxx" +#endif + Database * CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener, Error &error) @@ -49,8 +56,25 @@ CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener, param = allocated; } - if (param == nullptr) + if (param == nullptr) { +#ifdef ANDROID + /* if there is no override, use the Android cache + directory */ + + const AllocatedPath cache_dir = + context->GetCacheDir(Java::GetEnv()); + if (cache_dir.IsNull()) + return nullptr; + + const auto db_file = AllocatedPath::Build(cache_dir, "mpd.db"); + + allocated = new config_param("database"); + allocated->AddBlockParam("path", db_file.c_str(), -1); + param = allocated; +#else return nullptr; +#endif + } Database *db = DatabaseGlobalInit(loop, listener, *param, error); -- cgit v1.2.3