Skip to content

Commit 2a7e662

Browse files
committed
Merge remote-tracking branch 'origin/master' into release/5.4.2
2 parents 329e533 + f59c0eb commit 2a7e662

28 files changed

+323
-75
lines changed

AndroidSDKCore/src/main/java/com/leanplum/ActionContext.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,6 @@ public void runActionNamed(String name) {
369369
createActionContextForMessageId(messageAction.toString(), args, messageId, name, false);
370370
}
371371
}
372-
Leanplum.countAggregator().incrementCount("run_action_named");
373372
}
374373

375374
/**
@@ -527,7 +526,6 @@ public void runTrackedActionNamed(String name) {
527526
} catch (Throwable t) {
528527
Log.exception(t);
529528
}
530-
Leanplum.countAggregator().incrementCount("run_tracked_action_named");
531529
}
532530

533531
/**

AndroidSDKCore/src/main/java/com/leanplum/Leanplum.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.leanplum.callbacks.VariablesChangedCallback;
3535
import com.leanplum.internal.APIConfig;
3636
import com.leanplum.internal.ActionManager;
37+
import com.leanplum.internal.ApiConfigLoader;
3738
import com.leanplum.internal.Constants;
3839
import com.leanplum.internal.CountAggregator;
3940
import com.leanplum.internal.FeatureFlagManager;
@@ -277,6 +278,16 @@ public static void setAppIdForProductionMode(String appId, String accessKey) {
277278
APIConfig.getInstance().setAppId(appId, accessKey);
278279
}
279280

281+
/**
282+
* Loads appId and accessKey from Android resources.
283+
*/
284+
private static void loadApiConfigFromResources() {
285+
ApiConfigLoader loader = new ApiConfigLoader(getContext());
286+
loader.loadFromResources(
287+
Leanplum::setAppIdForProductionMode,
288+
Leanplum::setAppIdForDevelopmentMode);
289+
}
290+
280291
/**
281292
* Enable screen tracking.
282293
*/
@@ -291,7 +302,6 @@ public static void trackAllAppScreens() {
291302
*/
292303
public static void setVariantDebugInfoEnabled(boolean variantDebugInfoEnabled) {
293304
LeanplumInternal.setIsVariantDebugInfoEnabled(variantDebugInfoEnabled);
294-
countAggregator.incrementCount("set_variant_debug_info_enabled");
295305
}
296306

297307
/**
@@ -391,7 +401,6 @@ public static void syncResources() {
391401
} catch (Throwable t) {
392402
Log.exception(t);
393403
}
394-
countAggregator.incrementCount("sync_resources");
395404
}
396405

397406
/**
@@ -407,7 +416,6 @@ public static void syncResourcesAsync() {
407416
} catch (Throwable t) {
408417
Log.exception(t);
409418
}
410-
countAggregator.incrementCount("sync_resources");
411419
}
412420

413421
/**
@@ -429,7 +437,6 @@ public static void syncResources(
429437
} catch (Throwable t) {
430438
Log.exception(t);
431439
}
432-
countAggregator.incrementCount("sync_resource_paths");
433440
}
434441

435442
/**
@@ -451,7 +458,6 @@ public static void syncResourcesAsync(
451458
} catch (Throwable t) {
452459
Log.exception(t);
453460
}
454-
countAggregator.incrementCount("sync_resource_paths");
455461
}
456462

457463
/**
@@ -521,6 +527,11 @@ public static synchronized void start(final Context context, String userId,
521527
static synchronized void start(final Context context, final String userId,
522528
final Map<String, ?> attributes, StartCallback response, final Boolean isBackground) {
523529
try {
530+
boolean appIdNotSet = TextUtils.isEmpty(APIConfig.getInstance().appId());
531+
if (appIdNotSet) {
532+
loadApiConfigFromResources();
533+
}
534+
524535
LeanplumActivityHelper.setCurrentActivity(context);
525536

526537
// Detect if app is in background automatically if isBackground is not set.
@@ -616,7 +627,6 @@ public void run() {
616627
} catch (Throwable t) {
617628
Log.exception(t);
618629
}
619-
countAggregator.incrementCount("start_with_user_id");
620630
}
621631

622632
/**
@@ -750,7 +760,6 @@ public void error(Exception e) {
750760

751761
private static void handleStartResponse(final JSONObject response) {
752762
boolean success = RequestUtil.isResponseSuccess(response);
753-
Leanplum.countAggregator().incrementCount("on_start_response");
754763
if (!success) {
755764
try {
756765
LeanplumInternal.setHasStarted(true);
@@ -1455,7 +1464,6 @@ private static void defineAction(String name, int kind, ActionArgs args,
14551464
} catch (Throwable t) {
14561465
Log.exception(t);
14571466
}
1458-
Leanplum.countAggregator().incrementCount("define_action");
14591467
}
14601468

14611469
/**
@@ -1654,7 +1662,6 @@ private static void setTrafficSourceInfoInternal(HashMap<String, Object> params)
16541662
public static void track(final String event, double value, String info,
16551663
Map<String, ?> params) {
16561664
LeanplumInternal.track(event, value, info, params, null);
1657-
countAggregator.incrementCount("track");
16581665
}
16591666

16601667
/**
@@ -1853,9 +1860,6 @@ public static void track(String event, double value, String info) {
18531860
public static void trackGeofence(GeofenceEventType event, String info) {
18541861
if (featureFlagManager().isFeatureFlagEnabled("track_geofence")) {
18551862
LeanplumInternal.trackGeofence(event, 0.0, info, null, null);
1856-
countAggregator().incrementCount("track_geofence");
1857-
} else {
1858-
countAggregator().incrementCount("track_geofence_disabled");
18591863
}
18601864
}
18611865

@@ -1897,7 +1901,6 @@ public void run() {
18971901
} catch (Throwable t) {
18981902
Log.exception(t);
18991903
}
1900-
countAggregator.incrementCount("advance_to");
19011904
}
19021905

19031906
/**
@@ -2099,7 +2102,6 @@ public void error(Exception e) {
20992102
} catch (Throwable t) {
21002103
Log.exception(t);
21012104
}
2102-
countAggregator.incrementCount("force_content_update");
21032105
}
21042106

21052107
/**
@@ -2195,7 +2197,6 @@ public static Map<String, Object> getVariantDebugInfo() {
21952197
*/
21962198
public static void setDeviceLocation(Location location) {
21972199
setDeviceLocation(location, LeanplumLocationAccuracyType.CELL);
2198-
Leanplum.countAggregator().incrementCount("setDeviceLocation");
21992200
}
22002201

22012202
/**
@@ -2211,7 +2212,6 @@ public static void setDeviceLocation(Location location, LeanplumLocationAccuracy
22112212
"call setDeviceLocation. If you prefer to always set location manually, " +
22122213
"then call disableLocationCollection.");
22132214
}
2214-
Leanplum.countAggregator().incrementCount("setDeviceLocation_type");
22152215
LeanplumInternal.setUserLocationAttribute(location, type,
22162216
new LeanplumInternal.locationAttributeRequestsCallback() {
22172217
@Override
@@ -2254,7 +2254,6 @@ private static void parseVariantDebugInfo(JSONObject response) {
22542254
*/
22552255
public static void clearUserContent() {
22562256
VarCache.clearUserContent();
2257-
countAggregator.incrementCount("clear_user_content");
22582257
}
22592258

22602259
@VisibleForTesting

AndroidSDKCore/src/main/java/com/leanplum/LeanplumInbox.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,6 @@ private List<LeanplumInboxMessage> allMessages(List<LeanplumInboxMessage> messag
442442
} catch (Throwable t) {
443443
Log.exception(t);
444444
}
445-
Leanplum.countAggregator().incrementCount("all_messages_inbox");
446445
return messages;
447446
}
448447

AndroidSDKCore/src/main/java/com/leanplum/callbacks/RegisterDeviceCallback.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public void run() {
4747

4848
public void setResponseHandler(EmailCallback callback) {
4949
this.callback = callback;
50-
Leanplum.countAggregator().incrementCount("init_with_callback");
5150
}
5251

5352
public void run() { this.onResponse(callback);

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public void setAppId(String appId, String accessKey) {
5555
if (!TextUtils.isEmpty(accessKey)) {
5656
this.accessKey = accessKey.trim();
5757
}
58-
Leanplum.countAggregator().incrementCount("set_app_id");
5958
}
6059

6160
public void loadToken(String token) {
@@ -92,7 +91,6 @@ public String token() {
9291

9392
public void setToken(String token) {
9493
this.token = token;
95-
Leanplum.countAggregator().incrementCount("set_token");
9694
}
9795

9896
public void loadToken() {
@@ -104,7 +102,6 @@ public void loadToken() {
104102
return;
105103
}
106104
setToken(token);
107-
Leanplum.countAggregator().incrementCount("load_token");
108105
}
109106

110107
public void saveToken() {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ private static <T> ActionArg<T> argNamed(String name, T defaultValue, String kin
4747
arg.name = name;
4848
arg.kind = kind;
4949
arg.defaultValue = defaultValue;
50-
Leanplum.countAggregator().incrementCount("arg_named");
5150
return arg;
5251
}
5352

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,6 @@ public void recordMessageTrigger(String messageId) {
450450
int occurrences = getMessageTriggerOccurrences(messageId);
451451
occurrences++;
452452
saveMessageTriggerOccurrences(occurrences, messageId);
453-
Leanplum.countAggregator().incrementCount("record_message_trigger");
454453
}
455454

456455
/**
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright 2020, Leanplum, Inc. All rights reserved.
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
package com.leanplum.internal;
23+
24+
import android.content.Context;
25+
import android.text.TextUtils;
26+
27+
/**
28+
* Loads appId, accessKey and type of environment from the Android string resources.
29+
*/
30+
public class ApiConfigLoader {
31+
private static final String STRING_APPID = "leanplum_app_id";
32+
private static final String STRING_PROD_KEY = "leanplum_prod_key";
33+
private static final String STRING_DEV_KEY = "leanplum_dev_key";
34+
private static final String STRING_ENV = "leanplum_environment";
35+
36+
private static final String ENV_DEV = "development";
37+
private static final String ENV_PROD = "production";
38+
39+
private Context context;
40+
41+
@FunctionalInterface
42+
public interface KeyListener {
43+
void onKeysLoaded(String appId, String accessKey);
44+
}
45+
46+
public ApiConfigLoader(Context context) {
47+
this.context = context;
48+
}
49+
50+
private String getStringResource(String key) {
51+
try {
52+
String packageName = context.getPackageName();
53+
int id = context.getResources().getIdentifier(key, "string", packageName);
54+
return context.getString(id);
55+
} catch (Throwable t) { // Resources.NotFoundException
56+
Log.e("Cannot load string for key = %s. Message = %s", key, t.getMessage());
57+
return null;
58+
}
59+
}
60+
61+
public void loadFromResources(KeyListener prodKeyListener, KeyListener devKeyListener) {
62+
String appId = getStringResource(STRING_APPID);
63+
String prodKey = getStringResource(STRING_PROD_KEY);
64+
String devKey = getStringResource(STRING_DEV_KEY);
65+
String environment = getStringResource(STRING_ENV);
66+
67+
if (TextUtils.isEmpty(appId))
68+
return;
69+
70+
boolean devEnv = ENV_DEV.equals(environment);
71+
boolean hasProdKey = !TextUtils.isEmpty(prodKey);
72+
boolean hasDevKey = !TextUtils.isEmpty(devKey);
73+
74+
if (devEnv && hasDevKey) {
75+
devKeyListener.onKeysLoaded(appId, devKey);
76+
Log.i("Using appId and accessKey from Android resources for development environment.");
77+
}
78+
else if (!devEnv && hasProdKey) {
79+
prodKeyListener.onKeysLoaded(appId, prodKey);
80+
Log.i("Using appId and accessKey from Android resources for production environment.");
81+
}
82+
}
83+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
import java.util.Map;
99
import java.util.Set;
1010

11+
/**
12+
* Counter is not currently used and will be removed in the future.
13+
* It is still functional both on client and server side.
14+
*/
1115
public class CountAggregator {
1216
private Set<String> enabledCounters = new HashSet<>();
1317
private final Map<String, Integer> counts = new HashMap<>();

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public void setEnabledFeatureFlags(Set<String> enabledFeatureFlags) {
2424
}
2525

2626
public Boolean isFeatureFlagEnabled(String featureFlagName) {
27-
Leanplum.countAggregator().incrementCount("is_feature_flag_enabled");
2827
return this.enabledFeatureFlags.contains(featureFlagName);
2928
}
3029
}

0 commit comments

Comments
 (0)