Merge pull request #1160 from G10h4ck/android_service_cleaning

Multiple fixes for Android
This commit is contained in:
csoler 2018-01-30 20:55:01 +01:00 committed by GitHub
commit 1e3d2c2c9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 263 additions and 142 deletions

View File

@ -46,6 +46,7 @@ export HOST_NUM_CPU=1
./android-prepare-toolchain.sh ./android-prepare-toolchain.sh
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
== Preparing Qt Creator == Preparing Qt Creator
Now that your environement is set up you should configure Qt Creator for Android Now that your environement is set up you should configure Qt Creator for Android
@ -81,20 +82,13 @@ and add the following configurations
CONFIG+=no_retroshare_gui CONFIG+=no_retroshare_nogui CONFIG+=no_retroshare_plugins CONFIG+=retroshare_android_service CONFIG+=libresapilocalserver CONFIG+=no_libresapihttpserver CONFIG+=retroshare_qml_app CONFIG+=no_retroshare_gui CONFIG+=no_retroshare_nogui CONFIG+=no_retroshare_plugins CONFIG+=retroshare_android_service CONFIG+=libresapilocalserver CONFIG+=no_libresapihttpserver CONFIG+=retroshare_qml_app
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
WARNING: SQLCipher is not supported yet on RetroShare for Android. This poses a TIP: Some versions of QtCreator try to find the Android SDK in
major security concern, we are working to fix this ASAP.
WARNING: DHT is not supported yet on RetroShare for Android. So don't be
surprised if you are not able to connect to dynamic IP trusted nodes after not
using the app for a relatively long time. Once this happens getting a fresh
certificate link from your friends should work around the issue.
WARNING: Some versions of QtCreator try to find the Android SDK in
+/opt/android/sdk+. A workaround to this is to make a symbolic link there +/opt/android/sdk+. A workaround to this is to make a symbolic link there
pointing to your SDK installation path, like pointing to your SDK installation path, like
+mkdir -p /opt/android/sdk && ln -s /home/user/android-sdk-linux +mkdir -p /opt/android/sdk && ln -s /home/user/android-sdk-linux
/opt/android/sdk+ /opt/android/sdk+
== Quircks == Quircks
On some Android devices like +Huawei ALE-L21+ background applications are On some Android devices like +Huawei ALE-L21+ background applications are
@ -111,12 +105,26 @@ To enable enable _protection_: +Android menu -> Settings -> Privacy & security
Other devices may offer similar _features_ please report them. Other devices may offer similar _features_ please report them.
== Debugging with GDB == Debugging with GDB
QtCreator actually support debugging only for the foreground activity, so to QtCreator actually support debugging only for the foreground activity, so to
debug what's happening in the core extra trickery is needed. debug what's happening in the core extra trickery is needed.
First of all you need to authorize root access to applications, then once you
plug your sacrifical Android phone run this commands - Run the App in Debug mode from QtCreator "Start Debugging" button
- Enable QtCreator debugger console view Menu->Window->Debugger Log
- Run +show solib-search-path+ in the QtCreator GDB console
- Take note of the output you get in the right pane of the console
- Thanks https://stackoverflow.com/a/31164313 for the idea
TIP: QtCreator GDB console seems a bit buggy and easly trigger timeout
message when a command is run, in that case attempt to run the command while the
debugging is paused or at breakpoint, or with other similar tricks.
CAUTION: Following steps require root access on your Android device
Now on your phone yuo need to authorize root access to applications, then once
you plug your sacrifical Android phone run this commands
.Run gdbserver as root on Android phone .Run gdbserver as root on Android phone
[source,bash] [source,bash]
@ -124,37 +132,42 @@ plug your sacrifical Android phone run this commands
## Open a shell from your workstation on the connected Android phone ## Open a shell from your workstation on the connected Android phone
adb shell adb shell
## take note of the PID of the RetroShare process ## take the note of the phone IP address
ps | grep retroshare
## take the note of the phone IP
ip address show ip address show
## Gain root permissions on the shell ## Gain root permissions on the shell
su su
## Attach with gdbserver and listen on one TCP port ## Attach with gdbserver and listen on one TCP port
gdbserver :4567 --attach $RETROSHARE_PID gdbserver :4567 --attach $(pgrep org.retroshare.android.qml_app:rs)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
.Prepare and run Android NDK GDB on your workstation .Prepare and run Android NDK GDB on your workstation
[source,bash] [source,bash]
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
## Extract system lib from the phone to a temporary directory on your computer ## Setup some convenience variables
adb pull /system/lib /tmp/system_lib NDK_GDB="${ANDROID_NDK_PATH}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gdb"
RS_BUILD_PATH="${HOME}/Builds/RetroShare-Android_for_armeabi_v7a_GCC_4_9_Qt_5_9_2_android_armv7-Debug/"
## Start Android NDK GDB of your phone architecture passing the executable ## Start Android NDK GDB of your phone architecture passing the executable
/opt/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gdb RetroShare-Android_for_armeabi_v7a_GCC_4_9_Qt_5_9_2_android_armv7-Debug/retroshare-android-service/src/libretroshare-android-service.so $NDK_GDB $RS_BUILD_PATH/retroshare-android-service/src/libretroshare-android-service.so
## Instruct GDB how and where to find libraries ## Instruct GDB how and where to find debugging symbols
(gdb) set auto-solib-add on (gdb) set auto-solib-add on
(gdb) set solib-search-path /tmp/system_lib (gdb) set solib-search-path THE:BIG:LIST:OF:DIRECTORIES:YOU:TAKE:NOTE:BEFORE
## Connect to the gdbserver running on the phone ## Connect to the gdbserver running on the phone
(gdb) target remote $PHONE_IP:4567 (gdb) target remote $PHONE_IP:4567
## Have fun debugging
(gdb)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
TIP: Some time WiFi power saving on Android mess with the GDB connection,
to prevent that from appening open another +adb shell+ and live +ping+ toward
your work-station running
== Furter Readings == Furter Readings
@ -167,3 +180,5 @@ adb pull /system/lib /tmp/system_lib
- link:https://tthtlc.wordpress.com/2012/09/19/how-to-do-remote-debugging-via-gdbserver-running-inside-the-android-phone/[] - link:https://tthtlc.wordpress.com/2012/09/19/how-to-do-remote-debugging-via-gdbserver-running-inside-the-android-phone/[]
- link:https://source.android.com/devices/tech/debug/[] - link:https://source.android.com/devices/tech/debug/[]
- link:https://source.android.com/devices/tech/debug/gdb[] - link:https://source.android.com/devices/tech/debug/gdb[]
- link:https://fw4spl-org.github.io/fw4spl-blog/2015/07/27/Native-debugging-on-Android-with-QtCreator.html[]
- link:https://fragglet.livejournal.com/19646.html[]

View File

@ -6,9 +6,14 @@
[ -z ${ANDROID_NDK_ABI_VER+x} ] && export ANDROID_NDK_ABI_VER="4.9" [ -z ${ANDROID_NDK_ABI_VER+x} ] && export ANDROID_NDK_ABI_VER="4.9"
[ -z ${ANDROID_PLATFORM_VER+x} ] && export ANDROID_PLATFORM_VER="18" [ -z ${ANDROID_PLATFORM_VER+x} ] && export ANDROID_PLATFORM_VER="18"
[ -z ${NDK_TOOLCHAIN_PATH+x} ] && export NDK_TOOLCHAIN_PATH="${HOME}/Builds/android-toolchains/retroshare-android-${ANDROID_PLATFORM_VER}-${ANDROID_NDK_ARCH}-abi${ANDROID_NDK_ABI_VER}/" [ -z ${NDK_TOOLCHAIN_PATH+x} ] && export NDK_TOOLCHAIN_PATH="${HOME}/Builds/android-toolchains/retroshare-android-${ANDROID_PLATFORM_VER}-${ANDROID_NDK_ARCH}-abi${ANDROID_NDK_ABI_VER}/"
[ -z ${HOST_NUM_CPU+x} ] && export HOST_NUM_CPU=4 [ -z ${HOST_NUM_CPU+x} ] && export HOST_NUM_CPU=$(grep "^processor" /proc/cpuinfo | wc -l)
[ -z ${BZIP2_SOURCE_VERSION+x} ] && export BZIP2_SOURCE_VERSION="1.0.6"
[ -z ${OPENSSL_SOURCE_VERSION+x} ] && export OPENSSL_SOURCE_VERSION="1.0.2n"
[ -z ${SQLITE_SOURCE_YEAR+x} ] && export SQLITE_SOURCE_YEAR="2018"
[ -z ${SQLITE_SOURCE_VERSION+x} ] && export SQLITE_SOURCE_VERSION="3220000"
[ -z ${SQLCIPHER_SOURCE_VERSION+x} ] && export SQLCIPHER_SOURCE_VERSION="3.4.2"
[ -z ${LIBUPNP_SOURCE_VERSION+x} ] && export LIBUPNP_SOURCE_VERSION="1.6.24"
runDir="$(pwd)"
## You should not edit the following variables ## You should not edit the following variables
if [ "${ANDROID_NDK_ARCH}" == "x86" ]; then if [ "${ANDROID_NDK_ARCH}" == "x86" ]; then
@ -38,9 +43,9 @@ build_toolchain()
## More information available at retroshare://file?name=Android%20Native%20Development%20Kit%20Cookbook.pdf&size=29214468&hash=0123361c1b14366ce36118e82b90faf7c7b1b136 ## More information available at retroshare://file?name=Android%20Native%20Development%20Kit%20Cookbook.pdf&size=29214468&hash=0123361c1b14366ce36118e82b90faf7c7b1b136
build_bzlib() build_bzlib()
{ {
B_dir="bzip2-1.0.6" B_dir="bzip2-${BZIP2_SOURCE_VERSION}"
rm -rf $B_dir rm -rf $B_dir
[ -f $B_dir.tar.gz ] || wget http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz [ -f $B_dir.tar.gz ] || wget http://www.bzip.org/${BZIP2_SOURCE_VERSION}/bzip2-${BZIP2_SOURCE_VERSION}.tar.gz
tar -xf $B_dir.tar.gz tar -xf $B_dir.tar.gz
cd $B_dir cd $B_dir
sed -i "/^CC=.*/d" Makefile sed -i "/^CC=.*/d" Makefile
@ -59,7 +64,7 @@ build_bzlib()
## More information available at http://doc.qt.io/qt-5/opensslsupport.html ## More information available at http://doc.qt.io/qt-5/opensslsupport.html
build_openssl() build_openssl()
{ {
B_dir="openssl-1.0.2h" B_dir="openssl-${OPENSSL_SOURCE_VERSION}"
rm -rf $B_dir rm -rf $B_dir
[ -f $B_dir.tar.gz ] || wget https://www.openssl.org/source/$B_dir.tar.gz [ -f $B_dir.tar.gz ] || wget https://www.openssl.org/source/$B_dir.tar.gz
tar -xf $B_dir.tar.gz tar -xf $B_dir.tar.gz
@ -86,8 +91,8 @@ build_openssl()
build_sqlite() build_sqlite()
{ {
B_dir="sqlite-autoconf-3130000" B_dir="sqlite-autoconf-${SQLITE_SOURCE_VERSION}"
[ -f $B_dir.tar.gz ] || wget https://www.sqlite.org/2016/$B_dir.tar.gz [ -f $B_dir.tar.gz ] || wget https://www.sqlite.org/${SQLITE_SOURCE_YEAR}/$B_dir.tar.gz
tar -xf $B_dir.tar.gz tar -xf $B_dir.tar.gz
cd $B_dir cd $B_dir
./configure --prefix="${SYSROOT}/usr" --host=${ANDROID_NDK_ARCH}-linux ./configure --prefix="${SYSROOT}/usr" --host=${ANDROID_NDK_ARCH}-linux
@ -101,11 +106,18 @@ build_sqlite()
build_sqlcipher() build_sqlcipher()
{ {
echo "sqlcipher not supported yet on android" B_dir="sqlcipher-${SQLCIPHER_SOURCE_VERSION}"
return 0 T_file="${B_dir}.tar.gz"
[ -f $T_file ] || wget -O $T_file https://github.com/sqlcipher/sqlcipher/archive/v${SQLCIPHER_SOURCE_VERSION}.tar.gz
cd sqlcipher rm -rf $B_dir
./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="${SYSROOT}/usr/lib/libcrypto.a" tar -xf $T_file
cd $B_dir
./configure --build=$(sh ./config.guess) \
--host=${ANDROID_NDK_ARCH}-linux \
--prefix="${SYSROOT}/usr" --with-sysroot="${SYSROOT}" \
--enable-tempstore=yes \
--disable-tcl --disable-shared \
CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="${SYSROOT}/usr/lib/libcrypto.a"
make -j${HOST_NUM_CPU} make -j${HOST_NUM_CPU}
make install make install
cd .. cd ..
@ -113,9 +125,9 @@ build_sqlcipher()
build_libupnp() build_libupnp()
{ {
B_dir="libupnp-1.6.20" B_dir="libupnp-${LIBUPNP_SOURCE_VERSION}"
rm -rf $B_dir rm -rf $B_dir
[ -f $B_dir.tar.bz2 ] || wget https://sourceforge.net/projects/pupnp/files/pupnp/libUPnP%201.6.20/$B_dir.tar.bz2 [ -f $B_dir.tar.bz2 ] || wget https://sourceforge.net/projects/pupnp/files/pupnp/libUPnP%20${LIBUPNP_SOURCE_VERSION}/$B_dir.tar.bz2
tar -xf $B_dir.tar.bz2 tar -xf $B_dir.tar.bz2
cd $B_dir cd $B_dir
## liupnp must be configured as static library because if not the linker will ## liupnp must be configured as static library because if not the linker will
@ -149,4 +161,7 @@ build_toolchain
build_bzlib build_bzlib
build_openssl build_openssl
build_sqlite build_sqlite
build_sqlcipher
build_libupnp build_libupnp
echo NDK_TOOLCHAIN_PATH=${NDK_TOOLCHAIN_PATH}

View File

@ -46,6 +46,12 @@ unix {
INSTALLS += data_files INSTALLS += data_files
} }
android-* {
# see https://community.kde.org/Necessitas/Assets
bdboot.files=bitdht/bdboot.txt
bdboot.path=/assets/values
INSTALLS += bdboot
}
#################### Cross compilation for windows under Linux #################### #################### Cross compilation for windows under Linux ####################

View File

@ -17,32 +17,68 @@
*/ */
#include <QStringList> #include <QStringList>
#include <QFileInfo>
#include <QDir>
#include "ApiServerLocal.h" #include "ApiServerLocal.h"
#include "JsonStream.h" #include "JsonStream.h"
namespace resource_api{ namespace resource_api{
ApiServerLocal::ApiServerLocal(ApiServer* server, const QString &listenPath, QObject *parent) : ApiServerLocal::ApiServerLocal(ApiServer* server,
const QString &listenPath, QObject *parent) :
QObject(parent), serverThread(this), QObject(parent), serverThread(this),
localListener(server, listenPath) // Must have no parent to be movable to other thread // Must have no parent to be movable to other thread
localListener(server, listenPath)
{ {
qRegisterMetaType<QAbstractSocket::SocketState>();
localListener.moveToThread(&serverThread); localListener.moveToThread(&serverThread);
serverThread.start(); serverThread.start();
} }
ApiServerLocal::~ApiServerLocal() { serverThread.quit(); } ApiServerLocal::~ApiServerLocal()
{
serverThread.quit();
serverThread.wait();
}
ApiLocalListener::ApiLocalListener(ApiServer *server, ApiLocalListener::ApiLocalListener(ApiServer *server,
const QString &listenPath, const QString &listenPath,
QObject *parent) : QObject *parent) :
QObject(parent), mApiServer(server), mLocalServer(this) QObject(parent), mApiServer(server), mLocalServer(this)
{ {
QFileInfo fileInfo(listenPath);
if(fileInfo.exists())
{
std::cerr << __PRETTY_FUNCTION__ << listenPath.toLatin1().data()
<< " already exists. "
<< "Removing it assuming it's a past crash leftover! "
<< "Are you sure another instance is not listening there?"
<< std::endl;
mLocalServer.removeServer(listenPath); mLocalServer.removeServer(listenPath);
}
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
mLocalServer.setSocketOptions(QLocalServer::UserAccessOption); mLocalServer.setSocketOptions(QLocalServer::UserAccessOption);
#endif #endif
connect(&mLocalServer, SIGNAL(newConnection()), this, SLOT(handleConnection())); connect( &mLocalServer, &QLocalServer::newConnection,
mLocalServer.listen(listenPath); this, &ApiLocalListener::handleConnection );
QDir&& lDir(fileInfo.absoluteDir());
if(!lDir.exists())
{
std::cerr << __PRETTY_FUNCTION__ << " Directory for listening socket "
<< listenPath.toLatin1().data() << " doesn't exists. "
<< " Creating it!" << std::endl;
lDir.mkpath(lDir.absolutePath());
}
if(!mLocalServer.listen(listenPath))
{
std::cerr << __PRETTY_FUNCTION__ << " mLocalServer.listen("
<< listenPath.toLatin1().data() << ") failed with: "
<< mLocalServer.errorString().toLatin1().data() << std::endl;
}
} }
void ApiLocalListener::handleConnection() void ApiLocalListener::handleConnection()
@ -62,8 +98,12 @@ ApiLocalConnectionHandler::ApiLocalConnectionHandler(
ApiLocalConnectionHandler::~ApiLocalConnectionHandler() ApiLocalConnectionHandler::~ApiLocalConnectionHandler()
{ {
mLocalSocket->close(); /* Any attempt of closing the socket here also deferred method call, causes
delete mLocalSocket; * crash when the core is asked to stop, at least from the JSON API call.
* QMetaObject::invokeMethod(&app, "close", Qt::QueuedConnection)
* mLocalSocket->disconnectFromServer()
* mLocalSocket->close() */
mLocalSocket->deleteLater();
} }
void ApiLocalConnectionHandler::handlePendingRequests() void ApiLocalConnectionHandler::handlePendingRequests()

View File

@ -1045,7 +1045,8 @@ ResponseTask* ChatHandler::handleLobbyParticipants(Request &req, Response &resp)
return new SendLobbyParticipantsTask(mRsIdentity, mit->second); return new SendLobbyParticipantsTask(mRsIdentity, mit->second);
} }
void ChatHandler::handleGetDefaultIdentityForChatLobby(Request& req, Response& resp) void ChatHandler::handleGetDefaultIdentityForChatLobby(Request& /*req*/,
Response& resp)
{ {
RsGxsId gxsId; RsGxsId gxsId;
mRsMsgs->getDefaultIdentityForChatLobby(gxsId); mRsMsgs->getDefaultIdentityForChatLobby(gxsId);

View File

@ -23,8 +23,8 @@ namespace resource_api
FileSharingHandler::FileSharingHandler(StateTokenServer *sts, RsFiles *files, FileSharingHandler::FileSharingHandler(StateTokenServer *sts, RsFiles *files,
RsNotify& notify): RsNotify& notify):
mStateTokenServer(sts), mRsFiles(files), mNotify(notify), mStateTokenServer(sts), mMtx("FileSharingHandler Mtx"), mRsFiles(files),
mMtx("FileSharingHandler Mtx") mNotify(notify)
{ {
addResourceHandler("*", this, &FileSharingHandler::handleWildcard); addResourceHandler("*", this, &FileSharingHandler::handleWildcard);
addResourceHandler("force_check", this, &FileSharingHandler::handleForceCheck); addResourceHandler("force_check", this, &FileSharingHandler::handleForceCheck);
@ -79,7 +79,7 @@ void FileSharingHandler::handleForceCheck(Request&, Response& resp)
resp.setOk(); resp.setOk();
} }
void FileSharingHandler::handleGetSharedDir(Request& req, Response& resp) void FileSharingHandler::handleGetSharedDir(Request& /*req*/, Response& resp)
{ {
DirDetails dirDetails; DirDetails dirDetails;
mRsFiles->RequestDirDetails(NULL, dirDetails, RS_FILE_HINTS_LOCAL); mRsFiles->RequestDirDetails(NULL, dirDetails, RS_FILE_HINTS_LOCAL);

View File

@ -8,8 +8,8 @@ namespace resource_api
TransfersHandler::TransfersHandler(StateTokenServer *sts, RsFiles *files, RsPeers *peers, TransfersHandler::TransfersHandler(StateTokenServer *sts, RsFiles *files, RsPeers *peers,
RsNotify& notify): RsNotify& notify):
mStateTokenServer(sts), mFiles(files), mRsPeers(peers), mLastUpdateTS(0), mNotify(notify), mStateTokenServer(sts), mFiles(files), mRsPeers(peers), mNotify(notify),
mMtx("TransfersHandler") mMtx("TransfersHandler"), mLastUpdateTS(0)
{ {
addResourceHandler("*", this, &TransfersHandler::handleWildcard); addResourceHandler("*", this, &TransfersHandler::handleWildcard);
addResourceHandler("downloads", this, &TransfersHandler::handleDownloads); addResourceHandler("downloads", this, &TransfersHandler::handleDownloads);

View File

@ -8,8 +8,10 @@ TARGET = resapi
TARGET_PRL = libresapi TARGET_PRL = libresapi
DESTDIR = lib DESTDIR = lib
DEPENDPATH += ../../libretroshare/src/
INCLUDEPATH += ../../libretroshare/src INCLUDEPATH += ../../libretroshare/src
retroshare_android_service { retroshare_android_service {
win32 { win32 {
OBJECTS_DIR = temp/obj OBJECTS_DIR = temp/obj
@ -39,9 +41,6 @@ retroshare_android_service {
QMAKE_RC += --include-dir=$$_PRO_FILE_PWD_/../../libretroshare/src QMAKE_RC += --include-dir=$$_PRO_FILE_PWD_/../../libretroshare/src
} }
} }
DEPENDPATH += . ../../libretroshare/src/
INCLUDEPATH += ../../libretroshare/src/
} }
libresapihttpserver { libresapihttpserver {

View File

@ -917,24 +917,28 @@ test_bitdht {
################################# Android ##################################### ################################# Android #####################################
android-g++ { android-* {
## ifaddrs is missing on Android to add them don't use the one from ## ifaddrs is missing on Android to add them don't use the one from
## https://github.com/morristech/android-ifaddrs ## https://github.com/morristech/android-ifaddrs
## because they crash, use QNetworkInterface from Qt instead ## because it crash, use QNetworkInterface from Qt instead
CONFIG *= qt CONFIG *= qt
QT *= network QT *= network
## Add this here and not in retroshare.pri because static library are very DEFINES *= "fopen64=fopen"
## sensible to order in command line, has to be in the end of file for the DEFINES *= "fseeko64=fseeko"
## same reason DEFINES *= "ftello64=ftello"
LIBS *= -lbz2 -lupnp -lixml -lthreadutil -lsqlite3
## Static library are verysensible to order in command line, has to be in the
## end of file for this reason
LIBS += -L$$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/lib/ -lsqlcipher
PRE_TARGETDEPS += $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/lib/libsqlcipher.a
LIBS += -L$$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/lib/ -lssl LIBS += -L$$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/lib/ -lssl
INCLUDEPATH += $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/include
DEPENDPATH += $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/include
PRE_TARGETDEPS += $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/lib/libssl.a PRE_TARGETDEPS += $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/lib/libssl.a
LIBS += -L$$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/lib/ -lcrypto LIBS += -L$$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/lib/ -lcrypto
INCLUDEPATH += $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/include
DEPENDPATH += $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/include
PRE_TARGETDEPS += $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/lib/libcrypto.a PRE_TARGETDEPS += $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/lib/libcrypto.a
HEADERS += util/androiddebug.h HEADERS += util/androiddebug.h

View File

@ -35,6 +35,11 @@
#include "util/rswin.h" #include "util/rswin.h"
#endif #endif
#ifdef __ANDROID__
# include <QFile> // To install bdboot.txt
# include <QString> // for String::fromStdString(...)
#endif
#include "util/argstream.h" #include "util/argstream.h"
#include "util/rsdebug.h" #include "util/rsdebug.h"
#include "util/rsdir.h" #include "util/rsdir.h"
@ -1042,7 +1047,32 @@ int RsServer::StartupRetroShare()
uint64_t tmp_size ; uint64_t tmp_size ;
if (!RsDirUtil::checkFile(bootstrapfile,tmp_size,true)) if (!RsDirUtil::checkFile(bootstrapfile,tmp_size,true))
{ {
std::cerr << "DHT bootstrap file not in ConfigDir: " << bootstrapfile << std::endl; 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;
}
bdbootRF.close();
}
#else
std::string installfile = rsAccounts->PathDataDirectory(); std::string installfile = rsAccounts->PathDataDirectory();
installfile += "/"; installfile += "/";
installfile += BITDHT_BOOTSTRAP_FILENAME; installfile += BITDHT_BOOTSTRAP_FILENAME;
@ -1064,6 +1094,7 @@ int RsServer::StartupRetroShare()
{ {
std::cerr << "No Installation DHT bootstrap file to copy" << std::endl; std::cerr << "No Installation DHT bootstrap file to copy" << std::endl;
} }
#endif // def __ANDROID__
} }
/* construct the rest of the stack, important to build them in the correct order! */ /* construct the rest of the stack, important to build them in the correct order! */

View File

@ -122,10 +122,10 @@ SOURCES += openpgpsdk/opsstring.c
################################# Android ##################################### ################################# Android #####################################
android-g++ { android-* {
## Add this here and not in retroshare.pri because static library are very ## Add this here because static library are very sensible to order in
## sensible to order in command line ## command line
LIBS += -L$$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/lib/ -lssl LIBS += -L$$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/lib/ -lssl
INCLUDEPATH += $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/include INCLUDEPATH += $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/include
DEPENDPATH += $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/include DEPENDPATH += $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/include
@ -135,5 +135,4 @@ android-g++ {
INCLUDEPATH += $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/include INCLUDEPATH += $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/include
DEPENDPATH += $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/include DEPENDPATH += $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/include
PRE_TARGETDEPS += $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/lib/libcrypto.a PRE_TARGETDEPS += $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/lib/libcrypto.a
} }

View File

@ -24,19 +24,11 @@
#include <QDir> #include <QDir>
#include <QThread> #include <QThread>
#ifdef __ANDROID__
# include "util/androiddebug.h"
#endif
#include "libresapilocalclient.h" #include "libresapilocalclient.h"
#include "notificationsbridge.h" #include "notificationsbridge.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
#ifdef __ANDROID__
AndroidStdIOCatcher dbg; (void) dbg;
#endif
QCoreApplication app(argc, argv); QCoreApplication app(argc, argv);
QString sockPath = QDir::homePath() + "/.retroshare"; QString sockPath = QDir::homePath() + "/.retroshare";

View File

@ -12,15 +12,10 @@ RESOURCES += qml.qrc
TEMPLATE = app TEMPLATE = app
android-g++ { android-* {
TEMPLATE = lib TEMPLATE = lib
QT += androidextras QT += androidextras
} }
HEADERS += libresapilocalclient.h notificationsbridge.h HEADERS += libresapilocalclient.h notificationsbridge.h
SOURCES += libresapilocalclient.cpp main.cpp SOURCES += libresapilocalclient.cpp main.cpp
DEPENDPATH *= ../../libretroshare/src
INCLUDEPATH *= ../../libretroshare/src
PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a
LIBS *= ../../libretroshare/src/lib/libretroshare.a

View File

@ -6,10 +6,10 @@ QT += core network
QT -= gui QT -= gui
CONFIG += c++11 CONFIG += c++11
android-g++:CONFIG += dll android-*:CONFIG += dll
android-g++:TEMPLATE = lib android-*:TEMPLATE = lib
!android-g++:TEMPLATE = app !android-*:TEMPLATE = app
DEPENDPATH *= ../../libresapi/src DEPENDPATH *= ../../libresapi/src
INCLUDEPATH *= ../../libresapi/src INCLUDEPATH *= ../../libresapi/src

View File

@ -1,6 +1,6 @@
/* /*
* RetroShare Android Service * RetroShare Android Service
* Copyright (C) 2016-2017 Gioacchino Mazzurco <gio@eigenlab.org> * Copyright (C) 2016-2018 Gioacchino Mazzurco <gio@eigenlab.org>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
@ -18,8 +18,9 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <QDebug> #include <QDebug>
#include <QMetaObject>
#include <QDir> #include <QDir>
#include <QTimer>
#include <csignal>
#ifdef __ANDROID__ #ifdef __ANDROID__
# include "util/androiddebug.h" # include "util/androiddebug.h"
@ -38,6 +39,13 @@ int main(int argc, char *argv[])
#endif #endif
QCoreApplication app(argc, argv); QCoreApplication app(argc, argv);
signal(SIGINT, &QCoreApplication::exit);
signal(SIGTERM, &QCoreApplication::exit);
#ifdef SIGBREAK
signal(SIGBREAK, &QCoreApplication::exit);
#endif // def SIGBREAK
ApiServer api; ApiServer api;
RsControlModule ctrl_mod(argc, argv, api.getStateTokenServer(), &api, true); RsControlModule ctrl_mod(argc, argv, api.getStateTokenServer(), &api, true);
api.addResourceHandler( api.addResourceHandler(
@ -52,16 +60,13 @@ int main(int argc, char *argv[])
ApiServerLocal apiServerLocal(&api, sockPath); (void) apiServerLocal; ApiServerLocal apiServerLocal(&api, sockPath); (void) apiServerLocal;
while (!ctrl_mod.processShouldExit()) // This ugly but RsControlModule has no other way to callback for stop
{ QTimer shouldExitTimer;
app.processEvents(); shouldExitTimer.setTimerType(Qt::VeryCoarseTimer);
usleep(20000); shouldExitTimer.setInterval(1000);
} QObject::connect( &shouldExitTimer, &QTimer::timeout, [&](){
if(ctrl_mod.processShouldExit()) app.quit(); } );
/* Since QCoreApplication::quit() is a no-op until the event loop has been shouldExitTimer.start();
* started, we need to defer the call until it starts. Thus, we queue a
* deferred method call to quit() */
QMetaObject::invokeMethod(&app, "quit", Qt::QueuedConnection);
return app.exec(); return app.exec();
} }

View File

@ -160,7 +160,8 @@ QtObject
function startDistantChat (own_gxs_id, gxs_id, name, cb) function startDistantChat (own_gxs_id, gxs_id, name, cb)
{ {
console.log("startDistantChat()") console.log( "startDistantChat(own_gxs_id, gxs_id, name, cb)",
own_gxs_id, gxs_id, name, cb )
chatHelper.gxs_id = gxs_id chatHelper.gxs_id = gxs_id
chatHelper.name = name chatHelper.name = name
chatHelper.cb = cb chatHelper.cb = cb

View File

@ -54,18 +54,18 @@ public slots:
static QString b64AvatarGen (QVariantList onloads, int size) static QString b64AvatarGen (QVariantList onloads, int size)
{ {
qDebug() << "b64AvatarGen(): Generating face Avatar from"; qDebug() << "Generating hash face avatar";
QImage result(size, size, QImage::Format_ARGB32_Premultiplied); QImage result(size, size, QImage::Format_ARGB32_Premultiplied);
QPainter painter(&result); QPainter painter(&result);
int counter = 0; int counter = 0;
for (QVariantList::iterator j = onloads.begin(); j != onloads.end(); j++) for(QVariantList::iterator j = onloads.begin(); j != onloads.end(); ++j)
{ {
QImage image = getImage (":/"+(*j).toString()); QImage image = getImage (":/"+(*j).toString());
painter.drawImage(0, 0, image); // xi, yi is the position for imagei painter.drawImage(0, 0, image); // xi, yi is the position for imagei
counter++; ++counter;
} }
painter.end(); painter.end();

View File

@ -1,6 +1,6 @@
/* /*
* RetroShare Android QML App * RetroShare Android QML App
* Copyright (C) 2016-2017 Gioacchino Mazzurco <gio@eigenlab.org> * Copyright (C) 2016-2018 Gioacchino Mazzurco <gio@eigenlab.org>
* Copyright (C) 2016 Manu Pineda <manu@cooperativa.cat> * Copyright (C) 2016 Manu Pineda <manu@cooperativa.cat>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -41,12 +41,25 @@ int LibresapiLocalClient::request( const QString& path, const QString& jsonData,
<< callback.toString(); << callback.toString();
#endif // QT_DEBUG #endif // QT_DEBUG
int ret = -1;
if(mLocalSocket.isOpen())
{
QByteArray data; QByteArray data;
data.append(path); data.append('\n'); data.append(path); data.append('\n');
data.append(jsonData); data.append('\n'); data.append(jsonData); data.append('\n');
processingQueue.enqueue(PQRecord(path, jsonData, callback)); processingQueue.enqueue(PQRecord(path, jsonData, callback));
int ret = mLocalSocket.write(data); ret = mLocalSocket.write(data);
if(ret < 0) socketError(mLocalSocket.error()); if(ret < 0) socketError(mLocalSocket.error());
}
else
{
if(!mConnectAttemptTimer.isActive()) mConnectAttemptTimer.start();
qDebug() << __PRETTY_FUNCTION__
<< "Socket not ready yet! Ignoring request: "
<< path << jsonData;
}
return ret; return ret;
} }
@ -55,6 +68,23 @@ void LibresapiLocalClient::socketError(QLocalSocket::LocalSocketError error)
qCritical() << __PRETTY_FUNCTION__ << "Socket error! " << error qCritical() << __PRETTY_FUNCTION__ << "Socket error! " << error
<< mLocalSocket.errorString(); << mLocalSocket.errorString();
#ifdef QT_DEBUG
QString pQueueDump;
for (auto& qe: processingQueue )
{
pQueueDump.append(qe.mPath);
pQueueDump.append(QChar::Space);
pQueueDump.append(qe.mJsonData);
pQueueDump.append(QChar::LineSeparator);
}
qDebug() << __PRETTY_FUNCTION__ << "Discarded requests dump:"
<< QChar::LineSeparator << pQueueDump;
#endif //QT_DEBUG
processingQueue.clear();
if(mLocalSocket.state() == QLocalSocket::UnconnectedState && if(mLocalSocket.state() == QLocalSocket::UnconnectedState &&
!mConnectAttemptTimer.isActive()) !mConnectAttemptTimer.isActive())
{ {

View File

@ -17,18 +17,13 @@ RESOURCES += qml.qrc
# Platform interaction specific code # Platform interaction specific code
android-g++ { android-* {
QT += androidextras QT += androidextras
HEADERS += NativeCalls.h androidplatforminteracions.h HEADERS += NativeCalls.h androidplatforminteracions.h
SOURCES += NativeCalls.cpp androidplatforminteracions.cpp SOURCES += NativeCalls.cpp androidplatforminteracions.cpp
} else {
HEADERS += defaultplatforminteracions.h
SOURCES += defaultplatforminteracions.cpp
}
# Additional import path used to resolve QML modules in Qt Creator's code model ANDROID_EXTRA_LIBS *= $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/lib/libsqlite3.so
#QML_IMPORT_PATH = ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
#QML2_IMPORT_PATH =
# Default rules for deployment. # Default rules for deployment.
@ -44,9 +39,12 @@ DISTFILES += \
android/gradlew.bat \ android/gradlew.bat \
icons/retroshare.png icons/retroshare.png
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android } else {
DEPENDPATH *= ../../libretroshare/src HEADERS += defaultplatforminteracions.h
INCLUDEPATH *= ../../libretroshare/src SOURCES += defaultplatforminteracions.cpp
PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a }
LIBS *= ../../libretroshare/src/lib/libretroshare.a
# Additional import path used to resolve QML modules in Qt Creator's code model
#QML_IMPORT_PATH =
#QML2_IMPORT_PATH =

View File

@ -111,7 +111,7 @@ linux-* {
} }
} }
android-g++ { android-* {
isEmpty(NATIVE_LIBS_TOOLCHAIN_PATH) { isEmpty(NATIVE_LIBS_TOOLCHAIN_PATH) {
NATIVE_LIBS_TOOLCHAIN_PATH = $$(NATIVE_LIBS_TOOLCHAIN_PATH) NATIVE_LIBS_TOOLCHAIN_PATH = $$(NATIVE_LIBS_TOOLCHAIN_PATH)
} }
@ -119,21 +119,11 @@ android-g++ {
CONFIG -= no_retroshare_android_notify_service CONFIG -= no_retroshare_android_notify_service
CONFIG *= retroshare_android_notify_service CONFIG *= retroshare_android_notify_service
} }
CONFIG *= no_libresapihttpserver no_sqlcipher upnp_libupnp CONFIG *= no_libresapihttpserver upnp_libupnp
CONFIG -= libresapihttpserver sqlcipher upnp_miniupnpc CONFIG -= libresapihttpserver upnp_miniupnpc
QT *= androidextras QT *= androidextras
DEFINES *= "fopen64=fopen"
DEFINES *= "fseeko64=fseeko"
DEFINES *= "ftello64=ftello"
INCLUDEPATH += $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/include INCLUDEPATH += $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/include
LIBS *= -L$$NDK_TOOLCHAIN_PATH/sysroot/usr/lib/ LIBS *= -L$$NDK_TOOLCHAIN_PATH/sysroot/usr/lib/
LIBS *= -lbz2 -lupnp -lixml -lthreadutil -lsqlite3
ANDROID_EXTRA_LIBS *= $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/lib/libsqlite3.so
# message(LIBS: $$LIBS)
# message(ANDROID_EXTRA_LIBS: $$ANDROID_EXTRA_LIBS)
# message(ANDROID_PLATFORM: $$ANDROID_PLATFORM)
# message(ANDROID_PLATFORM_ROOT_PATH: $$ANDROID_PLATFORM_ROOT_PATH)
# message(NATIVE_LIBS_TOOLCHAIN_PATH: $$NATIVE_LIBS_TOOLCHAIN_PATH)
} }
win32 { win32 {