Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Don't call LifeCycleTracking for build < 14 #48

Merged
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 @@ -3,9 +3,9 @@
import android.app.Application;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;

import com.microsoft.applicationinsights.library.config.ApplicationInsightsConfig;
import com.microsoft.applicationinsights.logging.InternalLogging;

Expand Down Expand Up @@ -200,15 +200,19 @@ public void startInstance() {

// Initialize Telemetry
TelemetryClient.initialize(!telemetryDisabled);
LifeCycleTracking.initialize(telemetryContext, this.config);
Application application = INSTANCE.getApplication();
LifeCycleTracking.registerForPersistingWhenInBackground(application);
if (INSTANCE.getApplication() != null && !this.autoCollectionDisabled) {

if (INSTANCE.getApplication() != null &&
Util.isLifecycleTrackingAvailable() &&
!this.autoCollectionDisabled) {
LifeCycleTracking.initialize(telemetryContext, this.config);
LifeCycleTracking.registerForPersistingWhenInBackground(application);
LifeCycleTracking.registerPageViewCallbacks(application);
LifeCycleTracking.registerSessionManagementCallbacks(application);
} else {
InternalLogging.warn(TAG, "Auto collection of page views could not be " +
"started, since the given application was null");
"started. Either the given application was null, the device API level " +
"is lower than 14, or the user actively disabled the feature.");
}

// Start crash reporting
Expand Down Expand Up @@ -251,7 +255,7 @@ public static void enableActivityTracking(Application application) {
return;
}
if (!INSTANCE.telemetryDisabled) {
if(application != null){
if(application != null && Util.isLifecycleTrackingAvailable()){
LifeCycleTracking.registerActivityLifecycleCallbacks(application);
}
}
Expand All @@ -269,8 +273,11 @@ public static void enableAutoPageViewTracking() {
return;
} else if (INSTANCE.getApplication() == null) {
InternalLogging.warn(TAG, "Could not set page view tracking, because " +
"ApplicationInsights has not been setup with an application.");
"ApplicationInsights has not been setup with an application.");
return;
} else if (!Util.isLifecycleTrackingAvailable()) {
InternalLogging.warn(TAG, "Could not set page view tracking, because " +
"it is not supported on this OS version.");
} else {
LifeCycleTracking.registerPageViewCallbacks(INSTANCE.getApplication());
}
Expand All @@ -290,6 +297,9 @@ public static void disableAutoPageViewTracking() {
InternalLogging.warn(TAG, "Could not unset page view tracking, because " +
"ApplicationInsights has not been setup with an application.");
return;
} else if (!Util.isLifecycleTrackingAvailable()) {
InternalLogging.warn(TAG, "Could not unset page view tracking, because " +
"it is not supported on this OS version.");
} else {
LifeCycleTracking.unregisterPageViewCallbacks(INSTANCE.getApplication());
}
Expand All @@ -309,6 +319,9 @@ public static void enableAutoSessionManagement() {
InternalLogging.warn(TAG, "Could not set session management, because " +
"ApplicationInsights has not been setup with an application.");
return;
} else if (!Util.isLifecycleTrackingAvailable()) {
InternalLogging.warn(TAG, "Could not set session management, because " +
"it is not supported on this OS version.");
} else {
LifeCycleTracking.registerSessionManagementCallbacks(INSTANCE.getApplication());
}
Expand All @@ -328,6 +341,9 @@ public static void disableAutoSessionManagement() {
InternalLogging.warn(TAG, "Could not unset session management, because " +
"ApplicationInsights has not been setup with an application.");
return;
} else if (!Util.isLifecycleTrackingAvailable()) {
InternalLogging.warn(TAG, "Could not unset session management, because " +
"it is not supported on this OS version.");
} else {
LifeCycleTracking.unregisterSessionManagementCallbacks(INSTANCE.getApplication());
}
Expand Down