From e434c62055acd50a63614d6fabd28d600d5ae8da Mon Sep 17 00:00:00 2001 From: Yogev Ben David Date: Mon, 12 Aug 2019 16:23:29 +0300 Subject: [PATCH] Remove GCM leftovers (#359) * Remove GCM leftovers, fix typos * Print android unit tests output --- android/app/build.gradle | 19 ++++++++++++ android/app/src/main/AndroidManifest.xml | 6 ++-- .../wix/reactnativenotifications/Defs.java | 1 - .../RNNotificationsModule.java | 11 +++---- .../FcmInstanceIdListenerService.java | 12 +++---- .../FcmInstanceIdRefreshHandlerService.java | 12 +++---- .../{gcm => fcm}/FcmToken.java | 6 ++-- .../{gcm => fcm}/IFcmToken.java | 2 +- .../fcm/INotificationsFcmApplication.java | 7 +++++ .../gcm/INotificationsGcmApplication.java | 7 ----- .../src/main/AndroidManifest.xml | 3 -- example/android/send_notif.py | 31 ------------------- 12 files changed, 48 insertions(+), 69 deletions(-) rename android/app/src/main/java/com/wix/reactnativenotifications/{gcm => fcm}/FcmInstanceIdListenerService.java (75%) rename android/app/src/main/java/com/wix/reactnativenotifications/{gcm => fcm}/FcmInstanceIdRefreshHandlerService.java (73%) rename android/app/src/main/java/com/wix/reactnativenotifications/{gcm => fcm}/FcmToken.java (94%) rename android/app/src/main/java/com/wix/reactnativenotifications/{gcm => fcm}/IFcmToken.java (92%) create mode 100644 android/app/src/main/java/com/wix/reactnativenotifications/fcm/INotificationsFcmApplication.java delete mode 100644 android/app/src/main/java/com/wix/reactnativenotifications/gcm/INotificationsGcmApplication.java delete mode 100755 example/android/send_notif.py diff --git a/android/app/build.gradle b/android/app/build.gradle index d2c1944..9ea834b 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -17,6 +17,25 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + testOptions { + unitTests.all { t -> + reports { + html.enabled true + } + testLogging { + events "PASSED", "SKIPPED", "FAILED", "standardOut", "standardError" + } + afterSuite { desc, result -> + if (!desc.parent) { // will match the outermost suite + def output = " ${result.resultType} (${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped) " + def repeatLength = output.length() + println '\n\n' + ('-' * repeatLength) + '\n' + output + '\n' + ('-' * repeatLength) + '\n' + + println "see report at file://${t.reports.html.destination}/index.html" + } + } + } + } } dependencies { diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index ffef75f..b6dad7c 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -4,7 +4,7 @@ package="com.wix.reactnativenotifications"> + android:name=".fcm.FcmInstanceIdListenerService"> @@ -30,7 +30,7 @@ diff --git a/android/app/src/main/java/com/wix/reactnativenotifications/Defs.java b/android/app/src/main/java/com/wix/reactnativenotifications/Defs.java index 26a8b7a..ec7f72a 100644 --- a/android/app/src/main/java/com/wix/reactnativenotifications/Defs.java +++ b/android/app/src/main/java/com/wix/reactnativenotifications/Defs.java @@ -2,7 +2,6 @@ package com.wix.reactnativenotifications; public interface Defs { String LOGTAG = "ReactNativeNotifs"; - String GCM_SENDER_ID_ATTR_NAME = "com.wix.reactnativenotifications.gcmSenderId"; String TOKEN_RECEIVED_EVENT_NAME = "remoteNotificationsRegistered"; diff --git a/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java b/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java index 8fb5f01..61dddec 100644 --- a/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java +++ b/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java @@ -15,7 +15,6 @@ import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; import com.facebook.react.bridge.ReadableMap; -import com.wix.reactnativenotifications.core.AppLifecycleFacade; import com.wix.reactnativenotifications.core.AppLifecycleFacadeHolder; import com.wix.reactnativenotifications.core.InitialNotificationHolder; import com.wix.reactnativenotifications.core.NotificationIntentAdapter; @@ -25,9 +24,7 @@ import com.wix.reactnativenotifications.core.notification.PushNotification; import com.wix.reactnativenotifications.core.notification.PushNotificationProps; import com.wix.reactnativenotifications.core.notificationdrawer.IPushNotificationsDrawer; import com.wix.reactnativenotifications.core.notificationdrawer.PushNotificationsDrawer; -import com.wix.reactnativenotifications.gcm.FcmInstanceIdRefreshHandlerService; - -import com.google.firebase.FirebaseApp; +import com.wix.reactnativenotifications.fcm.FcmInstanceIdRefreshHandlerService; import static com.wix.reactnativenotifications.Defs.LOGTAG; @@ -50,7 +47,7 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements @Override public void initialize() { Log.d(LOGTAG, "Native module init"); - startGcmIntentService(FcmInstanceIdRefreshHandlerService.EXTRA_IS_APP_INIT); + startFcmIntentService(FcmInstanceIdRefreshHandlerService.EXTRA_IS_APP_INIT); final IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext()); notificationsDrawer.onAppInit(); @@ -75,7 +72,7 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements @ReactMethod public void refreshToken() { Log.d(LOGTAG, "Native method invocation: refreshToken()"); - startGcmIntentService(FcmInstanceIdRefreshHandlerService.EXTRA_MANUAL_REFRESH); + startFcmIntentService(FcmInstanceIdRefreshHandlerService.EXTRA_MANUAL_REFRESH); } @ReactMethod @@ -115,7 +112,7 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements promise.resolve(new Boolean(hasPermission)); } - protected void startGcmIntentService(String extraFlag) { + protected void startFcmIntentService(String extraFlag) { final Context appContext = getReactApplicationContext().getApplicationContext(); final Intent tokenFetchIntent = new Intent(appContext, FcmInstanceIdRefreshHandlerService.class); tokenFetchIntent.putExtra(extraFlag, true); diff --git a/android/app/src/main/java/com/wix/reactnativenotifications/gcm/FcmInstanceIdListenerService.java b/android/app/src/main/java/com/wix/reactnativenotifications/fcm/FcmInstanceIdListenerService.java similarity index 75% rename from android/app/src/main/java/com/wix/reactnativenotifications/gcm/FcmInstanceIdListenerService.java rename to android/app/src/main/java/com/wix/reactnativenotifications/fcm/FcmInstanceIdListenerService.java index 2456913..061b733 100644 --- a/android/app/src/main/java/com/wix/reactnativenotifications/gcm/FcmInstanceIdListenerService.java +++ b/android/app/src/main/java/com/wix/reactnativenotifications/fcm/FcmInstanceIdListenerService.java @@ -1,4 +1,4 @@ -package com.wix.reactnativenotifications.gcm; +package com.wix.reactnativenotifications.fcm; import android.os.Bundle; import android.util.Log; @@ -8,12 +8,10 @@ import com.google.firebase.messaging.RemoteMessage; import com.wix.reactnativenotifications.core.notification.IPushNotification; import com.wix.reactnativenotifications.core.notification.PushNotification; -import java.util.Map; - import static com.wix.reactnativenotifications.Defs.LOGTAG; /** - * Instance-ID + token refreshing handling service. Contacts the GCM to fetch the updated token. + * Instance-ID + token refreshing handling service. Contacts the FCM to fetch the updated token. * * @author amitd */ @@ -22,14 +20,14 @@ public class FcmInstanceIdListenerService extends FirebaseMessagingService { @Override public void onMessageReceived(RemoteMessage message){ Bundle bundle = message.toIntent().getExtras(); - Log.d(LOGTAG, "New message from GCM: " + bundle); + Log.d(LOGTAG, "New message from FCM: " + bundle); try { final IPushNotification notification = PushNotification.get(getApplicationContext(), bundle); notification.onReceived(); } catch (IPushNotification.InvalidNotificationException e) { - // A GCM message, yes - but not the kind we know how to work with. - Log.v(LOGTAG, "GCM message handling aborted", e); + // An FCM message, yes - but not the kind we know how to work with. + Log.v(LOGTAG, "FCM message handling aborted", e); } } } diff --git a/android/app/src/main/java/com/wix/reactnativenotifications/gcm/FcmInstanceIdRefreshHandlerService.java b/android/app/src/main/java/com/wix/reactnativenotifications/fcm/FcmInstanceIdRefreshHandlerService.java similarity index 73% rename from android/app/src/main/java/com/wix/reactnativenotifications/gcm/FcmInstanceIdRefreshHandlerService.java rename to android/app/src/main/java/com/wix/reactnativenotifications/fcm/FcmInstanceIdRefreshHandlerService.java index 8270ad6..dd2cc9a 100644 --- a/android/app/src/main/java/com/wix/reactnativenotifications/gcm/FcmInstanceIdRefreshHandlerService.java +++ b/android/app/src/main/java/com/wix/reactnativenotifications/fcm/FcmInstanceIdRefreshHandlerService.java @@ -1,4 +1,4 @@ -package com.wix.reactnativenotifications.gcm; +package com.wix.reactnativenotifications.fcm; import android.app.IntentService; import android.content.Intent; @@ -14,17 +14,17 @@ public class FcmInstanceIdRefreshHandlerService extends IntentService { @Override protected void onHandleIntent(Intent intent) { - IFcmToken gcmToken = FcmToken.get(this); - if (gcmToken == null) { + IFcmToken fcmToken = FcmToken.get(this); + if (fcmToken == null) { return; } if (intent.getBooleanExtra(EXTRA_IS_APP_INIT, false)) { - gcmToken.onAppReady(); + fcmToken.onAppReady(); } else if (intent.getBooleanExtra(EXTRA_MANUAL_REFRESH, false)) { - gcmToken.onManualRefresh(); + fcmToken.onManualRefresh(); } else { - gcmToken.onNewTokenReady(); + fcmToken.onNewTokenReady(); } } } diff --git a/android/app/src/main/java/com/wix/reactnativenotifications/gcm/FcmToken.java b/android/app/src/main/java/com/wix/reactnativenotifications/fcm/FcmToken.java similarity index 94% rename from android/app/src/main/java/com/wix/reactnativenotifications/gcm/FcmToken.java rename to android/app/src/main/java/com/wix/reactnativenotifications/fcm/FcmToken.java index 44c8ec6..04c2755 100644 --- a/android/app/src/main/java/com/wix/reactnativenotifications/gcm/FcmToken.java +++ b/android/app/src/main/java/com/wix/reactnativenotifications/fcm/FcmToken.java @@ -1,4 +1,4 @@ -package com.wix.reactnativenotifications.gcm; +package com.wix.reactnativenotifications.fcm; import android.content.Context; import android.util.Log; @@ -29,8 +29,8 @@ public class FcmToken implements IFcmToken { public static IFcmToken get(Context context) { Context appContext = context.getApplicationContext(); - if (appContext instanceof INotificationsGcmApplication) { - return ((INotificationsGcmApplication) appContext).getFcmToken(context); + if (appContext instanceof INotificationsFcmApplication) { + return ((INotificationsFcmApplication) appContext).getFcmToken(context); } return new FcmToken(appContext); } diff --git a/android/app/src/main/java/com/wix/reactnativenotifications/gcm/IFcmToken.java b/android/app/src/main/java/com/wix/reactnativenotifications/fcm/IFcmToken.java similarity index 92% rename from android/app/src/main/java/com/wix/reactnativenotifications/gcm/IFcmToken.java rename to android/app/src/main/java/com/wix/reactnativenotifications/fcm/IFcmToken.java index 9e75d39..ce9fd72 100644 --- a/android/app/src/main/java/com/wix/reactnativenotifications/gcm/IFcmToken.java +++ b/android/app/src/main/java/com/wix/reactnativenotifications/fcm/IFcmToken.java @@ -1,4 +1,4 @@ -package com.wix.reactnativenotifications.gcm; +package com.wix.reactnativenotifications.fcm; public interface IFcmToken { diff --git a/android/app/src/main/java/com/wix/reactnativenotifications/fcm/INotificationsFcmApplication.java b/android/app/src/main/java/com/wix/reactnativenotifications/fcm/INotificationsFcmApplication.java new file mode 100644 index 0000000..5a2cb1c --- /dev/null +++ b/android/app/src/main/java/com/wix/reactnativenotifications/fcm/INotificationsFcmApplication.java @@ -0,0 +1,7 @@ +package com.wix.reactnativenotifications.fcm; + +import android.content.Context; + +public interface INotificationsFcmApplication { + IFcmToken getFcmToken(Context context); +} diff --git a/android/app/src/main/java/com/wix/reactnativenotifications/gcm/INotificationsGcmApplication.java b/android/app/src/main/java/com/wix/reactnativenotifications/gcm/INotificationsGcmApplication.java deleted file mode 100644 index d318ecc..0000000 --- a/android/app/src/main/java/com/wix/reactnativenotifications/gcm/INotificationsGcmApplication.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.wix.reactnativenotifications.gcm; - -import android.content.Context; - -public interface INotificationsGcmApplication { - IFcmToken getFcmToken(Context context); -} diff --git a/example/android/myapplication/src/main/AndroidManifest.xml b/example/android/myapplication/src/main/AndroidManifest.xml index 5b14d1a..1229221 100644 --- a/example/android/myapplication/src/main/AndroidManifest.xml +++ b/example/android/myapplication/src/main/AndroidManifest.xml @@ -12,9 +12,6 @@ android:usesCleartextTraffic="true" android:label="@string/app_name" android:theme="@style/AppTheme"> -