Merge PR #346: Allow overriding the complete android packaging structure for branding

This commit is contained in:
Jenkins nymea 2020-10-19 22:23:58 +02:00
commit ae9f7f68e5
15 changed files with 59 additions and 25 deletions

View File

@ -45,13 +45,19 @@ HEADERS += \
../nymea-app/platformintegration/android/platformhelperandroid.h \
DISTFILES += \
../packaging/android/src/io/guh/nymeaapp/Action.java \
../packaging/android/src/io/guh/nymeaapp/NymeaAppControlService.java \
../packaging/android/src/io/guh/nymeaapp/NymeaAppService.java \
../packaging/android/src/io/guh/nymeaapp/NymeaAppControlsActivity.java \
../packaging/android/src/io/guh/nymeaapp/NymeaAppServiceConnection.java \
../packaging/android/src/io/guh/nymeaapp/Thing.java \
../packaging/android/src/io/guh/nymeaapp/State.java \
../packaging/android/src/io/guh/nymeaapp/NymeaHost.java \
java/io/guh/nymeaapp/Action.java \
java/io/guh/nymeaapp/NymeaAppControlService.java \
java/io/guh/nymeaapp/NymeaAppService.java \
java/io/guh/nymeaapp/NymeaAppControlsActivity.java \
java/io/guh/nymeaapp/NymeaAppServiceConnection.java \
java/io/guh/nymeaapp/Thing.java \
java/io/guh/nymeaapp/State.java \
java/io/guh/nymeaapp/NymeaHost.java \
controlviews/Main.qml
QMAKE_COPY_DIR=cp -f -R -v
javafiles.commands = $(MKDIR) $${ANDROID_PACKAGE_SOURCE_DIR}/src;
javafiles.commands += $(COPY_DIR) $${PWD}/java/io $${ANDROID_PACKAGE_SOURCE_DIR}/src/
QMAKE_EXTRA_TARGETS += javafiles
POST_TARGETDEPS += javafiles

View File

@ -10,4 +10,15 @@ APP_VERSION=$$member(VERSION_INFO, 0)
APP_REVISION=$$member(VERSION_INFO, 1)
DEFINES+=APP_VERSION=\\\"$${APP_VERSION}\\\"
android:QMAKE_POST_LINK += cp $$top_srcdir/version.txt $$top_builddir/
android: {
QMAKE_POST_LINK += cp $$top_srcdir/version.txt $$top_builddir/
!equals(OVERLAY_PATH, ""):!equals(BRANDING, "") {
ANDROID_PACKAGE_SOURCE_DIR = $${OVERLAY_PATH}/packaging/android_$$BRANDING
} else {
ANDROID_PACKAGE_SOURCE_DIR = $${top_srcdir}/packaging/android
}
message("Andorid package source dir $${ANDROID_PACKAGE_SOURCE_DIR}")
}

View File

@ -51,7 +51,6 @@ win32 {
}
android {
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/../packaging/android
android-clang {
FIREBASE_STL_VARIANT = c++
@ -70,6 +69,9 @@ android {
HEADERS += platformintegration/android/platformhelperandroid.h
SOURCES += platformintegration/android/platformhelperandroid.cpp
# https://bugreports.qt.io/browse/QTBUG-83165
LIBS += -L$${top_builddir}/libnymea-app/$${ANDROID_TARGET_ARCH}
DISTFILES += \
$$ANDROID_PACKAGE_SOURCE_DIR/AndroidManifest.xml \
$$ANDROID_PACKAGE_SOURCE_DIR/google-services.json \
@ -79,14 +81,17 @@ android {
$$ANDROID_PACKAGE_SOURCE_DIR/build.gradle \
$$ANDROID_PACKAGE_SOURCE_DIR/gradle/wrapper/gradle-wrapper.properties \
$$ANDROID_PACKAGE_SOURCE_DIR/gradlew.bat \
$$ANDROID_PACKAGE_SOURCE_DIR/src/io/guh/nymeaapp/NymeaAppActivity.java \
$$ANDROID_PACKAGE_SOURCE_DIR/src/io/guh/nymeaapp/NymeaAppNotificationService.java \
$$ANDROID_PACKAGE_SOURCE_DIR/LICENSE
$$ANDROID_PACKAGE_SOURCE_DIR/LICENSE \
platformintegration/android/java/io/guh/nymeaapp/NymeaAppActivity.java \
platformintegration/android/java/io/guh/nymeaapp/NymeaAppNotificationService.java \
# https://bugreports.qt.io/browse/QTBUG-83165
LIBS += -L$${top_builddir}/libnymea-app/$${ANDROID_TARGET_ARCH}
QMAKE_COPY_DIR=cp -f -R -v
QMAKE_MKDIR_COMMAND=echo tralala; mkdir
javafiles.commands = $(MKDIR) $${ANDROID_PACKAGE_SOURCE_DIR}/src/;
javafiles.commands += $(COPY_DIR) $${PWD}/platformintegration/android/java/io $${ANDROID_PACKAGE_SOURCE_DIR}/src/;
QMAKE_EXTRA_TARGETS += javafiles
POST_TARGETDEPS += javafiles
ANDROID_ABIS = armeabi-v7a arm64-v8a
}
macx: {

View File

@ -5,6 +5,7 @@ import com.google.firebase.messaging.FirebaseMessagingService;
import android.util.Log;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.app.PendingIntent;
import android.app.Notification;
import android.app.NotificationChannel;
@ -13,13 +14,16 @@ import android.net.Uri;
import android.content.Context;
import android.provider.Settings.System;
import android.os.Build;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.support.v4.app.NotificationCompat;
import java.util.Random;
public class NymeaAppNotificationService extends FirebaseMessagingService {
private static final String TAG = "nymea-app: NymeaAppNotificationService";
/**
* Called when message is received.
@ -48,8 +52,16 @@ public class NymeaAppNotificationService extends FirebaseMessagingService {
// PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, 0);
// We can't directly access R.drawable.ic_stat_notification from here:
// When the package is branded, the package name is not "io.guh.nymeaapp" and resources in
// the res/ folder are built into the app's package which isn't the same as this files package.
// Because of this, we need to dynamically fetch the resource from the package resources
int resId = getResources().getIdentifier("ic_stat_notificationicon", "drawable", getPackageName());
Log.d(TAG, "notification icon resource: " + resId + " Package:" + getPackageName());
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "notify_001")
.setSmallIcon(R.drawable.ic_stat_notificationicon)
.setSmallIcon(resId)
.setColor(0xFF57BAAE)
.setContentTitle(remoteMessage.getData().get("title"))
.setContentText(remoteMessage.getData().get("body"))
@ -67,7 +79,7 @@ public class NymeaAppNotificationService extends FirebaseMessagingService {
int notificationId = new Random().nextInt(60000);
Log.d("Posting Notification", remoteMessage.getMessageId());
Log.d(TAG, "Posting Notification: " + remoteMessage.getMessageId());
notificationManager.notify(notificationId, notificationBuilder.build());
}

View File

@ -53,11 +53,6 @@ static QAndroidJniObject getAndroidWindow()
PlatformHelperAndroid::PlatformHelperAndroid(QObject *parent) : PlatformHelper(parent)
{
// QAndroidIntent serviceIntent(QtAndroid::androidActivity().object(), "io.guh.nymeaapp.NymeaAppControlService");
// m_serviceConnection = new DeviceControlServiceConnection();
// QtAndroid::bindService(serviceIntent, *m_serviceConnection, QtAndroid::BindFlag::AutoCreate);
m_instance = this;
}

View File

@ -237,7 +237,12 @@ Item {
PlatformHelper.requestPermissions();
}
} else {
AWSClient.registerPushNotificationEndpoint(PushNotifications.token, PlatformHelper.machineHostname, PlatformHelper.deviceSerial + "+io.guh.nymeaapp", PlatformHelper.deviceManufacturer, PlatformHelper.deviceModel);
AWSClient.registerPushNotificationEndpoint(
PushNotifications.token,
PlatformHelper.machineHostname,
PlatformHelper.deviceSerial + "+io.guh.nymeaapp" + (appBranding.length > 0 ? "-" + appBranding : ""),
PlatformHelper.deviceManufacturer,
PlatformHelper.deviceModel);
}
}