diff --git a/app/build.gradle b/app/build.gradle index 845e6ab..f1c2cf9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,15 +1,15 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 23 - buildToolsVersion "23.0.3" + compileSdkVersion 24 + buildToolsVersion "24.0.1" defaultConfig { applicationId "com.unity3d.ads.example" minSdkVersion 9 - targetSdkVersion 23 - versionCode = 2002 - versionName = "2.0.2" + targetSdkVersion 24 + versionCode = 2003 + versionName = "2.0.3" } buildTypes { release { @@ -21,7 +21,7 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:23.0.0' + compile 'com.android.support:appcompat-v7:24.2.0' debugCompile project(path: ':lib', configuration: "debug") releaseCompile project(path: ':lib', configuration: "release") } diff --git a/app/src/main/java/com/unity3d/ads/example/UnityAdsExample.java b/app/src/main/java/com/unity3d/ads/example/UnityAdsExample.java index 439ec66..07094a6 100644 --- a/app/src/main/java/com/unity3d/ads/example/UnityAdsExample.java +++ b/app/src/main/java/com/unity3d/ads/example/UnityAdsExample.java @@ -29,6 +29,8 @@ public class UnityAdsExample extends Activity { private String interstitialPlacementId; private String incentivizedPlacementId; + private static int ordinal = 1; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -42,7 +44,6 @@ public class UnityAdsExample extends Activity { MediationMetaData mediationMetaData = new MediationMetaData(this); mediationMetaData.setName("mediationPartner"); mediationMetaData.setVersion("v12345"); - mediationMetaData.setOrdinal(1); mediationMetaData.commit(); MetaData debugMetaData = new MetaData(this); @@ -60,6 +61,10 @@ public class UnityAdsExample extends Activity { playerMetaData.setServerId("rikshot"); playerMetaData.commit(); + MediationMetaData ordinalMetaData = new MediationMetaData(self); + ordinalMetaData.setOrdinal(ordinal++); + ordinalMetaData.commit(); + UnityAds.show(self, interstitialPlacementId); } }); @@ -75,6 +80,10 @@ public class UnityAdsExample extends Activity { playerMetaData.setServerId("rikshot"); playerMetaData.commit(); + MediationMetaData ordinalMetaData = new MediationMetaData(self); + ordinalMetaData.setOrdinal(ordinal++); + ordinalMetaData.commit(); + UnityAds.show(self, incentivizedPlacementId); } }); diff --git a/build.gradle b/build.gradle index 6b3c317..8a31574 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.2' + classpath 'com.android.tools.build:gradle:2.1.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 6376c23..10c9c92 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Apr 07 11:46:35 EEST 2016 +#Mon Aug 22 16:49:01 EEST 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip diff --git a/lib/build.gradle b/lib/build.gradle index 27d4dd9..5577097 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -1,8 +1,8 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 23 - buildToolsVersion "23.0.3" + compileSdkVersion 24 + buildToolsVersion "24.0.1" com.android.ddmlib.DdmPreferences.setLogLevel("verbose") com.android.ddmlib.DdmPreferences.setTimeOut(10 * 60000) @@ -11,9 +11,9 @@ android { defaultConfig { minSdkVersion 9 - targetSdkVersion 23 - versionCode = 2002 - versionName = "2.0.2" + targetSdkVersion 24 + versionCode = 2003 + versionName = "2.0.3" setProperty("archivesBaseName", "unity-ads") diff --git a/lib/src/main/java/com/unity3d/ads/adunit/AdUnitActivity.java b/lib/src/main/java/com/unity3d/ads/adunit/AdUnitActivity.java index 5f18c0c..f484242 100644 --- a/lib/src/main/java/com/unity3d/ads/adunit/AdUnitActivity.java +++ b/lib/src/main/java/com/unity3d/ads/adunit/AdUnitActivity.java @@ -40,11 +40,18 @@ public class AdUnitActivity extends Activity { private ArrayList _keyEventList; boolean _keepScreenOn; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + // This error condition will trigger if activity is backgrounded while activity is in foreground, + // app process is killed while app is in background and then app is yet again launched to foreground + if(WebViewApp.getCurrentApp() == null) { + DeviceLog.error("Unity Ads web app is null, closing Unity Ads activity from onCreate"); + finish(); + return; + } + AdUnit.setAdUnitActivity(this); createLayout(); @@ -92,18 +99,45 @@ public class AdUnitActivity extends Activity { @Override protected void onStart() { super.onStart(); + + if(WebViewApp.getCurrentApp() == null) { + if(!isFinishing()) { + DeviceLog.error("Unity Ads web app is null, closing Unity Ads activity from onStart"); + finish(); + } + return; + } + WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.ADUNIT, AdUnitEvent.ON_START, _activityId); } @Override protected void onStop() { super.onStop(); + + if(WebViewApp.getCurrentApp() == null) { + if(!isFinishing()) { + DeviceLog.error("Unity Ads web app is null, closing Unity Ads activity from onStop"); + finish(); + } + return; + } + WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.ADUNIT, AdUnitEvent.ON_STOP, _activityId); } @Override protected void onResume() { super.onResume(); + + if(WebViewApp.getCurrentApp() == null) { + if(!isFinishing()) { + DeviceLog.error("Unity Ads web app is null, closing Unity Ads activity from onResume"); + finish(); + } + return; + } + setViews(_views); WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.ADUNIT, AdUnitEvent.ON_RESUME, _activityId); @@ -113,6 +147,14 @@ public class AdUnitActivity extends Activity { protected void onPause() { super.onPause(); + if(WebViewApp.getCurrentApp() == null) { + if(!isFinishing()) { + DeviceLog.error("Unity Ads web app is null, closing Unity Ads activity from onPause"); + finish(); + } + return; + } + if (isFinishing()) { ViewUtilities.removeViewFromParent(WebViewApp.getCurrentApp().getWebView()); } @@ -136,6 +178,15 @@ public class AdUnitActivity extends Activity { @Override protected void onDestroy() { super.onDestroy(); + + if(WebViewApp.getCurrentApp() == null) { + if(!isFinishing()) { + DeviceLog.error("Unity Ads web app is null, closing Unity Ads activity from onDestroy"); + finish(); + } + return; + } + AdUnit.setAdUnitActivity(null); WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.ADUNIT, AdUnitEvent.ON_DESTROY, isFinishing(), _activityId); diff --git a/lib/src/main/java/com/unity3d/ads/adunit/AdUnitOpen.java b/lib/src/main/java/com/unity3d/ads/adunit/AdUnitOpen.java index 6f30dfd..1466e79 100644 --- a/lib/src/main/java/com/unity3d/ads/adunit/AdUnitOpen.java +++ b/lib/src/main/java/com/unity3d/ads/adunit/AdUnitOpen.java @@ -13,7 +13,7 @@ import java.lang.reflect.Method; public class AdUnitOpen { private static ConditionVariable _waitShowStatus; - public static boolean open(String placementId, JSONObject options) throws NoSuchMethodException { + public static synchronized boolean open(String placementId, JSONObject options) throws NoSuchMethodException { Method showCallback = AdUnitOpen.class.getMethod("showCallback", CallbackStatus.class); _waitShowStatus = new ConditionVariable(); WebViewApp.getCurrentApp().invokeMethod("webview", "show", showCallback, placementId, options); diff --git a/lib/src/main/java/com/unity3d/ads/cache/CacheError.java b/lib/src/main/java/com/unity3d/ads/cache/CacheError.java index 73b7681..df5814e 100644 --- a/lib/src/main/java/com/unity3d/ads/cache/CacheError.java +++ b/lib/src/main/java/com/unity3d/ads/cache/CacheError.java @@ -6,5 +6,6 @@ public enum CacheError { FILE_ALREADY_CACHING, NOT_CACHING, JSON_ERROR, - NO_INTERNET + NO_INTERNET, + MALFORMED_URL } diff --git a/lib/src/main/java/com/unity3d/ads/cache/CacheThreadHandler.java b/lib/src/main/java/com/unity3d/ads/cache/CacheThreadHandler.java index 5518b35..343c1a3 100644 --- a/lib/src/main/java/com/unity3d/ads/cache/CacheThreadHandler.java +++ b/lib/src/main/java/com/unity3d/ads/cache/CacheThreadHandler.java @@ -113,15 +113,23 @@ class CacheThreadHandler extends Handler { // Note: active must be set to false before sending end/error event back to webview to allow webview to start next download or other operation immediately after receiving the event _active = false; postProcessDownload(startTime, source, targetFile, total, _currentRequest.getContentLength(), _currentRequest.isCanceled(), _currentRequest.getResponseCode(), _currentRequest.getResponseHeaders()); - } catch (FileNotFoundException e) { + } + catch (FileNotFoundException e) { DeviceLog.exception("Couldn't create target file", e); _active = false; WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.CACHE, CacheEvent.DOWNLOAD_ERROR, CacheError.FILE_IO_ERROR, source, e.getMessage()); - } catch (IOException e) { + } + catch (MalformedURLException e) { + DeviceLog.exception("Malformed URL", e); + _active = false; + WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.CACHE, CacheEvent.DOWNLOAD_ERROR, CacheError.MALFORMED_URL, source, e.getMessage()); + } + catch (IOException e) { DeviceLog.exception("Couldn't request stream", e); _active = false; WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.CACHE, CacheEvent.DOWNLOAD_ERROR, CacheError.FILE_IO_ERROR, source, e.getMessage()); - } finally { + } + finally { _currentRequest = null; try { if (fileOutput != null) { @@ -152,22 +160,13 @@ class CacheThreadHandler extends Handler { } } - private WebRequest getWebRequest(String source, long position, int connectTimeout, int readTimeout) { + private WebRequest getWebRequest(String source, long position, int connectTimeout, int readTimeout) throws MalformedURLException { HashMap> headers = new HashMap<>(); if (position > 0) { ArrayList list = new ArrayList(Arrays.asList(new String[]{"bytes=" + position + "-"})); headers.put("Range", list); } - WebRequest request = null; - - try { - request = new WebRequest(source, "GET", headers, connectTimeout, readTimeout); - } - catch (MalformedURLException e) { - DeviceLog.exception("Malformed URL", e); - } - - return request; + return new WebRequest(source, "GET", headers, connectTimeout, readTimeout); } } \ No newline at end of file diff --git a/lib/src/main/java/com/unity3d/ads/webview/WebView.java b/lib/src/main/java/com/unity3d/ads/webview/WebView.java index b13ff79..479835b 100644 --- a/lib/src/main/java/com/unity3d/ads/webview/WebView.java +++ b/lib/src/main/java/com/unity3d/ads/webview/WebView.java @@ -28,7 +28,6 @@ public class WebView extends android.webkit.WebView { } if (Build.VERSION.SDK_INT >= 19) { - WebView.setWebContentsDebuggingEnabled(true); try { _evaluateJavascript = android.webkit.WebView.class.getMethod("evaluateJavascript", String.class, ValueCallback.class); } catch(NoSuchMethodException e) {