This commit is contained in:
runner 2021-11-30 18:04:21 +00:00
Родитель 524eeba938
Коммит 7ec146f6c8
158 изменённых файлов: 1832 добавлений и 4912 удалений

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

@ -1,3 +0,0 @@
source "https://rubygems.org"
gem "fastlane"

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

@ -1,159 +0,0 @@
GEM
remote: https://rubygems.org/
specs:
CFPropertyList (3.0.1)
addressable (2.6.0)
public_suffix (>= 2.0.2, < 4.0)
atomos (0.1.3)
babosa (1.0.2)
claide (1.0.3)
colored (1.2)
colored2 (3.1.2)
commander-fastlane (4.4.6)
highline (~> 1.7.2)
declarative (0.0.10)
declarative-option (0.1.0)
digest-crc (0.4.1)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.7.5)
emoji_regex (1.0.1)
excon (0.66.0)
faraday (0.15.4)
multipart-post (>= 1.2, < 3)
faraday-cookie_jar (0.0.6)
faraday (>= 0.7.4)
http-cookie (~> 1.0.0)
faraday_middleware (0.13.1)
faraday (>= 0.7.4, < 1.0)
fastimage (2.1.5)
fastlane (2.130.0)
CFPropertyList (>= 2.3, < 4.0.0)
addressable (>= 2.3, < 3.0.0)
babosa (>= 1.0.2, < 2.0.0)
bundler (>= 1.12.0, < 3.0.0)
colored
commander-fastlane (>= 4.4.6, < 5.0.0)
dotenv (>= 2.1.1, < 3.0.0)
emoji_regex (>= 0.1, < 2.0)
excon (>= 0.45.0, < 1.0.0)
faraday (~> 0.9)
faraday-cookie_jar (~> 0.0.6)
faraday_middleware (~> 0.9)
fastimage (>= 2.1.0, < 3.0.0)
gh_inspector (>= 1.1.2, < 2.0.0)
google-api-client (>= 0.21.2, < 0.24.0)
google-cloud-storage (>= 1.15.0, < 2.0.0)
highline (>= 1.7.2, < 2.0.0)
json (< 3.0.0)
jwt (~> 2.1.0)
mini_magick (>= 4.9.4, < 5.0.0)
multi_xml (~> 0.5)
multipart-post (~> 2.0.0)
plist (>= 3.1.0, < 4.0.0)
public_suffix (~> 2.0.0)
rubyzip (>= 1.2.2, < 2.0.0)
security (= 0.1.3)
simctl (~> 1.6.3)
slack-notifier (>= 2.0.0, < 3.0.0)
terminal-notifier (>= 2.0.0, < 3.0.0)
terminal-table (>= 1.4.5, < 2.0.0)
tty-screen (>= 0.6.3, < 1.0.0)
tty-spinner (>= 0.8.0, < 1.0.0)
word_wrap (~> 1.0.0)
xcodeproj (>= 1.8.1, < 2.0.0)
xcpretty (~> 0.3.0)
xcpretty-travis-formatter (>= 0.0.3)
gh_inspector (1.1.3)
google-api-client (0.23.9)
addressable (~> 2.5, >= 2.5.1)
googleauth (>= 0.5, < 0.7.0)
httpclient (>= 2.8.1, < 3.0)
mime-types (~> 3.0)
representable (~> 3.0)
retriable (>= 2.0, < 4.0)
signet (~> 0.9)
google-cloud-core (1.3.1)
google-cloud-env (~> 1.0)
google-cloud-env (1.2.1)
faraday (~> 0.11)
google-cloud-storage (1.16.0)
digest-crc (~> 0.4)
google-api-client (~> 0.23)
google-cloud-core (~> 1.2)
googleauth (>= 0.6.2, < 0.10.0)
googleauth (0.6.7)
faraday (~> 0.12)
jwt (>= 1.4, < 3.0)
memoist (~> 0.16)
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (~> 0.7)
highline (1.7.10)
http-cookie (1.0.3)
domain_name (~> 0.5)
httpclient (2.8.3)
json (2.2.0)
jwt (2.1.0)
memoist (0.16.0)
mime-types (3.2.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2019.0331)
mini_magick (4.9.5)
multi_json (1.13.1)
multi_xml (0.6.0)
multipart-post (2.0.0)
nanaimo (0.2.6)
naturally (2.2.0)
os (1.0.1)
plist (3.5.0)
public_suffix (2.0.5)
representable (3.0.4)
declarative (< 0.1.0)
declarative-option (< 0.2.0)
uber (< 0.2.0)
retriable (3.1.2)
rouge (2.0.7)
rubyzip (1.2.3)
security (0.1.3)
signet (0.11.0)
addressable (~> 2.3)
faraday (~> 0.9)
jwt (>= 1.5, < 3.0)
multi_json (~> 1.10)
simctl (1.6.5)
CFPropertyList
naturally
slack-notifier (2.3.2)
terminal-notifier (2.0.0)
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
tty-cursor (0.7.0)
tty-screen (0.7.0)
tty-spinner (0.9.1)
tty-cursor (~> 0.7)
uber (0.1.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.6)
unicode-display_width (1.6.0)
word_wrap (1.0.0)
xcodeproj (1.12.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.2.6)
xcpretty (0.3.0)
rouge (~> 2.0.7)
xcpretty-travis-formatter (1.0.0)
xcpretty (~> 0.2, >= 0.0.7)
PLATFORMS
ruby
DEPENDENCIES
fastlane
BUNDLED WITH
2.0.2

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

@ -1,4 +1,4 @@
Unity Advertisements © 2020 Unity Technologies SF
Your use of the Unity Technologies SF ("Unity') software known as "Unity Advertisements" is subject to the Unity Monetization Services Terms of Service linked to and copied immediately below.
[Unity Monetization Services TOS](https://unity3d.com/legal/monetization-services-terms-of-service)
Your use of the Unity Advertisements software constitutes your acceptance of such terms. Unless expressly provided otherwise, the software under this license is made available strictly on an "AS IS" BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Please review the license for details on these and other terms and conditions.
Unity Advertisements copyright © 2021 Unity Technologies.
This software is subject to, and made available under, the terms of service for Operate Solutions (see https://unity3d.com/legal/one-operate-services-terms-of-service), and is an "Operate Service" as defined therein.
Your use of the Services constitutes your acceptance of such terms. Unless expressly provided otherwise, the software under this license is made available strictly on an "AS IS" BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Please review the terms of service for details on these and other terms and conditions.

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

@ -1,78 +0,0 @@
debug:
./gradlew :unity-ads:assembleDebug
release:
./gradlew :unity-ads:assembleRelease
clean:
./gradlew :unity-ads:clean
coverage:
./gradlew -i jacocoTestReport --debug
coverage-ci: debug test-ci coverage
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
javadoc:
./gradlew :unity-ads:javadoc
device-connected:
adb get-state 1>/dev/null 2>&1 && echo 'Device Attached' && exit 0 || echo 'Device NOT Attached' && exit -1
wake-up-device:
scripts/wakeUpDevice.sh
test: device-connected wake-up-device run-all-tests
test-local: device-connected wake-up-device push-test-server-address-ip run-all-tests
test-local-webview-staging: device-connected wake-up-device push-test-server-address-staging run-all-tests
test-local-staging-localhost: device-connected wake-up-device push-test-server-address-localhost run-all-tests
run-all-tests: test-instrumentation test-legacy test-integration
test-ci:
./gradlew unity-ads:connectedDebugAndroidTest -i -w --stacktrace -Pandroid.testInstrumentationRunnerArguments.class=com.unity3d.ads.test.InstrumentationTestSuite,com.unity3d.ads.test.LegacyTestSuite
test-instrumentation:
./gradlew unity-ads:connectedDebugAndroidTest -i -w --stacktrace -Pandroid.testInstrumentationRunnerArguments.class=com.unity3d.ads.test.InstrumentationTestSuite
test-legacy:
./gradlew unity-ads:connectedDebugAndroidTest -i -w --stacktrace -Pandroid.testInstrumentationRunnerArguments.class=com.unity3d.ads.test.LegacyTestSuite
test-integration:
./gradlew unity-ads:connectedDebugAndroidTest -i -w --stacktrace -Pandroid.testInstrumentationRunnerArguments.class=com.unity3d.ads.test.IntegrationTestSuite
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
push-test-server-address-staging:
echo "https://unity-ads-test-server.unityads.unity3d.com" > testServerAddress.txt
adb push testServerAddress.txt /data/local/tmp
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 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 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

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

@ -1,19 +1,18 @@
# Unity Ads 3 Android Release Repository
# Unity Ads Android Release Repository
Welcome to the Unity Ads 3 Android release repository.
Welcome to the Unity Ads Android SDK Repository.
## Binaries
Binaries can be found from the [releases tab](https://github.com/Unity-Technologies/unity-ads-android/releases).
Binaries can be found in the [releases tab](https://github.com/Unity-Technologies/unity-ads-android/releases).
## Integration Guide
Integration guide can be found [here](https://github.com/Unity-Technologies/unity-ads-android/wiki/sdk_android_integration_guide). There is [integration tutorial video](https://www.youtube.com/watch?v=MNdJ0KWlYPw) on YouTube.
Integration guide can be found [here](https://unityads.unity3d.com/help/android/integration-guide-android).
## API Reference
API Reference can be found [here](https://github.com/Unity-Technologies/unity-ads-android/wiki/sdk_android_api_reference)
API Reference can be found [here](https://unityads.unity3d.com/help/android/api-android)
## Transition guide from Unity Ads 1.5
Transition guide from Unity Ads 1.5 can be found [here](https://github.com/Unity-Technologies/unity-ads-android/wiki/sdk_android_transition_guide)
## License
The license can be viewed [here](LICENSE)

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

@ -7,8 +7,8 @@ android {
applicationId "com.unity3d.ads.example"
minSdkVersion 19
targetSdkVersion 30
versionCode = 3750
versionName = "3.7.5"
versionCode = 4000
versionName = "4.0.0"
}
flavorDimensions "arEnabled"
@ -36,4 +36,4 @@ dependencies {
arImplementation 'com.google.ar:core:1.4.0'
implementation 'androidx.transition:transition:1.4.1'
implementation project(':unity-ads')
}
}

Двоичные данные
app/src/main/ic_launcher-playstore.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 23 KiB

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

@ -23,12 +23,7 @@ public class SectionsPagerAdapter extends FragmentPagerAdapter {
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a UnityAdsFragment (defined as a static inner class below).
switch (position) {
case 0:
return UnityAdsFragment.newInstance(position);
default:
return UnityAdsFragment.newInstance(position);
}
return UnityAdsFragment.newInstance(position);
}
@Nullable

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

@ -1,5 +1,6 @@
package com.unity3d.ads.example.ui.main;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
@ -14,40 +15,70 @@ import android.view.animation.AlphaAnimation;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.unity3d.ads.IUnityAdsInitializationListener;
import com.unity3d.ads.IUnityAdsListener;
import com.unity3d.ads.IUnityAdsLoadListener;
import com.unity3d.ads.IUnityAdsShowListener;
import com.unity3d.ads.UnityAds;
import com.unity3d.ads.UnityAdsShowOptions;
import com.unity3d.ads.example.R;
import com.unity3d.ads.metadata.MediationMetaData;
import com.unity3d.ads.metadata.MetaData;
import com.unity3d.ads.metadata.PlayerMetaData;
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.misc.Utilities;
import com.unity3d.services.banners.BannerErrorInfo;
import com.unity3d.services.banners.BannerView;
import com.unity3d.services.banners.UnityBannerSize;
import com.unity3d.services.core.webview.WebView;
/**
* A placeholder fragment containing a simple view.
*/
public class UnityAdsFragment extends Fragment implements IUnityAdsListener, IUnityBannerListener {
public class UnityAdsFragment extends Fragment {
private final String LOGTAG = "UnityAdsExample";
private View root;
private EditText gameIdEdit;
private CheckBox testModeCheckBox;
private Button initializeButton;
private Button interstitialButton;
private Button incentivizedButton;
private Button bannerButton;
private TextView statusText;
private boolean bannerShowing = false;
private Button loadInterstitialButton;
private Button showInterstitialButton;
private Button loadRewardedButton;
private Button showRewardedButton;
private Button showBannerButton;
private Button hideBannerButton;
private BannerView bottomBanner;
private RelativeLayout bannerLayout;
private String interstitialPlacementId;
private String incentivizedPlacementId;
// Listener for banner events
private BannerView.IListener bannerListener = new BannerView.IListener() {
@Override
public void onBannerLoaded(BannerView bannerAdView) {
Log.v(LOGTAG, "onBannerLoaded: " + bannerAdView.getPlacementId());
enableButton(hideBannerButton);
}
@Override
public void onBannerFailedToLoad(BannerView bannerAdView, BannerErrorInfo errorInfo) {
Log.e(LOGTAG, "Unity Ads failed to load banner for " + bannerAdView.getPlacementId() + " with error: [" + errorInfo.errorCode + "] " + errorInfo.errorMessage);
}
@Override
public void onBannerClick(BannerView bannerAdView) {
Log.v(LOGTAG, "onBannerClick: " + bannerAdView.getPlacementId());
}
@Override
public void onBannerLeftApplication(BannerView bannerAdView) {
Log.v(LOGTAG, "onBannerLeftApplication: " + bannerAdView.getPlacementId());
}
};
private final String interstitialPlacementId = "video";
private final String rewardedPlacementId = "rewardedVideo";
private int ordinal = 1;
final private String defaultGameId = "14851";
@ -70,15 +101,21 @@ public class UnityAdsFragment extends Fragment implements IUnityAdsListener, IUn
this.gameIdEdit = root.findViewById(R.id.unityads_example_gameid_edit);
this.testModeCheckBox = root.findViewById(R.id.unityads_example_testmode_checkbox);
this.initializeButton = root.findViewById(R.id.unityads_example_initialize_button);
this.interstitialButton = root.findViewById(R.id.unityads_example_interstitial_button);
this.incentivizedButton = root.findViewById(R.id.unityads_example_incentivized_button);
this.bannerButton = root.findViewById(R.id.unityads_example_banner_button);
this.statusText = root.findViewById(R.id.unityads_example_statustext);
this.loadInterstitialButton = root.findViewById(R.id.unityads_example_load_interstitial_button);
this.showInterstitialButton = root.findViewById(R.id.unityads_example_show_interstitial_button);
this.loadRewardedButton = root.findViewById(R.id.unityads_example_load_rewarded_button);
this.showRewardedButton = root.findViewById(R.id.unityads_example_show_rewarded_button);
this.showBannerButton = root.findViewById(R.id.unityads_example_show_banner_button);
this.hideBannerButton = root.findViewById(R.id.unityads_example_hide_banner_button);
this.bannerLayout = root.findViewById(R.id.unityads_example_banner_layout);
enableButton(initializeButton);
disableButton(interstitialButton);
disableButton(incentivizedButton);
enableButton(bannerButton);
disableButton(loadInterstitialButton);
disableButton(showInterstitialButton);
disableButton(loadRewardedButton);
disableButton(showRewardedButton);
disableButton(showBannerButton);
disableButton(hideBannerButton);
SharedPreferences preferences = getActivity().getSharedPreferences("Settings", Context.MODE_PRIVATE);
gameIdEdit.setText(preferences.getString("gameId", defaultGameId));
@ -88,24 +125,14 @@ public class UnityAdsFragment extends Fragment implements IUnityAdsListener, IUn
WebView.setWebContentsDebuggingEnabled(true);
}
UnityAds.addListener(this);
UnityAds.setDebugMode(true);
MediationMetaData mediationMetaData = new MediationMetaData(getActivity());
mediationMetaData.setName("mediationPartner");
mediationMetaData.setVersion("v12345");
mediationMetaData.commit();
MetaData debugMetaData = new MetaData(getActivity());
debugMetaData.set("test.debugOverlayEnabled", true);
debugMetaData.commit();
this.initializeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String gameId = gameIdEdit.getText().toString();
if (gameId.isEmpty()) {
Toast.makeText(getActivity().getApplicationContext(), "Missing game id", Toast.LENGTH_SHORT).show();
Toast.makeText(getActivity().getApplicationContext(), "Missing Game ID", Toast.LENGTH_SHORT).show();
return;
}
@ -113,21 +140,22 @@ public class UnityAdsFragment extends Fragment implements IUnityAdsListener, IUn
gameIdEdit.setEnabled(false);
testModeCheckBox.setEnabled(false);
statusText.setText("Initializing...");
UnityAds.addListener(UnityAdsFragment.this);
UnityAds.initialize(getContext(), gameId, testModeCheckBox.isChecked(), new IUnityAdsInitializationListener() {
@Override
public void onInitializationComplete() {
statusText.setText("Initialization Complete");
Log.v(LOGTAG, "Unity Ads initialization complete");
enableButton(loadInterstitialButton);
enableButton(loadRewardedButton);
enableButton(showBannerButton);
}
@Override
public void onInitializationFailed(UnityAds.UnityAdsInitializationError error, String message) {
statusText.setText("Initialization Failed: [" + error + "] " + message);
Log.e(LOGTAG, "Unity Ads initialization failed: [" + error + "] " + message);
}
});
// store entered gameid in app settings
// Store entered Game ID in App Settings
SharedPreferences preferences = getActivity().getSharedPreferences("Settings", Context.MODE_PRIVATE);
SharedPreferences.Editor preferencesEdit = preferences.edit();
preferencesEdit.putString("gameId", gameId);
@ -135,61 +163,114 @@ public class UnityAdsFragment extends Fragment implements IUnityAdsListener, IUn
}
});
this.interstitialButton.setOnClickListener(new View.OnClickListener() {
this.loadInterstitialButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
disableButton(interstitialButton);
PlayerMetaData playerMetaData = new PlayerMetaData(getActivity());
playerMetaData.setServerId("rikshot");
playerMetaData.commit();
MediationMetaData ordinalMetaData = new MediationMetaData(getActivity());
ordinalMetaData.setOrdinal(ordinal++);
ordinalMetaData.commit();
UnityAds.show(getActivity(), interstitialPlacementId);
disableButton(loadInterstitialButton);
loadAd(true);
}
});
this.incentivizedButton.setOnClickListener(new View.OnClickListener() {
this.loadRewardedButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
disableButton(incentivizedButton);
PlayerMetaData playerMetaData = new PlayerMetaData(getActivity());
playerMetaData.setServerId("rikshot");
playerMetaData.commit();
MediationMetaData ordinalMetaData = new MediationMetaData(getActivity());
ordinalMetaData.setOrdinal(ordinal++);
ordinalMetaData.commit();
UnityAds.show(getActivity(), incentivizedPlacementId);
disableButton(loadRewardedButton);
loadAd(false);
}
});
this.bannerButton.setOnClickListener(new View.OnClickListener() {
this.showInterstitialButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (UnityAdsFragment.this.bannerShowing) {
UnityBanners.destroy();
UnityAdsFragment.this.bannerButton.setText(R.string.show_banner);
UnityAdsFragment.this.bannerShowing = false;
} else {
UnityAdsFragment.this.bannerShowing = true;
UnityAdsFragment.this.bannerButton.setText(R.string.hide_banner);
UnityBanners.setBannerPosition(BannerPosition.BOTTOM_CENTER);
UnityBanners.setBannerListener(UnityAdsFragment.this);
UnityBanners.loadBanner(getActivity(), "bannerads");
}
disableButton(showInterstitialButton);
showAd(true);
}
});
this.showRewardedButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
disableButton(showRewardedButton);
showAd(false);
}
});
this.showBannerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bottomBanner = new BannerView((Activity)v.getContext(), "bannerads", new UnityBannerSize(320, 50));
bottomBanner.setListener(bannerListener);
bottomBanner.load();
bannerLayout.addView(bottomBanner);
}
});
hideBannerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bottomBanner.removeAllViews();
bottomBanner = null;
showBannerButton.setEnabled(true);
}
});
return root;
}
private void loadAd(boolean canSkip) {
String placementToLoad = canSkip ? interstitialPlacementId : rewardedPlacementId;
PlayerMetaData playerMetaData = new PlayerMetaData(getActivity());
playerMetaData.setServerId("rikshot");
playerMetaData.commit();
MediationMetaData ordinalMetaData = new MediationMetaData(getActivity());
ordinalMetaData.setOrdinal(ordinal++);
ordinalMetaData.commit();
Log.v(LOGTAG, "Loading ad for " + placementToLoad + "...");
UnityAds.load(placementToLoad, new IUnityAdsLoadListener() {
@Override
public void onUnityAdsAdLoaded(String placementId) {
Log.v(LOGTAG, "Ad for " + placementId + " loaded");
enableButton(canSkip ? showInterstitialButton : showRewardedButton);
}
@Override
public void onUnityAdsFailedToLoad(String placementId, UnityAds.UnityAdsLoadError error, String message) {
Log.e(LOGTAG, "Ad for " + placementId + " failed to load: [" + error + "] " + message);
enableButton(canSkip ? loadInterstitialButton : loadRewardedButton);
}
});
}
private void showAd(boolean canSkip) {
String placementToShow = canSkip ? interstitialPlacementId : rewardedPlacementId;
UnityAds.show(getActivity(), placementToShow, new UnityAdsShowOptions(), new IUnityAdsShowListener() {
@Override
public void onUnityAdsShowFailure(String placementId, UnityAds.UnityAdsShowError error, String message) {
Log.e(LOGTAG, "onUnityAdsShowFailure: " + error + " - " + message);
}
@Override
public void onUnityAdsShowStart(String placementId) {
Log.v(LOGTAG, "onUnityAdsShowStart: " + placementId);
}
@Override
public void onUnityAdsShowClick(String placementId) {
Log.v(LOGTAG,"onUnityAdsShowClick: " + placementId);
}
@Override
public void onUnityAdsShowComplete(String placementId, UnityAds.UnityAdsShowCompletionState state) {
Log.v(LOGTAG,"onUnityAdsShowComplete: " + placementId);
enableButton(canSkip ? loadInterstitialButton : loadRewardedButton);
}
});
}
private void enableButton (Button btn) {
btn.setEnabled(true);
@ -206,97 +287,4 @@ public class UnityAdsFragment extends Fragment implements IUnityAdsListener, IUn
alphaUp.setFillAfter(true);
btn.startAnimation(alphaUp);
}
/* LISTENER */
@Override
public void onUnityAdsReady(final String zoneId) {
TextView statusText = this.statusText;
final Button interstitialButton = this.interstitialButton;
final Button incentivizedButton = this.incentivizedButton;
statusText.setText("");
DeviceLog.debug("onUnityAdsReady: " + zoneId);
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
// look for various default placement ids over time
switch (zoneId) {
case "video":
case "defaultZone":
case "defaultVideoAndPictureZone":
interstitialPlacementId = zoneId;
enableButton(interstitialButton);
break;
case "rewardedVideo":
case "rewardedVideoZone":
case "incentivizedZone":
incentivizedPlacementId = zoneId;
enableButton(incentivizedButton);
break;
}
}
});
toast("Ready", zoneId);
}
@Override
public void onUnityAdsStart(String zoneId) {
DeviceLog.debug("onUnityAdsStart: " + zoneId);
toast("Start", zoneId);
}
@Override
public void onUnityAdsFinish(String zoneId, UnityAds.FinishState result) {
DeviceLog.debug("onUnityAdsFinish: " + zoneId + " - " + result);
toast("Finish", zoneId + " " + result);
}
@Override
public void onUnityAdsError(UnityAds.UnityAdsError error, String message) {
DeviceLog.debug("onUnityAdsError: " + error + " - " + message);
toast("Error", error + " " + message);
TextView statusText = this.statusText;
statusText.setText(error + " - " + message);
}
private void toast(String callback, String msg) {
if (getContext() != null) {
Toast.makeText(getContext(), callback + ": " + msg, Toast.LENGTH_SHORT).show();
}
}
public void onUnityBannerLoaded(String placementId, final View view) {
final UnityAdsFragment self = this;
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
if (view.getParent() == null) {
self.getActivity().addContentView(view, view.getLayoutParams());
}
}
});
}
public void onUnityBannerUnloaded(String placementId) {
}
public void onUnityBannerShow(String placementId) {
}
public void onUnityBannerClick(String placementId) {
}
public void onUnityBannerHide(String placementId) {
}
public void onUnityBannerError(String message) {
Log.e("BANNER ERROR", message);
}
}

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

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<solid android:color="#7a7a7a"/>
<stroke android:width="5px" android:color="#FFFFFFFF" />
</shape>

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

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<vector
android:height="108dp"
android:width="108dp"
android:viewportHeight="108"
android:viewportWidth="108"
xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z"/>
<path android:fillColor="#00000000" android:pathData="M9,0L9,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,0L19,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M29,0L29,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M39,0L39,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M49,0L49,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M59,0L59,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M69,0L69,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M79,0L79,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M89,0L89,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M99,0L99,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,9L108,9"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,19L108,19"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,29L108,29"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,39L108,39"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,49L108,49"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,59L108,59"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,69L108,69"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,79L108,79"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,89L108,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,99L108,99"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,29L89,29"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,39L89,39"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,49L89,49"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,59L89,59"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,69L89,69"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,79L89,79"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M29,19L29,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M39,19L39,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M49,19L49,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M59,19L59,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M69,19L69,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M79,19L79,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
</vector>

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

@ -0,0 +1,32 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<group android:scaleX="1.2921429"
android:scaleY="1.2921429"
android:translateX="17.82"
android:translateY="17.82">
<path
android:pathData="M0,0h56v56h-56z"
android:fillColor="#4B7C18"/>
<path
android:pathData="M14,20L28,12L42,20V36L28,45L14,36.5V20Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M17.8663,32.8034L21.1073,23.2009H24.1978L27.4388,32.8034H24.9457L24.3139,30.7875H20.9998L20.368,32.8034H17.8663ZM23.7551,29.0209L22.6848,25.6166H22.6117L21.5457,29.0209H23.7551Z"
android:fillColor="#7CB342"/>
<path
android:pathData="M27.7698,29.2057C27.7698,26.6654 29.1324,25.5048 30.6411,25.5048C31.7759,25.5048 32.4034,26.1711 32.6785,26.833H32.7258V23.1966H35.0168V32.7992H32.7473V31.63H32.6785C32.3862,32.2963 31.7415,32.9023 30.654,32.9023C29.0593,32.9066 27.7698,31.6601 27.7698,29.2057ZM32.7731,29.2014C32.7731,28.0237 32.2874,27.2972 31.4449,27.2972C30.5895,27.2972 30.121,28.0409 30.121,29.2014C30.121,30.3663 30.5938,31.1185 31.4449,31.1185C32.2788,31.1185 32.7731,30.3706 32.7731,29.2014Z"
android:fillColor="#7CB342"/>
<path
android:pathData="M48.5653,15.9968L27.7827,4L7,15.9968V39.9946L27.7827,51.9957L48.5653,39.9946V15.9968ZM40.9916,35.9627L28.075,43.4204C27.8944,43.5236 27.6709,43.5236 27.4904,43.4204L14.5737,35.9627C14.3932,35.8596 14.2815,35.6662 14.2815,35.4555V20.5402C14.2815,20.3295 14.3932,20.1361 14.5737,20.033L27.4904,12.5753C27.6709,12.4721 27.8944,12.4721 28.075,12.5753L40.9916,20.033C41.1721,20.1361 41.2839,20.3295 41.2839,20.5402V35.4555C41.2839,35.6619 41.1721,35.8553 40.9916,35.9627Z"
android:fillColor="#9DC671"/>
<path
android:pathData="M14.5737,20.033L27.4904,12.5753C27.6709,12.4721 27.8944,12.4721 28.0749,12.5753L40.9916,20.033C41.0818,20.0845 41.1549,20.1576 41.2065,20.2479L48.5696,15.9968L27.7827,4L7,15.9968L14.3631,20.2479C14.4104,20.1619 14.4835,20.0888 14.5737,20.033Z"
android:fillColor="#B7D597"/>
<path
android:pathData="M48.5653,15.9968L41.2022,20.2479C41.2538,20.3338 41.2796,20.437 41.2796,20.5402V35.4555C41.2796,35.6661 41.1678,35.8596 40.9873,35.9627L28.0707,43.4204C27.9804,43.472 27.8772,43.4978 27.7784,43.4978V52L48.561,39.9989L48.5653,15.9968Z"
android:fillColor="#7CB342"/>
</group>
</vector>

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 559 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 9.6 KiB

Двоичные данные
app/src/main/res/drawable/unityads_logo.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 2.3 KiB

После

Ширина:  |  Высота:  |  Размер: 20 KiB

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

@ -1,18 +1,20 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/unityads_example_background"
android:id="@+id/unityads_example_layout_root">
<ImageView android:layout_width="280dp"
android:layout_height="wrap_content"
android:src="@drawable/unityads_logo"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_marginTop="40dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:id="@+id/unityads_example_title_text" />
<ImageView
android:id="@+id/unityads_example_title_text"
android:layout_width="280dp"
android:layout_height="157dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="40dp"
android:layout_marginTop="40dp"
android:layout_marginRight="40dp"
android:src="@drawable/unityads_logo" />
<LinearLayout
android:id="@+id/unityads_example_config_container"
@ -32,7 +34,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="90dp"
android:text="Game Id:"
android:text="Game ID:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
@ -57,10 +59,10 @@
<TextView
android:id="@+id/unityads_example_testmode_label"
android:layout_width="wrap_content"
android:layout_width="109dp"
android:layout_height="wrap_content"
android:width="90dp"
android:text="Testmode:"
android:text="Test Mode:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
@ -80,77 +82,157 @@
<LinearLayout
android:id="@+id/unityads_example_button_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="297dp"
android:layout_height="386dp"
android:layout_below="@+id/unityads_example_config_container"
android:layout_centerHorizontal="true"
android:orientation="vertical"
android:paddingLeft="15dp"
android:paddingStart="15dp"
android:paddingLeft="15dp"
android:paddingTop="25dp">
<Button
android:id="@+id/unityads_example_initialize_button"
android:layout_width="130dp"
android:layout_width="285dp"
android:layout_height="45dp"
android:layout_marginBottom="15dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="15dp"
android:background="#FF2196F3"
android:text="@string/unityads_example_initialize_text"
android:textColor="@android:color/white"
android:visibility="visible" />
<Button
android:id="@+id/unityads_example_interstitial_button"
android:layout_width="130dp"
android:layout_height="45dp"
android:layout_marginBottom="15dp"
android:layout_marginRight="15dp"
android:background="#FF2196F3"
android:enabled="false"
android:text="@string/unityads_example_interstitial_text"
android:textColor="@android:color/white"
android:visibility="visible" />
<Button
android:id="@+id/unityads_example_incentivized_button"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginBottom="15dp"
android:layout_marginRight="15dp"
android:background="#FF2196F3"
android:enabled="false"
android:text="@string/unityads_example_incentivized_text"
android:textColor="@android:color/white"
android:visibility="visible" />
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/unityads_example_banner_button"
android:layout_width="130dp"
android:layout_height="45dp"
android:layout_marginBottom="15dp"
android:layout_marginRight="15dp"
android:background="#FF2196F3"
android:enabled="false"
android:text="@string/show_banner"
android:textColor="@android:color/white"
android:visibility="visible" />
<TextView
android:id="@+id/interstitialTextView"
android:layout_width="108dp"
android:layout_height="35dp"
android:layout_weight="1"
android:text="@string/unityads_example_interstitial_text"
android:textColor="@color/design_default_color_background" />
<Button
android:id="@+id/unityads_example_load_interstitial_button"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="15dp"
android:layout_weight="1"
android:background="#FF2196F3"
android:enabled="false"
android:text="@string/unityads_example_load_text"
android:textColor="@android:color/white"
android:visibility="visible" />
<Button
android:id="@+id/unityads_example_show_interstitial_button"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="15dp"
android:layout_weight="1"
android:background="#FF2196F3"
android:enabled="false"
android:text="@string/unityads_example_show_text"
android:textColor="@android:color/white"
android:visibility="visible" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/rewardedTextView"
android:layout_width="109dp"
android:layout_height="35dp"
android:layout_weight="1"
android:text="@string/unityads_example_rewarded_text"
android:textColor="@color/design_default_color_background" />
<Button
android:id="@+id/unityads_example_load_rewarded_button"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="15dp"
android:layout_weight="1"
android:background="#FF2196F3"
android:enabled="false"
android:text="@string/unityads_example_load_text"
android:textColor="@android:color/white"
android:visibility="visible" />
<Button
android:id="@+id/unityads_example_show_rewarded_button"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="15dp"
android:layout_weight="1"
android:background="#FF2196F3"
android:enabled="false"
android:text="@string/unityads_example_show_text"
android:textColor="@android:color/white"
android:visibility="visible" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="@+id/bannerTextView"
android:layout_width="109dp"
android:layout_height="35dp"
android:layout_weight="1"
android:text="@string/unityads_example_banner_text"
android:textColor="@color/design_default_color_background" />
<Button
android:id="@+id/unityads_example_show_banner_button"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="15dp"
android:layout_weight="1"
android:background="#FF2196F3"
android:enabled="false"
android:text="@string/unityads_example_show_text"
android:textColor="@android:color/white"
android:visibility="visible" />
<Button
android:id="@+id/unityads_example_hide_banner_button"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="15dp"
android:layout_weight="1"
android:background="#FF2196F3"
android:enabled="false"
android:text="@string/unityads_example_hide_text"
android:textColor="@android:color/white"
android:visibility="visible" />
</LinearLayout>
<RelativeLayout
android:id="@+id/unityads_example_banner_layout"
android:layout_width="280dp"
android:layout_height="100dp">
</RelativeLayout>
</LinearLayout>
<TextView
android:id="@+id/unityads_example_statustext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/unityads_example_button_container"
android:gravity="center"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
</RelativeLayout>

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

@ -1,57 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/unityads_example_background"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:orientation="vertical"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingStart="15dp"
android:paddingTop="25dp"
android:gravity="center_horizontal">
<LinearLayout
android:id="@+id/top_banner_container"
android:layout_height="70dp"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
></LinearLayout>
<LinearLayout
android:id="@+id/unity_banner_ad_refresh_container"
android:layout_height="70dp"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
></LinearLayout>
<Button
android:id="@+id/top_banner_button"
android:layout_height="45dp"
android:layout_width="match_parent"
android:layout_marginBottom="15dp"
android:background="#FF2196F3"
android:text="@string/show_top_banner"
android:textColor="@android:color/white"
android:visibility="visible" />
<Button
android:id="@+id/unity_banner_ad_old_button"
android:layout_height="45dp"
android:layout_width="match_parent"
android:layout_marginBottom="15dp"
android:background="#FF2196F3"
android:text="@string/show_old_banner"
android:textColor="@android:color/white"
android:visibility="visible" />
</LinearLayout>
</RelativeLayout>

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

@ -1,37 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000FF"
android:id="@+id/native_promo_root">
<ImageView
android:id="@+id/imageView"
android:layout_width="350dp"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="@drawable/native_promo_background_portrait" />
<Button
android:id="@+id/native_promo_buy_button"
android:layout_width="198dp"
android:layout_height="52dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="45dp"
android:background="@drawable/native_promo_button"
android:text="Buy!" />
<Button
android:id="@+id/native_promo_close_button"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_alignEnd="@+id/imageView"
android:layout_alignParentTop="true"
android:background="@drawable/circle_button"
android:text="X"
android:textColor="#FFFFFFFF"
android:textStyle="bold" />
</RelativeLayout>

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

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
</adaptive-icon>

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

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
</adaptive-icon>

Двоичные данные
app/src/main/res/mipmap-hdpi/ic_launcher.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 8.3 KiB

После

Ширина:  |  Высота:  |  Размер: 2.5 KiB

Двоичные данные
app/src/main/res/mipmap-hdpi/ic_launcher_round.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 4.5 KiB

Двоичные данные
app/src/main/res/mipmap-mdpi/ic_launcher.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 4.6 KiB

После

Ширина:  |  Высота:  |  Размер: 1.8 KiB

Двоичные данные
app/src/main/res/mipmap-mdpi/ic_launcher_round.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.8 KiB

Двоичные данные
app/src/main/res/mipmap-xhdpi/ic_launcher.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 13 KiB

После

Ширина:  |  Высота:  |  Размер: 3.5 KiB

Двоичные данные
app/src/main/res/mipmap-xhdpi/ic_launcher_round.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 6.2 KiB

Двоичные данные
app/src/main/res/mipmap-xxhdpi/ic_launcher.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 25 KiB

После

Ширина:  |  Высота:  |  Размер: 5.3 KiB

Двоичные данные
app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 9.7 KiB

Двоичные данные
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 35 KiB

После

Ширина:  |  Высота:  |  Размер: 7.2 KiB

Двоичные данные
app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 14 KiB

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

@ -1,27 +1,12 @@
<resources>
<string name="unityads_example_product_name">UnityAds 2.0</string>
<string name="unityads_example_initialize_text">Initialize</string>
<string name="unityads_example_interstitial_text">Interstitial</string>
<string name="unityads_example_incentivized_text">Incentivized</string>
<string name="unityads_example_banner_text">Banner</string>
<string name="unityads_example_interstitial_text">Interstitial:</string>
<string name="unityads_example_rewarded_text">Rewarded:</string>
<string name="unityads_example_banner_text">Banner:</string>
<string name="unityads_example_load_text">Load</string>
<string name="unityads_example_show_text">Show</string>
<string name="unityads_example_hide_text">Hide</string>
<string name="title_activity_unity_ads_test_app">UnityAdsTestApp</string>
<string name="tab_text_1">Ads</string>
<string name="tab_text_2">Banners</string>
<string name="tab_text_3">Load</string>
<string name="app_name">Unity Ads Test App</string>
<string name="show_top_banner">Show Top Banner</string>
<string name="hide_top_banner">Hide Top Banner</string>
<string name="show_bottom_banner">Show Bottom Banner</string>
<string name="hide_bottom_banner">Hide Bottom Banner</string>
<string name="show_refresh_banner">Show Refresh Banner</string>
<string name="hide_refresh_banner">Hide Refresh Banner</string>
<string name="show_old_banner">Show Old Banner</string>
<string name="hide_old_banner">Hide Old Banner</string>
<string name="show_banner">Show Banner</string>
<string name="hide_banner">Hide Banner</string>
<string name="load_text">Load</string>
<string name="show_text">Show</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>

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

@ -1,63 +0,0 @@
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;

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

@ -1,24 +0,0 @@
#!/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

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

@ -7,20 +7,11 @@ if (project.rootProject.file('local.properties').exists()) {
properties.load(project.rootProject.file('local.properties').newDataInputStream())
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'org.mockito:mockito-core:2.25.0'
androidTestImplementation 'org.mockito:mockito-android:2.25.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test:rules:1.1.1'
compileOnly 'com.google.ar:core:1.0.0'
}
ext {
GROUP_ID = "com.unity3d.ads"
ARTIFACT_ID = "unity-ads"
VERSION_ID = "3.7.5"
VERSION_CODE = 3750
VERSION_ID = "4.0.0"
VERSION_CODE = 4000
SIGN_AAR = properties.getProperty("SIGN_AAR") ?: false
}
@ -78,17 +69,23 @@ dependencies {
androidTestCompileOnly project(':unity-scaradapter-1950')
androidTestCompileOnly project(':unity-scaradapter-1920')
androidTestCompileOnly project(':unity-scaradapter-common')
androidTestImplementation 'junit:junit:4.13.2'
androidTestImplementation 'org.mockito:mockito-core:2.28.2'
androidTestImplementation 'org.mockito:mockito-android:2.25.0'
// A bug in Mockito requires us to add this until an update in released
androidTestImplementation 'org.opentest4j:opentest4j:1.2.0'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test:rules:1.3.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'com.google.android.gms:play-services-ads:19.5.0'
androidTestImplementation 'com.android.billingclient:billing:4.0.0'
compileOnly 'com.google.ar:core:1.0.0'
compileOnly project(':unity-scaradapter-2000')
compileOnly project(':unity-scaradapter-1950')
compileOnly project(':unity-scaradapter-1920')
compileOnly project(':unity-scaradapter-common')
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:2.28.2'
}
task javadoc(type: Javadoc) {
@ -146,4 +143,4 @@ def getPropertyStringWithDefaultValue(String key, String defaultValue) {
apply from: 'publishing.gradle'
apply from: 'artifactory.gradle'
apply from: 'jacoco.gradle'
apply from: 'jacoco.gradle'

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

@ -2,6 +2,7 @@
package="com.unity3d.ads.test">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

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

@ -8,7 +8,6 @@ import com.unity3d.ads.test.instrumentation.services.ads.operation.LoadModuleDec
import com.unity3d.ads.test.instrumentation.services.ads.operation.LoadModuleTests;
import com.unity3d.ads.test.instrumentation.services.ads.operation.LoadOperationTests;
import com.unity3d.ads.test.instrumentation.services.ads.operation.ShowModuleTests;
import com.unity3d.ads.test.instrumentation.services.ads.properties.AdsPropertiesTests;
import com.unity3d.ads.test.instrumentation.services.ads.webplayer.WebPlayerViewCacheTest;
import com.unity3d.ads.test.instrumentation.services.ads.webplayer.WebPlayerViewSettingsCacheTest;
import com.unity3d.ads.test.instrumentation.services.banners.BannerViewCacheTests;
@ -27,7 +26,6 @@ import org.junit.runners.Suite;
@Suite.SuiteClasses({
UnityAnalyticsTest.class,
AcquisitionTypeTest.class,
AdsPropertiesTests.class,
InitializationNotificationCenterTest.class,
WebPlayerViewSettingsCacheTest.class,
WebPlayerViewCacheTest.class,

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

@ -16,7 +16,6 @@ import com.unity3d.ads.test.legacy.LoadOptionsTest;
import com.unity3d.ads.test.legacy.MetaDataTest;
import com.unity3d.ads.test.legacy.NativeCallbackTest;
import com.unity3d.ads.test.legacy.OpenAdvertisingIdentifierTest;
import com.unity3d.ads.test.legacy.PlacementTest;
import com.unity3d.ads.test.legacy.PreferencesTest;
import com.unity3d.ads.test.legacy.PublicApiTest;
import com.unity3d.ads.test.legacy.RequestTest;
@ -56,7 +55,6 @@ import org.junit.runners.Suite;
InvocationTest.class,
MetaDataTest.class,
NativeCallbackTest.class,
PlacementTest.class,
PublicApiTest.class,
RequestTest.class,
SdkPropertiesTest.class,

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

@ -29,6 +29,12 @@ public class ScarAdapterFactoryTest {
Assert.assertTrue(adapter instanceof com.unity3d.scar.adapter.v1950.ScarAdapter);
}
@Test
public void testScarAdapterFactory1980() {
IScarAdapter adapter = _scarAdapterFactory.createScarAdapter(ScarAdapterFactory.CODE_19_8, adsErrorHandlerMock);
Assert.assertTrue(adapter instanceof com.unity3d.scar.adapter.v1950.ScarAdapter);
}
@Test
public void testScarAdapterFactory2000() {
IScarAdapter adapter = _scarAdapterFactory.createScarAdapter(ScarAdapterFactory.CODE_20_0, adsErrorHandlerMock);

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

@ -28,7 +28,7 @@ public class MobileAdsBridgeTest {
OnInitializationCompleteListener initializationCompleteListener = Mockito.mock(OnInitializationCompleteListener.class);
MobileAdsBridge mobileAdsBridge = new MobileAdsBridge();
mobileAdsBridge.initialize(InstrumentationRegistry.getInstrumentation().getContext(), initializationCompleteListener);
Mockito.verify(initializationCompleteListener, timeout(1000).times(1)).onInitializationComplete(Mockito.any(InitializationStatus.class));
Mockito.verify(initializationCompleteListener, timeout(5000).times(1)).onInitializationComplete(Mockito.any(InitializationStatus.class));
String versionString = mobileAdsBridge.getVersionString();
Assert.assertTrue(String.format("Minor version 203404000 is not found in %s", versionString), versionString.contains("203404000"));
}

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

@ -10,6 +10,7 @@ import com.unity3d.services.ads.gmascar.bridges.InitializationStatusBridge;
import com.unity3d.services.ads.gmascar.bridges.InitializeListenerBridge;
import com.unity3d.services.ads.gmascar.bridges.MobileAdsBridge;
import com.unity3d.services.ads.gmascar.finder.GMAInitializer;
import com.unity3d.services.core.properties.ClientProperties;
import com.unity3d.services.core.webview.WebView;
import com.unity3d.services.core.webview.WebViewApp;
@ -37,6 +38,7 @@ public class GMAInitializerTest {
@Test
public void testGmaInitializer() {
GMAInitializer gmaInitializer = new GMAInitializer(mobileAdsBridge, initializeListenerBridge, initializationStatusBridge, adapterStatusBridge);
ClientProperties.setApplicationContext(InstrumentationRegistry.getInstrumentation().getContext());
gmaInitializer.initializeGMA();
Mockito.verify(mobileAdsBridge, times(1)).initialize(Mockito.any(Context.class), Mockito.any());
}

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

@ -1,24 +0,0 @@
package com.unity3d.ads.test.instrumentation.services.ads.mocks;
import com.unity3d.ads.IUnityAdsListener;
import com.unity3d.ads.UnityAds;
public class UnityAdsListenerMock implements IUnityAdsListener {
public void onUnityAdsReady(String placementId) {
}
public void onUnityAdsStart(String placementId) {
}
public void onUnityAdsFinish(String placementId, UnityAds.FinishState result) {
}
public void onUnityAdsError(UnityAds.UnityAdsError error, String message) {
}
}

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

@ -1,12 +1,15 @@
package com.unity3d.ads.test.instrumentation.services.ads.operation;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.times;
import com.unity3d.ads.IUnityAdsLoadListener;
import com.unity3d.ads.UnityAds;
import com.unity3d.ads.UnityAdsLoadOptions;
import com.unity3d.ads.test.TestUtilities;
import com.unity3d.services.ads.operation.load.ILoadModule;
import com.unity3d.services.ads.operation.load.LoadOperationState;
import com.unity3d.services.ads.operation.load.LoadModuleDecoratorInitializationBuffer;
import com.unity3d.services.ads.operation.load.LoadOperationState;
import com.unity3d.services.core.configuration.Configuration;
import com.unity3d.services.core.configuration.IInitializationNotificationCenter;
import com.unity3d.services.core.properties.SdkProperties;
@ -16,12 +19,9 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
public class LoadModuleDecoratorInitializationBufferTests {
private static String testPlacementId = "TestPlacementId";
private static int uiThreadDelay = 25;
private static final String testPlacementId = "TestPlacementId";
private static final int maxWaitTime = 25000;
private ILoadModule loadModuleMock = mock(ILoadModule.class);
private IInitializationNotificationCenter initializationNotificationCenterMock;
@ -54,9 +54,8 @@ public class LoadModuleDecoratorInitializationBufferTests {
SdkProperties.setInitializeState(SdkProperties.InitializationState.INITIALIZED_FAILED);
loadModuleInitBuffer.executeAdOperation(webViewBridgeInvokerMock, loadOperationState);
TestUtilities.SleepCurrentThread(uiThreadDelay);
Mockito.verify(loadListenerMock, times(1)).onUnityAdsFailedToLoad(testPlacementId, UnityAds.UnityAdsLoadError.INITIALIZE_FAILED, "[UnityAds] SDK Initialization Failed");
Mockito.verify(loadListenerMock, timeout(maxWaitTime).times(1)).onUnityAdsFailedToLoad(testPlacementId, UnityAds.UnityAdsLoadError.INITIALIZE_FAILED, "[UnityAds] SDK Initialization Failed");
}
@Test
@ -101,11 +100,9 @@ public class LoadModuleDecoratorInitializationBufferTests {
SdkProperties.setInitializeState(SdkProperties.InitializationState.INITIALIZING);
loadModuleInitBuffer.executeAdOperation(webViewBridgeInvokerMock, loadOperationStateMock);
TestUtilities.SleepCurrentThread(uiThreadDelay);
Mockito.verify(initializationNotificationCenterMock, times(1)).addListener(loadModuleInitBuffer);
loadModuleInitBuffer.onSdkInitializationFailed("UntestableMessage", 0);
TestUtilities.SleepCurrentThread(uiThreadDelay);
Mockito.verify(loadListenerMock, times(1)).onUnityAdsFailedToLoad(testPlacementId, UnityAds.UnityAdsLoadError.INITIALIZE_FAILED, "[UnityAds] SDK Initialization Failure");
Mockito.verify(loadListenerMock, timeout(maxWaitTime).times(1)).onUnityAdsFailedToLoad(testPlacementId, UnityAds.UnityAdsLoadError.INITIALIZE_FAILED, "[UnityAds] SDK Initialization Failure");
}
}

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

@ -1,20 +1,20 @@
package com.unity3d.ads.test.instrumentation.services.ads.operation;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import com.unity3d.ads.UnityAds;
import com.unity3d.services.ads.operation.load.ILoadModule;
import com.unity3d.services.ads.operation.load.LoadOperationState;
import com.unity3d.services.ads.operation.load.LoadModuleDecorator;
import com.unity3d.services.ads.operation.load.LoadOperationState;
import com.unity3d.services.core.webview.bridge.IWebViewBridgeInvoker;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
public class LoadModuleDecoratorTests {
private static String testId = "TestId";
private static final String testId = "TestId";
private ILoadModule loadModuleMock;

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

@ -1,33 +1,33 @@
package com.unity3d.ads.test.instrumentation.services.ads.operation;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.times;
import com.unity3d.ads.IUnityAdsLoadListener;
import com.unity3d.ads.UnityAds;
import com.unity3d.ads.UnityAdsLoadOptions;
import com.unity3d.ads.test.TestUtilities;
import com.unity3d.services.ads.operation.load.ILoadModule;
import com.unity3d.services.ads.operation.load.LoadOperationState;
import com.unity3d.services.ads.operation.load.LoadModuleDecoratorTimeout;
import com.unity3d.services.ads.operation.load.LoadOperationState;
import com.unity3d.services.core.webview.bridge.IWebViewBridgeInvoker;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.internal.matchers.Any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
public class LoadModuleDecoratorTimeoutTests {
private static String placementId = "TestPlacementId";
private static UnityAds.UnityAdsLoadError loadError = UnityAds.UnityAdsLoadError.INTERNAL_ERROR;
private static String loadErrorMessage = "LoadErrorMessage";
private static UnityAdsLoadOptions loadOptions = new UnityAdsLoadOptions();
private static final String placementId = "TestPlacementId";
private static final UnityAds.UnityAdsLoadError loadError = UnityAds.UnityAdsLoadError.INTERNAL_ERROR;
private static final String loadErrorMessage = "LoadErrorMessage";
private static final UnityAdsLoadOptions loadOptions = new UnityAdsLoadOptions();
private static int loadTimeout = 50;
private static int uiThreadDelay = 150;
private static final int loadTimeout = 50;
private static final int loadTimeoutExpireMs = loadTimeout * 10;
private static final int maxWaitTime = 25000;
private IUnityAdsLoadListener loadListenerMock;
private ILoadModule loadModuleMock;
@ -38,21 +38,13 @@ public class LoadModuleDecoratorTimeoutTests {
loadModuleMock = mock(ILoadModule.class);
}
@After
public void afterEachTest() {
//Allow for any timeout threads to complete before starting the next test to prevent inaccurate mock counts
TestUtilities.SleepCurrentThread(loadTimeout);
}
@Test
public void onUnityAdsFailedToLoadIsCalledWhenTimeoutIsReached() {
LoadOperationState loadOperationState = new LoadOperationState(placementId, loadListenerMock, loadOptions, OperationTestUtilities.createConfigurationWithLoadTimeout(loadTimeout));
LoadModuleDecoratorTimeout timeoutDecorator = new LoadModuleDecoratorTimeout(loadModuleMock);
timeoutDecorator.executeAdOperation(mock(IWebViewBridgeInvoker.class), loadOperationState);
TestUtilities.SleepCurrentThread(uiThreadDelay);
Mockito.verify(loadListenerMock, times(1)).onUnityAdsFailedToLoad(placementId, UnityAds.UnityAdsLoadError.TIMEOUT, "[UnityAds] Timeout while loading " + placementId);
Mockito.verify(loadListenerMock, timeout(maxWaitTime).times(1)).onUnityAdsFailedToLoad(placementId, UnityAds.UnityAdsLoadError.TIMEOUT, "[UnityAds] Timeout while loading " + placementId);
}
@Test
@ -61,11 +53,11 @@ public class LoadModuleDecoratorTimeoutTests {
LoadModuleDecoratorTimeout timeoutDecorator = new LoadModuleDecoratorTimeout(loadModuleMock);
timeoutDecorator.executeAdOperation(mock(IWebViewBridgeInvoker.class), loadOperationState);
TestUtilities.SleepCurrentThread(uiThreadDelay);
TestUtilities.SleepCurrentThread(loadTimeoutExpireMs);
timeoutDecorator.onUnityAdsAdLoaded(placementId);
timeoutDecorator.onUnityAdsFailedToLoad(placementId, loadError, loadErrorMessage);
Mockito.verify(loadListenerMock, times(1)).onUnityAdsFailedToLoad(placementId, UnityAds.UnityAdsLoadError.TIMEOUT, "[UnityAds] Timeout while loading " + placementId);
Mockito.verify(loadListenerMock, timeout(maxWaitTime).times(1)).onUnityAdsFailedToLoad(placementId, UnityAds.UnityAdsLoadError.TIMEOUT, "[UnityAds] Timeout while loading " + placementId);
Mockito.verify(loadListenerMock, times(0)).onUnityAdsAdLoaded(anyString());
}
@ -77,7 +69,6 @@ public class LoadModuleDecoratorTimeoutTests {
timeoutDecorator.executeAdOperation(mock(IWebViewBridgeInvoker.class), loadOperationState);
TestUtilities.SleepCurrentThread(25);
timeoutDecorator.onUnityAdsAdLoaded(placementId);
TestUtilities.SleepCurrentThread(uiThreadDelay);
Mockito.verify(loadModuleMock, times(1)).onUnityAdsAdLoaded(placementId);
Mockito.verify(loadModuleMock, times(0)).onUnityAdsFailedToLoad(anyString(), any(UnityAds.UnityAdsLoadError.class), anyString());

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

@ -1,18 +1,24 @@
package com.unity3d.ads.test.instrumentation.services.ads.operation;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.times;
import com.unity3d.ads.IUnityAdsLoadListener;
import com.unity3d.ads.UnityAds;
import com.unity3d.ads.UnityAdsLoadOptions;
import com.unity3d.ads.test.TestUtilities;
import com.unity3d.services.ads.operation.load.LoadOperationState;
import com.unity3d.services.ads.operation.load.LoadModule;
import com.unity3d.services.ads.operation.load.LoadOperation;
import com.unity3d.services.ads.operation.load.LoadOperationState;
import com.unity3d.services.core.request.ISDKMetricSender;
import com.unity3d.services.core.request.SDKMetricEvents;
import com.unity3d.services.core.webview.bridge.IWebViewBridgeInvoker;
import com.unity3d.services.core.webview.bridge.invocation.IWebViewBridgeInvocation;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@ -22,20 +28,14 @@ import org.mockito.stubbing.Answer;
import java.lang.reflect.Method;
import java.util.HashMap;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
public class LoadModuleTests {
private static String placementId = "TestPlacementId";
private static UnityAds.UnityAdsLoadError loadError = UnityAds.UnityAdsLoadError.INTERNAL_ERROR;
private static String loadErrorMessage = "LoadErrorMessage";
private static int uiThreadDelay = 50;
private static int webViewTimeout = 150;
private static UnityAdsLoadOptions unityAdsLoadOptions = new UnityAdsLoadOptions();
private static final String placementId = "TestPlacementId";
private static final UnityAds.UnityAdsLoadError loadError = UnityAds.UnityAdsLoadError.INTERNAL_ERROR;
private static final String loadErrorMessage = "LoadErrorMessage";
private static final int maxWaitTime = 25000;
private static final int webViewTimeout = 100;
private static final int loadTimeoutExpireMs = webViewTimeout + 10;
private static final UnityAdsLoadOptions unityAdsLoadOptions = new UnityAdsLoadOptions();
private IWebViewBridgeInvoker webViewBridgeInvokerMock;
private IUnityAdsLoadListener loadListenerMock;
@ -50,19 +50,12 @@ public class LoadModuleTests {
loadModule = new LoadModule(sdkMetricSender);
}
@After
public void afterEachTest() {
//Allow for any timeout threads to complete before starting the next test to prevent inaccurate mock counts
TestUtilities.SleepCurrentThread(webViewTimeout);
}
@Test
public void executeAdOperationCallsOnUnityAdsFailedToLoadWhenPlacementNotSet() {
LoadOperationState loadOperationState = new LoadOperationState(null, loadListenerMock, unityAdsLoadOptions, OperationTestUtilities.createConfigurationWithWebviewTimeout(webViewTimeout));
loadModule.executeAdOperation(webViewBridgeInvokerMock, loadOperationState);
TestUtilities.SleepCurrentThread(uiThreadDelay);
Mockito.verify(loadListenerMock, times(1)).onUnityAdsFailedToLoad("", UnityAds.UnityAdsLoadError.INVALID_ARGUMENT,"[UnityAds] Placement ID cannot be null");
Mockito.verify(loadListenerMock, timeout(maxWaitTime).times(1)).onUnityAdsFailedToLoad("", UnityAds.UnityAdsLoadError.INVALID_ARGUMENT,"[UnityAds] Placement ID cannot be null");
}
@Test
@ -77,9 +70,8 @@ public class LoadModuleTests {
}).when(webViewBridgeInvokerMock).invokeMethod(anyString(), anyString(), any(Method.class), any(Object.class));
loadModule.executeAdOperation(webViewBridgeInvokerMock, loadOperationState);
TestUtilities.SleepCurrentThread(uiThreadDelay);
Mockito.verify(loadListenerMock, times(1)).onUnityAdsFailedToLoad(placementId, UnityAds.UnityAdsLoadError.INTERNAL_ERROR, "[UnityAds] Internal communication failure");
Mockito.verify(loadListenerMock, timeout(maxWaitTime).times(1)).onUnityAdsFailedToLoad(placementId, UnityAds.UnityAdsLoadError.INTERNAL_ERROR, "[UnityAds] Internal communication failure");
Mockito.verify(sdkMetricSender, times(1)).SendSDKMetricEventWithTag(SDKMetricEvents.native_load_callback_error, new HashMap<String, String> (){{
put("cbs", "invocationFailure");
}});
@ -97,9 +89,8 @@ public class LoadModuleTests {
}).when(webViewBridgeInvokerMock).invokeMethod(anyString(), anyString(), any(Method.class), any(Object.class));
loadModule.executeAdOperation(webViewBridgeInvokerMock, loadOperationState);
TestUtilities.SleepCurrentThread(100);
TestUtilities.SleepCurrentThread(150);
Mockito.verify(loadListenerMock, times(1)).onUnityAdsFailedToLoad(placementId, UnityAds.UnityAdsLoadError.INTERNAL_ERROR, "[UnityAds] Internal communication timeout");
Mockito.verify(loadListenerMock, timeout(maxWaitTime).times(1)).onUnityAdsFailedToLoad(placementId, UnityAds.UnityAdsLoadError.INTERNAL_ERROR, "[UnityAds] Internal communication timeout");
Mockito.verify(sdkMetricSender, times(1)).SendSDKMetricEvent(eq(SDKMetricEvents.native_load_callback_timeout));
}
@ -108,9 +99,8 @@ public class LoadModuleTests {
LoadOperationState loadOperationState = new LoadOperationState(placementId, loadListenerMock, null, OperationTestUtilities.createConfigurationWithWebviewTimeout(webViewTimeout));
loadModule.executeAdOperation(webViewBridgeInvokerMock, loadOperationState);
TestUtilities.SleepCurrentThread(uiThreadDelay);
Mockito.verify(loadListenerMock, times(1)).onUnityAdsFailedToLoad(placementId, UnityAds.UnityAdsLoadError.INTERNAL_ERROR, "[UnityAds] Failed to create load request");
Mockito.verify(loadListenerMock, timeout(maxWaitTime).times(1)).onUnityAdsFailedToLoad(placementId, UnityAds.UnityAdsLoadError.INTERNAL_ERROR, "[UnityAds] Failed to create load request");
}
@Test
@ -118,8 +108,7 @@ public class LoadModuleTests {
LoadOperationState loadOperationState = new LoadOperationState(placementId, loadListenerMock, unityAdsLoadOptions, OperationTestUtilities.createConfigurationWithWebviewTimeout(webViewTimeout));
loadModule.executeAdOperation(webViewBridgeInvokerMock, loadOperationState);
TestUtilities.SleepCurrentThread(uiThreadDelay);
Mockito.verify(webViewBridgeInvokerMock, times(1)).invokeMethod(anyString(), anyString(), any(Method.class), any(Object.class));
Mockito.verify(webViewBridgeInvokerMock, timeout(maxWaitTime).times(1)).invokeMethod(anyString(), anyString(), any(Method.class), any(Object.class));
}
@Test
@ -130,8 +119,7 @@ public class LoadModuleTests {
loadModule.set(loadOperation);
loadModule.onUnityAdsAdLoaded(loadOperation.getId());
TestUtilities.SleepCurrentThread(uiThreadDelay);
Mockito.verify(loadListenerMock, times(1)).onUnityAdsAdLoaded(placementId);
Mockito.verify(loadListenerMock, timeout(maxWaitTime).times(1)).onUnityAdsAdLoaded(placementId);
}
@Test
@ -141,7 +129,6 @@ public class LoadModuleTests {
loadModule.set(null);
loadModule.onUnityAdsAdLoaded(loadOperation.getId());
TestUtilities.SleepCurrentThread(uiThreadDelay);
//No Verification as there is nothing to mock against. A null pointer exception is all that is being checked for here.
}
@ -153,8 +140,7 @@ public class LoadModuleTests {
loadModule.set(loadOperation);
loadModule.onUnityAdsFailedToLoad(loadOperation.getId(), loadError, loadErrorMessage);
TestUtilities.SleepCurrentThread(uiThreadDelay);
Mockito.verify(loadListenerMock, times(1)).onUnityAdsFailedToLoad(placementId, loadError, loadErrorMessage);
Mockito.verify(loadListenerMock, timeout(maxWaitTime).times(1)).onUnityAdsFailedToLoad(placementId, loadError, loadErrorMessage);
}
@Test
@ -164,7 +150,6 @@ public class LoadModuleTests {
loadModule.set(null);
loadModule.onUnityAdsFailedToLoad(loadOperation.getId(), loadError, loadErrorMessage);
TestUtilities.SleepCurrentThread(uiThreadDelay);
//No Verification as there is nothing to mock against. A null pointer exception is all that is being checked for here.
}
}

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

@ -1,33 +1,29 @@
package com.unity3d.ads.test.instrumentation.services.ads.operation;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.timeout;
import com.unity3d.ads.IUnityAdsLoadListener;
import com.unity3d.ads.UnityAds;
import com.unity3d.ads.UnityAdsLoadOptions;
import com.unity3d.ads.test.TestUtilities;
import com.unity3d.services.ads.operation.load.LoadOperationState;
import com.unity3d.services.ads.operation.load.LoadOperation;
import com.unity3d.services.ads.operation.load.LoadOperationState;
import com.unity3d.services.core.webview.bridge.invocation.IWebViewBridgeInvocation;
import junit.framework.Assert;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
public class LoadOperationTests {
private static String placementId = "TestPlacementId";
private static UnityAds.UnityAdsLoadError loadError = UnityAds.UnityAdsLoadError.INTERNAL_ERROR;
private static String loadErrorMessage = "LoadErrorMessage";
private static UnityAdsLoadOptions loadOptions = new UnityAdsLoadOptions();
private static final String placementId = "TestPlacementId";
private static final UnityAds.UnityAdsLoadError loadError = UnityAds.UnityAdsLoadError.INTERNAL_ERROR;
private static final String loadErrorMessage = "LoadErrorMessage";
private static final UnityAdsLoadOptions loadOptions = new UnityAdsLoadOptions();
private static int loadTimeout = 150;
private static int uiThreadDelay = 25;
private static final int loadTimeout = 150;
private static final int maxWaitTime = 25000;
private IUnityAdsLoadListener loadListenerMock;
@ -36,21 +32,14 @@ public class LoadOperationTests {
loadListenerMock = mock(IUnityAdsLoadListener.class);
}
@After
public void afterEachTest() {
//Allow for any timeout threads to complete before starting the next test to prevent inaccurate mock counts
TestUtilities.SleepCurrentThread(loadTimeout);
}
@Test
public void onUnityAdsAdLoadedCallsListenerOnUnityAdsAdLoadedWhenSet() {
LoadOperationState loadOperationState = new LoadOperationState(placementId, loadListenerMock, loadOptions, OperationTestUtilities.createConfigurationWithLoadTimeout(loadTimeout));
LoadOperation loadOperation = new LoadOperation(loadOperationState, mock(IWebViewBridgeInvocation.class));
loadOperation.onUnityAdsAdLoaded(placementId);
TestUtilities.SleepCurrentThread(uiThreadDelay);
Mockito.verify(loadListenerMock, times(1)).onUnityAdsAdLoaded(placementId);
Mockito.verify(loadListenerMock, timeout(maxWaitTime).times(1)).onUnityAdsAdLoaded(placementId);
}
@Test
@ -59,7 +48,6 @@ public class LoadOperationTests {
LoadOperation loadOperation = new LoadOperation(loadOperationState, mock(IWebViewBridgeInvocation.class));
loadOperation.onUnityAdsAdLoaded(placementId);
TestUtilities.SleepCurrentThread(uiThreadDelay);
//No Verification as there is nothing to mock against. A null pointer exception is all that is being checked for here.
}
@ -68,7 +56,6 @@ public class LoadOperationTests {
LoadOperation loadOperation = new LoadOperation(null, mock(IWebViewBridgeInvocation.class));
loadOperation.onUnityAdsAdLoaded(null);
TestUtilities.SleepCurrentThread(uiThreadDelay);
//No Verification as there is nothing to mock against. A null pointer exception is all that is being checked for here.
}
@ -78,9 +65,8 @@ public class LoadOperationTests {
LoadOperation loadOperation = new LoadOperation(loadOperationState, mock(IWebViewBridgeInvocation.class));
loadOperation.onUnityAdsAdLoaded(null);
TestUtilities.SleepCurrentThread(uiThreadDelay);
Mockito.verify(loadListenerMock, times(0)).onUnityAdsAdLoaded(anyString());
Mockito.verify(loadListenerMock, timeout(maxWaitTime).times(0)).onUnityAdsAdLoaded(anyString());
}
@Test
@ -89,9 +75,8 @@ public class LoadOperationTests {
LoadOperation loadOperation = new LoadOperation(loadOperationState, mock(IWebViewBridgeInvocation.class));
loadOperation.onUnityAdsFailedToLoad(placementId, loadError, loadErrorMessage);
TestUtilities.SleepCurrentThread(uiThreadDelay);
Mockito.verify(loadListenerMock, times(1)).onUnityAdsFailedToLoad(placementId, loadError, loadErrorMessage);
Mockito.verify(loadListenerMock, timeout(maxWaitTime).times(1)).onUnityAdsFailedToLoad(placementId, loadError, loadErrorMessage);
}
@Test
@ -100,7 +85,6 @@ public class LoadOperationTests {
LoadOperation loadOperation = new LoadOperation(loadOperationState, mock(IWebViewBridgeInvocation.class));
loadOperation.onUnityAdsFailedToLoad(placementId, loadError, loadErrorMessage);
TestUtilities.SleepCurrentThread(uiThreadDelay);
//No Verification as there is nothing to mock against. A null pointer exception is all that is being checked for here.
}
@ -109,7 +93,6 @@ public class LoadOperationTests {
LoadOperation loadOperation = new LoadOperation(null, mock(IWebViewBridgeInvocation.class));
loadOperation.onUnityAdsFailedToLoad(null, loadError, loadErrorMessage);
TestUtilities.SleepCurrentThread(uiThreadDelay);
//No Verification as there is nothing to mock against. A null pointer exception is all that is being checked for here.
}
@ -119,9 +102,8 @@ public class LoadOperationTests {
LoadOperation loadOperation = new LoadOperation(loadOperationState, mock(IWebViewBridgeInvocation.class));
loadOperation.onUnityAdsFailedToLoad(null, loadError, loadErrorMessage);
TestUtilities.SleepCurrentThread(uiThreadDelay);
Mockito.verify(loadListenerMock, times(0)).onUnityAdsFailedToLoad(null, loadError, loadErrorMessage);
Mockito.verify(loadListenerMock, timeout(maxWaitTime).times(0)).onUnityAdsFailedToLoad(null, loadError, loadErrorMessage);
}
@Test

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

@ -1,11 +1,17 @@
package com.unity3d.ads.test.instrumentation.services.ads.operation;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;
import androidx.test.rule.ActivityTestRule;
import com.unity3d.ads.IUnityAdsShowListener;
import com.unity3d.ads.UnityAds;
import com.unity3d.ads.UnityAdsShowOptions;
import com.unity3d.ads.test.TestUtilities;
import com.unity3d.ads.test.instrumentation.InstrumentationTestActivity;
import com.unity3d.services.ads.operation.show.IShowModule;
import com.unity3d.services.ads.operation.show.ShowModule;
@ -14,10 +20,8 @@ import com.unity3d.services.ads.operation.show.ShowOperationState;
import com.unity3d.services.core.request.ISDKMetricSender;
import com.unity3d.services.core.webview.bridge.CallbackStatus;
import com.unity3d.services.core.webview.bridge.IWebViewBridgeInvoker;
import com.unity3d.services.core.webview.bridge.invocation.WebViewBridgeInvocation;
import com.unity3d.services.core.webview.bridge.invocation.WebViewBridgeInvocationRunnable;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@ -25,20 +29,13 @@ import org.mockito.Mockito;
import java.lang.reflect.Method;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;
public class ShowModuleDecoratorTimeoutTests {
private static String placementId = "TestPlacementId";
private static UnityAdsShowOptions showOptions = new UnityAdsShowOptions();
private static final String placementId = "TestPlacementId";
private static final UnityAdsShowOptions showOptions = new UnityAdsShowOptions();
private ISDKMetricSender sdkMetricSender;
private static int showTimeout = 50;
private static int uiThreadDelay = 150;
private static final int showTimeout = 50;
private static final int maxWaitTime = 25000;
private IUnityAdsShowListener showListenerMock;
private IShowModule showModule;
@ -54,19 +51,13 @@ public class ShowModuleDecoratorTimeoutTests {
showModule = new ShowModule(sdkMetricSender);
}
@After
public void afterEachTest() {
//Allow for any timeout threads to complete before starting the next test to prevent inaccurate mock counts
TestUtilities.SleepCurrentThread(showTimeout);
}
@Test
public void testShowModuleDecoratorTimeout() {
ShowModuleDecoratorTimeout showModuleDecoratorTimeout = new ShowModuleDecoratorTimeout(showModule);
ShowOperationState showOperationState = new ShowOperationState(placementId, showListenerMock, _activityRule.getActivity(), showOptions, OperationTestUtilities.createConfigurationWithShowTimeout(showTimeout));
showModuleDecoratorTimeout.executeAdOperation(mock(IWebViewBridgeInvoker.class), showOperationState);
TestUtilities.SleepCurrentThread(uiThreadDelay);
Mockito.verify(showListenerMock, times(1)).onUnityAdsShowFailure(placementId, UnityAds.UnityAdsShowError.INTERNAL_ERROR, "[UnityAds] Timeout while trying to show TestPlacementId");
Mockito.verify(showListenerMock, timeout(maxWaitTime).times(1)).onUnityAdsShowFailure(placementId, UnityAds.UnityAdsShowError.INTERNAL_ERROR, "[UnityAds] Timeout while trying to show TestPlacementId");
}
@Test
@ -79,7 +70,6 @@ public class ShowModuleDecoratorTimeoutTests {
showModuleDecoratorTimeout.executeAdOperation(webViewBridgeInvoker, showOperationState);
WebViewBridgeInvocationRunnable.onInvocationComplete(CallbackStatus.OK);
showModuleDecoratorTimeout.onUnityAdsShowConsent(showOperationState.getId());
TestUtilities.SleepCurrentThread(uiThreadDelay);
Mockito.verify(showListenerMock, times(0)).onUnityAdsShowFailure(anyString(), any(UnityAds.UnityAdsShowError.class), anyString());
}
}

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

@ -1,11 +1,17 @@
package com.unity3d.ads.test.instrumentation.services.ads.operation;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.timeout;
import androidx.test.rule.ActivityTestRule;
import com.unity3d.ads.IUnityAdsShowListener;
import com.unity3d.ads.UnityAds;
import com.unity3d.ads.UnityAdsShowOptions;
import com.unity3d.ads.test.TestUtilities;
import com.unity3d.ads.test.instrumentation.InstrumentationTestActivity;
import com.unity3d.services.ads.operation.show.IShowModule;
import com.unity3d.services.ads.operation.show.ShowModule;
@ -26,19 +32,12 @@ import org.mockito.stubbing.Answer;
import java.lang.reflect.Method;
import java.util.HashMap;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
public class ShowModuleTests {
private static String placementId = "TestPlacementId";
private static UnityAdsShowOptions showOptions = new UnityAdsShowOptions();
private static final String placementId = "TestPlacementId";
private static final UnityAdsShowOptions showOptions = new UnityAdsShowOptions();
private static int showTimeout = 100;
private static int uiThreadDelay = 25;
private static final int showTimeout = 100;
private static final int maxWaitTime = 25000;
private IUnityAdsShowListener _showListenerMock;
private IShowModule _showModule;
@ -60,25 +59,23 @@ public class ShowModuleTests {
public void executeAdOperationCallsOnUnityAdsFailedToShowWhenPlacementNotSet() {
ShowOperationState showOperationState = new ShowOperationState(null, _showListenerMock, _activityRule.getActivity(), showOptions, OperationTestUtilities.createConfigurationWithShowTimeout(showTimeout));
_showModule.executeAdOperation(_webViewBridgeInvokerMock, showOperationState);
TestUtilities.SleepCurrentThread(uiThreadDelay);
Mockito.verify((_showListenerMock), times(1)).onUnityAdsShowFailure("", UnityAds.UnityAdsShowError.INVALID_ARGUMENT, "[UnityAds] Placement ID cannot be null");
Mockito.verify((_showListenerMock), timeout(maxWaitTime).times(1)).onUnityAdsShowFailure("", UnityAds.UnityAdsShowError.INVALID_ARGUMENT, "[UnityAds] Placement ID cannot be null");
}
@Test
public void showModuleCallsOnUnityAdsFailedToShowWhenInvocationCallbackFails() {
ShowOperationState showOperationState = new ShowOperationState(placementId, _showListenerMock, _activityRule.getActivity(), showOptions, OperationTestUtilities.createConfigurationWithShowTimeout(showTimeout));
doAnswer(new Answer() {
doAnswer(new Answer<Object>() {
public Object answer(InvocationOnMock invocation) {
return false;
}
}).when(_webViewBridgeInvokerMock).invokeMethod(anyString(), anyString(), any(Method.class), any(Object.class));
_showModule.executeAdOperation(_webViewBridgeInvokerMock, showOperationState);
TestUtilities.SleepCurrentThread(uiThreadDelay);
Mockito.verify((_showListenerMock), times(1)).onUnityAdsShowFailure(placementId, UnityAds.UnityAdsShowError.INTERNAL_ERROR, "WebViewBridgeInvocationRunnable:run: invokeMethod failure");
Mockito.verify(_sdkMetricSender, times(1)).SendSDKMetricEventWithTag(SDKMetricEvents.native_show_callback_error, new HashMap<String, String> (){{
Mockito.verify((_showListenerMock), timeout(maxWaitTime).times(1)).onUnityAdsShowFailure(placementId, UnityAds.UnityAdsShowError.INTERNAL_ERROR, "WebViewBridgeInvocationRunnable:run: invokeMethod failure");
Mockito.verify(_sdkMetricSender, timeout(maxWaitTime).times(1)).SendSDKMetricEventWithTag(SDKMetricEvents.native_show_callback_error, new HashMap<String, String> (){{
put("cbs", "invocationFailure");
}});
}
@ -87,7 +84,7 @@ public class ShowModuleTests {
public void showModuleCallsOnUnityAdsFailedToShowWhenInvocationCallbackTimesOut() {
ShowOperationState showOperationState = new ShowOperationState(placementId, _showListenerMock, _activityRule.getActivity(), showOptions, OperationTestUtilities.createConfigurationWithWebviewTimeout(50));
doAnswer(new Answer() {
doAnswer(new Answer<Object>() {
public Object answer(InvocationOnMock invocation) {
//Succeed invocation but don't simulate any return call from WebView so the request acknowledgement times out.
return true;
@ -95,10 +92,9 @@ public class ShowModuleTests {
}).when(_webViewBridgeInvokerMock).invokeMethod(anyString(), anyString(), any(Method.class), any(Object.class));
_showModule.executeAdOperation(_webViewBridgeInvokerMock, showOperationState);
TestUtilities.SleepCurrentThread(250);
Mockito.verify((_showListenerMock), times(1)).onUnityAdsShowFailure(placementId, UnityAds.UnityAdsShowError.INTERNAL_ERROR, "[UnityAds] Show Invocation Timeout");
Mockito.verify(_sdkMetricSender, times(1)).SendSDKMetricEvent(eq(SDKMetricEvents.native_show_callback_timeout));
Mockito.verify((_showListenerMock), timeout(maxWaitTime).times(1)).onUnityAdsShowFailure(placementId, UnityAds.UnityAdsShowError.INTERNAL_ERROR, "[UnityAds] Show Invocation Timeout");
Mockito.verify(_sdkMetricSender, timeout(maxWaitTime).times(1)).SendSDKMetricEvent(eq(SDKMetricEvents.native_show_callback_timeout));
}
@Test
@ -106,9 +102,7 @@ public class ShowModuleTests {
ShowOperationState showOperationState = new ShowOperationState(placementId, _showListenerMock, _activityRule.getActivity(), null, OperationTestUtilities.createConfigurationWithShowTimeout(showTimeout));
_showModule.executeAdOperation(_webViewBridgeInvokerMock, showOperationState);
TestUtilities.SleepCurrentThread(uiThreadDelay);
Mockito.verify((_showListenerMock), times(1)).onUnityAdsShowFailure(placementId, UnityAds.UnityAdsShowError.INTERNAL_ERROR, "[UnityAds] Error creating show options");
Mockito.verify((_showListenerMock), timeout(maxWaitTime).times(1)).onUnityAdsShowFailure(placementId, UnityAds.UnityAdsShowError.INTERNAL_ERROR, "[UnityAds] Error creating show options");
}
@Test
@ -116,9 +110,8 @@ public class ShowModuleTests {
ShowOperationState showOperationState = new ShowOperationState(placementId, _showListenerMock, _activityRule.getActivity(), showOptions, OperationTestUtilities.createConfigurationWithShowTimeout(showTimeout));
_showModule.executeAdOperation(_webViewBridgeInvokerMock, showOperationState);
TestUtilities.SleepCurrentThread(uiThreadDelay);
Mockito.verify((_webViewBridgeInvokerMock), times(1)).invokeMethod(anyString(), anyString(), any(Method.class), any(Object.class));
Mockito.verify((_webViewBridgeInvokerMock), timeout(maxWaitTime).times(1)).invokeMethod(anyString(), anyString(), any(Method.class), any(Object.class));
}
@Test
@ -128,9 +121,8 @@ public class ShowModuleTests {
_showModule.set(showOperation);
_showModule.onUnityAdsShowFailure(showOperation.getId(), UnityAds.UnityAdsShowError.INTERNAL_ERROR, "ErrorMessage");
TestUtilities.SleepCurrentThread(uiThreadDelay);
Mockito.verify(_showListenerMock, times(1)).onUnityAdsShowFailure(placementId, UnityAds.UnityAdsShowError.INTERNAL_ERROR, "ErrorMessage");
Mockito.verify(_showListenerMock, timeout(maxWaitTime).times(1)).onUnityAdsShowFailure(placementId, UnityAds.UnityAdsShowError.INTERNAL_ERROR, "ErrorMessage");
}
@Test
@ -139,7 +131,6 @@ public class ShowModuleTests {
ShowOperation showOperation = new ShowOperation(showOperationState, mock(IWebViewBridgeInvocation.class));
_showModule.onUnityAdsShowFailure(showOperation.getId(), UnityAds.UnityAdsShowError.INTERNAL_ERROR, "ErrorMessage");
TestUtilities.SleepCurrentThread(uiThreadDelay);
}
@Test
@ -149,9 +140,8 @@ public class ShowModuleTests {
_showModule.set(showOperation);
_showModule.onUnityAdsShowStart(showOperation.getId());
TestUtilities.SleepCurrentThread(uiThreadDelay);
Mockito.verify(_showListenerMock, times(1)).onUnityAdsShowStart(placementId);
Mockito.verify(_showListenerMock, timeout(maxWaitTime).times(1)).onUnityAdsShowStart(placementId);
}
@Test
@ -160,7 +150,6 @@ public class ShowModuleTests {
ShowOperation showOperation = new ShowOperation(showOperationState, mock(IWebViewBridgeInvocation.class));
_showModule.onUnityAdsShowStart(showOperation.getId());
TestUtilities.SleepCurrentThread(uiThreadDelay);
}
@Test
@ -170,9 +159,8 @@ public class ShowModuleTests {
_showModule.set(showOperation);
_showModule.onUnityAdsShowClick(showOperation.getId());
TestUtilities.SleepCurrentThread(uiThreadDelay);
Mockito.verify(_showListenerMock, times(1)).onUnityAdsShowClick(placementId);
Mockito.verify(_showListenerMock, timeout(maxWaitTime).times(1)).onUnityAdsShowClick(placementId);
}
@Test
@ -181,7 +169,6 @@ public class ShowModuleTests {
ShowOperation showOperation = new ShowOperation(showOperationState, mock(IWebViewBridgeInvocation.class));
_showModule.onUnityAdsShowClick(showOperation.getId());
TestUtilities.SleepCurrentThread(uiThreadDelay);
}
@Test
@ -191,9 +178,8 @@ public class ShowModuleTests {
_showModule.set(showOperation);
_showModule.onUnityAdsShowComplete(showOperation.getId(), UnityAds.UnityAdsShowCompletionState.COMPLETED);
TestUtilities.SleepCurrentThread(uiThreadDelay);
Mockito.verify(_showListenerMock, times(1)).onUnityAdsShowComplete(placementId, UnityAds.UnityAdsShowCompletionState.COMPLETED);
Mockito.verify(_showListenerMock, timeout(maxWaitTime).times(1)).onUnityAdsShowComplete(placementId, UnityAds.UnityAdsShowCompletionState.COMPLETED);
}
@Test
@ -202,6 +188,5 @@ public class ShowModuleTests {
ShowOperation showOperation = new ShowOperation(showOperationState, mock(IWebViewBridgeInvocation.class));
_showModule.onUnityAdsShowComplete(showOperation.getId(), UnityAds.UnityAdsShowCompletionState.COMPLETED);
TestUtilities.SleepCurrentThread(uiThreadDelay);
}
}

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

@ -1,177 +0,0 @@
package com.unity3d.ads.test.instrumentation.services.ads.properties;
import androidx.test.rule.ActivityTestRule;
import com.unity3d.ads.IUnityAdsListener;
import com.unity3d.ads.UnityAds;
import com.unity3d.ads.properties.AdsProperties;
import com.unity3d.ads.test.instrumentation.InstrumentationTestActivity;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mockito;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public class AdsPropertiesTests {
@Rule
public final ActivityTestRule<InstrumentationTestActivity> _activityRule = new ActivityTestRule<>(InstrumentationTestActivity.class);
@Before
public void before() {
for (IUnityAdsListener listener : AdsProperties.getListeners()) {
AdsProperties.removeListener(listener);
}
AdsProperties.setListener(null);
}
@Test
public void testSetListener() {
IUnityAdsListener listener = Mockito.mock(IUnityAdsListener.class);
AdsProperties.setListener(listener);
// test listener set
assertEquals(listener, AdsProperties.getListener());
// test that getListeners includes listener from set
assertTrue(AdsProperties.getListeners().contains(listener));
assertEquals(1, AdsProperties.getListeners().size());
}
@Test
public void testGetListener() {
// should be null when no listener is set
assertNull(AdsProperties.getListener());
}
@Test
public void testAddListener() {
IUnityAdsListener listener = Mockito.mock(IUnityAdsListener.class);
AdsProperties.addListener(listener);
Set<IUnityAdsListener> listeners = AdsProperties.getListeners();
assertEquals(1, listeners.size());
assertTrue(listeners.contains(listener));
}
@Test
public void testAddMultipleListener() {
IUnityAdsListener listener1 = Mockito.mock(IUnityAdsListener.class);
IUnityAdsListener listener2 = Mockito.mock(IUnityAdsListener.class);
AdsProperties.addListener(listener1);
AdsProperties.addListener(listener2);
Set<IUnityAdsListener> listeners = AdsProperties.getListeners();
assertEquals(2, listeners.size());
assertTrue(listeners.contains(listener1));
assertTrue(listeners.contains(listener2));
}
@Test
public void testRemoveListener() {
IUnityAdsListener listener = Mockito.mock(IUnityAdsListener.class);
AdsProperties.addListener(listener);
Set<IUnityAdsListener> listeners = AdsProperties.getListeners();
assertEquals(1, listeners.size());
assertTrue(listeners.contains(listener));
AdsProperties.removeListener(listener);
listeners = AdsProperties.getListeners();
assertEquals(0, listeners.size());
assertFalse(listeners.contains(listener));
}
@Test
public void testRemoveDuringIteration() {
IUnityAdsListener listener1 = Mockito.mock(IUnityAdsListener.class);
IUnityAdsListener listener2 = Mockito.mock(IUnityAdsListener.class);
AdsProperties.addListener(listener1);
AdsProperties.addListener(listener2);
Set<IUnityAdsListener> listeners = AdsProperties.getListeners();
try {
for (IUnityAdsListener listener : listeners) {
AdsProperties.removeListener(listener);
}
assertTrue(true);
} catch (Exception e) {
fail("An exception should not be thrown");
}
}
@Test
public void testInitializeMultipleListeners() {
IUnityAdsListener listener1 = Mockito.mock(IUnityAdsListener.class);
IUnityAdsListener listener2 = Mockito.mock(IUnityAdsListener.class);
UnityAds.initialize(_activityRule.getActivity(), "14851", listener1);
UnityAds.initialize(_activityRule.getActivity(), "14851", listener2);
assertEquals(2, AdsProperties.getListeners().size());
assertTrue(AdsProperties.getListeners().contains(listener1));
assertTrue(AdsProperties.getListeners().contains(listener2));
assertTrue(AdsProperties.getListener().equals(listener1));
}
@Test
public void testWrappingFirstListener() {
IUnityAdsListener listener1 = Mockito.mock(IUnityAdsListener.class);
IUnityAdsListener listener2 = Mockito.mock(IUnityAdsListener.class);
IUnityAdsListener listener3 = Mockito.mock(IUnityAdsListener.class);
// Initialize with first listener
UnityAds.initialize(_activityRule.getActivity(), "14851", listener1);
assertEquals(1, AdsProperties.getListeners().size());
assertTrue(UnityAds.getListener().equals(listener1));
// Replace listener from initialize
UnityAds.setListener(listener2);
assertEquals(1, AdsProperties.getListeners().size());
assertTrue(UnityAds.getListener().equals(listener2));
assertTrue(AdsProperties.getListeners().contains(listener2));
assertFalse(AdsProperties.getListeners().contains(listener1));
// Add another listener that should only be added
UnityAds.addListener(listener3);
assertTrue(UnityAds.getListener().equals(listener2));
assertEquals(2, AdsProperties.getListeners().size());
assertFalse(AdsProperties.getListeners().contains(listener1));
assertTrue(AdsProperties.getListeners().contains(listener2));
assertTrue(AdsProperties.getListeners().contains(listener3));
}
@Test
public void testSetOverwriteInit() {
IUnityAdsListener listener1 = Mockito.mock(IUnityAdsListener.class);
IUnityAdsListener listener2 = Mockito.mock(IUnityAdsListener.class);
IUnityAdsListener listener3 = Mockito.mock(IUnityAdsListener.class);
UnityAds.initialize(_activityRule.getActivity(), "14851", listener1);
UnityAds.setListener(listener2);
UnityAds.initialize(_activityRule.getActivity(), "14851", listener3);
assertEquals(2, AdsProperties.getListeners().size());
assertFalse(AdsProperties.getListeners().contains(listener1));
assertTrue(AdsProperties.getListeners().contains(listener2));
assertTrue(AdsProperties.getListeners().contains(listener3));
}
}

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

@ -50,7 +50,7 @@ public class BannerIntegrationTest {
}
};
InitializationNotificationCenter.getInstance().addListener(initializationListener);
UnityAds.initialize(_activityRule.getActivity(), "14851", null, true, true);
UnityAds.initialize(_activityRule.getActivity(), "14851", true);
initializeSemaphore.acquire();
}

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

@ -7,9 +7,6 @@ import android.os.Looper;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.unity3d.ads.IUnityAdsListener;
import com.unity3d.ads.UnityAds;
import com.unity3d.ads.properties.AdsProperties;
import com.unity3d.services.core.properties.ClientProperties;
import org.junit.Before;
@ -17,9 +14,6 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.Arrays;
import java.util.HashSet;
import static org.junit.Assert.*;
@RunWith(AndroidJUnit4.class)
@ -35,13 +29,6 @@ public class ClientPropertiesTest {
ClientProperties.setApplicationContext(null);
ClientProperties.setActivity(null);
ClientProperties.setGameId(null);
this.removeListeners();
}
private void removeListeners() {
for (IUnityAdsListener listener : AdsProperties.getListeners()) {
AdsProperties.removeListener(listener);
}
}
@Test
@ -76,31 +63,6 @@ public class ClientPropertiesTest {
assertEquals("GameID was not the same as expected", gameId, ClientProperties.getGameId());
}
@Test
public void testSetListener () {
IUnityAdsListener listener = new IUnityAdsListener() {
@Override
public void onUnityAdsReady(String placementId) {
// Testing, do nothing
}
@Override
public void onUnityAdsStart(String placementId) {
// Testing, do nothing
}
@Override
public void onUnityAdsFinish(String placementId, UnityAds.FinishState result) {
// Testing, do nothing
}
@Override
public void onUnityAdsError(UnityAds.UnityAdsError error, String message) {
// Testing, do nothing
}
};
AdsProperties.addListener(listener);
assertEquals("Listener was not the same as expected", new HashSet<>(Arrays.asList(listener)), AdsProperties.getListeners());
}
public class MockActivity extends Activity {
public MockActivity() {

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

@ -1,80 +0,0 @@
package com.unity3d.ads.test.legacy;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.unity3d.ads.UnityAds;
import com.unity3d.services.ads.placement.Placement;
import com.unity3d.services.core.properties.SdkProperties;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@RunWith(AndroidJUnit4.class)
public class PlacementTest {
@Test
public void testReset() {
SdkProperties.setInitialized(false);
Placement.reset();
assertFalse("Placement reset test: default placement isReady not false", Placement.isReady());
assertFalse("Placement reset test: random placement isReady not false", Placement.isReady("1234"));
assertEquals("Placement reset test: default placement getPlacementState is not NOT_AVAILABLE", Placement.getPlacementState(), UnityAds.PlacementState.NOT_AVAILABLE);
assertEquals("Placement reset test: random placement getPlacementState is not NOT_AVAILABLE", Placement.getPlacementState("1234"), UnityAds.PlacementState.NOT_AVAILABLE);
assertNull("Placement reset test: default placement defined after reset", Placement.getDefaultPlacement());
}
@Test
public void testDefaultPlacement() {
String testPlacement = "testPlacement";
Placement.reset();
SdkProperties.setInitialized(true);
assertFalse("Default placement test: default placement ready when not configured", UnityAds.isReady());
assertEquals("Default placement test: default placement state is not NOT_AVAILABLE when not configured", UnityAds.getPlacementState(), UnityAds.PlacementState.NOT_AVAILABLE);
Placement.setDefaultPlacement("testPlacement");
assertEquals("Default placement test: placement names do not match", testPlacement, Placement.getDefaultPlacement());
Placement.setPlacementState(testPlacement, UnityAds.PlacementState.WAITING.name());
assertFalse("Default placement test: placement is ready when it should not be ready due to waiting state", UnityAds.isReady());
assertEquals("Default placement test: placement is not waiting", UnityAds.getPlacementState(), UnityAds.PlacementState.WAITING);
Placement.setPlacementState(testPlacement, UnityAds.PlacementState.READY.name());
assertTrue("Default placement test: placement is not ready", UnityAds.isReady());
assertEquals("Default placement test: placement status is not ready", UnityAds.getPlacementState(), UnityAds.PlacementState.READY);
}
public void testCustomPlacement() {
String customPlacement = "customPlacement";
Placement.reset();
SdkProperties.setInitialized(true);
assertFalse("Custom placement test: placement is ready before placement configuration", UnityAds.isReady(customPlacement));
assertEquals("Custom placement test: placement state is not NOT_AVAILABLE before placement configuration", UnityAds.getPlacementState(customPlacement), UnityAds.PlacementState.NOT_AVAILABLE);
Placement.setPlacementState(customPlacement, UnityAds.PlacementState.DISABLED.name());
assertFalse("Custom placement test: placement is ready but placement state disabled means placement should not be ready", UnityAds.isReady(customPlacement));
assertEquals("Custom placement test: placement state is not DISABLED after disabling", UnityAds.getPlacementState(customPlacement), UnityAds.PlacementState.DISABLED);
Placement.setPlacementState(customPlacement, UnityAds.PlacementState.NO_FILL.name());
assertFalse("Custom placement test: placement is ready but placement state no fill means placement should not be ready", UnityAds.isReady(customPlacement));
assertEquals("Custom placement test: placement state is not NO_FILL after set to no fill", UnityAds.getPlacementState(customPlacement), UnityAds.PlacementState.NO_FILL);
Placement.setPlacementState(customPlacement, UnityAds.PlacementState.WAITING.name());
assertFalse("Custom placement test: placement is ready but placement state waiting means placement should not be ready", UnityAds.isReady(customPlacement));
assertEquals("Custom placement test: placement state is not WAITING after set to waiting", UnityAds.getPlacementState(customPlacement), UnityAds.PlacementState.WAITING);
Placement.setPlacementState(customPlacement, UnityAds.PlacementState.READY.name());
assertTrue("Custom placement test: placement is not ready but placement state ready means placement should be ready", UnityAds.isReady(customPlacement));
assertEquals("Custom placement test: placement state is not READY after set to ready", UnityAds.getPlacementState(customPlacement), UnityAds.PlacementState.READY);
}
}

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

@ -22,12 +22,6 @@ public class PublicApiTest {
assertTrue("Public API SDK version is null", UnityAds.getVersion() != null);
}
@Test
public void testIsReady() {
assertFalse("Public API default placement ready before init", UnityAds.isReady());
assertFalse("Public API non-existing placement ready", UnityAds.isReady("nonExistingPlacement"));
}
@Test
public void testDebugMode() {
UnityAds.setDebugMode(false);

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

@ -1,43 +0,0 @@
package com.unity3d.services.monetization.core.api;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.unity3d.services.monetization.placementcontent.core.PlacementContent;
import com.unity3d.services.core.webview.bridge.WebViewCallback;
import com.unity3d.services.monetization.core.placementcontent.PlacementContentResultFactory;
import com.unity3d.services.monetization.core.utilities.JSONUtilities;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@RunWith(AndroidJUnit4.class)
public class PlacementContentsTest {
@Test
public void createPlacementContentShouldCreateAPlacementContentAndPlaceItIntoThePlacementContentsMap() throws Exception {
WebViewCallback callback = mock(WebViewCallback.class);
PlacementContents.createPlacementContent(Fixture.placementID, JSONUtilities.mapToJsonObject(Fixture.params), callback);
verify(callback).invoke();
PlacementContent placementContent = com.unity3d.services.monetization.core.placementcontent.PlacementContents.getPlacementContent(Fixture.placementID);
assertNotNull("PlacementContent was null", placementContent);
assertEquals("Types were different", placementContent.getType(), "SHOW_AD");
}
private static class Fixture {
public static String placementID = "myPlacement";
public static Map<String, Object> params = new HashMap<>();
static {
params.put("type", PlacementContentResultFactory.PlacementContentResultType.SHOW_AD);
params.put("foo", "Bar");
}
}
}

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

@ -1,219 +0,0 @@
package com.unity3d.services.purchasing.core.api;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.unity3d.services.purchasing.core.IPurchasingAdapter;
import com.unity3d.services.purchasing.core.IRetrieveProductsListener;
import com.unity3d.services.purchasing.core.ITransactionListener;
import com.unity3d.services.purchasing.core.Product;
import com.unity3d.services.purchasing.core.Store;
import com.unity3d.services.purchasing.core.TransactionDetails;
import com.unity3d.services.purchasing.core.TransactionDetailsUtilities;
import com.unity3d.services.purchasing.core.TransactionError;
import com.unity3d.services.core.webview.WebViewApp;
import com.unity3d.services.core.webview.bridge.WebViewCallback;
import com.unity3d.services.purchasing.core.TransactionErrorDetails;
import com.unity3d.services.purchasing.core.TransactionErrorDetailsUtilities;
import com.unity3d.services.purchasing.core.properties.ClientProperties;
import com.unity3d.services.purchasing.core.PurchasingEvent;
import com.unity3d.services.monetization.core.utilities.JSONUtilities;
import com.unity3d.services.monetization.core.webview.WebViewEventCategory;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatcher;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@RunWith(AndroidJUnit4.class)
public class CustomPurchasingTest {
private IPurchasingAdapter purchasingAdapter;
private WebViewApp webViewApp;
@Before
public void setUp() {
purchasingAdapter = mock(IPurchasingAdapter.class);
webViewApp = mock(WebViewApp.class);
ClientProperties.setAdapter(purchasingAdapter);
WebViewApp.setCurrentApp(webViewApp);
}
@After
public void tearDown() {
ClientProperties.setAdapter(null);
WebViewApp.setCurrentApp(null);
}
@Test
public void availableShouldReturnTrueIfPurchasingAdapterIsSet() {
WebViewCallback callback = mock(WebViewCallback.class);
CustomPurchasing.available(callback);
verify(callback).invoke(true);
}
@Test
public void availableShouldReturnFalseIfPurchasingAdapterIsNotSet() {
WebViewCallback callback = mock(WebViewCallback.class);
ClientProperties.setAdapter(null);
CustomPurchasing.available(callback);
verify(callback).invoke(false);
}
@Test
public void retrieveCatalogsShouldCallThePurchasingAdapter() {
WebViewCallback callback = mock(WebViewCallback.class);
CustomPurchasing.refreshCatalog(callback);
verify(callback).invoke();
verify(purchasingAdapter).retrieveProducts(any(IRetrieveProductsListener.class));
}
@Test
public void retrieveCatalogShouldSendCatalogEventToWebView() {
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
IRetrieveProductsListener listener = invocation.getArgument(0);
listener.onProductsRetrieved(Fixture.products);
return null;
}
}).when(purchasingAdapter).retrieveProducts(any(IRetrieveProductsListener.class));
WebViewCallback callback = mock(WebViewCallback.class);
CustomPurchasing.refreshCatalog(callback);
verify(webViewApp).sendEvent(eq(WebViewEventCategory.CUSTOM_PURCHASING),
eq(PurchasingEvent.PRODUCTS_RETRIEVED),
argThat(new JsonArrayMatcher(CustomPurchasing.getJSONArrayFromProductList(Fixture.products))));
}
@Test
public void purchaseItemShouldCallThePurchasingAdapter() {
WebViewCallback callback = mock(WebViewCallback.class);
CustomPurchasing.purchaseItem(Fixture.productID, Fixture.purchaseExtras, callback);
verify(purchasingAdapter).onPurchase(eq(Fixture.productID), any(ITransactionListener.class), eq(JSONUtilities.jsonObjectToMap(Fixture.purchaseExtras)));
}
@Test
public void onTransactionCompleteShouldSendTransactionCompleteEventToWebView() {
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
ITransactionListener listener = invocation.getArgument(1);
listener.onTransactionComplete(Fixture.transactionDetails);
return null;
}
}).when(purchasingAdapter).onPurchase(eq(Fixture.productID), any(ITransactionListener.class), eq(JSONUtilities.jsonObjectToMap(Fixture.purchaseExtras)));
WebViewCallback callback = mock(WebViewCallback.class);
CustomPurchasing.purchaseItem(Fixture.productID, Fixture.purchaseExtras, callback);
verify(webViewApp).sendEvent(eq(WebViewEventCategory.CUSTOM_PURCHASING),
eq(PurchasingEvent.TRANSACTION_COMPLETE),
argThat(new JsonObjectMatcher(TransactionDetailsUtilities.getJSONObjectForTransactionDetails(Fixture.transactionDetails))));
}
@Test
public void onTransactionErrorShouldSendTransactionErrorEventToWebView() {
final TransactionErrorDetails detail = TransactionErrorDetails.newBuilder()
.withStore(Store.GOOGLE_PLAY)
.withTransactionError(TransactionError.ITEM_UNAVAILABLE)
.withExceptionMessage("test exception")
.withStoreSpecificErrorCode("google failed")
.build();
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
ITransactionListener listener = invocation.getArgument(1);
listener.onTransactionError(detail);
return null;
}
}).when(purchasingAdapter).onPurchase(eq(Fixture.productID), any(ITransactionListener.class), eq(JSONUtilities.jsonObjectToMap(Fixture.purchaseExtras)));
WebViewCallback callback = mock(WebViewCallback.class);
CustomPurchasing.purchaseItem(Fixture.productID, Fixture.purchaseExtras, callback);
;
verify(webViewApp).sendEvent(eq(WebViewEventCategory.CUSTOM_PURCHASING),
eq(PurchasingEvent.TRANSACTION_ERROR),
argThat(new JsonObjectMatcher(TransactionErrorDetailsUtilities.getJSONObjectForTransactionErrorDetails(detail))));
}
private static class Fixture {
public static String productID = "DEADBEEF-BEEFCACE";
public static List<Product> products;
public static JSONObject purchaseExtras;
public static TransactionDetails transactionDetails;
public static TransactionError transactionError = TransactionError.UNKNOWN_ERROR;
public static String transactionErrorMessage = "Someone set us up the bomb.";
static {
products = new ArrayList<>();
products.add(Product.newBuilder()
.withProductId("DEADBEEF-BEEFCACE")
.withLocalizedTitle("Sword of a Thousand Truths")
.withLocalizedPriceString("$9000.00")
.build());
purchaseExtras = new JSONObject();
try {
purchaseExtras.put("foo", "Bar");
} catch (JSONException e) {
e.printStackTrace();
}
transactionDetails = TransactionDetails.newBuilder()
.withProductId("foo")
.withTransactionId("abcd1234")
.withCurrency("USD")
.withPrice(new BigDecimal(23))
.withReceipt("Receipt=True")
.putExtra("foo", "bar")
.build();
}
}
private static class JsonArrayMatcher implements ArgumentMatcher<JSONArray> {
private final JSONArray src;
private JsonArrayMatcher(JSONArray src) {
this.src = src;
}
@Override
public boolean matches(JSONArray o) {
return src.toString().equals(o.toString());
}
}
private static class JsonObjectMatcher implements ArgumentMatcher<JSONObject> {
private final JSONObject src;
private JsonObjectMatcher(JSONObject src) {
this.src = src;
}
@Override
public boolean matches(JSONObject o) {
return src.toString().equals(o.toString());
}
}
}

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

@ -1,40 +0,0 @@
package com.unity3d.ads;
public interface IUnityAdsListener {
/**
* Callback that tells placement is ready to show ads. After this callback you can call UnityAds.show method for this placement.
* Note that sometimes placement might no longer be ready due to exceptional reasons. These situations will give no new callbacks.
* To avoid error situations, it is always best to check isReady method status before calling show.
*
* @param placementId Placement, as defined in Unity Ads admin tools
*/
void onUnityAdsReady(String placementId);
/**
* Callback for a successful start of advertisement after UnityAds.show. If there are errors in advertisement start,
* Unity Ads might never call this method. Instead Unity Ads will directly call onUnityAdsFinish with error status.
*
* @param placementId Placement, as defined in Unity Ads admin tools
*/
void onUnityAdsStart(String placementId);
/**
* Callback after advertisement has closed.
* Each call to UnityAds.show is guaranteed to give this callback even in all failure scenarios.
*
* @param placementId Placement, as defined in Unity Ads admin tools
* @param result If FinishState.COMPLETED, advertisement was watched to the end without skipping.
* If FinishState.SKIPPED, advertisement was skipped.
* If FinishState.ERROR, there was a technical error that prevented Unity Ads from showing ads.
*/
void onUnityAdsFinish(String placementId, UnityAds.FinishState result);
/**
* Callback for different errors in Unity Ads. All errors will be logged but this method can be used as
* additional debugging aid. This callback can also be used for collecting statistics from different error scenarios.
*
* @param error Error category
* @param message Human-readable error message
*/
void onUnityAdsError(UnityAds.UnityAdsError error, String message);
}

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

@ -8,54 +8,7 @@ import com.unity3d.services.ads.UnityAdsImplementation;
import com.unity3d.services.core.log.DeviceLog;
public final class UnityAds {
/**
* An enumeration for the completion state of an ad.
*/
public enum FinishState {
/**
* A state that indicates that the ad did not successfully display.
*/
ERROR,
/**
* A state that indicates that the user skipped the ad.
*/
SKIPPED,
/**
* A state that indicates that the ad was played entirely.
*/
COMPLETED
}
/**
* Describes state of Unity Ads placements. All placement states other than READY imply that placement is not currently ready to show ads.
*/
public enum PlacementState {
/**
* Placement is ready to show ads. You can call show method and ad unit will open.
*/
READY,
/**
* Current placement state is not available. SDK is not initialized or this placement has not been configured in Unity Ads admin tools.
*/
NOT_AVAILABLE,
/**
* Placement is disabled. Placement can be enabled via Unity Ads admin tools.
*/
DISABLED,
/**
* Placement is not yet ready but it will be ready in the future. Most likely reason is caching.
*/
WAITING,
/**
* Placement is properly configured but there are currently no ads available for the placement.
*/
NO_FILL
}
public enum UnityAdsShowCompletionState {
/**
* A state that indicates that the user skipped the ad.
@ -67,19 +20,6 @@ public final class UnityAds {
COMPLETED
}
public enum UnityAdsError {
NOT_INITIALIZED,
INITIALIZE_FAILED,
INVALID_ARGUMENT,
VIDEO_PLAYER_ERROR,
INIT_SANITY_CHECK_FAIL,
AD_BLOCKER_DETECTED,
FILE_IO_ERROR,
DEVICE_ID_ERROR,
SHOW_ERROR,
INTERNAL_ERROR
}
/**
* Enumeration of UnityAds initialization errors.
*/
@ -140,7 +80,7 @@ public final class UnityAds {
NOT_INITIALIZED,
/**
* Error related to placement not being ready
* Error related to placement not being ready
*/
NOT_READY,
@ -170,141 +110,6 @@ public final class UnityAds {
INTERNAL_ERROR,
}
/**
* Initializes Unity Ads. Unity Ads should be initialized when app starts.
*
* @param activity Current Android activity of calling app
* @param gameId Unique identifier for a game, given by Unity Ads admin tools or Unity editor
* @param listener Listener for IUnityAdsListener callbacks
* @deprecated this method is deprecated in favor of {@link #initialize(Context, String)} use {@link #addListener(IUnityAdsListener)} to add a listener and use Application Context
*/
@Deprecated
public static void initialize(final Activity activity, final String gameId, final IUnityAdsListener listener) {
boolean testMode = false;
boolean usePerPlacementLoad = false;
initialize(activity, gameId, listener, testMode, usePerPlacementLoad, null);
}
/**
* Initializes Unity Ads. Unity Ads should be initialized when app starts.
*
* @param activity Current Android activity of calling app
* @param gameId Unique identifier for a game, given by Unity Ads admin tools or Unity editor
* @deprecated this method is deprecated in favor of {@link #initialize(Context, String)} use Application Context
*/
@Deprecated
public static void initialize(final Activity activity, final String gameId) {
boolean testMode = false;
boolean usePerPlacementLoad = false;
initialize(activity, gameId, null, testMode, usePerPlacementLoad, null);
}
/**
* Initializes Unity Ads. Unity Ads should be initialized when app starts.
*
* @param activity Current Android activity of calling app
* @param gameId Unique identifier for a game, given by Unity Ads admin tools or Unity editor
* @param initializationListener Listener for IUnityAdsInitializationListener callbacks
* @deprecated this method is deprecated in favor of {@link #initialize(Context, String, IUnityAdsInitializationListener)} use Application Context
*/
@Deprecated
public static void initialize(final Activity activity, final String gameId, final IUnityAdsInitializationListener initializationListener) {
boolean testMode = false;
boolean usePerPlacementLoad = false;
initialize(activity, gameId, null, testMode, usePerPlacementLoad, initializationListener);
}
/**
* Initializes Unity Ads. Unity Ads should be initialized when app starts.
*
* @param activity Current Android activity of calling app
* @param gameId Unique identifier for a game, given by Unity Ads admin tools or Unity editor
* @param listener Listener for IUnityAdsListener callbacks
* @param testMode If true, only test ads are shown
* @deprecated this method is deprecated in favor of {@link #initialize(Context, String, boolean)} use {@link #addListener(IUnityAdsListener)} to add a listener and use Application Context
*/
@Deprecated
public static void initialize(final Activity activity, final String gameId, final IUnityAdsListener listener, final boolean testMode) {
boolean usePerPlacementLoad = false;
initialize(activity, gameId, listener, testMode, usePerPlacementLoad, null);
}
/**
* Initializes Unity Ads. Unity Ads should be initialized when app starts.
*
* @param activity Current Android activity of calling app
* @param gameId Unique identifier for a game, given by Unity Ads admin tools or Unity editor
* @param testMode If true, only test ads are shown
* @deprecated this method is deprecated in favor of {@link #initialize(Context, String, boolean)} use Application Context
*/
@Deprecated
public static void initialize(final Activity activity, final String gameId, final boolean testMode) {
boolean usePerPlacementLoad = false;
initialize(activity, gameId, null, testMode, usePerPlacementLoad, null);
}
/**
* Initializes Unity Ads. Unity Ads should be initialized when app starts.
*
* @param activity Current Android activity of calling app
* @param gameId Unique identifier for a game, given by Unity Ads admin tools or Unity editor
* @param testMode If true, only test ads are shown
* @param initializationListener Listener for IUnityAdsInitializationListener callbacks
* @deprecated this method is deprecated in favor of {@link #initialize(Context, String, boolean, IUnityAdsInitializationListener)} use Application context
*/
@Deprecated
public static void initialize(final Activity activity, final String gameId, final boolean testMode, final IUnityAdsInitializationListener initializationListener) {
boolean usePerPlacementLoad = false;
initialize(activity, gameId, null, testMode, usePerPlacementLoad, initializationListener);
}
/**
* Initializes Unity Ads. Unity Ads should be initialized when app starts.
* Note: The `load` API is in closed beta and available upon invite only. If you would like to be considered for the beta, please contact Unity Ads Support.
*
* @param activity Current Android activity of calling app
* @param gameId Unique identifier for a game, given by Unity Ads admin tools or Unity editor
* @param listener Listener for IUnityAdsListener callbacks
* @param testMode If true, only test ads are shown
* @param enablePerPlacementLoad Set this flag to `YES` to disable automatic placement caching. When this is enabled, developer must call `load` on placements before calling show
* @deprecated this method is deprecated in favor of {@link #initialize(Context, String, boolean, boolean)} use {@link #addListener(IUnityAdsListener)} to add a listener and use Application Context
*/
@Deprecated
public static void initialize(final Activity activity, final String gameId, final IUnityAdsListener listener, final boolean testMode, final boolean enablePerPlacementLoad) {
initialize(activity, gameId, listener, testMode, enablePerPlacementLoad, null);
}
/**
* Initializes Unity Ads. Unity Ads should be initialized when app starts.
* Note: The `load` API is in closed beta and available upon invite only. If you would like to be considered for the beta, please contact Unity Ads Support.
*
* @param activity Current Android activity of calling app
* @param gameId Unique identifier for a game, given by Unity Ads admin tools or Unity editor
* @param testMode If true, only test ads are shown
* @param enablePerPlacementLoad Set this flag to `YES` to disable automatic placement caching. When this is enabled, developer must call `load` on placements before calling show
* @deprecated this method is deprecated in favor of {@link #initialize(Context, String, boolean, boolean)} use Application Context
*/
@Deprecated
public static void initialize(final Activity activity, final String gameId, final boolean testMode, final boolean enablePerPlacementLoad) {
initialize(activity, gameId, null, testMode, enablePerPlacementLoad, null);
}
/**
* Initializes Unity Ads. Unity Ads should be initialized when app starts.
* Note: The `load` API is in closed beta and available upon invite only. If you would like to be considered for the beta, please contact Unity Ads Support.
*
* @param activity Current Android activity of calling app
* @param gameId Unique identifier for a game, given by Unity Ads admin tools or Unity editor
* @param testMode If true, only test ads are shown
* @param enablePerPlacementLoad Set this flag to `YES` to disable automatic placement caching. When this is enabled, developer must call `load` on placements before calling show
* @param initializationListener Listener for IUnityAdsInitializationListener callbacks
* @deprecated this method is deprecated in favor of {@link #initialize(Context, String, boolean, boolean, IUnityAdsInitializationListener)} use Application Context
*/
@Deprecated
public static void initialize(final Activity activity, final String gameId, final boolean testMode, final boolean enablePerPlacementLoad, final IUnityAdsInitializationListener initializationListener) {
initialize(activity, gameId, null, testMode, enablePerPlacementLoad, initializationListener);
}
/**
* Initializes Unity Ads. Unity Ads should be initialized when app starts.
*
@ -313,8 +118,7 @@ public final class UnityAds {
*/
public static void initialize(final Context context, final String gameId) {
boolean testMode = false;
boolean usePerPlacementLoad = false;
UnityAdsImplementation.initialize(context, gameId, null, testMode, usePerPlacementLoad, null);
UnityAdsImplementation.initialize(context, gameId, testMode, null);
}
/**
@ -326,8 +130,7 @@ public final class UnityAds {
*/
public static void initialize(final Context context, final String gameId, final IUnityAdsInitializationListener initializationListener) {
boolean testMode = false;
boolean usePerPlacementLoad = false;
UnityAdsImplementation.initialize(context, gameId, null, testMode, usePerPlacementLoad, initializationListener);
UnityAdsImplementation.initialize(context, gameId, testMode, initializationListener);
}
/**
@ -338,8 +141,7 @@ public final class UnityAds {
* @param testMode If true, only test ads are shown
*/
public static void initialize(final Context context, final String gameId, final boolean testMode) {
boolean usePerPlacementLoad = false;
UnityAdsImplementation.initialize(context, gameId, null, testMode, usePerPlacementLoad, null);
UnityAdsImplementation.initialize(context, gameId, testMode, null);
}
/**
@ -351,35 +153,7 @@ public final class UnityAds {
* @param initializationListener Listener for IUnityAdsInitializationListener callbacks
*/
public static void initialize(final Context context, final String gameId, final boolean testMode, final IUnityAdsInitializationListener initializationListener) {
boolean usePerPlacementLoad = false;
UnityAdsImplementation.initialize(context, gameId, null, testMode, usePerPlacementLoad, initializationListener);
}
/**
* Initializes Unity Ads. Unity Ads should be initialized when app starts.
* Note: The `load` API is in closed beta and available upon invite only. If you would like to be considered for the beta, please contact Unity Ads Support.
*
* @param context Current Android context of calling app in favor of Application Context
* @param gameId Unique identifier for a game, given by Unity Ads admin tools or Unity editor
* @param testMode If true, only test ads are shown
* @param enablePerPlacementLoad Set this flag to `YES` to disable automatic placement caching. When this is enabled, developer must call `load` on placements before calling show
*/
public static void initialize(final Context context, final String gameId, final boolean testMode, final boolean enablePerPlacementLoad) {
UnityAdsImplementation.initialize(context, gameId, null, testMode, enablePerPlacementLoad, null);
}
/**
* Initializes Unity Ads. Unity Ads should be initialized when app starts.
* Note: The `load` API is in closed beta and available upon invite only. If you would like to be considered for the beta, please contact Unity Ads Support.
*
* @param context Current Android context of calling app in favor of Application Context
* @param gameId Unique identifier for a game, given by Unity Ads admin tools or Unity editor
* @param testMode If true, only test ads are shown
* @param enablePerPlacementLoad Set this flag to `YES` to disable automatic placement caching. When this is enabled, developer must call `load` on placements before calling show
* @param initializationListener Listener for IUnityAdsInitializationListener callbacks
*/
public static void initialize(final Context context, final String gameId, final boolean testMode, final boolean enablePerPlacementLoad, final IUnityAdsInitializationListener initializationListener) {
UnityAdsImplementation.initialize(context, gameId, null, testMode, enablePerPlacementLoad, initializationListener);
UnityAdsImplementation.initialize(context, gameId, testMode, initializationListener);
}
/**
@ -391,51 +165,6 @@ public final class UnityAds {
return UnityServices.isInitialized();
}
/**
* Set listener for IUnityAdsListener callbacks. Use this if only ever using one listener.
* This overwrites the previous set listener.
*
* @param listener New listener for IUnityAdsListener callbacks
*
* @deprecated this method is deprecated in favor of {@link #addListener(IUnityAdsListener)}
*/
@Deprecated
public static void setListener(IUnityAdsListener listener) {
UnityAdsImplementation.setListener(listener);
}
/**
* Get current listener for IUnityAdsListener callbacks. Returns the most recent listener set through setListener
* or the listener from the first initialize
*
* @return Return IUnityAdsListener that was set from setListener
*
* @deprecated this method is deprecated in favor of {@link #addListener(IUnityAdsListener)} and {@link #removeListener(IUnityAdsListener)}
*/
@Deprecated
public static IUnityAdsListener getListener() {
return UnityAdsImplementation.getListener();
}
/**
* Add listener for IUnityAdsListener callbacks. Use this if subscribing multiple listeners.
* It is not recommended to mix setListener with addListener
*
* @param listener New listener for IUnityAdsListener callbacks
*/
public static void addListener(IUnityAdsListener listener) {
UnityAdsImplementation.addListener(listener);
}
/**
* Remove listener for IUnityAdsListener callbacks
*
* @param listener New listener for IUnityAdsListener callbacks
*/
public static void removeListener(IUnityAdsListener listener) {
UnityAdsImplementation.removeListener(listener);
}
/**
* Checks if current device supports running Unity Ads
*
@ -454,58 +183,6 @@ public final class UnityAds {
return UnityAdsImplementation.getVersion();
}
/**
* Check if default placement is ready to show ads
*
* @return If true, default placement is ready to show ads
* @deprecated Please migrate to using load call with {@link IUnityAdsLoadListener}.
*/
@Deprecated
public static boolean isReady() {
return UnityAdsImplementation.isReady();
}
/**
* Check if placement is ready to show ads
*
* @param placementId Placement, as defined in Unity Ads admin tools
* @return If true, placement is ready to show ads
* @deprecated Please migrate to using load call with {@link IUnityAdsLoadListener}.
*/
@Deprecated
public static boolean isReady(String placementId) {
return UnityAdsImplementation.isReady(placementId);
}
/**
* Get current state of default placement
*
* @return If PlacementState.READY, default placement is ready to show ads. Other states give detailed reasons why placement is not ready.
*/
public static PlacementState getPlacementState() {
return UnityAdsImplementation.getPlacementState();
}
/**
* Get current state of a placement
*
* @param placementId Placement, as defined in Unity Ads admin tools
* @return If PlacementState.READY, placement is ready to show ads. Other states give detailed reasons why placement is not ready.
*/
public static PlacementState getPlacementState(String placementId) {
return UnityAdsImplementation.getPlacementState(placementId);
}
/**
* Show one advertisement using default placement.
*
* @param activity Current Android activity of calling app
*/
@Deprecated
public static void show(final Activity activity) {
UnityAdsImplementation.show(activity);
}
/**
* Show one advertisement with custom placement.
*
@ -571,8 +248,7 @@ public final class UnityAds {
}
/**
* Request fill for a specific placement ID. This functionality is enabled through the `enablePerPlacementLoad` in initialize.
* Note: The `load` API is in closed beta and available upon invite only. If you would like to be considered for the beta, please contact Unity Ads Support.
* Request fill for a specific placement ID.
*
* @param placementId The placement ID to be loaded.
*/
@ -592,8 +268,7 @@ public final class UnityAds {
}
/**
* Request fill for a specific placement ID. This functionality is enabled through the `enablePerPlacementLoad` in initialize.
* Note: The `load` API is in closed beta and available upon invite only. If you would like to be considered for the beta, please contact Unity Ads Support.
* Request fill for a specific placement ID.
*
* @param placementId The placement ID to be loaded.
* @param listener The listener which is going to be notified about load request result.
@ -603,8 +278,7 @@ public final class UnityAds {
}
/**
* Request fill for a specific placement ID with custom options. This functionality is enabled through the `enablePerPlacementLoad` in initialize.
* Note: The `load` API is in closed beta and available upon invite only. If you would like to be considered for the beta, please contact Unity Ads Support
* Request fill for a specific placement ID with custom options.
*
* @param placementId The placement ID to be loaded.
* @param loadOptions Custom options.
@ -621,34 +295,4 @@ public final class UnityAds {
return UnityAdsImplementation.getToken();
}
/**
* Initializes Unity Ads. Unity Ads should be initialized when app starts.
* Note: The `load` API is in closed beta and available upon invite only. If you would like to be considered for the beta, please contact Unity Ads Support.
*
* @param activity Current Android activity of calling app
* @param gameId Unique identifier for a game, given by Unity Ads admin tools or Unity editor
* @param listener Listener for IUnityAdsListener callbacks
* @param testMode If true, only test ads are shown
* @param enablePerPlacementLoad Set this flag to `YES` to disable automatic placement caching. When this is enabled, developer must call `load` on placements before calling show
* @param initializationListener Listener for IUnityAdsInitializationListener callbacks
*/
private static void initialize(final Activity activity, final String gameId, final IUnityAdsListener listener, final boolean testMode, final boolean enablePerPlacementLoad, final IUnityAdsInitializationListener initializationListener) {
DeviceLog.entered();
if (activity == null) {
DeviceLog.error("Error while initializing Unity Ads: null activity, halting Unity Ads init");
if (listener != null) {
listener.onUnityAdsError(UnityAdsError.INITIALIZE_FAILED, "Error while initializing Unity Ads: null activity");
}
if (initializationListener != null) {
initializationListener.onInitializationFailed(UnityAdsInitializationError.INVALID_ARGUMENT, "Error while initializing Unity Ads: null activity");
}
return;
}
UnityAdsImplementation.initialize(activity.getApplicationContext(), gameId, listener, testMode, enablePerPlacementLoad, initializationListener);
}
}

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

@ -1,24 +0,0 @@
package com.unity3d.ads.mediation;
import com.unity3d.ads.IUnityAdsListener;
import com.unity3d.ads.UnityAds;
public interface IUnityAdsExtendedListener extends IUnityAdsListener {
/**
* Callback for a click event.
*
* @param placementId Placement, as defined in Unity Ads admin tools
*/
void onUnityAdsClick(String placementId);
/**
* Callback for a placement state change event.
*
* @param placementId Placement, as defined in Unity Ads admin tools
* @param oldState Placement state before the change
* @param newState Placement state after the change
*/
void onUnityAdsPlacementStateChanged(String placementId, UnityAds.PlacementState oldState, UnityAds.PlacementState newState);
}

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

@ -1,54 +0,0 @@
package com.unity3d.ads.properties;
import com.unity3d.ads.IUnityAdsListener;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
public class AdsProperties {
private static IUnityAdsListener _listener = null;
private static Set<IUnityAdsListener> _listeners = Collections.synchronizedSet(new LinkedHashSet<IUnityAdsListener>());
public static void setListener(IUnityAdsListener listener) {
// cleanup possible reference in _listeners
if (_listener != null) {
_listeners.remove(_listener);
}
_listener = listener;
}
public static IUnityAdsListener getListener() {
return _listener;
}
public static void addListener(IUnityAdsListener listener) {
if (_listener == null) {
// needed to bridge set/get listener and add/remove listener
_listener = listener;
}
if (listener != null) {
if (!_listeners.contains(listener)) {
_listeners.add(listener);
}
}
}
public static Set<IUnityAdsListener> getListeners() {
LinkedHashSet<IUnityAdsListener> listeners = new LinkedHashSet<>(_listeners);
if (_listener != null) {
listeners.add(_listener);
}
return listeners;
}
public static void removeListener(IUnityAdsListener listener) {
// cleanup possible reference in _listener
if (_listener != null && _listener.equals(listener)) {
_listener = null;
}
_listeners.remove(listener);
}
}

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

@ -1,28 +0,0 @@
package com.unity3d.ads.purchasing;
public interface IPurchasing {
/**
* Called when we initialize the PurchasingAPI in the webview
*
*/
void onGetPurchasingVersion();
/**
* Called whenever the IAP catalog refreshes in the Promo Parser
*
*/
void onGetProductCatalog();
/**
* Called when an in-app purchase is initiated from an ad.
*
* @param eventString The string provided via the ad.
*/
void onPurchasingCommand(String eventString);
/**
* Called to trigger intialization of purchasing APIs
*
*/
void onInitializePurchasing();
}

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

@ -1,31 +0,0 @@
package com.unity3d.ads.purchasing;
import com.unity3d.services.core.webview.WebViewApp;
import com.unity3d.services.core.webview.WebViewEventCategory;
public class Purchasing {
public enum UnityAdsPurchasingEvent {
COMMAND,
VERSION,
CATALOG,
INITIALIZATION,
EVENT
}
public static void initialize(IPurchasing purchasingInterface) {
com.unity3d.services.ads.api.Purchasing.setPurchasingInterface(purchasingInterface);
}
public static void dispatchReturnEvent(int event, String payload) {
WebViewApp webViewApp = WebViewApp.getCurrentApp();
if (webViewApp == null || !webViewApp.isWebAppLoaded()) {
return;
}
webViewApp.sendEvent(WebViewEventCategory.PURCHASING, UnityAdsPurchasingEvent.values()[event], payload);
}
}

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

@ -1,5 +0,0 @@
package com.unity3d.ads.purchasing;
public enum PurchasingError {
PURCHASE_INTERFACE_NULL
}

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

@ -1,5 +0,0 @@
package com.unity3d.services;
public interface IUnityServicesListener {
void onUnityServicesError(UnityServices.UnityServicesError error, String message);
}

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

@ -27,12 +27,10 @@ public class UnityServices {
* Initializes Unity Ads. Unity Ads should be initialized when app starts.
* @param context Current Android application context of calling app
* @param gameId Unique identifier for a game, given by Unity Ads admin tools or Unity editor
* @param listener Listener for IUnityAdsListener callbacks
* @param testMode If true, only test ads are shown
* @param enablePerPlacementLoad If true, disables automatic requests, and allows the load() function to request placements instead
* @param initializationListener Listener for IUnityAdsInitializationListener callbacks
*/
public static void initialize(final Context context, final String gameId, final IUnityServicesListener listener, final boolean testMode, final boolean enablePerPlacementLoad, final IUnityAdsInitializationListener initializationListener) {
public static void initialize(final Context context, final String gameId, final boolean testMode, final IUnityAdsInitializationListener initializationListener) {
DeviceLog.entered();
if (SdkProperties.getCurrentInitializationState() != SdkProperties.InitializationState.NOT_INITIALIZED) {
@ -48,20 +46,12 @@ public class UnityServices {
differingParameters += createExpectedParametersString("Test Mode", previousTestMode, testMode);
}
boolean previousLoadEnabled = SdkProperties.isPerPlacementLoadEnabled();
if (previousLoadEnabled != enablePerPlacementLoad) {
differingParameters += createExpectedParametersString("Enable Per Placement Load", previousLoadEnabled, enablePerPlacementLoad);
}
if (!TextUtils.isEmpty(differingParameters)) {
String message = "Unity Ads SDK failed to initialize due to already being initialized with different parameters" + differingParameters;
DeviceLog.warning(message);
if (initializationListener != null) {
initializationListener.onInitializationFailed(UnityAds.UnityAdsInitializationError.INVALID_ARGUMENT, message);
}
if (listener != null) {
listener.onUnityServicesError(UnityServicesError.INVALID_ARGUMENT, message);
}
return;
}
}
@ -84,7 +74,6 @@ public class UnityServices {
SdkProperties.setInitializeState(SdkProperties.InitializationState.INITIALIZING);
ClientProperties.setGameId(gameId);
SdkProperties.setTestMode(testMode);
SdkProperties.setPerPlacementLoadEnabled(enablePerPlacementLoad);
if(!isSupported()) {
DeviceLog.error("Error while initializing Unity Services: device is not supported");
@ -97,31 +86,28 @@ public class UnityServices {
if(gameId == null || gameId.length() == 0) {
DeviceLog.error("Error while initializing Unity Services: empty game ID, halting Unity Ads init");
SdkProperties.notifyInitializationFailed(UnityAds.UnityAdsInitializationError.INVALID_ARGUMENT, "Unity Ads SDK failed to initialize due to empty game ID");
if(listener != null) {
listener.onUnityServicesError(UnityServicesError.INVALID_ARGUMENT, "Empty game ID");
}
return;
}
if(context == null) {
DeviceLog.error("Error while initializing Unity Services: null context, halting Unity Ads init");
SdkProperties.notifyInitializationFailed(UnityAds.UnityAdsInitializationError.INVALID_ARGUMENT, "Unity Ads SDK failed to initialize due to null context");
if(listener != null) {
listener.onUnityServicesError(UnityServicesError.INVALID_ARGUMENT, "Null context");
}
return;
}
if (context instanceof Application) {
ClientProperties.setApplication((Application) context);
} else if (context instanceof Activity) {
ClientProperties.setApplication(((Activity) context).getApplication());
if (((Activity) context).getApplication() != null) {
ClientProperties.setApplication(((Activity) context).getApplication());
} else {
DeviceLog.error("Error while initializing Unity Services: cannot retrieve application from context, halting Unity Ads init");
SdkProperties.notifyInitializationFailed(UnityAds.UnityAdsInitializationError.INVALID_ARGUMENT, "Unity Ads SDK failed to initialize due to inability to retrieve application from context");
return;
}
} else {
DeviceLog.error("Error while initializing Unity Services: invalid context, halting Unity Ads init");
SdkProperties.notifyInitializationFailed(UnityAds.UnityAdsInitializationError.INVALID_ARGUMENT, "Unity Ads SDK failed to initialize due to invalid context");
if(listener != null) {
listener.onUnityServicesError(UnityServicesError.INVALID_ARGUMENT, "Invalid context");
}
return;
}
@ -132,15 +118,18 @@ public class UnityServices {
}
SdkProperties.setDebugMode(SdkProperties.getDebugMode());
SdkProperties.setListener(listener);
ClientProperties.setApplicationContext(context.getApplicationContext());
if (context.getApplicationContext() != null) {
ClientProperties.setApplicationContext(context.getApplicationContext());
} else {
DeviceLog.error("Error while initializing Unity Services: cannot retrieve application context, halting Unity Ads init");
SdkProperties.notifyInitializationFailed(UnityAds.UnityAdsInitializationError.INVALID_ARGUMENT, "Unity Ads SDK failed to initialize due to inability to retrieve application context");
return;
}
if(!EnvironmentCheck.isEnvironmentOk()) {
DeviceLog.error("Error during Unity Services environment check, halting Unity Services init");
SdkProperties.notifyInitializationFailed(UnityAds.UnityAdsInitializationError.INTERNAL_ERROR, "Unity Ads SDK failed to initialize due to environment check failed");
if(listener != null) {
listener.onUnityServicesError(UnityServicesError.INIT_SANITY_CHECK_FAIL, "Unity Services init environment check failed");
}
return;
}
DeviceLog.info("Unity Services environment check OK");

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

@ -4,33 +4,24 @@ import android.app.Activity;
import android.content.Context;
import com.unity3d.ads.IUnityAdsInitializationListener;
import com.unity3d.ads.IUnityAdsListener;
import com.unity3d.ads.IUnityAdsLoadListener;
import com.unity3d.ads.IUnityAdsShowListener;
import com.unity3d.ads.UnityAds;
import com.unity3d.ads.UnityAdsLoadOptions;
import com.unity3d.ads.UnityAdsShowOptions;
import com.unity3d.ads.properties.AdsProperties;
import com.unity3d.services.IUnityServicesListener;
import com.unity3d.services.UnityServices;
import com.unity3d.services.ads.operation.load.LoadOperationState;
import com.unity3d.services.ads.operation.load.LoadModule;
import com.unity3d.services.ads.operation.show.ShowOperationState;
import com.unity3d.services.ads.operation.show.ShowModule;
import com.unity3d.services.ads.placement.Placement;
import com.unity3d.services.ads.token.TokenStorage;
import com.unity3d.services.core.configuration.Configuration;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.misc.Utilities;
import com.unity3d.services.core.properties.ClientProperties;
import com.unity3d.services.core.webview.WebViewApp;
import com.unity3d.services.core.webview.bridge.WebViewBridgeInvoker;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public final class UnityAdsImplementation {
static ExecutorService _showExecutorService = Executors.newSingleThreadExecutor();
private static Configuration configuration = null;
private static WebViewBridgeInvoker webViewBridgeInvoker = new WebViewBridgeInvoker();
@ -39,11 +30,11 @@ public final class UnityAdsImplementation {
*
* @param context Current Android application context of calling app
* @param gameId Unique identifier for a game, given by Unity Ads admin tools or Unity editor
* @param listener Listener for IUnityAdsListener callbacks
* @param initializationListener Listener for IUnityAdsInitializationListener callbacks
*/
public static void initialize(final Context context, final String gameId, final IUnityAdsListener listener) {
public static void initialize(final Context context, final String gameId, final IUnityAdsInitializationListener initializationListener) {
boolean testMode = false;
initialize(context, gameId, listener, testMode);
initialize(context, gameId, testMode, initializationListener);
}
/**
@ -51,42 +42,23 @@ public final class UnityAdsImplementation {
*
* @param context Current Android application context of calling app
* @param gameId Unique identifier for a game, given by Unity Ads admin tools or Unity editor
* @param listener Listener for IUnityAdsListener callbacks
* @param testMode If true, only test ads are shown
*/
public static void initialize(final Context context, final String gameId, final IUnityAdsListener listener, final boolean testMode) {
boolean usePerPlacementLoad = false;
initialize(context, gameId, listener, testMode, usePerPlacementLoad, null);
public static void initialize(final Context context, final String gameId, final boolean testMode) {
initialize(context, gameId, testMode, null);
}
/**
* Initializes Unity Ads. Unity Ads should be initialized when app starts.
* @param context Current Android application context of calling app
* @param gameId Unique identifier for a game, given by Unity Ads admin tools or Unity editor
* @param listener Listener for IUnityAdsListener callbacks
* @param testMode If true, only test ads are shown
* @param enablePerPlacementLoad Set this flag to `YES` to disable automatic placement caching. When this is enabled, developer must call `load` on placements before calling show
* @param initializationListener Listener for IUnityAdsInitializationListener callbacks
*/
public static void initialize(final Context context, final String gameId, final IUnityAdsListener listener, final boolean testMode, final boolean enablePerPlacementLoad, final IUnityAdsInitializationListener initializationListener) {
public static void initialize(final Context context, final String gameId, final boolean testMode, final IUnityAdsInitializationListener initializationListener) {
DeviceLog.entered();
UnityAdsImplementation.addListener(listener);
UnityServices.initialize(context, gameId, new IUnityServicesListener() {
@Override
public void onUnityServicesError(UnityServices.UnityServicesError error, String message) {
if (listener == null) {
return;
}
if (error == UnityServices.UnityServicesError.INIT_SANITY_CHECK_FAIL) {
listener.onUnityAdsError(UnityAds.UnityAdsError.INIT_SANITY_CHECK_FAIL, message);
}
else if (error == UnityServices.UnityServicesError.INVALID_ARGUMENT) {
listener.onUnityAdsError(UnityAds.UnityAdsError.INVALID_ARGUMENT, message);
}
}
}, testMode, enablePerPlacementLoad, initializationListener);
UnityServices.initialize(context, gameId, testMode, initializationListener);
}
/**
@ -98,45 +70,6 @@ public final class UnityAdsImplementation {
return UnityServices.isInitialized();
}
/**
* Set listener for IUnityAdsListener callbacks
*
* @param listener New listener for IUnityAdsListener callbacks
*/
@Deprecated
public static void setListener(IUnityAdsListener listener) {
AdsProperties.setListener(listener);
}
/**
* Get current listener for IUnityAdsListener callbacks. Returns the most recent listener set through setListener
* or the listener from the first initialize
*
* @return Return IUnityAdsListener that was set from setListener
*/
@Deprecated
public static IUnityAdsListener getListener() {
return AdsProperties.getListener();
}
/**
* Add listener for IUnityAdsListener callbacks
*
* @param listener New listener for IUnityAdsListener callbacks
*/
public static void addListener(IUnityAdsListener listener) {
AdsProperties.addListener(listener);
}
/**
* Remove listener for IUnityAdsListener callbacks
*
* @param listener New listener for IUnityAdsListener callbacks
*/
public static void removeListener(IUnityAdsListener listener) {
AdsProperties.removeListener(listener);
}
/**
* Checks if current device supports running Unity Ads
*
@ -155,65 +88,6 @@ public final class UnityAdsImplementation {
return UnityServices.getVersion();
}
/**
* Check if default placement is ready to show ads
*
* @return If true, default placement is ready to show ads
*/
public static boolean isReady() {
return isSupported() && isInitialized() && Placement.isReady();
}
/**
* Check if placement is ready to show ads
*
* @param placementId Placement, as defined in Unity Ads admin tools
* @return If true, placement is ready to show ads
*/
public static boolean isReady(String placementId) {
return isSupported() && isInitialized() && placementId != null && Placement.isReady(placementId);
}
/**
* Get current state of default placement
*
* @return If PlacementState.READY, default placement is ready to show ads. Other states give detailed reasons why placement is not ready.
*/
public static UnityAds.PlacementState getPlacementState() {
if(isSupported() && isInitialized()) {
return Placement.getPlacementState();
} else {
return UnityAds.PlacementState.NOT_AVAILABLE;
}
}
/**
* Get current state of a placement
*
* @param placementId Placement, as defined in Unity Ads admin tools
* @return If PlacementState.READY, placement is ready to show ads. Other states give detailed reasons why placement is not ready.
*/
public static UnityAds.PlacementState getPlacementState(String placementId) {
if(isSupported() && isInitialized() && placementId != null) {
return Placement.getPlacementState(placementId);
} else {
return UnityAds.PlacementState.NOT_AVAILABLE;
}
}
/**
* Show one advertisement using default placement.
*
* @param activity Current Android activity of calling app
*/
public static void show(final Activity activity) {
if(Placement.getDefaultPlacement() != null) {
show(activity, Placement.getDefaultPlacement());
} else {
handleLegacyListenerShowError("", com.unity3d.ads.UnityAds.UnityAdsError.NOT_INITIALIZED, "Unity Ads default placement is not initialized");
}
}
/**
* Show one advertisement with custom placement.
*
@ -246,19 +120,16 @@ public final class UnityAdsImplementation {
public static void show(final Activity activity, final String placementId, final UnityAdsShowOptions showOptions, final IUnityAdsShowListener showListener) {
if (!isSupported()) {
String showErrorMessage = "Unity Ads is not supported for this device";
handleLegacyListenerShowError(placementId, UnityAds.UnityAdsError.NOT_INITIALIZED, showErrorMessage);
handleShowError(showListener, placementId, UnityAds.UnityAdsShowError.NOT_INITIALIZED, showErrorMessage);
return;
}
if(!isInitialized()) {
String showErrorMessage = "Unity Ads is not initialized";
handleLegacyListenerShowError(placementId, UnityAds.UnityAdsError.NOT_INITIALIZED, showErrorMessage);
handleShowError(showListener, placementId, UnityAds.UnityAdsShowError.NOT_INITIALIZED, showErrorMessage);
return;
}
if(activity == null) {
String showErrorMessage = "Activity must not be null";
handleLegacyListenerShowError(placementId, UnityAds.UnityAdsError.INVALID_ARGUMENT, showErrorMessage);
handleShowError(showListener, placementId, UnityAds.UnityAdsShowError.INVALID_ARGUMENT, showErrorMessage);
return;
}
@ -272,25 +143,6 @@ public final class UnityAdsImplementation {
showListener.onUnityAdsShowFailure(placementId, error, message);
}
private static void handleLegacyListenerShowError(final String placementId, final UnityAds.UnityAdsError error, final String message) {
final String errorMessage = "Unity Ads show failed: " + message;
DeviceLog.error(errorMessage);
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
for (IUnityAdsListener listener : AdsProperties.getListeners()) {
listener.onUnityAdsError(error, errorMessage);
if (placementId != null) {
listener.onUnityAdsFinish(placementId, UnityAds.FinishState.ERROR);
} else {
listener.onUnityAdsFinish("", UnityAds.FinishState.ERROR);
}
}
}
});
}
/**
* Toggles debug mode on/off
*

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

@ -1,100 +0,0 @@
package com.unity3d.services.ads.api;
import com.unity3d.ads.IUnityAdsListener;
import com.unity3d.ads.UnityAds;
import com.unity3d.ads.mediation.IUnityAdsExtendedListener;
import com.unity3d.ads.properties.AdsProperties;
import com.unity3d.services.core.misc.Utilities;
import com.unity3d.services.core.webview.bridge.WebViewCallback;
import com.unity3d.services.core.webview.bridge.WebViewExposed;
public class Listener {
@WebViewExposed
public static void sendReadyEvent(final String placementId, WebViewCallback callback) {
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
for (IUnityAdsListener listener : AdsProperties.getListeners()) {
listener.onUnityAdsReady(placementId);
}
}
});
callback.invoke();
}
@WebViewExposed
public static void sendStartEvent(final String placementId, WebViewCallback callback) {
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
for (IUnityAdsListener listener : AdsProperties.getListeners()) {
listener.onUnityAdsStart(placementId);
}
}
});
callback.invoke();
}
@WebViewExposed
public static void sendFinishEvent(final String placementId, final String result, WebViewCallback callback) {
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
for (IUnityAdsListener listener : AdsProperties.getListeners()) {
listener.onUnityAdsFinish(placementId, UnityAds.FinishState.valueOf(result));
}
}
});
callback.invoke();
}
@WebViewExposed
public static void sendClickEvent(final String placementId, WebViewCallback callback) {
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
for (IUnityAdsListener listener : AdsProperties.getListeners()) {
if (listener instanceof IUnityAdsExtendedListener) {
((IUnityAdsExtendedListener)listener).onUnityAdsClick(placementId);
}
}
}
});
callback.invoke();
}
@WebViewExposed
public static void sendPlacementStateChangedEvent(final String placementId, final String oldState, final String newState, WebViewCallback callback) {
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
for (IUnityAdsListener listener : AdsProperties.getListeners()) {
if (listener instanceof IUnityAdsExtendedListener) {
((IUnityAdsExtendedListener)listener).onUnityAdsPlacementStateChanged(placementId, UnityAds.PlacementState.valueOf(oldState), UnityAds.PlacementState.valueOf(newState));
}
}
}
});
callback.invoke();
}
@WebViewExposed
public static void sendErrorEvent(final String error, final String message, WebViewCallback callback) {
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
for (IUnityAdsListener listener : AdsProperties.getListeners()) {
listener.onUnityAdsError(UnityAds.UnityAdsError.valueOf(error), message);
}
}
});
callback.invoke();
}
}

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

@ -1,27 +0,0 @@
package com.unity3d.services.ads.api;
import com.unity3d.services.core.webview.bridge.WebViewCallback;
import com.unity3d.services.core.webview.bridge.WebViewExposed;
public class Placement {
@WebViewExposed
public static void setDefaultPlacement(String placement, WebViewCallback callback) {
com.unity3d.services.ads.placement.Placement.setDefaultPlacement(placement);
callback.invoke();
}
@WebViewExposed
public static void setPlacementState(String placement, String placementState, WebViewCallback callback) {
com.unity3d.services.ads.placement.Placement.setPlacementState(placement, placementState);
callback.invoke();
}
@WebViewExposed
public static void setDefaultBannerPlacement(String placement, WebViewCallback callback) {
com.unity3d.services.ads.placement.Placement.setDefaultBannerPlacement(placement);
callback.invoke();
}
}

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

@ -1,92 +0,0 @@
package com.unity3d.services.ads.api;
import com.unity3d.services.core.misc.Utilities;
import com.unity3d.ads.purchasing.IPurchasing;
import com.unity3d.ads.purchasing.PurchasingError;
import com.unity3d.services.core.webview.bridge.WebViewCallback;
import com.unity3d.services.core.webview.bridge.WebViewExposed;
public class Purchasing {
public static IPurchasing purchaseInterface = null;
public static void setPurchasingInterface(IPurchasing purchasing){
purchaseInterface = purchasing;
}
@WebViewExposed
public static void initiatePurchasingCommand(final String eventString, WebViewCallback callback) {
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
if (purchaseInterface != null) {
purchaseInterface.onPurchasingCommand(eventString);
}
}
});
if (purchaseInterface != null) {
callback.invoke();
}
else {
callback.error(PurchasingError.PURCHASE_INTERFACE_NULL);
}
}
@WebViewExposed
public static void getPromoVersion(WebViewCallback callback) {
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
if (purchaseInterface != null) {
purchaseInterface.onGetPurchasingVersion();
}
}
});
if (purchaseInterface != null) {
callback.invoke();
}
else {
callback.error(PurchasingError.PURCHASE_INTERFACE_NULL);
}
}
@WebViewExposed
public static void getPromoCatalog(WebViewCallback callback) {
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
if (purchaseInterface != null) {
purchaseInterface.onGetProductCatalog();
}
}
});
if (purchaseInterface != null) {
callback.invoke();
}
else {
callback.error(PurchasingError.PURCHASE_INTERFACE_NULL);
}
}
@WebViewExposed
public static void initializePurchasing(WebViewCallback callback) {
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
if (purchaseInterface != null) {
purchaseInterface.onInitializePurchasing();
}
}
});
if (purchaseInterface != null) {
callback.invoke();
}
else {
callback.error(PurchasingError.PURCHASE_INTERFACE_NULL);
}
}
}

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

@ -2,16 +2,11 @@ package com.unity3d.services.ads.configuration;
import android.os.ConditionVariable;
import com.unity3d.ads.IUnityAdsListener;
import com.unity3d.ads.UnityAds;
import com.unity3d.ads.properties.AdsProperties;
import com.unity3d.services.ads.UnityAdsImplementation;
import com.unity3d.services.ads.adunit.AdUnitOpen;
import com.unity3d.services.ads.placement.Placement;
import com.unity3d.services.ads.token.TokenStorage;
import com.unity3d.services.core.configuration.Configuration;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.misc.Utilities;
import java.net.InetAddress;
import java.net.MalformedURLException;
@ -25,11 +20,8 @@ public class AdsModuleConfiguration implements IAdsModuleConfiguration {
public Class[] getWebAppApiClassList() {
Class[] list = {
com.unity3d.services.ads.api.AdUnit.class,
com.unity3d.services.ads.api.Listener.class,
com.unity3d.services.ads.api.VideoPlayer.class,
com.unity3d.services.ads.api.Placement.class,
com.unity3d.services.ads.api.WebPlayer.class,
com.unity3d.services.ads.api.Purchasing.class,
com.unity3d.services.ads.api.Load.class,
com.unity3d.services.ads.api.Show.class,
com.unity3d.services.ads.api.Token.class,
@ -40,7 +32,6 @@ public class AdsModuleConfiguration implements IAdsModuleConfiguration {
}
public boolean resetState(Configuration configuration) {
Placement.reset();
AdUnitOpen.setConfiguration(configuration);
UnityAdsImplementation.setConfiguration(configuration);
TokenStorage.deleteTokens();
@ -85,15 +76,6 @@ public class AdsModuleConfiguration implements IAdsModuleConfiguration {
}
public boolean initErrorState(Configuration configuration, String state, String errorMessage) {
final String message = "Init failed in " + state;
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
for (IUnityAdsListener listener : AdsProperties.getListeners()) {
listener.onUnityAdsError(UnityAds.UnityAdsError.INITIALIZE_FAILED, message);
}
}
});
return true;
}

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

@ -6,7 +6,7 @@ import com.unity3d.services.core.log.DeviceLog;
public class ScarAdapterFactory {
public static final int CODE_20_0 = 210402000;
public static final int CODE_19_7 = 204204000;
public static final int CODE_19_8 = 204890000;
public static final int CODE_19_5 = 203404000;
public static final int CODE_19_2 = 201604000;
@ -14,7 +14,7 @@ public class ScarAdapterFactory {
IScarAdapter scarAdapter = null;
if (gmaVersionCode >= CODE_20_0) {
scarAdapter = new com.unity3d.scar.adapter.v2000.ScarAdapter(adsErrorHandler);
} else if (gmaVersionCode >= CODE_19_5 && gmaVersionCode <= CODE_19_7) {
} else if (gmaVersionCode >= CODE_19_5 && gmaVersionCode <= CODE_19_8) {
scarAdapter = new com.unity3d.scar.adapter.v1950.ScarAdapter(adsErrorHandler);
} else if (gmaVersionCode >= CODE_19_2) {
scarAdapter = new com.unity3d.scar.adapter.v1920.ScarAdapter(adsErrorHandler);

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

@ -1,6 +1,8 @@
package com.unity3d.services.ads.gmascar.bridges;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.reflection.GenericBridge;
import java.util.HashMap;
public class AdapterStatusBridge extends GenericBridge {

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

@ -1,5 +1,7 @@
package com.unity3d.services.ads.gmascar.bridges;
import com.unity3d.services.core.reflection.GenericBridge;
import java.util.HashMap;
import java.util.Map;

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

@ -2,6 +2,7 @@ package com.unity3d.services.ads.gmascar.bridges;
import com.unity3d.services.ads.gmascar.listeners.IInitializationStatusListener;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.reflection.GenericBridge;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

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

@ -3,6 +3,7 @@ package com.unity3d.services.ads.gmascar.bridges;
import android.content.Context;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.reflection.GenericBridge;
import java.util.HashMap;

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

@ -1,69 +0,0 @@
package com.unity3d.services.ads.placement;
import com.unity3d.ads.UnityAds;
import java.util.HashMap;
public class Placement {
private static HashMap<String,UnityAds.PlacementState> _placementReadyMap;
private static String _defaultPlacement;
private static String _defaultBannerPlacement;
public static void setPlacementState(String placement, String placementState) {
if (_placementReadyMap == null) {
_placementReadyMap = new HashMap<>();
}
_placementReadyMap.put(placement, UnityAds.PlacementState.valueOf(placementState));;
}
public static boolean isReady(String placement) {
return getPlacementState(placement) == UnityAds.PlacementState.READY;
}
public static boolean isReady() {
return getPlacementState() == UnityAds.PlacementState.READY;
}
public static UnityAds.PlacementState getPlacementState(String placement) {
return currentState(placement);
}
public static UnityAds.PlacementState getPlacementState() {
if(_defaultPlacement == null) {
return UnityAds.PlacementState.NOT_AVAILABLE;
}
return getPlacementState(_defaultPlacement);
}
// When SDK reinitializes all placement info is wiped out and has to be reinitialized by webview
public static void reset() {
_placementReadyMap = null;
_defaultPlacement = null;
}
public static void setDefaultPlacement(String placement) {
_defaultPlacement = placement;
}
public static String getDefaultPlacement() {
return _defaultPlacement;
}
public static void setDefaultBannerPlacement(String placement) {
_defaultBannerPlacement = placement;
}
public static String getDefaultBannerPlacement() {
return _defaultBannerPlacement;
}
private static UnityAds.PlacementState currentState(String placement) {
if(_placementReadyMap == null || !_placementReadyMap.containsKey(placement)) {
return UnityAds.PlacementState.NOT_AVAILABLE;
}
return _placementReadyMap.get(placement);
}
}

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

@ -7,7 +7,6 @@ import android.view.ViewGroup;
import android.widget.FrameLayout;
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;
@ -145,11 +144,6 @@ public final class UnityBanners {
// ********* CAUTION START *****************
// OLD BANNER API THAT DOES NOT SUPPORT MULTIPLE BANNERS
@Deprecated
public static void loadBanner(Activity activity) {
UnityBanners.loadBanner(activity, Placement.getDefaultBannerPlacement());
}
@Deprecated
public static void loadBanner(final Activity activity, final String placementId) {
DeviceLog.entered();
@ -160,10 +154,6 @@ public final class UnityBanners {
sendError("UnityAds is not initialized.");
return;
}
if (!UnityAds.isReady(placementId)) {
sendError("Banner placement " + placementId + " is not ready");
return;
}
ClientProperties.setActivity(activity);
UnityBanners.getInstance()._loadBanner(activity, placementId);

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

@ -30,7 +30,8 @@ public class Sdk {
WebViewApp.getCurrentApp().getConfiguration().getWebViewVersion(),
SdkProperties.getInitializationTime(),
SdkProperties.isReinitialized(),
SdkProperties.isPerPlacementLoadEnabled(),
// perPlacementLoadEnabled is now always true
true,
SdkProperties.getLatestConfiguration() != null,
Device.getElapsedRealtime()
};

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

@ -45,8 +45,6 @@ public class Configuration {
private String[] _moduleConfigurationList = {
"com.unity3d.services.core.configuration.CoreModuleConfiguration",
"com.unity3d.services.ads.configuration.AdsModuleConfiguration",
"com.unity3d.services.monetization.core.configuration.MonetizationModuleConfiguration",
"com.unity3d.services.purchasing.core.configuration.PurchasingModuleConfiguration",
"com.unity3d.services.analytics.core.configuration.AnalyticsModuleConfiguration",
"com.unity3d.services.ar.configuration.ARModuleConfiguration",
"com.unity3d.services.banners.configuration.BannersModuleConfiguration",

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

@ -5,7 +5,6 @@ import android.content.Context;
import com.unity3d.ads.BuildConfig;
import com.unity3d.ads.IUnityAdsInitializationListener;
import com.unity3d.ads.UnityAds;
import com.unity3d.services.IUnityServicesListener;
import com.unity3d.services.core.cache.CacheDirectory;
import com.unity3d.services.core.configuration.Configuration;
import com.unity3d.services.core.device.Device;
@ -27,7 +26,6 @@ public class SdkProperties {
private static final String CHINA_ISO_ALPHA_2_CODE = "CN";
private static final String CHINA_ISO_ALPHA_3_CODE = "CHN";
private static long _initializationTime = 0;
private static IUnityServicesListener _listener;
private static Configuration _latestConfiguration;
private static LinkedHashSet<IUnityAdsInitializationListener> _initializationListeners = new LinkedHashSet<IUnityAdsInitializationListener>();
@ -35,7 +33,6 @@ public class SdkProperties {
private static boolean _initialized = false;
private static boolean _reinitialized = false;
private static boolean _testMode = false;
private static boolean _perPlacementLoadEnabled = false;
private static boolean _debugMode = false;
private static AtomicReference<InitializationState> _currentInitializationState = new AtomicReference<>(InitializationState.NOT_INITIALIZED);
@ -88,12 +85,6 @@ public class SdkProperties {
_testMode = testMode;
}
public static boolean isPerPlacementLoadEnabled () { return _perPlacementLoadEnabled; }
public static void setPerPlacementLoadEnabled (boolean perPlacementLoad) {
_perPlacementLoadEnabled = perPlacementLoad;
}
public static int getVersionCode () {
return BuildConfig.VERSION_CODE;
}
@ -221,14 +212,6 @@ public class SdkProperties {
return _debugMode;
}
public static void setListener(IUnityServicesListener listener) {
_listener = listener;
}
public static IUnityServicesListener getListener() {
return _listener;
}
public static void addInitializationListener(IUnityAdsInitializationListener listener) {
if(listener == null) {
return;

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

@ -1,4 +1,4 @@
package com.unity3d.services.ads.gmascar.bridges;
package com.unity3d.services.core.reflection;
import com.unity3d.scar.adapter.common.GMAEvent;
import com.unity3d.services.core.log.DeviceLog;
@ -9,11 +9,14 @@ import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
/**
* Abstract class used to call any method reflectively. Subclass this to provide specific bridge invocation to other libraries.
*/
public abstract class GenericBridge {
private String _className;
private Map<String, Class[]> _functionAndParameters;
private Map<String, Method> _methodMap;
private final String _className;
private final Map<String, Class[]> _functionAndParameters;
private final Map<String, Method> _methodMap;
private boolean _methodMapBuilt = false;
protected abstract String getClassName();
@ -38,7 +41,7 @@ public abstract class GenericBridge {
return null;
}
} catch (ClassNotFoundException e) {
DeviceLog.debug("ERROR: Could not find GMA SDK Class %s %s", _className, e.getLocalizedMessage());
DeviceLog.debug("ERROR: Could not find Class %s %s", _className, e.getLocalizedMessage());
return null;
}
}
@ -107,7 +110,7 @@ public abstract class GenericBridge {
}
}
public Object callNonVoidMethod(String methodName, Object callingObj, Object... parameters) {
public <T> T callNonVoidMethod(String methodName, Object callingObj, Object... parameters) {
Method method = getMethod(methodName);
if (method == null) {
DeviceLog.debug("ERROR: Could not find method %s", methodName);
@ -115,7 +118,7 @@ public abstract class GenericBridge {
}
try {
return method.invoke(callingObj, parameters);
return (T)method.invoke(callingObj, parameters);
} catch (Exception e) {
DeviceLog.debug("ERROR: Could not invoke method %s : %s", methodName, e.getLocalizedMessage());
}

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

@ -0,0 +1,23 @@
package com.unity3d.services.core.reflection;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
/**
* Abstract class used to enable proxy invocation callbacks to any methods called reflectively.
*/
public abstract class GenericListenerProxy implements InvocationHandler {
public abstract Class<?> getProxyClass() throws ClassNotFoundException;
public Object getProxyInstance() throws ClassNotFoundException {
return Proxy.newProxyInstance(getProxyClass().getClassLoader(), new Class<?>[]{getProxyClass()}, this);
}
@Override
public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
// Fallback to just calling method in case proxy method is from Object (for example equals, etc.)
return m.invoke(this, args);
}
}

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

@ -1,13 +0,0 @@
package com.unity3d.services.monetization; import android.app.Activity;
import com.unity3d.services.IUnityServicesListener;
import com.unity3d.services.monetization.placementcontent.core.PlacementContent;
/**
* Listener for events within the Monetization service. Used in {@link UnityMonetization#setListener(IUnityMonetizationListener)},
* {@link UnityMonetization#initialize(Activity, String, IUnityMonetizationListener)}, or {@link UnityMonetization#initialize(Activity, String, IUnityMonetizationListener, boolean)}
*/
public interface IUnityMonetizationListener extends IUnityServicesListener {
void onPlacementContentReady(String placementId, PlacementContent placementcontent);
void onPlacementContentStateChange(String placementId, PlacementContent placementcontent, UnityMonetization.PlacementContentState previousState, UnityMonetization.PlacementContentState newState);
}

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

@ -1,104 +0,0 @@
package com.unity3d.services.monetization;
import android.app.Activity;
import com.unity3d.services.UnityServices;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.monetization.core.placementcontent.PlacementContents;
import com.unity3d.services.monetization.placementcontent.core.PlacementContent;
import com.unity3d.services.monetization.core.properties.ClientProperties;
@Deprecated
public class UnityMonetization {
/**
* Sets the listener for PlacementContent events.
* @param listener The listener for event callbacks.
*/
public static void setListener(IUnityMonetizationListener listener) {
ClientProperties.setListener(listener);
}
/**
* Returns the current monetization listener.
* @return The listener for event callbacks.
*/
public static IUnityMonetizationListener getListener() {
return ClientProperties.getListener();
}
/**
* Checks if a placementcontent is ready for the given placement.
* @param placementId Placement ID as configured in the Unity Ads dashboard.
* @return True, if a placementcontent is ready, or else false.
*/
public static boolean isReady(String placementId) {
return PlacementContents.isReady(placementId);
}
/**
* Returns the placementcontent for the given placement.
* @param placementId Placement ID as configured in the Unity Ads dashboard.
* @return PlacementContent, if one is available, or else null.
*/
public static PlacementContent getPlacementContent(String placementId) {
return PlacementContents.getPlacementContent(placementId);
}
/**
*
* @param placementId Placement ID as configured in the Unity Ads dashboard.
* @param asClass The class to cast the placementcontent to.
* @param <T> The type of placementcontent to be casted to.
* @return The placementcontent as T, if it is of that type. If it isn't, this function returns null.
*/
public static <T extends PlacementContent> T getPlacementContent(String placementId, Class<T> asClass) {
return PlacementContents.getPlacementContent(placementId, asClass);
}
public static void initialize(Activity activity, String gameId, IUnityMonetizationListener listener) {
boolean testMode = false;
initialize(activity, gameId, listener, testMode);
}
public static void initialize(Activity activity, String gameId, IUnityMonetizationListener listener, boolean testMode) {
DeviceLog.entered();
if (listener != null) {
setListener(listener);
}
ClientProperties.setMonetizationEnabled(true);
boolean usePerPlacementLoad = false;
UnityServices.initialize(activity.getApplicationContext(), gameId, listener, testMode, usePerPlacementLoad, null);
}
/**
* PlacementContentState is an enum representing the state of a placementcontent. All states other than READY describe
* that the placementcontent should not be used.
*/
public enum PlacementContentState {
/**
* Placement is ready to show ads. You can call show method and ad unit will open.
*/
READY,
/**
* Current placement state is not available. SDK is not initialized or this placement has not been configured in Unity Ads admin tools.
*/
NOT_AVAILABLE,
/**
* Placement is disabled. Placement can be enabled via Unity Ads admin tools.
*/
DISABLED,
/**
* Placement is not yet ready but it will be ready in the future. Most likely reason is caching.
*/
WAITING,
/**
* Placement is properly configured but there are currently no ads available for the placement.
*/
NO_FILL
}
}

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

@ -1,53 +0,0 @@
package com.unity3d.services.monetization.core.api;
import com.unity3d.services.monetization.IUnityMonetizationListener;
import com.unity3d.services.core.webview.bridge.WebViewCallback;
import com.unity3d.services.core.webview.bridge.WebViewExposed;
import com.unity3d.services.monetization.UnityMonetization;
import com.unity3d.services.monetization.core.placementcontent.PlacementContentListenerError;
import com.unity3d.services.monetization.placementcontent.core.PlacementContent;
import com.unity3d.services.monetization.core.placementcontent.PlacementContents;
import com.unity3d.services.monetization.core.properties.ClientProperties;
public class MonetizationListener {
@WebViewExposed
public static void isMonetizationEnabled(WebViewCallback callback) {
callback.invoke(ClientProperties.isMonetizationEnabled());
}
@WebViewExposed
public static void sendPlacementContentReady(String placementId, WebViewCallback callback) {
IUnityMonetizationListener placementContentListener = ClientProperties.getListener();
if (placementContentListener != null) {
try {
PlacementContent placementContent = PlacementContents.getPlacementContent(placementId);
placementContentListener.onPlacementContentReady(placementId, placementContent);
callback.invoke();
} catch (Exception e) {
callback.error(PlacementContentListenerError.PLACEMENTCONTENT_LISTENER_ERROR, e);
}
} else {
callback.error(PlacementContentListenerError.PLACEMENTCONTENT_LISTENER_NULL);
}
}
@WebViewExposed
public static void sendPlacementContentStateChanged(String placementId, String previousState, String newState, WebViewCallback callback) {
IUnityMonetizationListener placementContentListener = ClientProperties.getListener();
if (placementContentListener != null) {
try {
PlacementContent placementContent = PlacementContents.getPlacementContent(placementId);
placementContentListener.onPlacementContentStateChange(placementId,
placementContent,
UnityMonetization.PlacementContentState.valueOf(previousState),
UnityMonetization.PlacementContentState.valueOf(newState));
callback.invoke();
} catch (Exception e) {
callback.error(PlacementContentListenerError.PLACEMENTCONTENT_LISTENER_ERROR, e);
}
} else {
callback.error(PlacementContentListenerError.PLACEMENTCONTENT_LISTENER_NULL);
}
}
}

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

@ -1,40 +0,0 @@
package com.unity3d.services.monetization.core.api;
import com.unity3d.ads.UnityAds;
import com.unity3d.services.core.misc.Utilities;
import com.unity3d.services.monetization.UnityMonetization;
import com.unity3d.services.monetization.placementcontent.ads.IShowAdListener;
import com.unity3d.services.monetization.placementcontent.ads.ShowAdPlacementContent;
import com.unity3d.services.monetization.placementcontent.core.PlacementContent;
import com.unity3d.services.core.webview.bridge.WebViewCallback;
import com.unity3d.services.core.webview.bridge.WebViewExposed;
import com.unity3d.services.monetization.core.placementcontent.PlacementContentResultFactory;
import com.unity3d.services.monetization.core.utilities.JSONUtilities;
import org.json.JSONObject;
public class PlacementContents {
@WebViewExposed
public static void createPlacementContent(String placementId, JSONObject params, WebViewCallback callback) {
PlacementContent result = PlacementContentResultFactory.create(placementId, JSONUtilities.jsonObjectToMap(params));
com.unity3d.services.monetization.core.placementcontent.PlacementContents.putPlacementContent(placementId, result);
callback.invoke();
}
@WebViewExposed
public static void setPlacementContentState(String placementId, String state, WebViewCallback callback) {
com.unity3d.services.monetization.core.placementcontent.PlacementContents.setPlacementContentState(placementId, UnityMonetization.PlacementContentState.valueOf(state));
callback.invoke();
}
@WebViewExposed
public static void sendAdFinished(String placementId, final String finishState, WebViewCallback callback) {
ShowAdPlacementContent.sendAdFinished(placementId, UnityAds.FinishState.valueOf(finishState));
callback.invoke();
}
@WebViewExposed
public static void sendAdStarted(String placementId, WebViewCallback callback) {
ShowAdPlacementContent.sendAdStarted(placementId);
callback.invoke();
}
}

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

@ -1,39 +0,0 @@
package com.unity3d.services.monetization.core.configuration;
import com.unity3d.services.core.configuration.Configuration;
import com.unity3d.services.core.configuration.IModuleConfiguration;
import com.unity3d.services.monetization.core.api.MonetizationListener;
import com.unity3d.services.monetization.core.api.PlacementContents;
public class MonetizationModuleConfiguration implements IModuleConfiguration {
private static final Class[] WEB_APP_API_CLASS_LIST = new Class[] {
MonetizationListener.class,
PlacementContents.class
};
@Override
public Class[] getWebAppApiClassList() {
return WEB_APP_API_CLASS_LIST;
}
@Override
public boolean resetState(Configuration configuration) {
return true;
}
@Override
public boolean initModuleState(Configuration configuration) {
return true;
}
@Override
public boolean initErrorState(Configuration configuration, String state, String message) {
return true;
}
@Override
public boolean initCompleteState(Configuration configuration) {
return true;
}
}

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

@ -1,5 +0,0 @@
package com.unity3d.services.monetization.core.placementcontent;
public enum PlacementContentEvent {
CUSTOM
}

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

@ -1,6 +0,0 @@
package com.unity3d.services.monetization.core.placementcontent;
public enum PlacementContentListenerError {
PLACEMENTCONTENT_LISTENER_ERROR,
PLACEMENTCONTENT_LISTENER_NULL
}

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

@ -1,44 +0,0 @@
package com.unity3d.services.monetization.core.placementcontent;
import com.unity3d.services.monetization.placementcontent.core.NoFillPlacementContent;
import com.unity3d.services.monetization.placementcontent.ads.ShowAdPlacementContent;
import com.unity3d.services.monetization.placementcontent.core.PlacementContent;
import com.unity3d.services.monetization.placementcontent.purchasing.PromoAdPlacementContent;
import java.util.Map;
public class PlacementContentResultFactory {
public enum PlacementContentResultType {
SHOW_AD,
PROMO_AD,
NO_FILL,
CUSTOM;
static PlacementContentResultType parse(String type) {
if (type == null) {
return CUSTOM;
}
try {
return PlacementContentResultType.valueOf(type);
} catch (IllegalArgumentException e) {
return CUSTOM;
}
}
}
public static PlacementContent create(String placementId, Map<String, Object> params) {
PlacementContentResultType type = PlacementContentResultType.parse((String) params.get("type"));
switch (type) {
case SHOW_AD:
return new ShowAdPlacementContent(placementId, params);
case PROMO_AD:
return new PromoAdPlacementContent(placementId, params);
case NO_FILL:
return new NoFillPlacementContent(placementId, params);
case CUSTOM:
default:
return new PlacementContent(placementId, params);
}
}
}

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

@ -1,80 +0,0 @@
package com.unity3d.services.monetization.core.placementcontent;
import com.unity3d.services.monetization.UnityMonetization;
import com.unity3d.services.monetization.placementcontent.core.CustomEvent;
import com.unity3d.services.monetization.placementcontent.core.PlacementContent;
import java.util.HashMap;
import java.util.Map;
public class PlacementContents {
private static Map<String, PlacementContent> placementContentsMap = new HashMap<>();
private static final PlacementContent NOT_AVAILABLE = PlacementContents.getNotAvailablePlacementContent();
public static PlacementContent getPlacementContent(String placementId) {
PlacementContent content = placementContentsMap.get(placementId);
if (content == null) {
return NOT_AVAILABLE;
}
return content;
}
public static <T extends PlacementContent> T getPlacementContent(String placementId, Class<T> asClass) {
PlacementContent placementcontent = getPlacementContent(placementId);
if (asClass.isInstance(placementcontent)) {
return asClass.cast(placementcontent);
}
return null;
}
public static PlacementContent putPlacementContent(String placementId, PlacementContent placementcontent) {
return placementContentsMap.put(placementId, placementcontent);
}
public static boolean isReady(String placementId) {
PlacementContent result = getPlacementContent(placementId);
return result != null && result.isReady();
}
public static void removePlacementContent(String placementId) {
placementContentsMap.remove(placementId);
}
public static void setPlacementContentState(String placementId, UnityMonetization.PlacementContentState state) {
PlacementContent placementcontent = getPlacementContent(placementId);
if (placementcontent != null) {
placementcontent.setState(state);
}
}
private static PlacementContent getNotAvailablePlacementContent() {
Map<String, Object> params = new HashMap<>();
params.put("type", "NOT_AVAILABLE");
return new NotAvailablePlacementContent("", params);
}
private static final class NotAvailablePlacementContent extends PlacementContent {
public NotAvailablePlacementContent(String placementId, Map<String, Object> params) {
super(placementId, params);
}
@Override
public boolean isReady() {
return false;
}
@Override
public UnityMonetization.PlacementContentState getState() {
return UnityMonetization.PlacementContentState.NOT_AVAILABLE;
}
@Override
public void sendCustomEvent(CustomEvent customEvent) {
}
@Override
protected String getDefaultEventCategory() {
return "NOT_AVAILABLE";
}
}
}

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

@ -1,25 +0,0 @@
package com.unity3d.services.monetization.core.properties;
import com.unity3d.services.monetization.IUnityMonetizationListener;
public class ClientProperties {
private static IUnityMonetizationListener listener;
private static boolean monetizationEnabled;
public static IUnityMonetizationListener getListener() {
return listener;
}
public static void setListener(IUnityMonetizationListener listener) {
ClientProperties.listener = listener;
}
public static void setMonetizationEnabled(boolean monetizationEnabled) {
ClientProperties.monetizationEnabled = monetizationEnabled;
}
public static boolean isMonetizationEnabled() {
return monetizationEnabled;
}
}

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

@ -1,109 +0,0 @@
package com.unity3d.services.monetization.core.utilities;
import com.unity3d.services.core.log.DeviceLog;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class JSONUtilities {
public static Map<String, Object> jsonObjectToMap(JSONObject object) {
Map<String, Object> map = new HashMap<>(object.length());
for (Iterator<String> it = object.keys(); it.hasNext(); ) {
String key = it.next();
try {
Object value = mapTypeFromJSON(object.get(key));
map.put(key, value);
} catch (JSONException e) {
DeviceLog.error("Could not put value in map: %s, %s", key, e.getMessage());
}
}
return map;
}
public static List<Object> jsonArrayToList(JSONArray array) {
List<Object> values = new ArrayList<>(array.length());
for (int i = 0; i < array.length(); i++) {
try {
Object value = mapTypeFromJSON(array.get(i));
values.add(value);
} catch (JSONException e) {
DeviceLog.error("Could not put value into list: %s", e.getMessage());
}
}
return values;
}
private static Object mapTypeFromJSON(Object value) {
if (value instanceof JSONObject) {
value = jsonObjectToMap((JSONObject) value);
} else if (value instanceof JSONArray) {
value = jsonArrayToList((JSONArray) value);
}
return value;
}
public static JSONObject mapToJsonObject(Map<String, Object> extras) {
JSONObject object = new JSONObject();
for (Map.Entry<String, Object> entry : extras.entrySet()) {
try {
object.put(entry.getKey(), wrap(entry.getValue()));
} catch (JSONException e) {
DeviceLog.error("Could not map entry to object: %s, %s", entry.getKey(), entry.getValue());
}
}
return object;
}
// Taken from the JSON API library. Placed here for backwards compatibility
// so we don't up our minimum SDK.
public static Object wrap(Object o) {
if (o == null) {
return null;
}
if (o instanceof JSONArray || o instanceof JSONObject) {
return o;
}
if (o.equals(JSONObject.NULL)) {
return o;
}
try {
if (o instanceof Collection) {
return new JSONArray((Collection) o);
} else if (o.getClass().isArray()) {
return new JSONArray(Arrays.asList(o));
}
if (o instanceof Map) {
return new JSONObject((Map) o);
}
if (o instanceof Boolean ||
o instanceof Byte ||
o instanceof Character ||
o instanceof Double ||
o instanceof Float ||
o instanceof Integer ||
o instanceof Long ||
o instanceof Short ||
o instanceof String) {
return o;
}
if (o instanceof Enum) {
return o.toString();
}
if (o.getClass().getPackage().getName().startsWith("java.")) {
return o.toString();
}
} catch (Exception ignored) {
}
return null;
}
}

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

@ -1,6 +0,0 @@
package com.unity3d.services.monetization.core.webview;
public enum WebViewEventCategory {
PLACEMENT_CONTENT,
CUSTOM_PURCHASING
}

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

@ -1,25 +0,0 @@
package com.unity3d.services.monetization.placementcontent.ads;
import android.app.Activity;
import com.unity3d.ads.UnityAds;
/**
* Listener class for the {@link ShowAdPlacementContent#show(Activity, IShowAdListener)} method.
* Can be used to know when an ad has started or finished.
* A convenience class of {@link ShowAdListenerAdapter} can be used when only one method needs overriding.
*/
public interface IShowAdListener {
/**
* Called when the ad has finished.
* @param placementId Placement ID as configured in the Unity Ads dashboard.
* @param withState The state which the Ad has finished with.
*/
void onAdFinished(String placementId, UnityAds.FinishState withState);
/**
* Notifies that the ad for the given placement has started.
* @param placementId Placement ID as configured in the Unity Ads dashboard.
*/
void onAdStarted(String placementId);
}

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

@ -1,15 +0,0 @@
package com.unity3d.services.monetization.placementcontent.ads;
import com.unity3d.ads.UnityAds;
public abstract class ShowAdListenerAdapter implements IShowAdListener {
@Override
public void onAdFinished(String placementId, UnityAds.FinishState withState) {
// Intentionally left blank
}
@Override
public void onAdStarted(String placementId) {
// Intentionally left blank
}
}

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

@ -1,42 +0,0 @@
package com.unity3d.services.monetization.placementcontent.ads;
import android.app.Activity;
import com.unity3d.ads.UnityAds;
import com.unity3d.services.monetization.placementcontent.core.PlacementContent;
import com.unity3d.services.core.properties.ClientProperties;
import com.unity3d.services.monetization.placementcontent.core.RewardablePlacementContent;
import java.util.HashMap;
import java.util.Map;
public class ShowAdPlacementContent extends RewardablePlacementContent {
private static Map<String, IShowAdListener> listenerMap = new HashMap<>();
public ShowAdPlacementContent(String placementId, Map<String, Object> params) {
super(placementId, params);
}
public void show(Activity activity, IShowAdListener listener) {
listenerMap.put(placementId, listener);
if (UnityAds.isReady(placementId)) {
UnityAds.show(activity, placementId);
} else {
sendAdFinished(placementId, UnityAds.FinishState.ERROR);
}
}
public static void sendAdFinished(String placementId, UnityAds.FinishState finishState) {
IShowAdListener listener = listenerMap.remove(placementId);
if (listener != null) {
listener.onAdFinished(placementId, finishState);
}
}
public static void sendAdStarted(String placementId) {
IShowAdListener listener = listenerMap.get(placementId);
if (listener != null) {
listener.onAdStarted(placementId);
}
}
}

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

@ -1,108 +0,0 @@
package com.unity3d.services.monetization.placementcontent.core;
import java.util.HashMap;
import java.util.Map;
public class CustomEvent {
private String category;
private String type;
private Map<String, Object> data;
public CustomEvent() {
}
public CustomEvent(String type) {
this.type = type;
}
public CustomEvent(String type, Map<String, Object> data) {
this.type = type;
this.data = data;
}
public CustomEvent(String category, String type, Map<String, Object> data) {
this.category = category;
this.type = type;
this.data = data;
}
private CustomEvent(Builder builder) {
setCategory(builder.category);
setType(builder.type);
setData(builder.data);
}
public static Builder newBuilder() {
return new Builder();
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Map<String, Object> getData() {
return data;
}
public void setData(Map<String, Object> data) {
this.data = data;
}
public static final class Builder {
private String category;
private String type;
private Map<String, Object> data;
private Builder() {
}
public Builder withCategory(String val) {
category = val;
return this;
}
public Builder withType(String val) {
type = val;
return this;
}
public Builder withData(Map<String, Object> val) {
data = val;
return this;
}
public Builder putAllData(Map<String, Object> vals) {
if (data == null) {
data = new HashMap<>(vals);
} else {
data.putAll(vals);
}
return this;
}
public Builder putData(String key, Object value) {
if (data == null) {
data = new HashMap<>();
}
data.put(key, value);
return this;
}
public CustomEvent build() {
return new CustomEvent(this);
}
}
}

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

@ -1,31 +0,0 @@
package com.unity3d.services.monetization.placementcontent.core;
import com.unity3d.services.monetization.UnityMonetization;
import com.unity3d.services.monetization.placementcontent.core.PlacementContent;
import java.util.Map;
public class NoFillPlacementContent extends PlacementContent {
public NoFillPlacementContent(String placementId, Map<String, Object> params) {
super(placementId, params);
}
@Override
public boolean isReady() {
return false;
}
@Override
public UnityMonetization.PlacementContentState getState() {
return UnityMonetization.PlacementContentState.NO_FILL;
}
@Override
public void sendCustomEvent(CustomEvent customEvent) {
}
@Override
protected String getDefaultEventCategory() {
return "NO_FILL";
}
}

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

@ -1,87 +0,0 @@
package com.unity3d.services.monetization.placementcontent.core;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.monetization.UnityMonetization;
import com.unity3d.services.core.webview.WebViewApp;
import com.unity3d.services.monetization.core.placementcontent.PlacementContentEvent;
import com.unity3d.services.monetization.core.webview.WebViewEventCategory;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
public class PlacementContent {
protected String placementId;
private String type;
private Map<String, Object> extras = new HashMap<>();
private UnityMonetization.PlacementContentState state;
public PlacementContent(String placementId, Map<String, Object> params) {
this.placementId = placementId;
this.type = (String) params.get("type");
this.extras.putAll(params);
}
public Object getExtra(String key) {
return this.extras.get(key);
}
public Map<String, Object> getExtras() {
return this.extras;
}
public String getType() {
return type;
}
public void setState(UnityMonetization.PlacementContentState state) {
this.state = state;
}
public void sendCustomEvent(CustomEvent customEvent) {
if (customEvent.getCategory() == null) {
customEvent.setCategory(getDefaultEventCategory());
}
WebViewApp app = WebViewApp.getCurrentApp();
if (app == null) {
DeviceLog.warning("Could not send custom event due to app being null");
} else {
JSONObject eventDataMap = getJsonForCustomEvent(customEvent);
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.PLACEMENT_CONTENT, PlacementContentEvent.CUSTOM, placementId, eventDataMap);
}
}
private JSONObject getJsonForCustomEvent(CustomEvent customEvent) {
JSONObject json = new JSONObject();
try {
json.put("category", customEvent.getCategory());
json.put("type", customEvent.getType());
json.put("data", customEvent.getData());
} catch (JSONException e) {
DeviceLog.warning("Error creating json for custom event: ", e.getMessage());
}
return json;
}
public boolean isReady() {
return this.state == UnityMonetization.PlacementContentState.READY;
}
public void sendCustomEvent(String type, Map<String, Object> eventData) {
sendCustomEvent(new CustomEvent(type, eventData));
}
public void sendCustomEvent(String category, String type, Map<String, Object> eventData) {
sendCustomEvent(new CustomEvent(category, type, eventData));
}
public UnityMonetization.PlacementContentState getState() {
return state;
}
protected String getDefaultEventCategory() {
return "PLACEMENT_CONTENT";
}
}

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

@ -1,27 +0,0 @@
package com.unity3d.services.monetization.placementcontent.core;
import java.util.Map;
public class RewardablePlacementContent extends PlacementContent {
private boolean isRewarded;
private String rewardId;
public RewardablePlacementContent(String placementId, Map<String, Object> params) {
super(placementId, params);
if (params.containsKey("rewarded")) {
isRewarded = (boolean) params.get("rewarded");
}
if (params.containsKey("rewardId")) {
rewardId = (String) params.get("rewardId");
}
}
public boolean isRewarded() {
return isRewarded;
}
public String getRewardId() {
return rewardId;
}
}

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше