diff options
author | Max Kellermann <max@duempel.org> | 2014-03-01 20:20:29 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-03-01 22:20:28 +0100 |
commit | b8f1850bba98685e978025041e495198627b57f5 (patch) | |
tree | a406368074249d77e84572a4f228ea1fcfd19104 /src/db | |
parent | 5268f55344229f70e3565f63671eb582eaff733f (diff) |
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().
Diffstat (limited to 'src/db')
-rw-r--r-- | src/db/Configured.cxx | 26 |
1 files changed, 25 insertions, 1 deletions
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); |