diff --git a/README-Android.asciidoc b/README-Android.asciidoc index f746ebf11..0422b8796 100644 --- a/README-Android.asciidoc +++ b/README-Android.asciidoc @@ -46,6 +46,7 @@ export HOST_NUM_CPU=1 ./android-prepare-toolchain.sh ------------------------------------------------------------------------------- + == Preparing Qt Creator 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 ------------------------------------------------------------------------------- -WARNING: SQLCipher is not supported yet on RetroShare for Android. This poses a -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 +TIP: 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 pointing to your SDK installation path, like +mkdir -p /opt/android/sdk && ln -s /home/user/android-sdk-linux /opt/android/sdk+ + == Quircks 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. + == Debugging with GDB QtCreator actually support debugging only for the foreground activity, so to 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 [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 adb shell -## take note of the PID of the RetroShare process -ps | grep retroshare - -## take the note of the phone IP +## take the note of the phone IP address ip address show ## Gain root permissions on the shell su ## 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 [source,bash] -------------------------------------------------------------------------------- -## Extract system lib from the phone to a temporary directory on your computer -adb pull /system/lib /tmp/system_lib +## Setup some convenience variables +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 -/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 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 (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 @@ -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://source.android.com/devices/tech/debug/[] - 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[] diff --git a/android-prepare-toolchain.sh b/android-prepare-toolchain.sh index d89e071e2..4c6745c1d 100755 --- a/android-prepare-toolchain.sh +++ b/android-prepare-toolchain.sh @@ -6,9 +6,14 @@ [ -z ${ANDROID_NDK_ABI_VER+x} ] && export ANDROID_NDK_ABI_VER="4.9" [ -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 ${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 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 build_bzlib() { - B_dir="bzip2-1.0.6" + B_dir="bzip2-${BZIP2_SOURCE_VERSION}" 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 cd $B_dir sed -i "/^CC=.*/d" Makefile @@ -59,7 +64,7 @@ build_bzlib() ## More information available at http://doc.qt.io/qt-5/opensslsupport.html build_openssl() { - B_dir="openssl-1.0.2h" + B_dir="openssl-${OPENSSL_SOURCE_VERSION}" rm -rf $B_dir [ -f $B_dir.tar.gz ] || wget https://www.openssl.org/source/$B_dir.tar.gz tar -xf $B_dir.tar.gz @@ -86,8 +91,8 @@ build_openssl() build_sqlite() { - B_dir="sqlite-autoconf-3130000" - [ -f $B_dir.tar.gz ] || wget https://www.sqlite.org/2016/$B_dir.tar.gz + B_dir="sqlite-autoconf-${SQLITE_SOURCE_VERSION}" + [ -f $B_dir.tar.gz ] || wget https://www.sqlite.org/${SQLITE_SOURCE_YEAR}/$B_dir.tar.gz tar -xf $B_dir.tar.gz cd $B_dir ./configure --prefix="${SYSROOT}/usr" --host=${ANDROID_NDK_ARCH}-linux @@ -101,11 +106,18 @@ build_sqlite() build_sqlcipher() { - echo "sqlcipher not supported yet on android" - return 0 - - cd sqlcipher - ./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="${SYSROOT}/usr/lib/libcrypto.a" + B_dir="sqlcipher-${SQLCIPHER_SOURCE_VERSION}" + 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 + rm -rf $B_dir + 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 install cd .. @@ -113,9 +125,9 @@ build_sqlcipher() build_libupnp() { - B_dir="libupnp-1.6.20" + B_dir="libupnp-${LIBUPNP_SOURCE_VERSION}" 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 cd $B_dir ## liupnp must be configured as static library because if not the linker will @@ -149,4 +161,7 @@ build_toolchain build_bzlib build_openssl build_sqlite +build_sqlcipher build_libupnp + +echo NDK_TOOLCHAIN_PATH=${NDK_TOOLCHAIN_PATH} diff --git a/libbitdht/src/libbitdht.pro b/libbitdht/src/libbitdht.pro index 738deeab1..ad6986f32 100644 --- a/libbitdht/src/libbitdht.pro +++ b/libbitdht/src/libbitdht.pro @@ -46,6 +46,12 @@ unix { 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 #################### diff --git a/libresapi/src/api/ApiServerLocal.cpp b/libresapi/src/api/ApiServerLocal.cpp index ec1812af7..e14f85520 100644 --- a/libresapi/src/api/ApiServerLocal.cpp +++ b/libresapi/src/api/ApiServerLocal.cpp @@ -16,33 +16,69 @@ * along with this program. If not, see . */ -#include +#include +#include +#include + #include "ApiServerLocal.h" #include "JsonStream.h" + 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), - 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(); localListener.moveToThread(&serverThread); serverThread.start(); } -ApiServerLocal::~ApiServerLocal() { serverThread.quit(); } +ApiServerLocal::~ApiServerLocal() +{ + serverThread.quit(); + serverThread.wait(); +} ApiLocalListener::ApiLocalListener(ApiServer *server, const QString &listenPath, QObject *parent) : QObject(parent), mApiServer(server), mLocalServer(this) { - mLocalServer.removeServer(listenPath); + 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); + } #if QT_VERSION >= 0x050000 mLocalServer.setSocketOptions(QLocalServer::UserAccessOption); #endif - connect(&mLocalServer, SIGNAL(newConnection()), this, SLOT(handleConnection())); - mLocalServer.listen(listenPath); + connect( &mLocalServer, &QLocalServer::newConnection, + 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() @@ -62,8 +98,12 @@ ApiLocalConnectionHandler::ApiLocalConnectionHandler( ApiLocalConnectionHandler::~ApiLocalConnectionHandler() { - mLocalSocket->close(); - delete mLocalSocket; + /* Any attempt of closing the socket here also deferred method call, causes + * 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() diff --git a/libresapi/src/api/ChatHandler.cpp b/libresapi/src/api/ChatHandler.cpp index 01d770cd1..f03df69f9 100644 --- a/libresapi/src/api/ChatHandler.cpp +++ b/libresapi/src/api/ChatHandler.cpp @@ -1045,7 +1045,8 @@ ResponseTask* ChatHandler::handleLobbyParticipants(Request &req, Response &resp) return new SendLobbyParticipantsTask(mRsIdentity, mit->second); } -void ChatHandler::handleGetDefaultIdentityForChatLobby(Request& req, Response& resp) +void ChatHandler::handleGetDefaultIdentityForChatLobby(Request& /*req*/, + Response& resp) { RsGxsId gxsId; mRsMsgs->getDefaultIdentityForChatLobby(gxsId); diff --git a/libresapi/src/api/FileSharingHandler.cpp b/libresapi/src/api/FileSharingHandler.cpp index b8645ec2a..856275d9c 100644 --- a/libresapi/src/api/FileSharingHandler.cpp +++ b/libresapi/src/api/FileSharingHandler.cpp @@ -23,8 +23,8 @@ namespace resource_api FileSharingHandler::FileSharingHandler(StateTokenServer *sts, RsFiles *files, RsNotify& notify): - mStateTokenServer(sts), mRsFiles(files), mNotify(notify), - mMtx("FileSharingHandler Mtx") + mStateTokenServer(sts), mMtx("FileSharingHandler Mtx"), mRsFiles(files), + mNotify(notify) { addResourceHandler("*", this, &FileSharingHandler::handleWildcard); addResourceHandler("force_check", this, &FileSharingHandler::handleForceCheck); @@ -79,7 +79,7 @@ void FileSharingHandler::handleForceCheck(Request&, Response& resp) resp.setOk(); } -void FileSharingHandler::handleGetSharedDir(Request& req, Response& resp) +void FileSharingHandler::handleGetSharedDir(Request& /*req*/, Response& resp) { DirDetails dirDetails; mRsFiles->RequestDirDetails(NULL, dirDetails, RS_FILE_HINTS_LOCAL); diff --git a/libresapi/src/api/TransfersHandler.cpp b/libresapi/src/api/TransfersHandler.cpp index 39e9c5875..f563f377c 100644 --- a/libresapi/src/api/TransfersHandler.cpp +++ b/libresapi/src/api/TransfersHandler.cpp @@ -8,8 +8,8 @@ namespace resource_api TransfersHandler::TransfersHandler(StateTokenServer *sts, RsFiles *files, RsPeers *peers, RsNotify& notify): - mStateTokenServer(sts), mFiles(files), mRsPeers(peers), mLastUpdateTS(0), mNotify(notify), - mMtx("TransfersHandler") + mStateTokenServer(sts), mFiles(files), mRsPeers(peers), mNotify(notify), + mMtx("TransfersHandler"), mLastUpdateTS(0) { addResourceHandler("*", this, &TransfersHandler::handleWildcard); addResourceHandler("downloads", this, &TransfersHandler::handleDownloads); diff --git a/libresapi/src/libresapi.pro b/libresapi/src/libresapi.pro index 69745f1b0..ea2daa082 100644 --- a/libresapi/src/libresapi.pro +++ b/libresapi/src/libresapi.pro @@ -8,8 +8,10 @@ TARGET = resapi TARGET_PRL = libresapi DESTDIR = lib +DEPENDPATH += ../../libretroshare/src/ INCLUDEPATH += ../../libretroshare/src + retroshare_android_service { win32 { OBJECTS_DIR = temp/obj @@ -39,9 +41,6 @@ retroshare_android_service { QMAKE_RC += --include-dir=$$_PRO_FILE_PWD_/../../libretroshare/src } } - - DEPENDPATH += . ../../libretroshare/src/ - INCLUDEPATH += ../../libretroshare/src/ } libresapihttpserver { diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 1521f5574..ba9973793 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -917,24 +917,28 @@ test_bitdht { ################################# Android ##################################### -android-g++ { +android-* { ## ifaddrs is missing on Android to add them don't use the one from ## https://github.com/morristech/android-ifaddrs -## because they crash, use QNetworkInterface from Qt instead +## because it crash, use QNetworkInterface from Qt instead CONFIG *= qt QT *= network -## Add this here and not in retroshare.pri because static library are very -## sensible to order in command line, has to be in the end of file for the -## same reason + DEFINES *= "fopen64=fopen" + DEFINES *= "fseeko64=fseeko" + 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 - 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 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 HEADERS += util/androiddebug.h diff --git a/libretroshare/src/rsserver/rsinit.cc b/libretroshare/src/rsserver/rsinit.cc index dae235aa2..76aa66c9a 100644 --- a/libretroshare/src/rsserver/rsinit.cc +++ b/libretroshare/src/rsserver/rsinit.cc @@ -35,6 +35,11 @@ #include "util/rswin.h" #endif +#ifdef __ANDROID__ +# include // To install bdboot.txt +# include // for String::fromStdString(...) +#endif + #include "util/argstream.h" #include "util/rsdebug.h" #include "util/rsdir.h" @@ -1042,7 +1047,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; + 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(); installfile += "/"; installfile += BITDHT_BOOTSTRAP_FILENAME; @@ -1064,6 +1094,7 @@ int RsServer::StartupRetroShare() { 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! */ diff --git a/openpgpsdk/src/openpgpsdk.pro b/openpgpsdk/src/openpgpsdk.pro index 2fcad33d4..eaf4ef2e6 100644 --- a/openpgpsdk/src/openpgpsdk.pro +++ b/openpgpsdk/src/openpgpsdk.pro @@ -122,10 +122,10 @@ SOURCES += openpgpsdk/opsstring.c ################################# Android ##################################### -android-g++ { +android-* { -## Add this here and not in retroshare.pri because static library are very -## sensible to order in command line +## Add this here because static library are very sensible to order in +## command line 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 @@ -135,5 +135,4 @@ android-g++ { 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 - } diff --git a/retroshare-android-notify-service/src/main.cpp b/retroshare-android-notify-service/src/main.cpp index 47593da7f..267e9110e 100644 --- a/retroshare-android-notify-service/src/main.cpp +++ b/retroshare-android-notify-service/src/main.cpp @@ -24,19 +24,11 @@ #include #include -#ifdef __ANDROID__ -# include "util/androiddebug.h" -#endif - #include "libresapilocalclient.h" #include "notificationsbridge.h" int main(int argc, char *argv[]) { -#ifdef __ANDROID__ - AndroidStdIOCatcher dbg; (void) dbg; -#endif - QCoreApplication app(argc, argv); QString sockPath = QDir::homePath() + "/.retroshare"; diff --git a/retroshare-android-notify-service/src/retroshare-android-notify-service.pro b/retroshare-android-notify-service/src/retroshare-android-notify-service.pro index 4120e232d..7294bfcc4 100644 --- a/retroshare-android-notify-service/src/retroshare-android-notify-service.pro +++ b/retroshare-android-notify-service/src/retroshare-android-notify-service.pro @@ -12,15 +12,10 @@ RESOURCES += qml.qrc TEMPLATE = app -android-g++ { +android-* { TEMPLATE = lib QT += androidextras } HEADERS += libresapilocalclient.h notificationsbridge.h SOURCES += libresapilocalclient.cpp main.cpp - -DEPENDPATH *= ../../libretroshare/src -INCLUDEPATH *= ../../libretroshare/src -PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a -LIBS *= ../../libretroshare/src/lib/libretroshare.a diff --git a/retroshare-android-service/src/retroshare-android-service.pro b/retroshare-android-service/src/retroshare-android-service.pro index 54843d34f..bcafa7725 100644 --- a/retroshare-android-service/src/retroshare-android-service.pro +++ b/retroshare-android-service/src/retroshare-android-service.pro @@ -6,10 +6,10 @@ QT += core network QT -= gui CONFIG += c++11 -android-g++:CONFIG += dll +android-*:CONFIG += dll -android-g++:TEMPLATE = lib -!android-g++:TEMPLATE = app +android-*:TEMPLATE = lib +!android-*:TEMPLATE = app DEPENDPATH *= ../../libresapi/src INCLUDEPATH *= ../../libresapi/src diff --git a/retroshare-android-service/src/service.cpp b/retroshare-android-service/src/service.cpp index 6729768cc..4c36916e7 100644 --- a/retroshare-android-service/src/service.cpp +++ b/retroshare-android-service/src/service.cpp @@ -1,6 +1,6 @@ /* * RetroShare Android Service - * Copyright (C) 2016-2017 Gioacchino Mazzurco + * Copyright (C) 2016-2018 Gioacchino Mazzurco * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -18,8 +18,9 @@ #include #include -#include #include +#include +#include #ifdef __ANDROID__ # include "util/androiddebug.h" @@ -38,6 +39,13 @@ int main(int argc, char *argv[]) #endif QCoreApplication app(argc, argv); + + signal(SIGINT, &QCoreApplication::exit); + signal(SIGTERM, &QCoreApplication::exit); +#ifdef SIGBREAK + signal(SIGBREAK, &QCoreApplication::exit); +#endif // def SIGBREAK + ApiServer api; RsControlModule ctrl_mod(argc, argv, api.getStateTokenServer(), &api, true); api.addResourceHandler( @@ -52,16 +60,13 @@ int main(int argc, char *argv[]) ApiServerLocal apiServerLocal(&api, sockPath); (void) apiServerLocal; - while (!ctrl_mod.processShouldExit()) - { - app.processEvents(); - usleep(20000); - } - - /* Since QCoreApplication::quit() is a no-op until the event loop has been - * 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); + // This ugly but RsControlModule has no other way to callback for stop + QTimer shouldExitTimer; + shouldExitTimer.setTimerType(Qt::VeryCoarseTimer); + shouldExitTimer.setInterval(1000); + QObject::connect( &shouldExitTimer, &QTimer::timeout, [&](){ + if(ctrl_mod.processShouldExit()) app.quit(); } ); + shouldExitTimer.start(); return app.exec(); } diff --git a/retroshare-qml-app/src/ChatCache.qml b/retroshare-qml-app/src/ChatCache.qml index 07d9f48de..d59bad5ab 100644 --- a/retroshare-qml-app/src/ChatCache.qml +++ b/retroshare-qml-app/src/ChatCache.qml @@ -160,7 +160,8 @@ QtObject 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.name = name chatHelper.cb = cb diff --git a/retroshare-qml-app/src/androidimagepicker.h b/retroshare-qml-app/src/androidimagepicker.h index 06ceade18..7c18b561f 100644 --- a/retroshare-qml-app/src/androidimagepicker.h +++ b/retroshare-qml-app/src/androidimagepicker.h @@ -54,18 +54,18 @@ public slots: 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); QPainter painter(&result); 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()); painter.drawImage(0, 0, image); // xi, yi is the position for imagei - counter++; + ++counter; } painter.end(); diff --git a/retroshare-qml-app/src/libresapilocalclient.cpp b/retroshare-qml-app/src/libresapilocalclient.cpp index e332e7b94..79f738a35 100644 --- a/retroshare-qml-app/src/libresapilocalclient.cpp +++ b/retroshare-qml-app/src/libresapilocalclient.cpp @@ -1,6 +1,6 @@ /* * RetroShare Android QML App - * Copyright (C) 2016-2017 Gioacchino Mazzurco + * Copyright (C) 2016-2018 Gioacchino Mazzurco * Copyright (C) 2016 Manu Pineda * * 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(); #endif // QT_DEBUG - QByteArray data; - data.append(path); data.append('\n'); - data.append(jsonData); data.append('\n'); - processingQueue.enqueue(PQRecord(path, jsonData, callback)); - int ret = mLocalSocket.write(data); - if(ret < 0) socketError(mLocalSocket.error()); + int ret = -1; + + if(mLocalSocket.isOpen()) + { + QByteArray data; + data.append(path); data.append('\n'); + data.append(jsonData); data.append('\n'); + processingQueue.enqueue(PQRecord(path, jsonData, callback)); + ret = mLocalSocket.write(data); + 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; } @@ -55,6 +68,23 @@ void LibresapiLocalClient::socketError(QLocalSocket::LocalSocketError error) qCritical() << __PRETTY_FUNCTION__ << "Socket error! " << error << 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 && !mConnectAttemptTimer.isActive()) { diff --git a/retroshare-qml-app/src/retroshare-qml-app.pro b/retroshare-qml-app/src/retroshare-qml-app.pro index e136a7ab4..15054102c 100644 --- a/retroshare-qml-app/src/retroshare-qml-app.pro +++ b/retroshare-qml-app/src/retroshare-qml-app.pro @@ -17,11 +17,30 @@ RESOURCES += qml.qrc # Platform interaction specific code -android-g++ { +android-* { QT += androidextras HEADERS += NativeCalls.h androidplatforminteracions.h SOURCES += NativeCalls.cpp androidplatforminteracions.cpp + + ANDROID_EXTRA_LIBS *= $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/lib/libsqlite3.so + ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android + + + # Default rules for deployment. + include(deployment.pri) + + DISTFILES += \ + android/AndroidManifest.xml \ + android/gradle/wrapper/gradle-wrapper.jar \ + android/gradlew \ + android/res/values/libs.xml \ + android/build.gradle \ + android/gradle/wrapper/gradle-wrapper.properties \ + android/gradlew.bat \ + icons/retroshare.png + } else { + HEADERS += defaultplatforminteracions.h SOURCES += defaultplatforminteracions.cpp } @@ -29,24 +48,3 @@ android-g++ { # Additional import path used to resolve QML modules in Qt Creator's code model #QML_IMPORT_PATH = #QML2_IMPORT_PATH = - - -# Default rules for deployment. -include(deployment.pri) - -DISTFILES += \ - android/AndroidManifest.xml \ - android/gradle/wrapper/gradle-wrapper.jar \ - android/gradlew \ - android/res/values/libs.xml \ - android/build.gradle \ - android/gradle/wrapper/gradle-wrapper.properties \ - android/gradlew.bat \ - icons/retroshare.png - -ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android - -DEPENDPATH *= ../../libretroshare/src -INCLUDEPATH *= ../../libretroshare/src -PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a -LIBS *= ../../libretroshare/src/lib/libretroshare.a diff --git a/retroshare.pri b/retroshare.pri index 9c1be7fed..90901d8ae 100644 --- a/retroshare.pri +++ b/retroshare.pri @@ -111,7 +111,7 @@ linux-* { } } -android-g++ { +android-* { isEmpty(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 *= retroshare_android_notify_service } - CONFIG *= no_libresapihttpserver no_sqlcipher upnp_libupnp - CONFIG -= libresapihttpserver sqlcipher upnp_miniupnpc + CONFIG *= no_libresapihttpserver upnp_libupnp + CONFIG -= libresapihttpserver upnp_miniupnpc QT *= androidextras - DEFINES *= "fopen64=fopen" - DEFINES *= "fseeko64=fseeko" - DEFINES *= "ftello64=ftello" INCLUDEPATH += $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/include 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 {