Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ private void reportMetadataEvent() {
String language = deviceInfoProvider.getDeviceLanguage()
.replace('_', '-').toLowerCase();
Location location = deviceInfoProvider.getDeviceLocation(context);
String cityName = null;
String locationLongitude = null;
String locationLatitude = null;

if (location != null) {
cityName = deviceInfoProvider.getCityNameFromLocation(context, location);
locationLongitude = String.valueOf(location.getLongitude());
locationLatitude = String.valueOf(location.getLatitude());
}
Expand All @@ -60,7 +58,7 @@ private void reportMetadataEvent() {
.withSdkPlatform("Android")
.withSdkVersion(BuildConfig.OPTIMOVE_VERSION_NAME)
.withAppNs(packageName)
.withLocation(cityName)
.withLocation(null)
.withLocationLongitude(locationLongitude)
.withLocationLatitude(locationLatitude)
.withIp(deviceInfoProvider.getIP(context))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
package com.optimove.android.main.tools;

import android.content.Context;
import android.location.Address;
import android.location.Criteria;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationManager;
import android.net.wifi.WifiManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.optimove.android.main.tools.opti_logger.OptiLoggerStreamsContainer;

import java.io.IOException;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.ByteOrder;
import java.util.List;
import java.util.Locale;

import static android.content.Context.LOCATION_SERVICE;
Expand Down Expand Up @@ -82,21 +77,6 @@ public Location getDeviceLocation(Context context) {
}
}

public String getCityNameFromLocation(Context context, @NonNull Location location){
Geocoder gcd = new Geocoder(context, Locale.ENGLISH);

try {
List<Address> addresses = gcd.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
if (addresses.size() > 0) {
return addresses.get(0).getLocality();
} else {
return null;
}
} catch (IOException e) {
return null;
}
}

@Nullable
public String getUserAgent(){
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ private static void associateUserWithInstallImpl(Context context, @NonNull final
* @param context
*/
public static void pushRequestDeviceToken(Context context) {
// Check if SDK is initialized before using executorService
if (!initialized || executorService == null) {
log(TAG, "Optimobile SDK not initialized, skipping push token request");
return;
}

PushRegistration.RegisterTask task = new PushRegistration.RegisterTask(context);
executorService.submit(task);
}
Expand All @@ -264,6 +270,12 @@ public static void pushRequestDeviceToken(Context context) {
* @param context
*/
public static void pushUnregister(Context context) {
// Check if SDK is initialized before using executorService
if (!initialized || executorService == null) {
log(TAG, "Optimobile SDK not initialized, skipping push unregister");
return;
}

PushRegistration.UnregisterTask task = new PushRegistration.UnregisterTask(context);
executorService.submit(task);
}
Expand Down Expand Up @@ -522,6 +534,12 @@ static void trackEvent(@NonNull final Context context, @NonNull final String eve
throw new IllegalArgumentException("Optimobile.trackEvent expects a non-empty event type");
}

// Check if SDK is properly initialized
if (!initialized) {
log(TAG, "Optimobile SDK not initialized, skipping event tracking: " + eventType);
return;
}

Runnable trackingTask = new AnalyticsContract.TrackEventRunnable(context, eventType, timestamp, properties, immediateFlush);
executorService.submit(trackingTask);
}
Expand All @@ -535,6 +553,12 @@ static void trackEventImmediately(@NonNull final Context context, @NonNull final
}

private static void flushEvents(@NonNull final Context context) {
// Check if SDK is initialized before using executorService
if (!initialized || executorService == null) {
log(TAG, "Optimobile SDK not initialized, skipping event flush");
return;
}

Runnable flushingTask = new AnalyticsContract.FlushEventsRunnable(context);
executorService.submit(flushingTask);
}
Expand All @@ -544,6 +568,12 @@ private static void maybeTriggerInAppSync(Context context) {
return;
}

// Check if SDK is initialized before using executorService
if (!initialized || executorService == null) {
log(TAG, "Optimobile SDK not initialized, skipping in-app sync");
return;
}

Optimobile.executorService.submit(new Runnable() {
@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ protected void onPushReceived(Context context, PushMessage pushMessage) {
this.onBackgroundPush(context, pushMessage);
}

if (pushMessage.hasTitleAndMessage() && NotificationManagerCompat.from(context).areNotificationsEnabled()) {
// Don't show notifications for tickle pushes - they should remain silent even if they have title/message content
if (pushMessage.hasTitleAndMessage() && NotificationManagerCompat.from(context).areNotificationsEnabled() && pushMessage.getTickleId() == -1) {
processPushMessage(context, pushMessage);
}
}
Expand Down Expand Up @@ -152,6 +153,12 @@ protected void maybeTriggerInAppSync(Context context, PushMessage pushMessage) {
return;
}

// Check if SDK is initialized before using executorService
if (!Optimobile.isInitialized() || Optimobile.executorService == null) {
Optimobile.log(TAG, "Optimobile SDK not initialized, skipping in-app sync");
return;
}

Optimobile.executorService.submit(new Runnable() {
@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ private boolean isLaunchActivity(Context context, Activity activity) {
return false;
}

return component.getClassName().equals(activity.getComponentName().getClassName());
ComponentName activityComponent = activity.getComponentName();
if (activityComponent == null) {
return false;
}

return component.getClassName().equals(activityComponent.getClassName());
}


Expand Down
Loading