Skip to content
Snippets Groups Projects
Commit d91a066c authored by Adrien Béraud's avatar Adrien Béraud Committed by gerrit2
Browse files

android: add signal to retreive cache/data paths

The API to get data/cache paths are Java only.
Currently  we need to access files and cache paths but the design
keeps the possibility to access other paths using the name signal.

Refs #75320

Change-Id: Ic691f0b5073b8d5fa437e3aea64ad1ec9a19ac09
parent 74622d16
No related branches found
No related tags found
No related merge requests found
......@@ -79,6 +79,7 @@ getSignalHandlers()
exported_callback<DRing::ConfigurationSignal::Error>(),
#ifdef __ANDROID__
exported_callback<DRing::ConfigurationSignal::GetHardwareAudioFormat>(),
exported_callback<DRing::ConfigurationSignal::GetAppDataPath>(),
#endif
/* Presence */
......
......@@ -210,10 +210,18 @@ struct ConfigurationSignal {
using cb_type = void(const std::string& /*account_id*/, const std::string& /*certId*/, const std::string& /*state*/);
};
#ifdef __ANDROID__
/**
* These are special getters for Android so the daemon can retreive
* some informations only accessible through Java APIs
*/
struct GetHardwareAudioFormat {
constexpr static const char* name = "GetHardwareAudioFormat";
using cb_type = void(std::vector<int32_t>* /* params_ret */);
};
struct GetAppDataPath {
constexpr static const char* name = "GetAppDataPath";
using cb_type = void(const std::string& name, std::vector<std::string>* /* path_ret */);
};
#endif
};
......
......@@ -39,6 +39,10 @@
#include "logger.h"
#include "intrin.h"
#ifdef __ANDROID__
#include "client/ring_signal.h"
#endif
#include <sys/types.h>
#include <sys/stat.h>
......@@ -90,22 +94,6 @@ bool check_dir(const char *path)
return true;
}
#ifdef __ANDROID__
static char *program_dir = "/data/data/cx.ring";
#else
static char *program_dir = NULL;
#endif
void set_program_dir(char *program_path)
{
program_dir = dirname(program_path);
}
const char *get_program_dir()
{
return program_dir;
}
#ifndef _WIN32
/* Lock a file region */
static int
......@@ -322,6 +310,18 @@ FileHandle::~FileHandle()
}
}
#ifdef __ANDROID__
static std::string files_path;
static std::string cache_path;
static std::string config_path;
#else
static char *program_dir = NULL;
void set_program_dir(char *program_path)
{
program_dir = dirname(program_path);
}
#endif
std::string
get_cache_dir()
{
......@@ -331,7 +331,11 @@ get_cache_dir()
return cache_home;
} else {
#ifdef __ANDROID__
return get_home_dir() + DIR_SEPARATOR_STR + PACKAGE;
std::vector<std::string> paths;
emitSignal<DRing::ConfigurationSignal::GetAppDataPath>("cache", &paths);
if (not paths.empty())
cache_path = paths[0];
return cache_path;
#elif defined(__APPLE__)
return get_home_dir() + DIR_SEPARATOR_STR
+ "Library" + DIR_SEPARATOR_STR + "Caches"
......@@ -347,7 +351,11 @@ std::string
get_home_dir()
{
#if defined __ANDROID__
return get_program_dir();
std::vector<std::string> paths;
emitSignal<DRing::ConfigurationSignal::GetAppDataPath>("files", &paths);
if (not paths.empty())
files_path = paths[0];
return files_path;
#elif defined _WIN32
WCHAR path[MAX_PATH];
if (SUCCEEDED(SHGetFolderPathW(nullptr, CSIDL_PROFILE, nullptr, 0, path))) {
......@@ -356,7 +364,7 @@ get_home_dir()
WideCharToMultiByte(CP_ACP, 0, path, -1, tmp, MAX_PATH, &DefChar, nullptr);
return std::string(tmp);
}
return get_program_dir();
return program_dir;
#else
// 1) try getting user's home directory from the environment
......@@ -381,7 +389,11 @@ std::string
get_data_dir()
{
#ifdef __ANDROID__
return get_program_dir();
std::vector<std::string> paths;
emitSignal<DRing::ConfigurationSignal::GetAppDataPath>("files", &paths);
if (not paths.empty())
files_path = paths[0];
return files_path;
#elif defined(__APPLE__)
return get_home_dir() + DIR_SEPARATOR_STR
+ "Library" + DIR_SEPARATOR_STR + "Application Support"
......@@ -397,6 +409,42 @@ get_data_dir()
#endif
}
std::string
get_config_dir()
{
#ifdef __ANDROID__
std::vector<std::string> paths;
emitSignal<DRing::ConfigurationSignal::GetAppDataPath>("config", &paths);
if (not paths.empty())
config_path = paths[0];
return config_path;
#else
#ifdef __APPLE__
std::string configdir = fileutils::get_home_dir() + DIR_SEPARATOR_STR
+ "Library" + DIR_SEPARATOR_STR + "Application Support"
+ DIR_SEPARATOR_STR + PACKAGE;
#else
std::string configdir = fileutils::get_home_dir() + DIR_SEPARATOR_STR +
".config" + DIR_SEPARATOR_STR + PACKAGE;
#endif
const std::string xdg_env(XDG_CONFIG_HOME);
if (not xdg_env.empty())
configdir = xdg_env + DIR_SEPARATOR_STR + PACKAGE;
#ifndef _WIN32
if (mkdir(configdir.data(), 0700) != 0) {
#else
if (fileutils::recursive_mkdir(configdir.data()) != true) {
#endif
// If directory creation failed
if (errno != EEXIST)
RING_DBG("Cannot create directory: %s!", configdir.c_str());
}
return configdir;
#endif
}
#ifdef _WIN32
bool
recursive_mkdir(const std::string& path)
......
......@@ -54,12 +54,12 @@
namespace ring { namespace fileutils {
std::string get_data_dir();
std::string get_home_dir();
std::string get_config_dir();
std::string get_data_dir();
std::string get_cache_dir();
bool check_dir(const char *path);
void set_program_dir(char *program_path);
const char *get_program_dir();
std::string expand_path(const std::string &path);
bool isDirectoryWritable(const std::string &directory);
......
......@@ -2017,33 +2017,8 @@ Manager::getTelephoneFile()
std::string
Manager::retrieveConfigPath() const
{
#ifdef __ANDROID__
std::string configdir = "/data/data/cx.ring";
#elif __APPLE__
std::string configdir = fileutils::get_home_dir() + DIR_SEPARATOR_STR
+ "Library" + DIR_SEPARATOR_STR + "Application Support"
+ DIR_SEPARATOR_STR + PACKAGE;
#else
std::string configdir = fileutils::get_home_dir() + DIR_SEPARATOR_STR +
".config" + DIR_SEPARATOR_STR + PACKAGE;
#endif
const std::string xdg_env(XDG_CONFIG_HOME);
if (not xdg_env.empty())
configdir = xdg_env + DIR_SEPARATOR_STR + PACKAGE;
#ifndef _WIN32
if (mkdir(configdir.data(), 0700) != 0) {
#else
if (fileutils::recursive_mkdir(configdir.data()) != true) {
#endif
// If directory creation failed
if (errno != EEXIST)
RING_DBG("Cannot create directory: %s!", configdir.c_str());
}
static const char * const PROGNAME = "dring";
return configdir + DIR_SEPARATOR_STR + PROGNAME + ".yml";
return fileutils::get_config_dir() + DIR_SEPARATOR_STR + PROGNAME + ".yml";
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment