Skip to content

Commit ac6fd8f

Browse files
authored
[SDK-747] : Null checks added for application and context in push service (#75)
* Null checks added for application and context in push service * Changes in messaging service * SDK version updated * Change linebreak to LF
1 parent 6406f66 commit ac6fd8f

File tree

7 files changed

+33
-16
lines changed

7 files changed

+33
-16
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 20.11.15
2+
* Adding a mitigation when app is killed and received push notifications.
3+
* Underlying android SDK version is 20.11.12
4+
* Underlying iOS SDK version is 20.11.3
5+
16
## 20.11.14
27
* Fixed a bug that threw an exception when logging a warning for "setUserData".
38
* Underlying android SDK version is 20.11.12

CountlyReactNative.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'CountlyReactNative'
3-
s.version = '20.11.14'
3+
s.version = '20.11.15'
44
s.license = {
55
:type => 'COMMUNITY',
66
:text => <<-LICENSE

android/src/main/java/ly/count/android/sdk/react/CountlyMessagingService.java

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package ly.count.android.sdk.react;
22

3+
import android.app.Application;
4+
import android.content.Context;
35
import android.content.Intent;
46
import android.util.Log;
57

@@ -25,19 +27,27 @@ public void onNewToken(String token) {
2527
@Override
2628
public void onMessageReceived(RemoteMessage remoteMessage) {
2729
super.onMessageReceived(remoteMessage);
30+
if(Countly.sharedInstance().isLoggingEnabled()) {
31+
Log.d(Countly.TAG, "[CountlyMessagingService] got new message: " + remoteMessage.getData().toString());
32+
}
33+
CountlyReactNative.onNotification(remoteMessage.getData());
34+
2835

2936
if(!Countly.sharedInstance().isInitialized()) {
3037
int mode = CountlyPush.getLastMessagingMethod(this);
31-
if(mode == 0) {
32-
CountlyPush.init(getApplication(), Countly.CountlyMessagingMode.TEST);
33-
} else if(mode == 1) {
34-
CountlyPush.init(getApplication(), Countly.CountlyMessagingMode.PRODUCTION);
38+
Application application = getApplication();
39+
if(application == null){
40+
Log.d(Countly.TAG, "[CountlyMessagingService] getApplication() returns null: application must be non-null to init CountlyPush");
41+
}
42+
else {
43+
if(mode == 0) {
44+
CountlyPush.init(application, Countly.CountlyMessagingMode.TEST);
45+
} else if(mode == 1) {
46+
CountlyPush.init(application, Countly.CountlyMessagingMode.PRODUCTION);
47+
}
3548
}
3649
}
3750

38-
if(Countly.sharedInstance().isLoggingEnabled()) {
39-
Log.d(Countly.TAG, "[CountlyMessagingService] got new message: " + remoteMessage.getData().toString());
40-
}
4151

4252
// decode message data and extract meaningful information from it: title, body, badge, etc.
4353
CountlyPush.Message message = CountlyPush.decodeMessage(remoteMessage.getData());
@@ -47,8 +57,12 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
4757
// message.recordAction(getApplicationContext());
4858
// return;
4959
// }
50-
51-
Boolean result = CountlyPush.displayNotification(getApplicationContext(), message, getApplicationContext().getApplicationInfo().icon, null);
60+
Context context = getApplicationContext();
61+
if(context == null){
62+
Log.d(Countly.TAG, "[CountlyMessagingService] getApplicationContext() returns null: context must be non-null to displayNotification");
63+
return;
64+
}
65+
Boolean result = CountlyPush.displayNotification(context, message, context.getApplicationInfo().icon, null);
5266
if(Countly.sharedInstance().isLoggingEnabled()) {
5367
if (result == null) {
5468
Log.i(Countly.TAG, "[CountlyMessagingService] Message wasn't sent from Countly server, so it cannot be handled by Countly SDK");
@@ -58,8 +72,6 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
5872
Log.i(Countly.TAG, "[CountlyMessagingService] Message wasn't handled by Countly SDK because API level is too low for Notification support or because currentActivity is null (not enough lifecycle method calls)");
5973
}
6074
}
61-
62-
CountlyReactNative.onNotification(remoteMessage.getData());
6375
}
6476

6577
@Override

android/src/main/java/ly/count/android/sdk/react/CountlyReactNative.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public String toString(){
7575
public class CountlyReactNative extends ReactContextBaseJavaModule implements LifecycleEventListener {
7676

7777
public static final String TAG = "CountlyRNPlugin";
78-
private String COUNTLY_RN_SDK_VERSION_STRING = "20.11.14";
78+
private String COUNTLY_RN_SDK_VERSION_STRING = "20.11.15";
7979
private String COUNTLY_RN_SDK_NAME = "js-rnb-android";
8080

8181
private static CountlyConfig config = new CountlyConfig();

example/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ rm App.js
1111
curl https://raw.githubusercontent.com/Countly/countly-sdk-react-native-bridge/master/example/App.js --output App.js
1212
curl https://raw.githubusercontent.com/Countly/countly-sdk-react-native-bridge/master/example/Example.js --output Example.js
1313

14-
yarn add [email protected].14
14+
yarn add [email protected].15
1515

1616
cd ./ios
1717
pod install

ios/src/CountlyReactNative.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ @interface CountlyFeedbackWidget ()
2121
+ (CountlyFeedbackWidget *)createWithDictionary:(NSDictionary *)dictionary;
2222
@end
2323

24-
NSString* const kCountlyReactNativeSDKVersion = @"20.11.14";
24+
NSString* const kCountlyReactNativeSDKVersion = @"20.11.15";
2525
NSString* const kCountlyReactNativeSDKName = @"js-rnb-ios";
2626

2727
CountlyConfig* config = nil;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "countly-sdk-react-native-bridge",
3-
"version": "20.11.14",
3+
"version": "20.11.15",
44
"author": "Countly <[email protected]> (https://count.ly/)",
55
"bugs": {
66
"url": "https://github.com/Countly/countly-sdk-react-native-bridge/issues"

0 commit comments

Comments
 (0)