This commit is contained in:
Unity Ads Travis 2019-01-30 17:46:05 +00:00
Родитель edbffc8a16
Коммит 0885aed0c5
26 изменённых файлов: 2215 добавлений и 95 удалений

14
.editorconfig Normal file
Просмотреть файл

@ -0,0 +1,14 @@
[*]
charset=utf-8
end_of_line=lf
insert_final_newline=false
indent_style=space
indent_size=4
[*.java]
indent_style=tab
tab_width=4
[{*.yml,*.yaml}]
indent_style=space
indent_size=2

6
Jenkinsfile поставляемый Normal file
Просмотреть файл

@ -0,0 +1,6 @@
@Library('applifier-shared-libs@master') _
Script {
extraSteps = ['scripts/extra.groovy']
disable_registry = true
}

Просмотреть файл

@ -56,8 +56,8 @@ zip: release
rm unity-ads.aar
use-local-webview:
sed -i '' 's/return "https:\/\/config.unityads.unity3d.com\/webview\/" + getWebViewBranch() + "\/" + flavor + "\/config.json";/return "new-ip";/' "lib/src/main/java/com/unity3d/ads/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\/dev\/config.json";/' "lib/src/main/java/com/unity3d/ads/properties/SdkProperties.java"
sed -i '' 's/return "https:\/\/config.unityads.unity3d.com\/webview\/" + getWebViewBranch() + "\/" + flavor + "\/config.json";/return "new-ip";/' "lib/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";/' "lib/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";/' "lib/src/main/java/com/unity3d/ads/properties/SdkProperties.java"
sed -i '' 's/return ".*";/return "https:\/\/config.unityads.unity3d.com\/webview\/" + getWebViewBranch() + "\/" + flavor + "\/config.json";/' "lib/src/main/java/com/unity3d/services/core/properties/SdkProperties.java"

Просмотреть файл

@ -29,6 +29,7 @@ public class UnityAdsExample extends Activity {
private String interstitialPlacementId;
private String incentivizedPlacementId;
private Button bannerButton;
private static int ordinal = 1;
@ -93,6 +94,9 @@ public class UnityAdsExample extends Activity {
}
});
bannerButton = (Button) findViewById(R.id.unityads_example_banner_button);
disableButton(bannerButton);
final Button initializeButton = (Button) findViewById(R.id.unityads_example_initialize_button);
final EditText gameIdEdit = (EditText) findViewById(R.id.unityads_example_gameid_edit);
final CheckBox testModeCheckbox = (CheckBox) findViewById(R.id.unityads_example_testmode_checkbox);

Просмотреть файл

@ -24,6 +24,7 @@ import com.unity3d.ads.metadata.PlayerMetaData;
import com.unity3d.services.UnityServices;
import com.unity3d.services.banners.IUnityBannerListener;
import com.unity3d.services.banners.UnityBanners;
import com.unity3d.services.banners.view.BannerPosition;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.properties.SdkProperties;
import com.unity3d.services.core.webview.WebView;
@ -155,11 +156,12 @@ public class UnityMonetizationExample extends Activity {
});
bannerButton = (Button) findViewById(R.id.unityads_example_banner_button);
enableButton(bannerButton);
disableButton(bannerButton);
bannerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (bannerView == null) {
UnityBanners.setBannerPosition(BannerPosition.BOTTOM_CENTER);
UnityBanners.loadBanner(thisActivity, bannerPlacementId);
} else {
UnityBanners.destroy();
@ -196,6 +198,8 @@ public class UnityMonetizationExample extends Activity {
SharedPreferences.Editor preferencesEdit = preferences.edit();
preferencesEdit.putString("gameId", gameId);
preferencesEdit.commit();
enableButton(bannerButton);
}
});
@ -230,6 +234,8 @@ public class UnityMonetizationExample extends Activity {
else {
disableButton((Button) findViewById(R.id.unityads_example_incentivized_button));
}
enableButton(bannerButton);
}
}

Просмотреть файл

@ -11,8 +11,18 @@ android {
defaultConfig {
minSdkVersion 9
targetSdkVersion 26
versionCode = 3000
versionName = "3.0.0"
/*
Please ensure that the last two digits of version number does not exceed 50 unless
it is a China SDK. This is because adding 50 to the version number is a one-to-one
mapping between normal SDK and China SDK.
Example : version number 2350 corresponds to China version of 2300.
All SDK with version numbers with last two digits >= 50 will be treated
as China SDK for filtering in the backend.
*/
versionCode = 3001
versionName = "3.0.1"
setProperty("archivesBaseName", "unity-ads")
@ -77,6 +87,7 @@ android.libraryVariants.all { variant ->
linksOffline "http://developer.android.com/reference","${android.sdkDirectory}/docs/reference"
}
exclude '**/R.java'
exclude 'com/unity3d/services/ar/view/GLSurfaceView.java'
destinationDir = file("../javadoc/")
}
}

Просмотреть файл

@ -18,4 +18,10 @@ public class Placement {
callback.invoke();
}
@WebViewExposed
public static void setDefaultBannerPlacement(String placement, WebViewCallback callback) {
com.unity3d.services.ads.placement.Placement.setDefaultBannerPlacement(placement);
callback.invoke();
}
}

Просмотреть файл

@ -135,6 +135,33 @@ public class AR {
}
}
@WebViewExposed
public static void swapBuffers(WebViewCallback callback) {
AdUnitActivity activity = AdUnit.getAdUnitActivity();
if (activity != null && AR.getARView() != null) {
AR.getARView().swapBuffers();
callback.invoke();
} else {
callback.error(ARError.ARVIEW_NULL);
}
}
@WebViewExposed
public static void setViewRenderMode(Integer mode, WebViewCallback callback) {
final AdUnitActivity activity = AdUnit.getAdUnitActivity();
if (activity != null && AR.getARView() != null) {
try {
AR.getARView().setRenderMode(mode);
} catch (IllegalArgumentException e) {
callback.error(ARError.INVALID_VALUE);
return;
}
callback.invoke();
} else {
callback.error(ARError.ARVIEW_NULL);
}
}
// Android doesn't support video format selection at the moment and it's not possible to get the
// image size before session starts. This is here for API compatibility with iOS.
@WebViewExposed

Просмотреть файл

@ -3,7 +3,6 @@ package com.unity3d.services.ar.view;
import android.annotation.TargetApi;
import android.content.Context;
import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import android.os.Build;
import android.util.SparseArray;
@ -79,7 +78,8 @@ public class ARView extends GLSurfaceView implements GLSurfaceView.Renderer {
setEGLContextClientVersion(2);
setEGLConfigChooser(8, 8, 8, 8, 16, 0); // Alpha used for plane blending.
setRenderer(this);
setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
setPreserveEGLContextOnPause(true);
_displayRotationHelper = new DisplayRotationHelper(context);
}
@ -144,8 +144,6 @@ public class ARView extends GLSurfaceView implements GLSurfaceView.Renderer {
@Override
public void onDrawFrame(GL10 gl) {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
if (_shouldSendResize) {
// Fix for Samsung devices (S7-S9, manually send AR_WINDOW_RESIZED)
WebViewApp webViewApp = WebViewApp.getCurrentApp();
@ -176,22 +174,12 @@ public class ARView extends GLSurfaceView implements GLSurfaceView.Renderer {
return;
}
if (!_showCameraFrame) {
return;
}
_backgroundRenderer.draw(frame);
long currentTime = System.currentTimeMillis();
if (_timeOfLastDrawnCameraFrame == 0) {
_timeOfLastDrawnCameraFrame = currentTime;
}
long timeSinceLastDrawnCameraFrame = currentTime - _timeOfLastDrawnCameraFrame;
if (timeSinceLastDrawnCameraFrame < FRAME_UPDATE_TIMEOUT && !_drawNextCameraFrame) {
return;
}
_timeOfLastDrawnCameraFrame = currentTime;
_drawNextCameraFrame = false;
camera.getProjectionMatrix(_projectionMatrixArray, 0, _arNear, _arFar);
camera.getViewMatrix(_viewMatrixArray, 0);
@ -234,6 +222,13 @@ public class ARView extends GLSurfaceView implements GLSurfaceView.Renderer {
updatePlanes(updatedTrackables);
DeviceLog.debug(frame.toString());
if (!_showCameraFrame) {
return;
}
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
_backgroundRenderer.draw(frame);
}
}
@ -325,6 +320,13 @@ public class ARView extends GLSurfaceView implements GLSurfaceView.Renderer {
_sessionRunning = true;
_displayRotationHelper.onResume();
postDelayed(new Runnable() {
@Override
public void run() {
requestRender();
}
}, 200);
}
public void pauseSession() {
@ -334,7 +336,7 @@ public class ARView extends GLSurfaceView implements GLSurfaceView.Renderer {
}
public void setDrawNextCameraFrame() {
_drawNextCameraFrame = true;
requestRender();
}
public boolean getShowCameraFrame() {

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -4,6 +4,7 @@ import android.app.Activity;
import com.unity3d.ads.UnityAds;
import com.unity3d.services.ads.placement.Placement;
import com.unity3d.services.banners.view.BannerPosition;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.misc.Utilities;
import com.unity3d.services.core.properties.ClientProperties;
@ -64,6 +65,10 @@ public final class UnityBanners {
}).start();
}
public static void setBannerPosition(BannerPosition position) {
ClientProperties.setBannerDefaultPosition(position);
}
/**
* Change listener for IUnityAdsListener callbacks
*

Просмотреть файл

@ -30,9 +30,14 @@ public class Banner {
@Override
public synchronized void run() {
BannerView view = BannerView.getOrCreateInstance();
view.setBannerDimensions(width, height, BannerPosition.fromString(style));
view.setViews(getArrayFromJSONArray(viewsArray));
BannerPosition position = ClientProperties.getbannerDefaultPosition();
if (position == null) {
position = BannerPosition.fromString(style);
}
view.setBannerDimensions(width, height, position);
view.setViews(getArrayFromJSONArray(viewsArray));
WebViewApp app = WebViewApp.getCurrentApp();
if (app != null) {
app.sendEvent(WebViewEventCategory.BANNER, BannerEvent.BANNER_LOADED);
@ -104,7 +109,12 @@ public class Banner {
public void run() {
BannerView view = BannerView.getInstance();
if (view != null) {
view.setBannerDimensions(width, height, BannerPosition.fromString(style));
BannerPosition position = ClientProperties.getbannerDefaultPosition();
if ( position == null) {
position = BannerPosition.fromString(style);
}
view.setBannerDimensions(width, height, position);
view.setLayoutParams(view.getLayoutParams());
}
}

Просмотреть файл

@ -4,6 +4,8 @@ import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import com.unity3d.services.banners.UnityBanners;
public enum BannerPosition {
TOP_LEFT(new int[] {RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.ALIGN_PARENT_LEFT}, Gravity.TOP | Gravity.LEFT),
TOP_CENTER(new int[] {RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.CENTER_HORIZONTAL}, Gravity.TOP | Gravity.CENTER_HORIZONTAL),

Просмотреть файл

@ -56,11 +56,13 @@ public class Intent {
if (action != null)
intent.setAction(action);
if (uri != null)
if (uri != null && mimeType != null) {
intent.setDataAndType(Uri.parse(uri), mimeType);
} else if (uri != null) {
intent.setData(Uri.parse(uri));
if (mimeType != null)
} else if (mimeType != null) {
intent.setType(mimeType);
}
if (flags != null && flags > -1)
intent.setFlags(flags);

Просмотреть файл

@ -52,13 +52,13 @@ public class Storage {
if (s != null) {
boolean success = s.set(key, value);
if (success) {
callback.invoke(key, value);
callback.invoke(key);
} else {
callback.error(StorageError.COULDNT_SET_VALUE, key, value);
callback.error(StorageError.COULDNT_SET_VALUE, key);
}
}
else {
callback.error(StorageError.COULDNT_GET_STORAGE, type, key, value);
callback.error(StorageError.COULDNT_GET_STORAGE, type, key);
}
}

Просмотреть файл

@ -39,6 +39,8 @@ public class CacheDirectory {
}
if(testCacheDirectory(externalCache)) {
createNoMediaFile(externalCache);
_cacheDirectory = externalCache;
_type = CacheDirectoryType.EXTERNAL;
DeviceLog.debug("Unity Ads is using external cache directory: " + externalCache.getAbsolutePath());
@ -124,4 +126,20 @@ public class CacheDirectory {
return false;
}
}
private void createNoMediaFile(File path) {
File noMediaFile = new File(path, ".nomedia");
try {
boolean created = noMediaFile.createNewFile();
if(created) {
DeviceLog.debug("Successfully created .nomedia file");
} else {
DeviceLog.debug("Using existing .nomedia file");
}
} catch(Exception e) {
DeviceLog.exception("Failed to create .nomedia file", e);
}
}
}

Просмотреть файл

@ -121,7 +121,7 @@ public class Configuration {
return queryString;
}
protected void makeRequest () throws IOException, JSONException, IllegalStateException, NetworkIOException {
protected void makeRequest () throws IOException, JSONException, IllegalStateException, NetworkIOException, IllegalArgumentException {
if (_url == null) {
throw new MalformedURLException("Base URL is null");
}

Просмотреть файл

@ -25,21 +25,20 @@ public class Storage extends JsonStorage {
public synchronized boolean readStorage () {
File f = new File(_targetFileName);
String fileData = Utilities.readFile(f);
if (fileData != null) {
try {
setData(new JSONObject(Utilities.readFile(f)));
}
catch (Exception e) {
DeviceLog.exception("Error creating storage JSON", e);
try {
byte[] bytes = Utilities.readFileBytes(f);
if (bytes == null) {
return false;
}
String fileData = new String(bytes);
setData(new JSONObject(fileData));
return true;
}
return false;
catch (Exception e) {
DeviceLog.exception("Error creating storage JSON", e);
return false;
}
}
public synchronized boolean initStorage () {

Просмотреть файл

@ -130,55 +130,6 @@ public class Utilities {
return success;
}
public static String readFile (File fileToRead) {
if (fileToRead == null) {
return null;
}
String fileContent = "";
BufferedReader br = null;
FileReader fr = null;
if (fileToRead.exists() && fileToRead.canRead()) {
try {
fr = new FileReader(fileToRead);
br = new BufferedReader(fr);
String line;
while ((line = br.readLine()) != null) {
fileContent = fileContent.concat(line);
}
}
catch (Exception e) {
DeviceLog.exception("Problem reading file", e);
fileContent = null;
}
try {
if (br != null) {
br.close();
}
}
catch (Exception e) {
DeviceLog.exception("Couldn't close BufferedReader", e);
}
try {
if (fr != null) {
fr.close();
}
}
catch (Exception e) {
DeviceLog.exception("Couldn't close FileReader", e);
}
return fileContent;
}
else {
DeviceLog.error("File did not exist or couldn't be read");
}
return null;
}
public static byte[] readFileBytes(File file) throws IOException {
if (file == null) {
return null;

Просмотреть файл

@ -8,6 +8,7 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import com.unity3d.services.banners.view.BannerPosition;
import com.unity3d.services.core.log.DeviceLog;
import java.io.ByteArrayInputStream;
@ -25,6 +26,7 @@ public class ClientProperties {
private static Application _application;
private static String _gameId;
private static BannerPosition _bannerDefaultPosition;
public static Activity getActivity () {
return _activity.get();
@ -74,6 +76,14 @@ public class ClientProperties {
}
}
public static BannerPosition getbannerDefaultPosition () {
return _bannerDefaultPosition;
}
public static void setBannerDefaultPosition(BannerPosition position) {
_bannerDefaultPosition = position;
}
public static boolean isAppDebuggable() {
boolean debuggable = false;
boolean couldNotGetApplicationInfo = false;

Просмотреть файл

@ -209,13 +209,13 @@ public class WebRequest {
return total;
}
public String makeRequest () throws NetworkIOException, IOException, IllegalStateException {
public String makeRequest () throws NetworkIOException, IOException, IllegalStateException, IllegalArgumentException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
makeStreamRequest(baos);
return baos.toString("UTF-8");
}
private HttpURLConnection getHttpUrlConnectionWithHeaders() throws NetworkIOException {
private HttpURLConnection getHttpUrlConnectionWithHeaders() throws NetworkIOException, IllegalArgumentException {
HttpURLConnection connection;
if (getUrl().toString().startsWith("https://")) {
@ -226,7 +226,7 @@ public class WebRequest {
throw new NetworkIOException("Open HTTPS connection: " + e.getMessage());
}
}
else {
else if (getUrl().toString().startsWith("http://")) {
try {
connection = (HttpURLConnection)getUrl().openConnection();
}
@ -234,6 +234,9 @@ public class WebRequest {
throw new NetworkIOException("Open HTTP connection: " + e.getMessage());
}
}
else {
throw new IllegalArgumentException("Invalid url-protocol in url: " + getUrl().toString());
}
connection.setInstanceFollowRedirects(false);
connection.setConnectTimeout(getConnectTimeout());

Просмотреть файл

@ -66,7 +66,7 @@ public class WebRequestRunnable implements Runnable {
String response;
try {
response = _currentRequest.makeRequest();
} catch (IOException | NetworkIOException | IllegalStateException e) {
} catch (IOException | NetworkIOException | IllegalStateException | IllegalArgumentException e) {
DeviceLog.exception("Error completing request", e);
onFailed(e.getClass().getName() + ": " + e.getMessage());
return;

Просмотреть файл

@ -78,7 +78,7 @@ public class PromoMetadataUtilities {
productBuilder.withLocalizedTitle((String) productParams.get("localizedTitle"));
}
if (productParams.containsKey("localizedPrice")) {
productBuilder.withLocalizedPrice((double) productParams.get("localizedPrice"));
productBuilder.withLocalizedPrice(new Double(productParams.get("localizedPrice").toString()));
}
if (productParams.containsKey("productType")) {
productBuilder.withProductType((String) productParams.get("productType"));

4
scripts/build.sh Executable file
Просмотреть файл

@ -0,0 +1,4 @@
#!/bin/bash
set -x
echo "Building is done in downstream jobs!"

63
scripts/extra.groovy Normal file
Просмотреть файл

@ -0,0 +1,63 @@
def main() {
// commitId value is not used, but is here for learning purposes
commitId = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
echo "#### Commit $commitId ####"
if (env.BRANCH_NAME =~ /^PR-/) {
stage('checkout') {
dir('sharedLibs') {
checkout(
[$class: 'GitSCM', branches: [[name: 'master']],
userRemoteConfigs: [[credentialsId: 'applifier-readonly-jenkins-bot',
url: 'https://github.com/Applifier/unity-ads-sdk-tests.git']]]
)
script {
sharedLibs = load 'sharedLibs.groovy'
}
}
}
stage('Run tests') {
dir('results') {
parallel (
'hybrid_test': {
def jobName = "ads-sdk-hybrid-test-android"
def build_ = build(
job: "Applifier/unity-ads-sdk-tests/$jobName",
propagate: false,
wait: true,
parameters: [
string(name: 'UNITY_ADS_ANDROID_BRANCH', value: env.CHANGE_BRANCH),
]
)
def artifactFolder = "$jobName/$build_.number"
dir(jobName) {
sharedLibs.downloadFromGcp("$artifactFolder/*")
}
sharedLibs.removeFromGcp(artifactFolder)
},
'system_test': {
def jobName = "ads-sdk-systest-android"
build(
job: "Applifier/unity-ads-sdk-tests/$jobName",
propagate: false,
wait: false,
parameters: [
string(name: 'UNITY_ADS_ANDROID_BRANCH', value: env.CHANGE_BRANCH)
],
)
}
)
}
archiveArtifacts artifacts: "results/**", fingerprint: true
step ([$class: "JUnitResultArchiver", testResults: "results/**/*.xml"])
slackChannel = "ads-sdk-notify"
sharedLibs.sendTestSummary(slackChannel)
}
}
}
return this;

4
scripts/test.sh Executable file
Просмотреть файл

@ -0,0 +1,4 @@
#!/bin/bash
set -x
echo "Testing is done in downstream jobs!"