Skip to content

Commit

Permalink
SDK v7.13
Browse files Browse the repository at this point in the history
* commit '8732d1269e4c8b689dde7f125316114d031a6d7f':
  Updated SDK version, RELEASE-NOTES
  Merge pull request #516 in MOBILE-SDK/app_mobile-sdk-android from NoCookie_Changes_Android to develop
  • Loading branch information
avohraa committed Apr 28, 2021
2 parents f694034 + 8732d12 commit 231e38e
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 33 deletions.
4 changes: 4 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 7.13
### New Feature
+ MS-4693 Added support for Cookieless domain requests

## 7.12
### Improvements/Bug Fixes
+ MS-4704 Added support for OMID containerGeometry and onScreenContainerGeometry for Instream & OutStream Video Ads
Expand Down
4 changes: 2 additions & 2 deletions instreamvideo/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Project Properties
version = "1.26" // Instream SDK version
version = "1.27" // Instream SDK version

apply plugin: 'com.android.library'

Expand All @@ -10,7 +10,7 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 28
versionCode 24 // An integer value that represents the version of the code, relative to other versions. Increase for each release.
versionCode 25 // An integer value that represents the version of the code, relative to other versions. Increase for each release.
versionName version
consumerProguardFiles 'proguard-project.txt'
}
Expand Down
4 changes: 2 additions & 2 deletions sdk/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Project properties
version = "7.12"
version = "7.13"
group='com.appnexus.opensdk'

// Android build
Expand All @@ -9,7 +9,7 @@ android {
compileSdkVersion 28
buildToolsVersion '29.0.0'
defaultConfig {
versionCode 82 // An integer value that represents the version of the code, relative to other versions. Increase for each release.
versionCode 83 // An integer value that represents the version of the code, relative to other versions. Increase for each release.
versionName version
consumerProguardFiles 'proguard-project.txt'
minSdkVersion 14
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/com/appnexus/opensdk/AdWebView.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public void loadAd(BaseAdResponse ad) {
html = prependViewPort(html);
html = omidAdSession.prependOMIDJSToHTML(html);
}
this.loadDataWithBaseURL(Settings.getBaseUrl(), html, "text/html", "UTF-8", null);
this.loadDataWithBaseURL(Settings.getWebViewBaseUrl(), html, "text/html", "UTF-8", null);
}
} catch (OutOfMemoryError exception) {
// System is running low in memory and cannot process loadAd just return a failure.
Expand Down Expand Up @@ -337,7 +337,7 @@ protected void onPostExecute(HTTPResponse response) {
html = prependRawResources(html);
html = prependViewPort(html);

loadDataWithBaseURL(Settings.getBaseUrl(), html, "text/html", "UTF-8", null);
loadDataWithBaseURL(Settings.getWebViewBaseUrl(), html, "text/html", "UTF-8", null);
fireMRAIDEnabled();
}
}
Expand Down
10 changes: 10 additions & 0 deletions sdk/src/com/appnexus/opensdk/SDKSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -488,4 +488,14 @@ public static void setCountImpressionOn1pxRendering(boolean enable) {
countImpressionOn1pxRendering = enable;
}


/**
* @deprecated This will be removed in future releases. This is introduced just a fail safe kill switch for initial rollout. No Alternative.
* To allow/disallow using ib.adnxs-simple.com domain for Ad Requests.
* @param allow set true to enable, false to disable. Default is true.
* */
public static void setAllowUsingSimpleDomain(boolean allow) {
Settings.getSettings().simpleDomainUsageAllowed = allow;
}

}
7 changes: 4 additions & 3 deletions sdk/src/com/appnexus/opensdk/ut/UTAdRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ private void fail(ResultCode code) {
HashMap<String, UTAdResponse> makeRequest() {
try {

String baseUrl = UTConstants.REQUEST_BASE_URL_UT;
Settings.getSettings().deviceAccessAllowed = ANGDPRSettings.canIAccessDeviceData(requestParams.getContext()); // Make sure GDPR device access is allowed.
String baseUrl = Settings.getAdRequestUrl();
URL url = new URL(baseUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
Expand All @@ -137,7 +138,7 @@ HashMap<String, UTAdResponse> makeRequest() {
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Accept-Language", Settings.getSettings().language);
conn.setRequestProperty("User-Agent", Settings.getSettings().ua);
if (ANGDPRSettings.canIAccessDeviceData(requestParams.getContext()) && !Settings.getSettings().doNotTrack) {
if (Settings.getSettings().deviceAccessAllowed && !Settings.getSettings().doNotTrack) {
String cookieString = WebviewUtil.getCookie();
if (!TextUtils.isEmpty(cookieString)) {
conn.setRequestProperty("Cookie", cookieString);
Expand Down Expand Up @@ -183,7 +184,7 @@ HashMap<String, UTAdResponse> makeRequest() {

Clog.i(Clog.httpRespLogTag, "RESPONSE - " + result);
Map<String, List<String>> headers = conn.getHeaderFields();
if (ANGDPRSettings.canIAccessDeviceData(requestParams.getContext()) && !Settings.getSettings().doNotTrack) {
if (Settings.getSettings().deviceAccessAllowed && !Settings.getSettings().doNotTrack) {
WebviewUtil.cookieSync(headers);
}
ANMultiAdRequest anMultiAdRequest = getMultiAdRequest();
Expand Down
8 changes: 8 additions & 0 deletions sdk/src/com/appnexus/opensdk/ut/UTConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ public class UTConstants {
public static final String MRAID_JS_FILENAME = "mraid.js";
public static final String EXTRAS_KEY_MRAID = "MRAID";
public static final String EXTRAS_KEY_ORIENTATION = "ORIENTATION";

// URL Constants below should never be directly accessed inside SDK.
// Always use Settings.getWebViewBaseUrl() / Settings.getAdRequestUrl() / Settings.getCookieDomain()
public static String REQUEST_BASE_URL_UT = "https://mediation.adnxs.com/ut/v3";
public static String WEBVIEW_BASE_URL_UT = "https://mediation.adnxs.com/";
public static String COOKIE_DOMAIN = "https://mediation.adnxs.com"; // There is only one cookie domain. No cookies for ib.adnxs-simple

public static String REQUEST_BASE_URL_SIMPLE = "https://ib.adnxs-simple.com/ut/v3";
public static String WEBVIEW_BASE_URL_SIMPLE = "https://ib.adnxs-simple.com/";

}
5 changes: 4 additions & 1 deletion sdk/src/com/appnexus/opensdk/ut/UTRequestParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,10 @@ private JSONObject getDeviceObject() {
// limited ad tracking
device.put(DEVICE_LMT, Settings.getSettings().limitTrackingEnabled);

if (ANGDPRSettings.canIAccessDeviceData(context) && !SDKSettings.isAAIDUsageDisabled() && !Settings.getSettings().doNotTrack) {
// Update the value of device access consent in setting each time a request is made.
Settings.getSettings().deviceAccessAllowed = ANGDPRSettings.canIAccessDeviceData(context);

if (Settings.getSettings().deviceAccessAllowed && !SDKSettings.isAAIDUsageDisabled() && !Settings.getSettings().doNotTrack) {
if (!StringUtil.isEmpty(Settings.getSettings().aaid)) {
JSONObject device_id = new JSONObject();
device_id.put(DEVICE_ID_AAID, Settings.getSettings().aaid);
Expand Down
8 changes: 5 additions & 3 deletions sdk/src/com/appnexus/opensdk/utils/HTTPGet.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ private HttpURLConnection createConnection(URL url) throws IOException {

private void setConnectionParams(HttpURLConnection connection) throws ProtocolException {
connection.setRequestProperty("User-Agent", Settings.getSettings().ua);
String cookieString = WebviewUtil.getCookie();
if (!TextUtils.isEmpty(cookieString)) {
connection.setRequestProperty("Cookie",cookieString);
if (Settings.getSettings().deviceAccessAllowed && !Settings.getSettings().doNotTrack) {
String cookieString = WebviewUtil.getCookie();
if (!TextUtils.isEmpty(cookieString)) {
connection.setRequestProperty("Cookie", cookieString);
}
}
connection.setConnectTimeout(Settings.HTTP_CONNECTION_TIMEOUT);
connection.setReadTimeout(Settings.HTTP_SOCKET_TIMEOUT);
Expand Down
44 changes: 29 additions & 15 deletions sdk/src/com/appnexus/opensdk/utils/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@

import android.location.Location;
import android.os.Build;
import android.text.TextUtils;

import com.appnexus.opensdk.ANExternalUserIdSource;
import com.appnexus.opensdk.ANGDPRSettings;
import com.appnexus.opensdk.BuildConfig;
import com.appnexus.opensdk.MediaType;
import com.appnexus.opensdk.R;
import com.appnexus.opensdk.ut.UTConstants;

import java.net.URL;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
Expand All @@ -50,6 +54,10 @@ public enum CountImpression {
public String carrierName = null;
public String aaid = null;
public boolean limitTrackingEnabled = false;
// Caches the value of DeviceAccessConsent for each request and is updated every time a request is made.
// Use this value instead of calling and fetching from shared preference each time.
public boolean deviceAccessAllowed = true;

@Deprecated
public boolean useHttps=true;

Expand Down Expand Up @@ -100,6 +108,13 @@ public enum CountImpression {
* */
public static boolean countImpressionOn1pxRendering = false;

/**
* @deprecated
* This feature flag is responsible for turning on/off ib.adnxs-simple.com domain usage.
* By default this is true. This feature flag will be removed in future releases. This is introduced just as a failsafe kill switch.
* */
public static boolean simpleDomainUsageAllowed = true;

// STATICS
public static final int HTTP_CONNECTION_TIMEOUT = 15000;
public static final int HTTP_SOCKET_TIMEOUT = 20000;
Expand Down Expand Up @@ -134,11 +149,7 @@ public enum CountImpression {

public static final int VIDEO_AUTOPLAY_PERCENTAGE = 50;

private static String COOKIE_DOMAIN = "https://mediation.adnxs.com";
public static final String AN_UUID = "uuid2";
private static String BASE_URL = "https://mediation.adnxs.com/";
private static String REQUEST_BASE_URL = "https://mediation.adnxs.com/mob?";
private static String INSTALL_BASE_URL = "https://mediation.adnxs.com/install?";

private static String VIDEO_HTML = "file:///android_asset/apn_vastvideo.html";

Expand Down Expand Up @@ -185,26 +196,29 @@ public HashSet<String> getInvalidNetwork(MediaType type) {
return null;
}

public static String getBaseUrl() {
return BASE_URL;
}

public static String getRequestBaseUrl() {
return REQUEST_BASE_URL;
// Returns ib.adnxs-simple.com if we do not have deviceAccessConsent as per GDPR or when doNotTrack is turned on by publisher
public static String getWebViewBaseUrl() {
if ((!Settings.getSettings().deviceAccessAllowed || Settings.getSettings().doNotTrack) && Settings.getSettings().simpleDomainUsageAllowed) {
return UTConstants.WEBVIEW_BASE_URL_SIMPLE;
}
return UTConstants.WEBVIEW_BASE_URL_UT;
}

public static String getInstallBaseUrl() {
return INSTALL_BASE_URL;
// Returns ib.adnxs-simple.com if we do not have deviceAccessConsent as per GDPR or when doNotTrack is turned on by publisher
public static String getAdRequestUrl() {
if ((!Settings.getSettings().deviceAccessAllowed || Settings.getSettings().doNotTrack) && Settings.getSettings().simpleDomainUsageAllowed) {
return UTConstants.REQUEST_BASE_URL_SIMPLE;
}
return UTConstants.REQUEST_BASE_URL_UT;
}


public static String getVideoHtmlPage() {
return Settings.getSettings().debug_mode ? VIDEO_HTML.replace("apn_vastvideo.html", "apn_vastvideo.html?ast_debug=true") : VIDEO_HTML;
}


// There is only one cookie domain
public static String getCookieDomain(){
return COOKIE_DOMAIN;
return UTConstants.COOKIE_DOMAIN;
}

}
2 changes: 1 addition & 1 deletion sdk/src/com/appnexus/opensdk/utils/WebviewUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public static String getCookie() {
Clog.i(Clog.httpRespLogTag, "Unable to find a CookieManager");
return null;
}
return cm.getCookie(Settings.getBaseUrl());
return cm.getCookie(Settings.getCookieDomain());
}catch (Exception e){
// Catches PackageManager$NameNotFoundException for webview
Clog.e(Clog.httpRespLogTag, "Unable to find a CookieManager - Exception: "+e.getMessage());
Expand Down
2 changes: 2 additions & 0 deletions sdk/test/com/appnexus/opensdk/BaseRoboTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void setup() {
server.start();
HttpUrl url= server.url("/");
UTConstants.REQUEST_BASE_URL_UT = url.toString();
UTConstants.REQUEST_BASE_URL_SIMPLE = url.toString();
System.out.println(UTConstants.REQUEST_BASE_URL_UT);
ShadowSettings.setTestURL(url.toString());
TestResponsesUT.setTestURL(url.toString());
Expand Down Expand Up @@ -106,6 +107,7 @@ public void restartServer() {
server.start();
HttpUrl url= server.url("/");
UTConstants.REQUEST_BASE_URL_UT = url.toString();
UTConstants.REQUEST_BASE_URL_SIMPLE = url.toString();
System.out.println(UTConstants.REQUEST_BASE_URL_UT);
ShadowSettings.setTestURL(url.toString());
TestResponsesUT.setTestURL(url.toString());
Expand Down
18 changes: 14 additions & 4 deletions sdk/test/com/appnexus/opensdk/DefaultSettingsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

@Config(sdk = 21)
@RunWith(RobolectricTestRunner.class)
public class DefaultSettingsTest {
public class DefaultSettingsTest extends BaseRoboTest {

@Before
public void setup() {
Expand All @@ -38,6 +38,7 @@ public void setup() {

@After
public void tearDown() {
Settings.getSettings().deviceAccessAllowed = true; // Reset to defaultduring setup
}

@Test
Expand All @@ -54,8 +55,17 @@ public void testDefaultStaticValues() {
assertEquals(50, Settings.MIN_PERCENTAGE_VIEWED);
assertEquals("https://mediation.adnxs.com", Settings.getCookieDomain());
assertEquals("uuid2", Settings.AN_UUID);
assertEquals("https://mediation.adnxs.com/", Settings.getBaseUrl());
assertEquals("https://mediation.adnxs.com/mob?", Settings.getRequestBaseUrl());
assertEquals("https://mediation.adnxs.com/install?", Settings.getInstallBaseUrl());
assertEquals("https://mediation.adnxs.com/", Settings.getWebViewBaseUrl());
assertEquals("https://mediation.adnxs.com/ut/v3", Settings.getAdRequestUrl());
}

@Test
public void testDeviceAccessConsentFalseStaticValues() {
Settings.getSettings().deviceAccessAllowed = false;
assertEquals("https://mediation.adnxs.com", Settings.getCookieDomain()); // No seperate cookie domain
assertEquals("https://ib.adnxs-simple.com/", Settings.getWebViewBaseUrl());
System.out.println("Setting WebView Base URL"+Settings.getWebViewBaseUrl());
assertEquals("https://ib.adnxs-simple.com/ut/v3", Settings.getAdRequestUrl());
System.out.println("REQUEST Request URL"+Settings.getAdRequestUrl());
}
}
1 change: 1 addition & 0 deletions sdk/test/com/appnexus/opensdk/NativeRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public MockResponse dispatch(RecordedRequest request) throws InterruptedExceptio
server.setDispatcher(dispatcher);
HttpUrl impbus = server.url("/");
UTConstants.REQUEST_BASE_URL_UT = impbus.toString();
UTConstants.REQUEST_BASE_URL_SIMPLE = impbus.toString();
NativeAdRequestListener listener = new NativeAdRequestListener() {

@Override
Expand Down
3 changes: 3 additions & 0 deletions sdk/test/com/appnexus/opensdk/UTAdRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void setup() {
utRequestParameters.setPrimarySize(new AdSize(1, 1));
Settings.getSettings().ua = "";
SDKSettings.disableAAIDUsage(false);
SDKSettings.setDoNotTrack(false);
}

@Test
Expand Down Expand Up @@ -615,13 +616,15 @@ public void testGDPRSettings() throws Exception {
executionSteps();
JSONObject postDataBeforeGDPRValueSet = inspectPostData();
assertFalse(postDataBeforeGDPRValueSet.has("gdpr_consent"));
assertTrue(Settings.getSettings().deviceAccessAllowed); // Default case with no GDPR settings device access should be allowed

ANGDPRSettings.setConsentRequired(activity, true);
ANGDPRSettings.setConsentString(activity, "fooBar");
executionSteps();
JSONObject postDataWithGDPRValueSet = inspectPostData();
assertEquals(true, postDataWithGDPRValueSet.getJSONObject("gdpr_consent").getBoolean("consent_required"));
assertEquals("fooBar", postDataWithGDPRValueSet.getJSONObject("gdpr_consent").getString("consent_string"));
assertFalse(Settings.getSettings().deviceAccessAllowed); // When consent required set to true and no purpose consent string deviceAccess is not allowed
}

/**
Expand Down

0 comments on commit 231e38e

Please sign in to comment.