Skip to content

Commit

Permalink
Release 4.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
runner authored and runner committed Oct 5, 2022
1 parent d25a3c7 commit 9824957
Show file tree
Hide file tree
Showing 36 changed files with 305 additions and 87 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "com.unity3d.ads.example"
minSdkVersion 19
targetSdkVersion 30
versionCode = 4400
versionName = "4.4.0"
versionCode = 4410
versionName = "4.4.1"
}

buildTypes {
Expand Down
4 changes: 2 additions & 2 deletions unity-ads/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ if (project.rootProject.file('local.properties').exists()) {
ext {
GROUP_ID = "com.unity3d.ads"
ARTIFACT_ID = "unity-ads"
VERSION_ID = "4.4.0"
VERSION_CODE = 4400
VERSION_ID = "4.4.1"
VERSION_CODE = 4410
SIGN_AAR = properties.getProperty("SIGN_AAR") ?: false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public void testExperimentObjectWithInvalid() throws JSONException {
public void testExperimentObjectWithValueOnly() throws JSONException {
ExperimentObject exp = new ExperimentObject(new JSONObject("{\"value\": \"true\"}"));
Assert.assertTrue(exp.getBooleanValue());
Assert.assertEquals(ExperimentAppliedRule.NEXT, exp.getAppliedRule());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.unity3d.ads.test.instrumentation.services.core.configuration;

import com.unity3d.services.core.configuration.ExperimentAppliedRule;
import com.unity3d.services.core.configuration.ExperimentObject;
import com.unity3d.services.core.configuration.ExperimentObjects;
import com.unity3d.services.core.configuration.IExperiments;

Expand All @@ -18,22 +16,23 @@ public class ExperimentObjectsTest {
@Test
public void testExperimentObjectsNull() {
IExperiments expo = new ExperimentObjects(null);
Assert.assertFalse(expo.isTwoStageInitializationEnabled());
Assert.assertFalse(expo.isNativeTokenEnabled());
Assert.assertTrue(expo.isTwoStageInitializationEnabled());
Assert.assertTrue(expo.isNativeTokenEnabled());
}

@Test
public void testExperimentObjectsWithInvalid() throws JSONException {
ExperimentObjects expo = new ExperimentObjects(new JSONObject("{\"something\": false}"));
Assert.assertFalse(expo.isTwoStageInitializationEnabled());
Assert.assertFalse(expo.isNativeTokenEnabled());
Assert.assertTrue(expo.isTwoStageInitializationEnabled());
Assert.assertTrue(expo.isNativeTokenEnabled());
}

@Test
public void testExperimentObjects() throws JSONException {
IExperiments expo = new ExperimentObjects(new JSONObject("{\"tsi\": {\"value\": \"true\"}}"));
Assert.assertTrue(expo.isTwoStageInitializationEnabled());
Assert.assertFalse(expo.isNativeTokenEnabled());
Assert.assertTrue(expo.isNativeTokenEnabled());
Assert.assertFalse(expo.isForwardExperimentsToWebViewEnabled());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,21 @@ public void testExperimentsReaderWithDefaults() {
public void testExperimentsReaderWithLocalOnly() {
ExperimentsReader experimentsReader = new ExperimentsReader();
experimentsReader.updateLocalExperiments(_localExperimentsMock);
Mockito.when(_localExperimentsMock.isTwoStageInitializationEnabled()).thenReturn(true);
Assert.assertEquals(_localExperimentsMock, experimentsReader.getCurrentlyActiveExperiments());
validateDefaultExperiments(experimentsReader.getCurrentlyActiveExperiments());
}

@Test
public void testExperimentsReaderWithRemoteOnly() throws JSONException {
Mockito.when(_remoteExperimentsMock.getNextSessionExperiments()).thenReturn(new JSONObject("{\"tsi\":true}"));
Mockito.when(_remoteExperimentsMock.getNextSessionExperiments()).thenReturn(new JSONObject("{\"tsi_upii\":true}"));
Mockito.when(_remoteExperimentsMock.getCurrentSessionExperiments()).thenReturn(new JSONObject("{\"fff\":true}"));

ExperimentsReader experimentsReader = new ExperimentsReader();
experimentsReader.updateRemoteExperiments(_remoteExperimentsMock);

IExperiments resultExperiments = experimentsReader.getCurrentlyActiveExperiments();
Assert.assertFalse("Expected TSI flag to be false", resultExperiments.isTwoStageInitializationEnabled());
Assert.assertFalse("Expected TSI_UPII flag to be false", resultExperiments.isUpdatePiiFields());
Assert.assertTrue("Expected FFF flag to be true", resultExperiments.isForwardExperimentsToWebViewEnabled());

}
Expand Down Expand Up @@ -94,7 +95,7 @@ public void testExperimentsReaderWithLocalTsiEnabledAndRemoteFffEnabled() throws

private void validateDefaultExperiments(IExperiments experiments) {
Assert.assertFalse(experiments.shouldNativeTokenAwaitPrivacy());
Assert.assertFalse(experiments.isTwoStageInitializationEnabled());
Assert.assertTrue(experiments.isTwoStageInitializationEnabled());
Assert.assertFalse(experiments.isNativeWebViewCacheEnabled());
Assert.assertFalse(experiments.isWebAssetAdCaching());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ public void testExperimentsGetCurrentSessionExperiments() throws JSONException {

private void validateDefaultExperiments(Experiments experiments) {
Assert.assertFalse(experiments.shouldNativeTokenAwaitPrivacy());
Assert.assertFalse(experiments.isTwoStageInitializationEnabled());
Assert.assertTrue(experiments.isTwoStageInitializationEnabled());
Assert.assertTrue(experiments.isNativeTokenEnabled());
Assert.assertTrue(experiments.isPrivacyRequestEnabled());
Assert.assertFalse(experiments.isNativeWebViewCacheEnabled());
Assert.assertFalse(experiments.isWebAssetAdCaching());
Assert.assertFalse(experiments.isNewLifecycleTimer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void testGetTokenBeforeInit() {

@Test
public void testGetTokenBeforeInitAndTimeout() {
Metric _metric = TSIMetric.newAsyncTokenNull(new HashMap<String, String>(){{
Metric _metric = TSIMetric.newNativeGeneratedTokenNull(new HashMap<String, String>(){{
put ("state", "initializing");
}});

Expand All @@ -133,7 +133,7 @@ public void testGetTokenBeforeInitAndTimeout() {

@Test
public void testGetTokenBeforeInitAndTimeoutGuard() {
Metric _metric = TSIMetric.newAsyncTokenNull(new HashMap<String, String>(){{
Metric _metric = TSIMetric.newNativeGeneratedTokenNull(new HashMap<String, String>(){{
put ("state", "initializing");
}});

Expand All @@ -152,7 +152,7 @@ public void testGetTokenBeforeInitAndTimeoutGuard() {

@Test
public void testGetTokenBeforeInitAndInitTimeTokenReady() {
Metric _metric = TSIMetric.newAsyncTokenAvailable(new HashMap<String, String>(){{
Metric _metric = TSIMetric.newNativeGeneratedTokenAvailable(new HashMap<String, String>(){{
put ("state", "initializing");
}});

Expand Down Expand Up @@ -181,7 +181,7 @@ public void testGetTokenBeforeInitAndCreateEmptyQueue() throws JSONException {

@Test
public void testGetTokenBeforeInitAndCreateQueueTokenReady() throws JSONException {
Metric _metric = TSIMetric.newAsyncTokenAvailable(new HashMap<String, String>(){{
Metric _metric = TSIMetric.newNativeGeneratedTokenAvailable(new HashMap<String, String>(){{
put ("state", "initializing");
}});

Expand Down Expand Up @@ -243,7 +243,7 @@ public void testGetTokenAfterQueueTokenReady() throws JSONException {

@Test
public void testMultipleCallsBeforeInit() throws JSONException {
Metric _metric = TSIMetric.newAsyncTokenAvailable(new HashMap<String, String>(){{
Metric _metric = TSIMetric.newNativeGeneratedTokenAvailable(new HashMap<String, String>(){{
put ("state", "initializing");
}});

Expand All @@ -265,7 +265,7 @@ public void testMultipleCallsBeforeInit() throws JSONException {

@Test
public void testMultipleCallsBeforeInitAndQueue() throws JSONException {
Metric _metric = TSIMetric.newAsyncTokenAvailable(new HashMap<String, String>(){{
Metric _metric = TSIMetric.newNativeGeneratedTokenAvailable(new HashMap<String, String>(){{
put ("state", "initializing");
}});

Expand Down Expand Up @@ -294,7 +294,7 @@ public void testMultipleCallsBeforeInitAndQueue() throws JSONException {

@Test
public void testMultipleCallsBeforeInitAndSingleAfterInit() throws JSONException {
Metric _metric = TSIMetric.newAsyncTokenAvailable(new HashMap<String, String>(){{
Metric _metric = TSIMetric.newNativeGeneratedTokenAvailable(new HashMap<String, String>(){{
put ("state", "initializing");
}});

Expand Down Expand Up @@ -479,7 +479,7 @@ public void testDelayedConfigurationTwoConfigSets() throws JSONException {

@Test
public void testDelayedConfigurationConfigurationArrivedFirst() throws JSONException {
Metric _metric = TSIMetric.newAsyncTokenAvailable(new HashMap<String, String>(){{
Metric _metric = TSIMetric.newNativeGeneratedTokenAvailable(new HashMap<String, String>(){{
put ("state", "initializing");
}});
_asyncTokenStorage = new AsyncTokenStorage(_nativeTokenGenerator, _handler, _sdkMetrics);
Expand Down Expand Up @@ -559,4 +559,4 @@ public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
return true;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.unity3d.services.core.configuration.PrivacyConfigStorage;
import com.unity3d.services.core.device.reader.DeviceInfoReaderBuilder;
import com.unity3d.services.core.device.reader.IDeviceInfoReader;
import com.unity3d.services.core.device.reader.IGameSessionIdReader;
import com.unity3d.services.core.lifecycle.CachedLifecycle;
import com.unity3d.services.core.properties.ClientProperties;

Expand Down Expand Up @@ -45,6 +46,9 @@ public class DeviceInfoReaderBuilderTest {
@Mock
PrivacyConfigStorage _privacyConfigStorageMock;

@Mock
IGameSessionIdReader _gameSessionIdReaderMock;

@Before
public void setup() {
ClientProperties.setApplication((Application) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext());
Expand All @@ -60,7 +64,7 @@ public void setup() {
@Test
public void testDeviceInfoReaderBuilderWithPrivacy() {
Mockito.when(_privacyConfigMock.allowedToSendPii()).thenReturn(true);
DeviceInfoReaderBuilder deviceInfoReaderBuilder = new DeviceInfoReaderBuilder(_configReaderMock, _privacyConfigStorageMock);
DeviceInfoReaderBuilder deviceInfoReaderBuilder = new DeviceInfoReaderBuilder(_configReaderMock, _privacyConfigStorageMock, _gameSessionIdReaderMock);
IDeviceInfoReader deviceInfoReader = deviceInfoReaderBuilder.build();
Map<String, Object> deviceInfoData = deviceInfoReader.getDeviceInfoData();
Assert.assertNotNull(deviceInfoData.get(USER_NON_BEHAVIORAL_KEY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.unity3d.services.core.configuration.PrivacyConfigStorage;
import com.unity3d.services.core.device.reader.DeviceInfoReaderPrivacyBuilder;
import com.unity3d.services.core.device.reader.IDeviceInfoReader;
import com.unity3d.services.core.device.reader.IGameSessionIdReader;
import com.unity3d.services.core.lifecycle.CachedLifecycle;
import com.unity3d.services.core.properties.ClientProperties;
import com.unity3d.services.core.properties.SdkProperties;
Expand Down Expand Up @@ -44,6 +45,9 @@ public class DeviceInfoReaderPrivacyBuilderTest {
@Mock
PrivacyConfigStorage _privacyConfigStorageMock;

@Mock
IGameSessionIdReader _gameSessionIdReaderMock;

@Before
public void setup() {
ClientProperties.setApplication((Application) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext());
Expand All @@ -56,7 +60,7 @@ public void setup() {

@Test
public void testDeviceInfoReaderPrivacyBuilder() {
DeviceInfoReaderPrivacyBuilder deviceInfoReaderPrivacyBuilder = new DeviceInfoReaderPrivacyBuilder(_configReaderMock, _privacyConfigStorageMock);
DeviceInfoReaderPrivacyBuilder deviceInfoReaderPrivacyBuilder = new DeviceInfoReaderPrivacyBuilder(_configReaderMock, _privacyConfigStorageMock, _gameSessionIdReaderMock);
IDeviceInfoReader deviceInfoReader = deviceInfoReaderPrivacyBuilder.build();
Map<String, Object> deviceInfoData = deviceInfoReader.getDeviceInfoData();
Assert.assertEquals("privacy", deviceInfoData.get("callType"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.unity3d.ads.test.instrumentation.services.core.device;

import static com.unity3d.services.core.device.reader.JsonStorageKeyNames.GAME_SESSION_ID_NORMALIZED_KEY;

import androidx.test.platform.app.InstrumentationRegistry;

import com.unity3d.services.core.device.Storage;
import com.unity3d.services.core.device.StorageManager;
import com.unity3d.services.core.device.reader.GameSessionIdReader;
import com.unity3d.services.core.properties.ClientProperties;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class GameSessionIdReaderTest {

@Before
public void setup() {
ClientProperties.setApplicationContext(InstrumentationRegistry.getInstrumentation().getTargetContext());
}

@Test
public void testGameSessionIdReader() {
Long gameSessionId = GameSessionIdReader.getInstance().getGameSessionIdAndStore();

// validate we get a gameSessionId
Assert.assertNotNull(gameSessionId);
Assert.assertEquals(12, (Long.toString(gameSessionId)).length()) ;
// validate we store the value
StorageManager.init(InstrumentationRegistry.getInstrumentation().getTargetContext());
StorageManager.initStorage(StorageManager.StorageType.PRIVATE);
Storage storage = StorageManager.getStorage(StorageManager.StorageType.PRIVATE);
Long storedId = null;
if (storage != null) {
storedId = (Long) storage.get(GAME_SESSION_ID_NORMALIZED_KEY);
}
Assert.assertEquals(gameSessionId, storedId);
// validate on consecutive requests we get the same value
Long gameSessionId2 = GameSessionIdReader.getInstance().getGameSessionId();
Assert.assertEquals(gameSessionId, gameSessionId2);
// validate even on storage change we get same value
if (storage != null) {
storage.set(GAME_SESSION_ID_NORMALIZED_KEY, "newValueFromWebview");
storage.writeStorage();
}
Long gameSessionId3 = GameSessionIdReader.getInstance().getGameSessionId();
Assert.assertEquals(gameSessionId, gameSessionId3);
}


}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.unity3d.ads.test.instrumentation.services.core.device;

import static com.unity3d.services.core.device.reader.JsonStorageKeyNames.GAME_SESSION_ID_NORMALIZED_KEY;

import androidx.test.platform.app.InstrumentationRegistry;

import com.unity3d.services.core.device.reader.IGameSessionIdReader;
import com.unity3d.services.core.device.reader.MinimalDeviceInfoReader;
import com.unity3d.services.core.properties.ClientProperties;
import com.unity3d.services.core.properties.SdkProperties;
Expand All @@ -10,33 +13,42 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.Map;

@RunWith(MockitoJUnitRunner.class)
public class MinimalDeviceInfoReaderTest {
private static String TEST_GAME_ID = "123456";

@Mock
IGameSessionIdReader gameSessionIdReaderMock;

private static final String TEST_GAME_ID = "123456";
private static final Long TEST_GAME_SESSION_ID = 123567891011L;

@Before
public void setup() {
ClientProperties.setApplicationContext(InstrumentationRegistry.getInstrumentation().getTargetContext());
ClientProperties.setGameId(TEST_GAME_ID);
Mockito.when(gameSessionIdReaderMock.getGameSessionIdAndStore()).thenReturn(TEST_GAME_SESSION_ID);
}

@Test
public void testMinimalDeviceInfoReader() {
MinimalDeviceInfoReader minimalDeviceInfoReader = new MinimalDeviceInfoReader();
MinimalDeviceInfoReader minimalDeviceInfoReader = new MinimalDeviceInfoReader(gameSessionIdReaderMock);
Map<String, Object> deviceInfoData = minimalDeviceInfoReader.getDeviceInfoData();
Assert.assertEquals("android", deviceInfoData.get("platform"));
Assert.assertEquals(SdkProperties.getVersionName(), deviceInfoData.get("sdkVersionName"));
Assert.assertEquals(TEST_GAME_ID, deviceInfoData.get("gameId"));
Assert.assertEquals(TEST_GAME_SESSION_ID, deviceInfoData.get(GAME_SESSION_ID_NORMALIZED_KEY));
}

@Test
public void testMinimalDeviceInforeaderWithoutGameId() {
ClientProperties.setGameId(null);
MinimalDeviceInfoReader minimalDeviceInfoReader = new MinimalDeviceInfoReader();
MinimalDeviceInfoReader minimalDeviceInfoReader = new MinimalDeviceInfoReader(gameSessionIdReaderMock);
Map<String, Object> deviceInfoData = minimalDeviceInfoReader.getDeviceInfoData();
Assert.assertEquals(null, deviceInfoData.get("gameId"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
handler.post(new Runnable() {
@Override
public void run() {
WebViewApp.getCurrentApp().setWebView(new WebView(InstrumentationRegistry.getInstrumentation().getTargetContext()));
WebViewApp.getCurrentApp().setWebView(new WebView(InstrumentationRegistry.getInstrumentation().getTargetContext(), false));
webViewCV.open();
}
});
Expand Down
Loading

0 comments on commit 9824957

Please sign in to comment.