Skip to content

Commit

Permalink
Release 3.4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
UnitySteven committed Jun 4, 2020
1 parent a91c1a3 commit c70247b
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 225 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.unity3d.ads.example"
minSdkVersion 14
targetSdkVersion 26
versionCode = 3420
versionName = "3.4.2"
versionCode = 3460
versionName = "3.4.6"
}

flavorDimensions "arEnabled"
Expand Down
6 changes: 3 additions & 3 deletions unity-ads/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ext {
siteUrl = 'https://github.com/Unity-Technologies/unity-ads-android'
gitUrl = 'https://github.com/Unity-Technologies/unity-ads-android.git'

libraryVersion = '3.4.2'
libraryVersion = '3.4.6'

developerId = 'sbankhead'
developerName = 'Steven Bankhead'
Expand Down Expand Up @@ -50,8 +50,8 @@ android {
All SDK with version numbers with last two digits >= 50 will be treated
as China SDK for filtering in the backend.
*/
versionCode = 3420
versionName = "3.4.2"
versionCode = 3460
versionName = "3.4.6"

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.unity3d.ads.test.legacy.LifecycleListenerTest;
import com.unity3d.ads.test.legacy.MetaDataTest;
import com.unity3d.ads.test.legacy.NativeCallbackTest;
import com.unity3d.ads.test.legacy.PackageManagerTest;
import com.unity3d.ads.test.legacy.PlacementTest;
import com.unity3d.ads.test.legacy.PreferencesTest;
import com.unity3d.ads.test.legacy.PublicApiTest;
Expand Down Expand Up @@ -52,7 +51,6 @@
InvocationTest.class,
MetaDataTest.class,
NativeCallbackTest.class,
PackageManagerTest.class,
PlacementTest.class,
PublicApiTest.class,
RequestTest.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,6 @@ public void testAndroidId () {
assertTrue("AndroidID length should be 8 chars or more (64bit)", Device.getAndroidId().length() >= 8);
}

@Test
public void testIsAppInstalled () {
List<Map<String, Object>> installedPackages = Device.getInstalledPackages(false);
assertNotNull("Installed packages should not be null", installedPackages);
assertTrue("Installed packages contained: " + installedPackages.get(0).get("name") + " so it should also be installed", Device.isAppInstalled((String)installedPackages.get(0).get("name")));
}

@Test
public void testInstalledPackages () {
List<Map<String, Object>> installedPackages = Device.getInstalledPackages(false);
assertNotNull("Installed packages should not be null", installedPackages);
assertTrue("Installed packages should contain at least 1 entry", installedPackages.size() > 0);
}

@Test
public void testIsActiveNetworkConnected () {
assertTrue("Active network should be connected", Device.isActiveNetworkConnected());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import java.lang.reflect.Constructor;
import java.net.MalformedURLException;
import java.net.URISyntaxException;

Expand Down Expand Up @@ -244,4 +245,17 @@ public void testInitializeStateRetry() {
assertFalse("Init state retry test: retry delay is less than four seconds (should be five seconds)", (endTime - startTime) < 4000);
assertFalse("Init state retry test: retry delay is greater than six seconds (should be five seconds)", (endTime - startTime) > 6000);
}

@Test()
public void testInitializeThreadRunThrowOOMError() throws Exception {
Constructor<InitializeThread> constructor = InitializeThread.class.getDeclaredConstructor(Class.forName("com.unity3d.services.core.configuration.InitializeThread$InitializeState"));
constructor.setAccessible(true);
InitializeThread initializeThread = constructor.newInstance(new InitializeThread.InitializeStateCreate(null, null) {
@Override
public InitializeThread.InitializeStateCreate execute() {
throw new OutOfMemoryError("This should get caught automatically");
}
});
initializeThread.run();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,27 @@ public void testSha256Stream() throws Exception {
}

@Test
public void testReadFileBytes() throws Exception {
byte[] large_data = Utilities.readFileBytes(new File(SdkProperties.getCacheDirectory() + "/" + SdkProperties.getCacheFilePrefix() + "testfile_large.dat"));
public void testReadFileBytesNull() throws Exception {
byte[] null_data = Utilities.readFileBytes(new File(SdkProperties.getCacheDirectory() + "/" + SdkProperties.getCacheFilePrefix() + null));
assertEquals("Incorrectly read bytes of null file", null, null_data);
}

@Test
public void testReadFileBytesNonExistent() throws Exception {
byte[] fake_data = Utilities.readFileBytes(new File(SdkProperties.getCacheDirectory() + "/" + SdkProperties.getCacheFilePrefix() + "fake_file.dat"));
assertEquals("Incorrect read bytes of non-existent file", null, fake_data);
}

@Test
public void testReadFileBytesSmallFile() throws Exception {
byte[] small_data = Utilities.readFileBytes(new File(SdkProperties.getCacheDirectory() + "/" + SdkProperties.getCacheFilePrefix() + "testfile_small.dat"));
assertEquals("Incorrect read small file data size", 1024, small_data.length);
}

@Test
public void testReadFileBytesLargeFile() throws Exception {
byte[] large_data = Utilities.readFileBytes(new File(SdkProperties.getCacheDirectory() + "/" + SdkProperties.getCacheFilePrefix() + "testfile_large.dat"));
assertEquals("Incorrect read large file data size", 56789, large_data.length);
assertEquals("Incorrect read small file data size", 1024, small_data.length);
}

public void assertHash(int size, String sha256) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,13 @@ public void onLoadResource(WebView view, String url) {
@TargetApi(14)
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
if (shouldCallSuper("onReceivedSslError")) {
super.onReceivedSslError(view, handler, error);
}
// Don't call shouldCallSuper("onReceivedSslError") to ensure
// we always rely on the default behavior. Otherwise it is
// possible Google might reject the app as an unsafe implementation.
// https://support.google.com/faqs/answer/7071387?hl=en
super.onReceivedSslError(view, handler, error);
DeviceLog.error("Received SSL error for '%s': %s", error.getUrl(), error.toString());

if (shouldSendEvent("onReceivedSslError")) {
String url = "";
if (error != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package com.unity3d.services.core.api;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.hardware.Sensor;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.util.SparseArray;

import com.unity3d.services.core.device.Device;
Expand Down Expand Up @@ -147,11 +142,6 @@ public static void getNetworkCountryISO(WebViewCallback callback) {
callback.invoke(Device.getNetworkCountryISO());
}

@WebViewExposed
public static void isAppInstalled(String pkgname, WebViewCallback callback) {
callback.invoke(Device.isAppInstalled(pkgname));
}

@WebViewExposed
public static void isRooted(WebViewCallback callback) {
callback.invoke(Device.isRooted());
Expand All @@ -167,13 +157,6 @@ public static void isAdbEnabled(WebViewCallback callback) {
}
}

@WebViewExposed
public static void getInstalledPackages(boolean md5, WebViewCallback callback) {
List<Map<String, Object>> installedPackages = Device.getInstalledPackages(md5);
JSONArray packageJson = new JSONArray(installedPackages);
callback.invoke(packageJson);
}

@WebViewExposed
public static void getPackageInfo(String packageName, WebViewCallback callback) {
if (ClientProperties.getApplicationContext() != null) {
Expand Down Expand Up @@ -591,56 +574,5 @@ public static void getBuildId(WebViewCallback callback) {
public static void getBuildVersionIncremental(WebViewCallback callback) {
callback.invoke(Device.getBuildVersionIncremental());
}

@WebViewExposed
@SuppressLint("MissingPermission")
public static void getDeviceIdWithSlot(final Integer slotIndex, WebViewCallback callback) {
getDeviceIdCommon(slotIndex, callback);
}

@WebViewExposed
public static void getDeviceId(WebViewCallback callback) {
getDeviceIdCommon(null, callback);

}

@SuppressLint("MissingPermission")
private static void getDeviceIdCommon(final Integer slotIndex, WebViewCallback callback) {
if (ClientProperties.getApplicationContext() == null) {
callback.error(DeviceError.APPLICATION_CONTEXT_NULL);
return;
}

if (ClientProperties.getApplicationContext().checkCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
callback.error(PermissionsError.PERMISSION_NOT_GRANTED);
return;
}

TelephonyManager mTelephony = (TelephonyManager) ClientProperties.getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);

if (mTelephony != null) {
// check api version
// getDeviceId was deprecated in API level 26
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (slotIndex == null) {
callback.invoke(mTelephony.getImei());
} else {
callback.invoke(mTelephony.getImei(slotIndex));
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (slotIndex == null) {
callback.invoke(mTelephony.getDeviceId());
} else {
callback.invoke(mTelephony.getDeviceId(slotIndex));
}
} else if (slotIndex == null) {
// getDeviceId() is supported for API level <= 23 but getDeviceId(int) is not
callback.invoke(mTelephony.getDeviceId());
} else {
callback.error(DeviceError.API_LEVEL_ERROR, Build.VERSION.SDK_INT);
}
}

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ enum PermissionsError {
COULDNT_GET_PERMISSIONS,
NO_REQUESTED_PERMISSIONS,
ERROR_CHECKING_PERMISSION,
ERROR_REQUESTING_PERMISSIONS,
PERMISSION_NOT_GRANTED
ERROR_REQUESTING_PERMISSIONS
}

public class Permissions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import com.unity3d.services.core.webview.WebViewApp;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;

public class InitializeThread extends Thread {
Expand All @@ -31,10 +29,21 @@ private InitializeThread(InitializeState state) {

@Override
public void run() {
while ((_state != null && !(_state instanceof InitializeStateComplete)) && !_stopThread) {
_state = _state.execute();
try {
while ((_state != null && !(_state instanceof InitializeStateComplete)) && !_stopThread) {
try {
_state = _state.execute();
} catch (Exception e) {
DeviceLog.exception("Unity Ads SDK encountered an error during initialization, cancel initialization", e);
_state = new InitializeThread.InitializeStateForceReset();
} catch (OutOfMemoryError oom) {
DeviceLog.exception("Application doesn't have enough memory to initialize Unity Ads SDK", new Exception(oom));
_state = new InitializeThread.InitializeStateForceReset();
}
}
} catch (OutOfMemoryError oom) {
//Do Nothing
}

_thread = null;
}

Expand Down Expand Up @@ -225,7 +234,7 @@ public InitializeState execute() {

try {
localWebViewData = Utilities.readFileBytes(new File(SdkProperties.getLocalWebViewFile()));
} catch (IOException e) {
} catch (Exception e) {
DeviceLog.debug("Unity Ads init: webapp not found in local cache: " + e.getMessage());
return new InitializeStateLoadWeb(_configuration);
}
Expand All @@ -237,7 +246,7 @@ public InitializeState execute() {

try {
webViewDataString = new String(localWebViewData, "UTF-8");
} catch (UnsupportedEncodingException e) {
} catch (Exception e) {
return new InitializeStateError("load cache", e, _configuration);
}

Expand Down Expand Up @@ -469,7 +478,7 @@ public InitializeState execute() {
DeviceLog.debug("Unity Ads init: retrying in " + _delay + " seconds");
try {
Thread.sleep(_delay * 1000L);
} catch(InterruptedException e) {
} catch(Exception e) {
DeviceLog.exception("Init retry interrupted", e);
}

Expand Down
Loading

0 comments on commit c70247b

Please sign in to comment.