Skip to content

Commit 141a374

Browse files
authored
feat(core): Avoids call reflection every time when we call getLocationManager. (#165)
1 parent 1a3e3b9 commit 141a374

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

AndroidSDKCore/src/main/java/com/leanplum/internal/ActionManager.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class ActionManager {
5454
private static final String LEANPLUM_LOCAL_PUSH_HELPER =
5555
"com.leanplum.internal.LeanplumLocalPushHelper";
5656
private static final String PREFERENCES_NAME = "__leanplum_messaging__";
57+
private static LocationManager locationManager;
5758
private static boolean loggedLocationManagerFailure = false;
5859

5960
public static class MessageMatchResult {
@@ -69,14 +70,19 @@ public static synchronized ActionManager getInstance() {
6970
return instance;
7071
}
7172

72-
public static LocationManager getLocationManager() {
73+
public static synchronized LocationManager getLocationManager() {
74+
if (locationManager != null) {
75+
return locationManager;
76+
}
77+
7378
if (Util.hasPlayServices()) {
7479
try {
7580
// Reflection here prevents linker errors
7681
// if Google Play Services is not used in the client app.
77-
return (LocationManager) Class
82+
locationManager = (LocationManager) Class
7883
.forName("com.leanplum.LocationManagerImplementation")
7984
.getMethod("instance").invoke(null);
85+
return locationManager;
8086
} catch (Throwable t) {
8187
if (!loggedLocationManagerFailure) {
8288
Log.w("Geofencing support requires leanplum-location module and Google Play " +

0 commit comments

Comments
 (0)