mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-01 18:56:23 -04:00
Merge pull request #2517 from G10h4ck/android_without_qt
Run on Android without Qt
This commit is contained in:
commit
e55fa2b9d5
38 changed files with 1108 additions and 359 deletions
|
@ -32,12 +32,12 @@
|
|||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <system_error>
|
||||
#include <iostream>
|
||||
|
||||
#include "retroshare/rsinit.h"
|
||||
#include "rsaccounts.h"
|
||||
|
||||
#include "util/rsdebug.h"
|
||||
#include "util/rsdir.h"
|
||||
#include "util/rsstring.h"
|
||||
#include "util/folderiterator.h"
|
||||
|
@ -48,6 +48,11 @@
|
|||
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
#ifdef __ANDROID__
|
||||
# include "rs_android/rsjni.hpp"
|
||||
# include "rs_android/retroshareserviceandroid.hpp"
|
||||
#endif
|
||||
|
||||
// Global singleton declaration of data.
|
||||
RsAccountsDetail* RsAccounts::rsAccountsDetails = nullptr;
|
||||
|
||||
|
@ -328,22 +333,7 @@ bool RsAccountsDetail::defaultBaseDirectory()
|
|||
{
|
||||
std::string basedir;
|
||||
|
||||
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
#ifndef WINDOWS_SYS
|
||||
|
||||
// unix: homedir + /.retroshare
|
||||
char *h = getenv("HOME");
|
||||
if (h == NULL)
|
||||
{
|
||||
std::cerr << "defaultBaseDirectory() Error: cannot determine $HOME dir"
|
||||
<< std::endl;
|
||||
return false ;
|
||||
}
|
||||
|
||||
basedir = h;
|
||||
basedir += "/.retroshare";
|
||||
|
||||
#else
|
||||
#ifdef WINDOWS_SYS
|
||||
if (RsInit::isPortable())
|
||||
{
|
||||
// use directory "Data" in portable version
|
||||
|
@ -375,13 +365,53 @@ bool RsAccountsDetail::defaultBaseDirectory()
|
|||
}
|
||||
basedir += "\\RetroShare";
|
||||
}
|
||||
#endif
|
||||
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
#elif defined (__ANDROID__) // def WINDOWS_SYS
|
||||
|
||||
struct ApplicationInfo
|
||||
{
|
||||
static constexpr auto Name()
|
||||
{ return "android/content/pm/ApplicationInfo"; }
|
||||
};
|
||||
|
||||
auto uenv = jni::GetAttachedEnv(RsJni::getVM());
|
||||
JNIEnv& env = *uenv;
|
||||
auto androidContext = RetroShareServiceAndroid::getAndroidContext(env);
|
||||
auto& contextClass =
|
||||
jni::Class<RetroShareServiceAndroid::Context>::Singleton(env);
|
||||
|
||||
auto& applicationInfoClass = jni::Class<ApplicationInfo>::Singleton(env);
|
||||
|
||||
auto getApplicationInfo =
|
||||
contextClass.GetMethod<jni::Object<ApplicationInfo> ()>(
|
||||
env, "getApplicationInfo" );
|
||||
|
||||
auto applicationInfo = androidContext.Call(env, getApplicationInfo);
|
||||
|
||||
auto dataDirField = jni::Field<ApplicationInfo, jni::String>(
|
||||
env, applicationInfoClass, "dataDir" );
|
||||
|
||||
jni::Local<jni::String> dataDir = applicationInfo.Get<jni::String>(
|
||||
env, dataDirField );
|
||||
|
||||
basedir = jni::Make<std::string>(env, dataDir) + "/.retroshare/";
|
||||
|
||||
#else // def WINDOWS_SYS, if defined (__ANDROID__)
|
||||
// unix: homedir + /.retroshare
|
||||
char* h = getenv("HOME");
|
||||
if(h == nullptr)
|
||||
{
|
||||
RS_ERR("cannot determine $HOME dir");
|
||||
return false ;
|
||||
}
|
||||
|
||||
basedir = h;
|
||||
basedir += "/.retroshare";
|
||||
#endif // def WINDOWS_SYS
|
||||
|
||||
/* store to class variable */
|
||||
mBaseDirectory = basedir;
|
||||
std::cerr << "defaultBaseDirectory() = " << mBaseDirectory;
|
||||
std::cerr << std::endl;
|
||||
|
||||
RS_INFO(mBaseDirectory);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -941,6 +971,11 @@ bool RsAccountsDetail::exportIdentityToString(
|
|||
|
||||
bool RsAccountsDetail::copyGnuPGKeyrings()
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
RS_ERR(std::errc::not_supported);
|
||||
print_stacktrace();
|
||||
return false;
|
||||
#else
|
||||
std::string pgp_dir = PathPGPDirectory() ;
|
||||
|
||||
if(!RsDirUtil::checkCreateDirectory(pgp_dir))
|
||||
|
@ -992,6 +1027,7 @@ bool RsAccountsDetail::copyGnuPGKeyrings()
|
|||
}
|
||||
|
||||
return true ;
|
||||
#endif // def __ANDROID__
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -32,8 +32,9 @@
|
|||
#endif
|
||||
|
||||
#ifdef __ANDROID__
|
||||
# include <QFile> // To install bdboot.txt
|
||||
# include <QString> // for QString::fromStdString(...)
|
||||
# include <jni/jni.hpp>
|
||||
# include "rs_android/rsjni.hpp"
|
||||
# include "rs_android/retroshareserviceandroid.hpp"
|
||||
#endif
|
||||
|
||||
#include "util/argstream.h"
|
||||
|
@ -194,7 +195,7 @@ static const int SSLPWD_LEN = 64;
|
|||
|
||||
void RsInit::InitRsConfig()
|
||||
{
|
||||
RsInfo() << " libretroshare version: " << RS_HUMAN_READABLE_VERSION
|
||||
RsInfo() << "libretroshare version: " << RS_HUMAN_READABLE_VERSION
|
||||
<< std::endl;
|
||||
|
||||
rsInitConfig = new RsInitConfig;
|
||||
|
@ -1011,32 +1012,32 @@ int RsServer::StartupRetroShare()
|
|||
uint64_t tmp_size ;
|
||||
if (!RsDirUtil::checkFile(bootstrapfile,tmp_size,true))
|
||||
{
|
||||
std::cerr << "DHT bootstrap file not in ConfigDir: " << bootstrapfile
|
||||
<< std::endl;
|
||||
#ifdef __ANDROID__
|
||||
QFile bdbootRF("assets:/values/bdboot.txt");
|
||||
if(!bdbootRF.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
std::cerr << __PRETTY_FUNCTION__
|
||||
<< " bdbootRF(assets:/values/bdboot.txt).open(...) fail: "
|
||||
<< bdbootRF.errorString().toStdString() << std::endl;
|
||||
else
|
||||
{
|
||||
QFile bdbootCF(QString::fromStdString(bootstrapfile));
|
||||
if(!bdbootCF.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
std::cerr << __PRETTY_FUNCTION__ << " bdbootCF("
|
||||
<< bootstrapfile << ").open(...) fail: "
|
||||
<< bdbootRF.errorString().toStdString() << std::endl;
|
||||
else
|
||||
{
|
||||
bdbootCF.write(bdbootRF.readAll());
|
||||
bdbootCF.close();
|
||||
std::cerr << "Installed DHT bootstrap file not in ConfigDir: "
|
||||
<< bootstrapfile << std::endl;
|
||||
}
|
||||
RS_INFO("DHT bootstrap file not in ConfigDir: ", bootstrapfile);
|
||||
|
||||
bdbootRF.close();
|
||||
}
|
||||
#else
|
||||
#ifdef __ANDROID__
|
||||
auto uenv = jni::GetAttachedEnv(RsJni::getVM());
|
||||
JNIEnv& env = *uenv;
|
||||
|
||||
using AContext = RetroShareServiceAndroid::Context;
|
||||
|
||||
auto& assetHelperClass = jni::Class<RsJni::AssetHelper>::Singleton(env);
|
||||
|
||||
static auto copyAsset =
|
||||
assetHelperClass.GetStaticMethod<
|
||||
jni::jboolean(jni::Object<AContext>, jni::String, jni::String)>(
|
||||
env, "copyAsset" );
|
||||
|
||||
auto androidContext = RetroShareServiceAndroid::getAndroidContext(env);
|
||||
|
||||
jni::jboolean result = assetHelperClass.Call(
|
||||
env, copyAsset,
|
||||
androidContext,
|
||||
jni::Make<jni::String>(env, "values/bdboot.txt"),
|
||||
jni::Make<jni::String>(env, bootstrapfile) );
|
||||
|
||||
if(!result) RS_ERR("Failure installing ", bootstrapfile);
|
||||
|
||||
#else // def __ANDROID__
|
||||
std::cerr << "Checking for Installation DHT bootstrap file " << installfile << std::endl;
|
||||
if ((installfile != "") && (RsDirUtil::checkFile(installfile,tmp_size)))
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue