Commit e434c620 authored by Yogev Ben David's avatar Yogev Ben David Committed by GitHub

Remove GCM leftovers (#359)

* Remove GCM leftovers, fix typos

* Print android unit tests output
parent b4030449
...@@ -17,6 +17,25 @@ android { ...@@ -17,6 +17,25 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 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 { dependencies {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
package="com.wix.reactnativenotifications"> package="com.wix.reactnativenotifications">
<!-- <!--
Permissions required for enabling GCM. Permissions required for enabling FCM.
--> -->
<permission <permission
android:name="${applicationId}.permission.C2D_MESSAGE" android:name="${applicationId}.permission.C2D_MESSAGE"
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<service android:name=".core.ProxyService"/> <service android:name=".core.ProxyService"/>
<service <service
android:name=".gcm.FcmInstanceIdListenerService"> android:name=".fcm.FcmInstanceIdListenerService">
<intent-filter> <intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" /> <action android:name="com.google.firebase.MESSAGING_EVENT" />
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" /> <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
</service> </service>
<service <service
android:name=".gcm.FcmInstanceIdRefreshHandlerService" android:name=".fcm.FcmInstanceIdRefreshHandlerService"
android:exported="false" /> android:exported="false" />
</application> </application>
......
...@@ -2,7 +2,6 @@ package com.wix.reactnativenotifications; ...@@ -2,7 +2,6 @@ package com.wix.reactnativenotifications;
public interface Defs { public interface Defs {
String LOGTAG = "ReactNativeNotifs"; String LOGTAG = "ReactNativeNotifs";
String GCM_SENDER_ID_ATTR_NAME = "com.wix.reactnativenotifications.gcmSenderId";
String TOKEN_RECEIVED_EVENT_NAME = "remoteNotificationsRegistered"; String TOKEN_RECEIVED_EVENT_NAME = "remoteNotificationsRegistered";
......
...@@ -15,7 +15,6 @@ import com.facebook.react.bridge.ReactApplicationContext; ...@@ -15,7 +15,6 @@ import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod; import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.ReadableMap;
import com.wix.reactnativenotifications.core.AppLifecycleFacade;
import com.wix.reactnativenotifications.core.AppLifecycleFacadeHolder; import com.wix.reactnativenotifications.core.AppLifecycleFacadeHolder;
import com.wix.reactnativenotifications.core.InitialNotificationHolder; import com.wix.reactnativenotifications.core.InitialNotificationHolder;
import com.wix.reactnativenotifications.core.NotificationIntentAdapter; import com.wix.reactnativenotifications.core.NotificationIntentAdapter;
...@@ -25,9 +24,7 @@ import com.wix.reactnativenotifications.core.notification.PushNotification; ...@@ -25,9 +24,7 @@ import com.wix.reactnativenotifications.core.notification.PushNotification;
import com.wix.reactnativenotifications.core.notification.PushNotificationProps; import com.wix.reactnativenotifications.core.notification.PushNotificationProps;
import com.wix.reactnativenotifications.core.notificationdrawer.IPushNotificationsDrawer; import com.wix.reactnativenotifications.core.notificationdrawer.IPushNotificationsDrawer;
import com.wix.reactnativenotifications.core.notificationdrawer.PushNotificationsDrawer; import com.wix.reactnativenotifications.core.notificationdrawer.PushNotificationsDrawer;
import com.wix.reactnativenotifications.gcm.FcmInstanceIdRefreshHandlerService; import com.wix.reactnativenotifications.fcm.FcmInstanceIdRefreshHandlerService;
import com.google.firebase.FirebaseApp;
import static com.wix.reactnativenotifications.Defs.LOGTAG; import static com.wix.reactnativenotifications.Defs.LOGTAG;
...@@ -50,7 +47,7 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements ...@@ -50,7 +47,7 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements
@Override @Override
public void initialize() { public void initialize() {
Log.d(LOGTAG, "Native module init"); 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()); final IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext());
notificationsDrawer.onAppInit(); notificationsDrawer.onAppInit();
...@@ -75,7 +72,7 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements ...@@ -75,7 +72,7 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements
@ReactMethod @ReactMethod
public void refreshToken() { public void refreshToken() {
Log.d(LOGTAG, "Native method invocation: refreshToken()"); Log.d(LOGTAG, "Native method invocation: refreshToken()");
startGcmIntentService(FcmInstanceIdRefreshHandlerService.EXTRA_MANUAL_REFRESH); startFcmIntentService(FcmInstanceIdRefreshHandlerService.EXTRA_MANUAL_REFRESH);
} }
@ReactMethod @ReactMethod
...@@ -115,7 +112,7 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements ...@@ -115,7 +112,7 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements
promise.resolve(new Boolean(hasPermission)); promise.resolve(new Boolean(hasPermission));
} }
protected void startGcmIntentService(String extraFlag) { protected void startFcmIntentService(String extraFlag) {
final Context appContext = getReactApplicationContext().getApplicationContext(); final Context appContext = getReactApplicationContext().getApplicationContext();
final Intent tokenFetchIntent = new Intent(appContext, FcmInstanceIdRefreshHandlerService.class); final Intent tokenFetchIntent = new Intent(appContext, FcmInstanceIdRefreshHandlerService.class);
tokenFetchIntent.putExtra(extraFlag, true); tokenFetchIntent.putExtra(extraFlag, true);
......
package com.wix.reactnativenotifications.gcm; package com.wix.reactnativenotifications.fcm;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
...@@ -8,12 +8,10 @@ import com.google.firebase.messaging.RemoteMessage; ...@@ -8,12 +8,10 @@ import com.google.firebase.messaging.RemoteMessage;
import com.wix.reactnativenotifications.core.notification.IPushNotification; import com.wix.reactnativenotifications.core.notification.IPushNotification;
import com.wix.reactnativenotifications.core.notification.PushNotification; import com.wix.reactnativenotifications.core.notification.PushNotification;
import java.util.Map;
import static com.wix.reactnativenotifications.Defs.LOGTAG; 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 * @author amitd
*/ */
...@@ -22,14 +20,14 @@ public class FcmInstanceIdListenerService extends FirebaseMessagingService { ...@@ -22,14 +20,14 @@ public class FcmInstanceIdListenerService extends FirebaseMessagingService {
@Override @Override
public void onMessageReceived(RemoteMessage message){ public void onMessageReceived(RemoteMessage message){
Bundle bundle = message.toIntent().getExtras(); Bundle bundle = message.toIntent().getExtras();
Log.d(LOGTAG, "New message from GCM: " + bundle); Log.d(LOGTAG, "New message from FCM: " + bundle);
try { try {
final IPushNotification notification = PushNotification.get(getApplicationContext(), bundle); final IPushNotification notification = PushNotification.get(getApplicationContext(), bundle);
notification.onReceived(); notification.onReceived();
} catch (IPushNotification.InvalidNotificationException e) { } catch (IPushNotification.InvalidNotificationException e) {
// A GCM message, yes - but not the kind we know how to work with. // An FCM message, yes - but not the kind we know how to work with.
Log.v(LOGTAG, "GCM message handling aborted", e); Log.v(LOGTAG, "FCM message handling aborted", e);
} }
} }
} }
package com.wix.reactnativenotifications.gcm; package com.wix.reactnativenotifications.fcm;
import android.app.IntentService; import android.app.IntentService;
import android.content.Intent; import android.content.Intent;
...@@ -14,17 +14,17 @@ public class FcmInstanceIdRefreshHandlerService extends IntentService { ...@@ -14,17 +14,17 @@ public class FcmInstanceIdRefreshHandlerService extends IntentService {
@Override @Override
protected void onHandleIntent(Intent intent) { protected void onHandleIntent(Intent intent) {
IFcmToken gcmToken = FcmToken.get(this); IFcmToken fcmToken = FcmToken.get(this);
if (gcmToken == null) { if (fcmToken == null) {
return; return;
} }
if (intent.getBooleanExtra(EXTRA_IS_APP_INIT, false)) { if (intent.getBooleanExtra(EXTRA_IS_APP_INIT, false)) {
gcmToken.onAppReady(); fcmToken.onAppReady();
} else if (intent.getBooleanExtra(EXTRA_MANUAL_REFRESH, false)) { } else if (intent.getBooleanExtra(EXTRA_MANUAL_REFRESH, false)) {
gcmToken.onManualRefresh(); fcmToken.onManualRefresh();
} else { } else {
gcmToken.onNewTokenReady(); fcmToken.onNewTokenReady();
} }
} }
} }
package com.wix.reactnativenotifications.gcm; package com.wix.reactnativenotifications.fcm;
import android.content.Context; import android.content.Context;
import android.util.Log; import android.util.Log;
...@@ -29,8 +29,8 @@ public class FcmToken implements IFcmToken { ...@@ -29,8 +29,8 @@ public class FcmToken implements IFcmToken {
public static IFcmToken get(Context context) { public static IFcmToken get(Context context) {
Context appContext = context.getApplicationContext(); Context appContext = context.getApplicationContext();
if (appContext instanceof INotificationsGcmApplication) { if (appContext instanceof INotificationsFcmApplication) {
return ((INotificationsGcmApplication) appContext).getFcmToken(context); return ((INotificationsFcmApplication) appContext).getFcmToken(context);
} }
return new FcmToken(appContext); return new FcmToken(appContext);
} }
......
package com.wix.reactnativenotifications.gcm; package com.wix.reactnativenotifications.fcm;
public interface IFcmToken { public interface IFcmToken {
......
package com.wix.reactnativenotifications.gcm; package com.wix.reactnativenotifications.fcm;
import android.content.Context; import android.content.Context;
public interface INotificationsGcmApplication { public interface INotificationsFcmApplication {
IFcmToken getFcmToken(Context context); IFcmToken getFcmToken(Context context);
} }
...@@ -12,9 +12,6 @@ ...@@ -12,9 +12,6 @@
android:usesCleartextTraffic="true" android:usesCleartextTraffic="true"
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<meta-data
android:name="com.wix.reactnativenotifications.gcmSenderId"
android:value="434691868895\0"/>
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
......
#!/usr/bin/python
from urllib2 import *
import json
import sys
if len(sys.argv) < 2:
print 'Error: missing token argument'
sys.exit(1)
API_KEY = 'AIzaSyBVtqdO_SgPVhhXnyNGC_VXSbIX-fxk1YY'
TOKEN = sys.argv[1]
data = {
"to": TOKEN,
"data" : {
"body": "SUCCESS! Sent from script :)",
"title": "Wix Example Project"
}
}
dataJson = json.dumps(data)
request = Request(
'https://gcm-http.googleapis.com/gcm/send',
dataJson,
{
"Authorization" : "key="+API_KEY,
"Content-type" : "application/json"
}
)
print "Sending notification..."
print urlopen(request).read()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment