Skip to content

Commit

Permalink
Merge pull request #357 from AppsFlyerSDK/DELIVERY-63011/fix-android-…
Browse files Browse the repository at this point in the history
…null-pointer-exception

This should fix the NullPointerException
  • Loading branch information
Dani-Koza-AF authored Oct 30, 2024
2 parents a58a49b + 25fb530 commit 4f4ee27
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
package com.appsflyer.appsflyersdk;

public class AppsFlyerConstants {
final static String PLUGIN_VERSION = "6.15.1";
final static String AF_APP_INVITE_ONE_LINK = "appInviteOneLink";
final static String AF_HOST_PREFIX = "hostPrefix";
final static String AF_HOST_NAME = "hostName";
final static String AF_IS_DEBUG = "isDebug";
final static String AF_MANUAL_START = "manualStart";
final static String AF_DEV_KEY = "afDevKey";
final static String AF_EVENT_NAME = "eventName";
final static String AF_EVENT_VALUES = "eventValues";
final static String AF_ON_INSTALL_CONVERSION_DATA_LOADED = "onInstallConversionDataLoaded";
final static String AF_ON_APP_OPEN_ATTRIBUTION = "onAppOpenAttribution";
final static String AF_SUCCESS = "success";
final static String AF_FAILURE = "failure";
final static String AF_GCD = "GCD";
final static String AF_UDL = "UDL";
final static String AF_VALIDATE_PURCHASE = "validatePurchase";
final static String AF_GCD_CALLBACK = "onInstallConversionData";
final static String AF_OAOA_CALLBACK = "onAppOpenAttribution";
final static String AF_UDL_CALLBACK = "onDeepLinking";
final static String DISABLE_ADVERTISING_IDENTIFIER = "disableAdvertisingIdentifier";
public final class AppsFlyerConstants {
final static String PLUGIN_VERSION = "6.15.1";
final static String AF_APP_INVITE_ONE_LINK = "appInviteOneLink";
final static String AF_HOST_PREFIX = "hostPrefix";
final static String AF_HOST_NAME = "hostName";
final static String AF_IS_DEBUG = "isDebug";
final static String AF_MANUAL_START = "manualStart";
final static String AF_DEV_KEY = "afDevKey";
final static String AF_EVENT_NAME = "eventName";
final static String AF_EVENT_VALUES = "eventValues";
final static String AF_ON_INSTALL_CONVERSION_DATA_LOADED = "onInstallConversionDataLoaded";
final static String AF_ON_APP_OPEN_ATTRIBUTION = "onAppOpenAttribution";
final static String AF_SUCCESS = "success";
final static String AF_FAILURE = "failure";
final static String AF_GCD = "GCD";
final static String AF_UDL = "UDL";
final static String AF_VALIDATE_PURCHASE = "validatePurchase";
final static String AF_GCD_CALLBACK = "onInstallConversionData";
final static String AF_OAOA_CALLBACK = "onAppOpenAttribution";
final static String AF_UDL_CALLBACK = "onDeepLinking";
final static String DISABLE_ADVERTISING_IDENTIFIER = "disableAdvertisingIdentifier";

final static String AF_EVENTS_CHANNEL = "af-events";
final static String AF_METHOD_CHANNEL = "af-api";
final static String AF_CALLBACK_CHANNEL = "callbacks";
final static String AF_EVENTS_CHANNEL = "af-events";
final static String AF_METHOD_CHANNEL = "af-api";
final static String AF_CALLBACK_CHANNEL = "callbacks";

final static String AF_BROADCAST_ACTION_NAME = "com.appsflyer.appsflyersdk";
final static String AF_BROADCAST_ACTION_NAME = "com.appsflyer.appsflyersdk";

final static String AF_PLUGIN_TAG = "AppsFlyer_FlutterPlugin";
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

import static com.appsflyer.appsflyersdk.AppsFlyerConstants.AF_EVENTS_CHANNEL;
import static com.appsflyer.appsflyersdk.AppsFlyerConstants.AF_FAILURE;
import static com.appsflyer.appsflyersdk.AppsFlyerConstants.AF_PLUGIN_TAG;
import static com.appsflyer.appsflyersdk.AppsFlyerConstants.AF_SUCCESS;

/**
Expand Down Expand Up @@ -203,7 +204,7 @@ private void startListening(Object arguments, Result rawResult) {
@Override
public void onMethodCall(MethodCall call, Result result) {
if (activity == null) {
Log.d("AppsFlyer", "Activity isn't attached to the flutter engine");
Log.d(AF_PLUGIN_TAG, LogMessages.ACTIVITY_NOT_ATTACHED_TO_ENGINE);
return;
}
final String method = call.method;
Expand Down Expand Up @@ -362,11 +363,11 @@ private void performOnDeepLinking(MethodCall call, Result result) {
AppsFlyerLib.getInstance().performOnDeepLinking(intent, mApplication);
result.success(null);
} else {
Log.d("AppsFlyer", "performOnDeepLinking: intent is null!");
Log.d(AF_PLUGIN_TAG, "performOnDeepLinking: intent is null!");
result.error("NO_INTENT", "The intent is null", null);
}
} else {
Log.d("AppsFlyer", "performOnDeepLinking: activity is null!");
Log.d(AF_PLUGIN_TAG, "performOnDeepLinking: activity is null!");
result.error("NO_ACTIVITY", "The current activity is null", null);
}
}
Expand All @@ -379,34 +380,37 @@ private void anonymizeUser(MethodCall call, Result result) {

private void startSDKwithHandler(MethodCall call, final Result result) {
try {
final AppsFlyerLib instance = AppsFlyerLib.getInstance();
instance.start(activity, null, new AppsFlyerRequestListener() {
final AppsFlyerLib appsFlyerLib = AppsFlyerLib.getInstance();

appsFlyerLib.start(activity, null, new AppsFlyerRequestListener() {
@Override
public void onSuccess() {
uiThreadHandler.post(new Runnable() {
@Override
public void run() {
mMethodChannel.invokeMethod("onSuccess", null);
}
});
if (mMethodChannel != null) {
uiThreadHandler.post(() -> mMethodChannel.invokeMethod("onSuccess", null));
} else {
Log.e(AF_PLUGIN_TAG, LogMessages.METHOD_CHANNEL_IS_NULL);
result.error("NULL_OBJECT", LogMessages.METHOD_CHANNEL_IS_NULL, null);
}
}

@Override
public void onError(final int errorCode, final String errorMessage) {
uiThreadHandler.post(new Runnable() {
@Override
public void run() {
if (mMethodChannel != null) {
uiThreadHandler.post(() -> {
HashMap<String, Object> errorDetails = new HashMap<>();
errorDetails.put("errorCode", errorCode);
errorDetails.put("errorMessage", errorMessage);
mMethodChannel.invokeMethod("onError", errorDetails);
}
});
});
} else {
Log.e(AF_PLUGIN_TAG, LogMessages.METHOD_CHANNEL_IS_NULL);
result.error("NULL_OBJECT", LogMessages.METHOD_CHANNEL_IS_NULL, null);
}
}
});
result.success(null);
} catch (Exception e) {
result.error("UNEXPECTED_ERROR", e.getMessage(), null);
} catch (Throwable t) {
result.error("UNEXPECTED_ERROR", t.getMessage(), null);
}
}

Expand Down Expand Up @@ -532,14 +536,14 @@ private void sendPushNotificationData(MethodCall call, Result result) {
Bundle bundle;

if (pushPayload == null) {
Log.d("AppsFlyer", "Push payload is null");
Log.d(AF_PLUGIN_TAG, "Push payload is null");
return;
}

try {
bundle = this.jsonToBundle(new JSONObject(pushPayload));
} catch (JSONException e) {
Log.d("AppsFlyer", "Can't parse pushPayload to bundle");
Log.d(AF_PLUGIN_TAG, "Can't parse pushPayload to bundle");
return;
}

Expand All @@ -557,7 +561,7 @@ private void sendPushNotificationData(MethodCall call, Result result) {
}

if (errorMsg != null) {
Log.d("AppsFlyer", errorMsg);
Log.d(AF_PLUGIN_TAG, errorMsg);
return;
}

Expand Down Expand Up @@ -963,8 +967,8 @@ private void logAdRevenue(MethodCall call, Result result) {
try {
String monetizationNetwork = requireNonNullArgument(call, "monetizationNetwork");
String currencyIso4217Code = requireNonNullArgument(call, "currencyIso4217Code");
double revenue = requireNonNullArgument(call,"revenue");
String mediationNetworkString = requireNonNullArgument(call,"mediationNetwork");
double revenue = requireNonNullArgument(call, "revenue");
String mediationNetworkString = requireNonNullArgument(call, "mediationNetwork");

MediationNetwork mediationNetwork = MediationNetwork.valueOf(mediationNetworkString.toUpperCase());

Expand All @@ -984,10 +988,9 @@ private void logAdRevenue(MethodCall call, Result result) {
} catch (IllegalArgumentException e) {
// The IllegalArgumentException could come from either requireNonNullArgument or valueOf methods.
result.error("INVALID_ARGUMENT_PROVIDED", e.getMessage(), null);
}
catch (Throwable t) {
} catch (Throwable t) {
result.error("UNEXPECTED_ERROR", "[logAdRevenue]: An unexpected error occurred: " + t.getMessage(), null);
Log.e("AppsFlyer", "Unexpected exception occurred: [logAdRevenue]", t);
Log.e(AF_PLUGIN_TAG, "Unexpected exception occurred: [logAdRevenue]", t);
}
}

Expand All @@ -1004,7 +1007,7 @@ private void logAdRevenue(MethodCall call, Result result) {
private <T> T requireNonNullArgument(MethodCall call, String argumentName) throws IllegalArgumentException {
T argument = call.argument(argumentName);
if (argument == null) {
Log.e("AppsFlyer", "Exception occurred when trying to: " + call.method + "->" + argumentName + " must not be null");
Log.e(AF_PLUGIN_TAG, "Exception occurred when trying to: " + call.method + "->" + argumentName + " must not be null");
throw new IllegalArgumentException("[" + call.method + "]: " + argumentName + " must not be null");
}
return argument;
Expand Down
12 changes: 12 additions & 0 deletions android/src/main/java/com/appsflyer/appsflyersdk/LogMessages.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.appsflyer.appsflyersdk;

public final class LogMessages {

// Prevent the instantiation of this utilities class.
private LogMessages() {
throw new IllegalStateException("LogMessages class should not be instantiated");
}

public static final String METHOD_CHANNEL_IS_NULL = "mMethodChannel is null, cannot invoke the callback";
public static final String ACTIVITY_NOT_ATTACHED_TO_ENGINE = "Activity isn't attached to the flutter engine";
}

0 comments on commit 4f4ee27

Please sign in to comment.