Skip to content

Commit fe3c782

Browse files
Merge branch 'staging' into android24_7_1
2 parents 02b9335 + 9569a22 commit fe3c782

File tree

8 files changed

+60
-43
lines changed

8 files changed

+60
-43
lines changed

sdk/src/androidTest/java/ly/count/android/sdk/CountlyTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ public void testOnStop_reallyStopping_emptyEventQueue() {
401401
assertEquals(0, mCountly.getActivityCount());
402402
assertTrue(mCountly.getPrevSessionDurationStartTime() > 0);
403403
verify(requestQueueProvider).endSession(0);
404-
verify(requestQueueProvider, times(0)).recordEvents(anyString());
404+
verify(requestQueueProvider, times(1)).recordEvents(anyString()); // not 0 anymore, it will send orientation event
405405
}
406406

407407
/**
@@ -534,7 +534,7 @@ public void testOnTimer_activeSession_emptyEventQueue() {
534534
mCountly.onTimer();
535535

536536
verify(requestQueueProvider).updateSession(0);
537-
verify(requestQueueProvider, times(0)).recordEvents(anyString());
537+
verify(requestQueueProvider, times(1)).recordEvents(anyString()); // not 0 anymore, it will send orientation event
538538
}
539539

540540
@Test

sdk/src/androidTest/java/ly/count/android/sdk/DeviceIdTests.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import androidx.test.ext.junit.runners.AndroidJUnit4;
44
import java.util.Collections;
5+
import org.json.JSONException;
56
import org.junit.After;
67
import org.junit.Before;
78
import org.junit.Test;
@@ -284,7 +285,7 @@ public void legacyFallbackType_null() {
284285
* -- at this point 9 requests are generated (firs begin, 1 merge, 1 user profile, 1 end session for without merge, 1 begin session for the new user, 1 user profile, 1 user profile, 1 user profile, 1 merge)
285286
*/
286287
@Test
287-
public void sessionDurationScenario_1() throws InterruptedException {
288+
public void sessionDurationScenario_1() throws InterruptedException, JSONException {
288289
CountlyConfig config = TestUtils.createBaseConfig();
289290
config.setRequiresConsent(false);
290291
config.lifecycleObserver = () -> true;
@@ -304,11 +305,12 @@ public void sessionDurationScenario_1() throws InterruptedException {
304305
Thread.sleep(2000);
305306

306307
countly.deviceId().changeWithoutMerge("ff"); // this will generate a request with "end_session", "session_duration" fields and reset duration + begin_session
307-
assertEquals(5, TestUtils.getCurrentRQ().length);
308+
assertEquals(6, TestUtils.getCurrentRQ().length); // not 5 anymore, it will send orientation event as well
308309

309310
TestUtils.validateRequest("ff_merge", TestUtils.map("old_device_id", "1234"), 1);
310-
TestUtils.validateRequest("ff_merge", TestUtils.map("user_details", "{\"custom\":{\"prop2\":123,\"prop1\":\"string\",\"prop3\":false}}"), 2);
311-
ModuleSessionsTests.validateSessionEndRequest(3, 3, "ff_merge");
311+
ModuleEventsTests.validateEventInRQ("ff_merge", "[CLY]_orientation", 1, 0.0d, 0.0d, 2, 0, 1, -1);
312+
TestUtils.validateRequest("ff_merge", TestUtils.map("user_details", "{\"custom\":{\"prop2\":123,\"prop1\":\"string\",\"prop3\":false}}"), 3);
313+
ModuleSessionsTests.validateSessionEndRequest(4, 3, "ff_merge");
312314

313315
Thread.sleep(1000);
314316

@@ -336,13 +338,13 @@ public void sessionDurationScenario_1() throws InterruptedException {
336338

337339
countly.deviceId().changeWithMerge("ff_merge"); // this will generate a request with "session_duration" field and reset duration
338340

339-
assertEquals(9, TestUtils.getCurrentRQ().length);
341+
assertEquals(11, TestUtils.getCurrentRQ().length);
340342

341-
TestUtils.validateRequest("ff", TestUtils.map("user_details", "{\"custom\":{\"prop4\":[\"sd\"]}}"), 5);
342-
TestUtils.validateRequest("ff", TestUtils.map("user_details", "{\"custom\":{}}"), 6);
343-
TestUtils.validateRequest("ff", TestUtils.map("user_details", "{\"custom\":{\"prop2\":456,\"prop1\":\"string_a\",\"prop3\":true}}"), 7);
343+
TestUtils.validateRequest("ff", TestUtils.map("user_details", "{\"custom\":{\"prop4\":[\"sd\"]}}"), 7);
344+
TestUtils.validateRequest("ff", TestUtils.map("user_details", "{\"custom\":{}}"), 8);
345+
TestUtils.validateRequest("ff", TestUtils.map("user_details", "{\"custom\":{\"prop2\":456,\"prop1\":\"string_a\",\"prop3\":true}}"), 9);
344346

345-
TestUtils.validateRequest("ff_merge", TestUtils.map("old_device_id", "ff"), 8);
347+
TestUtils.validateRequest("ff_merge", TestUtils.map("old_device_id", "ff"), 10);
346348

347349
countly.halt();
348350
store.clear();

sdk/src/androidTest/java/ly/count/android/sdk/ModuleSessionsTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void manualSessionBeginUpdateEnd() throws InterruptedException {
4444

4545
Thread.sleep(2000);
4646
mCountly.sessions().endSession();
47-
validateSessionEndRequest(2, 2, TestUtils.commonDeviceId);
47+
validateSessionEndRequest(3, 2, TestUtils.commonDeviceId); // not idx 2 anymore, it will send orientation event RQ
4848
}
4949

5050
@Test
@@ -97,7 +97,7 @@ public void automaticSessionBeginEndWithManualDisabled() throws InterruptedExcep
9797

9898
mCountly.onStopInternal();
9999

100-
validateSessionEndRequest(1, 1, TestUtils.commonDeviceId);
100+
validateSessionEndRequest(2, 1, TestUtils.commonDeviceId); // not idx 1 anymore, it will send orientation event RQ
101101
}
102102

103103
/**

sdk/src/androidTest/java/ly/count/android/sdk/ScenarioEventIDTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void eventIDScenario_automaticViews() {
7272
verifyRecordEventToEventQueueNotCalled(eqp);
7373

7474
mCountly.onStartInternal(act);
75-
verifyRecordEventToEventQueueIDs(eqp, ModuleViews.VIEW_EVENT_KEY, idV[0], null, "", null, 0, 1);
75+
verifyRecordEventToEventQueueIDs(eqp, ModuleViews.VIEW_EVENT_KEY, idV[0], null, "", null, 1, 2); // not 1 anymore plus orientation
7676

7777
clearInvocations(eqp);
7878

@@ -83,7 +83,7 @@ public void eventIDScenario_automaticViews() {
8383

8484
//custom event 1
8585
mCountly.events().recordEvent(eKeys[0]);
86-
verifyRecordEventToEventQueueIDs(eqp, eKeys[0], idE[0], idV[1], null, "", 0, 1);
86+
verifyRecordEventToEventQueueIDs(eqp, eKeys[0], idE[1], idV[1], null, "", 0, 1);
8787
clearInvocations(eqp);
8888

8989
mCountly.onStopInternal();
@@ -92,7 +92,7 @@ public void eventIDScenario_automaticViews() {
9292

9393
//internal event
9494
mCountly.events().recordEvent(ModuleFeedback.RATING_EVENT_KEY);
95-
verifyRecordEventToEventQueueIDs(eqp, ModuleFeedback.RATING_EVENT_KEY, idE[1], idV[1], null, null, 0, 1);
95+
verifyRecordEventToEventQueueIDs(eqp, ModuleFeedback.RATING_EVENT_KEY, idE[2], idV[1], null, null, 0, 1);
9696
clearInvocations(eqp);
9797

9898
mCountly.onStopInternal();
@@ -101,7 +101,7 @@ public void eventIDScenario_automaticViews() {
101101

102102
//custom event 2
103103
mCountly.events().recordEvent(eKeys[1]);
104-
verifyRecordEventToEventQueueIDs(eqp, eKeys[1], idE[2], idV[1], null, idE[0], 0, 1);
104+
verifyRecordEventToEventQueueIDs(eqp, eKeys[1], idE[3], idV[1], null, idE[1], 0, 1);
105105
}
106106

107107
/**

sdk/src/androidTest/java/ly/count/android/sdk/scSE_SessionsTests.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ public void SE_201_CNR_M() throws InterruptedException {
9797

9898
flowManualSessions(countly);
9999

100-
Assert.assertEquals(4, TestUtils.getCurrentRQ().length);
100+
Assert.assertEquals(5, TestUtils.getCurrentRQ().length);
101101
validateSessionBeginRequest(0, TestUtils.commonDeviceId);
102-
validateSessionUpdateRequest(1, 2, TestUtils.commonDeviceId);
103102
validateSessionUpdateRequest(2, 2, TestUtils.commonDeviceId);
104-
validateSessionEndRequest(3, 2, TestUtils.commonDeviceId);
103+
validateSessionUpdateRequest(3, 2, TestUtils.commonDeviceId);
104+
validateSessionEndRequest(4, 2, TestUtils.commonDeviceId);
105105
}
106106

107107
/**
@@ -122,7 +122,7 @@ public void SE_202_CR_CNG_M() throws InterruptedException {
122122

123123
flowManualSessions(countly);
124124

125-
Assert.assertEquals(2, TestUtils.getCurrentRQ().length);
125+
Assert.assertEquals(2, TestUtils.getCurrentRQ().length); // not 2 anymore plus orientation
126126
validateSessionConsentRequest(0, false, TestUtils.commonDeviceId);
127127
validateRequest(TestUtils.map("location", ""), 1);
128128
}
@@ -211,22 +211,26 @@ public void SE_204_CNR_A_id_change() throws InterruptedException {
211211

212212
flowAutomaticSessions(countly);
213213

214-
Assert.assertEquals(12, TestUtils.getCurrentRQ().length);
214+
Assert.assertEquals(16, TestUtils.getCurrentRQ().length);
215215
validateSessionBeginRequest(0, TestUtils.commonDeviceId);
216216
TestUtils.validateRequest("newID", TestUtils.map("old_device_id", TestUtils.commonDeviceId), 1);
217-
validateSessionEndRequest(2, 2, "newID");
217+
// orientation request
218+
validateSessionEndRequest(3, 2, "newID");
218219

219-
validateSessionBeginRequest(3, "newID_2");
220-
TestUtils.validateRequest("newID", TestUtils.map("old_device_id", "newID_2"), 4);
221-
validateSessionEndRequest(5, 2, "newID");
222-
223-
validateSessionBeginRequest(6, "newID_2");
224-
validateSessionEndRequest(7, 1, "newID_2");
220+
validateSessionBeginRequest(4, "newID_2");
221+
TestUtils.validateRequest("newID", TestUtils.map("old_device_id", "newID_2"), 5);
222+
// orientation request
223+
validateSessionEndRequest(7, 2, "newID");
225224

226225
validateSessionBeginRequest(8, "newID_2");
227-
TestUtils.validateRequest("newID", TestUtils.map("old_device_id", "newID_2"), 9);
228-
validateSessionEndRequest(10, null, "newID");
229-
validateSessionBeginRequest(11, "newID");
226+
// orientation request
227+
validateSessionEndRequest(10, 1, "newID_2");
228+
229+
validateSessionBeginRequest(11, "newID_2");
230+
TestUtils.validateRequest("newID", TestUtils.map("old_device_id", "newID_2"), 12);
231+
// orientation request
232+
validateSessionEndRequest(14, null, "newID");
233+
validateSessionBeginRequest(15, "newID");
230234
}
231235

232236
/**

sdk/src/androidTest/java/ly/count/android/sdk/scUP_UserProfileTests.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ public void eventSaveScenario_manualSessions() throws JSONException {
4848
countly.userProfile().setProperty("theme", "dark_mode");
4949

5050
countly.events().recordEvent("test_event1");
51-
TestUtils.assertRQSize(2); // begin session request + user property request with dark_mode
51+
TestUtils.assertRQSize(3); // begin session request + user property request with dark_mode + orientation event
5252
countly.events().recordEvent("test_event2");
5353
countly.events().recordEvent("test_event3");
5454

5555
countly.userProfile().setProperty("theme", "light_mode");
56-
TestUtils.assertRQSize(2); // no request is generated on the way
56+
TestUtils.assertRQSize(3); // no request is generated on the way, not 2 anymore because of orientation event
5757

5858
countly.sessions().endSession();
5959
// begin_session + first user property request + 3 events + user property request with light_mode + end_session
60-
ModuleUserProfileTests.validateUserProfileRequest(1, 5, TestUtils.map(), TestUtils.map("theme", "dark_mode"));
61-
ModuleUserProfileTests.validateUserProfileRequest(3, 5, TestUtils.map(), TestUtils.map("theme", "light_mode"));
60+
ModuleUserProfileTests.validateUserProfileRequest(2, 6, TestUtils.map(), TestUtils.map("theme", "dark_mode"));
61+
ModuleUserProfileTests.validateUserProfileRequest(4, 6, TestUtils.map(), TestUtils.map("theme", "light_mode"));
6262
}
6363

6464
/**
@@ -325,8 +325,9 @@ public void UP_207_CNR_M() throws JSONException {
325325
TestUtils.assertRQSize(8);
326326
ModuleSessionsTests.validateSessionBeginRequest(0, TestUtils.commonDeviceId);
327327

328-
ModuleEventsTests.validateEventInRQ("A", 1, 0, 2);
329-
ModuleEventsTests.validateEventInRQ("B", 1, 1, 2);
328+
ModuleEventsTests.validateEventInRQ("[CLY]_orientation", 1, 0, 3);
329+
ModuleEventsTests.validateEventInRQ("A", 1, 1, 3); // not 2 anymore because of orientation, 0 is orientation
330+
ModuleEventsTests.validateEventInRQ("B", 1, 2, 3);
330331

331332
ModuleUserProfileTests.validateUserProfileRequest(2, 8, TestUtils.map(), TestUtils.map("a12345", "4"));
332333

@@ -378,8 +379,9 @@ public void UP_208_CR_CG_M() throws JSONException {
378379
ModuleConsentTests.validateAllConsentRequest(TestUtils.commonDeviceId, 0);
379380
ModuleSessionsTests.validateSessionBeginRequest(1, TestUtils.commonDeviceId);
380381

381-
ModuleEventsTests.validateEventInRQ("A", 2, 0, 2);
382-
ModuleEventsTests.validateEventInRQ("B", 2, 1, 2);
382+
ModuleEventsTests.validateEventInRQ("[CLY]_orientation", 2, 0, 3);
383+
ModuleEventsTests.validateEventInRQ("A", 2, 1, 3); // not 2 anymore because of orientation
384+
ModuleEventsTests.validateEventInRQ("B", 2, 2, 3); // not 2 anymore because of orientation
383385

384386
ModuleUserProfileTests.validateUserProfileRequest(3, 9, TestUtils.map(), TestUtils.map("a12345", "4"));
385387

@@ -435,7 +437,7 @@ public void UP_210_CNR_M_duration() throws InterruptedException, JSONException {
435437
sendUserData(countly);
436438
Thread.sleep(6000);
437439

438-
validateUserDataRequest(0, 1, "My Property", TestUtils.commonDeviceId);
440+
validateUserDataRequest(0, 1, "My Property", TestUtils.commonDeviceId); // plus orientation
439441
}
440442

441443
private void sendUserProperties(Countly countly) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ void beginSessionInternal() {
5757
sessionRunning = true;
5858
prevSessionDurationStartTime_ = System.currentTimeMillis();
5959
requestQueueProvider.beginSession(_cly.moduleLocation.locationDisabled, _cly.moduleLocation.locationCountryCode, _cly.moduleLocation.locationCity, _cly.moduleLocation.locationGpsCoordinates, _cly.moduleLocation.locationIpAddress, preparedMetrics);
60+
61+
if (_cly.moduleViews.trackOrientationChanges) {
62+
_cly.moduleViews.updateOrientation(_cly.context_.getResources().getConfiguration().orientation, true);
63+
}
6064
}
6165

6266
void updateSessionInternal() {

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,13 +436,14 @@ void stopAllViewsInternal(Map<String, Object> viewSegmentation) {
436436
autoCloseRequiredViews(true, viewSegmentation);
437437
}
438438

439-
void updateOrientation(int newOrientation) {
439+
void updateOrientation(int newOrientation, boolean forceSend) {
440+
L.d("[ModuleViews] updateOrientation, forceSend: [" + forceSend + "]");
440441
if (!consentProvider.getConsent(Countly.CountlyFeatureNames.users)) {
441442
L.d("[ModuleViews] updateOrientation, no consent given for users, skipping orientation tracking");
442443
return;
443444
}
444445

445-
if (currentOrientation == newOrientation) {
446+
if (!forceSend && currentOrientation == newOrientation) {
446447
L.d("[ModuleViews] updateOrientation, orientation did not change, skipping");
447448
return;
448449
}
@@ -462,6 +463,10 @@ void updateOrientation(int newOrientation) {
462463
eventProvider.recordEventInternal(ORIENTATION_EVENT_KEY, segm, 1, 0, 0, null, null);
463464
}
464465

466+
void updateOrientation(int newOrientation) {
467+
updateOrientation(newOrientation, false);
468+
}
469+
465470
void pauseRunningViewsAndSend() {
466471
L.d("[ModuleViews] pauseRunningViewsAndSend, going to the background and pausing");
467472
for (Map.Entry<String, ViewData> entry : viewDataMap.entrySet()) {

0 commit comments

Comments
 (0)