Skip to content

Commit

Permalink
Release: version 4.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Shayefar committed May 5, 2016
1 parent b5e96fc commit 5b7af6c
Show file tree
Hide file tree
Showing 15 changed files with 167 additions and 93 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### Version 4.6.1 (May 5, 2016)
- Enhanced caching logic for HTML and MRAID interstitials. Resource-heavy interstitials will now render more quickly when MoPubInterstitial#show() is called.

## Version 4.6.0 (April 21, 2016)
- Certified Chartboost version 6.4.1
- Certified Tapjoy version 11.5.1
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The MoPub SDK is available via:
}
dependencies {
compile('com.mopub:mopub-sdk:4.5.1@aar') {
compile('com.mopub:mopub-sdk:4.6.1@aar') {
transitive = true
}
}
Expand Down Expand Up @@ -62,8 +62,7 @@ The MoPub SDK is available via:
## New in this Version
Please view the [changelog](https://github.com/mopub/mopub-android-sdk/blob/master/CHANGELOG.md) for a complete list of additions, fixes, and enhancements in the latest release.
- Certified Chartboost version 6.4.1
- Certified Tapjoy version 11.5.1
- Enhanced caching logic for HTML and MRAID interstitials. Resource-heavy interstitials will now render more quickly when MoPubInterstitial#show() is called.
## Requirements
Expand Down
4 changes: 2 additions & 2 deletions mopub-sample/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mopub.simpleadsdemo"
android:versionCode="39"
android:versionName="4.6.0">
android:versionCode="40"
android:versionName="4.6.1">
<uses-sdk android:minSdkVersion="9"
android:targetSdkVersion="23"/>

Expand Down
4 changes: 2 additions & 2 deletions mopub-sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ apply plugin: 'com.android.application'

group = 'com.mopub'
description = '''MoPub Sample App'''
version = '4.6.0'
version = '4.6.1'

android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
lintOptions { abortOnError false }

defaultConfig {
versionCode 39
versionCode 40
versionName version
minSdkVersion 9
targetSdkVersion 23
Expand Down
4 changes: 2 additions & 2 deletions mopub-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ task wrapper(type: Wrapper) {

group = 'com.mopub'
description = '''MoPub Android SDK'''
version = '4.6.0'
version = '4.6.1'

android {
compileSdkVersion 23
Expand All @@ -46,7 +46,7 @@ android {
useLibrary 'org.apache.http.legacy'

defaultConfig {
versionCode 39
versionCode 40
versionName version
minSdkVersion 9
targetSdkVersion 23
Expand Down
2 changes: 1 addition & 1 deletion mopub-sdk/src/main/java/com/mopub/common/MoPub.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.mopub.mobileads.MoPubRewardedVideoManager.RequestParameters;

public class MoPub {
public static final String SDK_VERSION = "4.6.0";
public static final String SDK_VERSION = "4.6.1";

public enum LocationAwareness { NORMAL, TRUNCATED, DISABLED }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ public void onClose() {
mCloseableLayout.addView(adView,
new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
setContentView(mCloseableLayout);


}

@Override
Expand Down
76 changes: 46 additions & 30 deletions mopub-sdk/src/main/java/com/mopub/mobileads/BaseWebView.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mopub.mobileads;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.graphics.PixelFormat;
Expand All @@ -11,6 +12,7 @@
import android.webkit.WebSettings;
import android.webkit.WebView;

import com.mopub.common.VisibleForTesting;
import com.mopub.common.util.VersionCode;
import com.mopub.common.util.Views;
import com.mopub.mobileads.util.WebViews;
Expand All @@ -25,30 +27,29 @@ public BaseWebView(Context context) {
* an Activity context, as it will leak on Froyo devices and earlier.
*/
super(context.getApplicationContext());
enablePlugins(false);

enablePlugins(false);
restrictDeviceContentAccess();
WebViews.setDisableJSChromeClient(this);

if (!sDeadlockCleared) {
clearWebViewDeadlock(getContext());
sDeadlockCleared = true;
}
}

/*
* Disabling file access and content access prevents advertising creatives from
* detecting the presence of, or reading, files on the device filesystem.
*/

getSettings().setAllowFileAccess(false);
@Override
public void destroy() {
mIsDestroyed = true;

if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
getSettings().setAllowContentAccess(false);
}
// Needed to prevent receiving the following error on Android versions using WebViewClassic
// https://code.google.com/p/android/issues/detail?id=65833.
Views.removeFromParent(this);

if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
getSettings().setAllowFileAccessFromFileURLs(false);
getSettings().setAllowUniversalAccessFromFileURLs(false);
}
// Even after removing from the parent, WebViewClassic can leak because of a static
// reference from HTML5VideoViewProcessor. Removing children fixes this problem.
removeAllViews();
super.destroy();
}

protected void enablePlugins(final boolean enabled) {
Expand All @@ -64,23 +65,34 @@ protected void enablePlugins(final boolean enabled) {
}
}

@Override
public void destroy() {
mIsDestroyed = true;
/*
* Intended to be used with dummy WebViews to precache WebView javascript and assets.
*/
@SuppressLint("SetJavaScriptEnabled")
protected void enableJavascriptCaching() {
getSettings().setJavaScriptEnabled(true);
getSettings().setDomStorageEnabled(true);
getSettings().setAppCacheEnabled(true);
// Required for the Application Caches API to be enabled
// See: http://developer.android.com/reference/android/webkit/WebSettings.html#setAppCachePath(java.lang.String)
getSettings().setAppCachePath(getContext().getCacheDir().getAbsolutePath());
}

// Needed to prevent receiving the following error on Android versions using WebViewClassic
// https://code.google.com/p/android/issues/detail?id=65833.
Views.removeFromParent(this);
/*
* Disabling file access and content access prevents advertising creatives from
* detecting the presence of, or reading, files on the device filesystem.
*/
private void restrictDeviceContentAccess() {
getSettings().setAllowFileAccess(false);

// Even after removing from the parent, WebViewClassic can leak because of a static
// reference from HTML5VideoViewProcessor. Removing children fixes this problem.
removeAllViews();
super.destroy();
}
if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
getSettings().setAllowContentAccess(false);
}

@Deprecated // for testing
void setIsDestroyed(boolean isDestroyed) {
mIsDestroyed = isDestroyed;
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
getSettings().setAllowFileAccessFromFileURLs(false);
getSettings().setAllowUniversalAccessFromFileURLs(false);
}
}

/**
Expand All @@ -96,7 +108,7 @@ void setIsDestroyed(boolean isDestroyed) {
*/
private void clearWebViewDeadlock(@NonNull final Context context) {
if (VERSION.SDK_INT == VERSION_CODES.KITKAT) {
// Create an invisible webview
// Create an invisible WebView
final WebView webView = new WebView(context.getApplicationContext());
webView.setBackgroundColor(Color.TRANSPARENT);

Expand All @@ -120,5 +132,9 @@ private void clearWebViewDeadlock(@NonNull final Context context) {
}
}


@VisibleForTesting
@Deprecated // for testing
void setIsDestroyed(boolean isDestroyed) {
mIsDestroyed = isDestroyed;
}
}
12 changes: 8 additions & 4 deletions mopub-sdk/src/main/java/com/mopub/mobileads/MoPubActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,19 @@ static Intent createIntent(Context context,

static void preRenderHtml(final Context context, final AdReport adReport,
final CustomEventInterstitialListener customEventInterstitialListener,
String htmlData) {
HtmlInterstitialWebView dummyWebView = HtmlInterstitialWebViewFactory.create(context, adReport, customEventInterstitialListener, false, null, null);
final String htmlData) {
final HtmlInterstitialWebView dummyWebView = HtmlInterstitialWebViewFactory.create(context,
adReport, customEventInterstitialListener, false, null, null);

dummyWebView.enablePlugins(false);
dummyWebView.enableJavascriptCaching();

dummyWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.equals(MOPUB_FINISH_LOAD)) {
if (MOPUB_FINISH_LOAD.equals(url)) {
customEventInterstitialListener.onInterstitialLoaded();
} else if (url.equals(MOPUB_FAIL_LOAD)) {
} else if (MOPUB_FAIL_LOAD.equals(url)) {
customEventInterstitialListener.onInterstitialFailed(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,16 @@ public class MraidActivity extends BaseInterstitialActivity {
public static void preRenderHtml(@NonNull final Context context,
@NonNull final CustomEventInterstitialListener customEventInterstitialListener,
@NonNull final String htmlData) {
BaseWebView dummyWebView = new BaseWebView(context);
preRenderHtml(customEventInterstitialListener, htmlData, new BaseWebView(context));
}

@VisibleForTesting
static void preRenderHtml(
@NonNull final CustomEventInterstitialListener customEventInterstitialListener,
@NonNull final String htmlData, @NonNull final BaseWebView dummyWebView) {
dummyWebView.enablePlugins(false);
dummyWebView.enableJavascriptCaching();

dummyWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(final WebView view, final String url) {
Expand Down
19 changes: 12 additions & 7 deletions mopub-sdk/src/main/java/com/mopub/mobileads/util/WebViews.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class WebViews {
@TargetApi(VERSION_CODES.HONEYCOMB)
public static void onResume(@NonNull WebView webView) {
public static void onResume(@NonNull final WebView webView) {
if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
webView.onResume();
return;
Expand All @@ -29,7 +29,7 @@ public static void onResume(@NonNull WebView webView) {
}

@TargetApi(VERSION_CODES.HONEYCOMB)
public static void onPause(@NonNull WebView webView, boolean isFinishing) {
public static void onPause(@NonNull final WebView webView, boolean isFinishing) {
// XXX
// We need to call WebView#stopLoading and WebView#loadUrl here due to an Android
// bug where the audio of an HTML5 video will continue to play after the activity has been
Expand All @@ -53,31 +53,36 @@ public static void onPause(@NonNull WebView webView, boolean isFinishing) {
}
}

public static void setDisableJSChromeClient(WebView webView) {
public static void setDisableJSChromeClient(@NonNull final WebView webView) {
webView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
public boolean onJsAlert(@NonNull final WebView view, @NonNull final String url,
@NonNull final String message, @NonNull final JsResult result) {
MoPubLog.d(message);
result.confirm();
return true;
}

@Override
public boolean onJsConfirm(WebView view, String url, String message, JsResult result) {
public boolean onJsConfirm(@NonNull final WebView view, @NonNull final String url,
@NonNull final String message, @NonNull final JsResult result) {
MoPubLog.d(message);
result.confirm();
return true;
}

@Override
public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) {
public boolean onJsPrompt(@NonNull final WebView view, @NonNull final String url,
@NonNull final String message, @NonNull final String defaultValue,
@NonNull final JsPromptResult result) {
MoPubLog.d(message);
result.confirm();
return true;
}

@Override
public boolean onJsBeforeUnload(WebView view, String url, String message, JsResult result) {
public boolean onJsBeforeUnload(@NonNull final WebView view, @NonNull final String url,
@NonNull final String message, @NonNull final JsResult result) {
MoPubLog.d(message);
result.confirm();
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fabric-identifier=com.mopub.sdk.android:mopub
fabric-version=4.6.0+kit
fabric-version=4.6.1+kit
fabric-build-type=source
14 changes: 14 additions & 0 deletions mopub-sdk/src/test/java/com/mopub/mobileads/BaseWebViewTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.robolectric.Robolectric;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.fakes.RoboWebSettings;
import org.robolectric.shadows.ShadowWebView;

import static org.fest.assertions.api.Assertions.assertThat;
Expand Down Expand Up @@ -81,6 +82,19 @@ public void atLeastJellybeanMr2_shouldPass() throws Exception {
// pass
}

@Test
public void enableJavascriptCaching_enablesJavascriptDomStorageAndAppCache() {
subject = new BaseWebView(context);
final RoboWebSettings settings = (RoboWebSettings) subject.getSettings();

subject.enableJavascriptCaching();

assertThat(settings.getJavaScriptEnabled()).isTrue();
assertThat(settings.getDomStorageEnabled()).isTrue();
assertThat(settings.getAppCacheEnabled()).isTrue();
assertThat(settings.getAppCachePath()).isEqualTo(context.getCacheDir().getAbsolutePath());
}

@Test
public void destroy_shouldRemoveSelfFromParent_beforeCallingDestroy() throws Exception {
subject = new BaseWebView(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ public void preRenderHtml_shouldPreloadTheHtml() throws Exception {
verify(htmlInterstitialWebView).loadHtmlResponse(htmlData);
}

@Test
public void preRenderHtml_shouldEnableJavascriptCachingForDummyWebView() {
MoPubActivity.preRenderHtml(subject, mockAdReport, customEventInterstitialListener,
"html_data");

verify(htmlInterstitialWebView).enableJavascriptCaching();
}

@Test
public void preRenderHtml_shouldHaveAWebViewClientThatForwardsFinishLoad() throws Exception {
MoPubActivity.preRenderHtml(subject, mockAdReport, customEventInterstitialListener, null);
Expand Down
Loading

0 comments on commit 5b7af6c

Please sign in to comment.