Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<?xml version="1.0"?>
<manifest package="fr.calaos.calaoshome" xmlns:android="http://schemas.android.com/apk/res/android"
android:versionName="3.1.0"
android:versionCode="18"
android:installLocation="auto">
<manifest package="fr.calaos.calaoshome" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="3.1.0" android:versionCode="18" android:installLocation="auto">

<uses-sdk android:minSdkVersion="26" android:targetSdkVersion="29" />
<uses-sdk android:minSdkVersion="26" android:targetSdkVersion="29"/>

<!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.
Remove the comment if you do not require these default permissions. -->
Expand All @@ -16,18 +13,12 @@

<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>

<application android:hardwareAccelerated="true"
android:name="org.qtproject.qt5.android.bindings.QtApplication"
android:label="CalaosHome"
android:extractNativeLibs="true"
android:icon="@drawable/icon">

<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density"
android:name="fr.calaos.calaoshome.HardwareUtils"
android:label="-- %%INSERT_APP_NAME%% --"
android:screenOrientation="unspecified"
android:launchMode="singleTop">
<uses-permission android:name="android.permission.INTERNET" />

<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="CalaosHome" android:extractNativeLibs="true" android:icon="@drawable/icon"
android:usesCleartextTraffic="true"
>
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density" android:name="fr.calaos.calaoshome.HardwareUtils" android:label="-- %%INSERT_APP_NAME%% --" android:screenOrientation="unspecified" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
Expand Down Expand Up @@ -87,5 +78,24 @@
<!-- extract android style -->
</activity>
<!-- For adding service(s) please check: https://wiki.qt.io/AndroidServices -->


<!-- Firebase Messaging specific services -->
<service android:name="com.google.firebase.messaging.cpp.ListenerService" android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>

<service android:name="com.google.firebase.messaging.cpp.FcmInstanceIDListenerService" android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>

<service android:name="com.google.firebase.messaging.cpp.RegistrationIntentService" android:exported="false">
</service>
<service android:name="com.google.firebase.messaging.MessageForwardingService" android:exported="false">
</service>
</application>
</manifest>
110 changes: 109 additions & 1 deletion android/HardwareUtils_Android.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

#include "HardwareUtils_Android.h"
#include "notificationservice.h"
#include "../src/Common.h"
#include <QtAndroidExtras/QAndroidJniObject>
#include <QtAndroidExtras/QAndroidJniEnvironment>
#include <jni.h>
Expand Down Expand Up @@ -56,8 +58,9 @@ class FbListener: public ::firebase::messaging::Listener

virtual void OnMessage(const ::firebase::messaging::Message &message)
{
Q_UNUSED(message)
qDebug() << "Received FCM message";
NotificationService *ns = new NotificationService();
Comment thread
raoulh marked this conversation as resolved.
Outdated
ns->handleMessage(message);
}

private:
Expand All @@ -78,6 +81,16 @@ static ::firebase::InitResult firebaseInitializeMessaging(::firebase::App *app,
return res;
}


Comment thread
ryancrunchi marked this conversation as resolved.
Outdated









HardwareUtilsAndroid::HardwareUtilsAndroid(QObject *parent):
HardwareUtils(parent),
fcmListener(new FbListener())
Expand All @@ -88,6 +101,11 @@ HardwareUtilsAndroid::~HardwareUtilsAndroid()
{
}

HardwareUtilsAndroid *HardwareUtilsAndroid::Instance(QObject *parent)
{
return static_cast<HardwareUtilsAndroid*>(HardwareUtils::Instance(parent));
Comment thread
ryancrunchi marked this conversation as resolved.
Outdated
}

void HardwareUtilsAndroid::platformInit(QQmlApplicationEngine *e)
{
HardwareUtils::platformInit(e);
Expand Down Expand Up @@ -154,6 +172,66 @@ void HardwareUtilsAndroid::inputTextDialog(const QString &title, const QString &
jMessage.object<jstring>());
}

void HardwareUtilsAndroid::loadAuthKeychain(QString &email, QString &pass)
{
this->HardwareUtils::loadAuthKeychain(email, pass);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inutile d'appeler la classe HardwareUtils, les identifiants sont stockés dans les SharedPreferences android, et plus dans la config par defaut

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pour moi, HardwareUtilsAndroid est une sous classe et le fait d'appeler HardwareUtils c'est comme faire un super.. On garde les fonctionnalités de la super classe, et on spécialise dans la sous classe. Même si dans ce cas ça reste des fonctions de classe (static) et pas d'instance

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oui, mais dans le cas ici on veut soit utiliser le stockage par defaut des identifiants, soit dans dans la version géré dans la sous classe HardwareUtilsAndroid. Donc si t'appelles aussi HardwareUtils ca sera dans les 2 et c'est pas une bonne idée. Dans iOS par exemple ca utilise Keychain pour stocker les identifiants de maniere sécurisé, on ne veux pas les laisser trainer en clair a plusieurs endroits.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je viens de me rendre compte que ca ne marche pas en fait.
email et pass sont passé par ref, donc il faut leur affecter une valeur dans la fonction loadAuthKeychain.
Lorsque tu appelles QAndroidJniObject::callStaticMethod tu ne retournes pas les identifiants pour pouvoir les affecter.

QAndroidJniObject::callStaticMethod<void>("fr/calaos/calaoshome/HardwareUtils", "loadAuthKeychain");
}

void HardwareUtilsAndroid::saveAuthKeychain(const QString &email, const QString &pass)
{
this->HardwareUtils::saveAuthKeychain(email, pass);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idem: Inutile d'appeler la classe HardwareUtils, les identifiants sont stockés dans les SharedPreferences android, et plus dans la config par defaut

QAndroidJniObject jEmail = QAndroidJniObject::fromString(email);
QAndroidJniObject jPass = QAndroidJniObject::fromString(pass);
QAndroidJniObject::callStaticMethod<void>("fr/calaos/calaoshome/HardwareUtils", "saveAuthKeychain", "(Ljava/lang/String;Ljava/lang/String;)V",
jEmail.object<jstring>(),
jPass.object<jstring>()
);
}

void HardwareUtilsAndroid::setConfigOption(QString key, QString value)
{
this->HardwareUtils::setConfigOption(key, value);
Comment thread
raoulh marked this conversation as resolved.
Outdated
QAndroidJniObject jKey = QAndroidJniObject::fromString(key);
QAndroidJniObject jValue = QAndroidJniObject::fromString(value);
QAndroidJniObject::callStaticMethod<void>("fr/calaos/calaoshome/HardwareUtils", "setConfigOption", "(Ljava/lang/String;Ljava/lang/String;)V",
jKey.object<jstring>(),
jValue.object<jstring>()
);
}

QString HardwareUtilsAndroid::getConfigOption(QString key)
Comment thread
ryancrunchi marked this conversation as resolved.
Outdated
{
return this->HardwareUtils::getConfigOption(key);
}

void HardwareUtilsAndroid::resetAuthKeychain()
{
this->HardwareUtils::resetAuthKeychain();
QAndroidJniObject::callStaticMethod<void>("fr/calaos/calaoshome/HardwareUtils", "resetAuthKeychain", "()V");
}


Comment thread
ryancrunchi marked this conversation as resolved.
Outdated


















// JNI //

static void emitDialogTextValid(JNIEnv *env, jobject obj, jstring text)
{
Q_UNUSED(env);
Expand All @@ -174,10 +252,40 @@ static void emitDialogCancel(JNIEnv *env, jobject obj)
Qt::QueuedConnection);
}

static jstring getDemoUser(JNIEnv *env, jobject obj)
{
Q_UNUSED(env);
Comment thread
ryancrunchi marked this conversation as resolved.
Outdated
Q_UNUSED(obj);
auto stduser = Common::getDemoUser().toStdString();
const char* ret = stduser.c_str();
return env->NewStringUTF(ret);
}

static jstring getDemoPass(JNIEnv *env, jobject obj)
{
Q_UNUSED(env);
Comment thread
ryancrunchi marked this conversation as resolved.
Outdated
Q_UNUSED(obj);
auto stdpass = Common::getDemoPass().toStdString();
const char* ret = stdpass.c_str();
return env->NewStringUTF(ret);
}

static jstring getDemoHost(JNIEnv *env, jobject obj)
{
Q_UNUSED(env);
Comment thread
ryancrunchi marked this conversation as resolved.
Outdated
Q_UNUSED(obj);
auto stdhost = Common::getDemoHost().toStdString();
const char* ret = stdhost.c_str();
return env->NewStringUTF(ret);
}

static JNINativeMethod jniMethods[] =
{
{ "emitDialogTextValid", "(Ljava/lang/String;)V", reinterpret_cast<void *>(emitDialogTextValid) },
{ "emitDialogCancel", "()V", reinterpret_cast<void *>(emitDialogCancel) },
{ "getDemoUser", "()Ljava/lang/String;", reinterpret_cast<void *>(getDemoUser) },
{ "getDemoPass", "()Ljava/lang/String;", reinterpret_cast<void *>(getDemoPass) },
{ "getDemoHost", "()Ljava/lang/String;", reinterpret_cast<void *>(getDemoHost) },
};

// this method is called automatically by Java after the .so file is loaded
Expand Down
12 changes: 12 additions & 0 deletions android/HardwareUtils_Android.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,22 @@ class HardwareUtilsAndroid: public HardwareUtils
public:
virtual ~HardwareUtilsAndroid();

static HardwareUtilsAndroid *Instance(QObject *parent = NULL);

virtual void platformInit(QQmlApplicationEngine *e);

virtual void showAlertMessage(QString title, QString message, QString buttontext);

virtual void loadAuthKeychain(QString &email, QString &pass);

virtual void saveAuthKeychain(const QString &email, const QString &pass);

virtual void setConfigOption(QString key, QString value);

virtual void resetAuthKeychain();

virtual QString getConfigOption(QString key);

enum NetworkStatus
{
NotConnected = 0,
Expand Down
11 changes: 8 additions & 3 deletions android/android.pri
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ QT += gui-private
OTHER_FILES += $$PWD/src/fr/calaos/calaoshome/HardwareUtils.java
ANDROID_PACKAGE_SOURCE_DIR = $$PWD

SOURCES += $$PWD/HardwareUtils_Android.cpp
HEADERS += $$PWD/HardwareUtils_Android.h
SOURCES += $$PWD/HardwareUtils_Android.cpp \
$$PWD/NotificationService.cpp
HEADERS += $$PWD/HardwareUtils_Android.h \
$$PWD/NotificationService.h

FIREBASE_SDK = $$(FIREBASE_CPP_SDK_DIR)
isEmpty(FIREBASE_SDK) {
Expand All @@ -29,4 +31,7 @@ DISTFILES += \
$$PWD/AndroidManifest.xml \
$$PWD/build.gradle \
$$PWD/gradle/wrapper/gradle-wrapper.properties \
$$PWD/settings.gradle
$$PWD/settings.gradle \
$$PWD/src/fr/calaos/calaoshome/Common.java \
$$PWD/src/fr/calaos/calaoshome/Logger.java \
Comment thread
raoulh marked this conversation as resolved.
$$PWD/src/fr/calaos/calaoshome/NotificationService.java
27 changes: 27 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ repositories {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
api "androidx.appcompat:appcompat:1.2.0"
//compile 'com.google.android.gms:play-services-gcm:17.0.0'
//compile 'com.google.firebase:firebase-messaging:21.0.1'
//compile 'com.google.firebase.messaging.cpp:firebase_messaging_cpp@aar'
implementation 'com.squareup.picasso:picasso:2.8'
}

android {
Expand All @@ -74,7 +76,32 @@ android {
minSdkVersion 26
targetSdkVersion 29
}
/*
Comment thread
ryancrunchi marked this conversation as resolved.
Outdated
buildTypes {
release {

}

debug {

}
}

flavorDimensions "version"

productFlavors {
debug {
dimension "version"
applicationIdSuffix ".debug"
versionNameSuffix "-debug"
}
demo {
dimension "version"
applicationIdSuffix ".demo"
versionNameSuffix "-demo"
}
}
*/
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
Expand Down
Loading