From 2417560b45a7678763dcf2545c1c31029aff5495 Mon Sep 17 00:00:00 2001 From: Steven Bankhead Date: Thu, 18 Mar 2021 18:24:54 -0700 Subject: [PATCH] Release 3.6.2 --- Makefile | 89 ++++++++++--------- app/build.gradle | 4 +- build.gradle | 1 + scripts/wakeUpDevice.sh | 24 +++++ unity-ads/build.gradle | 62 ++++++++----- .../ads/test/legacy/ConnectivityTest.java | 57 ++++++++++++ .../com/unity3d/ads/metadata/MetaData.java | 21 +++++ .../connectivity/ConnectivityMonitor.java | 8 +- .../ConnectivityNetworkCallback.java | 4 +- 9 files changed, 198 insertions(+), 72 deletions(-) create mode 100755 scripts/wakeUpDevice.sh diff --git a/Makefile b/Makefile index 6c410934..b53cf00c 100644 --- a/Makefile +++ b/Makefile @@ -1,77 +1,78 @@ +debug: + ./gradlew :unity-ads:assembleDebug + release: ./gradlew :unity-ads:assembleRelease clean: ./gradlew :unity-ads:clean -test: test-hosted +coverage: + ./gradlew -i jacocoTestReport --debug -test-local: push-test-server-address exec-tests +coverage-ci: debug test-ci coverage -test-unit-tests: push-test-server-address exec-unit-tests +zip: release + cp unity-ads/build/outputs/aar/unity-ads-release.aar unity-ads.aar + zip -9r unity-ads.aar.zip unity-ads.aar + rm unity-ads.aar -build-test-apk: clean - ./gradlew :unity-ads:assembleAndroidTest --full-stacktrace +javadoc: + ./gradlew :unity-ads:javadoc -test-emulator: exec-tests +device-connected: + adb get-state 1>/dev/null 2>&1 && echo 'Device Attached' && exit 0 || echo 'Device NOT Attached' && exit -1 -test-hosted: push-test-server-address-hosted exec-tests +wake-up-device: + scripts/wakeUpDevice.sh -test-usb: push-test-server-address-local setup-adb-reverse exec-only-unit-tests dismantle-adb-reverse +test: device-connected wake-up-device run-all-tests -exec-tests: exec-unit-tests exec-hybrid-tests +test-local: device-connected wake-up-device push-test-server-address-ip run-all-tests -exec-unit-tests: clean - adb shell input keyevent 82 - ./gradlew :unity-ads:connectedCheck --full-stacktrace -Pandroid.testInstrumentationRunnerArguments.class=com.unity3d.ads.test.LegacyTestSuite +test-local-webview-staging: device-connected wake-up-device push-test-server-address-staging run-all-tests -exec-hybrid-tests: clean - adb shell input keyevent 82 - ./gradlew :unity-ads:connectedCheck --full-stacktrace -Pandroid.testInstrumentationRunnerArguments.class=com.unity3d.ads.test.HybridTestSuite +test-local-staging-localhost: device-connected wake-up-device push-test-server-address-localhost run-all-tests -push-test-server-address: - echo https://$(shell ifconfig |grep "inet" |grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" |grep -v -E "^0|^127" -m 1):8080 > testServerAddress.txt - adb push testServerAddress.txt /data/local/tmp +run-all-tests: test-instrumentation test-legacy test-integration -push-test-server-address-hosted: - echo "https://unity-ads-test-server.unityads.unity3d.com" > testServerAddress.txt - adb push testServerAddress.txt /data/local/tmp +test-ci: + ./gradlew connectedDebugAndroidTest -i -w --stacktrace -Pandroid.testInstrumentationRunnerArguments.class=com.unity3d.ads.test.InstrumentationTestSuite,com.unity3d.ads.test.LegacyTestSuite -push-test-server-address-local: - echo "https://localhost:8080" > testServerAddress.txt - adb push testServerAddress.txt /data/local/tmp +test-instrumentation: + ./gradlew connectedDebugAndroidTest -i -w --stacktrace -Pandroid.testInstrumentationRunnerArguments.class=com.unity3d.ads.test.InstrumentationTestSuite -setup-adb-reverse: - adb reverse tcp:8080 tcp:8080 +test-legacy: + ./gradlew connectedDebugAndroidTest -i -w --stacktrace -Pandroid.testInstrumentationRunnerArguments.class=com.unity3d.ads.test.LegacyTestSuite -dismantle-adb-reverse: - adb reverse --remove-all +test-integration: + ./gradlew connectedDebugAndroidTest -i -w --stacktrace -Pandroid.testInstrumentationRunnerArguments.class=com.unity3d.ads.test.IntegrationTestSuite -javadoc: - ./gradlew :unity-ads:javadoc +push-test-server-address-ip: + echo http://$(shell ifconfig |grep "inet" |grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" |grep -v -E "^0|^127" -m 1):8080 > testServerAddress.txt + adb push testServerAddress.txt /data/local/tmp -zip: release - cp unity-ads/build/outputs/aar/unity-ads-release.aar unity-ads.aar - zip -9r unity-ads.aar.zip unity-ads.aar - rm unity-ads.aar +push-test-server-address-staging: + echo "https://unity-ads-test-server.unityads.unity3d.com" > testServerAddress.txt + adb push testServerAddress.txt /data/local/tmp -verify-release-build: - if [[ -f "unity-ads.aar.zip" ]]; then \ - echo 'unity-ads.aar.zip exists'; \ - else \ - echo 'unity-ads.aar.zip does not exist'; \ - exit 1; \ - fi; +push-test-server-address-localhost: + echo "http://localhost:8080" > testServerAddress.txt + adb push testServerAddress.txt /data/local/tmp use-local-webview: - sed -i '' 's/return "https:\/\/config.unityads.unity3d.com\/webview\/" + getWebViewBranch() + "\/" + flavor + "\/config.json";/return "new-ip";/' "unity-ads/src/main/java/com/unity3d/services/core/properties/SdkProperties.java" - sed -i '' 's/return ".*";/return "https:\/\/$(shell ifconfig |grep "inet" |grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" |grep -v -E "^0|^127" -m 1):8000\/build\/" + flavor + "\/config.json";/' "unity-ads/src/main/java/com/unity3d/services/core/properties/SdkProperties.java" + sed -i '' 's/return baseURI + getWebViewBranch() + "\/" + flavor + "\/config.json";/return "new-ip";/' "unity-ads/src/main/java/com/unity3d/services/core/properties/SdkProperties.java" + sed -i '' 's/return ".*";/return "http:\/\/$(shell ifconfig |grep "inet" |grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" |grep -v -E "^0|^127" -m 1):8000\/build\/" + flavor + "\/config.json";/' "unity-ads/src/main/java/com/unity3d/services/core/properties/SdkProperties.java" use-public-webview: - sed -i '' 's/return ".*";/return "https:\/\/config.unityads.unity3d.com\/webview\/" + getWebViewBranch() + "\/" + flavor + "\/config.json";/' "unity-ads/src/main/java/com/unity3d/services/core/properties/SdkProperties.java" + sed -i '' 's/return ".*";/return baseURI + getWebViewBranch() + "\/" + flavor + "\/config.json";/' "unity-ads/src/main/java/com/unity3d/services/core/properties/SdkProperties.java" create-android-26-emulator: + ${ANDROID_HOME}/tools/bin/sdkmanager --install "system-images;android-26;google_apis;x86" echo "no" | ${ANDROID_HOME}/tools/bin/avdmanager create avd --name "android-26-test" --package "system-images;android-26;google_apis;x86" --device "Nexus 6P" --tag google_apis --abi google_apis/x86 --force start-android-26-emulator: ${ANDROID_HOME}/emulator/emulator -port 5556 -avd android-26-test -no-window -noaudio -no-boot-anim -memory 2048 -partition-size 1024 & + +kill-emulator: + adb emu kill \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 017e9d03..c2fa4273 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "com.unity3d.ads.example" minSdkVersion 19 targetSdkVersion 30 - versionCode = 3600 - versionName = "3.6.0" + versionCode = 3620 + versionName = "3.6.2" } flavorDimensions "arEnabled" diff --git a/build.gradle b/build.gradle index 6346dfdf..ed30e2dd 100644 --- a/build.gradle +++ b/build.gradle @@ -11,6 +11,7 @@ buildscript { // in the individual module build.gradle files classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' + classpath 'org.jacoco:org.jacoco.core:0.8.1' } } diff --git a/scripts/wakeUpDevice.sh b/scripts/wakeUpDevice.sh new file mode 100755 index 00000000..1f68efc3 --- /dev/null +++ b/scripts/wakeUpDevice.sh @@ -0,0 +1,24 @@ +#!/bin/bash -e +wakefulness=$(adb shell dumpsys power | grep 'mWakefulness=' | cut -d "=" -f2) + +if [[ "$wakefulness" == "Awake" ]] ; then + echo "Device Awake" + exit 0; +else + echo "Waking up device" + adb shell input keyevent KEYCODE_WAKEUP +fi + +adb shell input keyevent 82 + +displaySB2=$(adb shell dumpsys power | grep 'mHoldingDisplaySuspendBlocker=' | cut -d "=" -f2) +wakeLockSB2=$(adb shell dumpsys power | grep 'mHoldingWakeLockSuspendBlocker='| cut -d "=" -f2) +if [[ "$displaySB2" == "true" && "$wakeLockSB2" == "false" ]] ; then + echo "Unlocking device with passcode 5168" + adb shell input text 5168 && adb shell input keyevent 66 +fi + +if [[ "$wakefulness" == "Awake" ]] ; then + echo "Device Awake" + exit 0; +fi \ No newline at end of file diff --git a/unity-ads/build.gradle b/unity-ads/build.gradle index 1da3f912..706420bf 100644 --- a/unity-ads/build.gradle +++ b/unity-ads/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'com.jfrog.bintray' apply plugin: 'com.github.dcendents.android-maven' +apply plugin: 'jacoco' ext { bintrayRepo = "UnityAds" @@ -16,7 +17,7 @@ ext { siteUrl = 'https://github.com/Unity-Technologies/unity-ads-android' gitUrl = 'https://github.com/Unity-Technologies/unity-ads-android.git' - libraryVersion = '3.6.0' + libraryVersion = '3.6.2' developerId = 'sbankhead' developerName = 'Steven Bankhead' @@ -50,8 +51,8 @@ android { All SDK with version numbers with last two digits >= 50 will be treated as China SDK for filtering in the backend. */ - versionCode = 3600 - versionName = "3.6.0" + versionCode = 3620 + versionName = "3.6.2" setProperty("archivesBaseName", "unity-ads") @@ -76,24 +77,24 @@ android { } debug { minifyEnabled false - testCoverageEnabled false - consumerProguardFiles 'proguard-rules.pro' - } - coverage { testCoverageEnabled true consumerProguardFiles 'proguard-rules.pro' - signingConfig signingConfigs.debug - buildConfigField 'String', 'WEBVIEW_BRANCH', getPropertyStringWithDefaultValue('WEBVIEW_BRANCH', '"development"') } } libraryVariants.all { variant -> - variant.outputs.all { output -> - if (outputFile != null && outputFileName.endsWith('.aar')) { - outputFileName = "${archivesBaseName}-${variant.buildType.name}.aar" - } - } + variant.outputs.all { output -> + if (outputFile != null && outputFileName.endsWith('.aar')) { + outputFileName = "${archivesBaseName}-${variant.buildType.name}.aar" + } } + } + + testVariants.all { variant -> + variant.outputs.all { output -> + outputFileName = "../../androidTest.apk" + } + } } dependencies { @@ -105,12 +106,6 @@ dependencies { compileOnly 'com.google.ar:core:1.0.0' } -android.testVariants.all { variant -> - variant.outputs.all { output -> - outputFileName = "../../androidTest.apk" - } -} - task javadoc(type: Javadoc, overwrite: true) { description "Generates Javadoc for Release" source = android.sourceSets.main.java.srcDirs @@ -147,13 +142,38 @@ artifacts { archives androidSourcesJar } +jacoco { + toolVersion = '0.8.1' +} + +tasks.withType(Test) { + jacoco.includeNoLocationClasses = true +} + +task jacocoTestReport(type: JacocoReport) { + reports { + xml.enabled = true + html.enabled = true + } + + def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*'] + def javaClasses = fileTree(dir: "$project.buildDir/intermediates/classes/debug", excludes: fileFilter) + def javaSrc = "$project.projectDir/src/main/java" + + sourceDirectories = files([javaSrc]) + classDirectories = files([javaClasses]) + executionData = fileTree(dir: project.buildDir, includes: [ + 'outputs/code-coverage/connected/*coverage.ec' + ]) +} + +// Bintray task localProperties { if (!file("$rootDir/local.properties").exists()) { file("$rootDir/local.properties").withWriterAppend { w -> "" } } } -// Bintray bintray { Properties properties = new Properties() properties.load(project.rootProject.file('local.properties').newDataInputStream()) diff --git a/unity-ads/src/androidTest/java/com/unity3d/ads/test/legacy/ConnectivityTest.java b/unity-ads/src/androidTest/java/com/unity3d/ads/test/legacy/ConnectivityTest.java index 7abd8f73..331d3a7c 100644 --- a/unity-ads/src/androidTest/java/com/unity3d/ads/test/legacy/ConnectivityTest.java +++ b/unity-ads/src/androidTest/java/com/unity3d/ads/test/legacy/ConnectivityTest.java @@ -18,10 +18,15 @@ import com.unity3d.services.core.webview.bridge.Invocation; import com.unity3d.services.core.webview.bridge.WebViewCallback; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import java.util.ArrayList; +import java.util.List; + +import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -47,6 +52,58 @@ public void testListener() { assertEquals("ConnectivityMonitor connected callbacks not equal to one", 1, listener.getOnConnectedCalls()); } + private List createListeners(int count) { + final List listeners = new ArrayList<>(); + for (int x=0; x listeners, final int iterations, final boolean add) { + return new Thread(new Runnable() { + @Override + public void run() { + for (int x=0; x listeners = createListeners(10); + createListenerThread(listeners, 1000, true).start(); + createListenerThread(listeners, 1000, false).start(); + createConnectionThread(1000, cv).start(); + + boolean success = cv.block(10000); + Assert.assertThat(success, is(true)); + } + private class Listener implements IConnectivityListener { private int _onConnectedCalls = 0; private int _onDisconnectedCalls = 0; diff --git a/unity-ads/src/main/java/com/unity3d/ads/metadata/MetaData.java b/unity-ads/src/main/java/com/unity3d/ads/metadata/MetaData.java index 53431f9d..bb448334 100644 --- a/unity-ads/src/main/java/com/unity3d/ads/metadata/MetaData.java +++ b/unity-ads/src/main/java/com/unity3d/ads/metadata/MetaData.java @@ -29,6 +29,27 @@ public String getCategory () { return _category; } + /** + * Used by C# layer for reflective metadata set calls + */ + private synchronized boolean set (String key, boolean value) { + return set(key, (Object)value); + } + + /** + * Used by C# layer for reflective metadata set calls + */ + private synchronized boolean set (String key, int value) { + return set(key, (Object)value); + } + + /** + * Used by C# layer for reflective metadata set calls + */ + private synchronized boolean set (String key, long value) { + return set(key, (Object)value); + } + public synchronized boolean set (String key, Object value) { initData(); diff --git a/unity-ads/src/main/java/com/unity3d/services/core/connectivity/ConnectivityMonitor.java b/unity-ads/src/main/java/com/unity3d/services/core/connectivity/ConnectivityMonitor.java index 63e28546..5befcfb9 100644 --- a/unity-ads/src/main/java/com/unity3d/services/core/connectivity/ConnectivityMonitor.java +++ b/unity-ads/src/main/java/com/unity3d/services/core/connectivity/ConnectivityMonitor.java @@ -11,7 +11,9 @@ import com.unity3d.services.core.webview.WebViewApp; import com.unity3d.services.core.webview.WebViewEventCategory; -import java.util.HashSet; +import java.util.Collections; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; public class ConnectivityMonitor { private static int _connected = -1; @@ -19,7 +21,7 @@ public class ConnectivityMonitor { private static boolean _webappMonitoring = false; private static boolean _wifi = false; private static int _networkType = -1; - private static HashSet _listeners = null; + private static Set _listeners = null; public static void setConnectionMonitoring(boolean monitoring) { _webappMonitoring = monitoring; @@ -28,7 +30,7 @@ public static void setConnectionMonitoring(boolean monitoring) { public static void addListener(IConnectivityListener listener) { if(_listeners == null) { - _listeners = new HashSet<>(); + _listeners = Collections.newSetFromMap(new ConcurrentHashMap()); } _listeners.add(listener); diff --git a/unity-ads/src/main/java/com/unity3d/services/core/connectivity/ConnectivityNetworkCallback.java b/unity-ads/src/main/java/com/unity3d/services/core/connectivity/ConnectivityNetworkCallback.java index 1a820f85..573fb07c 100644 --- a/unity-ads/src/main/java/com/unity3d/services/core/connectivity/ConnectivityNetworkCallback.java +++ b/unity-ads/src/main/java/com/unity3d/services/core/connectivity/ConnectivityNetworkCallback.java @@ -15,7 +15,7 @@ public class ConnectivityNetworkCallback extends ConnectivityManager.NetworkCallback { private static ConnectivityNetworkCallback _impl = null; - public static void register() { + public static synchronized void register() { if(_impl == null) { _impl = new ConnectivityNetworkCallback(); @@ -24,7 +24,7 @@ public static void register() { } } - public static void unregister() { + public static synchronized void unregister() { if(_impl != null) { ConnectivityManager cm = (ConnectivityManager)ClientProperties.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE); cm.unregisterNetworkCallback(_impl);