Skip to content

Commit 3c7c57d

Browse files
author
Ville Orkas
committed
Release 2.0.3
1 parent 45f136f commit 3c7c57d

File tree

10 files changed

+92
-33
lines changed

10 files changed

+92
-33
lines changed

app/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 23
5-
buildToolsVersion "23.0.3"
4+
compileSdkVersion 24
5+
buildToolsVersion "24.0.1"
66

77
defaultConfig {
88
applicationId "com.unity3d.ads.example"
99
minSdkVersion 9
10-
targetSdkVersion 23
11-
versionCode = 2002
12-
versionName = "2.0.2"
10+
targetSdkVersion 24
11+
versionCode = 2003
12+
versionName = "2.0.3"
1313
}
1414
buildTypes {
1515
release {
@@ -21,7 +21,7 @@ android {
2121

2222
dependencies {
2323
compile fileTree(dir: 'libs', include: ['*.jar'])
24-
compile 'com.android.support:appcompat-v7:23.0.0'
24+
compile 'com.android.support:appcompat-v7:24.2.0'
2525
debugCompile project(path: ':lib', configuration: "debug")
2626
releaseCompile project(path: ':lib', configuration: "release")
2727
}

app/src/main/java/com/unity3d/ads/example/UnityAdsExample.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public class UnityAdsExample extends Activity {
2929
private String interstitialPlacementId;
3030
private String incentivizedPlacementId;
3131

32+
private static int ordinal = 1;
33+
3234
@Override
3335
protected void onCreate(Bundle savedInstanceState) {
3436
super.onCreate(savedInstanceState);
@@ -42,7 +44,6 @@ protected void onCreate(Bundle savedInstanceState) {
4244
MediationMetaData mediationMetaData = new MediationMetaData(this);
4345
mediationMetaData.setName("mediationPartner");
4446
mediationMetaData.setVersion("v12345");
45-
mediationMetaData.setOrdinal(1);
4647
mediationMetaData.commit();
4748

4849
MetaData debugMetaData = new MetaData(this);
@@ -60,6 +61,10 @@ public void onClick(View v) {
6061
playerMetaData.setServerId("rikshot");
6162
playerMetaData.commit();
6263

64+
MediationMetaData ordinalMetaData = new MediationMetaData(self);
65+
ordinalMetaData.setOrdinal(ordinal++);
66+
ordinalMetaData.commit();
67+
6368
UnityAds.show(self, interstitialPlacementId);
6469
}
6570
});
@@ -75,6 +80,10 @@ public void onClick(View v) {
7580
playerMetaData.setServerId("rikshot");
7681
playerMetaData.commit();
7782

83+
MediationMetaData ordinalMetaData = new MediationMetaData(self);
84+
ordinalMetaData.setOrdinal(ordinal++);
85+
ordinalMetaData.commit();
86+
7887
UnityAds.show(self, incentivizedPlacementId);
7988
}
8089
});

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ buildscript {
44
jcenter()
55
}
66
dependencies {
7-
classpath 'com.android.tools.build:gradle:2.1.2'
7+
classpath 'com.android.tools.build:gradle:2.1.3'
88

99
// NOTE: Do not place your application dependencies here; they belong
1010
// in the individual module build.gradle files
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Thu Apr 07 11:46:35 EEST 2016
1+
#Mon Aug 22 16:49:01 EEST 2016
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

lib/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
apply plugin: 'com.android.library'
22

33
android {
4-
compileSdkVersion 23
5-
buildToolsVersion "23.0.3"
4+
compileSdkVersion 24
5+
buildToolsVersion "24.0.1"
66
com.android.ddmlib.DdmPreferences.setLogLevel("verbose")
77
com.android.ddmlib.DdmPreferences.setTimeOut(10 * 60000)
88

@@ -11,9 +11,9 @@ android {
1111

1212
defaultConfig {
1313
minSdkVersion 9
14-
targetSdkVersion 23
15-
versionCode = 2002
16-
versionName = "2.0.2"
14+
targetSdkVersion 24
15+
versionCode = 2003
16+
versionName = "2.0.3"
1717

1818
setProperty("archivesBaseName", "unity-ads")
1919

lib/src/main/java/com/unity3d/ads/adunit/AdUnitActivity.java

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,18 @@ public class AdUnitActivity extends Activity {
4040
private ArrayList<Integer> _keyEventList;
4141
boolean _keepScreenOn;
4242

43-
4443
@Override
4544
protected void onCreate(Bundle savedInstanceState) {
4645
super.onCreate(savedInstanceState);
4746

47+
// This error condition will trigger if activity is backgrounded while activity is in foreground,
48+
// app process is killed while app is in background and then app is yet again launched to foreground
49+
if(WebViewApp.getCurrentApp() == null) {
50+
DeviceLog.error("Unity Ads web app is null, closing Unity Ads activity from onCreate");
51+
finish();
52+
return;
53+
}
54+
4855
AdUnit.setAdUnitActivity(this);
4956

5057
createLayout();
@@ -92,18 +99,45 @@ protected void onCreate(Bundle savedInstanceState) {
9299
@Override
93100
protected void onStart() {
94101
super.onStart();
102+
103+
if(WebViewApp.getCurrentApp() == null) {
104+
if(!isFinishing()) {
105+
DeviceLog.error("Unity Ads web app is null, closing Unity Ads activity from onStart");
106+
finish();
107+
}
108+
return;
109+
}
110+
95111
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.ADUNIT, AdUnitEvent.ON_START, _activityId);
96112
}
97113

98114
@Override
99115
protected void onStop() {
100116
super.onStop();
117+
118+
if(WebViewApp.getCurrentApp() == null) {
119+
if(!isFinishing()) {
120+
DeviceLog.error("Unity Ads web app is null, closing Unity Ads activity from onStop");
121+
finish();
122+
}
123+
return;
124+
}
125+
101126
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.ADUNIT, AdUnitEvent.ON_STOP, _activityId);
102127
}
103128

104129
@Override
105130
protected void onResume() {
106131
super.onResume();
132+
133+
if(WebViewApp.getCurrentApp() == null) {
134+
if(!isFinishing()) {
135+
DeviceLog.error("Unity Ads web app is null, closing Unity Ads activity from onResume");
136+
finish();
137+
}
138+
return;
139+
}
140+
107141
setViews(_views);
108142

109143
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.ADUNIT, AdUnitEvent.ON_RESUME, _activityId);
@@ -113,6 +147,14 @@ protected void onResume() {
113147
protected void onPause() {
114148
super.onPause();
115149

150+
if(WebViewApp.getCurrentApp() == null) {
151+
if(!isFinishing()) {
152+
DeviceLog.error("Unity Ads web app is null, closing Unity Ads activity from onPause");
153+
finish();
154+
}
155+
return;
156+
}
157+
116158
if (isFinishing()) {
117159
ViewUtilities.removeViewFromParent(WebViewApp.getCurrentApp().getWebView());
118160
}
@@ -136,6 +178,15 @@ public void onSaveInstanceState(Bundle outState) {
136178
@Override
137179
protected void onDestroy() {
138180
super.onDestroy();
181+
182+
if(WebViewApp.getCurrentApp() == null) {
183+
if(!isFinishing()) {
184+
DeviceLog.error("Unity Ads web app is null, closing Unity Ads activity from onDestroy");
185+
finish();
186+
}
187+
return;
188+
}
189+
139190
AdUnit.setAdUnitActivity(null);
140191
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.ADUNIT, AdUnitEvent.ON_DESTROY, isFinishing(), _activityId);
141192

lib/src/main/java/com/unity3d/ads/adunit/AdUnitOpen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
public class AdUnitOpen {
1414
private static ConditionVariable _waitShowStatus;
1515

16-
public static boolean open(String placementId, JSONObject options) throws NoSuchMethodException {
16+
public static synchronized boolean open(String placementId, JSONObject options) throws NoSuchMethodException {
1717
Method showCallback = AdUnitOpen.class.getMethod("showCallback", CallbackStatus.class);
1818
_waitShowStatus = new ConditionVariable();
1919
WebViewApp.getCurrentApp().invokeMethod("webview", "show", showCallback, placementId, options);

lib/src/main/java/com/unity3d/ads/cache/CacheError.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ public enum CacheError {
66
FILE_ALREADY_CACHING,
77
NOT_CACHING,
88
JSON_ERROR,
9-
NO_INTERNET
9+
NO_INTERNET,
10+
MALFORMED_URL
1011
}

lib/src/main/java/com/unity3d/ads/cache/CacheThreadHandler.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,23 @@ public void onRequestProgress(String url, long bytes, long total) {
113113
// 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
114114
_active = false;
115115
postProcessDownload(startTime, source, targetFile, total, _currentRequest.getContentLength(), _currentRequest.isCanceled(), _currentRequest.getResponseCode(), _currentRequest.getResponseHeaders());
116-
} catch (FileNotFoundException e) {
116+
}
117+
catch (FileNotFoundException e) {
117118
DeviceLog.exception("Couldn't create target file", e);
118119
_active = false;
119120
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.CACHE, CacheEvent.DOWNLOAD_ERROR, CacheError.FILE_IO_ERROR, source, e.getMessage());
120-
} catch (IOException e) {
121+
}
122+
catch (MalformedURLException e) {
123+
DeviceLog.exception("Malformed URL", e);
124+
_active = false;
125+
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.CACHE, CacheEvent.DOWNLOAD_ERROR, CacheError.MALFORMED_URL, source, e.getMessage());
126+
}
127+
catch (IOException e) {
121128
DeviceLog.exception("Couldn't request stream", e);
122129
_active = false;
123130
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.CACHE, CacheEvent.DOWNLOAD_ERROR, CacheError.FILE_IO_ERROR, source, e.getMessage());
124-
} finally {
131+
}
132+
finally {
125133
_currentRequest = null;
126134
try {
127135
if (fileOutput != null) {
@@ -152,22 +160,13 @@ private void postProcessDownload(long startTime, String source, File targetFile,
152160
}
153161
}
154162

155-
private WebRequest getWebRequest(String source, long position, int connectTimeout, int readTimeout) {
163+
private WebRequest getWebRequest(String source, long position, int connectTimeout, int readTimeout) throws MalformedURLException {
156164
HashMap<String, List<String>> headers = new HashMap<>();
157165
if (position > 0) {
158166
ArrayList list = new ArrayList(Arrays.asList(new String[]{"bytes=" + position + "-"}));
159167
headers.put("Range", list);
160168
}
161169

162-
WebRequest request = null;
163-
164-
try {
165-
request = new WebRequest(source, "GET", headers, connectTimeout, readTimeout);
166-
}
167-
catch (MalformedURLException e) {
168-
DeviceLog.exception("Malformed URL", e);
169-
}
170-
171-
return request;
170+
return new WebRequest(source, "GET", headers, connectTimeout, readTimeout);
172171
}
173172
}

lib/src/main/java/com/unity3d/ads/webview/WebView.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public WebView(Context context) {
2828
}
2929

3030
if (Build.VERSION.SDK_INT >= 19) {
31-
WebView.setWebContentsDebuggingEnabled(true);
3231
try {
3332
_evaluateJavascript = android.webkit.WebView.class.getMethod("evaluateJavascript", String.class, ValueCallback.class);
3433
} catch(NoSuchMethodException e) {

0 commit comments

Comments
 (0)