49
49
50
50
import static com .appsflyer .appsflyersdk .AppsFlyerConstants .AF_EVENTS_CHANNEL ;
51
51
import static com .appsflyer .appsflyersdk .AppsFlyerConstants .AF_FAILURE ;
52
+ import static com .appsflyer .appsflyersdk .AppsFlyerConstants .AF_PLUGIN_TAG ;
52
53
import static com .appsflyer .appsflyersdk .AppsFlyerConstants .AF_SUCCESS ;
53
54
54
55
/**
@@ -203,7 +204,7 @@ private void startListening(Object arguments, Result rawResult) {
203
204
@ Override
204
205
public void onMethodCall (MethodCall call , Result result ) {
205
206
if (activity == null ) {
206
- Log .d ("AppsFlyer" , "Activity isn't attached to the flutter engine" );
207
+ Log .d (AF_PLUGIN_TAG , LogMessages . ACTIVITY_NOT_ATTACHED_TO_ENGINE );
207
208
return ;
208
209
}
209
210
final String method = call .method ;
@@ -362,11 +363,11 @@ private void performOnDeepLinking(MethodCall call, Result result) {
362
363
AppsFlyerLib .getInstance ().performOnDeepLinking (intent , mApplication );
363
364
result .success (null );
364
365
} else {
365
- Log .d ("AppsFlyer" , "performOnDeepLinking: intent is null!" );
366
+ Log .d (AF_PLUGIN_TAG , "performOnDeepLinking: intent is null!" );
366
367
result .error ("NO_INTENT" , "The intent is null" , null );
367
368
}
368
369
} else {
369
- Log .d ("AppsFlyer" , "performOnDeepLinking: activity is null!" );
370
+ Log .d (AF_PLUGIN_TAG , "performOnDeepLinking: activity is null!" );
370
371
result .error ("NO_ACTIVITY" , "The current activity is null" , null );
371
372
}
372
373
}
@@ -379,34 +380,37 @@ private void anonymizeUser(MethodCall call, Result result) {
379
380
380
381
private void startSDKwithHandler (MethodCall call , final Result result ) {
381
382
try {
382
- final AppsFlyerLib instance = AppsFlyerLib .getInstance ();
383
- instance .start (activity , null , new AppsFlyerRequestListener () {
383
+ final AppsFlyerLib appsFlyerLib = AppsFlyerLib .getInstance ();
384
+
385
+ appsFlyerLib .start (activity , null , new AppsFlyerRequestListener () {
384
386
@ Override
385
387
public void onSuccess () {
386
- uiThreadHandler . post ( new Runnable ( ) {
387
- @ Override
388
- public void run () {
389
- mMethodChannel . invokeMethod ( "onSuccess" , null );
390
- }
391
- });
388
+ if ( mMethodChannel != null ) {
389
+ uiThreadHandler . post (() -> mMethodChannel . invokeMethod ( "onSuccess" , null ));
390
+ } else {
391
+ Log . e ( AF_PLUGIN_TAG , LogMessages . METHOD_CHANNEL_IS_NULL );
392
+ result . error ( "NULL_OBJECT" , LogMessages . METHOD_CHANNEL_IS_NULL , null );
393
+ }
392
394
}
393
395
394
396
@ Override
395
397
public void onError (final int errorCode , final String errorMessage ) {
396
- uiThreadHandler .post (new Runnable () {
397
- @ Override
398
- public void run () {
398
+ if (mMethodChannel != null ) {
399
+ uiThreadHandler .post (() -> {
399
400
HashMap <String , Object > errorDetails = new HashMap <>();
400
401
errorDetails .put ("errorCode" , errorCode );
401
402
errorDetails .put ("errorMessage" , errorMessage );
402
403
mMethodChannel .invokeMethod ("onError" , errorDetails );
403
- }
404
- });
404
+ });
405
+ } else {
406
+ Log .e (AF_PLUGIN_TAG , LogMessages .METHOD_CHANNEL_IS_NULL );
407
+ result .error ("NULL_OBJECT" , LogMessages .METHOD_CHANNEL_IS_NULL , null );
408
+ }
405
409
}
406
410
});
407
411
result .success (null );
408
- } catch (Exception e ) {
409
- result .error ("UNEXPECTED_ERROR" , e .getMessage (), null );
412
+ } catch (Throwable t ) {
413
+ result .error ("UNEXPECTED_ERROR" , t .getMessage (), null );
410
414
}
411
415
}
412
416
@@ -532,14 +536,14 @@ private void sendPushNotificationData(MethodCall call, Result result) {
532
536
Bundle bundle ;
533
537
534
538
if (pushPayload == null ) {
535
- Log .d ("AppsFlyer" , "Push payload is null" );
539
+ Log .d (AF_PLUGIN_TAG , "Push payload is null" );
536
540
return ;
537
541
}
538
542
539
543
try {
540
544
bundle = this .jsonToBundle (new JSONObject (pushPayload ));
541
545
} catch (JSONException e ) {
542
- Log .d ("AppsFlyer" , "Can't parse pushPayload to bundle" );
546
+ Log .d (AF_PLUGIN_TAG , "Can't parse pushPayload to bundle" );
543
547
return ;
544
548
}
545
549
@@ -557,7 +561,7 @@ private void sendPushNotificationData(MethodCall call, Result result) {
557
561
}
558
562
559
563
if (errorMsg != null ) {
560
- Log .d ("AppsFlyer" , errorMsg );
564
+ Log .d (AF_PLUGIN_TAG , errorMsg );
561
565
return ;
562
566
}
563
567
@@ -963,8 +967,8 @@ private void logAdRevenue(MethodCall call, Result result) {
963
967
try {
964
968
String monetizationNetwork = requireNonNullArgument (call , "monetizationNetwork" );
965
969
String currencyIso4217Code = requireNonNullArgument (call , "currencyIso4217Code" );
966
- double revenue = requireNonNullArgument (call ,"revenue" );
967
- String mediationNetworkString = requireNonNullArgument (call ,"mediationNetwork" );
970
+ double revenue = requireNonNullArgument (call , "revenue" );
971
+ String mediationNetworkString = requireNonNullArgument (call , "mediationNetwork" );
968
972
969
973
MediationNetwork mediationNetwork = MediationNetwork .valueOf (mediationNetworkString .toUpperCase ());
970
974
@@ -984,10 +988,9 @@ private void logAdRevenue(MethodCall call, Result result) {
984
988
} catch (IllegalArgumentException e ) {
985
989
// The IllegalArgumentException could come from either requireNonNullArgument or valueOf methods.
986
990
result .error ("INVALID_ARGUMENT_PROVIDED" , e .getMessage (), null );
987
- }
988
- catch (Throwable t ) {
991
+ } catch (Throwable t ) {
989
992
result .error ("UNEXPECTED_ERROR" , "[logAdRevenue]: An unexpected error occurred: " + t .getMessage (), null );
990
- Log .e ("AppsFlyer" , "Unexpected exception occurred: [logAdRevenue]" , t );
993
+ Log .e (AF_PLUGIN_TAG , "Unexpected exception occurred: [logAdRevenue]" , t );
991
994
}
992
995
}
993
996
@@ -1004,7 +1007,7 @@ private void logAdRevenue(MethodCall call, Result result) {
1004
1007
private <T > T requireNonNullArgument (MethodCall call , String argumentName ) throws IllegalArgumentException {
1005
1008
T argument = call .argument (argumentName );
1006
1009
if (argument == null ) {
1007
- Log .e ("AppsFlyer" , "Exception occurred when trying to: " + call .method + "->" + argumentName + " must not be null" );
1010
+ Log .e (AF_PLUGIN_TAG , "Exception occurred when trying to: " + call .method + "->" + argumentName + " must not be null" );
1008
1011
throw new IllegalArgumentException ("[" + call .method + "]: " + argumentName + " must not be null" );
1009
1012
}
1010
1013
return argument ;
0 commit comments