Skip to content

Commit 1910cfd

Browse files
authored
Merge pull request #399 from Countly/content_checks
[Android] fix content and test
2 parents a507dd9 + 1e72480 commit 1910cfd

File tree

5 files changed

+55
-43
lines changed

5 files changed

+55
-43
lines changed

CHANGELOG.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
* Disabled caching for webviews.
33
* Expanded the flag (enablePreviousNameRecording) to add current view name as segmentation to custom events. (Experimental!)
44

5-
* Mitigated an issue where a session could have started while the app was in the background when the device ID was changed (non-merge).
6-
* Mitigated an issue where content fetching was enabled after initialization of the SDK.
7-
85
* Fixed an issue where the validation of the parameters during content retrieval was improper.
6+
* Mitigated an issue where a session could have started while the app was in the background when the device ID was changed (non-merge).
97
* Mitigated an issue that density calculation was missing while resizing content.
8+
* Mitigated an issue where content fetching was enabled after initialization of the SDK.
109

1110
## 24.7.3
1211
* Automatic view pause/resumes are changed with stop/start for better data consistency.

sdk/src/main/java/ly/count/android/sdk/ConnectionQueue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ public String prepareFetchContents(int portraitWidth, int portraitHeight, int la
841841
L.e("Error while preparing fetch contents request");
842842
}
843843

844-
return prepareCommonRequestData() + "&method=queue" + "&category=" + Arrays.asList(categories) + "&res=" + UtilsNetworking.urlEncodeString(json.toString());
844+
return prepareCommonRequestData() + "&method=queue" + "&category=" + Arrays.asList(categories) + "&resolution=" + UtilsNetworking.urlEncodeString(json.toString());
845845
}
846846

847847
@Override

sdk/src/main/java/ly/count/android/sdk/CountlyWebViewClient.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ly.count.android.sdk;
22

3+
import android.util.Log;
34
import android.webkit.WebResourceRequest;
45
import android.webkit.WebResourceResponse;
56
import android.webkit.WebView;
@@ -29,13 +30,23 @@ public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request
2930
}
3031

3132
@Override
32-
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
33-
return null;
34-
}
33+
public WebResourceResponse shouldInterceptRequest(WebView view, String url) { return null ; }
3534

3635
@Override
3736
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
38-
return null;
37+
String url = request.getUrl().toString();
38+
Log.d(Countly.TAG, "[WebClient] Intercepted request URL: [" + url + "]");
39+
40+
// Call listeners for specific actions
41+
for (WebViewUrlListener listener : listeners) {
42+
boolean handled = listener.onUrl(url, view);
43+
if (handled) {
44+
Log.d(Countly.TAG, "Request handled by listener: " + url);
45+
break;
46+
}
47+
}
48+
49+
return super.shouldInterceptRequest(view, request);
3950
}
4051

4152
public void registerWebViewUrlListeners(List<WebViewUrlListener> listener) {

sdk/src/main/java/ly/count/android/sdk/ModuleContent.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,26 +125,27 @@ private String prepareContentFetchRequest(@NonNull DisplayMetrics displayMetrics
125125
}
126126

127127
boolean validateResponse(@NonNull JSONObject response) {
128-
boolean success = response.optString("result", "error").equals("success");
129-
JSONArray content = response.optJSONArray("content");
130-
return success && content != null && content.length() > 0;
128+
return response.has("geo");
129+
//boolean success = response.optString("result", "error").equals("success");
130+
//JSONArray content = response.optJSONArray("content");
131+
//return success && content != null && content.length() > 0;
131132
}
132133

133134
@NonNull
134135
Map<Integer, TransparentActivityConfig> parseContent(@NonNull JSONObject response, @NonNull DisplayMetrics displayMetrics) {
135136
Map<Integer, TransparentActivityConfig> placementCoordinates = new ConcurrentHashMap<>();
136137
JSONArray contents = response.optJSONArray("content");
137-
assert contents != null;
138+
//assert contents != null; TODO enable later
138139

139-
JSONObject contentObj = contents.optJSONObject(0);
140+
JSONObject contentObj = response; //contents.optJSONObject(0); TODO this will be changed
140141
assert contentObj != null;
141142

142-
String content = contentObj.optString("pathToHtml");
143-
JSONObject coordinates = contentObj.optJSONObject("placementCoordinates");
143+
String content = contentObj.optString("html");
144+
JSONObject coordinates = contentObj.optJSONObject("geo");
144145

145146
assert coordinates != null;
146-
placementCoordinates.put(Configuration.ORIENTATION_PORTRAIT, extractOrientationPlacements(coordinates, displayMetrics.density, "portrait", content));
147-
placementCoordinates.put(Configuration.ORIENTATION_LANDSCAPE, extractOrientationPlacements(coordinates, displayMetrics.density, "landscape", content));
147+
placementCoordinates.put(Configuration.ORIENTATION_PORTRAIT, extractOrientationPlacements(coordinates, displayMetrics.density, "p", content));
148+
placementCoordinates.put(Configuration.ORIENTATION_LANDSCAPE, extractOrientationPlacements(coordinates, displayMetrics.density, "l", content));
148149

149150
return placementCoordinates;
150151
}
@@ -155,8 +156,8 @@ private TransparentActivityConfig extractOrientationPlacements(@NonNull JSONObje
155156
assert orientationPlacements != null;
156157
int x = orientationPlacements.optInt("x");
157158
int y = orientationPlacements.optInt("y");
158-
int w = orientationPlacements.optInt("width");
159-
int h = orientationPlacements.optInt("height");
159+
int w = orientationPlacements.optInt("w");
160+
int h = orientationPlacements.optInt("h");
160161
L.d("[ModuleContent] extractOrientationPlacements, orientation: [" + orientation + "], x: [" + x + "], y: [" + y + "], w: [" + w + "], h: [" + h + "]");
161162

162163
TransparentActivityConfig config = new TransparentActivityConfig((int) Math.ceil(x * density), (int) Math.ceil(y * density), (int) Math.ceil(w * density), (int) Math.ceil(h * density));

sdk/src/main/java/ly/count/android/sdk/TransparentActivity.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -181,39 +181,40 @@ private boolean contentUrlAction(String url, TransparentActivityConfig config, W
181181
Map<String, Object> query = splitQuery(url);
182182
Log.v(Countly.TAG, "[TransparentActivity] contentUrlAction, query: [" + query + "]");
183183

184-
Object clyEvent = query.get("cly_x_action_event");
184+
Object clyEvent = query.get("?cly_x_action_event");
185185

186186
if (clyEvent == null || !clyEvent.equals("1")) {
187-
Log.w(Countly.TAG, "[TransparentActivity] contentUrlAction, this is not a countly action event url");
188-
return false;
189-
}
190-
Object clyAction = query.get("action");
191-
if (!(clyAction instanceof String)) {
192-
Log.w(Countly.TAG, "[TransparentActivity] contentUrlAction, action is not a string");
187+
Log.w(Countly.TAG, "[TransparentActivity] contentUrlAction, event:[" + clyEvent + "] this is not a countly action event url");
193188
return false;
194189
}
195190

196-
String action = (String) clyAction;
191+
Object clyAction = query.get("action");
197192
boolean result = false;
198-
199-
switch (action) {
200-
case "event":
201-
eventAction(query);
202-
break;
203-
case "link":
204-
result = linkAction(query, view);
205-
break;
206-
case "resize_me":
207-
resizeMeAction(query);
208-
break;
209-
default:
210-
break;
193+
if (clyAction instanceof String) {
194+
Log.d(Countly.TAG, "[TransparentActivity] contentUrlAction, action string:[" + clyAction + "]");
195+
String action = (String) clyAction;
196+
197+
switch (action) {
198+
case "event":
199+
eventAction(query);
200+
break;
201+
case "link":
202+
linkAction(query, view);
203+
break;
204+
case "resize_me":
205+
resizeMeAction(query);
206+
break;
207+
default:
208+
break;
209+
}
211210
}
212211

213212
if (query.containsKey("close") && Objects.equals(query.get("close"), "1")) {
214-
finish();
215-
config.globalContentCallback.onContentCallback(ContentStatus.CLOSED, query);
213+
if (config.globalContentCallback != null) { // TODO: verify this later
214+
config.globalContentCallback.onContentCallback(ContentStatus.CLOSED, query);
215+
}
216216
ModuleContent.waitForDelay = 2; // this is indicating that we will wait 1 min after closing the content and before fetching the next one
217+
finish();
217218
return true;
218219
}
219220

@@ -315,7 +316,7 @@ private void eventAction(Map<String, Object> query) {
315316

316317
private Map<String, Object> splitQuery(String url) {
317318
Map<String, Object> query_pairs = new ConcurrentHashMap<>();
318-
String[] pairs = url.split("https://countly_action_event?");
319+
String[] pairs = url.split("https://countly_action_event/?");
319320
if (pairs.length != 2) {
320321
return query_pairs;
321322
}

0 commit comments

Comments
 (0)