retroshare-service now build and runs fine on android (even older ones)

This commit is contained in:
Gioacchino Mazzurco 2018-10-05 22:29:49 +02:00
parent 1d8bb44811
commit b28512b889
No known key found for this signature in database
GPG key ID: A1FBCA3872E87051
18 changed files with 296 additions and 46 deletions

View file

@ -1,13 +1,34 @@
<?xml version="1.0"?>
<manifest package="org.retroshare.android.qml_app" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="0.6.4" android:versionCode="1" android:installLocation="auto">
<application android:name="org.qtproject.qt5.android.bindings.QtApplication" android:hardwareAccelerated="true" android:label="RetroShare" android:icon="@drawable/retroshare_128x128">
<activity android:label="">
<meta-data android:name="android.app.lib_name" android:value=""/>
<manifest
package="org.retroshare.service"
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionName="0.6.4" android:versionCode="1"
android:installLocation="auto">
<application android:name="org.qtproject.qt5.android.bindings.QtApplication" android:hardwareAccelerated="true" android:label="RetroShare" android:icon="@drawable/retroshare_service_128x128">
<activity
android:name=".RetroShareServiceControlActivity"
android:label="RetroShare" >
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<receiver android:name=".BootCompletedReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<receiver android:name=".AppUpdatedReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
</intent-filter>
</receiver>
<!-- For adding service(s) please check:
++ https://wiki.qt.io/AndroidServices -->
<service android:name=".RetroShareService" android:process=":rs" android:label="RetroShare Service" android:exported="true">
<service android:name=".RetroShareServiceAndroid" android:process=":rs" android:label="RetroShare Service" android:exported="true">
<!-- android:exported="true" Added to be able to run the service
++ from adb shell
++ android:process=":rs" is needed to force the service to run on
@ -16,16 +37,26 @@
<!-- Qt Application to launch -->
<meta-data android:name="android.app.lib_name" android:value="retroshare-service"/>
<!-- Ministro -->
<meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>
<meta-data android:name="android.app.repository" android:value="default"/>
<meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/>
<meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
<!-- Deploy Qt libs as part of package -->
<meta-data android:name="android.app.bundle_local_qt_libs" android:value="-- %%BUNDLE_LOCAL_QT_LIBS%% --"/>
<meta-data android:name="android.app.bundled_in_lib_resource_id" android:resource="@array/bundled_in_lib"/>
<meta-data android:name="android.app.bundled_in_assets_resource_id" android:resource="@array/bundled_in_assets"/>
<!-- Messages maps BEGIN -->
<!-- Run with local libs -->
<meta-data android:name="android.app.use_local_qt_libs" android:value="-- %%USE_LOCAL_QT_LIBS%% --"/>
<meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
<meta-data android:name="android.app.load_local_libs" android:value="-- %%INSERT_LOCAL_LIBS%% --"/>
<meta-data android:name="android.app.load_local_jars" android:value="-- %%INSERT_LOCAL_JARS%% --"/>
<meta-data android:name="android.app.static_init_classes" android:value="-- %%INSERT_INIT_CLASSES%% --"/>
<!-- Messages maps -->
<meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/>
<meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/>
<meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
<!-- Messages maps END -->
<!-- Messages maps -->
<!-- Background running -->
<meta-data android:name="android.app.background_running" android:value="true"/>
@ -33,7 +64,7 @@
</service>
</application>
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="21"/>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="18"/>
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
<!-- The following comment will be replaced upon deployment with default

View file

@ -1 +0,0 @@
../../../../../data/128x128/apps/retroshare.png

View file

@ -1 +0,0 @@
../../../../../data/48x48/apps/retroshare.png

View file

@ -0,0 +1 @@
../../../../data/retroshare-service_128x128.png

View file

@ -0,0 +1 @@
../../../../data/retroshare-service_48x48.png

View file

@ -0,0 +1,11 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/startStopButton" android:text="Stop"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>

View file

@ -0,0 +1,35 @@
/*
* RetroShare
* Copyright (C) 2016-2018 Gioacchino Mazzurco <gio@eigenlab.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.retroshare.service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class AppUpdatedReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Log.i("AppUpdatedReceiver", "onReceive() Restarting RetroShare Service After Update");
RetroShareServiceAndroid.stop(context);
RetroShareServiceAndroid.start(context);
}
}

View file

@ -0,0 +1,34 @@
/*
* RetroShare
* Copyright (C) 2016-2018 Gioacchino Mazzurco <gio@eigenlab.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.retroshare.service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class BootCompletedReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Log.i("BootCompletedReceiver", "onReceive() Starting RetroShare Service on boot");
RetroShareServiceAndroid.start(context);
}
}

View file

@ -0,0 +1,47 @@
/*
* RetroShare
* Copyright (C) 2016-2018 Gioacchino Mazzurco <gio@eigenlab.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.retroshare.service;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import org.qtproject.qt5.android.bindings.QtService;
public class RetroShareServiceAndroid extends QtService
{
public static void start(Context ctx)
{
ctx.startService(new Intent(ctx, RetroShareServiceAndroid.class));
}
public static void stop(Context ctx)
{
ctx.stopService(new Intent(ctx, RetroShareServiceAndroid.class));
}
public static boolean isRunning(Context ctx)
{
ActivityManager manager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE))
if (RetroShareServiceAndroid.class.getName().equals(service.service.getClassName()))
return true;
return false;
}
}

View file

@ -0,0 +1,64 @@
/*
* RetroShare
* Copyright (C) 2016-2018 Gioacchino Mazzurco <gio@eigenlab.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.retroshare.service;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import org.retroshare.service.R;
public class RetroShareServiceControlActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
setContentView(R.layout.retroshare_service_control_layout);
final Button button = (Button) findViewById(R.id.startStopButton);
button.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
if (RetroShareServiceAndroid.isRunning(RetroShareServiceControlActivity.this))
{
RetroShareServiceAndroid.stop(RetroShareServiceControlActivity.this);
button.setText("Start");
}
else
{
RetroShareServiceAndroid.start(RetroShareServiceControlActivity.this);
button.setText("Stop");
}
}
});
super.onCreate(savedInstanceState);
}
@Override
public void onResume()
{
super.onResume();
final Button button = (Button) findViewById(R.id.startStopButton);
button.setText(RetroShareServiceAndroid.isRunning(this) ? "Stop" : "Start");
}
}

View file

@ -21,6 +21,10 @@
#include <QObject>
#include <QStringList>
#ifdef __ANDROID__
# include <QAndroidService>
#endif // def __ANDROID__
#include "retroshare/rsinit.h"
#include "retroshare/rsiface.h"
@ -36,9 +40,10 @@ int main(int argc, char* argv[])
{
#ifdef __ANDROID__
AndroidStdIOCatcher dbg; (void) dbg;
#endif
QAndroidService app(argc, argv);
#else // def __ANDROID__
QCoreApplication app(argc, argv);
#endif // def __ANDROID__
signal(SIGINT, QCoreApplication::exit);
signal(SIGTERM, QCoreApplication::exit);

View file

@ -10,6 +10,8 @@ QT -= gui
SOURCES += retroshare-service.cc
android-* {
QT += androidextras
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
DISTFILES += android/AndroidManifest.xml \
@ -23,6 +25,7 @@ android-* {
android/gradlew.bat
}
appimage {
icon_files.path = "$${PREFIX}/share/icons/hicolor/scalable/"
icon_files.files = ../data/retroshare-service.svg