diff --git a/.github/workflows/integration_tests.yml b/.github/workflows/integration_tests.yml index 05c93a6188..2d4edf6f1d 100644 --- a/.github/workflows/integration_tests.yml +++ b/.github/workflows/integration_tests.yml @@ -17,7 +17,7 @@ on: required: true apis: description: 'CSV of apis to build and test' - default: 'analytics,app_check,auth,database,dynamic_links,firestore,functions,gma,installations,messaging,remote_config,storage,ump' + default: 'analytics,app_check,auth,database,dynamic_links,firestore,functions,installations,messaging,remote_config,storage,ump' required: true operating_systems: description: 'CSV of VMs to run on' @@ -186,7 +186,7 @@ jobs: # list. Then we can use fromJson to define the field in the matrix for the tests job. if [[ "${{ github.event.schedule }}" == "0 9 * * *" ]]; then # at 1am PST/2am PDT. Running integration tests and generate test report for all testapps except firestore - apis="analytics,app_check,auth,database,dynamic_links,functions,gma,installations,messaging,remote_config,storage,ump" + apis="analytics,app_check,auth,database,dynamic_links,functions,installations,messaging,remote_config,storage,ump" echo "::warning ::Running main nightly tests" elif [[ "${{ github.event.schedule }}" == "0 10 * * *" || "${{ github.event.schedule }}" == "0 11 * * *" ]]; then # at 2am PST/3am PDT and 3am PST/4am PDT. Running integration tests for firestore and generate test report. diff --git a/.github/workflows/update-dependencies.yml b/.github/workflows/update-dependencies.yml index 23db829d3e..3a0fd70d48 100644 --- a/.github/workflows/update-dependencies.yml +++ b/.github/workflows/update-dependencies.yml @@ -8,9 +8,6 @@ on: updateiOS: description: 'update iOS dependencies?' default: 1 - includeGMA: - description: 'include GMA?' - default: 0 triggerTests: description: 'trigger tests on PR?' default: 1 @@ -68,20 +65,16 @@ jobs: - name: Run update script run: | - gma_flag= - if [[ ${{ github.event.inputs.includeGMA }} -eq 1 ]]; then - gma_flag="--include_gma" - fi if [[ ${{ github.event.inputs.updateiOS }} -eq 1 ]]; then if [[ ${{ github.event.inputs.updateAndroid }} -eq 1 ]]; then # Update both echo "Updating all dependencies" - python scripts/update_android_ios_dependencies.py --logfile=${UPDATE_LOGFILE} ${gma_flag} + python scripts/update_android_ios_dependencies.py --logfile=${UPDATE_LOGFILE} echo "CHOSEN_DEPS=mobile" >> $GITHUB_ENV else # Update iOS only echo "Updating iOS dependencies only" - python scripts/update_android_ios_dependencies.py --skip_android --logfile=${UPDATE_LOGFILE} ${gma_flag} + python scripts/update_android_ios_dependencies.py --skip_android --logfile=${UPDATE_LOGFILE} echo "CHOSEN_DEPS=iOS" >> $GITHUB_ENV fi # iOS: Update Firestore external version to match Firestore Cocoapod version. @@ -165,7 +158,7 @@ jobs: elif [[ ${{ github.event.inputs.updateAndroid }} -eq 1 ]]; then # Update Android only echo "Updating Android dependencies only" - python scripts/update_android_ios_dependencies.py --skip_ios --logfile=${UPDATE_LOGFILE} ${gma_flag} + python scripts/update_android_ios_dependencies.py --skip_ios --logfile=${UPDATE_LOGFILE} echo "CHOSEN_DEPS=Android" >> $GITHUB_ENV else echo "::error ::Neither Android nor iOS selected. Exiting." diff --git a/Android/firebase_dependencies.gradle b/Android/firebase_dependencies.gradle index 94b39ec52c..c7a19de54b 100644 --- a/Android/firebase_dependencies.gradle +++ b/Android/firebase_dependencies.gradle @@ -27,8 +27,6 @@ def firebaseDependenciesMap = [ 'dynamic_links' : ['com.google.firebase:firebase-dynamic-links'], 'firestore' : ['com.google.firebase:firebase-firestore'], 'functions' : ['com.google.firebase:firebase-functions'], - 'gma' : ['com.google.android.gms:play-services-ads:23.0.0', - 'com.google.android.ump:user-messaging-platform:2.2.0'], 'installations' : ['com.google.firebase:firebase-installations'], 'invites' : ['com.google.firebase:firebase-invites'], // Messaging has an additional local dependency to include. @@ -52,7 +50,6 @@ def firebaseResourceDependenciesMap = [ 'auth' : [':auth:auth_resources'], 'database' : [':database:database_resources'], 'firestore' : [':firestore:firestore_resources'], - 'gma' : [':gma:gma_resources'], 'remote_config' : [':remote_config:remote_config_resources'], 'storage' : [':storage:storage_resources'], 'ump' : [':ump:ump_resources'] @@ -94,9 +91,6 @@ class Dependencies { def getFirestore() { libSet.add('firestore') } - def getGma() { - libSet.add('gma') - } def getFunctions() { libSet.add('functions') } diff --git a/CMakeLists.txt b/CMakeLists.txt index aea6d80a34..a5a505120e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,8 +48,6 @@ option(FIREBASE_INCLUDE_FIRESTORE option(FIREBASE_INCLUDE_FUNCTIONS "Include the Cloud Functions for Firebase library." ${FIREBASE_INCLUDE_LIBRARY_DEFAULT}) -option(FIREBASE_INCLUDE_GMA "Include the GMA library." - ${FIREBASE_INCLUDE_LIBRARY_DEFAULT}) option(FIREBASE_INCLUDE_UMP "Include the UMP library." ${FIREBASE_INCLUDE_LIBRARY_DEFAULT}) option(FIREBASE_INCLUDE_INSTALLATIONS @@ -125,9 +123,8 @@ if(FIREBASE_CPP_BUILD_TESTS OR FIREBASE_CPP_BUILD_STUB_TESTS) endif() if (PLATFORM STREQUAL TVOS OR PLATFORM STREQUAL SIMULATOR_TVOS) - # GMA, UMP, and FDL are not supported on tvOS. + # UMP and FDL are not supported on tvOS. set(FIREBASE_INCLUDE_DYNAMIC_LINKS OFF) - set(FIREBASE_INCLUDE_GMA OFF) set(FIREBASE_INCLUDE_UMP OFF) endif() @@ -635,9 +632,6 @@ endif() if (FIREBASE_INCLUDE_FUNCTIONS) add_subdirectory(functions) endif() -if (FIREBASE_INCLUDE_GMA) - add_subdirectory(gma) -endif() if (FIREBASE_INCLUDE_UMP) add_subdirectory(ump) endif() diff --git a/README.md b/README.md index 6a829a9a07..9332931fba 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,8 @@ iOS, and desktop platforms. It includes the following Firebase libraries: |[Google Analytics for Firebase](https://firebase.google.com/docs/analytics/)| |[Firebase Authentication](https://firebase.google.com/docs/auth/)|[Firebase Realtime Database](https://firebase.google.com/docs/database/)| |[Firebase Dynamic Links](https://firebase.google.com/docs/dynamic-links/)|[Cloud Firestore](https://firebase.google.com/docs/firestore/)| -|[Cloud Functions for Firebase](https://firebase.google.com/docs/functions/)|[Firebase Invites](https://firebase.google.com/docs/invites/)| -|[Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging/)|[Firebase Remote Config](https://firebase.google.com/docs/remote-config/)| -|[Cloud Storage for Firebase](https://firebase.google.com/docs/storage/)| +|[Cloud Functions for Firebase](https://firebase.google.com/docs/functions/)|[Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging/)| +|[Firebase Remote Config](https://firebase.google.com/docs/remote-config/)|[Cloud Storage for Firebase](https://firebase.google.com/docs/storage/)|
@@ -117,7 +116,6 @@ The CMake following targets are available to build and link with: | Firebase Dynamic Links | firebase_dynamic_links | | Cloud Firestore | firebase_firestore | | Cloud Functions for Firebase | firebase_functions | -| Firebase Invites | firebase_invites | | Firebase Cloud Messaging | firebase_messaging | | Firebase Remote Config | firebase_remote_config | | Cloud Storage for Firebase | firebase_storage | @@ -222,7 +220,6 @@ release version of each Firebase library is: | Firebase Dynamic Links | :dynamic_links:assembleRelease | | Cloud Firestore | :firestore:assembleRelease | | Cloud Functions for Firebase | :functions:assembleRelease | -| Firebase Invites | :invites:assembleRelease | | Firebase Cloud Messaging | :messaging:assembleRelease | | Firebase Remote Config | :remote_config:assembleRelease | | Cloud Storage for Firebase | :storage:assembleRelease | diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 9b2d0b333a..6b1108ac31 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -541,17 +541,6 @@ if (IOS) ${FIREBASE_SOURCE_DIR}/functions/src/include/firebase/functions/callable_reference.h ${FIREBASE_SOURCE_DIR}/functions/src/include/firebase/functions/callable_result.h ${FIREBASE_SOURCE_DIR}/functions/src/include/firebase/functions/common.h) - set(gma_HDRS - ${FIREBASE_SOURCE_DIR}/gma/src/include/firebase/gma.h - ${FIREBASE_SOURCE_DIR}/gma/src/include/firebase/gma/ad_view.h - ${FIREBASE_SOURCE_DIR}/gma/src/include/firebase/gma/interstitial_ad.h - ${FIREBASE_SOURCE_DIR}/gma/src/include/firebase/gma/internal/native_ad.h - ${FIREBASE_SOURCE_DIR}/gma/src/include/firebase/gma/internal/query_info.h - ${FIREBASE_SOURCE_DIR}/gma/src/include/firebase/gma/rewarded_ad.h - ${FIREBASE_SOURCE_DIR}/gma/src/include/firebase/gma/types.h - ${FIREBASE_SOURCE_DIR}/gma/src/include/firebase/gma/ump.h - ${FIREBASE_SOURCE_DIR}/gma/src/include/firebase/gma/ump/consent_info.h - ${FIREBASE_SOURCE_DIR}/gma/src/include/firebase/gma/ump/types.h) set(installations_HDRS ${FIREBASE_SOURCE_DIR}/installations/src/include/firebase/installations.h) set(messaging_HDRS @@ -580,7 +569,6 @@ if (IOS) ${dynamic_links_HDRS} ${firestore_HDRS} ${functions_HDRS} - ${gma_HDRS} ${installations_HDRS} ${messaging_HDRS} ${remote_config_HDRS} diff --git a/build_scripts/ios/build.sh b/build_scripts/ios/build.sh index c466d35af7..f21e4ff36e 100755 --- a/build_scripts/ios/build.sh +++ b/build_scripts/ios/build.sh @@ -27,7 +27,7 @@ readonly SUPPORTED_PLATFORMS=(device simulator) readonly SUPPORTED_ARCHITECTURES=(arm64 x86_64) readonly DEVICE_ARCHITECTURES=(arm64) readonly SIMULATOR_ARCHITECTURES=(arm64 x86_64) -readonly SUPPORTED_TARGETS=(firebase_analytics firebase_auth firebase_app_check firebase_database firebase_dynamic_links firebase_firestore firebase_functions firebase_gma firebase_installations firebase_messaging firebase_remote_config firebase_storage firebase_ump) +readonly SUPPORTED_TARGETS=(firebase_analytics firebase_auth firebase_app_check firebase_database firebase_dynamic_links firebase_firestore firebase_functions firebase_installations firebase_messaging firebase_remote_config firebase_storage firebase_ump) # build default value buildpath="ios_build" diff --git a/build_scripts/packaging.conf b/build_scripts/packaging.conf index 8f1ee6f401..5010b2c4a2 100644 --- a/build_scripts/packaging.conf +++ b/build_scripts/packaging.conf @@ -2,5 +2,5 @@ # List of all Firebase products to include in the binary SDK package. readonly -a product_list=(analytics app app_check auth database -dynamic_links firestore functions gma installations messaging +dynamic_links firestore functions installations messaging remote_config storage ump) diff --git a/docs/Doxyfile b/docs/Doxyfile index fabb54e5da..fea93c1f66 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -13,7 +13,7 @@ SORT_GROUP_NAMES = YES JAVADOC_AUTOBRIEF = YES # Firebase-specific options. -PREDEFINED = DOXYGEN DOXYGEN_ADMOB FIREBASE_DEPRECATED FIREBASE_NAMESPACE=firebase +PREDEFINED = DOXYGEN FIREBASE_DEPRECATED FIREBASE_NAMESPACE=firebase MACRO_EXPANSION = YES # Expand FIREBASE_DEPRECATED macros. EXPAND_ONLY_PREDEF = YES # Expand FIREBASE_DEPRECATED macros. VERBATIM_HEADERS = NO diff --git a/gma/CMakeLists.txt b/gma/CMakeLists.txt deleted file mode 100644 index 2b0b225740..0000000000 --- a/gma/CMakeLists.txt +++ /dev/null @@ -1,156 +0,0 @@ -# Copyright 2021 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# CMake file for the firebase_gma library - -# Common source files used by all platforms -set(common_SRCS - src/common/ump/consent_info.cc - src/common/ump/consent_info_internal.cc - src/common/gma_common.cc - src/common/ad_view.cc - src/common/ad_view_internal.cc - src/common/interstitial_ad.cc - src/common/interstitial_ad_internal.cc - src/common/full_screen_ad_event_listener.cc - src/common/native_ad.cc - src/common/native_ad_internal.cc - src/common/query_info.cc - src/common/query_info_internal.cc - src/common/rewarded_ad.cc - src/common/rewarded_ad_internal.cc) - -# Define the resource build needed for Android -firebase_cpp_gradle(":gma:gma_resources:generateDexJarRelease" - "${CMAKE_CURRENT_LIST_DIR}/gma_resources/build/gma_resources_lib.jar") -binary_to_array("gma_resources" - "${CMAKE_CURRENT_LIST_DIR}/gma_resources/build/gma_resources_lib.jar" - "firebase_gma" - "${FIREBASE_GEN_FILE_DIR}/gma") - -# Source files used by the Android implementation. -set(android_SRCS - ${gma_resources_source} - src/android/ump/consent_info_internal_android.cc - src/android/ad_request_converter.cc - src/android/ad_error_android.cc - src/android/adapter_response_info_android.cc - src/android/gma_android.cc - src/android/ad_view_internal_android.cc - src/android/interstitial_ad_internal_android.cc - src/android/native_ad_image_android.cc - src/android/native_ad_internal_android.cc - src/android/query_info_internal_android.cc - src/android/response_info_android.cc - src/android/rewarded_ad_internal_android.cc) - -# Source files used by the iOS implementation. -set(ios_SRCS - src/ios/ump/consent_info_internal_ios.mm - src/ios/FADAdSize.mm - src/ios/FADAdView.mm - src/ios/FADInterstitialDelegate.mm - src/ios/FADNativeDelegate.mm - src/ios/FADRequest.mm - src/ios/FADRewardedAdDelegate.mm - src/ios/ad_error_ios.mm - src/ios/adapter_response_info_ios.mm - src/ios/gma_ios.mm - src/ios/ad_view_internal_ios.mm - src/ios/interstitial_ad_internal_ios.mm - src/ios/native_ad_image_ios.mm - src/ios/native_ad_internal_ios.mm - src/ios/query_info_internal_ios.mm - src/ios/response_info_ios.mm - src/ios/rewarded_ad_internal_ios.mm) - -# Source files used by the stub implementation. -set(stub_SRCS - src/stub/ump/consent_info_internal_stub.cc - src/stub/ad_error_stub.cc - src/stub/adapter_response_info_stub.cc - src/stub/gma_stub.cc - src/stub/native_ad_image_stub.cc - src/stub/response_info_stub.cc) - -if(ANDROID) - set(gma_platform_SRCS - "${android_SRCS}") -elseif(IOS) - set(gma_platform_SRCS - "${ios_SRCS}") -else() - set(gma_platform_SRCS - "${stub_SRCS}") -endif() - -add_library(firebase_gma STATIC - ${common_SRCS} - ${gma_platform_SRCS}) - -set_property(TARGET firebase_gma PROPERTY FOLDER "Firebase Cpp") - -# Set up the dependency on Firebase App. -target_link_libraries(firebase_gma - PUBLIC firebase_app) -# Public headers all refer to each other relative to the src/include directory, -# while private headers are relative to the entire C++ SDK directory. -target_include_directories(firebase_gma - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/src/include - PRIVATE - ${FIREBASE_CPP_SDK_ROOT_DIR} -) -target_compile_definitions(firebase_gma - PRIVATE - -DINTERNAL_EXPERIMENTAL=1 -) -# Automatically include headers that might not be declared. -if(MSVC) - add_definitions(/FI"assert.h" /FI"string.h" /FI"stdint.h") -else() - add_definitions(-include assert.h -include string.h) -endif() - -if(ANDROID) - firebase_cpp_proguard_file(gma) -elseif(IOS) - # GMA for iOS uses weak references, which requires enabling Automatic - # Reference Counting (ARC). Also enable BitCode. - target_compile_options(firebase_gma - PUBLIC "-fobjc-arc" "-fembed-bitcode") - target_link_libraries(firebase_gma - PUBLIC "-fembed-bitcode") - - setup_pod_headers( - firebase_gma - POD_NAMES - Google-Mobile-Ads-SDK - GoogleUserMessagingPlatform - ) - - # GMA expects the header files to be in a subfolder, so set up a symlink to - # accomplish that. - symlink_pod_headers(firebase_gma Google-Mobile-Ads-SDK GoogleMobileAds) - symlink_pod_headers(firebase_gma GoogleUserMessagingPlatform UserMessagingPlatform) - - if (FIREBASE_XCODE_TARGET_FORMAT STREQUAL "frameworks") - set_target_properties(firebase_gma PROPERTIES - FRAMEWORK TRUE - ) - endif() -endif() - -cpp_pack_library(firebase_gma "") -cpp_pack_public_headers() diff --git a/gma/build.gradle b/gma/build.gradle deleted file mode 100644 index 9b54eea9f6..0000000000 --- a/gma/build.gradle +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2021 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -buildscript { - repositories { - google() - mavenCentral() - } - dependencies { - classpath 'com.android.tools.build:gradle:7.4.2' - } -} -allprojects { - repositories { - google() - mavenCentral() - } -} - -apply plugin: 'com.android.library' - -android { - compileSdkVersion 34 - ndkPath System.getenv('ANDROID_NDK_HOME') - buildToolsVersion '32.0.0' - - sourceSets { - main { - manifest.srcFile '../android_build_files/AndroidManifest.xml' - } - } - - externalNativeBuild { - cmake { - path '../CMakeLists.txt' - } - } - - defaultConfig { - minSdkVersion 23 - targetSdkVersion 34 - versionCode 1 - versionName "1.0" - - buildTypes { - release { - minifyEnabled false - } - } - - externalNativeBuild { - cmake { - targets 'firebase_gma' - // Args are: Re-use app library prebuilt by app gradle project. - // Don't configure all the cmake subprojects. - // Only include needed project. - arguments '-DFIREBASE_CPP_USE_PRIOR_GRADLE_BUILD=ON', - '-DFIREBASE_INCLUDE_LIBRARY_DEFAULT=OFF', - '-DFIREBASE_INCLUDE_GMA=ON' - } - } - } - - lintOptions { - abortOnError false - } -} - -dependencies { - implementation project(':app') -} -apply from: "$rootDir/android_build_files/android_abis.gradle" -apply from: "$rootDir/android_build_files/extract_and_dex.gradle" -apply from: "$rootDir/android_build_files/generate_proguard.gradle" -project.afterEvaluate { - generateProguardFile('gma') - setupDexDependencies(':gma:gma_resources') - preBuild.dependsOn(':app:build') - project.tasks.withType(com.android.build.gradle.internal.tasks.CheckAarMetadataTask) { - enabled = false - } -} diff --git a/gma/gma_additional.pro b/gma/gma_additional.pro deleted file mode 100644 index 57edbf9017..0000000000 --- a/gma/gma_additional.pro +++ /dev/null @@ -1,2 +0,0 @@ -# Additional ProGuard rules needed for the AdMob library. --keep class com.google.ads.mediation.admob.AdMobAdapter { *; } diff --git a/gma/gma_resources/AndroidManifest.xml b/gma/gma_resources/AndroidManifest.xml deleted file mode 100644 index 66236bd0d6..0000000000 --- a/gma/gma_resources/AndroidManifest.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - diff --git a/gma/gma_resources/build.gradle b/gma/gma_resources/build.gradle deleted file mode 100644 index dc9007d063..0000000000 --- a/gma/gma_resources/build.gradle +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2021 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -buildscript { - repositories { - google() - mavenCentral() - } - dependencies { - classpath 'com.android.tools.build:gradle:7.4.2' - classpath 'com.google.gms:google-services:4.4.1' - } -} -allprojects { - repositories { - google() - mavenCentral() - } -} - -apply plugin: 'com.android.library' - -android { - compileOptions { - sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 - } - - compileSdkVersion 34 - buildToolsVersion '32.0.0' - - defaultConfig { - minSdkVersion 23 - targetSdkVersion 34 - } - - sourceSets { - main { - manifest.srcFile 'AndroidManifest.xml' - java { - srcDirs = ['../src_java/com/google/firebase/gma/internal/cpp'] - } - } - } -} - -dependencies { - implementation platform('com.google.firebase:firebase-bom:33.15.0') - implementation 'com.google.firebase:firebase-analytics' - implementation 'com.google.android.gms:play-services-ads:23.0.0' - implementation 'com.google.android.ump:user-messaging-platform:2.2.0' -} - -afterEvaluate { - generateReleaseBuildConfig.enabled = false - project.tasks.withType(com.android.build.gradle.internal.tasks.CheckAarMetadataTask) { - enabled = false - } -} - -apply from: "$rootDir/android_build_files/extract_and_dex.gradle" -extractAndDexAarFile('gma_resources') diff --git a/gma/integration_test/AndroidManifest.xml b/gma/integration_test/AndroidManifest.xml deleted file mode 100644 index 8aa98a1958..0000000000 --- a/gma/integration_test/AndroidManifest.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/gma/integration_test/CMakeLists.txt b/gma/integration_test/CMakeLists.txt deleted file mode 100644 index 29c6a6e4d1..0000000000 --- a/gma/integration_test/CMakeLists.txt +++ /dev/null @@ -1,242 +0,0 @@ -# Copyright 2021 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Cmake file for a single C++ integration test build. - -cmake_minimum_required(VERSION 2.8) - -find_program(FIREBASE_PYTHON_EXECUTABLE - NAMES python3 python - DOC "The Python interpreter to use, such as one from a venv" - REQUIRED -) - -# User settings for Firebase integration tests. -# Path to Firebase SDK. -# Try to read the path to the Firebase C++ SDK from an environment variable. -if (NOT "$ENV{FIREBASE_CPP_SDK_DIR}" STREQUAL "") - set(DEFAULT_FIREBASE_CPP_SDK_DIR "$ENV{FIREBASE_CPP_SDK_DIR}") -else() - if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/../../cpp_sdk_version.json") - set(DEFAULT_FIREBASE_CPP_SDK_DIR "${CMAKE_CURRENT_LIST_DIR}/../..") - else() - set(DEFAULT_FIREBASE_CPP_SDK_DIR "firebase_cpp_sdk") - endif() -endif() -if ("${FIREBASE_CPP_SDK_DIR}" STREQUAL "") - set(FIREBASE_CPP_SDK_DIR ${DEFAULT_FIREBASE_CPP_SDK_DIR}) -endif() -if(NOT EXISTS ${FIREBASE_CPP_SDK_DIR}) - message(FATAL_ERROR "The Firebase C++ SDK directory does not exist: ${FIREBASE_CPP_SDK_DIR}. See the readme.md for more information") -endif() - -# Copy all prerequisite files for integration tests to run. -if(NOT ANDROID) - if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/../../setup_integration_tests.py) - # If this is running from inside the SDK directory, run the setup script. - execute_process( - COMMAND - ${FIREBASE_PYTHON_EXECUTABLE} - "${CMAKE_CURRENT_LIST_DIR}/../../setup_integration_tests.py" - "${CMAKE_CURRENT_LIST_DIR}" - RESULT_VARIABLE - FIREBASE_PYTHON_EXECUTABLE_RESULT - ) - if(NOT FIREBASE_PYTHON_EXECUTABLE_RESULT EQUAL 0) - message(FATAL_ERROR "Failed to run setup_integration_tests.py") - endif() - endif() -endif() - -# Windows runtime mode, either MD or MT depending on whether you are using -# /MD or /MT. For more information see: -# https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx -set(MSVC_RUNTIME_MODE MD) - -project(firebase_testapp) - -# Integration test source files. -set(FIREBASE_APP_FRAMEWORK_SRCS - src/app_framework.cc - src/app_framework.h -) - -set(FIREBASE_TEST_FRAMEWORK_SRCS - src/firebase_test_framework.h - src/firebase_test_framework.cc -) - -set(FIREBASE_INTEGRATION_TEST_SRCS - src/integration_test.cc -) - -# The include directory for the testapp. -include_directories(src) - -# Firebase C++ SDK requires C++14. -set (CMAKE_CXX_STANDARD 14) -set (CMAKE_CXX_STANDARD_REQUIRED YES) # Don't fall back to an earlier version. - -# Download and unpack googletest (and googlemock) at configure time -set(GOOGLETEST_ROOT ${CMAKE_CURRENT_LIST_DIR}/external/googletest) -# Note: Once googletest is downloaded once, it won't be updated or -# downloaded again unless you delete the "external/googletest" -# directory. -if (NOT EXISTS ${GOOGLETEST_ROOT}/src/googletest/src/gtest-all.cc) - configure_file(googletest.cmake - ${CMAKE_CURRENT_LIST_DIR}/external/googletest/CMakeLists.txt COPYONLY) - execute_process(COMMAND ${CMAKE_COMMAND} . - RESULT_VARIABLE result - WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/external/googletest ) - if(result) - message(FATAL_ERROR "CMake step for googletest failed: ${result}") - endif() - execute_process(COMMAND ${CMAKE_COMMAND} --build . - RESULT_VARIABLE result - WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/external/googletest ) - if(result) - message(FATAL_ERROR "Build step for googletest failed: ${result}") - endif() -endif() - -if(ANDROID) - # Build an Android application. - - # Source files used for the Android build. - set(FIREBASE_APP_FRAMEWORK_ANDROID_SRCS - src/android/android_app_framework.cc - ) - - # Source files used for the Android build. - set(FIREBASE_TEST_FRAMEWORK_ANDROID_SRCS - src/android/android_firebase_test_framework.cc - ) - - # Build native_app_glue as a static lib - add_library(native_app_glue STATIC - ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c) - - # Export ANativeActivity_onCreate(), - # Refer to: https://github.com/android-ndk/ndk/issues/381. - set(CMAKE_SHARED_LINKER_FLAGS - "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate") - - add_library(gtest STATIC - ${GOOGLETEST_ROOT}/src/googletest/src/gtest-all.cc) - target_include_directories(gtest - PRIVATE ${GOOGLETEST_ROOT}/src/googletest - PUBLIC ${GOOGLETEST_ROOT}/src/googletest/include) - add_library(gmock STATIC - ${GOOGLETEST_ROOT}/src/googlemock/src/gmock-all.cc) - target_include_directories(gmock - PRIVATE ${GOOGLETEST_ROOT}/src/googletest - PRIVATE ${GOOGLETEST_ROOT}/src/googlemock - PUBLIC ${GOOGLETEST_ROOT}/src/googletest/include - PUBLIC ${GOOGLETEST_ROOT}/src/googlemock/include) - - # Define the target as a shared library, as that is what gradle expects. - set(integration_test_target_name "android_integration_test_main") - add_library(${integration_test_target_name} SHARED - ${FIREBASE_APP_FRAMEWORK_SRCS} - ${FIREBASE_APP_FRAMEWORK_ANDROID_SRCS} - ${FIREBASE_INTEGRATION_TEST_SRCS} - ${FIREBASE_TEST_FRAMEWORK_SRCS} - ${FIREBASE_TEST_FRAMEWORK_ANDROID_SRCS} - ) - - target_include_directories(${integration_test_target_name} PRIVATE - ${ANDROID_NDK}/sources/android/native_app_glue) - - set(ADDITIONAL_LIBS log android atomic native_app_glue) -else() - # Build a desktop application. - add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) - - # Prevent overriding the parent project's compiler/linker - # settings on Windows - set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - - # Add googletest directly to our build. This defines - # the gtest and gtest_main targets. - add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/external/googletest/src - ${CMAKE_CURRENT_LIST_DIR}/external/googletest/build - EXCLUDE_FROM_ALL) - - # The gtest/gtest_main targets carry header search path - # dependencies automatically when using CMake 2.8.11 or - # later. Otherwise we have to add them here ourselves. - if (CMAKE_VERSION VERSION_LESS 2.8.11) - include_directories("${gtest_SOURCE_DIR}/include") - include_directories("${gmock_SOURCE_DIR}/include") - endif() - - # Windows runtime mode, either MD or MT depending on whether you are using - # /MD or /MT. For more information see: - # https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx - set(MSVC_RUNTIME_MODE MD) - - # Platform abstraction layer for the desktop integration test. - set(FIREBASE_APP_FRAMEWORK_DESKTOP_SRCS - src/desktop/desktop_app_framework.cc - src/desktop/desktop_firebase_test_framework.cc - ) - - set(integration_test_target_name "integration_test") - add_executable(${integration_test_target_name} - ${FIREBASE_APP_FRAMEWORK_SRCS} - ${FIREBASE_APP_FRAMEWORK_DESKTOP_SRCS} - ${FIREBASE_TEST_FRAMEWORK_SRCS} - ${FIREBASE_INTEGRATION_TEST_SRCS} - ) - - if(APPLE) - set(ADDITIONAL_LIBS - gssapi_krb5 - pthread - "-framework CoreFoundation" - "-framework Foundation" - "-framework GSS" - "-framework Security" - ) - elseif(MSVC) - set(ADDITIONAL_LIBS advapi32 ws2_32 crypt32) - else() - set(ADDITIONAL_LIBS pthread) - endif() - - # If a config file is present, copy it into the binary location so that it's - # possible to create the default Firebase app. - set(FOUND_JSON_FILE FALSE) - foreach(config "google-services-desktop.json" "google-services.json") - if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/${config}") - add_custom_command( - TARGET ${integration_test_target_name} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - "${CMAKE_CURRENT_LIST_DIR}/${config}" $) - set(FOUND_JSON_FILE TRUE) - break() - endif() - endforeach() - if(NOT FOUND_JSON_FILE) - message(WARNING "Failed to find either google-services-desktop.json or google-services.json. See the readme.md for more information.") - endif() -endif() - -# Add the Firebase libraries to the target using the function from the SDK. -add_subdirectory(${FIREBASE_CPP_SDK_DIR} bin/ EXCLUDE_FROM_ALL) -# Note that firebase_app needs to be last in the list. -set(firebase_libs firebase_gma firebase_app) -set(gtest_libs gtest gmock) -target_link_libraries(${integration_test_target_name} ${firebase_libs} - ${gtest_libs} ${ADDITIONAL_LIBS}) diff --git a/gma/integration_test/Images.xcassets/AppIcon.appiconset/Contents.json b/gma/integration_test/Images.xcassets/AppIcon.appiconset/Contents.json deleted file mode 100644 index d8db8d65fd..0000000000 --- a/gma/integration_test/Images.xcassets/AppIcon.appiconset/Contents.json +++ /dev/null @@ -1,98 +0,0 @@ -{ - "images" : [ - { - "idiom" : "iphone", - "size" : "20x20", - "scale" : "2x" - }, - { - "idiom" : "iphone", - "size" : "20x20", - "scale" : "3x" - }, - { - "idiom" : "iphone", - "size" : "29x29", - "scale" : "2x" - }, - { - "idiom" : "iphone", - "size" : "29x29", - "scale" : "3x" - }, - { - "idiom" : "iphone", - "size" : "40x40", - "scale" : "2x" - }, - { - "idiom" : "iphone", - "size" : "40x40", - "scale" : "3x" - }, - { - "idiom" : "iphone", - "size" : "60x60", - "scale" : "2x" - }, - { - "idiom" : "iphone", - "size" : "60x60", - "scale" : "3x" - }, - { - "idiom" : "ipad", - "size" : "20x20", - "scale" : "1x" - }, - { - "idiom" : "ipad", - "size" : "20x20", - "scale" : "2x" - }, - { - "idiom" : "ipad", - "size" : "29x29", - "scale" : "1x" - }, - { - "idiom" : "ipad", - "size" : "29x29", - "scale" : "2x" - }, - { - "idiom" : "ipad", - "size" : "40x40", - "scale" : "1x" - }, - { - "idiom" : "ipad", - "size" : "40x40", - "scale" : "2x" - }, - { - "idiom" : "ipad", - "size" : "76x76", - "scale" : "1x" - }, - { - "idiom" : "ipad", - "size" : "76x76", - "scale" : "2x" - }, - { - "idiom" : "ipad", - "size" : "83.5x83.5", - "scale" : "2x" - }, - { - "idiom" : "ios-marketing", - "size" : "1024x1024", - "scale" : "1x" - } - ], - "info" : { - "version" : 1, - "author" : "xcode" - } -} \ No newline at end of file diff --git a/gma/integration_test/Images.xcassets/LaunchImage.launchimage/Contents.json b/gma/integration_test/Images.xcassets/LaunchImage.launchimage/Contents.json deleted file mode 100644 index 6f870a4629..0000000000 --- a/gma/integration_test/Images.xcassets/LaunchImage.launchimage/Contents.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "images" : [ - { - "orientation" : "portrait", - "idiom" : "iphone", - "extent" : "full-screen", - "minimum-system-version" : "7.0", - "scale" : "2x" - }, - { - "orientation" : "portrait", - "idiom" : "iphone", - "subtype" : "retina4", - "extent" : "full-screen", - "minimum-system-version" : "7.0", - "scale" : "2x" - }, - { - "orientation" : "portrait", - "idiom" : "ipad", - "extent" : "full-screen", - "minimum-system-version" : "7.0", - "scale" : "1x" - }, - { - "orientation" : "landscape", - "idiom" : "ipad", - "extent" : "full-screen", - "minimum-system-version" : "7.0", - "scale" : "1x" - }, - { - "orientation" : "portrait", - "idiom" : "ipad", - "extent" : "full-screen", - "minimum-system-version" : "7.0", - "scale" : "2x" - }, - { - "orientation" : "landscape", - "idiom" : "ipad", - "extent" : "full-screen", - "minimum-system-version" : "7.0", - "scale" : "2x" - } - ], - "info" : { - "version" : 1, - "author" : "xcode" - } -} \ No newline at end of file diff --git a/gma/integration_test/Info.plist b/gma/integration_test/Info.plist deleted file mode 100644 index 953571e326..0000000000 --- a/gma/integration_test/Info.plist +++ /dev/null @@ -1,41 +0,0 @@ - - - - - GADApplicationIdentifier - ca-app-pub-3940256099942544~1458002511 - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - APPL - CFBundleShortVersionString - 1.0 - CFBundleVersion - 1 - LSRequiresIPhoneOS - - UILaunchStoryboardName - LaunchScreen - NSUserTrackingUsageDescription - This identifier will be used to deliver personalized ads to you. - CFBundleURLTypes - - - CFBundleURLSchemes - - REPLACE_WITH_REVERSED_CLIENT_ID - firebase-game-loop - firebase-ui-test - - - - - diff --git a/gma/integration_test/LaunchScreen.storyboard b/gma/integration_test/LaunchScreen.storyboard deleted file mode 100644 index 673e0f7e68..0000000000 --- a/gma/integration_test/LaunchScreen.storyboard +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/gma/integration_test/LibraryManifest.xml b/gma/integration_test/LibraryManifest.xml deleted file mode 100644 index a5db8d174d..0000000000 --- a/gma/integration_test/LibraryManifest.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - diff --git a/gma/integration_test/Podfile b/gma/integration_test/Podfile deleted file mode 100644 index c0d08178b1..0000000000 --- a/gma/integration_test/Podfile +++ /dev/null @@ -1,18 +0,0 @@ -source 'https://github.com/CocoaPods/Specs.git' -platform :ios, '13.0' -# Firebase GMA test application. -use_frameworks! :linkage => :static - -target 'integration_test' do - platform :ios, '13.0' - pod 'Firebase/CoreOnly', '11.14.0' - pod 'Google-Mobile-Ads-SDK', '11.2.0' - pod 'GoogleUserMessagingPlatform', '2.3.0' -end - -post_install do |installer| - # If this is running from inside the SDK directory, run the setup script. - system("if [[ -r ../../setup_integration_tests.py ]]; then python3 ../../setup_integration_tests.py .; fi") - system("python3 ./download_googletest.py") -end - diff --git a/gma/integration_test/build.gradle b/gma/integration_test/build.gradle deleted file mode 100644 index 16f9d2b87e..0000000000 --- a/gma/integration_test/build.gradle +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2021 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Top-level build file where you can add configuration options common to all sub-projects/modules. -buildscript { - repositories { - mavenLocal() - maven { url 'https://maven.google.com' } - mavenCentral() - } - dependencies { - classpath 'com.android.tools.build:gradle:7.4.2' - // r8 on this version of the Android tools has a bug, - // so specify a different version to use. - classpath 'com.android.tools:r8:8.3.37' - classpath 'com.google.gms:google-services:4.4.1' - } -} - -allprojects { - repositories { - mavenLocal() - maven { url 'https://maven.google.com' } - mavenCentral() - } -} - -apply plugin: 'com.android.application' - -android { - compileOptions { - sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 - } - compileSdkVersion 34 - ndkPath System.getenv('ANDROID_NDK_HOME') - buildToolsVersion '32.0.0' - - sourceSets { - main { - jniLibs.srcDirs = ['libs'] - manifest.srcFile 'AndroidManifest.xml' - java.srcDirs = ['src/android/java'] - res.srcDirs = ['res'] - } - } - - defaultConfig { - applicationId 'com.google.android.admob.testapp' - minSdkVersion 23 - targetSdkVersion 34 - versionCode 1 - versionName '1.0' - externalNativeBuild.cmake { - arguments "-DFIREBASE_CPP_SDK_DIR=$gradle.firebase_cpp_sdk_dir" - } - multiDexEnabled true - } - externalNativeBuild.cmake { - path 'CMakeLists.txt' - } - buildTypes { - release { - minifyEnabled true - proguardFile getDefaultProguardFile('proguard-android.txt') - proguardFile file('proguard.pro') - } - } - lintOptions { - abortOnError false - } -} - -apply from: "$gradle.firebase_cpp_sdk_dir/Android/firebase_dependencies.gradle" -firebaseCpp.dependencies { - gma -} - -apply plugin: 'com.google.gms.google-services' - -task copyIntegrationTestFiles(type:Exec) { - // If this is running form inside the SDK directory, run the setup script. - if (project.file('../../setup_integration_tests.py').exists()) { - commandLine 'python3', '../../setup_integration_tests.py', project.projectDir.toString() - } - else { - commandLine 'echo', '' - } -} - -build.dependsOn(copyIntegrationTestFiles) - -project.afterEvaluate { - project.tasks.withType(com.android.build.gradle.internal.tasks.CheckAarMetadataTask) { - enabled = false - } -} diff --git a/gma/integration_test/empty.swift b/gma/integration_test/empty.swift deleted file mode 100644 index b637790955..0000000000 --- a/gma/integration_test/empty.swift +++ /dev/null @@ -1,9 +0,0 @@ -// -// empty.swift -// integration_test -// -// Created by David Della Bitta on 5/12/22. -// Copyright © 2022 Google. All rights reserved. -// - -import Foundation diff --git a/gma/integration_test/googletest.cmake b/gma/integration_test/googletest.cmake deleted file mode 100644 index a643a3e2f2..0000000000 --- a/gma/integration_test/googletest.cmake +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright 2021 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Download GoogleTest from GitHub as an external project. -# Pin to 1.11.0 because we touch internal GoogleTest structures that could change in the future. - -# This CMake file is taken from: -# https://github.com/google/googletest/blob/master/googletest/README.md#incorporating-into-an-existing-cmake-project - -cmake_minimum_required(VERSION 2.8.2) - -project(googletest-download NONE) - -include(ExternalProject) -ExternalProject_Add(googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG "release-1.11.0" - SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/src" - BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/build" - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - TEST_COMMAND "" -) diff --git a/gma/integration_test/gradle.properties b/gma/integration_test/gradle.properties deleted file mode 100644 index ac891ac594..0000000000 --- a/gma/integration_test/gradle.properties +++ /dev/null @@ -1,2 +0,0 @@ -android.useAndroidX = true -org.gradle.jvmargs=-Xmx2560m diff --git a/gma/integration_test/gradle/wrapper/gradle-wrapper.jar b/gma/integration_test/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 8c0fb64a86..0000000000 Binary files a/gma/integration_test/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/gma/integration_test/gradle/wrapper/gradle-wrapper.properties b/gma/integration_test/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 2eb04a3b17..0000000000 --- a/gma/integration_test/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Mon Nov 27 14:03:45 PST 2017 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https://services.gradle.org/distributions/gradle-7.5.1-all.zip diff --git a/gma/integration_test/gradlew b/gma/integration_test/gradlew deleted file mode 100755 index 06eaee39e2..0000000000 --- a/gma/integration_test/gradlew +++ /dev/null @@ -1,178 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright 2021 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn ( ) { - echo "$*" -} - -die ( ) { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; -esac - -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- -APP_HOME="`pwd -P`" -cd "$SAVED" >&- - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" - -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gma/integration_test/gradlew.bat b/gma/integration_test/gradlew.bat deleted file mode 100644 index 51923e981d..0000000000 --- a/gma/integration_test/gradlew.bat +++ /dev/null @@ -1,104 +0,0 @@ -@rem Copyright 2021 Google LLC -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem http://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windowz variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/gma/integration_test/integration_test.xcodeproj/project.pbxproj b/gma/integration_test/integration_test.xcodeproj/project.pbxproj deleted file mode 100644 index 3f0c3ff6ad..0000000000 --- a/gma/integration_test/integration_test.xcodeproj/project.pbxproj +++ /dev/null @@ -1,383 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 520BC0391C869159008CFBC3 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 520BC0381C869159008CFBC3 /* GoogleService-Info.plist */; }; - 529226D61C85F68000C89379 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 529226D51C85F68000C89379 /* Foundation.framework */; }; - 529226D81C85F68000C89379 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 529226D71C85F68000C89379 /* CoreGraphics.framework */; }; - 529226DA1C85F68000C89379 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 529226D91C85F68000C89379 /* UIKit.framework */; }; - D61C5F8E22BABA9C00A79141 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D61C5F8C22BABA9B00A79141 /* Images.xcassets */; }; - D61C5F9622BABAD200A79141 /* integration_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = D61C5F9222BABAD100A79141 /* integration_test.cc */; }; - D62CCBC022F367140099BE9F /* gmock-all.cc in Sources */ = {isa = PBXBuildFile; fileRef = D62CCBBF22F367140099BE9F /* gmock-all.cc */; }; - D640F3172819C85800AC956E /* empty.swift in Sources */ = {isa = PBXBuildFile; fileRef = D640F3162819C85800AC956E /* empty.swift */; }; - D66B16871CE46E8900E5638A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D66B16861CE46E8900E5638A /* LaunchScreen.storyboard */; }; - D67D355822BABD2200292C1D /* gtest-all.cc in Sources */ = {isa = PBXBuildFile; fileRef = D67D355622BABD2100292C1D /* gtest-all.cc */; }; - D686A3292A8B16F20034845A /* AppTrackingTransparency.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D686A3282A8B16F20034845A /* AppTrackingTransparency.framework */; }; - D6C179E922CB322900C2651A /* ios_app_framework.mm in Sources */ = {isa = PBXBuildFile; fileRef = D6C179E722CB322900C2651A /* ios_app_framework.mm */; }; - D6C179EA22CB322900C2651A /* ios_firebase_test_framework.mm in Sources */ = {isa = PBXBuildFile; fileRef = D6C179E822CB322900C2651A /* ios_firebase_test_framework.mm */; }; - D6C179EE22CB323300C2651A /* firebase_test_framework.cc in Sources */ = {isa = PBXBuildFile; fileRef = D6C179EC22CB323300C2651A /* firebase_test_framework.cc */; }; - D6C179F022CB32A000C2651A /* app_framework.cc in Sources */ = {isa = PBXBuildFile; fileRef = D6C179EF22CB32A000C2651A /* app_framework.cc */; }; -/* End PBXBuildFile section */ - -/* Begin PBXFileReference section */ - 520BC0381C869159008CFBC3 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; - 529226D21C85F68000C89379 /* integration_test.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = integration_test.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 529226D51C85F68000C89379 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; - 529226D71C85F68000C89379 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; - 529226D91C85F68000C89379 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; - 529226EE1C85F68000C89379 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; - D61C5F8C22BABA9B00A79141 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; - D61C5F8D22BABA9C00A79141 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - D61C5F9222BABAD100A79141 /* integration_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = integration_test.cc; path = src/integration_test.cc; sourceTree = ""; }; - D62CCBBF22F367140099BE9F /* gmock-all.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "gmock-all.cc"; path = "external/googletest/src/googlemock/src/gmock-all.cc"; sourceTree = ""; }; - D62CCBC122F367320099BE9F /* gmock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = gmock.h; path = external/googletest/src/googlemock/include/gmock/gmock.h; sourceTree = ""; }; - D640F3162819C85800AC956E /* empty.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = empty.swift; path = src/empty.swift; sourceTree = ""; }; - D66B16861CE46E8900E5638A /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = ""; }; - D67D355622BABD2100292C1D /* gtest-all.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "gtest-all.cc"; path = "external/googletest/src/googletest/src/gtest-all.cc"; sourceTree = ""; }; - D67D355722BABD2100292C1D /* gtest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = gtest.h; path = external/googletest/src/googletest/include/gtest/gtest.h; sourceTree = ""; }; - D686A3282A8B16F20034845A /* AppTrackingTransparency.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppTrackingTransparency.framework; path = System/Library/Frameworks/AppTrackingTransparency.framework; sourceTree = SDKROOT; }; - D6C179E722CB322900C2651A /* ios_app_framework.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = ios_app_framework.mm; path = src/ios/ios_app_framework.mm; sourceTree = ""; }; - D6C179E822CB322900C2651A /* ios_firebase_test_framework.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = ios_firebase_test_framework.mm; path = src/ios/ios_firebase_test_framework.mm; sourceTree = ""; }; - D6C179EB22CB323300C2651A /* firebase_test_framework.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = firebase_test_framework.h; path = src/firebase_test_framework.h; sourceTree = ""; }; - D6C179EC22CB323300C2651A /* firebase_test_framework.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = firebase_test_framework.cc; path = src/firebase_test_framework.cc; sourceTree = ""; }; - D6C179ED22CB323300C2651A /* app_framework.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = app_framework.h; path = src/app_framework.h; sourceTree = ""; }; - D6C179EF22CB32A000C2651A /* app_framework.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = app_framework.cc; path = src/app_framework.cc; sourceTree = ""; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 529226CF1C85F68000C89379 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 529226D81C85F68000C89379 /* CoreGraphics.framework in Frameworks */, - D686A3292A8B16F20034845A /* AppTrackingTransparency.framework in Frameworks */, - 529226DA1C85F68000C89379 /* UIKit.framework in Frameworks */, - 529226D61C85F68000C89379 /* Foundation.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 529226C91C85F68000C89379 = { - isa = PBXGroup; - children = ( - D61C5F8C22BABA9B00A79141 /* Images.xcassets */, - D61C5F8D22BABA9C00A79141 /* Info.plist */, - D66B16861CE46E8900E5638A /* LaunchScreen.storyboard */, - 520BC0381C869159008CFBC3 /* GoogleService-Info.plist */, - 5292271D1C85FB5500C89379 /* src */, - 529226D41C85F68000C89379 /* Frameworks */, - 529226D31C85F68000C89379 /* Products */, - ); - sourceTree = ""; - }; - 529226D31C85F68000C89379 /* Products */ = { - isa = PBXGroup; - children = ( - 529226D21C85F68000C89379 /* integration_test.app */, - ); - name = Products; - sourceTree = ""; - }; - 529226D41C85F68000C89379 /* Frameworks */ = { - isa = PBXGroup; - children = ( - D686A3282A8B16F20034845A /* AppTrackingTransparency.framework */, - 529226D51C85F68000C89379 /* Foundation.framework */, - 529226D71C85F68000C89379 /* CoreGraphics.framework */, - 529226D91C85F68000C89379 /* UIKit.framework */, - 529226EE1C85F68000C89379 /* XCTest.framework */, - ); - name = Frameworks; - sourceTree = ""; - }; - 5292271D1C85FB5500C89379 /* src */ = { - isa = PBXGroup; - children = ( - D640F3162819C85800AC956E /* empty.swift */, - D62CCBC122F367320099BE9F /* gmock.h */, - D62CCBBF22F367140099BE9F /* gmock-all.cc */, - D67D355622BABD2100292C1D /* gtest-all.cc */, - D67D355722BABD2100292C1D /* gtest.h */, - D6C179EF22CB32A000C2651A /* app_framework.cc */, - D6C179ED22CB323300C2651A /* app_framework.h */, - D6C179EC22CB323300C2651A /* firebase_test_framework.cc */, - D6C179EB22CB323300C2651A /* firebase_test_framework.h */, - D61C5F9222BABAD100A79141 /* integration_test.cc */, - 5292271E1C85FB5B00C89379 /* ios */, - ); - name = src; - sourceTree = ""; - }; - 5292271E1C85FB5B00C89379 /* ios */ = { - isa = PBXGroup; - children = ( - D6C179E722CB322900C2651A /* ios_app_framework.mm */, - D6C179E822CB322900C2651A /* ios_firebase_test_framework.mm */, - ); - name = ios; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - 529226D11C85F68000C89379 /* integration_test */ = { - isa = PBXNativeTarget; - buildConfigurationList = 529226F91C85F68000C89379 /* Build configuration list for PBXNativeTarget "integration_test" */; - buildPhases = ( - 529226CE1C85F68000C89379 /* Sources */, - 529226CF1C85F68000C89379 /* Frameworks */, - 529226D01C85F68000C89379 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = integration_test; - productName = testapp; - productReference = 529226D21C85F68000C89379 /* integration_test.app */; - productType = "com.apple.product-type.application"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 529226CA1C85F68000C89379 /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 0640; - ORGANIZATIONNAME = Google; - TargetAttributes = { - 529226D11C85F68000C89379 = { - CreatedOnToolsVersion = 6.4; - DevelopmentTeam = EQHXZ8M8AV; - LastSwiftMigration = 1320; - ProvisioningStyle = Automatic; - }; - }; - }; - buildConfigurationList = 529226CD1C85F68000C89379 /* Build configuration list for PBXProject "integration_test" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - English, - en, - ); - mainGroup = 529226C91C85F68000C89379; - productRefGroup = 529226D31C85F68000C89379 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 529226D11C85F68000C89379 /* integration_test */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXResourcesBuildPhase section */ - 529226D01C85F68000C89379 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - D61C5F8E22BABA9C00A79141 /* Images.xcassets in Resources */, - D66B16871CE46E8900E5638A /* LaunchScreen.storyboard in Resources */, - 520BC0391C869159008CFBC3 /* GoogleService-Info.plist in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - 529226CE1C85F68000C89379 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - D67D355822BABD2200292C1D /* gtest-all.cc in Sources */, - D62CCBC022F367140099BE9F /* gmock-all.cc in Sources */, - D6C179EA22CB322900C2651A /* ios_firebase_test_framework.mm in Sources */, - D61C5F9622BABAD200A79141 /* integration_test.cc in Sources */, - D6C179E922CB322900C2651A /* ios_app_framework.mm in Sources */, - D640F3172819C85800AC956E /* empty.swift in Sources */, - D6C179F022CB32A000C2651A /* app_framework.cc in Sources */, - D6C179EE22CB323300C2651A /* firebase_test_framework.cc in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin XCBuildConfiguration section */ - 529226F71C85F68000C89379 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 13.0; - MTL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = iphoneos; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Debug; - }; - 529226F81C85F68000C89379 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 13.0; - MTL_ENABLE_DEBUG_INFO = NO; - SDKROOT = iphoneos; - TARGETED_DEVICE_FAMILY = "1,2"; - VALIDATE_PRODUCT = YES; - }; - name = Release; - }; - 529226FA1C85F68000C89379 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; - CLANG_ENABLE_MODULES = YES; - CODE_SIGN_IDENTITY = "iPhone Developer"; - CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = ""; - EXCLUDED_ARCHS = i386; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)", - ); - HEADER_SEARCH_PATHS = ( - "$(inherited)", - /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, - "\"$(SRCROOT)/src\"", - "\"$(SRCROOT)/external/googletest/src/googletest/include\"", - "\"$(SRCROOT)/external/googletest/src/googlemock/include\"", - "\"$(SRCROOT)/external/googletest/src/googletest\"", - "\"$(SRCROOT)/external/googletest/src/googlemock\"", - ); - INFOPLIST_FILE = "$(SRCROOT)/Info.plist"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_NAME = "$(TARGET_NAME)"; - PROVISIONING_PROFILE_SPECIFIER = ""; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 5.3; - WRAPPER_EXTENSION = app; - }; - name = Debug; - }; - 529226FB1C85F68000C89379 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; - CLANG_ENABLE_MODULES = YES; - CODE_SIGN_IDENTITY = "iPhone Developer"; - CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = ""; - EXCLUDED_ARCHS = i386; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)", - ); - HEADER_SEARCH_PATHS = ( - "$(inherited)", - /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, - "\"$(SRCROOT)/src\"", - "\"$(SRCROOT)/external/googletest/src/googletest/include\"", - "\"$(SRCROOT)/external/googletest/src/googlemock/include\"", - "\"$(SRCROOT)/external/googletest/src/googletest\"", - "\"$(SRCROOT)/external/googletest/src/googlemock\"", - ); - INFOPLIST_FILE = "$(SRCROOT)/Info.plist"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_NAME = "$(TARGET_NAME)"; - PROVISIONING_PROFILE_SPECIFIER = ""; - SWIFT_VERSION = 5.3; - WRAPPER_EXTENSION = app; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 529226CD1C85F68000C89379 /* Build configuration list for PBXProject "integration_test" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 529226F71C85F68000C89379 /* Debug */, - 529226F81C85F68000C89379 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 529226F91C85F68000C89379 /* Build configuration list for PBXNativeTarget "integration_test" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 529226FA1C85F68000C89379 /* Debug */, - 529226FB1C85F68000C89379 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 529226CA1C85F68000C89379 /* Project object */; -} diff --git a/gma/integration_test/proguard.pro b/gma/integration_test/proguard.pro deleted file mode 100644 index 2d04b8a9a5..0000000000 --- a/gma/integration_test/proguard.pro +++ /dev/null @@ -1,2 +0,0 @@ --ignorewarnings --keep,includedescriptorclasses public class com.google.firebase.example.LoggingUtils { * ; } diff --git a/gma/integration_test/res/layout/main.xml b/gma/integration_test/res/layout/main.xml deleted file mode 100644 index 56e8488b7a..0000000000 --- a/gma/integration_test/res/layout/main.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - diff --git a/gma/integration_test/res/values/strings.xml b/gma/integration_test/res/values/strings.xml deleted file mode 100644 index ff36817020..0000000000 --- a/gma/integration_test/res/values/strings.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - Firebase GMA Integration Test - diff --git a/gma/integration_test/settings.gradle b/gma/integration_test/settings.gradle deleted file mode 100644 index 7e56f6228e..0000000000 --- a/gma/integration_test/settings.gradle +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2021 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -def firebase_cpp_sdk_dir = System.getProperty('firebase_cpp_sdk.dir') -if (firebase_cpp_sdk_dir == null || firebase_cpp_sdk_dir.isEmpty()) { - firebase_cpp_sdk_dir = System.getenv('FIREBASE_CPP_SDK_DIR') - if (firebase_cpp_sdk_dir == null || firebase_cpp_sdk_dir.isEmpty()) { - if ((file('../../cpp_sdk_version.json')).exists()) { - firebase_cpp_sdk_dir = file('../..').absolutePath - } - else if ((file('firebase_cpp_sdk')).exists()) { - firebase_cpp_sdk_dir = 'firebase_cpp_sdk' - } else { - throw new StopActionException( - 'firebase_cpp_sdk.dir property or the FIREBASE_CPP_SDK_DIR ' + - 'environment variable must be set to reference the Firebase C++ ' + - 'SDK install directory. This is used to configure static library ' + - 'and C/C++ include paths for the SDK.') - } - } -} -if (!(new File(firebase_cpp_sdk_dir)).exists()) { - throw new StopActionException( - sprintf('Firebase C++ SDK directory %s does not exist', - firebase_cpp_sdk_dir)) -} -gradle.ext.firebase_cpp_sdk_dir = "$firebase_cpp_sdk_dir" -includeBuild("$firebase_cpp_sdk_dir") { - name = "firebase_cpp_sdk" -} diff --git a/gma/integration_test/src/integration_test.cc b/gma/integration_test/src/integration_test.cc deleted file mode 100644 index e26beb6ff3..0000000000 --- a/gma/integration_test/src/integration_test.cc +++ /dev/null @@ -1,3328 +0,0 @@ -// Copyright 2021 Google LLC. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "app_framework.h" // NOLINT -#include "firebase/app.h" -#include "firebase/gma.h" -#include "firebase/gma/types.h" -#include "firebase/gma/ump.h" -#include "firebase/util.h" -#include "firebase_test_framework.h" // NOLINT - -#if defined(ANDROID) || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) -// includes for phone-only tests. -#include -#include -#endif // defined(ANDROID) || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) - -// The TO_STRING macro is useful for command line defined strings as the quotes -// get stripped. -#define TO_STRING_EXPAND(X) #X -#define TO_STRING(X) TO_STRING_EXPAND(X) - -// Path to the Firebase config file to load. -#ifdef FIREBASE_CONFIG -#define FIREBASE_CONFIG_STRING TO_STRING(FIREBASE_CONFIG) -#else -#define FIREBASE_CONFIG_STRING "" -#endif // FIREBASE_CONFIG - -namespace firebase_testapp_automated { - -// The GMA app IDs for the test app. -#if defined(ANDROID) -// If you change the GMA app ID for your Android app, make sure to change it -// in AndroidManifest.xml as well. -const char* kGmaAppID = "ca-app-pub-3940256099942544~3347511713"; -#else -// If you change the GMA app ID for your iOS app, make sure to change the -// value for "GADApplicationIdentifier" in your Info.plist as well. -const char* kGmaAppID = "ca-app-pub-3940256099942544~1458002511"; -#endif - -// These ad units IDs have been created specifically for testing, and will -// always return test ads. -#if defined(ANDROID) -const char* kBannerAdUnit = "ca-app-pub-3940256099942544/6300978111"; -const char* kInterstitialAdUnit = "ca-app-pub-3940256099942544/1033173712"; -const char* kRewardedAdUnit = "ca-app-pub-3940256099942544/5224354917"; -const char* kNativeAdUnit = "ca-app-pub-3940256099942544/2247696110"; -#else -const char* kBannerAdUnit = "ca-app-pub-3940256099942544/2934735716"; -const char* kInterstitialAdUnit = "ca-app-pub-3940256099942544/4411468910"; -const char* kRewardedAdUnit = "ca-app-pub-3940256099942544/1712485313"; -const char* kNativeAdUnit = "ca-app-pub-3940256099942544/3986624511"; -#endif - -// Used in a test to send an errant ad unit id. -const char* kBadAdUnit = "oops"; - -// Standard Banner Ad Size. -static const int kBannerWidth = 320; -static const int kBannerHeight = 50; - -enum AdCallbackEvent { - AdCallbackEventClicked = 0, - AdCallbackEventClosed, - AdCallbackEventAdImpression, - AdCallbackEventOpened, - AdCallbackEventPaidEvent -}; - -// Error domains vary across phone SDKs. -#if defined(ANDROID) -const char* kErrorDomain = "com.google.android.gms.ads"; -#else -const char* kErrorDomain = "com.google.admob"; -#endif - -// Sample test device IDs to use in making the request. -// You can replace these with actual device IDs for certain tests (e.g. UMP) -// to work on hardware devices. -const std::vector kTestDeviceIDs = { - "2077ef9a63d2b398840261c8221a0c9b", "098fe087d987c9a878965454a65654d7"}; - -// Sample keywords to use in making the request. -static const std::vector kKeywords({"GMA", "C++", "Fun"}); - -// "Extra" key value pairs can be added to the request as well. Typically -// these are used when testing new features. -static const std::map kGmaAdapterExtras = { - {"the_name_of_an_extra", "the_value_for_that_extra"}, - {"heres", "a second example"}}; - -#if defined(ANDROID) -static const char* kAdNetworkExtrasClassName = - "com/google/ads/mediation/admob/AdMobAdapter"; -#else -static const char* kAdNetworkExtrasClassName = "GADExtras"; -#endif - -// Class nname of the GMA SDK returned in initialization results. -#if defined(ANDROID) -const char kGmaClassName[] = "com.google.android.gms.ads.MobileAds"; -#elif defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE -const char kGmaClassName[] = "GADMobileAds"; -#else // desktop -const char kGmaClassName[] = "stub"; -#endif - -// Used to detect kAdErrorCodeAdNetworkClassLoadErrors when loading -// ads. -static const char* kAdNetworkExtrasInvalidClassName = "abc123321cba"; - -static const char* kContentUrl = "http://www.firebase.com"; - -static const std::vector kNeighboringContentURLs = { - "test_url1", "test_url2", "test_url3"}; - -using app_framework::LogDebug; -using app_framework::LogInfo; -using app_framework::LogWarning; -using app_framework::ProcessEvents; - -using firebase_test_framework::FirebaseTest; - -using testing::AnyOf; -using testing::Contains; -using testing::ElementsAre; -using testing::Eq; -using testing::HasSubstr; -using testing::Pair; -using testing::Property; - -class FirebaseGmaTest : public FirebaseTest { - public: - FirebaseGmaTest(); - ~FirebaseGmaTest() override; - - static void SetUpTestSuite(); - static void TearDownTestSuite(); - - void SetUp() override; - void TearDown() override; - - protected: - firebase::gma::AdRequest GetAdRequest(); - firebase::Variant GetVariantMap(); - - static firebase::App* shared_app_; -}; - -class FirebaseGmaUITest : public FirebaseGmaTest { - public: - FirebaseGmaUITest(); - ~FirebaseGmaUITest() override; - - void SetUp() override; -}; - -class FirebaseGmaMinimalTest : public FirebaseTest { - public: - FirebaseGmaMinimalTest(); - ~FirebaseGmaMinimalTest() override; -}; - -// Runs GMA Tests on methods and functions that should be run -// before GMA initializes. -class FirebaseGmaPreInitializationTests : public FirebaseGmaTest { - public: - FirebaseGmaPreInitializationTests(); - ~FirebaseGmaPreInitializationTests() override; - - static void SetUpTestSuite(); - - void SetUp() override; -}; - -firebase::App* FirebaseGmaTest::shared_app_ = nullptr; - -void PauseForVisualInspectionAndCallbacks() { - app_framework::ProcessEvents(300); -} - -void InitializeGma(firebase::App* shared_app) { - LogDebug("Initializing GMA."); - - ::firebase::ModuleInitializer initializer; - initializer.Initialize(shared_app, nullptr, - [](::firebase::App* app, void* /* userdata */) { - LogDebug("Try to initialize GMA"); - firebase::InitResult result; - ::firebase::gma::Initialize(*app, &result); - return result; - }); - - FirebaseGmaTest::WaitForCompletion(initializer.InitializeLastResult(), - "Initialize"); - - ASSERT_EQ(initializer.InitializeLastResult().error(), 0) - << initializer.InitializeLastResult().error_message(); - - LogDebug("Successfully initialized GMA."); -} - -void FirebaseGmaTest::SetUpTestSuite() { - LogDebug("Initialize Firebase App."); - - FindFirebaseConfig(FIREBASE_CONFIG_STRING); - -#if defined(ANDROID) - shared_app_ = ::firebase::App::Create(app_framework::GetJniEnv(), - app_framework::GetActivity()); -#else - shared_app_ = ::firebase::App::Create(); -#endif // defined(ANDROID) - - InitializeGma(shared_app_); -} - -void FirebaseGmaTest::TearDownTestSuite() { - // GMA does some of its initialization in the main thread, so if you terminate - // it before initialization has completed, it can cause issues. So wait for - // any pending GMA initialization to be completed before calling terminate. - WaitForCompletion(firebase::gma::InitializeLastResult(), - "gma::InitializeLastResult"); - LogDebug("Shutdown GMA."); - firebase::gma::Terminate(); - LogDebug("Shutdown Firebase App."); - delete shared_app_; - shared_app_ = nullptr; -} - -FirebaseGmaTest::FirebaseGmaTest() {} - -FirebaseGmaTest::~FirebaseGmaTest() {} - -void FirebaseGmaTest::SetUp() { - TEST_DOES_NOT_REQUIRE_USER_INTERACTION; - ProcessEvents(100); // Flush main thread queue. - FirebaseTest::SetUp(); - - // This example uses ad units that are specially configured to return test ads - // for every request. When using your own ad unit IDs, however, it's important - // to register the device IDs associated with any devices that will be used to - // test the app. This ensures that regardless of the ad unit ID, those - // devices will always receive test ads in compliance with GMA policy. - // - // Device IDs can be obtained by checking the logcat or the Xcode log while - // debugging. They appear as a long string of hex characters. - firebase::gma::RequestConfiguration request_configuration; - request_configuration.test_device_ids = kTestDeviceIDs; - request_configuration.test_device_ids.push_back(GetDebugDeviceId()); - firebase::gma::SetRequestConfiguration(request_configuration); -} - -void FirebaseGmaTest::TearDown() { FirebaseTest::TearDown(); } - -firebase::gma::AdRequest FirebaseGmaTest::GetAdRequest() { - firebase::gma::AdRequest request; - - // Additional keywords to be used in targeting. - for (auto keyword_iter = kKeywords.begin(); keyword_iter != kKeywords.end(); - ++keyword_iter) { - request.add_keyword((*keyword_iter).c_str()); - } - - for (auto extras_iter = kGmaAdapterExtras.begin(); - extras_iter != kGmaAdapterExtras.end(); ++extras_iter) { - request.add_extra(kAdNetworkExtrasClassName, extras_iter->first.c_str(), - extras_iter->second.c_str()); - } - - // Content URL - request.set_content_url(kContentUrl); - - // Neighboring Content URLs - request.add_neighboring_content_urls(kNeighboringContentURLs); - - return request; -} - -firebase::Variant FirebaseGmaTest::GetVariantMap() { - firebase::Variant in_key = firebase::Variant::FromMutableString("inner_key"); - firebase::Variant in_val = firebase::Variant::FromMutableString("inner_val"); - firebase::Variant out_key = firebase::Variant::FromMutableString("outer_key"); - - firebase::Variant out_val = firebase::Variant::EmptyMap(); - out_val.map()[in_key] = in_val; - - firebase::Variant variant_map = firebase::Variant::EmptyMap(); - variant_map.map()[out_key] = out_val; - - return variant_map; -} - -FirebaseGmaMinimalTest::FirebaseGmaMinimalTest() {} - -FirebaseGmaMinimalTest::~FirebaseGmaMinimalTest() {} - -FirebaseGmaUITest::FirebaseGmaUITest() {} - -FirebaseGmaUITest::~FirebaseGmaUITest() {} - -void FirebaseGmaUITest::SetUp() { - TEST_REQUIRES_USER_INTERACTION; - FirebaseTest::SetUp(); - // This example uses ad units that are specially configured to return test ads - // for every request. When using your own ad unit IDs, however, it's important - // to register the device IDs associated with any devices that will be used to - // test the app. This ensures that regardless of the ad unit ID, those - // devices will always receive test ads in compliance with GMA policy. - // - // Device IDs can be obtained by checking the logcat or the Xcode log while - // debugging. They appear as a long string of hex characters. - firebase::gma::RequestConfiguration request_configuration; - request_configuration.test_device_ids = kTestDeviceIDs; - request_configuration.test_device_ids.push_back(GetDebugDeviceId()); - firebase::gma::SetRequestConfiguration(request_configuration); -} - -FirebaseGmaPreInitializationTests::FirebaseGmaPreInitializationTests() {} - -FirebaseGmaPreInitializationTests::~FirebaseGmaPreInitializationTests() {} - -void FirebaseGmaPreInitializationTests::SetUp() { FirebaseTest::SetUp(); } - -void FirebaseGmaPreInitializationTests::SetUpTestSuite() { - LogDebug("Initialize Firebase App."); - FindFirebaseConfig(FIREBASE_CONFIG_STRING); -#if defined(ANDROID) - shared_app_ = ::firebase::App::Create(app_framework::GetJniEnv(), - app_framework::GetActivity()); -#else - shared_app_ = ::firebase::App::Create(); -#endif // defined(ANDROID) -} - -// Test cases below. - -TEST_F(FirebaseGmaMinimalTest, TestInitializeGmaWithoutFirebase) { - // Don't initialize mediation in this test so that a later test can still - // verify that mediation has not been initialized. - firebase::gma::DisableMediationInitialization(); - LogDebug("Initializing GMA without a Firebase App."); - firebase::InitResult result; -#if defined(ANDROID) - ::firebase::gma::Initialize(app_framework::GetJniEnv(), - app_framework::GetActivity(), &result); -#else // !defined(ANDROID) - ::firebase::gma::Initialize(&result); -#endif // defined(ANDROID) - EXPECT_EQ(result, ::firebase::kInitResultSuccess); - WaitForCompletion(firebase::gma::InitializeLastResult(), "gma::Initialize"); - LogDebug("Successfully initialized GMA."); - - LogDebug("Shutdown GMA."); - firebase::gma::Terminate(); -} - -TEST_F(FirebaseGmaPreInitializationTests, TestDisableMediationInitialization) { - // Note: This test should be disabled or put in an entirely different test - // binrary if we ever wish to test mediation in this application. - firebase::gma::DisableMediationInitialization(); - - // Ensure that GMA can initialize. - InitializeGma(shared_app_); - auto initialize_future = firebase::gma::InitializeLastResult(); - WaitForCompletion(initialize_future, "gma::Initialize"); - ASSERT_NE(initialize_future.result(), nullptr); - EXPECT_EQ(*initialize_future.result(), - firebase::gma::GetInitializationStatus()); - -#if (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) - // Check to see that only one Adapter was initialized, the base GMA adapter. - // Note: DisableMediationInitialization is only implemented on iOS. - std::map adapter_status = - firebase::gma::GetInitializationStatus().GetAdapterStatusMap(); - EXPECT_EQ(adapter_status.size(), 1); - EXPECT_THAT( - adapter_status, - Contains( - Pair(kGmaClassName, - Property(&firebase::gma::AdapterStatus::is_initialized, true)))) - << "Expected adapter class '" << kGmaClassName << "' is not loaded."; -#endif -} - -TEST_F(FirebaseGmaTest, TestInitializationStatus) { - // Ensure Initialize()'s result matches GetInitializationStatus(). - auto initialize_future = firebase::gma::InitializeLastResult(); - WaitForCompletion(initialize_future, "gma::Initialize"); - ASSERT_NE(initialize_future.result(), nullptr); - EXPECT_EQ(*initialize_future.result(), - firebase::gma::GetInitializationStatus()); - - for (auto adapter_status : - firebase::gma::GetInitializationStatus().GetAdapterStatusMap()) { - LogDebug("GMA Mediation Adapter '%s' %s (latency %d ms): %s", - adapter_status.first.c_str(), - (adapter_status.second.is_initialized() ? "loaded" : "NOT loaded"), - adapter_status.second.latency(), - adapter_status.second.description().c_str()); - } - - // Confirm that the default Google Mobile Ads SDK class name shows up in the - // list. It should either be is_initialized = true, or description should say - // "Timeout" (this is a special case we are using to deflake this test on - // Android emulator). - EXPECT_THAT( - initialize_future.result()->GetAdapterStatusMap(), - Contains(Pair( - kGmaClassName, - AnyOf(Property(&firebase::gma::AdapterStatus::is_initialized, true), - Property(&firebase::gma::AdapterStatus::description, - HasSubstr("Timeout")))))) - << "Expected adapter class '" << kGmaClassName << "' is not loaded."; -} - -TEST_F(FirebaseGmaPreInitializationTests, TestDisableSDKCrashReporting) { - // We can't test to see if this method successfully reconfigures crash - // reporting, but we're still calling it as a sanity check and to ensure - // the symbol exists in the library. - firebase::gma::DisableSDKCrashReporting(); -} - -TEST_F(FirebaseGmaTest, TestSetAppKeyEnabled) { - // We can't test to see if this method successfully enables/disables - // the app key, but we're still calling it as a sanity check and to - // ensure the symbol exists in the library. - firebase::gma::SetIsSameAppKeyEnabled(true); -} - -TEST_F(FirebaseGmaTest, TestGetAdRequest) { GetAdRequest(); } - -TEST_F(FirebaseGmaTest, TestGetVariantMap) { GetVariantMap(); } - -TEST_F(FirebaseGmaTest, TestGetAdRequestValues) { - SKIP_TEST_ON_DESKTOP; - - firebase::gma::AdRequest request = GetAdRequest(); - - // Content URL. - EXPECT_TRUE(request.content_url() == std::string(kContentUrl)); - - // Extras. - std::map > configured_extras = - request.extras(); - - EXPECT_EQ(configured_extras.size(), 1); - for (auto extras_name_iter = configured_extras.begin(); - extras_name_iter != configured_extras.end(); ++extras_name_iter) { - // Confirm class name. - const std::string class_name = extras_name_iter->first; - EXPECT_EQ(class_name, kAdNetworkExtrasClassName); - - // Grab the extras. - const std::map& configured_extras = - extras_name_iter->second; - EXPECT_EQ(configured_extras.size(), kGmaAdapterExtras.size()); - - // Check the extra key value pairs. - for (auto constant_extras_iter = kGmaAdapterExtras.begin(); - constant_extras_iter != kGmaAdapterExtras.end(); - ++constant_extras_iter) { - // Ensure the configured value matches the constant for the same key. - EXPECT_EQ(configured_extras.at(constant_extras_iter->first), - constant_extras_iter->second); - } - } - - const std::unordered_set configured_keywords = - request.keywords(); - EXPECT_EQ(configured_keywords.size(), kKeywords.size()); - for (auto keyword_iter = kKeywords.begin(); keyword_iter != kKeywords.end(); - ++keyword_iter) { - EXPECT_TRUE(configured_keywords.find(*keyword_iter) != - configured_keywords.end()); - } - - const std::unordered_set configured_neighboring_content_urls = - request.neighboring_content_urls(); - EXPECT_EQ(configured_neighboring_content_urls.size(), - kNeighboringContentURLs.size()); - for (auto url_iter = kNeighboringContentURLs.begin(); - url_iter != kNeighboringContentURLs.end(); ++url_iter) { - EXPECT_TRUE(configured_neighboring_content_urls.find(*url_iter) != - configured_neighboring_content_urls.end()); - } -} - -// A listener to detect when the AdInspector has been closed. Additionally, -// checks for errors when opening the AdInspector while it's already open. -class TestAdInspectorClosedListener - : public firebase::gma::AdInspectorClosedListener { - public: - TestAdInspectorClosedListener() - : num_closed_events_(0), num_successful_results_(0) {} - - // Called when the user clicked the ad. - void OnAdInspectorClosed(const firebase::gma::AdResult& ad_result) override { - ++num_closed_events_; - if (ad_result.is_successful()) { - ++num_successful_results_; - } else { -#if defined(ANDROID) - EXPECT_EQ(ad_result.ad_error().code(), - firebase::gma::kAdErrorCodeInsepctorAlreadyOpen); - EXPECT_STREQ(ad_result.ad_error().message().c_str(), - "Ad inspector cannot be opened because it is already open."); -#else - // The iOS GMA SDK returns internal errors for all AdInspector failures. - EXPECT_EQ(ad_result.ad_error().code(), - firebase::gma::kAdErrorCodeInternalError); - EXPECT_STREQ(ad_result.ad_error().message().c_str(), - "Ad Inspector cannot be opened because it is already open."); -#endif - } - } - - uint8_t num_closed_events() const { return num_closed_events_; } - uint8_t num_successful_results() const { return num_successful_results_; } - - private: - uint8_t num_closed_events_; - uint8_t num_successful_results_; -}; - -// This is for manual test only -// Ensure we can open the AdInspector and listen to its events. -TEST_F(FirebaseGmaTest, TestAdInspector) { - TEST_REQUIRES_USER_INTERACTION; - TestAdInspectorClosedListener listener; - - firebase::gma::OpenAdInspector(app_framework::GetWindowController(), - &listener); - - // Call OpenAdInspector, even on Desktop (above), to ensure the stub linked - // correctly. However, the rest of the testing is mobile-only beahvior. - SKIP_TEST_ON_DESKTOP; - - // Open the inspector a second time to generate a - // kAdErrorCodeInsepctorAlreadyOpen result. - app_framework::ProcessEvents(2000); - - firebase::gma::OpenAdInspector(app_framework::GetWindowController(), - &listener); - - while (listener.num_closed_events() < 2) { - app_framework::ProcessEvents(2000); - } - - EXPECT_EQ(listener.num_successful_results(), 1); -} - -// A simple listener to help test changes to a AdViews. -class TestBoundingBoxListener - : public firebase::gma::AdViewBoundingBoxListener { - public: - void OnBoundingBoxChanged(firebase::gma::AdView* ad_view, - firebase::gma::BoundingBox box) override { - bounding_box_changes_.push_back(box); - } - std::vector bounding_box_changes_; -}; - -// A simple listener to help test changes an Ad. -class TestAdListener : public firebase::gma::AdListener { - public: - TestAdListener() - : num_on_ad_clicked_(0), - num_on_ad_closed_(0), - num_on_ad_impression_(0), - num_on_ad_opened_(0) {} - - void OnAdClicked() override { num_on_ad_clicked_++; } - void OnAdClosed() override { num_on_ad_closed_++; } - void OnAdImpression() override { num_on_ad_impression_++; } - void OnAdOpened() override { num_on_ad_opened_++; } - - int num_on_ad_clicked_; - int num_on_ad_closed_; - int num_on_ad_impression_; - int num_on_ad_opened_; -}; - -// A simple listener track FullScreen presentation changes. -class TestFullScreenContentListener - : public firebase::gma::FullScreenContentListener { - public: - TestFullScreenContentListener() - : num_on_ad_clicked_(0), - num_on_ad_dismissed_full_screen_content_(0), - num_on_ad_failed_to_show_full_screen_content_(0), - num_on_ad_impression_(0), - num_on_ad_showed_full_screen_content_(0) {} - - int num_ad_clicked() const { return num_on_ad_clicked_; } - int num_ad_dismissed() const { - return num_on_ad_dismissed_full_screen_content_; - } - int num_ad_failed_to_show_content() const { - return num_on_ad_failed_to_show_full_screen_content_; - } - int num_ad_impressions() const { return num_on_ad_impression_; } - int num_ad_showed_content() const { - return num_on_ad_showed_full_screen_content_; - } - - void OnAdClicked() override { num_on_ad_clicked_++; } - - void OnAdDismissedFullScreenContent() override { - num_on_ad_dismissed_full_screen_content_++; - } - - void OnAdFailedToShowFullScreenContent( - const firebase::gma::AdError& ad_error) override { - num_on_ad_failed_to_show_full_screen_content_++; - failure_codes_.push_back(ad_error.code()); - } - - void OnAdImpression() override { num_on_ad_impression_++; } - - void OnAdShowedFullScreenContent() override { - num_on_ad_showed_full_screen_content_++; - } - - const std::vector failure_codes() const { - return failure_codes_; - } - - private: - int num_on_ad_clicked_; - int num_on_ad_dismissed_full_screen_content_; - int num_on_ad_failed_to_show_full_screen_content_; - int num_on_ad_impression_; - int num_on_ad_showed_full_screen_content_; - - std::vector failure_codes_; -}; - -// A simple listener track UserEarnedReward events. -class TestUserEarnedRewardListener - : public firebase::gma::UserEarnedRewardListener { - public: - TestUserEarnedRewardListener() : num_on_user_earned_reward_(0) {} - - int num_earned_rewards() const { return num_on_user_earned_reward_; } - - void OnUserEarnedReward(const firebase::gma::AdReward& reward) override { - ++num_on_user_earned_reward_; - EXPECT_EQ(reward.type(), "coins"); - EXPECT_EQ(reward.amount(), 10); - } - - private: - int num_on_user_earned_reward_; -}; - -// A simple listener track ad pay events. -class TestPaidEventListener : public firebase::gma::PaidEventListener { - public: - TestPaidEventListener() : num_on_paid_event_(0) {} - - int num_paid_events() const { return num_on_paid_event_; } - - void OnPaidEvent(const firebase::gma::AdValue& value) override { - ++num_on_paid_event_; - // These are the values for GMA test ads. If they change then we should - // alter the test to match the new expected values. - EXPECT_EQ(value.currency_code(), "USD"); - EXPECT_EQ(value.value_micros(), 0); - } - int num_on_paid_event_; -}; - -TEST_F(FirebaseGmaTest, TestAdSize) { - uint32_t kWidth = 50; - uint32_t kHeight = 10; - - using firebase::gma::AdSize; - - const AdSize adaptive_landscape = - AdSize::GetLandscapeAnchoredAdaptiveBannerAdSize(kWidth); - EXPECT_EQ(adaptive_landscape.width(), kWidth); - EXPECT_EQ(adaptive_landscape.height(), 0); - EXPECT_EQ(adaptive_landscape.type(), AdSize::kTypeAnchoredAdaptive); - EXPECT_EQ(adaptive_landscape.orientation(), AdSize::kOrientationLandscape); - - const AdSize adaptive_portrait = - AdSize::GetPortraitAnchoredAdaptiveBannerAdSize(kWidth); - EXPECT_EQ(adaptive_portrait.width(), kWidth); - EXPECT_EQ(adaptive_portrait.height(), 0); - EXPECT_EQ(adaptive_portrait.type(), AdSize::kTypeAnchoredAdaptive); - EXPECT_EQ(adaptive_portrait.orientation(), AdSize::kOrientationPortrait); - - EXPECT_FALSE(adaptive_portrait == adaptive_landscape); - EXPECT_TRUE(adaptive_portrait != adaptive_landscape); - - const firebase::gma::AdSize adaptive_current = - AdSize::GetCurrentOrientationAnchoredAdaptiveBannerAdSize(kWidth); - EXPECT_EQ(adaptive_current.width(), kWidth); - EXPECT_EQ(adaptive_current.height(), 0); - EXPECT_EQ(adaptive_current.type(), AdSize::kTypeAnchoredAdaptive); - EXPECT_EQ(adaptive_current.orientation(), AdSize::kOrientationCurrent); - - const firebase::gma::AdSize custom_ad_size(kWidth, kHeight); - EXPECT_EQ(custom_ad_size.width(), kWidth); - EXPECT_EQ(custom_ad_size.height(), kHeight); - EXPECT_EQ(custom_ad_size.type(), AdSize::kTypeStandard); - EXPECT_EQ(custom_ad_size.orientation(), AdSize::kOrientationCurrent); - - const AdSize custom_ad_size_2(kWidth, kHeight); - EXPECT_TRUE(custom_ad_size == custom_ad_size_2); - EXPECT_FALSE(custom_ad_size != custom_ad_size_2); - - const AdSize banner = AdSize::kBanner; - EXPECT_EQ(banner.width(), 320); - EXPECT_EQ(banner.height(), 50); - EXPECT_EQ(banner.type(), AdSize::kTypeStandard); - EXPECT_EQ(banner.orientation(), AdSize::kOrientationCurrent); - - const AdSize fullbanner = AdSize::kFullBanner; - EXPECT_EQ(fullbanner.width(), 468); - EXPECT_EQ(fullbanner.height(), 60); - EXPECT_EQ(fullbanner.type(), AdSize::kTypeStandard); - EXPECT_EQ(fullbanner.orientation(), AdSize::kOrientationCurrent); - - const AdSize leaderboard = AdSize::kLeaderboard; - EXPECT_EQ(leaderboard.width(), 728); - EXPECT_EQ(leaderboard.height(), 90); - EXPECT_EQ(leaderboard.type(), AdSize::kTypeStandard); - EXPECT_EQ(leaderboard.orientation(), AdSize::kOrientationCurrent); - - const AdSize medium_rectangle = AdSize::kMediumRectangle; - EXPECT_EQ(medium_rectangle.width(), 300); - EXPECT_EQ(medium_rectangle.height(), 250); - EXPECT_EQ(medium_rectangle.type(), AdSize::kTypeStandard); - EXPECT_EQ(medium_rectangle.orientation(), AdSize::kOrientationCurrent); -} - -TEST_F(FirebaseGmaTest, TestRequestConfigurationSetGetEmptyConfig) { - SKIP_TEST_ON_DESKTOP; - - firebase::gma::RequestConfiguration set_configuration; - firebase::gma::SetRequestConfiguration(set_configuration); - firebase::gma::RequestConfiguration retrieved_configuration = - firebase::gma::GetRequestConfiguration(); - - EXPECT_EQ( - retrieved_configuration.max_ad_content_rating, - firebase::gma::RequestConfiguration::kMaxAdContentRatingUnspecified); - EXPECT_EQ( - retrieved_configuration.tag_for_child_directed_treatment, - firebase::gma::RequestConfiguration::kChildDirectedTreatmentUnspecified); - EXPECT_EQ(retrieved_configuration.tag_for_under_age_of_consent, - firebase::gma::RequestConfiguration::kUnderAgeOfConsentUnspecified); - EXPECT_EQ(retrieved_configuration.test_device_ids.size(), 0); -} - -TEST_F(FirebaseGmaTest, TestRequestConfigurationSetGet) { - SKIP_TEST_ON_DESKTOP; - - firebase::gma::RequestConfiguration set_configuration; - set_configuration.max_ad_content_rating = - firebase::gma::RequestConfiguration::kMaxAdContentRatingPG; - set_configuration.tag_for_child_directed_treatment = - firebase::gma::RequestConfiguration::kChildDirectedTreatmentTrue; - set_configuration.tag_for_under_age_of_consent = - firebase::gma::RequestConfiguration::kUnderAgeOfConsentFalse; - set_configuration.test_device_ids.push_back("1"); - set_configuration.test_device_ids.push_back("2"); - set_configuration.test_device_ids.push_back("3"); - firebase::gma::SetRequestConfiguration(set_configuration); - - firebase::gma::RequestConfiguration retrieved_configuration = - firebase::gma::GetRequestConfiguration(); - - EXPECT_EQ(retrieved_configuration.max_ad_content_rating, - firebase::gma::RequestConfiguration::kMaxAdContentRatingPG); - -#if defined(ANDROID) - EXPECT_EQ(retrieved_configuration.tag_for_child_directed_treatment, - firebase::gma::RequestConfiguration::kChildDirectedTreatmentTrue); - EXPECT_EQ(retrieved_configuration.tag_for_under_age_of_consent, - firebase::gma::RequestConfiguration::kUnderAgeOfConsentFalse); -#else // iOS - // iOS doesn't allow for the querying of these values. - EXPECT_EQ( - retrieved_configuration.tag_for_child_directed_treatment, - firebase::gma::RequestConfiguration::kChildDirectedTreatmentUnspecified); - EXPECT_EQ(retrieved_configuration.tag_for_under_age_of_consent, - firebase::gma::RequestConfiguration::kUnderAgeOfConsentUnspecified); -#endif - - EXPECT_EQ(retrieved_configuration.test_device_ids.size(), 3); - EXPECT_TRUE(std::count(retrieved_configuration.test_device_ids.begin(), - retrieved_configuration.test_device_ids.end(), "1")); - EXPECT_TRUE(std::count(retrieved_configuration.test_device_ids.begin(), - retrieved_configuration.test_device_ids.end(), "2")); - EXPECT_TRUE(std::count(retrieved_configuration.test_device_ids.begin(), - retrieved_configuration.test_device_ids.end(), "3")); -} - -// Simple Load Tests as a sanity check. These don't show the ad, just -// ensure that we can load them before diving into the interactive tests. -TEST_F(FirebaseGmaTest, TestAdViewLoadAd) { - SKIP_TEST_ON_DESKTOP; - SKIP_TEST_ON_SIMULATOR; - - const firebase::gma::AdSize banner_ad_size(kBannerWidth, kBannerHeight); - firebase::gma::AdView* ad_view = new firebase::gma::AdView(); - WaitForCompletion(ad_view->Initialize(app_framework::GetWindowContext(), - kBannerAdUnit, banner_ad_size), - "Initialize"); - firebase::Future load_ad_future; - const firebase::gma::AdResult* result_ptr = nullptr; - - load_ad_future = ad_view->LoadAd(GetAdRequest()); - WaitForCompletion(load_ad_future, "LoadAd"); - - result_ptr = load_ad_future.result(); - ASSERT_NE(result_ptr, nullptr); - EXPECT_TRUE(result_ptr->is_successful()); - - ASSERT_NE(result_ptr, nullptr); - EXPECT_FALSE(result_ptr->response_info().adapter_responses().empty()); - EXPECT_FALSE( - result_ptr->response_info().mediation_adapter_class_name().empty()); - EXPECT_FALSE(result_ptr->response_info().response_id().empty()); - EXPECT_FALSE(result_ptr->response_info().ToString().empty()); - - EXPECT_EQ(ad_view->ad_size().width(), kBannerWidth); - EXPECT_EQ(ad_view->ad_size().height(), kBannerHeight); - EXPECT_EQ(ad_view->ad_size().type(), firebase::gma::AdSize::kTypeStandard); - - load_ad_future.Release(); - WaitForCompletion(ad_view->Destroy(), "Destroy"); - delete ad_view; -} - -TEST_F(FirebaseGmaTest, TestInterstitialAdLoad) { - SKIP_TEST_ON_DESKTOP; - SKIP_TEST_ON_SIMULATOR; - - firebase::gma::InterstitialAd* interstitial = - new firebase::gma::InterstitialAd(); - - WaitForCompletion(interstitial->Initialize(app_framework::GetWindowContext()), - "Initialize"); - - // When the InterstitialAd is initialized, load an ad. - firebase::Future load_ad_future = - interstitial->LoadAd(kInterstitialAdUnit, GetAdRequest()); - - // This test behaves differently if it's running in UI mode - // (manually on a device) or in non-UI mode (via automated tests). - if (ShouldRunUITests()) { - // Run in manual mode: fail if any error occurs. - WaitForCompletion(load_ad_future, "LoadAd"); - } else { - // Run in automated test mode: don't fail if NoFill occurred. - WaitForCompletion( - load_ad_future, "LoadAd (ignoring NoFill error)", - {firebase::gma::kAdErrorCodeNone, firebase::gma::kAdErrorCodeNoFill}); - } - if (load_ad_future.error() == firebase::gma::kAdErrorCodeNone) { - const firebase::gma::AdResult* result_ptr = load_ad_future.result(); - ASSERT_NE(result_ptr, nullptr); - EXPECT_TRUE(result_ptr->is_successful()); - EXPECT_FALSE(result_ptr->response_info().adapter_responses().empty()); - EXPECT_FALSE( - result_ptr->response_info().mediation_adapter_class_name().empty()); - EXPECT_FALSE(result_ptr->response_info().response_id().empty()); - EXPECT_FALSE(result_ptr->response_info().ToString().empty()); - } - - load_ad_future.Release(); - delete interstitial; -} - -TEST_F(FirebaseGmaTest, TestRewardedAdLoad) { - SKIP_TEST_ON_DESKTOP; - SKIP_TEST_ON_SIMULATOR; - - firebase::gma::RewardedAd* rewarded = new firebase::gma::RewardedAd(); - - WaitForCompletion(rewarded->Initialize(app_framework::GetWindowContext()), - "Initialize"); - - // When the RewardedAd is initialized, load an ad. - firebase::Future load_ad_future = - rewarded->LoadAd(kRewardedAdUnit, GetAdRequest()); - - // This test behaves differently if it's running in UI mode - // (manually on a device) or in non-UI mode (via automated tests). - if (ShouldRunUITests()) { - // Run in manual mode: fail if any error occurs. - WaitForCompletion(load_ad_future, "LoadAd"); - } else { - // Run in automated test mode: don't fail if NoFill occurred. - WaitForCompletion( - load_ad_future, "LoadAd (ignoring NoFill error)", - {firebase::gma::kAdErrorCodeNone, firebase::gma::kAdErrorCodeNoFill}); - } - if (load_ad_future.error() == firebase::gma::kAdErrorCodeNone) { - // In UI mode, or in non-UI mode if a NoFill error didn't occur, check that - // the ad loaded correctly. - const firebase::gma::AdResult* result_ptr = load_ad_future.result(); - ASSERT_NE(result_ptr, nullptr); - EXPECT_TRUE(result_ptr->is_successful()); - EXPECT_FALSE(result_ptr->response_info().adapter_responses().empty()); - EXPECT_FALSE( - result_ptr->response_info().mediation_adapter_class_name().empty()); - EXPECT_FALSE(result_ptr->response_info().response_id().empty()); - EXPECT_FALSE(result_ptr->response_info().ToString().empty()); - } - load_ad_future.Release(); - delete rewarded; -} - -TEST_F(FirebaseGmaTest, TestNativeAdLoad) { - SKIP_TEST_ON_DESKTOP; - SKIP_TEST_ON_SIMULATOR; - - firebase::gma::NativeAd* native_ad = new firebase::gma::NativeAd(); - - WaitForCompletion(native_ad->Initialize(app_framework::GetWindowContext()), - "Initialize"); - - // When the NativeAd is initialized, load an ad. - firebase::Future load_ad_future = - native_ad->LoadAd(kNativeAdUnit, GetAdRequest()); - - // Don't fail loadAd, if NoFill occurred. - WaitForCompletion( - load_ad_future, "LoadAd (ignoring NoFill error)", - {firebase::gma::kAdErrorCodeNone, firebase::gma::kAdErrorCodeNoFill}); - - if (load_ad_future.error() == firebase::gma::kAdErrorCodeNone) { - const firebase::gma::AdResult* result_ptr = load_ad_future.result(); - ASSERT_NE(result_ptr, nullptr); - EXPECT_TRUE(result_ptr->is_successful()); - EXPECT_FALSE(result_ptr->response_info().adapter_responses().empty()); - EXPECT_FALSE( - result_ptr->response_info().mediation_adapter_class_name().empty()); - EXPECT_FALSE(result_ptr->response_info().response_id().empty()); - EXPECT_FALSE(result_ptr->response_info().ToString().empty()); - - // Check image assets. - // Native ads usually contain only one large image asset. - // Check the validity of the first asset from the vector. - EXPECT_FALSE(native_ad->images().empty()); - EXPECT_FALSE(native_ad->images().at(0).image_uri().empty()); - EXPECT_GT(native_ad->images().at(0).scale(), 0); - - // Try loading large image asset. - firebase::Future load_image_future = - native_ad->images().at(0).LoadImage(); - WaitForCompletion(load_image_future, "LoadImage"); - const firebase::gma::ImageResult* img_result_ptr = - load_image_future.result(); - ASSERT_NE(img_result_ptr, nullptr); - EXPECT_TRUE(img_result_ptr->is_successful()); - EXPECT_GT(img_result_ptr->image().size(), 0); - - load_image_future.Release(); - } else if (load_ad_future.error() == firebase::gma::kAdErrorCodeNoFill) { - LogWarning("LoadAd returned NoFill in TestNativeAdLoad"); - } - - load_ad_future.Release(); - delete native_ad; -} - -TEST_F(FirebaseGmaTest, TestCreateQueryInfo) { - SKIP_TEST_ON_DESKTOP; - SKIP_TEST_ON_SIMULATOR; - - firebase::gma::QueryInfo* query_info = new firebase::gma::QueryInfo(); - - WaitForCompletion(query_info->Initialize(app_framework::GetWindowContext()), - "Initialize"); - - firebase::gma::AdRequest request = GetAdRequest(); - // Set the requester type to 8. QueryInfo gets generated without a - // query_info_type set, but throws a warning that it is missing. - request.add_extra(kAdNetworkExtrasClassName, "query_info_type", - "requester_type_8"); - // When the QueryInfo is initialized, generate a query info string. - firebase::Future create_query_info_future = - query_info->CreateQueryInfo(firebase::gma::kAdFormatNative, request); - - WaitForCompletion(create_query_info_future, "CreateQueryInfo"); - - if (create_query_info_future.error() == firebase::gma::kAdErrorCodeNone) { - const firebase::gma::QueryInfoResult* result_ptr = - create_query_info_future.result(); - ASSERT_NE(result_ptr, nullptr); - EXPECT_TRUE(result_ptr->is_successful()); - EXPECT_FALSE(result_ptr->query_info().empty()); - } - - create_query_info_future.Release(); - delete query_info; -} - -TEST_F(FirebaseGmaTest, TestCreateQueryInfoWithAdUnit) { - SKIP_TEST_ON_DESKTOP; - SKIP_TEST_ON_SIMULATOR; - - firebase::gma::QueryInfo* query_info = new firebase::gma::QueryInfo(); - - WaitForCompletion(query_info->Initialize(app_framework::GetWindowContext()), - "Initialize"); - - firebase::gma::AdRequest request = GetAdRequest(); - // Set the requester type to 8. QueryInfo gets generated without a - // query_info_type set, but throws a warning that it is missing. - request.add_extra(kAdNetworkExtrasClassName, "query_info_type", - "requester_type_8"); - // When the QueryInfo is initialized, generate a query info string. - // Providing a bad/empty ad unit does not affect the query info generation. - firebase::Future create_query_info_future = - query_info->CreateQueryInfoWithAdUnit(firebase::gma::kAdFormatNative, - request, kNativeAdUnit); - - WaitForCompletion(create_query_info_future, "CreateQueryInfoWithAdUnit"); - - if (create_query_info_future.error() == firebase::gma::kAdErrorCodeNone) { - const firebase::gma::QueryInfoResult* result_ptr = - create_query_info_future.result(); - ASSERT_NE(result_ptr, nullptr); - EXPECT_TRUE(result_ptr->is_successful()); - EXPECT_FALSE(result_ptr->query_info().empty()); - } - - create_query_info_future.Release(); - delete query_info; -} - -// Interactive test section. These have been placed up front so that the -// tester doesn't get bored waiting for them. -TEST_F(FirebaseGmaUITest, TestAdViewAdOpenedAdClosed) { - SKIP_TEST_ON_DESKTOP; - SKIP_TEST_ON_SIMULATOR; - - const firebase::gma::AdSize banner_ad_size(kBannerWidth, kBannerHeight); - firebase::gma::AdView* ad_view = new firebase::gma::AdView(); - WaitForCompletion(ad_view->Initialize(app_framework::GetWindowContext(), - kBannerAdUnit, banner_ad_size), - "Initialize"); - - // Set the listener. - TestAdListener ad_listener; - ad_view->SetAdListener(&ad_listener); - - TestPaidEventListener paid_event_listener; - ad_view->SetPaidEventListener(&paid_event_listener); - - // Load the AdView ad. - firebase::gma::AdRequest request = GetAdRequest(); - firebase::Future load_ad_future = - ad_view->LoadAd(request); - WaitForCompletion(load_ad_future, "LoadAd"); - - if (load_ad_future.error() == firebase::gma::kAdErrorCodeNone) { - WaitForCompletion(ad_view->Show(), "Show 0"); - - // Ad Events differ per platform. See the following for more info: - // https://www.googblogs.com/google-mobile-ads-sdk-a-note-on-ad-click-events/ - // and https://groups.google.com/g/google-admob-ads-sdk/c/lzdt5szxSVU -#if defined(ANDROID) - LogDebug("Click the Ad, and then close the ad to continue"); - - while (ad_listener.num_on_ad_opened_ == 0) { - app_framework::ProcessEvents(1000); - } - - while (ad_listener.num_on_ad_closed_ == 0) { - app_framework::ProcessEvents(1000); - } - - // Ensure all of the expected events were triggered on Android. - EXPECT_EQ(ad_listener.num_on_ad_clicked_, 1); - EXPECT_EQ(ad_listener.num_on_ad_impression_, 1); - EXPECT_EQ(ad_listener.num_on_ad_opened_, 1); - EXPECT_EQ(ad_listener.num_on_ad_closed_, 1); - EXPECT_EQ(paid_event_listener.num_paid_events(), 1); -#else - LogDebug("Click the Ad, and then close the ad to continue"); - - while (ad_listener.num_on_ad_clicked_ == 0) { - app_framework::ProcessEvents(1000); - } - - LogDebug("Waiting for a moment to ensure all callbacks are recorded."); - app_framework::ProcessEvents(2000); - - // Ensure all of the expected events were triggered on iOS. - EXPECT_EQ(ad_listener.num_on_ad_clicked_, 1); - EXPECT_EQ(ad_listener.num_on_ad_impression_, 1); - EXPECT_EQ(paid_event_listener.num_paid_events(), 1); - EXPECT_EQ(ad_listener.num_on_ad_opened_, 0); - EXPECT_EQ(ad_listener.num_on_ad_closed_, 0); -#endif - } - - load_ad_future.Release(); - ad_view->SetAdListener(nullptr); - ad_view->SetPaidEventListener(nullptr); - WaitForCompletion(ad_view->Destroy(), "Destroy the AdView"); - delete ad_view; -} - -TEST_F(FirebaseGmaUITest, TestInterstitialAdLoadAndShow) { - SKIP_TEST_ON_DESKTOP; - SKIP_TEST_ON_SIMULATOR; - - firebase::gma::InterstitialAd* interstitial = - new firebase::gma::InterstitialAd(); - - WaitForCompletion(interstitial->Initialize(app_framework::GetWindowContext()), - "Initialize"); - - TestFullScreenContentListener content_listener; - interstitial->SetFullScreenContentListener(&content_listener); - - TestPaidEventListener paid_event_listener; - interstitial->SetPaidEventListener(&paid_event_listener); - - // When the InterstitialAd is initialized, load an ad. - firebase::gma::AdRequest request = GetAdRequest(); - firebase::Future load_ad_future = - interstitial->LoadAd(kInterstitialAdUnit, request); - WaitForCompletion(load_ad_future, "LoadAd"); - - if (load_ad_future.error() == firebase::gma::kAdErrorCodeNone) { - WaitForCompletion(interstitial->Show(), "Show"); - - LogDebug("Click the Ad, and then return to the app to continue"); - - while (content_listener.num_ad_dismissed() == 0) { - app_framework::ProcessEvents(1000); - } - - LogDebug("Waiting for a moment to ensure all callbacks are recorded."); - app_framework::ProcessEvents(2000); - - EXPECT_EQ(content_listener.num_ad_clicked(), 1); - EXPECT_EQ(content_listener.num_ad_showed_content(), 1); - EXPECT_EQ(content_listener.num_ad_impressions(), 1); - EXPECT_EQ(content_listener.num_ad_failed_to_show_content(), 0); - EXPECT_EQ(content_listener.num_ad_dismissed(), 1); - EXPECT_EQ(paid_event_listener.num_paid_events(), 1); - -#if (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) - // Show the Ad again. Note: Android's Interstitial ads fail silently - // when attempting to show the ad twice. - LogDebug("Attempting to show ad again, checking for correct error result."); - WaitForCompletion(interstitial->Show(), "Show"); - app_framework::ProcessEvents(5000); - EXPECT_THAT(content_listener.failure_codes(), - ElementsAre(firebase::gma::kAdErrorCodeAdAlreadyUsed)); -#endif // TARGET_OS_IPHONE - } - - load_ad_future.Release(); - interstitial->SetFullScreenContentListener(nullptr); - interstitial->SetPaidEventListener(nullptr); - - delete interstitial; -} - -TEST_F(FirebaseGmaUITest, TestRewardedAdLoadAndShow) { - SKIP_TEST_ON_DESKTOP; - SKIP_TEST_ON_SIMULATOR; - - // TODO(@drsanta): remove when GMA whitelists CI devices. - TEST_REQUIRES_USER_INTERACTION_ON_IOS; - - firebase::gma::RewardedAd* rewarded = new firebase::gma::RewardedAd(); - - WaitForCompletion(rewarded->Initialize(app_framework::GetWindowContext()), - "Initialize"); - - TestFullScreenContentListener content_listener; - rewarded->SetFullScreenContentListener(&content_listener); - - TestPaidEventListener paid_event_listener; - rewarded->SetPaidEventListener(&paid_event_listener); - - // When the RewardedAd is initialized, load an ad. - firebase::gma::AdRequest request = GetAdRequest(); - firebase::Future load_ad_future = - rewarded->LoadAd(kRewardedAdUnit, request); - WaitForCompletion(load_ad_future, "LoadAd"); - - if (load_ad_future.error() == firebase::gma::kAdErrorCodeNone) { - firebase::gma::RewardedAd::ServerSideVerificationOptions options; - // We cannot programmatically verify that the GMA phone SDKs marshal - // these values properly (there are no get methods). At least invoke the - // method to ensure least we can set them without any exceptions occurring. - options.custom_data = "custom data"; - options.user_id = "123456"; - rewarded->SetServerSideVerificationOptions(options); - - TestUserEarnedRewardListener earned_reward_listener; - WaitForCompletion(rewarded->Show(&earned_reward_listener), "Show"); - - LogDebug( - "Wait for the Ad to finish playing, click the ad, return to the ad, " - "then close the ad to continue."); - - while (content_listener.num_ad_dismissed() == 0) { - app_framework::ProcessEvents(1000); - } - - LogDebug("Waiting for a moment to ensure all callbacks are recorded."); - app_framework::ProcessEvents(2000); - - // If not running the UI test in CI (running manually), keep this check. - // Else running the UI test in CI, skip this check. - if (!ShouldRunUITests()) { - EXPECT_EQ(content_listener.num_ad_clicked(), 1); - } - EXPECT_EQ(content_listener.num_ad_showed_content(), 1); - EXPECT_EQ(content_listener.num_ad_impressions(), 1); - EXPECT_EQ(content_listener.num_ad_dismissed(), 1); - EXPECT_EQ(content_listener.num_ad_failed_to_show_content(), 0); - EXPECT_EQ(earned_reward_listener.num_earned_rewards(), 1); - EXPECT_EQ(paid_event_listener.num_paid_events(), 1); - - // Show the Ad again - LogDebug("Attempting to show ad again, checking for correct error result."); - WaitForCompletion(rewarded->Show(&earned_reward_listener), "Show"); - app_framework::ProcessEvents(2000); - EXPECT_THAT(content_listener.failure_codes(), - testing::ElementsAre(firebase::gma::kAdErrorCodeAdAlreadyUsed)); - } - - load_ad_future.Release(); - rewarded->SetFullScreenContentListener(nullptr); - rewarded->SetPaidEventListener(nullptr); - - delete rewarded; -} - -// Other AdView Tests - -TEST_F(FirebaseGmaTest, TestAdViewLoadAdEmptyAdRequest) { - SKIP_TEST_ON_DESKTOP; - SKIP_TEST_ON_SIMULATOR; - - const firebase::gma::AdSize banner_ad_size(kBannerWidth, kBannerHeight); - firebase::gma::AdView* ad_view = new firebase::gma::AdView(); - WaitForCompletion(ad_view->Initialize(app_framework::GetWindowContext(), - kBannerAdUnit, banner_ad_size), - "Initialize"); - firebase::gma::AdRequest request; - firebase::Future load_ad_future; - const firebase::gma::AdResult* result_ptr = nullptr; - - load_ad_future = ad_view->LoadAd(request); - WaitForCompletion(load_ad_future, "LoadAd"); - result_ptr = load_ad_future.result(); - ASSERT_NE(result_ptr, nullptr); - EXPECT_TRUE(result_ptr->is_successful()); - - EXPECT_FALSE(result_ptr->response_info().adapter_responses().empty()); - EXPECT_FALSE( - result_ptr->response_info().mediation_adapter_class_name().empty()); - EXPECT_FALSE(result_ptr->response_info().response_id().empty()); - EXPECT_FALSE(result_ptr->response_info().ToString().empty()); - - EXPECT_EQ(ad_view->ad_size().width(), kBannerWidth); - EXPECT_EQ(ad_view->ad_size().height(), kBannerHeight); - EXPECT_EQ(ad_view->ad_size().type(), firebase::gma::AdSize::kTypeStandard); - - load_ad_future.Release(); - WaitForCompletion(ad_view->Destroy(), "Destroy"); - - delete ad_view; -} - -TEST_F(FirebaseGmaTest, TestAdViewLoadAdAnchorAdaptiveAd) { - SKIP_TEST_ON_DESKTOP; - SKIP_TEST_ON_SIMULATOR; - - using firebase::gma::AdSize; - AdSize banner_ad_size = - AdSize::GetCurrentOrientationAnchoredAdaptiveBannerAdSize(kBannerWidth); - firebase::gma::AdView* ad_view = new firebase::gma::AdView(); - WaitForCompletion(ad_view->Initialize(app_framework::GetWindowContext(), - kBannerAdUnit, banner_ad_size), - "Initialize"); - - WaitForCompletion(ad_view->LoadAd(GetAdRequest()), "LoadAd"); - - const AdSize ad_size = ad_view->ad_size(); - EXPECT_EQ(ad_size.width(), kBannerWidth); - EXPECT_NE(ad_size.height(), 0); - EXPECT_EQ(ad_size.type(), AdSize::kTypeAnchoredAdaptive); - EXPECT_EQ(ad_size.orientation(), AdSize::kOrientationCurrent); - WaitForCompletion(ad_view->Destroy(), "Destroy"); - delete ad_view; -} - -TEST_F(FirebaseGmaTest, TestAdViewLoadAdInlineAdaptiveAd) { - SKIP_TEST_ON_DESKTOP; - SKIP_TEST_ON_SIMULATOR; - using firebase::gma::AdSize; - - using firebase::gma::AdSize; - AdSize banner_ad_size = - AdSize::GetCurrentOrientationInlineAdaptiveBannerAdSize(kBannerWidth); - firebase::gma::AdView* ad_view = new firebase::gma::AdView(); - WaitForCompletion(ad_view->Initialize(app_framework::GetWindowContext(), - kBannerAdUnit, banner_ad_size), - "Initialize"); - - WaitForCompletion(ad_view->LoadAd(GetAdRequest()), "LoadAd"); - - const AdSize ad_size = ad_view->ad_size(); - EXPECT_EQ(ad_size.width(), kBannerWidth); - EXPECT_NE(ad_size.height(), 0); - EXPECT_EQ(ad_size.type(), AdSize::kTypeInlineAdaptive); - EXPECT_EQ(ad_size.orientation(), AdSize::kOrientationCurrent); - WaitForCompletion(ad_view->Destroy(), "Destroy"); - delete ad_view; -} - -TEST_F(FirebaseGmaTest, TestAdViewLoadAdGetInlineAdaptiveBannerMaxHeight) { - SKIP_TEST_ON_DESKTOP; - SKIP_TEST_ON_SIMULATOR; - - using firebase::gma::AdSize; - AdSize banner_ad_size = - AdSize::GetInlineAdaptiveBannerAdSize(kBannerWidth, kBannerHeight); - firebase::gma::AdView* ad_view = new firebase::gma::AdView(); - WaitForCompletion(ad_view->Initialize(app_framework::GetWindowContext(), - kBannerAdUnit, banner_ad_size), - "Initialize"); - - WaitForCompletion(ad_view->LoadAd(GetAdRequest()), "LoadAd"); - - const AdSize ad_size = ad_view->ad_size(); - EXPECT_EQ(ad_size.width(), kBannerWidth); - EXPECT_NE(ad_size.height(), 0); - EXPECT_TRUE(ad_size.height() <= kBannerHeight); - EXPECT_EQ(ad_size.type(), AdSize::kTypeInlineAdaptive); - EXPECT_EQ(ad_size.orientation(), AdSize::kOrientationCurrent); - WaitForCompletion(ad_view->Destroy(), "Destroy"); - delete ad_view; -} - -TEST_F(FirebaseGmaTest, TestAdViewLoadAdDestroyNotCalled) { - SKIP_TEST_ON_DESKTOP; - SKIP_TEST_ON_SIMULATOR; - - const firebase::gma::AdSize banner_ad_size(kBannerWidth, kBannerHeight); - firebase::gma::AdView* ad_view = new firebase::gma::AdView(); - WaitForCompletion(ad_view->Initialize(app_framework::GetWindowContext(), - kBannerAdUnit, banner_ad_size), - "Initialize"); - WaitForCompletion(ad_view->LoadAd(GetAdRequest()), "LoadAd"); - delete ad_view; -} - -TEST_F(FirebaseGmaTest, TestAdViewAdSizeCompareOp) { - using firebase::gma::AdSize; - EXPECT_TRUE(AdSize(50, 100) == AdSize(50, 100)); - EXPECT_TRUE(AdSize(100, 50) == AdSize(100, 50)); - EXPECT_FALSE(AdSize(50, 100) == AdSize(100, 50)); - EXPECT_FALSE(AdSize(10, 10) == AdSize(50, 50)); - - EXPECT_FALSE(AdSize(50, 100) != AdSize(50, 100)); - EXPECT_FALSE(AdSize(100, 50) != AdSize(100, 50)); - EXPECT_TRUE(AdSize(50, 100) != AdSize(100, 50)); - EXPECT_TRUE(AdSize(10, 10) != AdSize(50, 50)); - - EXPECT_TRUE(AdSize::GetLandscapeAnchoredAdaptiveBannerAdSize(100) == - AdSize::GetLandscapeAnchoredAdaptiveBannerAdSize(100)); - EXPECT_FALSE(AdSize::GetLandscapeAnchoredAdaptiveBannerAdSize(100) != - AdSize::GetLandscapeAnchoredAdaptiveBannerAdSize(100)); - - EXPECT_TRUE(AdSize::GetPortraitAnchoredAdaptiveBannerAdSize(100) == - AdSize::GetPortraitAnchoredAdaptiveBannerAdSize(100)); - EXPECT_FALSE(AdSize::GetPortraitAnchoredAdaptiveBannerAdSize(100) != - AdSize::GetPortraitAnchoredAdaptiveBannerAdSize(100)); - - EXPECT_TRUE(AdSize::GetInlineAdaptiveBannerAdSize(100, 50) == - AdSize::GetInlineAdaptiveBannerAdSize(100, 50)); - EXPECT_FALSE(AdSize::GetInlineAdaptiveBannerAdSize(100, 50) != - AdSize::GetInlineAdaptiveBannerAdSize(100, 50)); - - EXPECT_TRUE(AdSize::GetLandscapeInlineAdaptiveBannerAdSize(100) == - AdSize::GetLandscapeInlineAdaptiveBannerAdSize(100)); - EXPECT_FALSE(AdSize::GetLandscapeInlineAdaptiveBannerAdSize(100) != - AdSize::GetLandscapeInlineAdaptiveBannerAdSize(100)); - - EXPECT_TRUE(AdSize::GetPortraitInlineAdaptiveBannerAdSize(100) == - AdSize::GetPortraitInlineAdaptiveBannerAdSize(100)); - EXPECT_TRUE(AdSize::GetLandscapeInlineAdaptiveBannerAdSize(100) == - AdSize::GetLandscapeInlineAdaptiveBannerAdSize(100)); - EXPECT_TRUE(AdSize::GetCurrentOrientationInlineAdaptiveBannerAdSize(100) == - AdSize::GetCurrentOrientationInlineAdaptiveBannerAdSize(100)); - - EXPECT_FALSE(AdSize::GetLandscapeAnchoredAdaptiveBannerAdSize(100) == - AdSize::GetPortraitAnchoredAdaptiveBannerAdSize(100)); - EXPECT_TRUE(AdSize::GetLandscapeAnchoredAdaptiveBannerAdSize(100) != - AdSize::GetPortraitAnchoredAdaptiveBannerAdSize(100)); - - EXPECT_FALSE(AdSize::GetLandscapeAnchoredAdaptiveBannerAdSize(100) == - AdSize(100, 100)); - EXPECT_TRUE(AdSize::GetLandscapeAnchoredAdaptiveBannerAdSize(100) != - AdSize(100, 100)); - - EXPECT_FALSE(AdSize::GetPortraitAnchoredAdaptiveBannerAdSize(100) == - AdSize(100, 100)); - EXPECT_TRUE(AdSize::GetPortraitAnchoredAdaptiveBannerAdSize(100) != - AdSize(100, 100)); -} - -TEST_F(FirebaseGmaTest, TestAdViewDestroyBeforeInitialization) { - SKIP_TEST_ON_DESKTOP; - firebase::gma::AdView* ad_view = new firebase::gma::AdView(); - WaitForCompletion(ad_view->Destroy(), "Destroy AdView"); -} - -TEST_F(FirebaseGmaTest, TestAdViewAdSizeBeforeInitialization) { - SKIP_TEST_ON_DESKTOP; - firebase::gma::AdView* ad_view = new firebase::gma::AdView(); - const firebase::gma::AdSize& ad_size = firebase::gma::AdSize(0, 0); - EXPECT_TRUE(ad_view->ad_size() == ad_size); - - WaitForCompletion(ad_view->Destroy(), "Destroy AdView"); -} - -TEST_F(FirebaseGmaTest, TestAdView) { - SKIP_TEST_ON_DESKTOP; - SKIP_TEST_ON_SIMULATOR; - - const firebase::gma::AdSize banner_ad_size(kBannerWidth, kBannerHeight); - firebase::gma::AdView* ad_view = new firebase::gma::AdView(); - WaitForCompletion(ad_view->Initialize(app_framework::GetWindowContext(), - kBannerAdUnit, banner_ad_size), - "Initialize"); - EXPECT_TRUE(ad_view->ad_size() == banner_ad_size); - - // Set the listener. - TestBoundingBoxListener bounding_box_listener; - ad_view->SetBoundingBoxListener(&bounding_box_listener); - PauseForVisualInspectionAndCallbacks(); - - int expected_num_bounding_box_changes = 0; - EXPECT_EQ(expected_num_bounding_box_changes, - bounding_box_listener.bounding_box_changes_.size()); - - // Load the AdView ad. - firebase::gma::AdRequest request = GetAdRequest(); - firebase::Future load_ad_future = - ad_view->LoadAd(request); - WaitForCompletion(load_ad_future, "LoadAd"); - - const bool ad_loaded = - load_ad_future.error() == firebase::gma::kAdErrorCodeNone; - - // Suppress the extensive testing below if the ad failed to load. - if (ad_loaded) { - EXPECT_EQ(ad_view->ad_size().width(), kBannerWidth); - EXPECT_EQ(ad_view->ad_size().height(), kBannerHeight); - EXPECT_EQ(expected_num_bounding_box_changes, - bounding_box_listener.bounding_box_changes_.size()); - const firebase::gma::AdResult* result_ptr = load_ad_future.result(); - ASSERT_NE(result_ptr, nullptr); - EXPECT_TRUE(result_ptr->is_successful()); - const firebase::gma::ResponseInfo response_info = - result_ptr->ad_error().response_info(); - EXPECT_TRUE(response_info.adapter_responses().empty()); - - // Make the AdView visible. - WaitForCompletion(ad_view->Show(), "Show 0"); - PauseForVisualInspectionAndCallbacks(); - EXPECT_EQ(++expected_num_bounding_box_changes, - bounding_box_listener.bounding_box_changes_.size()); - - // Move to each of the six pre-defined positions. - WaitForCompletion(ad_view->SetPosition(firebase::gma::AdView::kPositionTop), - "SetPosition(Top)"); - PauseForVisualInspectionAndCallbacks(); - EXPECT_EQ(ad_view->bounding_box().position, - firebase::gma::AdView::kPositionTop); - EXPECT_EQ(++expected_num_bounding_box_changes, - bounding_box_listener.bounding_box_changes_.size()); - - WaitForCompletion( - ad_view->SetPosition(firebase::gma::AdView::kPositionTopLeft), - "SetPosition(TopLeft)"); - PauseForVisualInspectionAndCallbacks(); - EXPECT_EQ(ad_view->bounding_box().position, - firebase::gma::AdView::kPositionTopLeft); - EXPECT_EQ(++expected_num_bounding_box_changes, - bounding_box_listener.bounding_box_changes_.size()); - - WaitForCompletion( - ad_view->SetPosition(firebase::gma::AdView::kPositionTopRight), - "SetPosition(TopRight)"); - PauseForVisualInspectionAndCallbacks(); - EXPECT_EQ(ad_view->bounding_box().position, - firebase::gma::AdView::kPositionTopRight); - EXPECT_EQ(++expected_num_bounding_box_changes, - bounding_box_listener.bounding_box_changes_.size()); - - WaitForCompletion( - ad_view->SetPosition(firebase::gma::AdView::kPositionBottom), - "SetPosition(Bottom)"); - PauseForVisualInspectionAndCallbacks(); - EXPECT_EQ(ad_view->bounding_box().position, - firebase::gma::AdView::kPositionBottom); - EXPECT_EQ(++expected_num_bounding_box_changes, - bounding_box_listener.bounding_box_changes_.size()); - - WaitForCompletion( - ad_view->SetPosition(firebase::gma::AdView::kPositionBottomLeft), - "SetPosition(BottomLeft)"); - PauseForVisualInspectionAndCallbacks(); - EXPECT_EQ(ad_view->bounding_box().position, - firebase::gma::AdView::kPositionBottomLeft); - EXPECT_EQ(++expected_num_bounding_box_changes, - bounding_box_listener.bounding_box_changes_.size()); - - WaitForCompletion( - ad_view->SetPosition(firebase::gma::AdView::kPositionBottomRight), - "SetPosition(BottomRight)"); - PauseForVisualInspectionAndCallbacks(); - EXPECT_EQ(ad_view->bounding_box().position, - firebase::gma::AdView::kPositionBottomRight); - EXPECT_EQ(++expected_num_bounding_box_changes, - bounding_box_listener.bounding_box_changes_.size()); - - // Move to some coordinates. - WaitForCompletion(ad_view->SetPosition(100, 300), "SetPosition(x0, y0)"); - PauseForVisualInspectionAndCallbacks(); - EXPECT_EQ(ad_view->bounding_box().position, - firebase::gma::AdView::kPositionUndefined); - EXPECT_EQ(++expected_num_bounding_box_changes, - bounding_box_listener.bounding_box_changes_.size()); - - WaitForCompletion(ad_view->SetPosition(100, 400), "SetPosition(x1, y1)"); - PauseForVisualInspectionAndCallbacks(); - EXPECT_EQ(ad_view->bounding_box().position, - firebase::gma::AdView::kPositionUndefined); - EXPECT_EQ(++expected_num_bounding_box_changes, - bounding_box_listener.bounding_box_changes_.size()); - - // Try hiding and showing the AdView. - WaitForCompletion(ad_view->Hide(), "Hide 1"); - PauseForVisualInspectionAndCallbacks(); - EXPECT_EQ(expected_num_bounding_box_changes, - bounding_box_listener.bounding_box_changes_.size()); - - WaitForCompletion(ad_view->Show(), "Show 1"); - PauseForVisualInspectionAndCallbacks(); - EXPECT_EQ(++expected_num_bounding_box_changes, - bounding_box_listener.bounding_box_changes_.size()); - - // Move again after hiding/showing. - WaitForCompletion(ad_view->SetPosition(100, 300), "SetPosition(x2, y2)"); - PauseForVisualInspectionAndCallbacks(); - EXPECT_EQ(ad_view->bounding_box().position, - firebase::gma::AdView::kPositionUndefined); - EXPECT_EQ(++expected_num_bounding_box_changes, - bounding_box_listener.bounding_box_changes_.size()); - - WaitForCompletion(ad_view->SetPosition(100, 400), "SetPosition(x3, y3)"); - PauseForVisualInspectionAndCallbacks(); - EXPECT_EQ(ad_view->bounding_box().position, - firebase::gma::AdView::kPositionUndefined); - EXPECT_EQ(++expected_num_bounding_box_changes, - bounding_box_listener.bounding_box_changes_.size()); - - WaitForCompletion(ad_view->Hide(), "Hide 2"); - PauseForVisualInspectionAndCallbacks(); - EXPECT_EQ(expected_num_bounding_box_changes, - bounding_box_listener.bounding_box_changes_.size()); - - LogDebug("Waiting for a moment to ensure all callbacks are recorded."); - app_framework::ProcessEvents(2000); - } - - // Clean up the ad object. - load_ad_future.Release(); - WaitForCompletion(ad_view->Destroy(), "Destroy AdView"); - ad_view->SetBoundingBoxListener(nullptr); - delete ad_view; - - PauseForVisualInspectionAndCallbacks(); - - if (ad_loaded) { - // If the ad was show, do the final bounding box checks after the ad has - // been destroyed. -#if defined(ANDROID) || TARGET_OS_IPHONE - EXPECT_EQ(++expected_num_bounding_box_changes, - bounding_box_listener.bounding_box_changes_.size()); - - // As an extra check, all bounding boxes except the last should have the - // same size aspect ratio that we requested. For example if you requested a - // 320x50 banner, you can get one with the size 960x150. Use EXPECT_NEAR - // because the calculation can have a small bit of error. - double kAspectRatioAllowedError = 0.05; // Allow about 5% of error. - double expected_aspect_ratio = - static_cast(kBannerWidth) / static_cast(kBannerHeight); - for (int i = 0; i < bounding_box_listener.bounding_box_changes_.size() - 1; - ++i) { - double actual_aspect_ratio = - static_cast( - bounding_box_listener.bounding_box_changes_[i].width) / - static_cast( - bounding_box_listener.bounding_box_changes_[i].height); - EXPECT_NEAR(actual_aspect_ratio, expected_aspect_ratio, - kAspectRatioAllowedError) - << "AdView size " - << bounding_box_listener.bounding_box_changes_[i].width << "x" - << bounding_box_listener.bounding_box_changes_[i].height - << " does not have the same aspect ratio as requested size " - << kBannerWidth << "x" << kBannerHeight << "."; - } - - // And finally, the last bounding box change, when the AdView is deleted, - // should have invalid values (-1,-1, -1, -1). - EXPECT_TRUE( - bounding_box_listener.bounding_box_changes_.back().x == -1 && - bounding_box_listener.bounding_box_changes_.back().y == -1 && - bounding_box_listener.bounding_box_changes_.back().width == -1 && - bounding_box_listener.bounding_box_changes_.back().height == -1); -#endif // defined(ANDROID) || TARGET_OS_IPHONE - } -} - -TEST_F(FirebaseGmaTest, TestAdViewErrorNotInitialized) { - SKIP_TEST_ON_DESKTOP; - - firebase::gma::AdView* ad_view = new firebase::gma::AdView(); - - WaitForCompletion(ad_view->LoadAd(GetAdRequest()), "LoadAd", - firebase::gma::kAdErrorCodeUninitialized); - - firebase::gma::AdView::Position position; - WaitForCompletion(ad_view->SetPosition(position), "SetPosition(position)", - firebase::gma::kAdErrorCodeUninitialized); - - WaitForCompletion(ad_view->SetPosition(0, 0), "SetPosition(x,y)", - firebase::gma::kAdErrorCodeUninitialized); - - WaitForCompletion(ad_view->Hide(), "Hide", - firebase::gma::kAdErrorCodeUninitialized); - WaitForCompletion(ad_view->Show(), "Show", - firebase::gma::kAdErrorCodeUninitialized); - WaitForCompletion(ad_view->Pause(), "Pause", - firebase::gma::kAdErrorCodeUninitialized); - WaitForCompletion(ad_view->Resume(), "Resume", - firebase::gma::kAdErrorCodeUninitialized); - WaitForCompletion(ad_view->Destroy(), "Destroy the AdView"); - delete ad_view; -} - -TEST_F(FirebaseGmaTest, TestAdViewErrorAlreadyInitialized) { - SKIP_TEST_ON_DESKTOP; - - const firebase::gma::AdSize banner_ad_size(kBannerWidth, kBannerHeight); - { - firebase::gma::AdView* ad_view = new firebase::gma::AdView(); - firebase::Future first_initialize = ad_view->Initialize( - app_framework::GetWindowContext(), kBannerAdUnit, banner_ad_size); - firebase::Future second_initialize = ad_view->Initialize( - app_framework::GetWindowContext(), kBannerAdUnit, banner_ad_size); - - WaitForCompletion(first_initialize, "First Initialize 1"); - WaitForCompletion(second_initialize, "Second Initialize 1", - firebase::gma::kAdErrorCodeAlreadyInitialized); - - first_initialize.Release(); - second_initialize.Release(); - WaitForCompletion(ad_view->Destroy(), "Destroy AdView 1"); - delete ad_view; - } - - // Reverse the order of the completion waits. - { - firebase::gma::AdView* ad_view = new firebase::gma::AdView(); - firebase::Future first_initialize = ad_view->Initialize( - app_framework::GetWindowContext(), kBannerAdUnit, banner_ad_size); - firebase::Future second_initialize = ad_view->Initialize( - app_framework::GetWindowContext(), kBannerAdUnit, banner_ad_size); - - WaitForCompletion(second_initialize, "Second Initialize 1", - firebase::gma::kAdErrorCodeAlreadyInitialized); - WaitForCompletion(first_initialize, "First Initialize 1"); - - first_initialize.Release(); - second_initialize.Release(); - WaitForCompletion(ad_view->Destroy(), "Destroy AdView 2"); - delete ad_view; - } -} - -TEST_F(FirebaseGmaTest, TestAdViewErrorLoadInProgress) { - SKIP_TEST_ON_DESKTOP; - - const firebase::gma::AdSize banner_ad_size(kBannerWidth, kBannerHeight); - firebase::gma::AdView* ad_view = new firebase::gma::AdView(); - WaitForCompletion(ad_view->Initialize(app_framework::GetWindowContext(), - kBannerAdUnit, banner_ad_size), - "Initialize"); - - // Load the AdView ad. - // Note potential flake: this test assumes the attempt to load an ad - // won't resolve immediately. If it does then the result may be two - // successful ad loads instead of the expected - // kAdErrorCodeLoadInProgress error. - firebase::gma::AdRequest request = GetAdRequest(); - firebase::Future first_load_ad = - ad_view->LoadAd(request); - firebase::Future second_load_ad = - ad_view->LoadAd(request); - - WaitForCompletion(second_load_ad, "Second LoadAd", - firebase::gma::kAdErrorCodeLoadInProgress); - WaitForCompletionAnyResult(first_load_ad, "First LoadAd"); - - const firebase::gma::AdResult* result_ptr = second_load_ad.result(); - ASSERT_NE(result_ptr, nullptr); - EXPECT_FALSE(result_ptr->is_successful()); - EXPECT_EQ(result_ptr->ad_error().code(), - firebase::gma::kAdErrorCodeLoadInProgress); - EXPECT_EQ(result_ptr->ad_error().message(), "Ad is currently loading."); - EXPECT_EQ(result_ptr->ad_error().domain(), "SDK"); - const firebase::gma::ResponseInfo response_info = - result_ptr->ad_error().response_info(); - EXPECT_TRUE(response_info.adapter_responses().empty()); - - first_load_ad.Release(); - second_load_ad.Release(); - - WaitForCompletion(ad_view->Destroy(), "Destroy the AdView"); - delete ad_view; -} - -TEST_F(FirebaseGmaTest, TestAdViewErrorBadAdUnitId) { - SKIP_TEST_ON_DESKTOP; - - const firebase::gma::AdSize banner_ad_size(kBannerWidth, kBannerHeight); - firebase::gma::AdView* ad_view = new firebase::gma::AdView(); - WaitForCompletion(ad_view->Initialize(app_framework::GetWindowContext(), - kBadAdUnit, banner_ad_size), - "Initialize"); - - // Load the AdView ad. - firebase::gma::AdRequest request = GetAdRequest(); - firebase::Future load_ad = ad_view->LoadAd(request); - WaitForCompletion(load_ad, "LoadAd", - firebase::gma::kAdErrorCodeInvalidRequest); - - const firebase::gma::AdResult* result_ptr = load_ad.result(); - ASSERT_NE(result_ptr, nullptr); - EXPECT_FALSE(result_ptr->is_successful()); - EXPECT_EQ(result_ptr->ad_error().code(), - firebase::gma::kAdErrorCodeInvalidRequest); - - EXPECT_FALSE(result_ptr->ad_error().message().empty()); - EXPECT_EQ(result_ptr->ad_error().domain(), kErrorDomain); - - const firebase::gma::ResponseInfo response_info = - result_ptr->ad_error().response_info(); - EXPECT_TRUE(response_info.adapter_responses().empty()); - load_ad.Release(); - - WaitForCompletion(ad_view->Destroy(), "Destroy the AdView"); - delete ad_view; -} - -TEST_F(FirebaseGmaTest, TestAdViewErrorBadExtrasClassName) { - SKIP_TEST_ON_DESKTOP; - - const firebase::gma::AdSize banner_ad_size(kBannerWidth, kBannerHeight); - firebase::gma::AdView* ad_view = new firebase::gma::AdView(); - WaitForCompletion(ad_view->Initialize(app_framework::GetWindowContext(), - kBannerAdUnit, banner_ad_size), - "Initialize"); - - // Load the AdView ad. - firebase::gma::AdRequest request = GetAdRequest(); - request.add_extra(kAdNetworkExtrasInvalidClassName, "shouldnot", "work"); - WaitForCompletion(ad_view->LoadAd(request), "LoadAd", - firebase::gma::kAdErrorCodeAdNetworkClassLoadError); - WaitForCompletion(ad_view->Destroy(), "Destroy the AdView"); - delete ad_view; -} - -// Other InterstitialAd Tests - -TEST_F(FirebaseGmaTest, TestInterstitialAdLoadEmptyRequest) { - SKIP_TEST_ON_DESKTOP; - SKIP_TEST_ON_SIMULATOR; - - firebase::gma::InterstitialAd* interstitial = - new firebase::gma::InterstitialAd(); - - WaitForCompletion(interstitial->Initialize(app_framework::GetWindowContext()), - "Initialize"); - - // When the InterstitialAd is initialized, load an ad. - firebase::gma::AdRequest request; - - firebase::Future load_ad_future = - interstitial->LoadAd(kInterstitialAdUnit, request); - - // This test behaves differently if it's running in UI mode - // (manually on a device) or in non-UI mode (via automated tests). - if (ShouldRunUITests()) { - // Run in manual mode: fail if any error occurs. - WaitForCompletion(load_ad_future, "LoadAd"); - } else { - // Run in automated test mode: don't fail if NoFill occurred. - WaitForCompletion( - load_ad_future, "LoadAd (ignoring NoFill error)", - {firebase::gma::kAdErrorCodeNone, firebase::gma::kAdErrorCodeNoFill}); - } - if (load_ad_future.error() == firebase::gma::kAdErrorCodeNone) { - const firebase::gma::AdResult* result_ptr = load_ad_future.result(); - ASSERT_NE(result_ptr, nullptr); - EXPECT_TRUE(result_ptr->is_successful()); - EXPECT_FALSE(result_ptr->response_info().adapter_responses().empty()); - EXPECT_FALSE( - result_ptr->response_info().mediation_adapter_class_name().empty()); - EXPECT_FALSE(result_ptr->response_info().response_id().empty()); - EXPECT_FALSE(result_ptr->response_info().ToString().empty()); - } - load_ad_future.Release(); - delete interstitial; -} - -TEST_F(FirebaseGmaTest, TestInterstitialAdErrorNotInitialized) { - SKIP_TEST_ON_DESKTOP; - - firebase::gma::InterstitialAd* interstitial_ad = - new firebase::gma::InterstitialAd(); - - firebase::gma::AdRequest request = GetAdRequest(); - WaitForCompletion(interstitial_ad->LoadAd(kInterstitialAdUnit, request), - "LoadAd", firebase::gma::kAdErrorCodeUninitialized); - WaitForCompletion(interstitial_ad->Show(), "Show", - firebase::gma::kAdErrorCodeUninitialized); - - delete interstitial_ad; -} - -TEST_F(FirebaseGmaTest, TesInterstitialAdErrorAlreadyInitialized) { - SKIP_TEST_ON_DESKTOP; - - { - firebase::gma::InterstitialAd* interstitial_ad = - new firebase::gma::InterstitialAd(); - firebase::Future first_initialize = - interstitial_ad->Initialize(app_framework::GetWindowContext()); - firebase::Future second_initialize = - interstitial_ad->Initialize(app_framework::GetWindowContext()); - - WaitForCompletion(first_initialize, "First Initialize 1"); - WaitForCompletion(second_initialize, "Second Initialize 1", - firebase::gma::kAdErrorCodeAlreadyInitialized); - - first_initialize.Release(); - second_initialize.Release(); - - delete interstitial_ad; - } - - // Reverse the order of the completion waits. - { - firebase::gma::InterstitialAd* interstitial_ad = - new firebase::gma::InterstitialAd(); - firebase::Future first_initialize = - interstitial_ad->Initialize(app_framework::GetWindowContext()); - firebase::Future second_initialize = - interstitial_ad->Initialize(app_framework::GetWindowContext()); - - WaitForCompletion(second_initialize, "Second Initialize 1", - firebase::gma::kAdErrorCodeAlreadyInitialized); - WaitForCompletion(first_initialize, "First Initialize 1"); - - first_initialize.Release(); - second_initialize.Release(); - - delete interstitial_ad; - } -} - -TEST_F(FirebaseGmaTest, TestInterstitialAdErrorLoadInProgress) { - SKIP_TEST_ON_DESKTOP; - - firebase::gma::InterstitialAd* interstitial_ad = - new firebase::gma::InterstitialAd(); - WaitForCompletion( - interstitial_ad->Initialize(app_framework::GetWindowContext()), - "Initialize"); - - // Load the interstitial ad. - // Note potential flake: this test assumes the attempt to load an ad - // won't resolve immediately. If it does then the result may be two - // successful ad loads instead of the expected - // kAdErrorCodeLoadInProgress error. - firebase::gma::AdRequest request = GetAdRequest(); - firebase::Future first_load_ad = - interstitial_ad->LoadAd(kInterstitialAdUnit, request); - firebase::Future second_load_ad = - interstitial_ad->LoadAd(kInterstitialAdUnit, request); - - WaitForCompletion(second_load_ad, "Second LoadAd", - firebase::gma::kAdErrorCodeLoadInProgress); - WaitForCompletionAnyResult(first_load_ad, "First LoadAd"); - - const firebase::gma::AdResult* result_ptr = second_load_ad.result(); - ASSERT_NE(result_ptr, nullptr); - EXPECT_FALSE(result_ptr->is_successful()); - EXPECT_EQ(result_ptr->ad_error().code(), - firebase::gma::kAdErrorCodeLoadInProgress); - EXPECT_EQ(result_ptr->ad_error().message(), "Ad is currently loading."); - EXPECT_EQ(result_ptr->ad_error().domain(), "SDK"); - const firebase::gma::ResponseInfo response_info = - result_ptr->ad_error().response_info(); - EXPECT_TRUE(response_info.adapter_responses().empty()); - - first_load_ad.Release(); - second_load_ad.Release(); - delete interstitial_ad; -} - -TEST_F(FirebaseGmaTest, TestInterstitialAdErrorBadAdUnitId) { - SKIP_TEST_ON_DESKTOP; - - firebase::gma::InterstitialAd* interstitial_ad = - new firebase::gma::InterstitialAd(); - WaitForCompletion( - interstitial_ad->Initialize(app_framework::GetWindowContext()), - "Initialize"); - - // Load the interstitial ad. - firebase::gma::AdRequest request = GetAdRequest(); - firebase::Future load_ad_future = - interstitial_ad->LoadAd(kBadAdUnit, request); - WaitForCompletion(load_ad_future, "LoadAd", - firebase::gma::kAdErrorCodeInvalidRequest); - - const firebase::gma::AdResult* result_ptr = load_ad_future.result(); - ASSERT_NE(result_ptr, nullptr); - EXPECT_FALSE(result_ptr->is_successful()); - EXPECT_EQ(result_ptr->ad_error().code(), - firebase::gma::kAdErrorCodeInvalidRequest); - EXPECT_FALSE(result_ptr->ad_error().message().empty()); - EXPECT_EQ(result_ptr->ad_error().domain(), kErrorDomain); - const firebase::gma::ResponseInfo response_info = - result_ptr->ad_error().response_info(); - EXPECT_TRUE(response_info.adapter_responses().empty()); - - load_ad_future.Release(); - delete interstitial_ad; -} - -TEST_F(FirebaseGmaTest, TestInterstitialAdErrorBadExtrasClassName) { - SKIP_TEST_ON_DESKTOP; - - firebase::gma::InterstitialAd* interstitial_ad = - new firebase::gma::InterstitialAd(); - WaitForCompletion( - interstitial_ad->Initialize(app_framework::GetWindowContext()), - "Initialize"); - - // Load the interstitial ad. - firebase::gma::AdRequest request = GetAdRequest(); - request.add_extra(kAdNetworkExtrasInvalidClassName, "shouldnot", "work"); - WaitForCompletion(interstitial_ad->LoadAd(kInterstitialAdUnit, request), - "LoadAd", - firebase::gma::kAdErrorCodeAdNetworkClassLoadError); - delete interstitial_ad; -} - -// Other RewardedAd Tests. - -TEST_F(FirebaseGmaTest, TestRewardedAdLoadEmptyRequest) { - SKIP_TEST_ON_DESKTOP; - SKIP_TEST_ON_SIMULATOR; - - // Note: while showing an ad requires user interaction in another test, - // this test is mean as a baseline loadAd functionality test. - firebase::gma::RewardedAd* rewarded = new firebase::gma::RewardedAd(); - - WaitForCompletion(rewarded->Initialize(app_framework::GetWindowContext()), - "Initialize"); - - // When the RewardedAd is initialized, load an ad. - firebase::gma::AdRequest request; - firebase::Future load_ad_future = - rewarded->LoadAd(kRewardedAdUnit, request); - - // This test behaves differently if it's running in UI mode - // (manually on a device) or in non-UI mode (via automated tests). - if (ShouldRunUITests()) { - // Run in manual mode: fail if any error occurs. - WaitForCompletion(load_ad_future, "LoadAd"); - } else { - // Run in automated test mode: don't fail if NoFill occurred. - WaitForCompletion( - load_ad_future, "LoadAd (ignoring NoFill error)", - {firebase::gma::kAdErrorCodeNone, firebase::gma::kAdErrorCodeNoFill}); - } - if (load_ad_future.error() == firebase::gma::kAdErrorCodeNone) { - // In UI mode, or in non-UI mode if a NoFill error didn't occur, check that - // the ad loaded correctly. - const firebase::gma::AdResult* result_ptr = load_ad_future.result(); - ASSERT_NE(result_ptr, nullptr); - EXPECT_TRUE(result_ptr->is_successful()); - EXPECT_FALSE(result_ptr->response_info().adapter_responses().empty()); - EXPECT_FALSE( - result_ptr->response_info().mediation_adapter_class_name().empty()); - EXPECT_FALSE(result_ptr->response_info().response_id().empty()); - EXPECT_FALSE(result_ptr->response_info().ToString().empty()); - } - load_ad_future.Release(); - delete rewarded; -} - -TEST_F(FirebaseGmaTest, TestRewardedAdErrorNotInitialized) { - SKIP_TEST_ON_DESKTOP; - - firebase::gma::RewardedAd* rewarded_ad = new firebase::gma::RewardedAd(); - - firebase::gma::AdRequest request = GetAdRequest(); - WaitForCompletion(rewarded_ad->LoadAd(kRewardedAdUnit, request), "LoadAd", - firebase::gma::kAdErrorCodeUninitialized); - WaitForCompletion(rewarded_ad->Show(/*listener=*/nullptr), "Show", - firebase::gma::kAdErrorCodeUninitialized); - - delete rewarded_ad; -} - -TEST_F(FirebaseGmaTest, TesRewardedAdErrorAlreadyInitialized) { - SKIP_TEST_ON_DESKTOP; - - { - firebase::gma::RewardedAd* rewarded = new firebase::gma::RewardedAd(); - firebase::Future first_initialize = - rewarded->Initialize(app_framework::GetWindowContext()); - firebase::Future second_initialize = - rewarded->Initialize(app_framework::GetWindowContext()); - - WaitForCompletionAnyResult(first_initialize, "First Initialize 1"); - WaitForCompletion(second_initialize, "Second Initialize 1", - firebase::gma::kAdErrorCodeAlreadyInitialized); - - first_initialize.Release(); - second_initialize.Release(); - - delete rewarded; - } - - // Reverse the order of the completion waits. - { - firebase::gma::RewardedAd* rewarded = new firebase::gma::RewardedAd(); - firebase::Future first_initialize = - rewarded->Initialize(app_framework::GetWindowContext()); - firebase::Future second_initialize = - rewarded->Initialize(app_framework::GetWindowContext()); - - WaitForCompletion(second_initialize, "Second Initialize 1", - firebase::gma::kAdErrorCodeAlreadyInitialized); - WaitForCompletionAnyResult(first_initialize, "First Initialize 1"); - - first_initialize.Release(); - second_initialize.Release(); - - delete rewarded; - } -} - -TEST_F(FirebaseGmaTest, TestRewardedAdErrorLoadInProgress) { - SKIP_TEST_ON_DESKTOP; - - // TODO(@drsanta): remove when GMA whitelists CI devices. - TEST_REQUIRES_USER_INTERACTION_ON_IOS; - - firebase::gma::RewardedAd* rewarded = new firebase::gma::RewardedAd(); - WaitForCompletion(rewarded->Initialize(app_framework::GetWindowContext()), - "Initialize"); - - // Load the rewarded ad. - // Note potential flake: this test assumes the attempt to load an ad - // won't resolve immediately. If it does then the result may be two - // successful ad loads instead of the expected - // kAdErrorCodeLoadInProgress error. - firebase::gma::AdRequest request = GetAdRequest(); - firebase::Future first_load_ad = - rewarded->LoadAd(kRewardedAdUnit, request); - firebase::Future second_load_ad = - rewarded->LoadAd(kRewardedAdUnit, request); - - WaitForCompletion(second_load_ad, "Second LoadAd", - firebase::gma::kAdErrorCodeLoadInProgress); - WaitForCompletionAnyResult(first_load_ad, "First LoadAd"); - - const firebase::gma::AdResult* result_ptr = second_load_ad.result(); - ASSERT_NE(result_ptr, nullptr); - EXPECT_FALSE(result_ptr->is_successful()); - EXPECT_EQ(result_ptr->ad_error().code(), - firebase::gma::kAdErrorCodeLoadInProgress); - EXPECT_EQ(result_ptr->ad_error().message(), "Ad is currently loading."); - EXPECT_EQ(result_ptr->ad_error().domain(), "SDK"); - const firebase::gma::ResponseInfo response_info = - result_ptr->ad_error().response_info(); - EXPECT_TRUE(response_info.adapter_responses().empty()); - - first_load_ad.Release(); - second_load_ad.Release(); - delete rewarded; -} - -TEST_F(FirebaseGmaTest, TestRewardedAdErrorBadAdUnitId) { - SKIP_TEST_ON_DESKTOP; - - firebase::gma::RewardedAd* rewarded = new firebase::gma::RewardedAd(); - WaitForCompletion(rewarded->Initialize(app_framework::GetWindowContext()), - "Initialize"); - - // Load the rewarded ad. - firebase::gma::AdRequest request = GetAdRequest(); - firebase::Future load_ad_future = - rewarded->LoadAd(kBadAdUnit, request); - WaitForCompletion(load_ad_future, "LoadAd", - firebase::gma::kAdErrorCodeInvalidRequest); - - const firebase::gma::AdResult* result_ptr = load_ad_future.result(); - ASSERT_NE(result_ptr, nullptr); - EXPECT_FALSE(result_ptr->is_successful()); - EXPECT_EQ(result_ptr->ad_error().code(), - firebase::gma::kAdErrorCodeInvalidRequest); - EXPECT_FALSE(result_ptr->ad_error().message().empty()); - EXPECT_EQ(result_ptr->ad_error().domain(), kErrorDomain); - const firebase::gma::ResponseInfo response_info = - result_ptr->ad_error().response_info(); - EXPECT_TRUE(response_info.adapter_responses().empty()); - - load_ad_future.Release(); - delete rewarded; -} - -TEST_F(FirebaseGmaTest, TestRewardedAdErrorBadExtrasClassName) { - SKIP_TEST_ON_DESKTOP; - - firebase::gma::RewardedAd* rewarded = new firebase::gma::RewardedAd(); - WaitForCompletion(rewarded->Initialize(app_framework::GetWindowContext()), - "Initialize"); - - // Load the rewarded ad. - firebase::gma::AdRequest request = GetAdRequest(); - request.add_extra(kAdNetworkExtrasInvalidClassName, "shouldnot", "work"); - WaitForCompletion(rewarded->LoadAd(kRewardedAdUnit, request), "LoadAd", - firebase::gma::kAdErrorCodeAdNetworkClassLoadError); - delete rewarded; -} - -// Other NativeAd Tests - -TEST_F(FirebaseGmaTest, TestNativeAdLoadEmptyRequest) { - SKIP_TEST_ON_DESKTOP; - SKIP_TEST_ON_SIMULATOR; - - firebase::gma::NativeAd* native_ad = new firebase::gma::NativeAd(); - - WaitForCompletion(native_ad->Initialize(app_framework::GetWindowContext()), - "Initialize"); - - // When the NativeAd is initialized, load an ad. - firebase::gma::AdRequest request; - - firebase::Future load_ad_future = - native_ad->LoadAd(kNativeAdUnit, request); - - // Don't fail loadAd, if NoFill occurred. - WaitForCompletion( - load_ad_future, "LoadAd (ignoring NoFill error)", - {firebase::gma::kAdErrorCodeNone, firebase::gma::kAdErrorCodeNoFill}); - if (load_ad_future.error() == firebase::gma::kAdErrorCodeNone) { - const firebase::gma::AdResult* result_ptr = load_ad_future.result(); - ASSERT_NE(result_ptr, nullptr); - EXPECT_TRUE(result_ptr->is_successful()); - EXPECT_FALSE(result_ptr->response_info().adapter_responses().empty()); - EXPECT_FALSE( - result_ptr->response_info().mediation_adapter_class_name().empty()); - EXPECT_FALSE(result_ptr->response_info().response_id().empty()); - EXPECT_FALSE(result_ptr->response_info().ToString().empty()); - } else if (load_ad_future.error() == firebase::gma::kAdErrorCodeNoFill) { - LogWarning("LoadAd returned NoFill in TestNativeAdLoadEmptyRequest"); - } - - load_ad_future.Release(); - delete native_ad; -} - -TEST_F(FirebaseGmaTest, TestNativeRecordImpression) { - SKIP_TEST_ON_DESKTOP; - SKIP_TEST_ON_SIMULATOR; - - firebase::gma::NativeAd* native_ad = new firebase::gma::NativeAd(); - - WaitForCompletion(native_ad->Initialize(app_framework::GetWindowContext()), - "Initialize"); - - // Set the listener. - TestAdListener ad_listener; - native_ad->SetAdListener(&ad_listener); - - // When the NativeAd is initialized, load an ad. - firebase::Future load_ad_future = - native_ad->LoadAd(kNativeAdUnit, GetAdRequest()); - - // Don't fail loadAd, if NoFill occurred. - WaitForCompletion( - load_ad_future, "LoadAd (ignoring NoFill error)", - {firebase::gma::kAdErrorCodeNone, firebase::gma::kAdErrorCodeNoFill}); - - // Proceed verifying the RecordImpression, only when loadAd is successful. - if (load_ad_future.error() == firebase::gma::kAdErrorCodeNone) { - const firebase::gma::AdResult* result_ptr = load_ad_future.result(); - ASSERT_NE(result_ptr, nullptr); - EXPECT_TRUE(result_ptr->is_successful()); - - firebase::Variant impression_payload = GetVariantMap(); - -#if defined(ANDROID) - // Android doesn't have a return type for this API. - WaitForCompletion(native_ad->RecordImpression(impression_payload), - "RecordImpression"); -#else // iOS - // Test Ad unit IDs are not allowlisted to record impression and the request - // is expected to be rejected by the server. iOS returns the failure. - WaitForCompletion(native_ad->RecordImpression(impression_payload), - "RecordImpression", - firebase::gma::kAdErrorCodeInvalidRequest); -#endif - - // Use an allowlisted Ad unit ID that can record an impression, to verify - // the impression count while testing locally. - EXPECT_EQ(ad_listener.num_on_ad_impression_, 0); - - firebase::Variant str_variant = - firebase::Variant::FromMutableString("test"); - WaitForCompletion(native_ad->RecordImpression(str_variant), - "RecordImpression 2", - firebase::gma::kAdErrorCodeInvalidArgument); - } else if (load_ad_future.error() == firebase::gma::kAdErrorCodeNoFill) { - LogWarning("LoadAd returned NoFill in TestNativeRecordImpression"); - } - - load_ad_future.Release(); - delete native_ad; -} - -TEST_F(FirebaseGmaTest, TestNativePerformClick) { - SKIP_TEST_ON_DESKTOP; - SKIP_TEST_ON_SIMULATOR; - - firebase::gma::NativeAd* native_ad = new firebase::gma::NativeAd(); - - WaitForCompletion(native_ad->Initialize(app_framework::GetWindowContext()), - "Initialize"); - - // Set the listener. - TestAdListener ad_listener; - native_ad->SetAdListener(&ad_listener); - - // When the NativeAd is initialized, load an ad. - firebase::Future load_ad_future = - native_ad->LoadAd(kNativeAdUnit, GetAdRequest()); - - // Don't fail loadAd, if NoFill occurred. - WaitForCompletion( - load_ad_future, "LoadAd (ignoring NoFill error)", - {firebase::gma::kAdErrorCodeNone, firebase::gma::kAdErrorCodeNoFill}); - - // Proceed verifying the PerformClick, only when loadAd is successful. - if (load_ad_future.error() == firebase::gma::kAdErrorCodeNone) { - const firebase::gma::AdResult* result_ptr = load_ad_future.result(); - ASSERT_NE(result_ptr, nullptr); - EXPECT_TRUE(result_ptr->is_successful()); - - firebase::Variant click_payload = GetVariantMap(); - - // Android and iOS doesn't have a return type for this API. - WaitForCompletion(native_ad->PerformClick(click_payload), "PerformClick"); - - // Test Ad unit IDs are not allowlisted to use PerformClick API and the - // request is expected to be rejected by the server. Use an allowlisted Ad - // unit ID to verify the ad click count while testing locally. - EXPECT_EQ(ad_listener.num_on_ad_clicked_, 0); - - firebase::Variant str_variant = - firebase::Variant::FromMutableString("test"); - WaitForCompletion(native_ad->PerformClick(str_variant), "PerformClick 2", - firebase::gma::kAdErrorCodeInvalidArgument); - } else if (load_ad_future.error() == firebase::gma::kAdErrorCodeNoFill) { - LogWarning("LoadAd returned NoFill in TestNativePerformClick"); - } - - load_ad_future.Release(); - delete native_ad; -} - -TEST_F(FirebaseGmaTest, TestNativeAdErrorNotInitialized) { - SKIP_TEST_ON_DESKTOP; - - firebase::gma::NativeAd* native_ad = new firebase::gma::NativeAd(); - - firebase::gma::AdRequest request = GetAdRequest(); - WaitForCompletion(native_ad->LoadAd(kNativeAdUnit, request), "LoadAd", - firebase::gma::kAdErrorCodeUninitialized); - - firebase::Variant variant = firebase::Variant::EmptyMap(); - WaitForCompletion(native_ad->RecordImpression(variant), "RecordImpression", - firebase::gma::kAdErrorCodeUninitialized); - WaitForCompletion(native_ad->PerformClick(variant), "PerformClick", - firebase::gma::kAdErrorCodeUninitialized); - - delete native_ad; -} - -TEST_F(FirebaseGmaTest, TestNativeAdErrorAlreadyInitialized) { - SKIP_TEST_ON_DESKTOP; - - { - firebase::gma::NativeAd* native_ad = new firebase::gma::NativeAd(); - firebase::Future first_initialize = - native_ad->Initialize(app_framework::GetWindowContext()); - firebase::Future second_initialize = - native_ad->Initialize(app_framework::GetWindowContext()); - - WaitForCompletion(first_initialize, "First Initialize 1"); - WaitForCompletion(second_initialize, "Second Initialize 1", - firebase::gma::kAdErrorCodeAlreadyInitialized); - - first_initialize.Release(); - second_initialize.Release(); - - delete native_ad; - } - - // Reverse the order of the completion waits. - { - firebase::gma::NativeAd* native_ad = new firebase::gma::NativeAd(); - firebase::Future first_initialize = - native_ad->Initialize(app_framework::GetWindowContext()); - firebase::Future second_initialize = - native_ad->Initialize(app_framework::GetWindowContext()); - - WaitForCompletion(second_initialize, "Second Initialize 1", - firebase::gma::kAdErrorCodeAlreadyInitialized); - WaitForCompletion(first_initialize, "First Initialize 1"); - - first_initialize.Release(); - second_initialize.Release(); - - delete native_ad; - } -} - -TEST_F(FirebaseGmaTest, TestNativeAdErrorBadAdUnitId) { - SKIP_TEST_ON_DESKTOP; - - firebase::gma::NativeAd* native_ad = new firebase::gma::NativeAd(); - WaitForCompletion(native_ad->Initialize(app_framework::GetWindowContext()), - "Initialize"); - - // Load the native ad. - firebase::gma::AdRequest request = GetAdRequest(); - firebase::Future load_ad_future = - native_ad->LoadAd(kBadAdUnit, request); - WaitForCompletion(load_ad_future, "LoadAd", - firebase::gma::kAdErrorCodeInvalidRequest); - - const firebase::gma::AdResult* result_ptr = load_ad_future.result(); - ASSERT_NE(result_ptr, nullptr); - EXPECT_FALSE(result_ptr->is_successful()); - EXPECT_EQ(result_ptr->ad_error().code(), - firebase::gma::kAdErrorCodeInvalidRequest); - EXPECT_FALSE(result_ptr->ad_error().message().empty()); - EXPECT_EQ(result_ptr->ad_error().domain(), kErrorDomain); - const firebase::gma::ResponseInfo response_info = - result_ptr->ad_error().response_info(); - EXPECT_TRUE(response_info.adapter_responses().empty()); - - load_ad_future.Release(); - delete native_ad; -} - -TEST_F(FirebaseGmaTest, TestNativeAdErrorBadExtrasClassName) { - SKIP_TEST_ON_DESKTOP; - - firebase::gma::NativeAd* native_ad = new firebase::gma::NativeAd(); - WaitForCompletion(native_ad->Initialize(app_framework::GetWindowContext()), - "Initialize"); - - // Load the native ad. - firebase::gma::AdRequest request = GetAdRequest(); - request.add_extra(kAdNetworkExtrasInvalidClassName, "shouldnot", "work"); - WaitForCompletion(native_ad->LoadAd(kNativeAdUnit, request), "LoadAd", - firebase::gma::kAdErrorCodeAdNetworkClassLoadError); - delete native_ad; -} - -// Stress tests. These take a while so run them near the end. -TEST_F(FirebaseGmaTest, TestAdViewStress) { - SKIP_TEST_ON_DESKTOP; - SKIP_TEST_ON_EMULATOR; - - // TODO(@drsanta): remove when GMA whitelists CI devices - TEST_REQUIRES_USER_INTERACTION_ON_IOS; - TEST_REQUIRES_USER_INTERACTION_ON_ANDROID; - - for (int i = 0; i < 10; ++i) { - const firebase::gma::AdSize banner_ad_size(kBannerWidth, kBannerHeight); - firebase::gma::AdView* ad_view = new firebase::gma::AdView(); - WaitForCompletion(ad_view->Initialize(app_framework::GetWindowContext(), - kBannerAdUnit, banner_ad_size), - "TestAdViewStress Initialize"); - - // Load the AdView ad. - firebase::gma::AdRequest request = GetAdRequest(); - firebase::Future future = ad_view->LoadAd(request); - WaitForCompletion( - future, "TestAdViewStress LoadAd", - {firebase::gma::kAdErrorCodeNone, firebase::gma::kAdErrorCodeNoFill}); - // Stress tests may exhaust the ad pool. If so, loadAd will return - // kAdErrorCodeNoFill. - if (future.error() == firebase::gma::kAdErrorCodeNone) { - EXPECT_EQ(ad_view->ad_size().width(), kBannerWidth); - EXPECT_EQ(ad_view->ad_size().height(), kBannerHeight); - } - WaitForCompletion(ad_view->Destroy(), "Destroy the AdView"); - delete ad_view; - } -} - -TEST_F(FirebaseGmaTest, TestInterstitialAdStress) { - SKIP_TEST_ON_DESKTOP; - SKIP_TEST_ON_EMULATOR; - - // TODO(@drsanta): remove when GMA whitelists CI devices - TEST_REQUIRES_USER_INTERACTION_ON_IOS; - TEST_REQUIRES_USER_INTERACTION_ON_ANDROID; - - for (int i = 0; i < 10; ++i) { - firebase::gma::InterstitialAd* interstitial = - new firebase::gma::InterstitialAd(); - - WaitForCompletion( - interstitial->Initialize(app_framework::GetWindowContext()), - "TestInterstitialAdStress Initialize"); - - // When the InterstitialAd is initialized, load an ad. - firebase::gma::AdRequest request = GetAdRequest(); - firebase::Future future = - interstitial->LoadAd(kInterstitialAdUnit, request); - WaitForCompletion( - future, "TestInterstitialAdStress LoadAd", - {firebase::gma::kAdErrorCodeNone, firebase::gma::kAdErrorCodeNoFill}); - // Stress tests may exhaust the ad pool. If so, loadAd will return - // kAdErrorCodeNoFill. - delete interstitial; - } -} - -TEST_F(FirebaseGmaTest, TestRewardedAdStress) { - SKIP_TEST_ON_DESKTOP; - SKIP_TEST_ON_EMULATOR; - - // TODO(@drsanta): remove when GMA whitelists CI devices. - TEST_REQUIRES_USER_INTERACTION_ON_IOS; - TEST_REQUIRES_USER_INTERACTION_ON_ANDROID; - - for (int i = 0; i < 10; ++i) { - firebase::gma::RewardedAd* rewarded = new firebase::gma::RewardedAd(); - - WaitForCompletion(rewarded->Initialize(app_framework::GetWindowContext()), - "TestRewardedAdStress Initialize"); - - // When the RewardedAd is initialized, load an ad. - firebase::gma::AdRequest request = GetAdRequest(); - firebase::Future future = - rewarded->LoadAd(kRewardedAdUnit, request); - WaitForCompletion( - future, "TestRewardedAdStress LoadAd", - {firebase::gma::kAdErrorCodeNone, firebase::gma::kAdErrorCodeNoFill}); - // Stress tests may exhaust the ad pool. If so, loadAd will return - // kAdErrorCodeNoFill. - delete rewarded; - } -} - -#if defined(ANDROID) || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) -// Test runs & compiles for phones only. - -struct ThreadArgs { - firebase::gma::AdView* ad_view; - sem_t* semaphore; -}; - -static void* DeleteAdViewOnSignal(void* args) { - ThreadArgs* thread_args = static_cast(args); - sem_wait(thread_args->semaphore); - delete thread_args->ad_view; - return nullptr; -} - -TEST_F(FirebaseGmaTest, TestAdViewMultithreadDeletion) { - SKIP_TEST_ON_DESKTOP; - SKIP_TEST_ON_MOBILE; // TODO(b/172832275): This test is temporarily - // disabled on all platforms due to flakiness - // on Android. Once it's fixed, this test should - // be re-enabled on mobile. - - const firebase::gma::AdSize banner_ad_size(kBannerWidth, kBannerHeight); - - for (int i = 0; i < 5; ++i) { - firebase::gma::AdView* ad_view = new firebase::gma::AdView(); - WaitForCompletion(ad_view->Initialize(app_framework::GetWindowContext(), - kBannerAdUnit, banner_ad_size), - "Initialize"); - sem_t semaphore; - sem_init(&semaphore, 0, 1); - - ThreadArgs args = {ad_view, &semaphore}; - - pthread_t t1; - int err = pthread_create(&t1, nullptr, &DeleteAdViewOnSignal, &args); - EXPECT_EQ(err, 0); - - ad_view->Destroy(); - sem_post(&semaphore); - - // Blocks until DeleteAdViewOnSignal function is done. - void* result = nullptr; - err = pthread_join(t1, &result); - - EXPECT_EQ(err, 0); - EXPECT_EQ(result, nullptr); - - sem_destroy(&semaphore); - } -} -#endif // #if defined(ANDROID) || (defined(TARGET_OS_IPHONE) && - // TARGET_OS_IPHONE) - -class FirebaseGmaUmpTest : public FirebaseGmaTest { - public: - FirebaseGmaUmpTest() : consent_info_(nullptr) {} - - // Whether to call ConsentInfo::Reset() upon initialization, which - // resets UMP's consent state to as if the app was first installed. - enum ResetOption { kReset, kNoReset }; - - void InitializeUmp(ResetOption reset = kReset); - void TerminateUmp(ResetOption reset = kReset); - - void SetUp() override; - void TearDown() override; - - protected: - firebase::gma::ump::ConsentInfo* consent_info_; -}; - -void FirebaseGmaUmpTest::InitializeUmp(ResetOption reset) { - using firebase::gma::ump::ConsentInfo; - firebase::InitResult result; - consent_info_ = ConsentInfo::GetInstance(*shared_app_, &result); - - EXPECT_NE(consent_info_, nullptr); - EXPECT_EQ(result, firebase::kInitResultSuccess); - - if (consent_info_ != nullptr && reset == kReset) { - consent_info_->Reset(); - } -} - -void FirebaseGmaUmpTest::TerminateUmp(ResetOption reset) { - if (consent_info_) { - if (reset == kReset) { - consent_info_->Reset(); - } - delete consent_info_; - consent_info_ = nullptr; - } -} - -void FirebaseGmaUmpTest::SetUp() { - FirebaseGmaTest::SetUp(); - InitializeUmp(); - ASSERT_NE(consent_info_, nullptr); -} - -void FirebaseGmaUmpTest::TearDown() { - TerminateUmp(); - FirebaseGmaTest::TearDown(); -} - -// Tests for User Messaging Platform -TEST_F(FirebaseGmaUmpTest, TestUmpInitialization) { - // Initialize handled automatically in test setup. - EXPECT_NE(consent_info_, nullptr); - // Terminate handled automatically in test teardown. -} - -// Tests for User Messaging Platform -TEST_F(FirebaseGmaUmpTest, TestUmpDefaultsToUnknownStatus) { - EXPECT_EQ(consent_info_->GetConsentStatus(), - firebase::gma::ump::kConsentStatusUnknown); - EXPECT_EQ(consent_info_->GetConsentFormStatus(), - firebase::gma::ump::kConsentFormStatusUnknown); - EXPECT_EQ(consent_info_->GetPrivacyOptionsRequirementStatus(), - firebase::gma::ump::kPrivacyOptionsRequirementStatusUnknown); - EXPECT_FALSE(consent_info_->CanRequestAds()); -} - -// Tests for User Messaging Platform -TEST_F(FirebaseGmaUmpTest, TestUmpGetInstanceIsAlwaysEqual) { - using firebase::gma::ump::ConsentInfo; - - EXPECT_NE(consent_info_, nullptr); - - // Ensure that GetInstance() with any options is always equal. - EXPECT_EQ(consent_info_, ConsentInfo::GetInstance()); - EXPECT_EQ(consent_info_, ConsentInfo::GetInstance(*shared_app_)); - -#if defined(ANDROID) - EXPECT_EQ(consent_info_, - ConsentInfo::GetInstance(app_framework::GetJniEnv(), - app_framework::GetActivity())); - - firebase::App* second_app = firebase::App::Create( - firebase::AppOptions(), "2ndApp", app_framework::GetJniEnv(), - app_framework::GetActivity()); -#else - firebase::App* second_app = - firebase::App::Create(firebase::AppOptions(), "2ndApp"); -#endif // defined(ANDROID) - - EXPECT_EQ(consent_info_, ConsentInfo::GetInstance(*second_app)); - - delete second_app; -} - -TEST_F(FirebaseGmaUmpTest, TestUmpRequestConsentInfoUpdate) { - using firebase::gma::ump::ConsentRequestParameters; - using firebase::gma::ump::ConsentStatus; - - FLAKY_TEST_SECTION_BEGIN(); - - ConsentRequestParameters params; - params.tag_for_under_age_of_consent = false; - - firebase::Future future = - consent_info_->RequestConsentInfoUpdate(params); - - EXPECT_TRUE(future == consent_info_->RequestConsentInfoUpdateLastResult()); - - WaitForCompletion(future, "RequestConsentInfoUpdate", - {firebase::gma::ump::kConsentRequestSuccess, - firebase::gma::ump::kConsentRequestErrorNetwork}); - // Retry only network errors. - EXPECT_NE(future.error(), firebase::gma::ump::kConsentRequestErrorNetwork); - - FLAKY_TEST_SECTION_END(); - - EXPECT_NE(consent_info_->GetConsentStatus(), - firebase::gma::ump::kConsentStatusUnknown); - EXPECT_NE(consent_info_->GetConsentFormStatus(), - firebase::gma::ump::kConsentFormStatusUnknown); - EXPECT_NE(consent_info_->GetPrivacyOptionsRequirementStatus(), - firebase::gma::ump::kPrivacyOptionsRequirementStatusUnknown); -} - -TEST_F(FirebaseGmaUmpTest, TestUmpRequestConsentInfoUpdateDebugEEA) { - using firebase::gma::ump::ConsentDebugSettings; - using firebase::gma::ump::ConsentRequestParameters; - using firebase::gma::ump::ConsentStatus; - - FLAKY_TEST_SECTION_BEGIN(); - - ConsentRequestParameters params; - params.tag_for_under_age_of_consent = false; - params.debug_settings.debug_geography = - firebase::gma::ump::kConsentDebugGeographyEEA; - params.debug_settings.debug_device_ids = kTestDeviceIDs; - params.debug_settings.debug_device_ids.push_back(GetDebugDeviceId()); - - firebase::Future future = - consent_info_->RequestConsentInfoUpdate(params); - - WaitForCompletion(future, "RequestConsentInfoUpdate", - {firebase::gma::ump::kConsentRequestSuccess, - firebase::gma::ump::kConsentRequestErrorNetwork}); - // Retry only network errors. - EXPECT_NE(future.error(), firebase::gma::ump::kConsentRequestErrorNetwork); - - FLAKY_TEST_SECTION_END(); - - EXPECT_EQ(consent_info_->GetConsentStatus(), - firebase::gma::ump::kConsentStatusRequired); -} - -TEST_F(FirebaseGmaUmpTest, TestUmpRequestConsentInfoUpdateDebugNonEEA) { - using firebase::gma::ump::ConsentDebugSettings; - using firebase::gma::ump::ConsentRequestParameters; - using firebase::gma::ump::ConsentStatus; - - FLAKY_TEST_SECTION_BEGIN(); - - ConsentRequestParameters params; - params.tag_for_under_age_of_consent = false; - params.debug_settings.debug_geography = - firebase::gma::ump::kConsentDebugGeographyNonEEA; - params.debug_settings.debug_device_ids = kTestDeviceIDs; - params.debug_settings.debug_device_ids.push_back(GetDebugDeviceId()); - - firebase::Future future = - consent_info_->RequestConsentInfoUpdate(params); - - WaitForCompletion(future, "RequestConsentInfoUpdate", - {firebase::gma::ump::kConsentRequestSuccess, - firebase::gma::ump::kConsentRequestErrorNetwork}); - // Retry only network errors. - EXPECT_NE(future.error(), firebase::gma::ump::kConsentRequestErrorNetwork); - - FLAKY_TEST_SECTION_END(); - - EXPECT_THAT(consent_info_->GetConsentStatus(), - AnyOf(Eq(firebase::gma::ump::kConsentStatusNotRequired), - Eq(firebase::gma::ump::kConsentStatusRequired))); -} - -TEST_F(FirebaseGmaUmpTest, TestUmpLoadForm) { - using firebase::gma::ump::ConsentDebugSettings; - using firebase::gma::ump::ConsentFormStatus; - using firebase::gma::ump::ConsentRequestParameters; - using firebase::gma::ump::ConsentStatus; - - ConsentRequestParameters params; - params.tag_for_under_age_of_consent = false; - params.debug_settings.debug_geography = - firebase::gma::ump::kConsentDebugGeographyEEA; - params.debug_settings.debug_device_ids = kTestDeviceIDs; - params.debug_settings.debug_device_ids.push_back(GetDebugDeviceId()); - - WaitForCompletion(consent_info_->RequestConsentInfoUpdate(params), - "RequestConsentInfoUpdate"); - - EXPECT_EQ(consent_info_->GetConsentStatus(), - firebase::gma::ump::kConsentStatusRequired); - - EXPECT_EQ(consent_info_->GetConsentFormStatus(), - firebase::gma::ump::kConsentFormStatusAvailable); - - // Load the form. Run this step with retry in case of network timeout. - WaitForCompletion( - RunWithRetry([&]() { return consent_info_->LoadConsentForm(); }), - "LoadConsentForm", - {firebase::gma::ump::kConsentFormSuccess, - firebase::gma::ump::kConsentFormErrorTimeout}); - - firebase::Future future = consent_info_->LoadConsentFormLastResult(); - - EXPECT_EQ(consent_info_->GetConsentFormStatus(), - firebase::gma::ump::kConsentFormStatusAvailable); - - if (future.error() == firebase::gma::ump::kConsentFormErrorTimeout) { - LogWarning("Timed out after multiple tries, but passing anyway."); - } -} - -TEST_F(FirebaseGmaUmpTest, TestUmpShowForm) { - TEST_REQUIRES_USER_INTERACTION; - - using firebase::gma::ump::ConsentDebugSettings; - using firebase::gma::ump::ConsentFormStatus; - using firebase::gma::ump::ConsentRequestParameters; - using firebase::gma::ump::ConsentStatus; - - ConsentRequestParameters params; - params.tag_for_under_age_of_consent = false; - params.debug_settings.debug_geography = - firebase::gma::ump::kConsentDebugGeographyEEA; - params.debug_settings.debug_device_ids = kTestDeviceIDs; - params.debug_settings.debug_device_ids.push_back(GetDebugDeviceId()); - - WaitForCompletion(consent_info_->RequestConsentInfoUpdate(params), - "RequestConsentInfoUpdate"); - - EXPECT_EQ(consent_info_->GetConsentStatus(), - firebase::gma::ump::kConsentStatusRequired); - - EXPECT_EQ(consent_info_->GetConsentFormStatus(), - firebase::gma::ump::kConsentFormStatusAvailable); - - WaitForCompletion(consent_info_->LoadConsentForm(), "LoadConsentForm"); - - EXPECT_EQ(consent_info_->GetConsentFormStatus(), - firebase::gma::ump::kConsentFormStatusAvailable); - - firebase::Future future = - consent_info_->ShowConsentForm(app_framework::GetWindowController()); - - EXPECT_TRUE(future == consent_info_->ShowConsentFormLastResult()); - - WaitForCompletion(future, "ShowConsentForm"); - - EXPECT_EQ(consent_info_->GetConsentStatus(), - firebase::gma::ump::kConsentStatusObtained); -} - -TEST_F(FirebaseGmaUmpTest, TestUmpLoadFormUnderAgeOfConsent) { - SKIP_TEST_ON_IOS_SIMULATOR; - - using firebase::gma::ump::ConsentDebugSettings; - using firebase::gma::ump::ConsentFormStatus; - using firebase::gma::ump::ConsentRequestParameters; - using firebase::gma::ump::ConsentStatus; - - FLAKY_TEST_SECTION_BEGIN(); - - ConsentRequestParameters params; - params.tag_for_under_age_of_consent = true; - params.debug_settings.debug_geography = - firebase::gma::ump::kConsentDebugGeographyEEA; - params.debug_settings.debug_device_ids = kTestDeviceIDs; - params.debug_settings.debug_device_ids.push_back(GetDebugDeviceId()); - - firebase::Future future = - consent_info_->RequestConsentInfoUpdate(params); - - WaitForCompletion(future, "RequestConsentInfoUpdate", - {firebase::gma::ump::kConsentRequestSuccess, - firebase::gma::ump::kConsentRequestErrorNetwork}); - // Retry only network errors. - EXPECT_NE(future.error(), firebase::gma::ump::kConsentRequestErrorNetwork); - - FLAKY_TEST_SECTION_END(); - - firebase::Future load_future = consent_info_->LoadConsentForm(); - WaitForCompletion(load_future, "LoadConsentForm", - {firebase::gma::ump::kConsentFormErrorUnavailable, - firebase::gma::ump::kConsentFormErrorTimeout, - firebase::gma::ump::kConsentFormSuccess}); -} - -TEST_F(FirebaseGmaUmpTest, TestUmpLoadFormUnavailableDebugNonEEA) { - using firebase::gma::ump::ConsentDebugSettings; - using firebase::gma::ump::ConsentFormStatus; - using firebase::gma::ump::ConsentRequestParameters; - using firebase::gma::ump::ConsentStatus; - - FLAKY_TEST_SECTION_BEGIN(); - - ConsentRequestParameters params; - params.tag_for_under_age_of_consent = false; - params.debug_settings.debug_geography = - firebase::gma::ump::kConsentDebugGeographyNonEEA; - params.debug_settings.debug_device_ids = kTestDeviceIDs; - params.debug_settings.debug_device_ids.push_back(GetDebugDeviceId()); - - firebase::Future future = - consent_info_->RequestConsentInfoUpdate(params); - - WaitForCompletion(future, "RequestConsentInfoUpdate", - {firebase::gma::ump::kConsentRequestSuccess, - firebase::gma::ump::kConsentRequestErrorNetwork}); - // Retry only network errors. - EXPECT_NE(future.error(), firebase::gma::ump::kConsentRequestErrorNetwork); - - FLAKY_TEST_SECTION_END(); - - if (consent_info_->GetConsentStatus() != - firebase::gma::ump::kConsentStatusRequired) { - WaitForCompletion(consent_info_->LoadConsentForm(), "LoadConsentForm", - firebase::gma::ump::kConsentFormErrorUnavailable); - } -} - -TEST_F(FirebaseGmaUmpTest, TestUmpLoadAndShowIfRequiredDebugNonEEA) { - using firebase::gma::ump::ConsentDebugSettings; - using firebase::gma::ump::ConsentRequestParameters; - using firebase::gma::ump::ConsentStatus; - - FLAKY_TEST_SECTION_BEGIN(); - - ConsentRequestParameters params; - params.tag_for_under_age_of_consent = false; - params.debug_settings.debug_geography = - firebase::gma::ump::kConsentDebugGeographyNonEEA; - params.debug_settings.debug_device_ids = kTestDeviceIDs; - params.debug_settings.debug_device_ids.push_back(GetDebugDeviceId()); - - firebase::Future future = - consent_info_->RequestConsentInfoUpdate(params); - - WaitForCompletion(future, "RequestConsentInfoUpdate", - {firebase::gma::ump::kConsentRequestSuccess, - firebase::gma::ump::kConsentRequestErrorNetwork}); - // Retry only network errors. - EXPECT_NE(future.error(), firebase::gma::ump::kConsentRequestErrorNetwork); - - FLAKY_TEST_SECTION_END(); - - EXPECT_THAT(consent_info_->GetConsentStatus(), - AnyOf(Eq(firebase::gma::ump::kConsentStatusNotRequired), - Eq(firebase::gma::ump::kConsentStatusRequired))); - - if (consent_info_->GetConsentStatus() == - firebase::gma::ump::kConsentStatusNotRequired || - ShouldRunUITests()) { - // If ConsentStatus is Required, we only want to do this next part if UI - // interaction is allowed, as it will show a consent form which won't work - // in automated testing. - firebase::Future future = - consent_info_->LoadAndShowConsentFormIfRequired( - app_framework::GetWindowController()); - - EXPECT_TRUE(future == - consent_info_->LoadAndShowConsentFormIfRequiredLastResult()); - - WaitForCompletion(future, "LoadAndShowConsentFormIfRequired"); - } -} - -TEST_F(FirebaseGmaUmpTest, TestUmpLoadAndShowIfRequiredDebugEEA) { - using firebase::gma::ump::ConsentDebugSettings; - using firebase::gma::ump::ConsentRequestParameters; - using firebase::gma::ump::ConsentStatus; - - TEST_REQUIRES_USER_INTERACTION; - - ConsentRequestParameters params; - params.tag_for_under_age_of_consent = false; - params.debug_settings.debug_geography = - firebase::gma::ump::kConsentDebugGeographyEEA; - params.debug_settings.debug_device_ids = kTestDeviceIDs; - params.debug_settings.debug_device_ids.push_back(GetDebugDeviceId()); - - WaitForCompletion(consent_info_->RequestConsentInfoUpdate(params), - "RequestConsentInfoUpdate"); - - EXPECT_EQ(consent_info_->GetConsentStatus(), - firebase::gma::ump::kConsentStatusRequired); - - firebase::Future future = - consent_info_->LoadAndShowConsentFormIfRequired( - app_framework::GetWindowController()); - - EXPECT_TRUE(future == - consent_info_->LoadAndShowConsentFormIfRequiredLastResult()); - - WaitForCompletion(future, "LoadAndShowConsentFormIfRequired"); - - EXPECT_EQ(consent_info_->GetConsentStatus(), - firebase::gma::ump::kConsentStatusObtained); -} - -TEST_F(FirebaseGmaUmpTest, TestUmpPrivacyOptions) { - using firebase::gma::ump::ConsentDebugSettings; - using firebase::gma::ump::ConsentRequestParameters; - using firebase::gma::ump::ConsentStatus; - using firebase::gma::ump::PrivacyOptionsRequirementStatus; - - TEST_REQUIRES_USER_INTERACTION; - - ConsentRequestParameters params; - params.tag_for_under_age_of_consent = false; - params.debug_settings.debug_geography = - firebase::gma::ump::kConsentDebugGeographyEEA; - params.debug_settings.debug_device_ids = kTestDeviceIDs; - params.debug_settings.debug_device_ids.push_back(GetDebugDeviceId()); - - WaitForCompletion(consent_info_->RequestConsentInfoUpdate(params), - "RequestConsentInfoUpdate"); - - EXPECT_EQ(consent_info_->GetConsentStatus(), - firebase::gma::ump::kConsentStatusRequired); - - EXPECT_FALSE(consent_info_->CanRequestAds()); - - WaitForCompletion(consent_info_->LoadAndShowConsentFormIfRequired( - app_framework::GetWindowController()), - "LoadAndShowConsentFormIfRequired"); - - EXPECT_EQ(consent_info_->GetConsentStatus(), - firebase::gma::ump::kConsentStatusObtained); - - EXPECT_TRUE(consent_info_->CanRequestAds()) << "After consent obtained"; - - LogInfo( - "******** On the Privacy Options screen that is about to appear, please " - "select DO NOT CONSENT."); - - ProcessEvents(5000); - - EXPECT_EQ(consent_info_->GetPrivacyOptionsRequirementStatus(), - firebase::gma::ump::kPrivacyOptionsRequirementStatusRequired); - - firebase::Future future = consent_info_->ShowPrivacyOptionsForm( - app_framework::GetWindowController()); - - EXPECT_TRUE(future == consent_info_->ShowPrivacyOptionsFormLastResult()); - - WaitForCompletion(future, "ShowPrivacyOptionsForm"); -} - -TEST_F(FirebaseGmaUmpTest, TestCanRequestAdsNonEEA) { - using firebase::gma::ump::ConsentDebugSettings; - using firebase::gma::ump::ConsentRequestParameters; - using firebase::gma::ump::ConsentStatus; - - ConsentRequestParameters params; - params.tag_for_under_age_of_consent = false; - params.debug_settings.debug_geography = - firebase::gma::ump::kConsentDebugGeographyNonEEA; - params.debug_settings.debug_device_ids = kTestDeviceIDs; - params.debug_settings.debug_device_ids.push_back(GetDebugDeviceId()); - - WaitForCompletion(consent_info_->RequestConsentInfoUpdate(params), - "RequestConsentInfoUpdate"); - - EXPECT_THAT(consent_info_->GetConsentStatus(), - AnyOf(Eq(firebase::gma::ump::kConsentStatusNotRequired), - Eq(firebase::gma::ump::kConsentStatusRequired))); - - if (consent_info_->GetConsentStatus() == - firebase::gma::ump::kConsentStatusNotRequired) { - EXPECT_TRUE(consent_info_->CanRequestAds()); - } -} - -TEST_F(FirebaseGmaUmpTest, TestCanRequestAdsEEA) { - using firebase::gma::ump::ConsentDebugSettings; - using firebase::gma::ump::ConsentRequestParameters; - using firebase::gma::ump::ConsentStatus; - - ConsentRequestParameters params; - params.tag_for_under_age_of_consent = false; - params.debug_settings.debug_geography = - firebase::gma::ump::kConsentDebugGeographyEEA; - params.debug_settings.debug_device_ids = kTestDeviceIDs; - params.debug_settings.debug_device_ids.push_back(GetDebugDeviceId()); - - WaitForCompletion(consent_info_->RequestConsentInfoUpdate(params), - "RequestConsentInfoUpdate"); - - EXPECT_EQ(consent_info_->GetConsentStatus(), - firebase::gma::ump::kConsentStatusRequired); - - EXPECT_FALSE(consent_info_->CanRequestAds()); -} - -TEST_F(FirebaseGmaUmpTest, TestUmpCleanupWithDelay) { - // Ensure that if ConsentInfo is deleted after a delay, Futures are - // properly invalidated. - using firebase::gma::ump::ConsentFormStatus; - using firebase::gma::ump::ConsentRequestParameters; - using firebase::gma::ump::ConsentStatus; - - ConsentRequestParameters params; - params.tag_for_under_age_of_consent = false; - params.debug_settings.debug_geography = - firebase::gma::ump::kConsentDebugGeographyNonEEA; - params.debug_settings.debug_device_ids = kTestDeviceIDs; - params.debug_settings.debug_device_ids.push_back(GetDebugDeviceId()); - - firebase::Future future_request = - consent_info_->RequestConsentInfoUpdate(params); - firebase::Future future_load = consent_info_->LoadConsentForm(); - firebase::Future future_show = - consent_info_->ShowConsentForm(app_framework::GetWindowController()); - firebase::Future future_load_and_show = - consent_info_->LoadAndShowConsentFormIfRequired( - app_framework::GetWindowController()); - firebase::Future future_privacy = consent_info_->ShowPrivacyOptionsForm( - app_framework::GetWindowController()); - - ProcessEvents(5000); - - TerminateUmp(kNoReset); - - EXPECT_EQ(future_request.status(), firebase::kFutureStatusInvalid); - EXPECT_EQ(future_load.status(), firebase::kFutureStatusInvalid); - EXPECT_EQ(future_show.status(), firebase::kFutureStatusInvalid); - EXPECT_EQ(future_load_and_show.status(), firebase::kFutureStatusInvalid); - EXPECT_EQ(future_privacy.status(), firebase::kFutureStatusInvalid); -} - -TEST_F(FirebaseGmaUmpTest, TestUmpCleanupRaceCondition) { - // Ensure that if ConsentInfo is deleted immediately, operations - // (and their Futures) are properly invalidated. - - using firebase::gma::ump::ConsentFormStatus; - using firebase::gma::ump::ConsentRequestParameters; - using firebase::gma::ump::ConsentStatus; - - ConsentRequestParameters params; - params.tag_for_under_age_of_consent = false; - params.debug_settings.debug_geography = - firebase::gma::ump::kConsentDebugGeographyNonEEA; - params.debug_settings.debug_device_ids = kTestDeviceIDs; - params.debug_settings.debug_device_ids.push_back(GetDebugDeviceId()); - - firebase::Future future_request = - consent_info_->RequestConsentInfoUpdate(params); - firebase::Future future_load = consent_info_->LoadConsentForm(); - firebase::Future future_show = - consent_info_->ShowConsentForm(app_framework::GetWindowController()); - firebase::Future future_load_and_show = - consent_info_->LoadAndShowConsentFormIfRequired( - app_framework::GetWindowController()); - firebase::Future future_privacy = consent_info_->ShowPrivacyOptionsForm( - app_framework::GetWindowController()); - - TerminateUmp(kNoReset); - - EXPECT_EQ(future_request.status(), firebase::kFutureStatusInvalid); - EXPECT_EQ(future_load.status(), firebase::kFutureStatusInvalid); - EXPECT_EQ(future_show.status(), firebase::kFutureStatusInvalid); - EXPECT_EQ(future_load_and_show.status(), firebase::kFutureStatusInvalid); - EXPECT_EQ(future_privacy.status(), firebase::kFutureStatusInvalid); - - ProcessEvents(5000); -} - -TEST_F(FirebaseGmaUmpTest, TestUmpCallbacksOnWrongInstance) { - // Ensure that if ConsentInfo is deleted and then recreated, stale - // callbacks don't call into the new instance and cause crashes. - using firebase::gma::ump::ConsentFormStatus; - using firebase::gma::ump::ConsentRequestParameters; - using firebase::gma::ump::ConsentStatus; - - ConsentRequestParameters params; - params.tag_for_under_age_of_consent = false; - params.debug_settings.debug_geography = - firebase::gma::ump::kConsentDebugGeographyNonEEA; - params.debug_settings.debug_device_ids = kTestDeviceIDs; - params.debug_settings.debug_device_ids.push_back(GetDebugDeviceId()); - - LogDebug("RequestConsentInfoUpdate"); - consent_info_->RequestConsentInfoUpdate(params).OnCompletion( - [](const firebase::Future&) { - LogDebug("RequestConsentInfoUpdate done"); - }); - LogDebug("LoadConsentForm"); - consent_info_->LoadConsentForm().OnCompletion( - [](const firebase::Future&) { LogDebug("LoadConsentForm done"); }); - // In automated tests, only check RequestConsentInfoUpdate and LoadConsentForm - // as the rest may show UI. - if (ShouldRunUITests()) { - LogDebug("ShowConsentForm"); - consent_info_->ShowConsentForm(app_framework::GetWindowController()) - .OnCompletion([](const firebase::Future&) { - LogDebug("ShowConsentForm done"); - }); - LogDebug("LoadAndShowConsentFormIfRequired"); - consent_info_ - ->LoadAndShowConsentFormIfRequired(app_framework::GetWindowController()) - .OnCompletion([](const firebase::Future&) { - LogDebug("LoadAndShowConsentFormIfRequired done"); - }); - LogDebug("ShowPrivacyOptionsForm"); - consent_info_->ShowPrivacyOptionsForm(app_framework::GetWindowController()) - .OnCompletion([](const firebase::Future&) { - LogDebug("ShowPrivacyOptionsForm done"); - }); - } - - LogDebug("Terminate"); - TerminateUmp(kNoReset); - - LogDebug("Initialize"); - InitializeUmp(kNoReset); - - // Give the operations time to complete. - LogDebug("Wait"); - ProcessEvents(5000); - - LogDebug("Done"); -} - -TEST_F(FirebaseGmaUmpTest, TestUmpMethodsReturnOperationInProgress) { - SKIP_TEST_ON_DESKTOP; - SKIP_TEST_ON_IOS_SIMULATOR; // LoadAndShowConsentFormIfRequired - // is too quick on simulator. - - using firebase::gma::ump::ConsentFormStatus; - using firebase::gma::ump::ConsentRequestParameters; - using firebase::gma::ump::ConsentStatus; - - // Check that all of the UMP operations properly return an OperationInProgress - // error if called more than once at the same time. - - // This depends on timing, so it's inherently flaky. - FLAKY_TEST_SECTION_BEGIN(); - - ConsentRequestParameters params; - params.tag_for_under_age_of_consent = false; - params.debug_settings.debug_geography = - firebase::gma::ump::kConsentDebugGeographyNonEEA; - params.debug_settings.debug_device_ids = kTestDeviceIDs; - params.debug_settings.debug_device_ids.push_back(GetDebugDeviceId()); - - firebase::Future future_request_1 = - consent_info_->RequestConsentInfoUpdate(params); - firebase::Future future_request_2 = - consent_info_->RequestConsentInfoUpdate(params); - WaitForCompletion( - future_request_2, "RequestConsentInfoUpdate second", - firebase::gma::ump::kConsentRequestErrorOperationInProgress); - WaitForCompletion(future_request_1, "RequestConsentInfoUpdate first", - {firebase::gma::ump::kConsentRequestSuccess, - firebase::gma::ump::kConsentRequestErrorNetwork}); - - consent_info_->Reset(); - - FLAKY_TEST_SECTION_END(); -} - -TEST_F(FirebaseGmaUmpTest, TestUmpMethodsReturnOperationInProgressWithUI) { - SKIP_TEST_ON_DESKTOP; - TEST_REQUIRES_USER_INTERACTION; - - using firebase::gma::ump::ConsentFormStatus; - using firebase::gma::ump::ConsentRequestParameters; - using firebase::gma::ump::ConsentStatus; - - // Check that all of the UMP operations properly return an OperationInProgress - // error if called more than once at the same time. This test include methods - // with UI interaction. - - ConsentRequestParameters params; - params.tag_for_under_age_of_consent = false; - params.debug_settings.debug_geography = - firebase::gma::ump::kConsentDebugGeographyEEA; - params.debug_settings.debug_device_ids = kTestDeviceIDs; - params.debug_settings.debug_device_ids.push_back(GetDebugDeviceId()); - - firebase::Future future_request_1 = - consent_info_->RequestConsentInfoUpdate(params); - firebase::Future future_request_2 = - consent_info_->RequestConsentInfoUpdate(params); - WaitForCompletion( - future_request_2, "RequestConsentInfoUpdate second", - firebase::gma::ump::kConsentRequestErrorOperationInProgress); - WaitForCompletion(future_request_1, "RequestConsentInfoUpdate first"); - - firebase::Future future_load_1 = consent_info_->LoadConsentForm(); - firebase::Future future_load_2 = consent_info_->LoadConsentForm(); - WaitForCompletion(future_load_2, "LoadConsentForm second", - firebase::gma::ump::kConsentFormErrorOperationInProgress); - WaitForCompletion(future_load_1, "LoadConsentForm first"); - - firebase::Future future_show_1 = - consent_info_->ShowConsentForm(app_framework::GetWindowController()); - firebase::Future future_show_2 = - consent_info_->ShowConsentForm(app_framework::GetWindowController()); - WaitForCompletion(future_show_2, "ShowConsentForm second", - firebase::gma::ump::kConsentFormErrorOperationInProgress); - WaitForCompletion(future_show_1, "ShowConsentForm first"); - - firebase::Future future_privacy_1 = - consent_info_->ShowPrivacyOptionsForm( - app_framework::GetWindowController()); - firebase::Future future_privacy_2 = - consent_info_->ShowPrivacyOptionsForm( - app_framework::GetWindowController()); - WaitForCompletion(future_privacy_2, "ShowPrivacyOptionsForm second", - firebase::gma::ump::kConsentFormErrorOperationInProgress); - WaitForCompletion(future_privacy_1, "ShowPrivacyOptionsForm first"); - - consent_info_->Reset(); - // Request again so we can test LoadAndShowConsentFormIfRequired. - WaitForCompletion(consent_info_->RequestConsentInfoUpdate(params), - "RequestConsentInfoUpdate"); - - firebase::Future future_load_and_show_1 = - consent_info_->LoadAndShowConsentFormIfRequired( - app_framework::GetWindowController()); - firebase::Future future_load_and_show_2 = - consent_info_->LoadAndShowConsentFormIfRequired( - app_framework::GetWindowController()); - WaitForCompletion(future_load_and_show_2, - "LoadAndShowConsentFormIfRequired second", - firebase::gma::ump::kConsentFormErrorOperationInProgress); - WaitForCompletion(future_load_and_show_1, - "LoadAndShowConsentFormIfRequired first"); -} - -} // namespace firebase_testapp_automated diff --git a/gma/src/android/ad_error_android.cc b/gma/src/android/ad_error_android.cc deleted file mode 100644 index 7bf5563efd..0000000000 --- a/gma/src/android/ad_error_android.cc +++ /dev/null @@ -1,296 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/android/ad_error_android.h" - -#include - -#include -#include - -#include "gma/src/android/ad_request_converter.h" -#include "gma/src/android/gma_android.h" -#include "gma/src/android/response_info_android.h" -#include "gma/src/common/gma_common.h" -#include "gma/src/include/firebase/gma.h" - -namespace firebase { -namespace gma { - -METHOD_LOOKUP_DEFINITION(ad_error, - PROGUARD_KEEP_CLASS - "com/google/android/gms/ads/AdError", - ADERROR_METHODS); - -METHOD_LOOKUP_DEFINITION(load_ad_error, - PROGUARD_KEEP_CLASS - "com/google/android/gms/ads/LoadAdError", - LOADADERROR_METHODS); - -const char* const AdError::kUndefinedDomain = "undefined"; - -AdError::AdError() { - // Default constructor is available for Future creation. - // Initialize it with some helpful debug values in the case - // an AdError makes it to the application in this default state. - internal_ = new AdErrorInternal(); - internal_->ad_error_type = AdErrorInternal::kAdErrorInternalWrapperError; - internal_->code = kAdErrorCodeUninitialized; - internal_->domain = "SDK"; - internal_->message = "This AdError has not be initialized."; - internal_->to_string = internal_->message; - internal_->native_ad_error = nullptr; - - // While most data is passed into this object through the AdErrorInternal - // structure (above), the response_info_ is constructed when parsing - // the native_ad_error itself. - response_info_ = new ResponseInfo(); -} - -AdError::AdError(const AdErrorInternal& ad_error_internal) { - JNIEnv* env = GetJNI(); - FIREBASE_ASSERT(env); - - internal_ = new AdErrorInternal(); - internal_->is_successful = ad_error_internal.is_successful; - internal_->ad_error_type = ad_error_internal.ad_error_type; - internal_->native_ad_error = nullptr; - response_info_ = new ResponseInfo(); - - // AdErrors can be returned on success, or for errors encountered in the C++ - // SDK wrapper, or in the Android GMA SDK. The structure is populated - // differently across these three scenarios. - if (internal_->is_successful) { - internal_->code = kAdErrorCodeNone; - internal_->message = ""; - internal_->domain = ""; - internal_->to_string = ""; - } else if (internal_->ad_error_type == - AdErrorInternal::kAdErrorInternalWrapperError) { - // Wrapper errors come with prepopulated code, domain, etc, fields. - internal_->code = ad_error_internal.code; - internal_->domain = ad_error_internal.domain; - internal_->message = ad_error_internal.message; - internal_->to_string = ad_error_internal.to_string; - } else { - FIREBASE_ASSERT(ad_error_internal.native_ad_error != nullptr); - - // AdErrors based on GMA Android SDK errors will fetch code, domain, - // message, and to_string values from the Java object. - internal_->native_ad_error = - env->NewGlobalRef(ad_error_internal.native_ad_error); - - JNIEnv* env = ::firebase::gma::GetJNI(); - FIREBASE_ASSERT(env); - - // Error Code. Map the Android GMA SDK error codes to our - // platform-independent C++ SDK error codes. - jint j_error_code = env->CallIntMethod( - internal_->native_ad_error, ad_error::GetMethodId(ad_error::kGetCode)); - switch (internal_->ad_error_type) { - case AdErrorInternal::kAdErrorInternalFullScreenContentError: - // Full screen content errors have their own error codes. - internal_->code = - MapAndroidFullScreenContentErrorCodeToCPPErrorCode(j_error_code); - break; - case AdErrorInternal::kAdErrorInternalOpenAdInspectorError: - // AdInspector errors have their own error codes. - internal_->code = - MapAndroidOpenAdInspectorErrorCodeToCPPErrorCode(j_error_code); - break; - default: - internal_->code = - MapAndroidAdRequestErrorCodeToCPPErrorCode(j_error_code); - } - - // Error domain string. - jobject j_domain = - env->CallObjectMethod(internal_->native_ad_error, - ad_error::GetMethodId(ad_error::kGetDomain)); - FIREBASE_ASSERT(j_domain); - internal_->domain = util::JStringToString(env, j_domain); - env->DeleteLocalRef(j_domain); - - // Error message. - jobject j_message = - env->CallObjectMethod(internal_->native_ad_error, - ad_error::GetMethodId(ad_error::kGetMessage)); - FIREBASE_ASSERT(j_message); - internal_->message = util::JStringToString(env, j_message); - env->DeleteLocalRef(j_message); - - // Differentiate between a com.google.android.gms.ads.AdError or its - // com.google.android.gms.ads.LoadAdError subclass. - if (internal_->ad_error_type == - AdErrorInternal::kAdErrorInternalLoadAdError) { - // LoadAdError object. - jobject j_response_info = env->CallObjectMethod( - internal_->native_ad_error, - load_ad_error::GetMethodId(load_ad_error::kGetResponseInfo)); - - if (j_response_info != nullptr) { - ResponseInfoInternal response_info_internal; - response_info_internal.j_response_info = j_response_info; - *response_info_ = ResponseInfo(response_info_internal); - env->DeleteLocalRef(j_response_info); - } - - // A to_string value of this LoadAdError. Invoke the set_to_string - // protected method of the AdError parent class to overwrite whatever - // it parsed. - jobject j_to_string = env->CallObjectMethod( - internal_->native_ad_error, - load_ad_error::GetMethodId(load_ad_error::kToString)); - internal_->to_string = util::JStringToString(env, j_to_string); - env->DeleteLocalRef(j_to_string); - } else { - // AdError object. - jobject j_to_string = - env->CallObjectMethod(internal_->native_ad_error, - ad_error::GetMethodId(ad_error::kToString)); - FIREBASE_ASSERT(j_to_string); - internal_->to_string = util::JStringToString(env, j_to_string); - env->DeleteLocalRef(j_to_string); - } - } -} - -AdError::AdError(const AdError& ad_result) : AdError() { - FIREBASE_ASSERT(ad_result.response_info_ != nullptr); - // Reuse the assignment operator. - this->response_info_ = new ResponseInfo(); - *this = ad_result; -} - -AdError& AdError::operator=(const AdError& ad_result) { - if (&ad_result == this) { - return *this; - } - - JNIEnv* env = GetJNI(); - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(internal_); - FIREBASE_ASSERT(ad_result.internal_); - FIREBASE_ASSERT(response_info_); - FIREBASE_ASSERT(ad_result.response_info_); - - AdErrorInternal* preexisting_internal = internal_; - { - // Lock the parties so they're not deleted while the copying takes place. - MutexLock ad_result_lock(ad_result.internal_->mutex); - MutexLock lock(internal_->mutex); - internal_ = new AdErrorInternal(); - - internal_->is_successful = ad_result.internal_->is_successful; - internal_->ad_error_type = ad_result.internal_->ad_error_type; - internal_->code = ad_result.internal_->code; - internal_->domain = ad_result.internal_->domain; - internal_->message = ad_result.internal_->message; - if (ad_result.internal_->native_ad_error != nullptr) { - internal_->native_ad_error = - env->NewGlobalRef(ad_result.internal_->native_ad_error); - } - if (preexisting_internal->native_ad_error) { - env->DeleteGlobalRef(preexisting_internal->native_ad_error); - preexisting_internal->native_ad_error = nullptr; - } - - *response_info_ = *ad_result.response_info_; - } - - // Deleting the internal_ deletes the mutex within it, so we wait for - // complete deletion until after the mutex lock leaves scope. - delete preexisting_internal; - - return *this; -} - -AdError::~AdError() { - FIREBASE_ASSERT(internal_); - FIREBASE_ASSERT(response_info_); - - if (internal_->native_ad_error != nullptr) { - JNIEnv* env = GetJNI(); - FIREBASE_ASSERT(env); - env->DeleteGlobalRef(internal_->native_ad_error); - internal_->native_ad_error = nullptr; - } - - delete internal_; - internal_ = nullptr; - - delete response_info_; - response_info_ = nullptr; -} - -std::unique_ptr AdError::GetCause() const { - FIREBASE_ASSERT(internal_); - - // AdErrors my contain another AdError which points to the cause of this - // error. However, this is only possible if this AdError represents - // and Android GMA SDK error and not a wrapper error. - if (internal_->ad_error_type == - AdErrorInternal::kAdErrorInternalWrapperError) { - return std::unique_ptr(nullptr); - } else { - FIREBASE_ASSERT(internal_->native_ad_error); - JNIEnv* env = GetJNI(); - FIREBASE_ASSERT(env); - - jobject native_ad_error = env->CallObjectMethod( - internal_->native_ad_error, ad_error::GetMethodId(ad_error::kGetCause)); - - AdErrorInternal ad_error_internal; - ad_error_internal.native_ad_error = native_ad_error; - - std::unique_ptr ad_result = - std::unique_ptr(new AdError(ad_error_internal)); - env->DeleteLocalRef(native_ad_error); - return ad_result; - } -} - -/// Gets the error's code. -AdErrorCode AdError::code() const { - FIREBASE_ASSERT(internal_); - return internal_->code; -} - -/// Gets the domain of the error. -const std::string& AdError::domain() const { - FIREBASE_ASSERT(internal_); - return internal_->domain; -} - -/// Gets the message describing the error. -const std::string& AdError::message() const { - FIREBASE_ASSERT(internal_); - return internal_->message; -} - -const ResponseInfo& AdError::response_info() const { - FIREBASE_ASSERT(response_info_ != nullptr); - return *response_info_; -} - -/// Returns a log friendly string version of this object. -const std::string& AdError::ToString() const { - FIREBASE_ASSERT(internal_); - return internal_->to_string; -} - -} // namespace gma -} // namespace firebase diff --git a/gma/src/android/ad_error_android.h b/gma/src/android/ad_error_android.h deleted file mode 100644 index e723a482a0..0000000000 --- a/gma/src/android/ad_error_android.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_ANDROID_AD_ERROR_ANDROID_H_ -#define FIREBASE_GMA_SRC_ANDROID_AD_ERROR_ANDROID_H_ - -#include - -#include "app/src/include/firebase/internal/mutex.h" -#include "app/src/util_android.h" -#include "gma/src/common/ad_error_internal.h" -#include "gma/src/include/firebase/gma/types.h" - -namespace firebase { -namespace gma { - -// Used to set up the cache of class method IDs to reduce -// time spent looking up methods by string. -// clang-format off -#define ADERROR_METHODS(X) \ - X(GetCause, "getCause", \ - "()Lcom/google/android/gms/ads/AdError;"), \ - X(GetCode, "getCode", "()I"), \ - X(GetDomain, "getDomain", "()Ljava/lang/String;"), \ - X(GetMessage, "getMessage", "()Ljava/lang/String;"), \ - X(ToString, "toString", "()Ljava/lang/String;") -// clang-format on - -#define LOADADERROR_METHODS(X) \ - X(GetResponseInfo, "getResponseInfo", \ - "()Lcom/google/android/gms/ads/ResponseInfo;"), \ - X(ToString, "toString", "()Ljava/lang/String;") -// clang-format on - -METHOD_LOOKUP_DECLARATION(ad_error, ADERROR_METHODS); -METHOD_LOOKUP_DECLARATION(load_ad_error, LOADADERROR_METHODS); - -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_ANDROID_AD_ERROR_ANDROID_H_ diff --git a/gma/src/android/ad_request_converter.cc b/gma/src/android/ad_request_converter.cc deleted file mode 100644 index fca10a8f86..0000000000 --- a/gma/src/android/ad_request_converter.cc +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/android/ad_request_converter.h" - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "app/src/log.h" -#include "app/src/util_android.h" -#include "gma/src/android/gma_android.h" -#include "gma/src/common/gma_common.h" -#include "gma/src/include/firebase/gma.h" -#include "gma/src/include/firebase/gma/types.h" - -namespace firebase { -namespace gma { - -METHOD_LOOKUP_DEFINITION(ad_request_builder, - PROGUARD_KEEP_CLASS - "com/google/android/gms/ads/AdRequest$Builder", - ADREQUESTBUILDER_METHODS); - -jobject GetJavaAdRequestFromCPPAdRequest(const AdRequest& request, - gma::AdErrorCode* error) { - FIREBASE_ASSERT(error); - *error = kAdErrorCodeNone; - - JNIEnv* env = ::firebase::gma::GetJNI(); - jobject builder = env->NewObject( - ad_request_builder::GetClass(), - ad_request_builder::GetMethodId(ad_request_builder::kConstructor)); - - // Network Extras. - // The map associates class names of mediation adapters with a - // key value pairs, the extras, to send to those mediation adapters. - // e.g. Mediation_Map < class name, Extras_Map < key, value > > - const std::map>& extras = - request.extras(); - for (auto adapter_iter = extras.begin(); adapter_iter != extras.end(); - ++adapter_iter) { - std::string adapter_name = adapter_iter->first; - - jclass adapter_class = util::FindClass(env, adapter_name.c_str()); - if (adapter_class == nullptr) { - LogError( - "Failed to resolve extras class. Check that \"%s\"" - " is present in your APK.", - adapter_name.c_str()); - *error = kAdErrorCodeAdNetworkClassLoadError; - env->DeleteLocalRef(builder); - return nullptr; - } - - jobject extras_bundle = - env->NewObject(util::bundle::GetClass(), - util::bundle::GetMethodId(util::bundle::kConstructor)); - - for (auto extra_iter = adapter_iter->second.begin(); - extra_iter != adapter_iter->second.end(); ++extra_iter) { - jstring extra_key_str = env->NewStringUTF(extra_iter->first.c_str()); - jstring extra_value_str = env->NewStringUTF(extra_iter->second.c_str()); - env->CallVoidMethod(extras_bundle, - util::bundle::GetMethodId(util::bundle::kPutString), - extra_key_str, extra_value_str); - env->DeleteLocalRef(extra_value_str); - env->DeleteLocalRef(extra_key_str); - } - - builder = util::ContinueBuilder( - env, builder, - env->CallObjectMethod(builder, - ad_request_builder::GetMethodId( - ad_request_builder::kAddNetworkExtrasBundle), - adapter_class, extras_bundle)); - - env->DeleteLocalRef(extras_bundle); - env->DeleteLocalRef(adapter_class); - } - - // Keywords. - const std::unordered_set& keywords = request.keywords(); - for (auto keyword = keywords.begin(); keyword != keywords.end(); ++keyword) { - jstring keyword_str = env->NewStringUTF((*keyword).c_str()); - builder = util::ContinueBuilder( - env, builder, - env->CallObjectMethod( - builder, - ad_request_builder::GetMethodId(ad_request_builder::kAddKeyword), - keyword_str)); - env->DeleteLocalRef(keyword_str); - } - - // Content URL - if (!request.content_url().empty()) { - jstring content_url = env->NewStringUTF(request.content_url().c_str()); - builder = util::ContinueBuilder( - env, builder, - env->CallObjectMethod( - builder, - ad_request_builder::GetMethodId(ad_request_builder::kSetContentUrl), - content_url)); - env->DeleteLocalRef(content_url); - } - - // Neighboring Content Urls. - if (!request.neighboring_content_urls().empty()) { - jobject url_list = util::StdUnorderedSetToJavaList( - env, request.neighboring_content_urls()); - builder = util::ContinueBuilder( - env, builder, - env->CallObjectMethod( - builder, - ad_request_builder::GetMethodId( - ad_request_builder::kSetNeighboringContentUrls), - url_list)); - env->DeleteLocalRef(url_list); - } - - // Set the request agent string so requests originating from this library can - // be tracked and reported on as a group. - jstring agent_str = env->NewStringUTF(firebase::gma::GetRequestAgentString()); - builder = util::ContinueBuilder( - env, builder, - env->CallObjectMethod( - builder, - ad_request_builder::GetMethodId(ad_request_builder::kSetRequestAgent), - agent_str)); - env->DeleteLocalRef(agent_str); - - // Build request and load ad. - jobject java_request_ref = env->CallObjectMethod( - builder, ad_request_builder::GetMethodId(ad_request_builder::kBuild)); - env->DeleteLocalRef(builder); - - return java_request_ref; -} - -AdErrorCode MapAndroidAdRequestErrorCodeToCPPErrorCode(jint j_error_code) { - // Android error code sourced from - // https://developers.google.com/android/reference/com/google/android/gms/ads/AdRequest - switch (j_error_code) { - case 0: // ERROR_CODE_INTERNAL_ERROR - return kAdErrorCodeInternalError; - case 1: // ERROR_CODE_INVALID_REQUEST - return kAdErrorCodeInvalidRequest; - case 2: // ERROR_CODE_NETWORK_ERROR - return kAdErrorCodeNetworkError; - case 3: // ERROR_CODE_NO_FILL - return kAdErrorCodeNoFill; - case 8: // ERROR_CODE_APP_ID_MISSING - return kAdErrorCodeApplicationIdentifierMissing; - case 9: // ERROR_CODE_MEDIATION_NO_FILL - return kAdErrorCodeMediationNoFill; - case 10: // ERROR_CODE_REQUEST_ID_MISMATCH - return kAdErrorCodeInvalidRequest; - case 11: // ERROR_CODE_INVALID_AD_STRING - return kAdErrorCodeInvalidAdString; - default: - return kAdErrorCodeUnknown; - } -} - -AdErrorCode MapAndroidFullScreenContentErrorCodeToCPPErrorCode( - jint j_error_code) { - // Android FullScreenContent error codes sourced from: - // https://developers.google.com/android/reference/com/google/android/gms/ads/FullScreenContentCallback - switch (j_error_code) { - case 0: // ERROR_CODE_INTERNAL_ERROR - return kAdErrorCodeInternalError; - case 1: // ERROR_CODE_AD_REUSED - return kAdErrorCodeAdAlreadyUsed; - case 2: // ERROR_CODE_NOT_READY - return kAdErrorCodeAdNotReady; - case 3: // ERROR_CODE_APP_NOT_FOREGROUND - return kAdErrorCodeAppNotInForeground; - case 4: // ERROR_CODE_MEDIATION_SHOW_ERROR - return kAdErrorCodeMediationShowError; - default: - return kAdErrorCodeUnknown; - } -} - -AdErrorCode MapAndroidOpenAdInspectorErrorCodeToCPPErrorCode(int j_error_code) { - // Android AdInspector error codes sourced from: - // https://developers.google.com/android/reference/com/google/android/gms/ads/AdInspectorError#constants - switch (j_error_code) { - case 0: // ERROR_CODE_INTERNAL_ERROR - return kAdErrorCodeInternalError; - break; - case 1: // ERROR_CODE_FAILED_TO_LOAD - return kAdErrorCodeInspectorFailedToLoad; - break; - case 2: // ERROR_CODE_NOT_IN_TEST_MODE - return kAdErrorCodeNotInTestMode; - break; - case 3: // ERROR_CODE_ALREADY_OPEN - return kAdErrorCodeInsepctorAlreadyOpen; - break; - default: - return kAdErrorCodeUnknown; - } -} - -} // namespace gma -} // namespace firebase diff --git a/gma/src/android/ad_request_converter.h b/gma/src/android/ad_request_converter.h deleted file mode 100644 index 7fa5d1e106..0000000000 --- a/gma/src/android/ad_request_converter.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_ANDROID_AD_REQUEST_CONVERTER_H_ -#define FIREBASE_GMA_SRC_ANDROID_AD_REQUEST_CONVERTER_H_ - -#include - -#include "app/src/util_android.h" -#include "gma/src/include/firebase/gma/types.h" - -namespace firebase { -namespace gma { - -/// Converts instances of the AdRequest struct used by the C++ wrapper to -/// jobject references to Mobile Ads SDK AdRequest objects. -/// -/// @param[in] request The AdRequest struct to be converted into a Java -/// AdRequest. -/// @param[out] error kAdErrorCodeNone on success, or another error if -/// problems occurred. -/// @return On success, a local reference to an Android object representing the -/// AdRequest, or nullptr on error. -jobject GetJavaAdRequestFromCPPAdRequest(const AdRequest& request, - gma::AdErrorCode* error); - -// Converts the Android AdRequest error codes to the CPP -// platform-independent error codes defined in AdErrorCode. -AdErrorCode MapAndroidAdRequestErrorCodeToCPPErrorCode(jint j_error_code); - -// Converts the Android FullScreenContentCallback error codes to the CPP -// platform-independent error codes defined in AdErrorCode. -AdErrorCode MapAndroidFullScreenContentErrorCodeToCPPErrorCode( - jint j_error_code); - -// Converts the Android OpenAdInspector error codes to the CPP -// platform-independent error codes defined in AdErrorCode. -AdErrorCode MapAndroidOpenAdInspectorErrorCodeToCPPErrorCode(jint j_error_code); - -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_ANDROID_AD_REQUEST_CONVERTER_H_ diff --git a/gma/src/android/ad_view_internal_android.cc b/gma/src/android/ad_view_internal_android.cc deleted file mode 100644 index 309ad92c8a..0000000000 --- a/gma/src/android/ad_view_internal_android.cc +++ /dev/null @@ -1,475 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/android/ad_view_internal_android.h" - -#include -#include - -#include -#include -#include - -#include "app/src/assert.h" -#include "app/src/util_android.h" -#include "gma/src/android/ad_request_converter.h" -#include "gma/src/android/gma_android.h" -#include "gma/src/common/gma_common.h" -#include "gma/src/include/firebase/gma.h" -#include "gma/src/include/firebase/gma/ad_view.h" -#include "gma/src/include/firebase/gma/types.h" - -namespace firebase { -namespace gma { - -METHOD_LOOKUP_DEFINITION(ad_view_helper, - "com/google/firebase/gma/internal/cpp/AdViewHelper", - ADVIEWHELPER_METHODS); - -METHOD_LOOKUP_DEFINITION( - ad_view_helper_ad_view_listener, - "com/google/firebase/gma/internal/cpp/AdViewHelper$AdViewListener", - ADVIEWHELPER_ADVIEWLISTENER_METHODS); - -METHOD_LOOKUP_DEFINITION(ad_view, "com/google/android/gms/ads/AdView", - AD_VIEW_METHODS); - -namespace internal { - -// Contains data to invoke Initialize from the main thread. -struct InitializeOnMainThreadData { - InitializeOnMainThreadData() - : ad_parent(nullptr), - ad_size(0, 0), - ad_unit_id(), - ad_view(nullptr), - ad_view_helper(nullptr), - callback_data(nullptr) {} - ~InitializeOnMainThreadData() { - JNIEnv* env = GetJNI(); - env->DeleteGlobalRef(ad_parent); - env->DeleteGlobalRef(ad_view); - env->DeleteGlobalRef(ad_view_helper); - } - - AdParent ad_parent; - AdSize ad_size; - std::string ad_unit_id; - jobject ad_view; - jobject ad_view_helper; - FutureCallbackData* callback_data; -}; - -// Contains data to invoke LoadAd from the main thread. -struct LoadAdOnMainThreadData { - // Thread-safe call data. - LoadAdOnMainThreadData() - : ad_request(), callback_data(nullptr), ad_view_helper(nullptr) {} - ~LoadAdOnMainThreadData() { - JNIEnv* env = GetJNI(); - env->DeleteGlobalRef(ad_view_helper); - } - - AdRequest ad_request; - FutureCallbackData* callback_data; - jobject ad_view_helper; -}; - -// Contains data to facilitate various method calls on the main thraed. -// Thoe corresponding methods have no patamters and return Future -// results. -struct NulleryInvocationOnMainThreadData { - // Thread-safe call data. - NulleryInvocationOnMainThreadData() - : callback_data(nullptr), ad_view_helper(nullptr) {} - ~NulleryInvocationOnMainThreadData() { - JNIEnv* env = GetJNI(); - env->DeleteGlobalRef(ad_view_helper); - } - - FutureCallbackData* callback_data; - jobject ad_view_helper; - ad_view_helper::Method method; -}; - -AdViewInternalAndroid::AdViewInternalAndroid(AdView* base) - : AdViewInternal(base), - destroyed_(false), - helper_(nullptr), - initialized_(false) { - firebase::MutexLock lock(mutex_); - - JNIEnv* env = ::firebase::gma::GetJNI(); - FIREBASE_ASSERT(env); - - jobject activity = ::firebase::gma::GetActivity(); - FIREBASE_ASSERT(activity); - - jobject adview_ref = - env->NewObject(ad_view::GetClass(), - ad_view::GetMethodId(ad_view::kConstructor), activity); - - bool jni_exception = util::CheckAndClearJniExceptions(env); - FIREBASE_ASSERT(!jni_exception); - FIREBASE_ASSERT(adview_ref); - - jobject helper_ref = - env->NewObject(ad_view_helper::GetClass(), - ad_view_helper::GetMethodId(ad_view_helper::kConstructor), - reinterpret_cast(this), adview_ref); - - jni_exception = util::CheckAndClearJniExceptions(env); - FIREBASE_ASSERT(!jni_exception); - FIREBASE_ASSERT(helper_ref); - - ad_view_ = env->NewGlobalRef(adview_ref); - env->DeleteLocalRef(adview_ref); - - helper_ = env->NewGlobalRef(helper_ref); - env->DeleteLocalRef(helper_ref); -} - -AdViewInternalAndroid::~AdViewInternalAndroid() { - firebase::MutexLock lock(mutex_); - JNIEnv* env = ::firebase::gma::GetJNI(); - if (!destroyed_) { - // The application should have invoked Destroy already, but - // invoke it to prevent leaking memory. - LogWarning( - "Warning: AdView destructor invoked before the application " - " called Destroy() on the object."); - - env->CallVoidMethod(helper_, - ad_view_helper::GetMethodId(ad_view_helper::kDestroy), - /*callbackDataPtr=*/reinterpret_cast(ad_view_), - /*destructor_invocation=*/true); - } else { - env->DeleteGlobalRef(ad_view_); - } - - ad_view_ = nullptr; - - env->DeleteGlobalRef(helper_); - helper_ = nullptr; -} - -// This function is run on the main thread and is called in the -// AdViewInternalAndroid::Initialize() method. -void InitializeAdViewOnMainThread(void* data) { - InitializeOnMainThreadData* call_data = - reinterpret_cast(data); - JNIEnv* env = GetJNI(); - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(call_data); - FIREBASE_ASSERT(call_data->ad_view); - FIREBASE_ASSERT(call_data->ad_view_helper); - FIREBASE_ASSERT(call_data->callback_data); - - jstring ad_unit_id_str = - static_cast(::firebase::gma::GetJNI()->CallObjectMethod( - call_data->ad_view, ad_view::GetMethodId(ad_view::kGetAdUnitId))); - - if (ad_unit_id_str != nullptr) { - env->DeleteLocalRef(ad_unit_id_str); - - call_data->callback_data->future_data->future_impl.Complete( - call_data->callback_data->future_handle, kAdErrorCodeAlreadyInitialized, - kAdAlreadyInitializedErrorMessage); - delete call_data->callback_data; - call_data->callback_data = nullptr; - delete call_data; - return; - } - - ad_unit_id_str = env->NewStringUTF(call_data->ad_unit_id.c_str()); - env->CallVoidMethod(call_data->ad_view, - ad_view::GetMethodId(ad_view::kSetAdUnitId), - ad_unit_id_str); - bool jni_exception = util::CheckAndClearJniExceptions(env); - FIREBASE_ASSERT(!jni_exception); - env->DeleteLocalRef(ad_unit_id_str); - - jobject ad_size = - CreateJavaAdSize(env, call_data->ad_parent, call_data->ad_size); - FIREBASE_ASSERT(ad_size); - env->CallVoidMethod(call_data->ad_view, - ad_view::GetMethodId(ad_view::kSetAdSize), ad_size); - jni_exception = util::CheckAndClearJniExceptions(env); - FIREBASE_ASSERT(!jni_exception); - env->DeleteLocalRef(ad_size); - - env->CallVoidMethod(call_data->ad_view_helper, - ad_view_helper::GetMethodId(ad_view_helper::kInitialize), - call_data->ad_parent); - jni_exception = util::CheckAndClearJniExceptions(env); - FIREBASE_ASSERT(!jni_exception); - - jobject ad_listener = nullptr; - ad_listener = - env->NewObject(ad_view_helper_ad_view_listener::GetClass(), - ad_view_helper_ad_view_listener::GetMethodId( - ad_view_helper_ad_view_listener::kConstructor), - call_data->ad_view_helper); - jni_exception = util::CheckAndClearJniExceptions(env); - FIREBASE_ASSERT(!jni_exception); - - env->CallVoidMethod(call_data->ad_view, - ad_view::GetMethodId(ad_view::kSetAdListener), - ad_listener); - jni_exception = util::CheckAndClearJniExceptions(env); - FIREBASE_ASSERT(!jni_exception); - - env->CallVoidMethod(call_data->ad_view, - ad_view::GetMethodId(ad_view::kSetOnPaidEventListener), - ad_listener); - jni_exception = util::CheckAndClearJniExceptions(env); - FIREBASE_ASSERT(!jni_exception); - - env->DeleteLocalRef(ad_listener); - - call_data->callback_data->future_data->future_impl.Complete( - call_data->callback_data->future_handle, kAdErrorCodeNone, ""); - - delete call_data->callback_data; - call_data->callback_data = nullptr; - delete call_data; -} - -Future AdViewInternalAndroid::Initialize(AdParent parent, - const char* ad_unit_id, - const AdSize& size) { - firebase::MutexLock lock(mutex_); - - if (initialized_) { - const SafeFutureHandle future_handle = - future_data_.future_impl.SafeAlloc(kAdViewFnInitialize); - Future future = MakeFuture(&future_data_.future_impl, future_handle); - CompleteFuture(kAdErrorCodeAlreadyInitialized, - kAdAlreadyInitializedErrorMessage, future_handle, - &future_data_); - return future; - } - - initialized_ = true; - ad_size_ = size; - - FutureCallbackData* callback_data = - CreateVoidFutureCallbackData(kAdViewFnInitialize, &future_data_); - Future future = - MakeFuture(&future_data_.future_impl, callback_data->future_handle); - - JNIEnv* env = ::firebase::gma::GetJNI(); - FIREBASE_ASSERT(env); - - jobject activity = ::firebase::gma::GetActivity(); - InitializeOnMainThreadData* call_data = new InitializeOnMainThreadData(); - call_data->ad_parent = env->NewGlobalRef(parent); - call_data->ad_size = size; - call_data->ad_unit_id = ad_unit_id; - call_data->ad_view = env->NewGlobalRef(ad_view_); - call_data->ad_view_helper = env->NewGlobalRef(helper_); - call_data->callback_data = callback_data; - util::RunOnMainThread(env, activity, InitializeAdViewOnMainThread, call_data); - return future; -} - -// This function is run on the main thread and is called in the -// AdViewInternalAndroid::LoadAd() method. -void LoadAdOnMainThread(void* data) { - LoadAdOnMainThreadData* call_data = - reinterpret_cast(data); - JNIEnv* env = GetJNI(); - FIREBASE_ASSERT(env); - - gma::AdErrorCode error = kAdErrorCodeNone; - jobject j_ad_request = - GetJavaAdRequestFromCPPAdRequest(call_data->ad_request, &error); - - if (j_ad_request == nullptr) { - if (error == kAdErrorCodeNone) { - error = kAdErrorCodeInternalError; - } - call_data->callback_data->future_data->future_impl.CompleteWithResult( - call_data->callback_data->future_handle, error, - kAdCouldNotParseAdRequestErrorMessage, AdResult()); - delete call_data->callback_data; - call_data->callback_data = nullptr; - } else { - ::firebase::gma::GetJNI()->CallVoidMethod( - call_data->ad_view_helper, - ad_view_helper::GetMethodId(ad_view_helper::kLoadAd), - reinterpret_cast(call_data->callback_data), j_ad_request); - env->DeleteLocalRef(j_ad_request); - } - delete call_data; -} - -Future AdViewInternalAndroid::LoadAd(const AdRequest& request) { - firebase::MutexLock lock(mutex_); - - JNIEnv* env = GetJNI(); - FIREBASE_ASSERT(env); - - FutureCallbackData* callback_data = - CreateAdResultFutureCallbackData(kAdViewFnLoadAd, &future_data_); - Future future = - MakeFuture(&future_data_.future_impl, callback_data->future_handle); - - LoadAdOnMainThreadData* call_data = new LoadAdOnMainThreadData(); - call_data->ad_request = request; - call_data->callback_data = callback_data; - call_data->ad_view_helper = env->NewGlobalRef(helper_); - - jobject activity = ::firebase::gma::GetActivity(); - util::RunOnMainThread(env, activity, LoadAdOnMainThread, call_data); - - return future; -} - -BoundingBox AdViewInternalAndroid::bounding_box() const { - // This JNI integer array consists of the BoundingBox's width, height, - // x-coordinate, and y-coordinate. - JNIEnv* env = ::firebase::gma::GetJNI(); - jintArray jni_int_array = (jintArray)env->CallObjectMethod( - helper_, ad_view_helper::GetMethodId(ad_view_helper::kGetBoundingBox)); - - // The bounding box array must consist of 4 integers: width, height, - // x-coordinate, and y-coordinate. - int count = static_cast(env->GetArrayLength(jni_int_array)); - assert(count == 4); - (void)count; - - jint* bounding_box_elements = - env->GetIntArrayElements(jni_int_array, nullptr); - BoundingBox box; - box.width = static_cast(bounding_box_elements[0]); - box.height = static_cast(bounding_box_elements[1]); - box.x = static_cast(bounding_box_elements[2]); - box.y = static_cast(bounding_box_elements[3]); - jint j_position = env->CallIntMethod( - helper_, ad_view_helper::GetMethodId(ad_view_helper::kGetPosition)); - box.position = static_cast(j_position); - env->ReleaseIntArrayElements(jni_int_array, bounding_box_elements, 0); - env->DeleteLocalRef(jni_int_array); - - return box; -} - -Future AdViewInternalAndroid::Hide() { - firebase::MutexLock lock(mutex_); - return InvokeNullary(kAdViewFnHide, ad_view_helper::kHide); -} - -Future AdViewInternalAndroid::Show() { - firebase::MutexLock lock(mutex_); - return InvokeNullary(kAdViewFnShow, ad_view_helper::kShow); -} - -Future AdViewInternalAndroid::Pause() { - firebase::MutexLock lock(mutex_); - return InvokeNullary(kAdViewFnPause, ad_view_helper::kPause); -} - -Future AdViewInternalAndroid::Resume() { - firebase::MutexLock lock(mutex_); - return InvokeNullary(kAdViewFnResume, ad_view_helper::kResume); -} - -Future AdViewInternalAndroid::Destroy() { - firebase::MutexLock lock(mutex_); - destroyed_ = true; - FutureCallbackData* callback_data = - CreateVoidFutureCallbackData(kAdViewFnDestroy, &future_data_); - Future future = - MakeFuture(&future_data_.future_impl, callback_data->future_handle); - ::firebase::gma::GetJNI()->CallVoidMethod( - helper_, ad_view_helper::GetMethodId(ad_view_helper::kDestroy), - reinterpret_cast(callback_data), /*destructor_invocation=*/false); - return future; -} - -Future AdViewInternalAndroid::SetPosition(int x, int y) { - firebase::MutexLock lock(mutex_); - - FutureCallbackData* callback_data = - CreateVoidFutureCallbackData(kAdViewFnSetPosition, &future_data_); - Future future = - MakeFuture(&future_data_.future_impl, callback_data->future_handle); - - ::firebase::gma::GetJNI()->CallVoidMethod( - helper_, ad_view_helper::GetMethodId(ad_view_helper::kMoveToXY), - reinterpret_cast(callback_data), x, y); - - return future; -} - -Future AdViewInternalAndroid::SetPosition(AdView::Position position) { - firebase::MutexLock lock(mutex_); - - FutureCallbackData* callback_data = - CreateVoidFutureCallbackData(kAdViewFnSetPosition, &future_data_); - Future future = - MakeFuture(&future_data_.future_impl, callback_data->future_handle); - - ::firebase::gma::GetJNI()->CallVoidMethod( - helper_, ad_view_helper::GetMethodId(ad_view_helper::kMoveToPosition), - reinterpret_cast(callback_data), static_cast(position)); - - return future; -} - -// This function is run on the main thread and is called in the -// AdViewInternalAndroid::InvokeNullary() method. -void InvokeNulleryOnMainThread(void* data) { - JNIEnv* env = GetJNI(); - FIREBASE_ASSERT(env); - - NulleryInvocationOnMainThreadData* call_data = - reinterpret_cast(data); - - ::firebase::gma::GetJNI()->CallVoidMethod( - call_data->ad_view_helper, ad_view_helper::GetMethodId(call_data->method), - reinterpret_cast(call_data->callback_data)); - call_data->callback_data = nullptr; - delete call_data; -} - -Future AdViewInternalAndroid::InvokeNullary( - AdViewFn fn, ad_view_helper::Method method) { - JNIEnv* env = ::firebase::gma::GetJNI(); - jobject activity = ::firebase::gma::GetActivity(); - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(activity); - - FutureCallbackData* callback_data = - CreateVoidFutureCallbackData(fn, &future_data_); - Future future = - MakeFuture(&future_data_.future_impl, callback_data->future_handle); - - NulleryInvocationOnMainThreadData* call_data = - new NulleryInvocationOnMainThreadData(); - call_data->callback_data = callback_data; - call_data->ad_view_helper = env->NewGlobalRef(helper_); - call_data->method = method; - - util::RunOnMainThread(env, activity, InvokeNulleryOnMainThread, call_data); - - return future; -} - -} // namespace internal -} // namespace gma -} // namespace firebase diff --git a/gma/src/android/ad_view_internal_android.h b/gma/src/android/ad_view_internal_android.h deleted file mode 100644 index 53d1010d99..0000000000 --- a/gma/src/android/ad_view_internal_android.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_ANDROID_AD_VIEW_INTERNAL_ANDROID_H_ -#define FIREBASE_GMA_SRC_ANDROID_AD_VIEW_INTERNAL_ANDROID_H_ - -#include "app/src/include/firebase/internal/mutex.h" -#include "app/src/util_android.h" -#include "gma/src/common/ad_view_internal.h" - -namespace firebase { -namespace gma { - -// Used to set up the cache of AdViewHelper class method IDs to reduce -// time spent looking up methods by string. -// clang-format off -#define ADVIEWHELPER_METHODS(X) \ - X(Constructor, "", "(JLcom/google/android/gms/ads/AdView;)V"), \ - X(Initialize, "initialize", "(Landroid/app/Activity;)V"), \ - X(LoadAd, "loadAd", "(JLcom/google/android/gms/ads/AdRequest;)V"), \ - X(Hide, "hide", "(J)V"), \ - X(Show, "show", "(J)V"), \ - X(Pause, "pause", "(J)V"), \ - X(Resume, "resume", "(J)V"), \ - X(Destroy, "destroy", "(JZ)V"), \ - X(MoveToPosition, "moveTo", "(JI)V"), \ - X(MoveToXY, "moveTo", "(JII)V"), \ - X(GetBoundingBox, "getBoundingBox", "()[I"), \ - X(GetPosition, "getPosition", "()I") -// clang-format on - -METHOD_LOOKUP_DECLARATION(ad_view_helper, ADVIEWHELPER_METHODS); - -#define ADVIEWHELPER_ADVIEWLISTENER_METHODS(X) \ - X(Constructor, "", \ - "(Lcom/google/firebase/gma/internal/cpp/AdViewHelper;)V") - -METHOD_LOOKUP_DECLARATION(ad_view_helper_ad_view_listener, - ADVIEWHELPER_ADVIEWLISTENER_METHODS); - -// clang-format off -#define AD_VIEW_METHODS(X) \ - X(Constructor, "", "(Landroid/content/Context;)V"), \ - X(GetAdUnitId, "getAdUnitId", "()Ljava/lang/String;"), \ - X(SetAdSize, "setAdSize", "(Lcom/google/android/gms/ads/AdSize;)V"), \ - X(SetAdUnitId, "setAdUnitId", "(Ljava/lang/String;)V"), \ - X(SetAdListener, "setAdListener", \ - "(Lcom/google/android/gms/ads/AdListener;)V"), \ - X(SetOnPaidEventListener, "setOnPaidEventListener", \ - "(Lcom/google/android/gms/ads/OnPaidEventListener;)V") -// clang-format on - -METHOD_LOOKUP_DECLARATION(ad_view, AD_VIEW_METHODS); - -namespace internal { - -class AdViewInternalAndroid : public AdViewInternal { - public: - explicit AdViewInternalAndroid(AdView* base); - ~AdViewInternalAndroid() override; - - Future Initialize(AdParent parent, const char* ad_unit_id, - const AdSize& size) override; - Future LoadAd(const AdRequest& request) override; - BoundingBox bounding_box() const override; - Future SetPosition(int x, int y) override; - Future SetPosition(AdView::Position position) override; - Future Hide() override; - Future Show() override; - Future Pause() override; - Future Resume() override; - Future Destroy() override; - bool is_initialized() const override { return initialized_; } - - private: - // Convenience method to "dry" the JNI calls that don't take parameters beyond - // the future callback pointer. - Future InvokeNullary(AdViewFn fn, ad_view_helper::Method method); - - // Reference to the Android AdView object used to display AdView ads. - jobject ad_view_; - - // Marks if Destroy() was called on the object. - bool destroyed_; - - // Reference to the Java helper object used to interact with the Mobile Ads - // SDK. - jobject helper_; - - // Tracks if this AdView has been initialized. - bool initialized_; - - // Mutex to guard against concurrent operations; - Mutex mutex_; -}; - -} // namespace internal -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_ANDROID_AD_VIEW_INTERNAL_ANDROID_H_ diff --git a/gma/src/android/adapter_response_info_android.cc b/gma/src/android/adapter_response_info_android.cc deleted file mode 100644 index 25c110ba09..0000000000 --- a/gma/src/android/adapter_response_info_android.cc +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/android/adapter_response_info_android.h" - -#include - -#include "gma/src/android/ad_error_android.h" -#include "gma/src/android/gma_android.h" -#include "gma/src/common/gma_common.h" -#include "gma/src/include/firebase/gma.h" - -namespace firebase { -namespace gma { - -METHOD_LOOKUP_DEFINITION(adapter_response_info, - PROGUARD_KEEP_CLASS - "com/google/android/gms/ads/AdapterResponseInfo", - ADAPTERRESPONSEINFO_METHODS); - -AdapterResponseInfo::AdapterResponseInfo( - const AdapterResponseInfoInternal& internal) - : ad_result_() { - JNIEnv* env = GetJNI(); - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(internal.j_adapter_response_info); - - // Parse the fields of the GMA Android SDK's AdapterResponseInfo using the - // reference in the internal structure. - const jobject j_adapter_response_info = - env->NewLocalRef(internal.j_adapter_response_info); - - // Construct an AdErrorInternal from the Android SDK AdError object in the - // AdapterResponseInfo. - const jobject j_native_ad_error = env->CallObjectMethod( - j_adapter_response_info, - adapter_response_info::GetMethodId(adapter_response_info::kGetAdError)); - - if (j_native_ad_error != nullptr) { - AdErrorInternal ad_error_internal; - ad_error_internal.native_ad_error = j_native_ad_error; - AdError ad_error = AdError(ad_error_internal); - if (ad_error.code() != kAdErrorCodeNone) { - ad_result_ = AdResult(ad_error); - } - env->DeleteLocalRef(ad_error_internal.native_ad_error); - } - - // The class name of the adapter. - const jobject j_adapter_class_name = - env->CallObjectMethod(j_adapter_response_info, - adapter_response_info::GetMethodId( - adapter_response_info::kGetAdapterClassName)); - FIREBASE_ASSERT(j_adapter_class_name); - adapter_class_name_ = util::JStringToString(env, j_adapter_class_name); - env->DeleteLocalRef(j_adapter_class_name); - - // The latenency in milliseconds of time between request and response. - const jlong j_latency = env->CallLongMethod( - j_adapter_response_info, adapter_response_info::GetMethodId( - adapter_response_info::kGetLatencyMillis)); - latency_ = (int64_t)j_latency; - - // A string represenation of the AdapterResponseInfo. - const jobject j_to_string = env->CallObjectMethod( - j_adapter_response_info, - adapter_response_info::GetMethodId(adapter_response_info::kToString)); - FIREBASE_ASSERT(j_to_string); - to_string_ = util::JStringToString(env, j_to_string); - env->DeleteLocalRef(j_to_string); - env->DeleteLocalRef(j_adapter_response_info); -} - -} // namespace gma -} // namespace firebase diff --git a/gma/src/android/adapter_response_info_android.h b/gma/src/android/adapter_response_info_android.h deleted file mode 100644 index 405e502364..0000000000 --- a/gma/src/android/adapter_response_info_android.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_ANDROID_ADAPTER_RESPONSE_INFO_ANDROID_H_ -#define FIREBASE_GMA_SRC_ANDROID_ADAPTER_RESPONSE_INFO_ANDROID_H_ - -#include - -#include "app/src/util_android.h" -#include "gma/src/include/firebase/gma/types.h" - -namespace firebase { -namespace gma { - -struct AdapterResponseInfoInternal { - jobject j_adapter_response_info; -}; - -// Used to set up the cache of class method IDs to reduce -// time spent looking up methods by string. -// clang-format off -#define ADAPTERRESPONSEINFO_METHODS(X) \ - X(GetAdError, "getAdError", \ - "()Lcom/google/android/gms/ads/AdError;"), \ - X(GetAdapterClassName, "getAdapterClassName", "()Ljava/lang/String;"), \ - X(GetLatencyMillis, "getLatencyMillis", "()J"), \ - X(ToString, "toString", "()Ljava/lang/String;") -// clang-format on - -METHOD_LOOKUP_DECLARATION(adapter_response_info, ADAPTERRESPONSEINFO_METHODS); - -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_ANDROID_ADAPTER_RESPONSE_INFO_ANDROID_H_ diff --git a/gma/src/android/gma_android.cc b/gma/src/android/gma_android.cc deleted file mode 100644 index 9fc2400892..0000000000 --- a/gma/src/android/gma_android.cc +++ /dev/null @@ -1,1510 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/android/gma_android.h" - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "app/src/assert.h" -#include "app/src/embedded_file.h" -#include "app/src/include/firebase/internal/common.h" -#include "app/src/include/google_play_services/availability.h" -#include "app/src/reference_counted_future_impl.h" -#include "app/src/util_android.h" -#include "gma/gma_resources.h" -#include "gma/src/android/ad_error_android.h" -#include "gma/src/android/ad_request_converter.h" -#include "gma/src/android/ad_view_internal_android.h" -#include "gma/src/android/adapter_response_info_android.h" -#include "gma/src/android/interstitial_ad_internal_android.h" -#include "gma/src/android/native_ad_image_android.h" -#include "gma/src/android/native_ad_internal_android.h" -#include "gma/src/android/query_info_internal_android.h" -#include "gma/src/android/response_info_android.h" -#include "gma/src/android/rewarded_ad_internal_android.h" -#include "gma/src/common/gma_common.h" -#include "gma/src/include/firebase/gma.h" -#include "gma/src/include/firebase/gma/types.h" - -namespace firebase { -namespace gma { - -namespace internal { -::firebase::Mutex g_cached_gma_embedded_files_mutex; -std::vector<::firebase::internal::EmbeddedFile>* g_cached_gma_embedded_files = - nullptr; -} // namespace internal - -METHOD_LOOKUP_DEFINITION(mobile_ads, - PROGUARD_KEEP_CLASS - "com/google/android/gms/ads/MobileAds", - MOBILEADS_METHODS); -METHOD_LOOKUP_DEFINITION(ad_size, - PROGUARD_KEEP_CLASS - "com/google/android/gms/ads/AdSize", - ADSIZE_METHODS); -METHOD_LOOKUP_DEFINITION(request_config, - PROGUARD_KEEP_CLASS - "com/google/android/gms/ads/RequestConfiguration", - REQUESTCONFIGURATION_METHODS); - -METHOD_LOOKUP_DEFINITION( - request_config_builder, - PROGUARD_KEEP_CLASS - "com/google/android/gms/ads/RequestConfiguration$Builder", - REQUESTCONFIGURATIONBUILDER_METHODS); - -METHOD_LOOKUP_DEFINITION( - initialization_status, - PROGUARD_KEEP_CLASS - "com/google/android/gms/ads/initialization/InitializationStatus", - INITIALIZATION_STATUS_METHODS); - -METHOD_LOOKUP_DEFINITION( - adapter_status, - PROGUARD_KEEP_CLASS - "com/google/android/gms/ads/initialization/AdapterStatus", - ADAPTER_STATUS_METHODS); - -METHOD_LOOKUP_DEFINITION( - adapter_status_state, - PROGUARD_KEEP_CLASS - "com/google/android/gms/ads/initialization/AdapterStatus$State", - METHOD_LOOKUP_NONE, ADAPTER_STATUS_STATE_FIELDS); - -METHOD_LOOKUP_DEFINITION( - ad_inspector_helper, - "com/google/firebase/gma/internal/cpp/AdInspectorHelper", - AD_INSPECTOR_HELPER_METHODS); - -METHOD_LOOKUP_DEFINITION( - gma_initialization_helper, - "com/google/firebase/gma/internal/cpp/GmaInitializationHelper", - GMA_INITIALIZATION_HELPER_METHODS); - -// Constants representing each GMA function that returns a Future. -enum GmaFn { - kGmaFnInitialize, - kGmaFnCount, -}; - -static JavaVM* g_java_vm = nullptr; -static const ::firebase::App* g_app = nullptr; -static jobject g_activity; - -static bool g_initialized = false; - -static ReferenceCountedFutureImpl* g_future_impl = nullptr; -// Mutex for creation/deletion of a g_future_impl. -static Mutex g_future_impl_mutex; // NOLINT -static SafeFutureHandle g_initialization_handle = - SafeFutureHandle::kInvalidHandle; // NOLINT - -struct OpenAdInspectorCallData { - // Thread-safe call data. - OpenAdInspectorCallData() - : vm(g_java_vm), ad_parent(nullptr), listener(nullptr) {} - ~OpenAdInspectorCallData() { - JNIEnv* env = firebase::util::GetThreadsafeJNIEnv(vm); - env->DeleteGlobalRef(ad_parent); - } - JavaVM* vm; - AdParent ad_parent; - AdInspectorClosedListener* listener; -}; - -struct MobileAdsCallData { - // Thread-safe call data. - MobileAdsCallData() : vm(g_java_vm), activity_global(nullptr) {} - ~MobileAdsCallData() { - JNIEnv* env = firebase::util::GetThreadsafeJNIEnv(vm); - env->DeleteGlobalRef(activity_global); - } - JavaVM* vm; - jobject activity_global; -}; - -// This function is run on the main thread and is called in the -// InitializeGoogleMobileAds() function. -void CallInitializeGoogleMobileAds(void* data) { - MobileAdsCallData* call_data = reinterpret_cast(data); - JNIEnv* env = firebase::util::GetThreadsafeJNIEnv(call_data->vm); - bool jni_env_exists = (env != nullptr); - FIREBASE_ASSERT(jni_env_exists); - - jobject activity = call_data->activity_global; - env->CallStaticVoidMethod(gma_initialization_helper::GetClass(), - gma_initialization_helper::GetMethodId( - gma_initialization_helper::kInitializeGma), - activity); - // Check if there is a JNI exception since the MobileAds.initialize method can - // throw an IllegalArgumentException if the pub passes null for the activity. - bool jni_exception = util::CheckAndClearJniExceptions(env); - FIREBASE_ASSERT(!jni_exception); - - delete call_data; -} - -static AdapterStatus ConvertFromJavaAdapterStatus(jobject j_adapter_status) { - JNIEnv* env = ::firebase::gma::GetJNI(); - - std::string description = util::JniStringToString( - env, env->CallObjectMethod( - j_adapter_status, - adapter_status::GetMethodId(adapter_status::kGetDescription))); - util::CheckAndClearJniExceptions(env); - - int latency = env->CallIntMethod( - j_adapter_status, - adapter_status::GetMethodId(adapter_status::kGetLatency)); - util::CheckAndClearJniExceptions(env); - - jobject j_state_current = env->CallObjectMethod( - j_adapter_status, - adapter_status::GetMethodId(adapter_status::kGetInitializationState)); - util::CheckAndClearJniExceptions(env); - - jobject j_state_ready = env->GetStaticObjectField( - adapter_status_state::GetClass(), - adapter_status_state::GetFieldId(adapter_status_state::kReady)); - util::CheckAndClearJniExceptions(env); - - // is_initialized = (status.getInitializationStatus() == - // AdapterState.State.READY) - bool is_initialized = env->CallBooleanMethod( - j_state_current, util::enum_class::GetMethodId(util::enum_class::kEquals), - j_state_ready); - util::CheckAndClearJniExceptions(env); - - env->DeleteLocalRef(j_state_current); - env->DeleteLocalRef(j_state_ready); - env->DeleteLocalRef(j_adapter_status); - return GmaInternal::CreateAdapterStatus(description, is_initialized, latency); -} - -static AdapterInitializationStatus PopulateAdapterInitializationStatus( - jobject j_init_status) { - if (!j_init_status) return GmaInternal::CreateAdapterInitializationStatus({}); - - JNIEnv* env = ::firebase::gma::GetJNI(); - std::map adapter_status_map; - // Map - jobject j_map = env->CallObjectMethod( - j_init_status, initialization_status::GetMethodId( - initialization_status::kGetAdapterStatusMap)); - util::CheckAndClearJniExceptions(env); - - // Extract keys and values from the map. - // key_set = map.keySet(); - jobject j_key_set = - env->CallObjectMethod(j_map, util::map::GetMethodId(util::map::kKeySet)); - util::CheckAndClearJniExceptions(env); - - // iter = key_set.iterator(); - jobject j_iter = env->CallObjectMethod( - j_key_set, util::set::GetMethodId(util::set::kIterator)); - util::CheckAndClearJniExceptions(env); - - // while (iter.hasNext()) { - while (env->CallBooleanMethod( - j_iter, util::iterator::GetMethodId(util::iterator::kHasNext))) { - // adapter_name = iter.next(); - jobject j_adapter_name = env->CallObjectMethod( - j_iter, util::iterator::GetMethodId(util::iterator::kNext)); - util::CheckAndClearJniExceptions(env); - - // adapter_status = map.get(adapter_name); - jobject j_adapter_status = env->CallObjectMethod( - j_map, util::map::GetMethodId(util::map::kGet), j_adapter_name); - util::CheckAndClearJniExceptions(env); - - std::string key = - util::JniStringToString(env, j_adapter_name); // deletes name - AdapterStatus value = - ConvertFromJavaAdapterStatus(j_adapter_status); // deletes status - - adapter_status_map[key] = value; - } - - env->DeleteLocalRef(j_iter); - env->DeleteLocalRef(j_key_set); - env->DeleteLocalRef(j_map); - - return GmaInternal::CreateAdapterInitializationStatus(adapter_status_map); -} - -// Initializes the Google Mobile Ads SDK using the MobileAds.initialize() -// method. The GMA app ID is retrieved from the App's android manifest. -Future InitializeGoogleMobileAds(JNIEnv* env) { - Future future_to_return; - { - MutexLock lock(g_future_impl_mutex); - FIREBASE_ASSERT(g_future_impl); - FIREBASE_ASSERT( - g_initialization_handle.get() == - SafeFutureHandle::kInvalidHandle.get()); - g_initialization_handle = - g_future_impl->SafeAlloc(kGmaFnInitialize); - future_to_return = MakeFuture(g_future_impl, g_initialization_handle); - } - - MobileAdsCallData* call_data = new MobileAdsCallData(); - call_data->activity_global = env->NewGlobalRef(g_activity); - util::RunOnMainThread(env, g_activity, CallInitializeGoogleMobileAds, - call_data); - - return future_to_return; -} - -Future Initialize(const ::firebase::App& app, - InitResult* init_result_out) { - FIREBASE_ASSERT(!g_initialized); - g_app = &app; - return Initialize(g_app->GetJNIEnv(), g_app->activity(), init_result_out); -} - -Future Initialize(JNIEnv* env, jobject activity, - InitResult* init_result_out) { - FIREBASE_ASSERT(!g_initialized); - - if (g_java_vm == nullptr) { - env->GetJavaVM(&g_java_vm); - } - - if (!util::Initialize(env, activity)) { - if (init_result_out) { - *init_result_out = kInitResultFailedMissingDependency; - } - // Need to return an invalid Future, because without GMA initialized, - // there is no ReferenceCountedFutureImpl to hold an actual Future instance. - return Future(); - } - - // GMA requires Google Play services if the class - // "com.google.android.gms.ads.internal.ClientApi" does not exist. - if (!util::FindClass(env, "com/google/android/gms/ads/internal/ClientApi") && - google_play_services::CheckAvailability(env, activity) != - google_play_services::kAvailabilityAvailable) { - util::Terminate(env); - if (init_result_out) { - *init_result_out = kInitResultFailedMissingDependency; - } - // Need to return an invalid Future, because without GMA initialized, - // there is no ReferenceCountedFutureImpl to hold an actual Future instance. - return Future(); - } - - // Between this and UMP, we only want to load these files once. - { - MutexLock lock(internal::g_cached_gma_embedded_files_mutex); - if (internal::g_cached_gma_embedded_files == nullptr) { - internal::g_cached_gma_embedded_files = - new std::vector(); - *internal::g_cached_gma_embedded_files = - util::CacheEmbeddedFiles(env, activity, - firebase::internal::EmbeddedFile::ToVector( - firebase_gma::gma_resources_filename, - firebase_gma::gma_resources_data, - firebase_gma::gma_resources_size)); - } - } - const std::vector& embedded_files = - *internal::g_cached_gma_embedded_files; - - if (!(mobile_ads::CacheMethodIds(env, activity) && - ad_request_builder::CacheMethodIds(env, activity) && - adapter_response_info::CacheMethodIds(env, activity) && - ad_error::CacheMethodIds(env, activity) && - ad_size::CacheMethodIds(env, activity) && - ad_view::CacheMethodIds(env, activity) && - request_config::CacheMethodIds(env, activity) && - request_config_builder::CacheMethodIds(env, activity) && - response_info::CacheMethodIds(env, activity) && - adapter_status::CacheMethodIds(env, activity) && - adapter_status_state::CacheFieldIds(env, activity) && - initialization_status::CacheMethodIds(env, activity) && - ad_inspector_helper::CacheClassFromFiles(env, activity, - &embedded_files) != nullptr && - ad_inspector_helper::CacheMethodIds(env, activity) && - gma_initialization_helper::CacheClassFromFiles( - env, activity, &embedded_files) != nullptr && - gma_initialization_helper::CacheMethodIds(env, activity) && - ad_view_helper::CacheClassFromFiles(env, activity, &embedded_files) != - nullptr && - ad_view_helper::CacheMethodIds(env, activity) && - ad_view_helper_ad_view_listener::CacheMethodIds(env, activity) && - interstitial_ad_helper::CacheClassFromFiles( - env, activity, &embedded_files) != nullptr && - interstitial_ad_helper::CacheMethodIds(env, activity) && - native_ad_helper::CacheClassFromFiles(env, activity, &embedded_files) != - nullptr && - native_ad_helper::CacheMethodIds(env, activity) && - native_image::CacheMethodIds(env, activity) && - download_helper::CacheClassFromFiles(env, activity, &embedded_files) != - nullptr && - download_helper::CacheMethodIds(env, activity) && - query_info_helper::CacheClassFromFiles(env, activity, - &embedded_files) != nullptr && - query_info_helper::CacheMethodIds(env, activity) && - rewarded_ad_helper::CacheClassFromFiles(env, activity, - &embedded_files) != nullptr && - rewarded_ad_helper::CacheMethodIds(env, activity) && - load_ad_error::CacheMethodIds(env, activity) && - gma::RegisterNatives())) { - ReleaseClasses(env); - util::Terminate(env); - if (init_result_out) { - *init_result_out = kInitResultFailedMissingDependency; - } - return Future(); - } - - { - MutexLock lock(g_future_impl_mutex); - g_future_impl = new ReferenceCountedFutureImpl(kGmaFnCount); - } - - g_initialized = true; - g_activity = env->NewGlobalRef(activity); - - Future future = InitializeGoogleMobileAds(env); - RegisterTerminateOnDefaultAppDestroy(); - - if (init_result_out) { - *init_result_out = kInitResultSuccess; - } - return future; -} - -Future InitializeLastResult() { - MutexLock lock(g_future_impl_mutex); - return g_future_impl - ? static_cast&>( - g_future_impl->LastResult(kGmaFnInitialize)) - : Future(); -} - -AdapterInitializationStatus GetInitializationStatus() { - if (g_initialized) { - JNIEnv* env = ::firebase::gma::GetJNI(); - jobject j_status = env->CallStaticObjectMethod( - mobile_ads::GetClass(), - mobile_ads::GetMethodId(mobile_ads::kGetInitializationStatus)); - util::CheckAndClearJniExceptions(env); - AdapterInitializationStatus status = - PopulateAdapterInitializationStatus(j_status); - env->DeleteLocalRef(j_status); - return status; - } else { - // Returns an empty map. - return PopulateAdapterInitializationStatus(nullptr); - } -} - -void DisableSDKCrashReporting() {} - -void DisableMediationInitialization() {} - -void SetRequestConfiguration( - const RequestConfiguration& request_configuration) { - JNIEnv* env = ::firebase::gma::GetJNI(); - jobject builder = env->NewObject(request_config_builder::GetClass(), - request_config_builder::GetMethodId( - request_config_builder::kConstructor)); - bool jni_exception = util::CheckAndClearJniExceptions(env); - FIREBASE_ASSERT(!jni_exception); - - // Test DeviceIds - if (request_configuration.test_device_ids.size() > 0) { - jobject test_device_list = - util::StdVectorToJavaList(env, request_configuration.test_device_ids); - builder = util::ContinueBuilder( - env, builder, - env->CallObjectMethod(builder, - request_config_builder::GetMethodId( - request_config_builder::kSetTestDeviceIds), - test_device_list)); - jni_exception = util::CheckAndClearJniExceptions(env); - FIREBASE_ASSERT(!jni_exception); - env->DeleteLocalRef(test_device_list); - } - - jstring j_string_max_ad_rating = nullptr; - switch (request_configuration.max_ad_content_rating) { - case RequestConfiguration::kMaxAdContentRatingG: - j_string_max_ad_rating = env->NewStringUTF("G"); - break; - case RequestConfiguration::kMaxAdContentRatingPG: - j_string_max_ad_rating = env->NewStringUTF("PG"); - break; - case RequestConfiguration::kMaxAdContentRatingT: - j_string_max_ad_rating = env->NewStringUTF("T"); - break; - case RequestConfiguration::kMaxAdContentRatingMA: - j_string_max_ad_rating = env->NewStringUTF("MA"); - break; - case RequestConfiguration::kMaxAdContentRatingUnspecified: - default: - j_string_max_ad_rating = env->NewStringUTF(""); - break; - } - builder = util::ContinueBuilder( - env, builder, - env->CallObjectMethod(builder, - request_config_builder::GetMethodId( - request_config_builder::kSetMaxAdContentRating), - j_string_max_ad_rating)); - jni_exception = util::CheckAndClearJniExceptions(env); - FIREBASE_ASSERT(!jni_exception); - env->DeleteLocalRef(j_string_max_ad_rating); - - int child_directed_treatment_tag; - switch (request_configuration.tag_for_child_directed_treatment) { - case RequestConfiguration::kChildDirectedTreatmentFalse: - child_directed_treatment_tag = 0; - break; - case RequestConfiguration::kChildDirectedTreatmentTrue: - child_directed_treatment_tag = 1; - break; - default: - case RequestConfiguration::kChildDirectedTreatmentUnspecified: - child_directed_treatment_tag = -1; - break; - } - builder = util::ContinueBuilder( - env, builder, - env->CallObjectMethod( - builder, - request_config_builder::GetMethodId( - request_config_builder::kSetTagForChildDirectedTreatment), - child_directed_treatment_tag)); - jni_exception = util::CheckAndClearJniExceptions(env); - FIREBASE_ASSERT(!jni_exception); - - int under_age_of_consent_tag; - switch (request_configuration.tag_for_under_age_of_consent) { - case RequestConfiguration::kUnderAgeOfConsentFalse: - under_age_of_consent_tag = 0; - break; - case RequestConfiguration::kUnderAgeOfConsentTrue: - under_age_of_consent_tag = 1; - break; - default: - case RequestConfiguration::kUnderAgeOfConsentUnspecified: - under_age_of_consent_tag = -1; - break; - } - builder = util::ContinueBuilder( - env, builder, - env->CallObjectMethod( - builder, - request_config_builder::GetMethodId( - request_config_builder::kSetTagForUnderAgeOfConsent), - under_age_of_consent_tag)); - jni_exception = util::CheckAndClearJniExceptions(env); - FIREBASE_ASSERT(!jni_exception); - - // Build request configuration. - jobject j_request_configuration = env->CallObjectMethod( - builder, - request_config_builder::GetMethodId(request_config_builder::kBuild)); - jni_exception = util::CheckAndClearJniExceptions(env); - FIREBASE_ASSERT(!jni_exception); - env->DeleteLocalRef(builder); - - // Set the request configuration. - env->CallStaticVoidMethod( - mobile_ads::GetClass(), - mobile_ads::GetMethodId(mobile_ads::kSetRequestConfiguration), - j_request_configuration); - - env->DeleteLocalRef(j_request_configuration); -} - -RequestConfiguration GetRequestConfiguration() { - JNIEnv* env = ::firebase::gma::GetJNI(); - RequestConfiguration request_configuration; - jobject j_request_config = env->CallStaticObjectMethod( - mobile_ads::GetClass(), - mobile_ads::GetMethodId(mobile_ads::kGetRequestConfiguration)); - bool jni_exception = util::CheckAndClearJniExceptions(env); - FIREBASE_ASSERT(!jni_exception); - FIREBASE_ASSERT(j_request_config != nullptr); - - // Max Ad Content Rating. - const jstring j_max_ad_content_rating = - static_cast(env->CallObjectMethod( - j_request_config, - request_config::GetMethodId(request_config::kGetMaxAdContentRating))); - jni_exception = util::CheckAndClearJniExceptions(env); - FIREBASE_ASSERT(!jni_exception); - FIREBASE_ASSERT(j_max_ad_content_rating != nullptr); - const std::string max_ad_content_rating = - env->GetStringUTFChars(j_max_ad_content_rating, nullptr); - FIREBASE_ASSERT(!jni_exception); - if (max_ad_content_rating == "G") { - request_configuration.max_ad_content_rating = - RequestConfiguration::kMaxAdContentRatingG; - } else if (max_ad_content_rating == "PG") { - request_configuration.max_ad_content_rating = - RequestConfiguration::kMaxAdContentRatingPG; - } else if (max_ad_content_rating == "MA") { - request_configuration.max_ad_content_rating = - RequestConfiguration::kMaxAdContentRatingMA; - } else if (max_ad_content_rating == "T") { - request_configuration.max_ad_content_rating = - RequestConfiguration::kMaxAdContentRatingT; - } else if (max_ad_content_rating == "") { - request_configuration.max_ad_content_rating = - RequestConfiguration::kMaxAdContentRatingUnspecified; - } else { - FIREBASE_ASSERT_MESSAGE(false, - "RequestConfiguration unknown MaxAdContentRating"); - } - env->DeleteLocalRef(j_max_ad_content_rating); - - // Tag For Child Directed Treatment - const jint j_child_directed_treatment_tag = env->CallIntMethod( - j_request_config, request_config::GetMethodId( - request_config::kGetTagForChildDirectedTreatment)); - jni_exception = util::CheckAndClearJniExceptions(env); - FIREBASE_ASSERT(!jni_exception); - switch (j_child_directed_treatment_tag) { - case -1: - request_configuration.tag_for_child_directed_treatment = - RequestConfiguration::kChildDirectedTreatmentUnspecified; - break; - case 0: - request_configuration.tag_for_child_directed_treatment = - RequestConfiguration::kChildDirectedTreatmentFalse; - break; - case 1: - request_configuration.tag_for_child_directed_treatment = - RequestConfiguration::kChildDirectedTreatmentTrue; - break; - default: - FIREBASE_ASSERT_MESSAGE( - false, "RequestConfiguration unknown TagForChildDirectedTreatment"); - } - - // Tag For Under Age Of Consent - const jint j_under_age_of_consent_tag = env->CallIntMethod( - j_request_config, - request_config::GetMethodId(request_config::kGetTagForUnderAgeOfConsent)); - jni_exception = util::CheckAndClearJniExceptions(env); - FIREBASE_ASSERT(!jni_exception); - switch (j_under_age_of_consent_tag) { - case -1: - request_configuration.tag_for_under_age_of_consent = - RequestConfiguration::kUnderAgeOfConsentUnspecified; - break; - case 0: - request_configuration.tag_for_under_age_of_consent = - RequestConfiguration::kUnderAgeOfConsentFalse; - break; - case 1: - request_configuration.tag_for_under_age_of_consent = - RequestConfiguration::kUnderAgeOfConsentTrue; - break; - default: - FIREBASE_ASSERT_MESSAGE( - false, "RequestConfiguration unknown TagForUnderAgeOfConsent"); - } - - // Test Device Ids - const jobject j_test_device_id_list = env->CallObjectMethod( - j_request_config, - request_config::GetMethodId(request_config::kGetTestDeviceIds)); - jni_exception = util::CheckAndClearJniExceptions(env); - FIREBASE_ASSERT(!jni_exception); - FIREBASE_ASSERT(j_test_device_id_list != nullptr); - util::JavaListToStdStringVector(env, &request_configuration.test_device_ids, - j_test_device_id_list); - env->DeleteLocalRef(j_test_device_id_list); - - return request_configuration; -} - -// This function is run on the main thread and is called in the -// OpenAdInspector() function. -void CallOpenAdInspector(void* data) { - OpenAdInspectorCallData* call_data = - reinterpret_cast(data); - JNIEnv* env = firebase::util::GetThreadsafeJNIEnv(call_data->vm); - jlong jlistener = (jlong)call_data->listener; - - jobject ad_inspector_helper_ref = env->NewObject( - ad_inspector_helper::GetClass(), - ad_inspector_helper::GetMethodId(ad_inspector_helper::kConstructor), - jlistener); - bool jni_exception = util::CheckAndClearJniExceptions(env); - FIREBASE_ASSERT(!jni_exception); - - env->CallStaticVoidMethod( - mobile_ads::GetClass(), - mobile_ads::GetMethodId(mobile_ads::kOpenAdInspector), - call_data->ad_parent, ad_inspector_helper_ref); - util::CheckAndClearJniExceptions(env); - - jni_exception = util::CheckAndClearJniExceptions(env); - FIREBASE_ASSERT(!jni_exception); - - env->DeleteLocalRef(ad_inspector_helper_ref); - delete call_data; -} - -void OpenAdInspector(AdParent parent, AdInspectorClosedListener* listener) { - JNIEnv* env = ::firebase::gma::GetJNI(); - FIREBASE_ASSERT(env); - - OpenAdInspectorCallData* call_data = new OpenAdInspectorCallData(); - call_data->ad_parent = env->NewGlobalRef(parent); - call_data->listener = listener; - jobject activity = ::firebase::gma::GetActivity(); - util::RunOnMainThread(env, activity, CallOpenAdInspector, call_data); -} - -void SetIsSameAppKeyEnabled(bool is_enabled) {} - -// Release classes registered by this module. -void ReleaseClasses(JNIEnv* env) { - mobile_ads::ReleaseClass(env); - ad_request_builder::ReleaseClass(env); - adapter_response_info::ReleaseClass(env); - ad_error::ReleaseClass(env); - ad_size::ReleaseClass(env); - ad_view::ReleaseClass(env); - request_config::ReleaseClass(env); - request_config_builder::ReleaseClass(env); - response_info::ReleaseClass(env); - adapter_status::ReleaseClass(env); - adapter_status_state::ReleaseClass(env); - initialization_status::ReleaseClass(env); - ad_inspector_helper::ReleaseClass(env); - gma_initialization_helper::ReleaseClass(env); - ad_view_helper::ReleaseClass(env); - ad_view_helper_ad_view_listener::ReleaseClass(env); - interstitial_ad_helper::ReleaseClass(env); - native_ad_helper::ReleaseClass(env); - native_image::ReleaseClass(env); - download_helper::ReleaseClass(env); - query_info_helper::ReleaseClass(env); - rewarded_ad_helper::ReleaseClass(env); - load_ad_error::ReleaseClass(env); -} - -bool IsInitialized() { return g_initialized; } - -void Terminate() { - if (!g_initialized) { - LogWarning("GMA already shut down"); - return; - } - { - MutexLock lock(g_future_impl_mutex); - g_initialization_handle = - SafeFutureHandle::kInvalidHandle; - delete g_future_impl; - g_future_impl = nullptr; - } - UnregisterTerminateOnDefaultAppDestroy(); - DestroyCleanupNotifier(); - FIREBASE_ASSERT(g_activity); - JNIEnv* env = GetJNI(); - g_initialized = false; - g_app = nullptr; - g_java_vm = nullptr; - env->DeleteGlobalRef(g_activity); - g_activity = nullptr; - - ReleaseClasses(env); - util::Terminate(env); -} - -const ::firebase::App* GetApp() { - FIREBASE_ASSERT(g_app); - return g_app; -} - -JNIEnv* GetJNI() { - if (g_app) { - return g_app->GetJNIEnv(); - } else { - FIREBASE_ASSERT(g_java_vm); - return firebase::util::GetThreadsafeJNIEnv(g_java_vm); - } -} - -jobject GetActivity() { return (g_app) ? g_app->activity() : g_activity; } - -static void CompleteAdFutureCallback(JNIEnv* env, jclass clazz, jlong data_ptr, - jint error_code, jstring error_message) { - if (data_ptr == 0) return; // test call only - - const char* error_msg = env->GetStringUTFChars(error_message, nullptr); - - firebase::gma::FutureCallbackData* callback_data = - reinterpret_cast*>(data_ptr); - - callback_data->future_data->future_impl.Complete( - callback_data->future_handle, static_cast(error_code), error_msg); - - env->ReleaseStringUTFChars(error_message, error_msg); - - // This method is responsible for disposing of the callback data struct. - delete callback_data; -} - -void CompleteLoadAdCallback(FutureCallbackData* callback_data, - jobject j_load_ad_error, AdErrorCode error_code, - const std::string& error_message) { - FIREBASE_ASSERT(callback_data); - - std::string future_error_message; - AdErrorInternal ad_error_internal; - - ad_error_internal.native_ad_error = j_load_ad_error; - ad_error_internal.ad_error_type = - AdErrorInternal::kAdErrorInternalLoadAdError; - ad_error_internal.is_successful = true; // assume until proven otherwise. - ad_error_internal.code = error_code; - - // Further result configuration is based on success/failure. - if (j_load_ad_error != nullptr) { - // The Android SDK returned an error. Use the native_ad_error object - // to populate a AdResult with the error specifics. - ad_error_internal.is_successful = false; - } else if (ad_error_internal.code != kAdErrorCodeNone) { - // C++ SDK Android GMA Wrapper encountered an error. - ad_error_internal.ad_error_type = - AdErrorInternal::kAdErrorInternalWrapperError; - ad_error_internal.is_successful = false; - ad_error_internal.message = error_message; - ad_error_internal.domain = "SDK"; - ad_error_internal.to_string = - std::string("Internal error: ") + ad_error_internal.message; - future_error_message = ad_error_internal.message; - } - - // Invoke a friend of AdResult to have it invoke the AdResult - // protected constructor with the AdErrorInternal data. - GmaInternal::CompleteLoadAdFutureFailure( - callback_data, ad_error_internal.code, future_error_message, - ad_error_internal); -} - -void CompleteLoadAdAndroidErrorResult(JNIEnv* env, jlong data_ptr, - jobject j_load_ad_error, - AdErrorCode error_code, - jstring j_error_message) { - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(data_ptr); - FIREBASE_ASSERT(j_error_message); - - FutureCallbackData* callback_data = - reinterpret_cast*>(data_ptr); - - std::string error_message = util::JStringToString(env, j_error_message); - - CompleteLoadAdCallback(callback_data, j_load_ad_error, error_code, - error_message); -} - -void CompleteLoadAdInternalResult(FutureCallbackData* callback_data, - AdErrorCode error_code, - const char* error_message) { - FIREBASE_ASSERT(callback_data); - FIREBASE_ASSERT(error_message); - - CompleteLoadAdCallback(callback_data, /*j_load_ad_error=*/nullptr, error_code, - error_message); -} - -AdValue::PrecisionType ConvertAndroidPrecisionTypeToCPPPrecisionType( - const jint j_precision_type) { - // Values taken from: - // https://firebase.google.com/docs/reference/android/com/google/android/gms/ads/AdValue.PrecisionType - switch (j_precision_type) { - default: - LogWarning("Could not convert AdValue precisionType: %l", - j_precision_type); - return AdValue::kAdValuePrecisionUnknown; - case 0: - return AdValue::kAdValuePrecisionUnknown; - case 1: // ESTIMATED - return AdValue::kAdValuePrecisionEstimated; - case 2: // PUBLISHER_PROVIDED - return AdValue::kAdValuePrecisionPublisherProvided; - case 3: // PRECISE - return AdValue::kAdValuePrecisionPrecise; - } -} - -static void JNICALL GmaInitializationHelper_initializationCompleteCallback( - JNIEnv* env, jclass clazz, jobject j_initialization_status) { - AdapterInitializationStatus adapter_status = - PopulateAdapterInitializationStatus(j_initialization_status); - { - MutexLock lock(g_future_impl_mutex); - // Check if g_future_impl still exists; if not, Terminate() was called, - // ignore the result of this callback. - if (g_future_impl && - g_initialization_handle.get() != - SafeFutureHandle::kInvalidHandle - .get()) { - g_future_impl->CompleteWithResult(g_initialization_handle, 0, "", - adapter_status); - g_initialization_handle = - SafeFutureHandle::kInvalidHandle; - } - } -} - -static void JNICALL AdInspectorHelper_adInspectorClosedCallback( - JNIEnv* env, jclass clazz, jlong native_callback_ptr, jobject j_ad_error) { - firebase::gma::AdInspectorClosedListener* listener = - reinterpret_cast( - native_callback_ptr); - - // A default-constructed AdResult represents a successful result. - AdResult ad_result; - if (j_ad_error != nullptr) { - AdErrorInternal ad_error_internal; - ad_error_internal.ad_error_type = - AdErrorInternal::kAdErrorInternalOpenAdInspectorError; - ad_error_internal.native_ad_error = j_ad_error; - ad_error_internal.is_successful = false; - ad_result = AdResult(GmaInternal::CreateAdError(ad_error_internal)); - } - listener->OnAdInspectorClosed(ad_result); -} - -namespace { - -// Common JNI methods -// -void JNI_completeAdFutureCallback(JNIEnv* env, jclass clazz, jlong data_ptr, - jint error_code, jstring error_message) { - CompleteAdFutureCallback(env, clazz, data_ptr, error_code, error_message); -} - -void JNI_completeLoadedAd(JNIEnv* env, jclass clazz, jlong data_ptr, - jobject j_response_info) { - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(data_ptr); - FIREBASE_ASSERT(j_response_info); - - FutureCallbackData* callback_data = - reinterpret_cast*>(data_ptr); - GmaInternal::CompleteLoadAdFutureSuccess( - callback_data, ResponseInfoInternal({j_response_info})); - env->DeleteLocalRef(j_response_info); -} - -void JNI_completeCreateQueryInfoSuccess(JNIEnv* env, jclass clazz, - jlong data_ptr, jstring j_query_info) { - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(data_ptr); - FIREBASE_ASSERT(j_query_info); - - std::string query_info = util::JStringToString(env, j_query_info); - FutureCallbackData* callback_data = - reinterpret_cast*>(data_ptr); - GmaInternal::CompleteCreateQueryInfoFutureSuccess(callback_data, query_info); - env->DeleteLocalRef(j_query_info); -} - -void JNI_completeQueryInfoError(JNIEnv* env, jclass clazz, jlong data_ptr, - jint j_error_code, jstring j_error_message) { - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(data_ptr); - FIREBASE_ASSERT(j_error_message); - - // QueryInfo errors return only internal AdErrorCode values. - const AdErrorCode error_code = static_cast(j_error_code); - std::string error_message = util::JStringToString(env, j_error_message); - - FutureCallbackData* callback_data = - reinterpret_cast*>(data_ptr); - GmaInternal::CompleteCreateQueryInfoFutureFailure(callback_data, error_code, - error_message); -} - -void JNI_NativeAd_completeLoadedAd(JNIEnv* env, jclass clazz, jlong data_ptr, - jlong native_internal_data_ptr, - jobject j_icon, jobjectArray j_images, - jobject j_adchoices_icon, - jobject j_response_info) { - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(data_ptr); - FIREBASE_ASSERT(native_internal_data_ptr); - FIREBASE_ASSERT(j_images); - FIREBASE_ASSERT(j_response_info); - - internal::NativeAdInternalAndroid* native_ad_internal = - reinterpret_cast( - native_internal_data_ptr); - - // getIcon() is nullable and a valid ad can exist without an icon image. - if (j_icon != nullptr) { - NativeAdImageInternal icon_internal; - icon_internal.native_ad_image = j_icon; - - // Invoke a friend of NativeAdInternal to update its icon image asset. - GmaInternal::InsertNativeInternalImage(native_ad_internal, icon_internal, - "icon", true); - env->DeleteLocalRef(j_icon); - } - - // getAdChoicesInfo().getImages() can return an empty list and a valid ad can - // exist without an adchoices icon image. - if (j_adchoices_icon != nullptr) { - NativeAdImageInternal adchoices_icon_internal; - adchoices_icon_internal.native_ad_image = j_adchoices_icon; - - // Invoke a friend of NativeAdInternal to update its icon image asset. - GmaInternal::InsertNativeInternalImage( - native_ad_internal, adchoices_icon_internal, "adchoices_icon", true); - env->DeleteLocalRef(j_adchoices_icon); - } - - const size_t len = env->GetArrayLength(j_images); - // Loop through images array. - for (size_t i = 0; i < len; ++i) { - jobject j_image = env->GetObjectArrayElement(j_images, i); - NativeAdImageInternal image_internal; - image_internal.native_ad_image = j_image; - GmaInternal::InsertNativeInternalImage(native_ad_internal, image_internal, - "image", false); - } - - FutureCallbackData* callback_data = - reinterpret_cast*>(data_ptr); - GmaInternal::CompleteLoadAdFutureSuccess( - callback_data, ResponseInfoInternal({j_response_info})); - - env->DeleteLocalRef(j_response_info); -} - -void JNI_NativeAd_notifyAdClicked(JNIEnv* env, jclass clazz, jlong data_ptr) { - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(data_ptr); - - firebase::gma::internal::NativeAdInternal* internal = - reinterpret_cast(data_ptr); - internal->NotifyListenerAdClicked(); -} - -void JNI_NativeAd_notifyAdClosed(JNIEnv* env, jclass clazz, jlong data_ptr) { - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(data_ptr); - - firebase::gma::internal::NativeAdInternal* internal = - reinterpret_cast(data_ptr); - internal->NotifyListenerAdClosed(); -} - -void JNI_NativeAd_notifyAdImpression(JNIEnv* env, jclass clazz, - jlong data_ptr) { - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(data_ptr); - - firebase::gma::internal::NativeAdInternal* internal = - reinterpret_cast(data_ptr); - internal->NotifyListenerAdImpression(); -} - -void JNI_NativeAd_notifyAdOpened(JNIEnv* env, jclass clazz, jlong data_ptr) { - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(data_ptr); - - firebase::gma::internal::NativeAdInternal* internal = - reinterpret_cast(data_ptr); - internal->NotifyListenerAdOpened(); -} - -void JNI_NativeImage_completeLoadedImage(JNIEnv* env, jclass clazz, - jlong data_ptr, - jobject j_image_bytes) { - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(data_ptr); - FIREBASE_ASSERT(j_image_bytes); - - std::vector img_data = - util::JniByteArrayToVector(env, j_image_bytes); - - FutureCallbackData* callback_data = - reinterpret_cast*>(data_ptr); - GmaInternal::CompleteLoadImageFutureSuccess(callback_data, img_data); -} - -void JNI_completeLoadImageError(JNIEnv* env, jclass clazz, jlong data_ptr, - jint j_error_code, jstring j_error_message) { - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(data_ptr); - FIREBASE_ASSERT(j_error_message); - - std::string error_message = util::JStringToString(env, j_error_message); - const AdErrorCode error_code = - MapAndroidAdRequestErrorCodeToCPPErrorCode(j_error_code); - - FutureCallbackData* callback_data = - reinterpret_cast*>(data_ptr); - GmaInternal::CompleteLoadImageFutureFailure(callback_data, error_code, - error_message); -} - -void JNI_completeLoadAdError(JNIEnv* env, jclass clazz, jlong data_ptr, - jobject j_load_ad_error, jint j_error_code, - jstring j_error_message) { - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(data_ptr); - FIREBASE_ASSERT(j_error_message); - const AdErrorCode error_code = - MapAndroidAdRequestErrorCodeToCPPErrorCode(j_error_code); - CompleteLoadAdAndroidErrorResult(env, data_ptr, j_load_ad_error, error_code, - j_error_message); -} - -// Internal Errors use AdError codes. -void JNI_completeLoadAdInternalError(JNIEnv* env, jclass clazz, jlong data_ptr, - jint j_error_code, - jstring j_error_message) { - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(data_ptr); - FIREBASE_ASSERT(j_error_message); - const AdErrorCode error_code = static_cast(j_error_code); - CompleteLoadAdAndroidErrorResult(env, data_ptr, /*j_load_ad_error=*/nullptr, - error_code, j_error_message); -} - -void JNI_notifyAdClickedFullScreenContentEvent(JNIEnv* env, jclass clazz, - jlong data_ptr) { - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(data_ptr); - internal::FullScreenAdEventListener* listener = - reinterpret_cast(data_ptr); - listener->NotifyListenerOfAdClickedFullScreenContent(); -} - -void JNI_notifyAdDismissedFullScreenContentEvent(JNIEnv* env, jclass clazz, - jlong data_ptr) { - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(data_ptr); - internal::FullScreenAdEventListener* listener = - reinterpret_cast(data_ptr); - listener->NotifyListenerOfAdDismissedFullScreenContent(); -} - -void JNI_notifyAdFailedToShowFullScreenContentEvent(JNIEnv* env, jclass clazz, - jlong data_ptr, - jobject j_ad_error) { - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(data_ptr); - FIREBASE_ASSERT(j_ad_error); - internal::FullScreenAdEventListener* listener = - reinterpret_cast(data_ptr); - AdErrorInternal ad_error_internal; - ad_error_internal.ad_error_type = - AdErrorInternal::kAdErrorInternalFullScreenContentError; - ad_error_internal.native_ad_error = j_ad_error; - - // Invoke GmaInternal, a friend of AdResult, to have it access its - // protected constructor with the AdErrorCode data. - const AdError& ad_result = GmaInternal::CreateAdError(ad_error_internal); - listener->NotifyListenerOfAdFailedToShowFullScreenContent(ad_result); -} - -void JNI_notifyAdImpressionEvent(JNIEnv* env, jclass clazz, jlong data_ptr) { - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(data_ptr); - internal::FullScreenAdEventListener* listener = - reinterpret_cast(data_ptr); - listener->NotifyListenerOfAdImpression(); -} - -void JNI_notifyAdShowedFullScreenContentEvent(JNIEnv* env, jclass clazz, - jlong data_ptr) { - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(data_ptr); - internal::FullScreenAdEventListener* listener = - reinterpret_cast(data_ptr); - listener->NotifyListenerOfAdShowedFullScreenContent(); -} - -void JNI_notifyAdPaidEvent(JNIEnv* env, jclass clazz, jlong data_ptr, - jstring j_currency_code, jint j_precision_type, - jlong j_value_micros) { - FIREBASE_ASSERT(data_ptr); - internal::FullScreenAdEventListener* listener = - reinterpret_cast(data_ptr); - - const char* currency_code = env->GetStringUTFChars(j_currency_code, nullptr); - const AdValue::PrecisionType precision_type = - ConvertAndroidPrecisionTypeToCPPPrecisionType(j_precision_type); - AdValue ad_value(currency_code, precision_type, (int64_t)j_value_micros); - listener->NotifyListenerOfPaidEvent(ad_value); -} - -// JNI functions specific to AdViews -// -void JNI_AdViewHelper_completeLoadedAd(JNIEnv* env, jclass clazz, - jlong callback_data_ptr, - jlong ad_view_internal_data_ptr, - int width, int height, - jobject j_response_info) { - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(callback_data_ptr); - FIREBASE_ASSERT(ad_view_internal_data_ptr); - FIREBASE_ASSERT(j_response_info); - - internal::AdViewInternalAndroid* ad_view_internal = - reinterpret_cast( - ad_view_internal_data_ptr); - - // Invoke a friend of AdViewInternal to update its AdSize's width and height. - GmaInternal::UpdateAdViewInternalAdSizeDimensions(ad_view_internal, width, - height); - // Complete the Future. - FutureCallbackData* callback_data = - reinterpret_cast*>(callback_data_ptr); - GmaInternal::CompleteLoadAdFutureSuccess( - callback_data, ResponseInfoInternal({j_response_info})); - env->DeleteLocalRef(j_response_info); -} - -void JNI_AdViewHelper_notifyBoundingBoxChanged(JNIEnv* env, jclass clazz, - jlong data_ptr) { - firebase::gma::internal::AdViewInternal* internal = - reinterpret_cast(data_ptr); - internal->NotifyListenerOfBoundingBoxChange(internal->bounding_box()); -} - -void JNI_AdViewHelper_notifyAdClicked(JNIEnv* env, jclass clazz, - jlong data_ptr) { - firebase::gma::internal::AdViewInternal* internal = - reinterpret_cast(data_ptr); - internal->NotifyListenerAdClicked(); -} - -void JNI_AdViewHelper_notifyAdClosed(JNIEnv* env, jclass clazz, - jlong data_ptr) { - firebase::gma::internal::AdViewInternal* internal = - reinterpret_cast(data_ptr); - internal->NotifyListenerAdClosed(); -} - -void JNI_AdViewHelper_notifyAdImpression(JNIEnv* env, jclass clazz, - jlong data_ptr) { - firebase::gma::internal::AdViewInternal* internal = - reinterpret_cast(data_ptr); - internal->NotifyListenerAdImpression(); -} - -void JNI_AdViewHelper_notifyAdOpened(JNIEnv* env, jclass clazz, - jlong data_ptr) { - firebase::gma::internal::AdViewInternal* internal = - reinterpret_cast(data_ptr); - internal->NotifyListenerAdOpened(); -} - -void JNI_AdViewHelper_notifyAdPaidEvent(JNIEnv* env, jclass clazz, - jlong data_ptr, jstring j_currency_code, - jint j_precision_type, - jlong j_value_micros) { - FIREBASE_ASSERT(data_ptr); - internal::AdViewInternal* internal = - reinterpret_cast(data_ptr); - - const char* currency_code = env->GetStringUTFChars(j_currency_code, nullptr); - const AdValue::PrecisionType precision_type = - ConvertAndroidPrecisionTypeToCPPPrecisionType(j_precision_type); - AdValue ad_value(currency_code, precision_type, (int64_t)j_value_micros); - internal->NotifyListenerOfPaidEvent(ad_value); -} - -void JNI_AdViewHelper_releaseGlobalReference(JNIEnv* env, jclass clazz, - jlong data_ptr) { - FIREBASE_ASSERT(data_ptr); - jobject ad_view = reinterpret_cast(data_ptr); - env->DeleteGlobalRef(ad_view); -} - -// JNI functions specific to RewardedAds -// -void JNI_RewardedAd_UserEarnedReward(JNIEnv* env, jclass clazz, jlong data_ptr, - jstring reward_type, jint amount) { - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(data_ptr); - internal::RewardedAdInternal* internal = - reinterpret_cast(data_ptr); - internal->NotifyListenerOfUserEarnedReward( - util::JStringToString(env, reward_type), (int64_t)amount); -} - -} // namespace - -bool RegisterNatives() { - static const JNINativeMethod kAdViewMethods[] = { - {"completeAdViewFutureCallback", "(JILjava/lang/String;)V", - reinterpret_cast(&JNI_completeAdFutureCallback)}, - {"completeAdViewLoadedAd", - "(JJIILcom/google/android/gms/ads/ResponseInfo;)V", - reinterpret_cast(&JNI_AdViewHelper_completeLoadedAd)}, - {"completeAdViewLoadAdError", - "(JLcom/google/android/gms/ads/LoadAdError;ILjava/lang/String;)V", - reinterpret_cast(&JNI_completeLoadAdError)}, - {"completeAdViewLoadAdInternalError", "(JILjava/lang/String;)V", - reinterpret_cast(&JNI_completeLoadAdInternalError)}, - {"notifyBoundingBoxChanged", "(J)V", - reinterpret_cast(&JNI_AdViewHelper_notifyBoundingBoxChanged)}, - {"notifyAdClicked", "(J)V", - reinterpret_cast(&JNI_AdViewHelper_notifyAdClicked)}, - {"notifyAdClosed", "(J)V", - reinterpret_cast(&JNI_AdViewHelper_notifyAdClosed)}, - {"notifyAdImpression", "(J)V", - reinterpret_cast(&JNI_AdViewHelper_notifyAdImpression)}, - {"notifyAdOpened", "(J)V", - reinterpret_cast(&JNI_AdViewHelper_notifyAdOpened)}, - {"notifyPaidEvent", "(JLjava/lang/String;IJ)V", - reinterpret_cast(&JNI_AdViewHelper_notifyAdPaidEvent)}, - {"releaseAdViewGlobalReferenceCallback", "(J)V", - reinterpret_cast(&JNI_AdViewHelper_releaseGlobalReference)}}; - static const JNINativeMethod kInterstitialMethods[] = { - {"completeInterstitialAdFutureCallback", "(JILjava/lang/String;)V", - reinterpret_cast(&JNI_completeAdFutureCallback)}, - {"completeInterstitialLoadedAd", - "(JLcom/google/android/gms/ads/ResponseInfo;)V", - reinterpret_cast(&JNI_completeLoadedAd)}, - {"completeInterstitialLoadAdError", - "(JLcom/google/android/gms/ads/LoadAdError;ILjava/lang/String;)V", - reinterpret_cast(&JNI_completeLoadAdError)}, - {"completeInterstitialLoadAdInternalError", "(JILjava/lang/String;)V", - reinterpret_cast(&JNI_completeLoadAdInternalError)}, - {"notifyAdClickedFullScreenContentEvent", "(J)V", - reinterpret_cast(&JNI_notifyAdClickedFullScreenContentEvent)}, - {"notifyAdDismissedFullScreenContentEvent", "(J)V", - reinterpret_cast(&JNI_notifyAdDismissedFullScreenContentEvent)}, - {"notifyAdFailedToShowFullScreenContentEvent", - "(JLcom/google/android/gms/ads/AdError;)V", - reinterpret_cast( - &JNI_notifyAdFailedToShowFullScreenContentEvent)}, - {"notifyAdImpressionEvent", "(J)V", - reinterpret_cast(&JNI_notifyAdImpressionEvent)}, - {"notifyAdShowedFullScreenContentEvent", "(J)V", - reinterpret_cast(&JNI_notifyAdShowedFullScreenContentEvent)}, - {"notifyPaidEvent", "(JLjava/lang/String;IJ)V", - reinterpret_cast(&JNI_notifyAdPaidEvent)}, - }; - - static const JNINativeMethod kNativeAdMethods[] = { - {"completeNativeAdFutureCallback", "(JILjava/lang/String;)V", - reinterpret_cast(&JNI_completeAdFutureCallback)}, - {"completeNativeLoadedAd", - "(JJLcom/google/android/gms/ads/nativead/NativeAd$Image;[Lcom/google/" - "android/gms/ads/nativead/NativeAd$Image;Lcom/google/android/gms/ads/" - "nativead/NativeAd$Image;Lcom/google/android/gms/ads/ResponseInfo;)V", - reinterpret_cast(&JNI_NativeAd_completeLoadedAd)}, - {"completeNativeLoadAdError", - "(JLcom/google/android/gms/ads/LoadAdError;ILjava/lang/String;)V", - reinterpret_cast(&JNI_completeLoadAdError)}, - {"completeNativeLoadAdInternalError", "(JILjava/lang/String;)V", - reinterpret_cast(&JNI_completeLoadAdInternalError)}, - {"notifyAdClicked", "(J)V", - reinterpret_cast(&JNI_NativeAd_notifyAdClicked)}, - {"notifyAdClosed", "(J)V", - reinterpret_cast(&JNI_NativeAd_notifyAdClosed)}, - {"notifyAdImpression", "(J)V", - reinterpret_cast(&JNI_NativeAd_notifyAdImpression)}, - {"notifyAdOpened", "(J)V", - reinterpret_cast(&JNI_NativeAd_notifyAdOpened)}, - }; - - static const JNINativeMethod kQueryInfoMethods[] = { - {"completeQueryInfoFutureCallback", "(JILjava/lang/String;)V", - reinterpret_cast(&JNI_completeAdFutureCallback)}, - {"completeCreateQueryInfoSuccess", "(JLjava/lang/String;)V", - reinterpret_cast(&JNI_completeCreateQueryInfoSuccess)}, - {"completeCreateQueryInfoError", "(JILjava/lang/String;)V", - reinterpret_cast(&JNI_completeQueryInfoError)}, - }; - - static const JNINativeMethod kNativeImageMethods[] = { - {"completeNativeImageFutureCallback", "(JILjava/lang/String;)V", - reinterpret_cast(&JNI_completeAdFutureCallback)}, - {"completeNativeLoadedImage", "(J[B)V", - reinterpret_cast(&JNI_NativeImage_completeLoadedImage)}, - {"completeNativeLoadImageError", "(JILjava/lang/String;)V", - reinterpret_cast(&JNI_completeLoadImageError)}, - }; - - static const JNINativeMethod kRewardedAdMethods[] = { - {"completeRewardedAdFutureCallback", "(JILjava/lang/String;)V", - reinterpret_cast(&JNI_completeAdFutureCallback)}, - {"completeRewardedLoadedAd", - "(JLcom/google/android/gms/ads/ResponseInfo;)V", - reinterpret_cast(&JNI_completeLoadedAd)}, - {"completeRewardedLoadAdError", - "(JLcom/google/android/gms/ads/LoadAdError;ILjava/lang/String;)V", - reinterpret_cast(&JNI_completeLoadAdError)}, - {"completeRewardedLoadAdInternalError", "(JILjava/lang/String;)V", - reinterpret_cast(&JNI_completeLoadAdInternalError)}, - {"notifyUserEarnedRewardEvent", "(JLjava/lang/String;I)V", - reinterpret_cast(&JNI_RewardedAd_UserEarnedReward)}, - {"notifyAdClickedFullScreenContentEvent", "(J)V", - reinterpret_cast(&JNI_notifyAdClickedFullScreenContentEvent)}, - {"notifyAdDismissedFullScreenContentEvent", "(J)V", - reinterpret_cast(&JNI_notifyAdDismissedFullScreenContentEvent)}, - {"notifyAdFailedToShowFullScreenContentEvent", - "(JLcom/google/android/gms/ads/AdError;)V", - reinterpret_cast( - &JNI_notifyAdFailedToShowFullScreenContentEvent)}, - {"notifyAdImpressionEvent", "(J)V", - reinterpret_cast(&JNI_notifyAdImpressionEvent)}, - {"notifyAdShowedFullScreenContentEvent", "(J)V", - reinterpret_cast(&JNI_notifyAdShowedFullScreenContentEvent)}, - {"notifyPaidEvent", "(JLjava/lang/String;IJ)V", - reinterpret_cast(&JNI_notifyAdPaidEvent)}, - }; - static const JNINativeMethod kGmaInitializationMethods[] = { - {"initializationCompleteCallback", - "(Lcom/google/android/gms/ads/initialization/InitializationStatus;)V", - reinterpret_cast( - &GmaInitializationHelper_initializationCompleteCallback)} // NOLINT - }; - static const JNINativeMethod kAdInspectorHelperMethods[] = { - {"adInspectorClosedCallback", "(JLcom/google/android/gms/ads/AdError;)V", - reinterpret_cast( - &AdInspectorHelper_adInspectorClosedCallback)} // NOLINT - }; - - JNIEnv* env = GetJNI(); - return ad_inspector_helper::RegisterNatives( - env, kAdInspectorHelperMethods, - FIREBASE_ARRAYSIZE(kAdInspectorHelperMethods)) && - ad_view_helper::RegisterNatives(env, kAdViewMethods, - FIREBASE_ARRAYSIZE(kAdViewMethods)) && - interstitial_ad_helper::RegisterNatives( - env, kInterstitialMethods, - FIREBASE_ARRAYSIZE(kInterstitialMethods)) && - native_ad_helper::RegisterNatives( - env, kNativeAdMethods, FIREBASE_ARRAYSIZE(kNativeAdMethods)) && - download_helper::RegisterNatives( - env, kNativeImageMethods, - FIREBASE_ARRAYSIZE(kNativeImageMethods)) && - query_info_helper::RegisterNatives( - env, kQueryInfoMethods, FIREBASE_ARRAYSIZE(kQueryInfoMethods)) && - rewarded_ad_helper::RegisterNatives( - env, kRewardedAdMethods, FIREBASE_ARRAYSIZE(kRewardedAdMethods)) && - gma_initialization_helper::RegisterNatives( - env, kGmaInitializationMethods, - FIREBASE_ARRAYSIZE(kGmaInitializationMethods)); -} - -jobject CreateJavaAdSize(JNIEnv* env, jobject j_activity, - const AdSize& adsize) { - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(j_activity); - - jobject j_ad_size = nullptr; - switch (adsize.type()) { - case AdSize::kTypeAnchoredAdaptive: - switch (adsize.orientation()) { - case AdSize::kOrientationLandscape: - j_ad_size = env->CallStaticObjectMethod( - ad_size::GetClass(), - ad_size::GetMethodId( - ad_size::kGetLandscapeAnchoredAdaptiveBannerAdSize), - j_activity, adsize.width()); - break; - case AdSize::kOrientationPortrait: - j_ad_size = env->CallStaticObjectMethod( - ad_size::GetClass(), - ad_size::GetMethodId( - ad_size::kGetPortraitAnchoredAdaptiveBannerAdSize), - j_activity, adsize.width()); - break; - case AdSize::kOrientationCurrent: - j_ad_size = env->CallStaticObjectMethod( - ad_size::GetClass(), - ad_size::GetMethodId( - ad_size::kGetCurrentOrientationAnchoredAdaptiveBannerAdSize), - j_activity, adsize.width()); - break; - default: - FIREBASE_ASSERT_MESSAGE(true, - "Unknown Anchor Adaptive AdSize Orientation"); - } - break; - case AdSize::kTypeInlineAdaptive: - if (adsize.height() != 0) { - j_ad_size = env->CallStaticObjectMethod( - ad_size::GetClass(), - ad_size::GetMethodId(ad_size::kGetInlineAdaptiveBannerAdSize), - adsize.width(), adsize.height()); - } else { - switch (adsize.orientation()) { - case AdSize::kOrientationLandscape: - j_ad_size = env->CallStaticObjectMethod( - ad_size::GetClass(), - ad_size::GetMethodId( - ad_size::kGetLandscapeInlineAdaptiveBannerAdSize), - j_activity, adsize.width()); - break; - case AdSize::kOrientationPortrait: - j_ad_size = env->CallStaticObjectMethod( - ad_size::GetClass(), - ad_size::GetMethodId( - ad_size::kGetPortraitInlineAdaptiveBannerAdSize), - j_activity, adsize.width()); - break; - case AdSize::kOrientationCurrent: - j_ad_size = env->CallStaticObjectMethod( - ad_size::GetClass(), - ad_size::GetMethodId( - ad_size::kGetCurrentOrientationInlineAdaptiveBannerAdSize), - j_activity, adsize.width()); - break; - default: - FIREBASE_ASSERT_MESSAGE( - true, "Unknown Inline Adaptive AdSize Orientation"); - } - } - break; - case AdSize::kTypeStandard: - j_ad_size = env->NewObject(ad_size::GetClass(), - ad_size::GetMethodId(ad_size::kConstructor), - adsize.width(), adsize.height()); - break; - default: - FIREBASE_ASSERT_MESSAGE(true, "Unknown AdSize Type"); - } - bool jni_exception = util::CheckAndClearJniExceptions(env); - FIREBASE_ASSERT(!jni_exception); - FIREBASE_ASSERT(j_ad_size); - return j_ad_size; -} - -} // namespace gma -} // namespace firebase diff --git a/gma/src/android/gma_android.h b/gma/src/android/gma_android.h deleted file mode 100644 index 20e9357eab..0000000000 --- a/gma/src/android/gma_android.h +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_ANDROID_GMA_ANDROID_H_ -#define FIREBASE_GMA_SRC_ANDROID_GMA_ANDROID_H_ - -#include - -#include - -#include "app/src/embedded_file.h" -#include "app/src/util_android.h" -#include "firebase/internal/mutex.h" -#include "gma/src/common/gma_common.h" - -namespace firebase { -namespace gma { - -// Used to setup the cache of class method IDs to reduce -// time spent looking up methods by string. -// clang-format off -#define AD_INSPECTOR_HELPER_METHODS(X) \ - X(Constructor, "", "(J)V") -// clang-format on - -// clang-format off -#define ADREQUESTBUILDER_METHODS(X) \ - X(Constructor, "", "()V"), \ - X(Build, "build", "()Lcom/google/android/gms/ads/AdRequest;"), \ - X(AddKeyword, "addKeyword", \ - "(Ljava/lang/String;)" \ - "Lcom/google/android/gms/ads/AbstractAdRequestBuilder;"), \ - X(AddNetworkExtrasBundle, "addNetworkExtrasBundle", \ - "(Ljava/lang/Class;Landroid/os/Bundle;)" \ - "Lcom/google/android/gms/ads/AbstractAdRequestBuilder;"), \ - X(SetContentUrl, "setContentUrl", \ - "(Ljava/lang/String;)" \ - "Lcom/google/android/gms/ads/AbstractAdRequestBuilder;"), \ - X(SetNeighboringContentUrls, "setNeighboringContentUrls", \ - "(Ljava/util/List;)" \ - "Lcom/google/android/gms/ads/AbstractAdRequestBuilder;"), \ - X(SetRequestAgent, "setRequestAgent", \ - "(Ljava/lang/String;)" \ - "Lcom/google/android/gms/ads/AbstractAdRequestBuilder;") -// clang-format on - -// clang-format off -#define ADSIZE_METHODS(X) \ - X(Constructor, "", "(II)V"), \ - X(GetCurrentOrientationAnchoredAdaptiveBannerAdSize, \ - "getCurrentOrientationAnchoredAdaptiveBannerAdSize", \ - "(Landroid/content/Context;I)Lcom/google/android/gms/ads/AdSize;", \ - util::kMethodTypeStatic), \ - X(GetLandscapeAnchoredAdaptiveBannerAdSize, \ - "getLandscapeAnchoredAdaptiveBannerAdSize", \ - "(Landroid/content/Context;I)Lcom/google/android/gms/ads/AdSize;", \ - util::kMethodTypeStatic), \ - X(GetPortraitAnchoredAdaptiveBannerAdSize, \ - "getPortraitAnchoredAdaptiveBannerAdSize", \ - "(Landroid/content/Context;I)Lcom/google/android/gms/ads/AdSize;", \ - util::kMethodTypeStatic), \ - X(GetInlineAdaptiveBannerAdSize, \ - "getInlineAdaptiveBannerAdSize", \ - "(II)Lcom/google/android/gms/ads/AdSize;", \ - util::kMethodTypeStatic), \ - X(GetCurrentOrientationInlineAdaptiveBannerAdSize, \ - "getCurrentOrientationInlineAdaptiveBannerAdSize", \ - "(Landroid/content/Context;I)Lcom/google/android/gms/ads/AdSize;", \ - util::kMethodTypeStatic), \ - X(GetLandscapeInlineAdaptiveBannerAdSize, \ - "getLandscapeInlineAdaptiveBannerAdSize", \ - "(Landroid/content/Context;I)Lcom/google/android/gms/ads/AdSize;", \ - util::kMethodTypeStatic), \ - X(GetPortraitInlineAdaptiveBannerAdSize, \ - "getPortraitInlineAdaptiveBannerAdSize", \ - "(Landroid/content/Context;I)Lcom/google/android/gms/ads/AdSize;", \ - util::kMethodTypeStatic) -// clang-format on - -// clang-format off -#define MOBILEADS_METHODS(X) \ - X(Initialize, "initialize", \ - "(Landroid/content/Context;)V", util::kMethodTypeStatic), \ - X(OpenAdInspector, "openAdInspector", \ - "(Landroid/content/Context;" \ - "Lcom/google/android/gms/ads/OnAdInspectorClosedListener;)V", \ - util::kMethodTypeStatic), \ - X(SetRequestConfiguration, "setRequestConfiguration", \ - "(Lcom/google/android/gms/ads/RequestConfiguration;)V", \ - util::kMethodTypeStatic), \ - X(GetRequestConfiguration, "getRequestConfiguration", \ - "()Lcom/google/android/gms/ads/RequestConfiguration;", \ - util::kMethodTypeStatic), \ - X(GetInitializationStatus, "getInitializationStatus", \ - "()Lcom/google/android/gms/ads/initialization/InitializationStatus;", \ - util::kMethodTypeStatic) -// clang-format on - -// clang-format off -#define REQUESTCONFIGURATIONBUILDER_METHODS(X) \ - X(Constructor, "", "()V"), \ - X(Build, "build", \ - "()Lcom/google/android/gms/ads/RequestConfiguration;"), \ - X(SetMaxAdContentRating, "setMaxAdContentRating", \ - "(Ljava/lang/String;)" \ - "Lcom/google/android/gms/ads/RequestConfiguration$Builder;"), \ - X(SetTagForChildDirectedTreatment, "setTagForChildDirectedTreatment", \ - "(I)Lcom/google/android/gms/ads/RequestConfiguration$Builder;"), \ - X(SetTagForUnderAgeOfConsent, "setTagForUnderAgeOfConsent", \ - "(I)Lcom/google/android/gms/ads/RequestConfiguration$Builder;"), \ - X(SetTestDeviceIds, "setTestDeviceIds", \ - "(Ljava/util/List;)" \ - "Lcom/google/android/gms/ads/RequestConfiguration$Builder;") -// clang-format on - -// clang-format off -#define REQUESTCONFIGURATION_METHODS(X) \ - X(GetMaxAdContentRating , "getMaxAdContentRating", \ - "()Ljava/lang/String;"), \ - X(GetTagForChildDirectedTreatment , "getTagForChildDirectedTreatment", \ - "()I"), \ - X(GetTagForUnderAgeOfConsent , "getTagForUnderAgeOfConsent", "()I"), \ - X(GetTestDeviceIds , "getTestDeviceIds", "()Ljava/util/List;") - - -// clang-format off -#define INITIALIZATION_STATUS_METHODS(X) \ - X(GetAdapterStatusMap, "getAdapterStatusMap", "()Ljava/util/Map;") -// clang-format on - -// clang-format off -#define ADAPTER_STATUS_METHODS(X) \ - X(GetDescription, "getDescription", "()Ljava/lang/String;"), \ - X(GetLatency, "getLatency", "()I"), \ - X(GetInitializationState, "getInitializationState", \ - "()Lcom/google/android/gms/ads/initialization/AdapterStatus$State;") -// clang-format on - -// clang-format off -#define ADAPTER_STATUS_STATE_FIELDS(X) \ - X(NotReady, "NOT_READY", \ - "Lcom/google/android/gms/ads/initialization/AdapterStatus$State;", \ - util::kFieldTypeStatic), \ - X(Ready, "READY", \ - "Lcom/google/android/gms/ads/initialization/AdapterStatus$State;", \ - util::kFieldTypeStatic) -// clang-format on - -// clang-format off -#define GMA_INITIALIZATION_HELPER_METHODS(X) \ - X(InitializeGma, "initializeGma", "(Landroid/content/Context;)V", \ - util::kMethodTypeStatic) -// clang-format on - -METHOD_LOOKUP_DECLARATION(ad_request_builder, ADREQUESTBUILDER_METHODS); -METHOD_LOOKUP_DECLARATION(mobile_ads, MOBILEADS_METHODS); -METHOD_LOOKUP_DECLARATION(request_config, REQUESTCONFIGURATION_METHODS); -METHOD_LOOKUP_DECLARATION(request_config_builder, - REQUESTCONFIGURATIONBUILDER_METHODS); -METHOD_LOOKUP_DECLARATION(ad_size, ADSIZE_METHODS); -METHOD_LOOKUP_DECLARATION(initialization_status, INITIALIZATION_STATUS_METHODS); -METHOD_LOOKUP_DECLARATION(adapter_status, ADAPTER_STATUS_METHODS); -METHOD_LOOKUP_DECLARATION(adapter_status_state, METHOD_LOOKUP_NONE, - ADAPTER_STATUS_STATE_FIELDS); - -METHOD_LOOKUP_DECLARATION(ad_inspector_helper, AD_INSPECTOR_HELPER_METHODS); -METHOD_LOOKUP_DECLARATION(gma_initialization_helper, - GMA_INITIALIZATION_HELPER_METHODS); - -// Needed when GMA is initialized without Firebase. -JNIEnv* GetJNI(); - -// Retrieves the activity used to initialize GMA. -jobject GetActivity(); - -// Register the native callbacks needed by the Futures. -bool RegisterNatives(); - -// Release classes registered by this module. -void ReleaseClasses(JNIEnv* env); - -// Constructs a com.google.android.gms.ads.AdSize object from a C++ AdSize -// counterpart. -jobject CreateJavaAdSize(JNIEnv* env, jobject activity, - const AdSize& an_ad_size); - -namespace internal { -// GMA and UMP share embedded dex files; this ensures -// that they are only loaded once each run. -extern ::firebase::Mutex g_cached_gma_embedded_files_mutex; -extern std::vector<::firebase::internal::EmbeddedFile>* - g_cached_gma_embedded_files; -} // namespace internal - -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_ANDROID_GMA_ANDROID_H_ diff --git a/gma/src/android/interstitial_ad_internal_android.cc b/gma/src/android/interstitial_ad_internal_android.cc deleted file mode 100644 index 295d96a5cd..0000000000 --- a/gma/src/android/interstitial_ad_internal_android.cc +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/android/interstitial_ad_internal_android.h" - -#include -#include - -#include -#include - -#include "app/src/assert.h" -#include "app/src/util_android.h" -#include "gma/src/android/ad_request_converter.h" -#include "gma/src/android/gma_android.h" -#include "gma/src/common/gma_common.h" -#include "gma/src/include/firebase/gma.h" -#include "gma/src/include/firebase/gma/interstitial_ad.h" -#include "gma/src/include/firebase/gma/types.h" - -namespace firebase { -namespace gma { - -METHOD_LOOKUP_DEFINITION( - interstitial_ad_helper, - "com/google/firebase/gma/internal/cpp/InterstitialAdHelper", - INTERSTITIALADHELPER_METHODS); - -namespace internal { - -InterstitialAdInternalAndroid::InterstitialAdInternalAndroid( - InterstitialAd* base) - : InterstitialAdInternal(base), helper_(nullptr), initialized_(false) { - firebase::MutexLock lock(mutex_); - JNIEnv* env = ::firebase::gma::GetJNI(); - jobject helper_ref = env->NewObject( - interstitial_ad_helper::GetClass(), - interstitial_ad_helper::GetMethodId(interstitial_ad_helper::kConstructor), - reinterpret_cast(this)); - - FIREBASE_ASSERT(helper_ref); - helper_ = env->NewGlobalRef(helper_ref); - FIREBASE_ASSERT(helper_); - env->DeleteLocalRef(helper_ref); -} - -InterstitialAdInternalAndroid::~InterstitialAdInternalAndroid() { - firebase::MutexLock lock(mutex_); - JNIEnv* env = ::firebase::gma::GetJNI(); - // Since it's currently not possible to destroy the intersitial ad, just - // disconnect from it so the listener doesn't initiate callbacks with stale - // data. - env->CallVoidMethod(helper_, interstitial_ad_helper::GetMethodId( - interstitial_ad_helper::kDisconnect)); - env->DeleteGlobalRef(helper_); - helper_ = nullptr; -} - -Future InterstitialAdInternalAndroid::Initialize(AdParent parent) { - firebase::MutexLock lock(mutex_); - - if (initialized_) { - const SafeFutureHandle future_handle = - future_data_.future_impl.SafeAlloc(kInterstitialAdFnInitialize); - Future future = MakeFuture(&future_data_.future_impl, future_handle); - CompleteFuture(kAdErrorCodeAlreadyInitialized, - kAdAlreadyInitializedErrorMessage, future_handle, - &future_data_); - return future; - } - - initialized_ = true; - JNIEnv* env = ::firebase::gma::GetJNI(); - FIREBASE_ASSERT(env); - - FutureCallbackData* callback_data = - CreateVoidFutureCallbackData(kInterstitialAdFnInitialize, &future_data_); - Future future = - MakeFuture(&future_data_.future_impl, callback_data->future_handle); - env->CallVoidMethod( - helper_, - interstitial_ad_helper::GetMethodId(interstitial_ad_helper::kInitialize), - reinterpret_cast(callback_data), parent); - return future; -} - -Future InterstitialAdInternalAndroid::LoadAd( - const char* ad_unit_id, const AdRequest& request) { - firebase::MutexLock lock(mutex_); - - if (!initialized_) { - SafeFutureHandle future_handle = - CreateFuture(kInterstitialAdFnLoadAd, &future_data_); - Future future = - MakeFuture(&future_data_.future_impl, future_handle); - CompleteFuture(kAdErrorCodeUninitialized, kAdUninitializedErrorMessage, - future_handle, &future_data_, AdResult()); - return future; - } - - gma::AdErrorCode error = kAdErrorCodeNone; - jobject j_request = GetJavaAdRequestFromCPPAdRequest(request, &error); - if (j_request == nullptr) { - if (error == kAdErrorCodeNone) { - error = kAdErrorCodeInternalError; - } - return CreateAndCompleteFutureWithResult( - kInterstitialAdFnLoadAd, error, kAdCouldNotParseAdRequestErrorMessage, - &future_data_, AdResult()); - } - JNIEnv* env = GetJNI(); - FIREBASE_ASSERT(env); - FutureCallbackData* callback_data = - CreateAdResultFutureCallbackData(kInterstitialAdFnLoadAd, &future_data_); - Future future = - MakeFuture(&future_data_.future_impl, callback_data->future_handle); - - jstring j_ad_unit_str = env->NewStringUTF(ad_unit_id); - ::firebase::gma::GetJNI()->CallVoidMethod( - helper_, - interstitial_ad_helper::GetMethodId(interstitial_ad_helper::kLoadAd), - reinterpret_cast(callback_data), j_ad_unit_str, j_request); - env->DeleteLocalRef(j_ad_unit_str); - env->DeleteLocalRef(j_request); - return future; -} - -Future InterstitialAdInternalAndroid::Show() { - firebase::MutexLock lock(mutex_); - if (!initialized_) { - const SafeFutureHandle future_handle = - future_data_.future_impl.SafeAlloc(kInterstitialAdFnShow); - Future future = MakeFuture(&future_data_.future_impl, future_handle); - CompleteFuture(kAdErrorCodeUninitialized, kAdUninitializedErrorMessage, - future_handle, &future_data_); - return future; - } - - FutureCallbackData* callback_data = - CreateVoidFutureCallbackData(kInterstitialAdFnShow, &future_data_); - Future future = - MakeFuture(&future_data_.future_impl, callback_data->future_handle); - - ::firebase::gma::GetJNI()->CallVoidMethod( - helper_, - interstitial_ad_helper::GetMethodId(interstitial_ad_helper::kShow), - reinterpret_cast(callback_data)); - - return future; -} - -} // namespace internal -} // namespace gma -} // namespace firebase diff --git a/gma/src/android/interstitial_ad_internal_android.h b/gma/src/android/interstitial_ad_internal_android.h deleted file mode 100644 index b83460febb..0000000000 --- a/gma/src/android/interstitial_ad_internal_android.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_ANDROID_INTERSTITIAL_AD_INTERNAL_ANDROID_H_ -#define FIREBASE_GMA_SRC_ANDROID_INTERSTITIAL_AD_INTERNAL_ANDROID_H_ - -#include "app/src/include/firebase/internal/mutex.h" -#include "app/src/util_android.h" -#include "gma/src/common/interstitial_ad_internal.h" - -namespace firebase { -namespace gma { - -// Used to set up the cache of InterstitialAdHelper class method IDs to reduce -// time spent looking up methods by string. -// clang-format off -#define INTERSTITIALADHELPER_METHODS(X) \ - X(Constructor, "", "(J)V"), \ - X(Initialize, "initialize", "(JLandroid/app/Activity;)V"), \ - X(Show, "show", "(J)V"), \ - X(LoadAd, "loadAd", \ - "(JLjava/lang/String;Lcom/google/android/gms/ads/AdRequest;)V"), \ - X(Disconnect, "disconnect", "()V") -// clang-format on - -METHOD_LOOKUP_DECLARATION(interstitial_ad_helper, INTERSTITIALADHELPER_METHODS); - -namespace internal { - -class InterstitialAdInternalAndroid : public InterstitialAdInternal { - public: - explicit InterstitialAdInternalAndroid(InterstitialAd* base); - ~InterstitialAdInternalAndroid() override; - - Future Initialize(AdParent parent) override; - Future LoadAd(const char* ad_unit_id, - const AdRequest& request) override; - Future Show() override; - bool is_initialized() const override { return initialized_; } - - private: - // Reference to the Java helper object used to interact with the Mobile Ads - // SDK. - jobject helper_; - - // Tracks if this Interstial Ad has been initialized. - bool initialized_; - - // Mutex to guard against concurrent operations; - Mutex mutex_; -}; - -} // namespace internal -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_ANDROID_INTERSTITIAL_AD_INTERNAL_ANDROID_H_ diff --git a/gma/src/android/native_ad_image_android.cc b/gma/src/android/native_ad_image_android.cc deleted file mode 100644 index 23af8c4fb2..0000000000 --- a/gma/src/android/native_ad_image_android.cc +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/android/native_ad_image_android.h" - -#include - -#include -#include - -#include "gma/src/android/gma_android.h" -#include "gma/src/common/gma_common.h" -#include "gma/src/include/firebase/gma.h" -#include "gma/src/include/firebase/gma/internal/native_ad.h" -#include "gma/src/include/firebase/gma/types.h" - -namespace firebase { -namespace gma { - -METHOD_LOOKUP_DEFINITION(native_image, - PROGUARD_KEEP_CLASS - "com/google/android/gms/ads/nativead/NativeAd$Image", - NATIVEADIMAGE_METHODS); - -METHOD_LOOKUP_DEFINITION(download_helper, - "com/google/firebase/gma/internal/cpp/DownloadHelper", - DOWNLOADHELPER_METHODS); - -NativeAdImage::NativeAdImage() { - // Initialize the default constructor with some helpful debug values in the - // case a NativeAdImage makes it to the application in this default state. - internal_ = new NativeAdImageInternal(); - internal_->scale = 0; - internal_->uri = "This NativeAdImage has not been initialized."; - internal_->native_ad_image = nullptr; -} - -NativeAdImage::NativeAdImage( - const NativeAdImageInternal& native_ad_image_internal) { - JNIEnv* env = ::firebase::gma::GetJNI(); - FIREBASE_ASSERT(env); - - internal_ = new NativeAdImageInternal(); - internal_->native_ad_image = nullptr; - - FIREBASE_ASSERT(native_ad_image_internal.native_ad_image != nullptr); - - internal_->native_ad_image = - env->NewGlobalRef(native_ad_image_internal.native_ad_image); - - util::CheckAndClearJniExceptions(env); - - // NativeAdImage Uri. - jobject j_uri = - env->CallObjectMethod(internal_->native_ad_image, - native_image::GetMethodId(native_image::kGetUri)); - util::CheckAndClearJniExceptions(env); - FIREBASE_ASSERT(j_uri); - internal_->uri = util::JniUriToString(env, j_uri); - - // Images requested with an android user agent may return webp images. Trim - // webp parameter from image url to get the original JPG/PNG image. - std::size_t eq_pos = internal_->uri.rfind("="); - std::size_t webp_pos = internal_->uri.rfind("-rw"); - if (webp_pos != std::string::npos && eq_pos != std::string::npos && - webp_pos > eq_pos) { - internal_->uri.replace(webp_pos, 3, ""); - } - - // NativeAdImage scale. - jdouble j_scale = - env->CallDoubleMethod(internal_->native_ad_image, - native_image::GetMethodId(native_image::kGetScale)); - util::CheckAndClearJniExceptions(env); - FIREBASE_ASSERT(j_scale); - internal_->scale = static_cast(j_scale); -} - -NativeAdImage::NativeAdImage(const NativeAdImage& source_native_image) - : NativeAdImage() { - // Reuse the assignment operator. - *this = source_native_image; -} - -NativeAdImage& NativeAdImage::operator=(const NativeAdImage& r_native_image) { - if (&r_native_image == this) { - return *this; - } - - JNIEnv* env = GetJNI(); - FIREBASE_ASSERT(env); - FIREBASE_ASSERT(internal_); - FIREBASE_ASSERT(r_native_image.internal_); - - NativeAdImageInternal* preexisting_internal = internal_; - { - // Lock the parties so they're not deleted while the copying takes place. - MutexLock r_native_image_lock(r_native_image.internal_->mutex); - MutexLock lock(internal_->mutex); - internal_ = new NativeAdImageInternal(); - - internal_->uri = r_native_image.internal_->uri; - internal_->scale = r_native_image.internal_->scale; - if (r_native_image.internal_->native_ad_image != nullptr) { - internal_->native_ad_image = - env->NewGlobalRef(r_native_image.internal_->native_ad_image); - } - if (preexisting_internal->native_ad_image) { - env->DeleteGlobalRef(preexisting_internal->native_ad_image); - preexisting_internal->native_ad_image = nullptr; - } - } - - // Deleting the internal_ deletes the mutex within it, so we wait for - // complete deletion until after the mutex lock leaves scope. - delete preexisting_internal; - - return *this; -} - -NativeAdImage::~NativeAdImage() { - FIREBASE_ASSERT(internal_); - - JNIEnv* env = GetJNI(); - FIREBASE_ASSERT(env); - if (internal_->native_ad_image != nullptr) { - env->DeleteGlobalRef(internal_->native_ad_image); - internal_->native_ad_image = nullptr; - } - - if (internal_->helper != nullptr) { - env->DeleteGlobalRef(internal_->helper); - internal_->helper = nullptr; - } - internal_->callback_data = nullptr; - - delete internal_; - internal_ = nullptr; -} - -/// Gets the native ad image URI. -const std::string& NativeAdImage::image_uri() const { - FIREBASE_ASSERT(internal_); - return internal_->uri; -} - -/// Gets the image scale, which denotes the ratio of pixels to dp. -double NativeAdImage::scale() const { - FIREBASE_ASSERT(internal_); - return internal_->scale; -} - -/// Triggers the auto loaded image and returns an ImageResult future. -Future NativeAdImage::LoadImage() const { - firebase::MutexLock lock(internal_->mutex); - - JNIEnv* env = ::firebase::gma::GetJNI(); - FIREBASE_ASSERT(env); - - if (internal_->uri.empty()) { - return CreateAndCompleteFutureWithImageResult( - kNativeAdImageFnLoadImage, kAdErrorCodeImageUrlMalformed, - kImageUrlMalformedErrorMessage, &internal_->future_data, ImageResult()); - } - - jstring uri_jstring = env->NewStringUTF(internal_->uri.c_str()); - jobject helper_ref = env->NewObject( - download_helper::GetClass(), - download_helper::GetMethodId(download_helper::kConstructor), uri_jstring); - - FIREBASE_ASSERT(helper_ref); - internal_->helper = env->NewGlobalRef(helper_ref); - FIREBASE_ASSERT(internal_->helper); - - env->DeleteLocalRef(uri_jstring); - if (util::CheckAndClearJniExceptions(env)) { - return CreateAndCompleteFutureWithImageResult( - kNativeAdImageFnLoadImage, kAdErrorCodeImageUrlMalformed, - kImageUrlMalformedErrorMessage, &internal_->future_data, ImageResult()); - } - - FutureCallbackData* callback_data = - CreateImageResultFutureCallbackData(kNativeAdImageFnLoadImage, - &internal_->future_data); - - Future future = MakeFuture(&internal_->future_data.future_impl, - callback_data->future_handle); - - env->CallVoidMethod(internal_->helper, - download_helper::GetMethodId(download_helper::kDownload), - reinterpret_cast(callback_data)); - - util::CheckAndClearJniExceptions(env); - return future; -} - -Future NativeAdImage::LoadImageLastResult() const { - return static_cast&>( - internal_->future_data.future_impl.LastResult(kNativeAdImageFnLoadImage)); -} - -} // namespace gma -} // namespace firebase diff --git a/gma/src/android/native_ad_image_android.h b/gma/src/android/native_ad_image_android.h deleted file mode 100644 index 2e240f0a9f..0000000000 --- a/gma/src/android/native_ad_image_android.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_ANDROID_NATIVE_AD_IMAGE_ANDROID_H_ -#define FIREBASE_GMA_SRC_ANDROID_NATIVE_AD_IMAGE_ANDROID_H_ - -#include - -#include "app/src/include/firebase/internal/mutex.h" -#include "app/src/util_android.h" -#include "gma/src/common/native_ad_image_internal.h" -#include "gma/src/include/firebase/gma/internal/native_ad.h" -#include "gma/src/include/firebase/gma/types.h" - -namespace firebase { -namespace gma { - -// Used to set up the cache of class method IDs to reduce -// time spent looking up methods by string. -// clang-format off -#define NATIVEADIMAGE_METHODS(X) \ - X(GetScale, "getScale", "()D"), \ - X(GetUri, "getUri", "()Landroid/net/Uri;"), \ - X(GetDrawable, "getDrawable", "()Landroid/graphics/drawable/Drawable;") - -#define DOWNLOADHELPER_METHODS(X) \ - X(Constructor, "", "(Ljava/lang/String;)V"), \ - X(AddHeader, "addHeader", "(Ljava/lang/String;Ljava/lang/String;)V"), \ - X(Download, "download", "(J)V"), \ - X(GetResponseCode, "getResponseCode", "()I") -// clang-format on - -METHOD_LOOKUP_DECLARATION(native_image, NATIVEADIMAGE_METHODS); -METHOD_LOOKUP_DECLARATION(download_helper, DOWNLOADHELPER_METHODS); - -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_ANDROID_NATIVE_AD_IMAGE_ANDROID_H_ diff --git a/gma/src/android/native_ad_internal_android.cc b/gma/src/android/native_ad_internal_android.cc deleted file mode 100644 index b99e1d643b..0000000000 --- a/gma/src/android/native_ad_internal_android.cc +++ /dev/null @@ -1,270 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/android/native_ad_internal_android.h" - -#include -#include - -#include -#include - -#include "app/src/assert.h" -#include "app/src/util_android.h" -#include "gma/src/android/ad_request_converter.h" -#include "gma/src/android/gma_android.h" -#include "gma/src/common/gma_common.h" -#include "gma/src/include/firebase/gma.h" -#include "gma/src/include/firebase/gma/internal/native_ad.h" -#include "gma/src/include/firebase/gma/types.h" - -namespace firebase { -namespace gma { - -METHOD_LOOKUP_DEFINITION(native_ad_helper, - "com/google/firebase/gma/internal/cpp/NativeAdHelper", - NATIVEADHELPER_METHODS); - -namespace internal { - -NativeAdInternalAndroid::NativeAdInternalAndroid(NativeAd* base) - : NativeAdInternal(base), helper_(nullptr), initialized_(false) { - firebase::MutexLock lock(mutex_); - JNIEnv* env = ::firebase::gma::GetJNI(); - jobject helper_ref = env->NewObject( - native_ad_helper::GetClass(), - native_ad_helper::GetMethodId(native_ad_helper::kConstructor), - reinterpret_cast(this)); - util::CheckAndClearJniExceptions(env); - - FIREBASE_ASSERT(helper_ref); - helper_ = env->NewGlobalRef(helper_ref); - FIREBASE_ASSERT(helper_); - env->DeleteLocalRef(helper_ref); -} - -NativeAdInternalAndroid::~NativeAdInternalAndroid() { - firebase::MutexLock lock(mutex_); - JNIEnv* env = ::firebase::gma::GetJNI(); - // Since it's currently not possible to destroy the native ad, just - // disconnect from it so the listener doesn't initiate callbacks with stale - // data. - env->CallVoidMethod( - helper_, native_ad_helper::GetMethodId(native_ad_helper::kDisconnect)); - util::CheckAndClearJniExceptions(env); - env->DeleteGlobalRef(helper_); - helper_ = nullptr; -} - -Future NativeAdInternalAndroid::Initialize(AdParent parent) { - firebase::MutexLock lock(mutex_); - - if (initialized_) { - const SafeFutureHandle future_handle = - future_data_.future_impl.SafeAlloc(kNativeAdFnInitialize); - Future future = MakeFuture(&future_data_.future_impl, future_handle); - CompleteFuture(kAdErrorCodeAlreadyInitialized, - kAdAlreadyInitializedErrorMessage, future_handle, - &future_data_); - return future; - } - - initialized_ = true; - JNIEnv* env = ::firebase::gma::GetJNI(); - FIREBASE_ASSERT(env); - - FutureCallbackData* callback_data = - CreateVoidFutureCallbackData(kNativeAdFnInitialize, &future_data_); - Future future = - MakeFuture(&future_data_.future_impl, callback_data->future_handle); - env->CallVoidMethod( - helper_, native_ad_helper::GetMethodId(native_ad_helper::kInitialize), - reinterpret_cast(callback_data), parent); - util::CheckAndClearJniExceptions(env); - return future; -} - -Future NativeAdInternalAndroid::LoadAd(const char* ad_unit_id, - const AdRequest& request) { - firebase::MutexLock lock(mutex_); - - if (!initialized_) { - SafeFutureHandle future_handle = - CreateFuture(kNativeAdFnLoadAd, &future_data_); - Future future = - MakeFuture(&future_data_.future_impl, future_handle); - CompleteFuture(kAdErrorCodeUninitialized, kAdUninitializedErrorMessage, - future_handle, &future_data_, AdResult()); - return future; - } - - gma::AdErrorCode error = kAdErrorCodeNone; - jobject j_request = GetJavaAdRequestFromCPPAdRequest(request, &error); - if (j_request == nullptr) { - if (error == kAdErrorCodeNone) { - error = kAdErrorCodeInternalError; - } - return CreateAndCompleteFutureWithResult( - kNativeAdFnLoadAd, error, kAdCouldNotParseAdRequestErrorMessage, - &future_data_, AdResult()); - } - JNIEnv* env = GetJNI(); - FIREBASE_ASSERT(env); - FutureCallbackData* callback_data = - CreateAdResultFutureCallbackData(kNativeAdFnLoadAd, &future_data_); - Future future = - MakeFuture(&future_data_.future_impl, callback_data->future_handle); - - jstring j_ad_unit_str = env->NewStringUTF(ad_unit_id); - ::firebase::gma::GetJNI()->CallVoidMethod( - helper_, native_ad_helper::GetMethodId(native_ad_helper::kLoadAd), - reinterpret_cast(callback_data), j_ad_unit_str, j_request); - util::CheckAndClearJniExceptions(env); - env->DeleteLocalRef(j_ad_unit_str); - env->DeleteLocalRef(j_request); - return future; -} - -Future NativeAdInternalAndroid::RecordImpression( - const Variant& impression_data) { - firebase::MutexLock lock(mutex_); - - if (!initialized_) { - return CreateAndCompleteFuture(kNativeAdFnRecordImpression, - kAdErrorCodeUninitialized, - kAdUninitializedErrorMessage, &future_data_); - } - - jobject impression_bundle = variantmap_to_bundle(impression_data); - - if (impression_bundle == nullptr) { - return CreateAndCompleteFuture( - kNativeAdFnRecordImpression, kAdErrorCodeInvalidArgument, - kUnsupportedVariantTypeErrorMessage, &future_data_); - } - - JNIEnv* env = ::firebase::gma::GetJNI(); - FIREBASE_ASSERT(env); - - FutureCallbackData* callback_data = - CreateVoidFutureCallbackData(kNativeAdFnRecordImpression, &future_data_); - Future future = - MakeFuture(&future_data_.future_impl, callback_data->future_handle); - env->CallVoidMethod( - helper_, - native_ad_helper::GetMethodId(native_ad_helper::kRecordImpression), - reinterpret_cast(callback_data), impression_bundle); - - util::CheckAndClearJniExceptions(env); - - return future; -} - -Future NativeAdInternalAndroid::PerformClick(const Variant& click_data) { - firebase::MutexLock lock(mutex_); - - if (!initialized_) { - return CreateAndCompleteFuture(kNativeAdFnPerformClick, - kAdErrorCodeUninitialized, - kAdUninitializedErrorMessage, &future_data_); - } - - jobject click_bundle = variantmap_to_bundle(click_data); - - if (click_bundle == nullptr) { - return CreateAndCompleteFuture( - kNativeAdFnPerformClick, kAdErrorCodeInvalidArgument, - kUnsupportedVariantTypeErrorMessage, &future_data_); - } - - JNIEnv* env = ::firebase::gma::GetJNI(); - FIREBASE_ASSERT(env); - - FutureCallbackData* callback_data = - CreateVoidFutureCallbackData(kNativeAdFnPerformClick, &future_data_); - Future future = - MakeFuture(&future_data_.future_impl, callback_data->future_handle); - env->CallVoidMethod( - helper_, native_ad_helper::GetMethodId(native_ad_helper::kPerformClick), - reinterpret_cast(callback_data), click_bundle); - - util::CheckAndClearJniExceptions(env); - - return future; -} - -jobject NativeAdInternalAndroid::variantmap_to_bundle( - const Variant& variant_data) { - if (!variant_data.is_map()) { - return nullptr; - } - - JNIEnv* env = ::firebase::gma::GetJNI(); - FIREBASE_ASSERT(env); - - jobject variant_bundle = - env->NewObject(util::bundle::GetClass(), - util::bundle::GetMethodId(util::bundle::kConstructor)); - FIREBASE_ASSERT(variant_bundle); - - for (const auto& kvp : variant_data.map()) { - const Variant& key = kvp.first; - const Variant& value = kvp.second; - - if (!key.is_string()) { - return nullptr; - } - jstring key_str = env->NewStringUTF(key.string_value()); - util::CheckAndClearJniExceptions(env); - - if (value.is_int64()) { - jlong val_long = (jlong)value.int64_value(); - env->CallVoidMethod(variant_bundle, - util::bundle::GetMethodId(util::bundle::kPutLong), - key_str, val_long); - } else if (value.is_double()) { - jfloat val_float = (jfloat)value.double_value(); - env->CallVoidMethod(variant_bundle, - util::bundle::GetMethodId(util::bundle::kPutFloat), - key_str, val_float); - } else if (value.is_string()) { - jstring val_str = env->NewStringUTF(value.string_value()); - env->CallVoidMethod(variant_bundle, - util::bundle::GetMethodId(util::bundle::kPutString), - key_str, val_str); - env->DeleteLocalRef(val_str); - } else if (value.is_map()) { - jobject val_bundle = variantmap_to_bundle(value); - env->CallVoidMethod(variant_bundle, - util::bundle::GetMethodId(util::bundle::kPutBundle), - key_str, val_bundle); - env->DeleteLocalRef(val_bundle); - } else { - // Unsupported value type. - env->DeleteLocalRef(key_str); - return nullptr; - } - - util::CheckAndClearJniExceptions(env); - env->DeleteLocalRef(key_str); - } - - return variant_bundle; -} - -} // namespace internal -} // namespace gma -} // namespace firebase diff --git a/gma/src/android/native_ad_internal_android.h b/gma/src/android/native_ad_internal_android.h deleted file mode 100644 index c4b02e056e..0000000000 --- a/gma/src/android/native_ad_internal_android.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_ANDROID_NATIVE_AD_INTERNAL_ANDROID_H_ -#define FIREBASE_GMA_SRC_ANDROID_NATIVE_AD_INTERNAL_ANDROID_H_ - -#include "app/src/include/firebase/internal/mutex.h" -#include "app/src/util_android.h" -#include "gma/src/common/native_ad_internal.h" - -namespace firebase { -namespace gma { - -// Used to set up the cache of NativeAdHelper class method IDs to reduce -// time spent looking up methods by string. -// clang-format off -#define NATIVEADHELPER_METHODS(X) \ - X(Constructor, "", "(J)V"), \ - X(Initialize, "initialize", "(JLandroid/app/Activity;)V"), \ - X(LoadAd, "loadAd", \ - "(JLjava/lang/String;Lcom/google/android/gms/ads/AdRequest;)V"), \ - X(RecordImpression, "recordImpression", "(JLandroid/os/Bundle;)V"), \ - X(PerformClick, "performClick", "(JLandroid/os/Bundle;)V"), \ - X(Disconnect, "disconnect", "()V") -// clang-format on - -METHOD_LOOKUP_DECLARATION(native_ad_helper, NATIVEADHELPER_METHODS); - -namespace internal { - -class NativeAdInternalAndroid : public NativeAdInternal { - public: - explicit NativeAdInternalAndroid(NativeAd* base); - ~NativeAdInternalAndroid() override; - - Future Initialize(AdParent parent) override; - Future LoadAd(const char* ad_unit_id, - const AdRequest& request) override; - bool is_initialized() const override { return initialized_; } - Future RecordImpression(const Variant& impression_data) override; - Future PerformClick(const Variant& click_data) override; - jobject variantmap_to_bundle(const Variant& variant_data); - - private: - // Reference to the Java helper object used to interact with the Mobile Ads - // SDK. - jobject helper_; - - // Tracks if this Native Ad has been initialized. - bool initialized_; - - // Mutex to guard against concurrent operations; - Mutex mutex_; -}; - -} // namespace internal -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_ANDROID_NATIVE_AD_INTERNAL_ANDROID_H_ diff --git a/gma/src/android/query_info_internal_android.cc b/gma/src/android/query_info_internal_android.cc deleted file mode 100644 index 6321021adb..0000000000 --- a/gma/src/android/query_info_internal_android.cc +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/android/query_info_internal_android.h" - -#include -#include - -#include -#include - -#include "app/src/assert.h" -#include "app/src/util_android.h" -#include "gma/src/android/ad_request_converter.h" -#include "gma/src/android/gma_android.h" -#include "gma/src/common/gma_common.h" -#include "gma/src/include/firebase/gma.h" -#include "gma/src/include/firebase/gma/internal/query_info.h" -#include "gma/src/include/firebase/gma/types.h" - -namespace firebase { -namespace gma { - -METHOD_LOOKUP_DEFINITION(query_info_helper, - "com/google/firebase/gma/internal/cpp/QueryInfoHelper", - QUERYINFOHELPER_METHODS); - -namespace internal { - -QueryInfoInternalAndroid::QueryInfoInternalAndroid(QueryInfo* base) - : QueryInfoInternal(base), helper_(nullptr), initialized_(false) { - firebase::MutexLock lock(mutex_); - JNIEnv* env = ::firebase::gma::GetJNI(); - jobject helper_ref = env->NewObject( - query_info_helper::GetClass(), - query_info_helper::GetMethodId(query_info_helper::kConstructor), - reinterpret_cast(this)); - util::CheckAndClearJniExceptions(env); - - FIREBASE_ASSERT(helper_ref); - helper_ = env->NewGlobalRef(helper_ref); - FIREBASE_ASSERT(helper_); - env->DeleteLocalRef(helper_ref); -} - -QueryInfoInternalAndroid::~QueryInfoInternalAndroid() { - firebase::MutexLock lock(mutex_); - JNIEnv* env = ::firebase::gma::GetJNI(); - - env->CallVoidMethod( - helper_, query_info_helper::GetMethodId(query_info_helper::kDisconnect)); - util::CheckAndClearJniExceptions(env); - env->DeleteGlobalRef(helper_); - helper_ = nullptr; -} - -Future QueryInfoInternalAndroid::Initialize(AdParent parent) { - firebase::MutexLock lock(mutex_); - - if (initialized_) { - const SafeFutureHandle future_handle = - future_data_.future_impl.SafeAlloc(kQueryInfoFnInitialize); - Future future = MakeFuture(&future_data_.future_impl, future_handle); - CompleteFuture(kAdErrorCodeAlreadyInitialized, - kAdAlreadyInitializedErrorMessage, future_handle, - &future_data_); - return future; - } - - initialized_ = true; - JNIEnv* env = ::firebase::gma::GetJNI(); - FIREBASE_ASSERT(env); - - FutureCallbackData* callback_data = - CreateVoidFutureCallbackData(kQueryInfoFnInitialize, &future_data_); - Future future = - MakeFuture(&future_data_.future_impl, callback_data->future_handle); - env->CallVoidMethod( - helper_, query_info_helper::GetMethodId(query_info_helper::kInitialize), - reinterpret_cast(callback_data), parent); - util::CheckAndClearJniExceptions(env); - return future; -} - -Future QueryInfoInternalAndroid::CreateQueryInfo( - AdFormat format, const AdRequest& request) { - firebase::MutexLock lock(mutex_); - - if (!initialized_) { - SafeFutureHandle future_handle = - CreateFuture(kQueryInfoFnCreateQueryInfo, - &future_data_); - Future future = - MakeFuture(&future_data_.future_impl, future_handle); - CompleteFuture(kAdErrorCodeUninitialized, kAdUninitializedErrorMessage, - future_handle, &future_data_, QueryInfoResult()); - return future; - } - - gma::AdErrorCode error = kAdErrorCodeNone; - jobject j_request = GetJavaAdRequestFromCPPAdRequest(request, &error); - if (j_request == nullptr) { - if (error == kAdErrorCodeNone) { - error = kAdErrorCodeInternalError; - } - return CreateAndCompleteFutureWithQueryInfoResult( - kQueryInfoFnCreateQueryInfo, error, - kAdCouldNotParseAdRequestErrorMessage, &future_data_, - QueryInfoResult()); - } - JNIEnv* env = GetJNI(); - FIREBASE_ASSERT(env); - FutureCallbackData* callback_data = - CreateQueryInfoResultFutureCallbackData(kQueryInfoFnCreateQueryInfo, - &future_data_); - Future future = - MakeFuture(&future_data_.future_impl, callback_data->future_handle); - - jstring j_ad_unit_str = env->NewStringUTF(""); - ::firebase::gma::GetJNI()->CallVoidMethod( - helper_, - query_info_helper::GetMethodId(query_info_helper::kCreateQueryInfo), - reinterpret_cast(callback_data), static_cast(format), - j_ad_unit_str, j_request); - util::CheckAndClearJniExceptions(env); - env->DeleteLocalRef(j_ad_unit_str); - env->DeleteLocalRef(j_request); - return future; -} - -Future QueryInfoInternalAndroid::CreateQueryInfoWithAdUnit( - AdFormat format, const AdRequest& request, const char* ad_unit_id) { - firebase::MutexLock lock(mutex_); - - if (!initialized_) { - SafeFutureHandle future_handle = - CreateFuture(kQueryInfoFnCreateQueryInfoWithAdUnit, - &future_data_); - Future future = - MakeFuture(&future_data_.future_impl, future_handle); - CompleteFuture(kAdErrorCodeUninitialized, kAdUninitializedErrorMessage, - future_handle, &future_data_, QueryInfoResult()); - return future; - } - - gma::AdErrorCode error = kAdErrorCodeNone; - jobject j_request = GetJavaAdRequestFromCPPAdRequest(request, &error); - if (j_request == nullptr) { - if (error == kAdErrorCodeNone) { - error = kAdErrorCodeInternalError; - } - return CreateAndCompleteFutureWithQueryInfoResult( - kQueryInfoFnCreateQueryInfoWithAdUnit, error, - kAdCouldNotParseAdRequestErrorMessage, &future_data_, - QueryInfoResult()); - } - JNIEnv* env = GetJNI(); - FIREBASE_ASSERT(env); - FutureCallbackData* callback_data = - CreateQueryInfoResultFutureCallbackData( - kQueryInfoFnCreateQueryInfoWithAdUnit, &future_data_); - Future future = - MakeFuture(&future_data_.future_impl, callback_data->future_handle); - - jstring j_ad_unit_str = env->NewStringUTF(ad_unit_id); - ::firebase::gma::GetJNI()->CallVoidMethod( - helper_, - query_info_helper::GetMethodId(query_info_helper::kCreateQueryInfo), - reinterpret_cast(callback_data), static_cast(format), - j_ad_unit_str, j_request); - util::CheckAndClearJniExceptions(env); - env->DeleteLocalRef(j_ad_unit_str); - env->DeleteLocalRef(j_request); - return future; -} - -} // namespace internal -} // namespace gma -} // namespace firebase diff --git a/gma/src/android/query_info_internal_android.h b/gma/src/android/query_info_internal_android.h deleted file mode 100644 index e3ee51a6c9..0000000000 --- a/gma/src/android/query_info_internal_android.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_ANDROID_QUERY_INFO_INTERNAL_ANDROID_H_ -#define FIREBASE_GMA_SRC_ANDROID_QUERY_INFO_INTERNAL_ANDROID_H_ - -#include "app/src/include/firebase/internal/mutex.h" -#include "app/src/util_android.h" -#include "gma/src/common/query_info_internal.h" - -namespace firebase { -namespace gma { - -// Used to set up the cache of QueryInfoHelper class method IDs to reduce -// time spent looking up methods by string. -// clang-format off -#define QUERYINFOHELPER_METHODS(X) \ - X(Constructor, "", "(J)V"), \ - X(Initialize, "initialize", "(JLandroid/app/Activity;)V"), \ - X(CreateQueryInfo, "createQueryInfo", \ - "(JILjava/lang/String;Lcom/google/android/gms/ads/AdRequest;)V"), \ - X(Disconnect, "disconnect", "()V") -// clang-format on - -METHOD_LOOKUP_DECLARATION(query_info_helper, QUERYINFOHELPER_METHODS); - -namespace internal { -class QueryInfoInternalAndroid : public QueryInfoInternal { - public: - explicit QueryInfoInternalAndroid(QueryInfo* base); - ~QueryInfoInternalAndroid() override; - - Future Initialize(AdParent parent) override; - Future CreateQueryInfo(AdFormat format, - const AdRequest& request) override; - Future CreateQueryInfoWithAdUnit( - AdFormat format, const AdRequest& request, - const char* ad_unit_id) override; - bool is_initialized() const override { return initialized_; } - - private: - // Reference to the Java helper object used to interact with the Mobile Ads - // SDK. - jobject helper_; - - // Tracks if this QueryInfo has been initialized. - bool initialized_; - - // Mutex to guard against concurrent operations; - Mutex mutex_; -}; - -} // namespace internal -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_ANDROID_QUERY_INFO_INTERNAL_ANDROID_H_ diff --git a/gma/src/android/response_info_android.cc b/gma/src/android/response_info_android.cc deleted file mode 100644 index c71bdc6b29..0000000000 --- a/gma/src/android/response_info_android.cc +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/android/response_info_android.h" - -#include "gma/src/android/ad_error_android.h" -#include "gma/src/android/adapter_response_info_android.h" -#include "gma/src/android/gma_android.h" -#include "gma/src/common/gma_common.h" -#include "gma/src/include/firebase/gma.h" - -namespace firebase { -namespace gma { - -METHOD_LOOKUP_DEFINITION(response_info, - PROGUARD_KEEP_CLASS - "com/google/android/gms/ads/ResponseInfo", - RESPONSEINFO_METHODS); - -ResponseInfo::ResponseInfo() { - to_string_ = "This ResponseInfo has not been initialized."; -} - -ResponseInfo::ResponseInfo(const ResponseInfoInternal& response_info_internal) { - FIREBASE_ASSERT(response_info_internal.j_response_info); - - const jobject j_response_info = response_info_internal.j_response_info; - JNIEnv* env = GetJNI(); - FIREBASE_ASSERT(env); - - // The list of AdapterResponseInfos which contains response information - // for each of the adapters that attempted to fulfill the GMA operation. - const jobject j_adapter_response_info_list = env->CallObjectMethod( - j_response_info, - response_info::GetMethodId(response_info::kGetAdapterResponses)); - FIREBASE_ASSERT(j_adapter_response_info_list); - - const int list_size = (int)env->CallIntMethod( - j_adapter_response_info_list, util::list::GetMethodId(util::list::kSize)); - for (int i = 0; i < list_size; ++i) { - // AdapterResponseInfo for this adapter. - jobject j_adapter_response_info = - env->CallObjectMethod(j_adapter_response_info_list, - util::list::GetMethodId(util::list::kGet), i); - FIREBASE_ASSERT(j_adapter_response_info); - AdapterResponseInfoInternal adapter_response_internal; - adapter_response_internal.j_adapter_response_info = j_adapter_response_info; - adapter_responses_.push_back( - AdapterResponseInfo(adapter_response_internal)); - env->DeleteLocalRef(j_adapter_response_info); - } - - // The Mediation Adapter class name. - const jobject j_mediation_adapter_classname = env->CallObjectMethod( - j_response_info, - response_info::GetMethodId(response_info::kGetMediationAdapterClassName)); - if (j_mediation_adapter_classname != nullptr) { - mediation_adapter_class_name_ = - util::JStringToString(env, j_mediation_adapter_classname); - env->DeleteLocalRef(j_mediation_adapter_classname); - } - - // The Response ID for this adapter response. - const jobject j_response_id = env->CallObjectMethod( - j_response_info, - response_info::GetMethodId(response_info::kGetResponseId)); - if (j_response_id != nullptr) { - response_id_ = util::JStringToString(env, j_response_id); - env->DeleteLocalRef(j_response_id); - } - - // A String representation of the ResponseInfo. - const jobject j_to_string = env->CallObjectMethod( - j_response_info, response_info::GetMethodId(response_info::kToString)); - FIREBASE_ASSERT(j_to_string); - to_string_ = util::JStringToString(env, j_to_string); - env->DeleteLocalRef(j_to_string); -} - -} // namespace gma -} // namespace firebase diff --git a/gma/src/android/response_info_android.h b/gma/src/android/response_info_android.h deleted file mode 100644 index 0488d301d3..0000000000 --- a/gma/src/android/response_info_android.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_ANDROID_RESPONSE_INFO_ANDROID_H_ -#define FIREBASE_GMA_SRC_ANDROID_RESPONSE_INFO_ANDROID_H_ - -#include - -#include "app/src/util_android.h" -#include "gma/src/include/firebase/gma/types.h" - -namespace firebase { -namespace gma { - -struct ResponseInfoInternal { - jobject j_response_info; -}; - -// Used to set up the cache of class method IDs to reduce -// time spent looking up methods by string. -// clang-format off -#define RESPONSEINFO_METHODS(X) \ - X(GetAdapterResponses, "getAdapterResponses", \ - "()Ljava/util/List;"), \ - X(GetMediationAdapterClassName, "getMediationAdapterClassName", \ - "()Ljava/lang/String;"), \ - X(GetResponseId, "getResponseId", "()Ljava/lang/String;"), \ - X(ToString, "toString", "()Ljava/lang/String;") -// clang-format on - -METHOD_LOOKUP_DECLARATION(response_info, RESPONSEINFO_METHODS); - -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_ANDROID_RESPONSE_INFO_ANDROID_H_ diff --git a/gma/src/android/rewarded_ad_internal_android.cc b/gma/src/android/rewarded_ad_internal_android.cc deleted file mode 100644 index 69eebcc17f..0000000000 --- a/gma/src/android/rewarded_ad_internal_android.cc +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/android/rewarded_ad_internal_android.h" - -#include -#include - -#include -#include - -#include "app/src/assert.h" -#include "app/src/util_android.h" -#include "gma/src/android/ad_request_converter.h" -#include "gma/src/android/gma_android.h" -#include "gma/src/common/gma_common.h" -#include "gma/src/include/firebase/gma.h" -#include "gma/src/include/firebase/gma/types.h" - -namespace firebase { -namespace gma { - -METHOD_LOOKUP_DEFINITION( - rewarded_ad_helper, "com/google/firebase/gma/internal/cpp/RewardedAdHelper", - REWARDEDADHELPER_METHODS); - -namespace internal { - -RewardedAdInternalAndroid::RewardedAdInternalAndroid(RewardedAd* base) - : RewardedAdInternal(base), helper_(nullptr), initialized_(false) { - firebase::MutexLock lock(mutex_); - JNIEnv* env = ::firebase::gma::GetJNI(); - jobject helper_ref = env->NewObject( - rewarded_ad_helper::GetClass(), - rewarded_ad_helper::GetMethodId(rewarded_ad_helper::kConstructor), - reinterpret_cast(this)); - util::CheckAndClearJniExceptions(env); - - FIREBASE_ASSERT(helper_ref); - helper_ = env->NewGlobalRef(helper_ref); - FIREBASE_ASSERT(helper_); - env->DeleteLocalRef(helper_ref); -} - -RewardedAdInternalAndroid::~RewardedAdInternalAndroid() { - firebase::MutexLock lock(mutex_); - JNIEnv* env = ::firebase::gma::GetJNI(); - // Since it's currently not possible to destroy the rewarded ad, just - // disconnect from it so the listener doesn't initiate callbacks with stale - // data. - env->CallVoidMethod(helper_, rewarded_ad_helper::GetMethodId( - rewarded_ad_helper::kDisconnect)); - util::CheckAndClearJniExceptions(env); - env->DeleteGlobalRef(helper_); - - helper_ = nullptr; - full_screen_content_listener_ = nullptr; - paid_event_listener_ = nullptr; - user_earned_reward_listener_ = nullptr; -} - -Future RewardedAdInternalAndroid::Initialize(AdParent parent) { - firebase::MutexLock lock(mutex_); - if (initialized_) { - const SafeFutureHandle future_handle = - future_data_.future_impl.SafeAlloc(kRewardedAdFnInitialize); - Future future = MakeFuture(&future_data_.future_impl, future_handle); - CompleteFuture(kAdErrorCodeAlreadyInitialized, - kAdAlreadyInitializedErrorMessage, future_handle, - &future_data_); - return future; - } - - initialized_ = true; - FutureCallbackData* callback_data = - CreateVoidFutureCallbackData(kRewardedAdFnInitialize, &future_data_); - Future future = - MakeFuture(&future_data_.future_impl, callback_data->future_handle); - - JNIEnv* env = ::firebase::gma::GetJNI(); - FIREBASE_ASSERT(env); - env->CallVoidMethod( - helper_, rewarded_ad_helper::GetMethodId(rewarded_ad_helper::kInitialize), - reinterpret_cast(callback_data), parent); - util::CheckAndClearJniExceptions(env); - return future; -} - -Future RewardedAdInternalAndroid::LoadAd(const char* ad_unit_id, - const AdRequest& request) { - firebase::MutexLock lock(mutex_); - if (!initialized_) { - SafeFutureHandle future_handle = - future_data_.future_impl.SafeAlloc(kRewardedAdFnLoadAd, - AdResult()); - Future future = - MakeFuture(&future_data_.future_impl, future_handle); - CompleteFuture(kAdErrorCodeUninitialized, kAdUninitializedErrorMessage, - future_handle, &future_data_, AdResult()); - return future; - } - - gma::AdErrorCode error = kAdErrorCodeNone; - jobject j_request = GetJavaAdRequestFromCPPAdRequest(request, &error); - if (j_request == nullptr) { - if (error == kAdErrorCodeNone) { - error = kAdErrorCodeInternalError; - } - return CreateAndCompleteFutureWithResult( - kRewardedAdFnLoadAd, error, kAdCouldNotParseAdRequestErrorMessage, - &future_data_, AdResult()); - } - FutureCallbackData* callback_data = - CreateAdResultFutureCallbackData(kRewardedAdFnLoadAd, &future_data_); - Future future = - MakeFuture(&future_data_.future_impl, callback_data->future_handle); - - JNIEnv* env = GetJNI(); - FIREBASE_ASSERT(env); - jstring j_ad_unit_str = env->NewStringUTF(ad_unit_id); - env->CallVoidMethod( - helper_, rewarded_ad_helper::GetMethodId(rewarded_ad_helper::kLoadAd), - reinterpret_cast(callback_data), j_ad_unit_str, j_request); - util::CheckAndClearJniExceptions(env); - env->DeleteLocalRef(j_ad_unit_str); - env->DeleteLocalRef(j_request); - - return future; -} - -Future RewardedAdInternalAndroid::Show( - UserEarnedRewardListener* listener) { - firebase::MutexLock lock(mutex_); - if (!initialized_) { - const SafeFutureHandle future_handle = - future_data_.future_impl.SafeAlloc(kRewardedAdFnShow); - Future future = MakeFuture(&future_data_.future_impl, future_handle); - CompleteFuture(kAdErrorCodeUninitialized, kAdUninitializedErrorMessage, - future_handle, &future_data_); - return future; - } - - user_earned_reward_listener_ = listener; - - FutureCallbackData* callback_data = - CreateVoidFutureCallbackData(kRewardedAdFnShow, &future_data_); - Future future = - MakeFuture(&future_data_.future_impl, callback_data->future_handle); - - JNIEnv* env = GetJNI(); - FIREBASE_ASSERT(env); - jstring j_verification_custom_data = - env->NewStringUTF(serverSideVerificationOptions_.custom_data.c_str()); - jstring j_verification_user_id = - env->NewStringUTF(serverSideVerificationOptions_.user_id.c_str()); - env->CallVoidMethod( - helper_, rewarded_ad_helper::GetMethodId(rewarded_ad_helper::kShow), - reinterpret_cast(callback_data), j_verification_custom_data, - j_verification_user_id); - util::CheckAndClearJniExceptions(env); - env->DeleteLocalRef(j_verification_custom_data); - env->DeleteLocalRef(j_verification_user_id); - - return future; -} - -} // namespace internal -} // namespace gma -} // namespace firebase diff --git a/gma/src/android/rewarded_ad_internal_android.h b/gma/src/android/rewarded_ad_internal_android.h deleted file mode 100644 index 197e8defc8..0000000000 --- a/gma/src/android/rewarded_ad_internal_android.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_ANDROID_REWARDED_AD_INTERNAL_ANDROID_H_ -#define FIREBASE_GMA_SRC_ANDROID_REWARDED_AD_INTERNAL_ANDROID_H_ - -#include "app/src/include/firebase/internal/mutex.h" -#include "app/src/util_android.h" -#include "gma/src/common/rewarded_ad_internal.h" - -namespace firebase { -namespace gma { - -// Used to set up the cache of RewardedAdHelper class method IDs to reduce -// time spent looking up methods by string. -// clang-format off -#define REWARDEDADHELPER_METHODS(X) \ - X(Constructor, "", "(J)V"), \ - X(Initialize, "initialize", "(JLandroid/app/Activity;)V"), \ - X(Show, "show", "(JLjava/lang/String;Ljava/lang/String;)V"), \ - X(LoadAd, "loadAd", \ - "(JLjava/lang/String;Lcom/google/android/gms/ads/AdRequest;)V"), \ - X(Disconnect, "disconnect", "()V") -// clang-format on - -METHOD_LOOKUP_DECLARATION(rewarded_ad_helper, REWARDEDADHELPER_METHODS); - -namespace internal { - -class RewardedAdInternalAndroid : public RewardedAdInternal { - public: - explicit RewardedAdInternalAndroid(RewardedAd* base); - ~RewardedAdInternalAndroid() override; - - Future Initialize(AdParent parent) override; - Future LoadAd(const char* ad_unit_id, - const AdRequest& request) override; - Future Show(UserEarnedRewardListener* listener) override; - bool is_initialized() const override { return initialized_; } - - private: - // Reference to the Java helper object used to interact with the Mobile Ads - // SDK. - jobject helper_; - - // Tracks if this Rewarded Ad has been initialized. - bool initialized_; - - // Mutex to guard against concurrent operations; - Mutex mutex_; -}; - -} // namespace internal -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_ANDROID_REWARDED_AD_INTERNAL_ANDROID_H_ diff --git a/gma/src/android/ump/consent_info_internal_android.cc b/gma/src/android/ump/consent_info_internal_android.cc deleted file mode 100644 index 903b7126cd..0000000000 --- a/gma/src/android/ump/consent_info_internal_android.cc +++ /dev/null @@ -1,668 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/android/ump/consent_info_internal_android.h" - -#include - -#include -#include - -#include "app/src/assert.h" -#include "app/src/thread.h" -#include "app/src/util_android.h" -#include "firebase/internal/common.h" -#include "gma/gma_resources.h" -#include "gma/src/android/gma_android.h" - -namespace firebase { -namespace gma { -namespace ump { -namespace internal { - -ConsentInfoInternalAndroid* ConsentInfoInternalAndroid::s_instance = nullptr; -firebase::Mutex ConsentInfoInternalAndroid::s_instance_mutex; - -// clang-format off -#define CONSENTINFOHELPER_METHODS(X) \ - X(Constructor, "", "(JLandroid/app/Activity;)V"), \ - X(GetConsentStatus, "getConsentStatus", "()I"), \ - X(RequestConsentInfoUpdate, "requestConsentInfoUpdate", \ - "(JZILjava/util/ArrayList;)V"), \ - X(LoadConsentForm, "loadConsentForm", "(J)V"), \ - X(ShowConsentForm, "showConsentForm", "(JLandroid/app/Activity;)Z"), \ - X(LoadAndShowConsentFormIfRequired, "loadAndShowConsentFormIfRequired", \ - "(JLandroid/app/Activity;)V"), \ - X(GetPrivacyOptionsRequirementStatus, "getPrivacyOptionsRequirementStatus", \ - "()I"), \ - X(ShowPrivacyOptionsForm, "showPrivacyOptionsForm", \ - "(JLandroid/app/Activity;)V"), \ - X(Reset, "reset", "()V"), \ - X(CanRequestAds, "canRequestAds", "()Z"), \ - X(IsConsentFormAvailable, "isConsentFormAvailable", "()Z"), \ - X(Disconnect, "disconnect", "()V") -// clang-format on - -// clang-format off -#define CONSENTINFOHELPER_FIELDS(X) \ - X(PrivacyOptionsRequirementUnknown, \ - "PRIVACY_OPTIONS_REQUIREMENT_UNKNOWN", "I", util::kFieldTypeStatic), \ - X(PrivacyOptionsRequirementRequired, \ - "PRIVACY_OPTIONS_REQUIREMENT_REQUIRED", "I", util::kFieldTypeStatic), \ - X(PrivacyOptionsRequirementNotRequired, \ - "PRIVACY_OPTIONS_REQUIREMENT_NOT_REQUIRED", "I", util::kFieldTypeStatic), \ - X(FunctionRequestConsentInfoUpdate, \ - "FUNCTION_REQUEST_CONSENT_INFO_UPDATE", "I", util::kFieldTypeStatic), \ - X(FunctionLoadConsentForm, \ - "FUNCTION_LOAD_CONSENT_FORM", "I", util::kFieldTypeStatic), \ - X(FunctionShowConsentForm, \ - "FUNCTION_SHOW_CONSENT_FORM", "I", util::kFieldTypeStatic), \ - X(FunctionLoadAndShowConsentFormIfRequired, \ - "FUNCTION_LOAD_AND_SHOW_CONSENT_FORM_IF_REQUIRED", \ - "I", util::kFieldTypeStatic), \ - X(FunctionShowPrivacyOptionsForm, \ - "FUNCTION_SHOW_PRIVACY_OPTIONS_FORM", "I", util::kFieldTypeStatic), \ - X(FunctionCount, "FUNCTION_COUNT", "I", util::kFieldTypeStatic) -// clang-format on - -METHOD_LOOKUP_DECLARATION(consent_info_helper, CONSENTINFOHELPER_METHODS, - CONSENTINFOHELPER_FIELDS); - -METHOD_LOOKUP_DEFINITION( - consent_info_helper, - "com/google/firebase/gma/internal/cpp/ConsentInfoHelper", - CONSENTINFOHELPER_METHODS, CONSENTINFOHELPER_FIELDS); - -// clang-format off -#define CONSENTINFORMATION_CONSENTSTATUS_FIELDS(X) \ - X(Unknown, "UNKNOWN", "I", util::kFieldTypeStatic), \ - X(NotRequired, "NOT_REQUIRED", "I", util::kFieldTypeStatic), \ - X(Required, "REQUIRED", "I", util::kFieldTypeStatic), \ - X(Obtained, "OBTAINED", "I", util::kFieldTypeStatic) -// clang-format on - -METHOD_LOOKUP_DECLARATION(consentinformation_consentstatus, METHOD_LOOKUP_NONE, - CONSENTINFORMATION_CONSENTSTATUS_FIELDS); -METHOD_LOOKUP_DEFINITION( - consentinformation_consentstatus, - PROGUARD_KEEP_CLASS - "com/google/android/ump/ConsentInformation$ConsentStatus", - METHOD_LOOKUP_NONE, CONSENTINFORMATION_CONSENTSTATUS_FIELDS); - -// clang-format off -#define FORMERROR_ERRORCODE_FIELDS(X) \ - X(InternalError, "INTERNAL_ERROR", "I", util::kFieldTypeStatic), \ - X(InternetError, "INTERNET_ERROR", "I", util::kFieldTypeStatic), \ - X(InvalidOperation, "INVALID_OPERATION", "I", util::kFieldTypeStatic), \ - X(TimeOut, "TIME_OUT", "I", util::kFieldTypeStatic) -// clang-format on - -METHOD_LOOKUP_DECLARATION(formerror_errorcode, METHOD_LOOKUP_NONE, - FORMERROR_ERRORCODE_FIELDS); -METHOD_LOOKUP_DEFINITION(formerror_errorcode, - PROGUARD_KEEP_CLASS - "com/google/android/ump/FormError$ErrorCode", - METHOD_LOOKUP_NONE, FORMERROR_ERRORCODE_FIELDS); - -// clang-format off -#define CONSENTDEBUGSETTINGS_DEBUGGEOGRAPHY_FIELDS(X) \ - X(Disabled, "DEBUG_GEOGRAPHY_DISABLED", "I", util::kFieldTypeStatic), \ - X(EEA, "DEBUG_GEOGRAPHY_EEA", "I", util::kFieldTypeStatic), \ - X(NotEEA, "DEBUG_GEOGRAPHY_NOT_EEA", "I", util::kFieldTypeStatic) -// clang-format on - -METHOD_LOOKUP_DECLARATION(consentdebugsettings_debuggeography, - METHOD_LOOKUP_NONE, - CONSENTDEBUGSETTINGS_DEBUGGEOGRAPHY_FIELDS); -METHOD_LOOKUP_DEFINITION( - consentdebugsettings_debuggeography, - PROGUARD_KEEP_CLASS - "com/google/android/ump/ConsentDebugSettings$DebugGeography", - METHOD_LOOKUP_NONE, CONSENTDEBUGSETTINGS_DEBUGGEOGRAPHY_FIELDS); - -// This explicitly implements the constructor for the outer class, -// ConsentInfoInternal. -ConsentInfoInternal* ConsentInfoInternal::CreateInstance(JNIEnv* jni_env, - jobject activity) { - ConsentInfoInternalAndroid* ptr = - new ConsentInfoInternalAndroid(jni_env, activity); - if (!ptr->valid()) { - delete ptr; - return nullptr; - } - return ptr; -} - -static void ReleaseClasses(JNIEnv* env) { - consent_info_helper::ReleaseClass(env); - consentinformation_consentstatus::ReleaseClass(env); - formerror_errorcode::ReleaseClass(env); - consentdebugsettings_debuggeography::ReleaseClass(env); -} - -ConsentInfoInternalAndroid::~ConsentInfoInternalAndroid() { - JNIEnv* env = GetJNIEnv(); - env->CallVoidMethod(helper_, consent_info_helper::GetMethodId( - consent_info_helper::kDisconnect)); - - MutexLock lock(s_instance_mutex); - s_instance = nullptr; - - env->DeleteGlobalRef(helper_); - helper_ = nullptr; - - ReleaseClasses(env); - util::Terminate(env); - - env->DeleteGlobalRef(activity_); - activity_ = nullptr; - java_vm_ = nullptr; -} - -// clang-format off -#define ENUM_VALUE(class_namespace, field_name) \ - env->GetStaticIntField(class_namespace::GetClass(), \ - class_namespace::GetFieldId(class_namespace::k##field_name)) -// clang-format on - -void ConsentInfoInternalAndroid::CacheEnumValues(JNIEnv* env) { - // Cache enum values when the class loads, to avoid JNI lookups during - // callbacks later on when converting enums between Android and C++ values. - enums_.consentstatus_unknown = - ENUM_VALUE(consentinformation_consentstatus, Unknown); - enums_.consentstatus_required = - ENUM_VALUE(consentinformation_consentstatus, Required); - enums_.consentstatus_not_required = - ENUM_VALUE(consentinformation_consentstatus, NotRequired); - enums_.consentstatus_obtained = - ENUM_VALUE(consentinformation_consentstatus, Obtained); - - enums_.debug_geography_disabled = - ENUM_VALUE(consentdebugsettings_debuggeography, Disabled); - enums_.debug_geography_eea = - ENUM_VALUE(consentdebugsettings_debuggeography, EEA); - enums_.debug_geography_not_eea = - ENUM_VALUE(consentdebugsettings_debuggeography, NotEEA); - - enums_.formerror_success = 0; - enums_.formerror_internal = ENUM_VALUE(formerror_errorcode, InternalError); - enums_.formerror_network = ENUM_VALUE(formerror_errorcode, InternetError); - enums_.formerror_invalid_operation = - ENUM_VALUE(formerror_errorcode, InvalidOperation); - enums_.formerror_timeout = ENUM_VALUE(formerror_errorcode, TimeOut); - - enums_.privacy_options_requirement_unknown = - ENUM_VALUE(consent_info_helper, PrivacyOptionsRequirementUnknown); - enums_.privacy_options_requirement_required = - ENUM_VALUE(consent_info_helper, PrivacyOptionsRequirementRequired); - enums_.privacy_options_requirement_not_required = - ENUM_VALUE(consent_info_helper, PrivacyOptionsRequirementNotRequired); - - enums_.function_request_consent_info_update = - ENUM_VALUE(consent_info_helper, FunctionRequestConsentInfoUpdate); - enums_.function_load_consent_form = - ENUM_VALUE(consent_info_helper, FunctionLoadConsentForm); - enums_.function_show_consent_form = - ENUM_VALUE(consent_info_helper, FunctionShowConsentForm); - enums_.function_load_and_show_consent_form_if_required = - ENUM_VALUE(consent_info_helper, FunctionLoadAndShowConsentFormIfRequired); - enums_.function_show_privacy_options_form = - ENUM_VALUE(consent_info_helper, FunctionShowPrivacyOptionsForm); - enums_.function_count = ENUM_VALUE(consent_info_helper, FunctionCount); -} - -void ConsentInfoInternalAndroid::JNI_ConsentInfoHelper_completeFuture( - JNIEnv* env, jclass clazz, jint future_fn, jlong consent_info_internal_ptr, - jlong future_handle, jint error_code, jobject error_message_obj) { - MutexLock lock(s_instance_mutex); - if (consent_info_internal_ptr == 0 || s_instance == nullptr) { - // Calling this with a null pointer, or if there is no active - // instance, is a no-op, so just return. - return; - } - ConsentInfoInternalAndroid* instance = - reinterpret_cast(consent_info_internal_ptr); - if (s_instance != instance) { - // If the instance we were called with does not match the current - // instance, a bad race condition has occurred (whereby while waiting for - // the operation to complete, ConsentInfo was deleted and then recreated). - // In that case, fully ignore this callback. - return; - } - std::string error_message = - error_message_obj ? util::JniStringToString(env, error_message_obj) : ""; - instance->CompleteFutureFromJniCallback( - env, future_fn, static_cast(future_handle), - static_cast(error_code), - error_message.length() > 0 ? error_message.c_str() : nullptr); -} - -ConsentInfoInternalAndroid::ConsentInfoInternalAndroid(JNIEnv* env, - jobject activity) - : java_vm_(nullptr), - activity_(nullptr), - helper_(nullptr), - has_requested_consent_info_update_(false) { - MutexLock lock(s_instance_mutex); - FIREBASE_ASSERT(s_instance == nullptr); - s_instance = this; - - util::Initialize(env, activity); - env->GetJavaVM(&java_vm_); - - // Between this and GMA, we only want to load these files once. - { - MutexLock lock( - ::firebase::gma::internal::g_cached_gma_embedded_files_mutex); - if (::firebase::gma::internal::g_cached_gma_embedded_files == nullptr) { - ::firebase::gma::internal::g_cached_gma_embedded_files = - new std::vector(); - *::firebase::gma::internal::g_cached_gma_embedded_files = - util::CacheEmbeddedFiles(env, activity, - firebase::internal::EmbeddedFile::ToVector( - firebase_gma::gma_resources_filename, - firebase_gma::gma_resources_data, - firebase_gma::gma_resources_size)); - } - } - const std::vector& embedded_files = - *::firebase::gma::internal::g_cached_gma_embedded_files; - - if (!(consent_info_helper::CacheClassFromFiles(env, activity, - &embedded_files) != nullptr && - consent_info_helper::CacheMethodIds(env, activity) && - consent_info_helper::CacheFieldIds(env, activity) && - consentinformation_consentstatus::CacheFieldIds(env, activity) && - formerror_errorcode::CacheFieldIds(env, activity) && - consentdebugsettings_debuggeography::CacheFieldIds(env, activity))) { - ReleaseClasses(env); - util::Terminate(env); - return; - } - static const JNINativeMethod kConsentInfoHelperNativeMethods[] = { - {"completeFuture", "(IJJILjava/lang/String;)V", - reinterpret_cast(&JNI_ConsentInfoHelper_completeFuture)}}; - if (!consent_info_helper::RegisterNatives( - env, kConsentInfoHelperNativeMethods, - FIREBASE_ARRAYSIZE(kConsentInfoHelperNativeMethods))) { - util::CheckAndClearJniExceptions(env); - ReleaseClasses(env); - util::Terminate(env); - return; - } - util::CheckAndClearJniExceptions(env); - jobject helper_ref = env->NewObject( - consent_info_helper::GetClass(), - consent_info_helper::GetMethodId(consent_info_helper::kConstructor), - reinterpret_cast(this), activity); - util::CheckAndClearJniExceptions(env); - if (!helper_ref) { - ReleaseClasses(env); - util::Terminate(env); - return; - } - - helper_ = env->NewGlobalRef(helper_ref); - FIREBASE_ASSERT(helper_); - env->DeleteLocalRef(helper_ref); - - activity_ = env->NewGlobalRef(activity); - - util::CheckAndClearJniExceptions(env); - - CacheEnumValues(env); - - util::CheckAndClearJniExceptions(env); -} - -ConsentStatus ConsentInfoInternalAndroid::CppConsentStatusFromAndroid( - jint status) { - if (status == enums().consentstatus_unknown) return kConsentStatusUnknown; - if (status == enums().consentstatus_required) return kConsentStatusRequired; - if (status == enums().consentstatus_not_required) - return kConsentStatusNotRequired; - if (status == enums().consentstatus_obtained) return kConsentStatusObtained; - LogWarning("GMA: Unknown ConsentStatus returned by UMP Android SDK: %d", - (int)status); - return kConsentStatusUnknown; -} - -PrivacyOptionsRequirementStatus -ConsentInfoInternalAndroid::CppPrivacyOptionsRequirementStatusFromAndroid( - jint status) { - if (status == enums().privacy_options_requirement_unknown) - return kPrivacyOptionsRequirementStatusUnknown; - if (status == enums().privacy_options_requirement_required) - return kPrivacyOptionsRequirementStatusRequired; - if (status == enums().privacy_options_requirement_not_required) - return kPrivacyOptionsRequirementStatusNotRequired; - LogWarning( - "GMA: Unknown PrivacyOptionsRequirementStatus returned by UMP Android " - "SDK: %d", - (int)status); - return kPrivacyOptionsRequirementStatusUnknown; -} - -jint ConsentInfoInternalAndroid::AndroidDebugGeographyFromCppDebugGeography( - ConsentDebugGeography geo) { - switch (geo) { - case kConsentDebugGeographyDisabled: - return enums().debug_geography_disabled; - case kConsentDebugGeographyEEA: - return enums().debug_geography_eea; - case kConsentDebugGeographyNonEEA: - return enums().debug_geography_not_eea; - default: - return enums().debug_geography_disabled; - } -} - -// Android uses FormError to report request errors as well. -ConsentRequestError -ConsentInfoInternalAndroid::CppConsentRequestErrorFromAndroidFormError( - jint error, const char* message) { - if (error == enums().formerror_success) return kConsentRequestSuccess; - if (error == enums().formerror_internal) return kConsentRequestErrorInternal; - if (error == enums().formerror_network) return kConsentRequestErrorNetwork; - if (error == enums().formerror_invalid_operation) { - // Error strings taken directly from the UMP Android SDK. - if (message && strcasestr(message, "misconfiguration") != nullptr) - return kConsentRequestErrorMisconfiguration; - else if (message && - strcasestr(message, "requires a valid application ID") != nullptr) - return kConsentRequestErrorInvalidAppId; - else - return kConsentRequestErrorInvalidOperation; - } - LogWarning("GMA: Unknown RequestError returned by UMP Android SDK: %d (%s)", - (int)error, message ? message : ""); - return kConsentRequestErrorUnknown; -} - -ConsentFormError -ConsentInfoInternalAndroid::CppConsentFormErrorFromAndroidFormError( - jint error, const char* message) { - if (error == enums().formerror_success) return kConsentFormSuccess; - if (error == enums().formerror_internal) return kConsentFormErrorInternal; - if (error == enums().formerror_timeout) return kConsentFormErrorTimeout; - if (error == enums().formerror_invalid_operation) { - // Error strings taken directly from the UMP Android SDK. - if (message && strcasestr(message, "no available form") != nullptr) - return kConsentFormErrorUnavailable; - else if (message && strcasestr(message, "form is not required") != nullptr) - return kConsentFormErrorUnavailable; - else if (message && - strcasestr(message, "can only be invoked once") != nullptr) - return kConsentFormErrorAlreadyUsed; - else - return kConsentFormErrorInvalidOperation; - } - LogWarning("GMA: Unknown RequestError returned by UMP Android SDK: %d (%s)", - (int)error, message ? message : ""); - return kConsentFormErrorUnknown; -} - -Future ConsentInfoInternalAndroid::RequestConsentInfoUpdate( - const ConsentRequestParameters& params) { - if (RequestConsentInfoUpdateLastResult().status() == kFutureStatusPending) { - // This operation is already in progress. - // Return a future with an error - this will not override the Fn entry. - SafeFutureHandle error_handle = CreateFuture(); - CompleteFuture(error_handle, kConsentRequestErrorOperationInProgress); - return MakeFuture(futures(), error_handle); - } - - SafeFutureHandle handle = - CreateFuture(kConsentInfoFnRequestConsentInfoUpdate); - JNIEnv* env = GetJNIEnv(); - - jlong future_handle = static_cast(handle.get().id()); - jboolean tag_for_under_age_of_consent = - params.tag_for_under_age_of_consent ? JNI_TRUE : JNI_FALSE; - jint debug_geography = AndroidDebugGeographyFromCppDebugGeography( - params.debug_settings.debug_geography); - jobject debug_device_ids_list = - util::StdVectorToJavaList(env, params.debug_settings.debug_device_ids); - env->CallVoidMethod(helper_, - consent_info_helper::GetMethodId( - consent_info_helper::kRequestConsentInfoUpdate), - future_handle, tag_for_under_age_of_consent, - debug_geography, debug_device_ids_list); - - if (env->ExceptionCheck()) { - std::string exception_message = util::GetAndClearExceptionMessage(env); - CompleteFuture(handle, kConsentRequestErrorInternal, - exception_message.c_str()); - } else { - has_requested_consent_info_update_ = true; - } - env->DeleteLocalRef(debug_device_ids_list); - - return MakeFuture(futures(), handle); -} - -ConsentStatus ConsentInfoInternalAndroid::GetConsentStatus() { - if (!valid()) { - return kConsentStatusUnknown; - } - JNIEnv* env = GetJNIEnv(); - jint result = env->CallIntMethod( - helper_, - consent_info_helper::GetMethodId(consent_info_helper::kGetConsentStatus)); - if (env->ExceptionCheck()) { - util::CheckAndClearJniExceptions(env); - return kConsentStatusUnknown; - } - return CppConsentStatusFromAndroid(result); -} - -ConsentFormStatus ConsentInfoInternalAndroid::GetConsentFormStatus() { - if (!valid() || !has_requested_consent_info_update_) { - return kConsentFormStatusUnknown; - } - JNIEnv* env = GetJNIEnv(); - jboolean is_available = env->CallBooleanMethod( - helper_, consent_info_helper::GetMethodId( - consent_info_helper::kIsConsentFormAvailable)); - if (env->ExceptionCheck()) { - util::CheckAndClearJniExceptions(env); - return kConsentFormStatusUnknown; - } - return (is_available == JNI_FALSE) ? kConsentFormStatusUnavailable - : kConsentFormStatusAvailable; -} - -Future ConsentInfoInternalAndroid::LoadConsentForm() { - if (LoadConsentFormLastResult().status() == kFutureStatusPending) { - // This operation is already in progress. - // Return a future with an error - this will not override the Fn entry. - SafeFutureHandle error_handle = CreateFuture(); - CompleteFuture(error_handle, kConsentFormErrorOperationInProgress); - return MakeFuture(futures(), error_handle); - } - - SafeFutureHandle handle = CreateFuture(kConsentInfoFnLoadConsentForm); - JNIEnv* env = GetJNIEnv(); - jlong future_handle = static_cast(handle.get().id()); - - env->CallVoidMethod( - helper_, - consent_info_helper::GetMethodId(consent_info_helper::kLoadConsentForm), - future_handle); - if (env->ExceptionCheck()) { - std::string exception_message = util::GetAndClearExceptionMessage(env); - CompleteFuture(handle, kConsentFormErrorInternal, - exception_message.c_str()); - } - return MakeFuture(futures(), handle); -} - -Future ConsentInfoInternalAndroid::ShowConsentForm(FormParent parent) { - if (ShowConsentFormLastResult().status() == kFutureStatusPending) { - // This operation is already in progress. - // Return a future with an error - this will not override the Fn entry. - SafeFutureHandle error_handle = CreateFuture(); - CompleteFuture(error_handle, kConsentFormErrorOperationInProgress); - return MakeFuture(futures(), error_handle); - } - - SafeFutureHandle handle = CreateFuture(kConsentInfoFnShowConsentForm); - JNIEnv* env = GetJNIEnv(); - - jlong future_handle = static_cast(handle.get().id()); - jboolean success = env->CallBooleanMethod( - helper_, - consent_info_helper::GetMethodId(consent_info_helper::kShowConsentForm), - future_handle, parent); - if (env->ExceptionCheck()) { - std::string exception_message = util::GetAndClearExceptionMessage(env); - CompleteFuture(handle, kConsentFormErrorInternal, - exception_message.c_str()); - } else if (success == JNI_FALSE) { - CompleteFuture( - handle, kConsentFormErrorUnavailable, - "The consent form is unavailable. Please call LoadConsentForm and " - "ensure it completes successfully before calling ShowConsentForm."); - } - return MakeFuture(futures(), handle); -} - -Future ConsentInfoInternalAndroid::LoadAndShowConsentFormIfRequired( - FormParent parent) { - if (LoadAndShowConsentFormIfRequiredLastResult().status() == - kFutureStatusPending) { - // This operation is already in progress. - // Return a future with an error - this will not override the Fn entry. - SafeFutureHandle error_handle = CreateFuture(); - CompleteFuture(error_handle, kConsentFormErrorOperationInProgress); - return MakeFuture(futures(), error_handle); - } - - SafeFutureHandle handle = - CreateFuture(kConsentInfoFnLoadAndShowConsentFormIfRequired); - - JNIEnv* env = GetJNIEnv(); - jlong future_handle = static_cast(handle.get().id()); - - env->CallVoidMethod( - helper_, - consent_info_helper::GetMethodId( - consent_info_helper::kLoadAndShowConsentFormIfRequired), - future_handle, parent); - if (env->ExceptionCheck()) { - std::string exception_message = util::GetAndClearExceptionMessage(env); - CompleteFuture(handle, kConsentFormErrorInternal, - exception_message.c_str()); - } - - return MakeFuture(futures(), handle); -} - -PrivacyOptionsRequirementStatus -ConsentInfoInternalAndroid::GetPrivacyOptionsRequirementStatus() { - if (!valid()) { - return kPrivacyOptionsRequirementStatusUnknown; - } - JNIEnv* env = GetJNIEnv(); - jint result = env->CallIntMethod( - helper_, consent_info_helper::GetMethodId( - consent_info_helper::kGetPrivacyOptionsRequirementStatus)); - return CppPrivacyOptionsRequirementStatusFromAndroid(result); -} - -Future ConsentInfoInternalAndroid::ShowPrivacyOptionsForm( - FormParent parent) { - if (ShowPrivacyOptionsFormLastResult().status() == kFutureStatusPending) { - // This operation is already in progress. - // Return a future with an error - this will not override the Fn entry. - SafeFutureHandle error_handle = CreateFuture(); - CompleteFuture(error_handle, kConsentFormErrorOperationInProgress); - return MakeFuture(futures(), error_handle); - } - - SafeFutureHandle handle = - CreateFuture(kConsentInfoFnShowPrivacyOptionsForm); - - JNIEnv* env = GetJNIEnv(); - jlong future_handle = static_cast(handle.get().id()); - - env->CallVoidMethod(helper_, - consent_info_helper::GetMethodId( - consent_info_helper::kShowPrivacyOptionsForm), - future_handle, parent); - if (env->ExceptionCheck()) { - std::string exception_message = util::GetAndClearExceptionMessage(env); - CompleteFuture(handle, kConsentFormErrorInternal, - exception_message.c_str()); - } - - return MakeFuture(futures(), handle); -} - -bool ConsentInfoInternalAndroid::CanRequestAds() { - JNIEnv* env = GetJNIEnv(); - jboolean can_request = env->CallBooleanMethod( - helper_, - consent_info_helper::GetMethodId(consent_info_helper::kCanRequestAds)); - if (env->ExceptionCheck()) { - util::CheckAndClearJniExceptions(env); - return false; - } - return (can_request == JNI_FALSE) ? false : true; -} - -void ConsentInfoInternalAndroid::Reset() { - JNIEnv* env = GetJNIEnv(); - env->CallVoidMethod( - helper_, consent_info_helper::GetMethodId(consent_info_helper::kReset)); - util::CheckAndClearJniExceptions(env); -} - -JNIEnv* ConsentInfoInternalAndroid::GetJNIEnv() { - return firebase::util::GetThreadsafeJNIEnv(java_vm_); -} -jobject ConsentInfoInternalAndroid::activity() { return activity_; } - -void ConsentInfoInternalAndroid::CompleteFutureFromJniCallback( - JNIEnv* env, jint future_fn, FutureHandleId handle_id, int java_error_code, - const char* error_message) { - if (!futures()->ValidFuture(handle_id)) { - // This future is no longer valid, so no need to complete it. - return; - } - if (future_fn < 0 || future_fn >= enums().function_count) { - // Called with an invalid function ID, ignore this callback. - return; - } - FutureHandle raw_handle(handle_id); - SafeFutureHandle handle(raw_handle); - if (future_fn == enums().function_request_consent_info_update) { - // RequestConsentInfoUpdate uses the ConsentRequestError enum. - ConsentRequestError error_code = CppConsentRequestErrorFromAndroidFormError( - java_error_code, error_message); - CompleteFuture(handle, error_code, error_message); - } else { - // All other methods use the ConsentFormError enum. - ConsentFormError error_code = - CppConsentFormErrorFromAndroidFormError(java_error_code, error_message); - CompleteFuture(handle, error_code, error_message); - } -} - -} // namespace internal -} // namespace ump -} // namespace gma -} // namespace firebase diff --git a/gma/src/android/ump/consent_info_internal_android.h b/gma/src/android/ump/consent_info_internal_android.h deleted file mode 100644 index 4c0498671f..0000000000 --- a/gma/src/android/ump/consent_info_internal_android.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_ANDROID_UMP_CONSENT_INFO_INTERNAL_ANDROID_H_ -#define FIREBASE_GMA_SRC_ANDROID_UMP_CONSENT_INFO_INTERNAL_ANDROID_H_ - -#include - -#include "app/src/util_android.h" -#include "firebase/internal/mutex.h" -#include "gma/src/common/ump/consent_info_internal.h" - -namespace firebase { -namespace gma { -namespace ump { -namespace internal { - -class ConsentInfoInternalAndroid : public ConsentInfoInternal { - public: - ConsentInfoInternalAndroid(JNIEnv* env, jobject activity); - ~ConsentInfoInternalAndroid() override; - - ConsentStatus GetConsentStatus() override; - ConsentFormStatus GetConsentFormStatus() override; - - Future RequestConsentInfoUpdate( - const ConsentRequestParameters& params) override; - Future LoadConsentForm() override; - Future ShowConsentForm(FormParent parent) override; - - Future LoadAndShowConsentFormIfRequired(FormParent parent) override; - - PrivacyOptionsRequirementStatus GetPrivacyOptionsRequirementStatus() override; - Future ShowPrivacyOptionsForm(FormParent parent) override; - - bool CanRequestAds() override; - - void Reset() override; - - bool valid() { return (helper_ != nullptr); } - - JNIEnv* GetJNIEnv(); - jobject activity(); - - private: - struct EnumCache { - jint consentstatus_unknown; - jint consentstatus_required; - jint consentstatus_not_required; - jint consentstatus_obtained; - - jint formerror_success; - jint formerror_internal; - jint formerror_network; - jint formerror_invalid_operation; - jint formerror_timeout; - - jint debug_geography_disabled; - jint debug_geography_eea; - jint debug_geography_not_eea; - - jint privacy_options_requirement_unknown; - jint privacy_options_requirement_required; - jint privacy_options_requirement_not_required; - - jint function_request_consent_info_update; - jint function_load_consent_form; - jint function_show_consent_form; - jint function_load_and_show_consent_form_if_required; - jint function_show_privacy_options_form; - jint function_count; - }; - - // JNI native method callback for ConsentInfoHelper.completeFuture. - // Calls CompleteFutureFromJniCallback() below. - static void JNI_ConsentInfoHelper_completeFuture( - JNIEnv* env, jclass clazz, jint future_fn, - jlong consent_info_internal_ptr, jlong future_handle, jint error_code, - jobject error_message_obj); - - // Complete the given Future when called from JNI. - void CompleteFutureFromJniCallback(JNIEnv* env, jint future_fn, - FutureHandleId handle_id, int error_code, - const char* error_message); - - // Cache Java enum field values in the struct below. - void CacheEnumValues(JNIEnv* env); - - // Enum conversion methods. - ConsentStatus CppConsentStatusFromAndroid(jint status); - PrivacyOptionsRequirementStatus CppPrivacyOptionsRequirementStatusFromAndroid( - jint status); - jint AndroidDebugGeographyFromCppDebugGeography(ConsentDebugGeography geo); - ConsentRequestError CppConsentRequestErrorFromAndroidFormError( - jint error, const char* message = nullptr); - ConsentFormError CppConsentFormErrorFromAndroidFormError( - jint error, const char* message = nullptr); - - const EnumCache& enums() { return enums_; } - - static ConsentInfoInternalAndroid* s_instance; - static firebase::Mutex s_instance_mutex; - - EnumCache enums_; - - JavaVM* java_vm_; - jobject activity_; - jobject helper_; - - // Needed for GetConsentFormStatus to return Unknown. - bool has_requested_consent_info_update_; -}; - -} // namespace internal -} // namespace ump -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_ANDROID_UMP_CONSENT_INFO_INTERNAL_ANDROID_H_ diff --git a/gma/src/common/ad_error_internal.h b/gma/src/common/ad_error_internal.h deleted file mode 100644 index 78d5cfa3a4..0000000000 --- a/gma/src/common/ad_error_internal.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_COMMON_AD_ERROR_INTERNAL_H_ -#define FIREBASE_GMA_SRC_COMMON_AD_ERROR_INTERNAL_H_ - -#include - -#include "gma/src/common/gma_common.h" -#include "gma/src/include/firebase/gma/types.h" - -namespace firebase { -namespace gma { - -#if FIREBASE_PLATFORM_ANDROID -typedef jobject NativeSdkAdError; -#elif FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS -typedef const NSError* NativeSdkAdError; -#else -typedef void* NativeSdkAdError; -#endif - -struct AdErrorInternal { - // The type of AdError, based on the operation that was requested. - enum AdErrorInternalType { - // Standard AdError type for most Ad operations. - kAdErrorInternalAdError = 1, - // AdError represents an error the GMA SDK wrapper. - kAdErrorInternalWrapperError, - // AdError from a LoadAd operation. - kAdErrorInternalLoadAdError, - // AdError from an attempt to show a full screen ad. - kAdErrorInternalFullScreenContentError, - // AdError from an attempt to show the AdInspector. - kAdErrorInternalOpenAdInspectorError - }; - - // Default constructor. - AdErrorInternal() { - ad_error_type = kAdErrorInternalAdError; - code = kAdErrorCodeNone; - native_ad_error = nullptr; - } - - // The type of AdError, based on the operation that was requested. - AdErrorInternalType ad_error_type; - - // True if this was a successful result. - bool is_successful; - - // An error code. - AdErrorCode code; - - // A cached value of com.google.android.gms.ads.AdError.domain. - std::string domain; - - // A cached value of com.google.android.gms.ads.AdError.message. - std::string message; - - // A cached result from invoking com.google.android.gms.ads.AdError.ToString. - std::string to_string; - - // If this is not a successful result, or if it's a wrapper error, then - // native_ad_error is a reference to a error object returned by the iOS or - // Android GMA SDK. - NativeSdkAdError native_ad_error; - - Mutex mutex; -}; - -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_COMMON_AD_ERROR_INTERNAL_H_ diff --git a/gma/src/common/ad_view.cc b/gma/src/common/ad_view.cc deleted file mode 100644 index 6438fafb5b..0000000000 --- a/gma/src/common/ad_view.cc +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/include/firebase/gma/ad_view.h" - -#include "app/src/assert.h" -#include "app/src/include/firebase/future.h" -#include "gma/src/common/ad_view_internal.h" -#include "gma/src/common/gma_common.h" - -namespace firebase { -namespace gma { - -AdView::AdView() { - FIREBASE_ASSERT(gma::IsInitialized()); - internal_ = internal::AdViewInternal::CreateInstance(this); - GetOrCreateCleanupNotifier()->RegisterObject(this, [](void* object) { - LogWarning("AdView must be deleted before gma::Terminate."); - AdView* ad_view = reinterpret_cast(object); - delete ad_view->internal_; - ad_view->internal_ = nullptr; - }); -} - -AdView::~AdView() { - GetOrCreateCleanupNotifier()->UnregisterObject(this); - delete internal_; -} - -// Initialize must be called before any other methods in the namespace. This -// method asserts that Initialize() has been invoked and allowed to complete. -static bool CheckIsInitialized(internal::AdViewInternal* internal) { - FIREBASE_ASSERT(internal); - return internal->is_initialized(); -} - -Future AdView::Initialize(AdParent parent, const char* ad_unit_id, - const AdSize& size) { - return internal_->Initialize(parent, ad_unit_id, size); -} - -Future AdView::InitializeLastResult() const { - return internal_->GetLastResult(internal::kAdViewFnInitialize); -} - -void AdView::SetAdListener(AdListener* listener) { - internal_->SetAdListener(listener); -} - -void AdView::SetBoundingBoxListener(AdViewBoundingBoxListener* listener) { - internal_->SetBoundingBoxListener(listener); -} - -void AdView::SetPaidEventListener(PaidEventListener* listener) { - internal_->SetPaidEventListener(listener); -} - -Future AdView::SetPosition(int x, int y) { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFuture( - firebase::gma::internal::kAdViewFnSetPosition, - kAdErrorCodeUninitialized, kAdUninitializedErrorMessage, - &internal_->future_data_); - } - return internal_->SetPosition(x, y); -} - -Future AdView::SetPosition(Position position) { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFuture( - firebase::gma::internal::kAdViewFnSetPosition, - kAdErrorCodeUninitialized, kAdUninitializedErrorMessage, - &internal_->future_data_); - } - return internal_->SetPosition(position); -} - -Future AdView::SetPositionLastResult() const { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFuture( - firebase::gma::internal::kAdViewFnSetPosition, - kAdErrorCodeUninitialized, kAdUninitializedErrorMessage, - &internal_->future_data_); - } - return internal_->GetLastResult(internal::kAdViewFnSetPosition); -} - -Future AdView::LoadAd(const AdRequest& request) { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFutureWithResult( - firebase::gma::internal::kAdViewFnLoadAd, kAdErrorCodeUninitialized, - kAdUninitializedErrorMessage, &internal_->future_data_, AdResult()); - } - return internal_->LoadAd(request); -} - -Future AdView::LoadAdLastResult() const { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFutureWithResult( - firebase::gma::internal::kAdViewFnLoadAd, kAdErrorCodeUninitialized, - kAdUninitializedErrorMessage, &(internal_->future_data_), AdResult()); - } - return internal_->GetLoadAdLastResult(); -} - -Future AdView::Hide() { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFuture( - firebase::gma::internal::kAdViewFnHide, kAdErrorCodeUninitialized, - kAdUninitializedErrorMessage, &internal_->future_data_); - } - return internal_->Hide(); -} - -Future AdView::HideLastResult() const { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFuture( - firebase::gma::internal::kAdViewFnHide, kAdErrorCodeUninitialized, - kAdUninitializedErrorMessage, &internal_->future_data_); - } - return internal_->GetLastResult(internal::kAdViewFnHide); -} - -Future AdView::Show() { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFuture( - firebase::gma::internal::kAdViewFnShow, kAdErrorCodeUninitialized, - kAdUninitializedErrorMessage, &internal_->future_data_); - } - return internal_->Show(); -} - -Future AdView::ShowLastResult() const { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFuture( - firebase::gma::internal::kAdViewFnShow, kAdErrorCodeUninitialized, - kAdUninitializedErrorMessage, &internal_->future_data_); - } - return internal_->GetLastResult(internal::kAdViewFnShow); -} - -Future AdView::Pause() { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFuture( - firebase::gma::internal::kAdViewFnPause, kAdErrorCodeUninitialized, - kAdUninitializedErrorMessage, &internal_->future_data_); - } - return internal_->Pause(); -} - -Future AdView::PauseLastResult() const { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFuture( - firebase::gma::internal::kAdViewFnPause, kAdErrorCodeUninitialized, - kAdUninitializedErrorMessage, &internal_->future_data_); - } - return internal_->GetLastResult(internal::kAdViewFnPause); -} - -Future AdView::Resume() { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFuture( - firebase::gma::internal::kAdViewFnResume, kAdErrorCodeUninitialized, - kAdUninitializedErrorMessage, &internal_->future_data_); - } - return internal_->Resume(); -} - -Future AdView::ResumeLastResult() const { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFuture( - firebase::gma::internal::kAdViewFnResume, kAdErrorCodeUninitialized, - kAdUninitializedErrorMessage, &internal_->future_data_); - } - return internal_->GetLastResult(internal::kAdViewFnResume); -} - -Future AdView::Destroy() { return internal_->Destroy(); } - -Future AdView::DestroyLastResult() const { - return internal_->GetLastResult(internal::kAdViewFnDestroy); -} - -BoundingBox AdView::bounding_box() const { - if (!CheckIsInitialized(internal_)) return BoundingBox(); - return internal_->bounding_box(); -} - -AdSize AdView::ad_size() const { return internal_->ad_size(); } - -} // namespace gma -} // namespace firebase diff --git a/gma/src/common/ad_view_internal.cc b/gma/src/common/ad_view_internal.cc deleted file mode 100644 index 47484cc832..0000000000 --- a/gma/src/common/ad_view_internal.cc +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/common/ad_view_internal.h" - -#include "app/src/include/firebase/future.h" -#include "app/src/include/firebase/internal/mutex.h" -#include "app/src/include/firebase/internal/platform.h" -#include "app/src/reference_counted_future_impl.h" -#include "gma/src/include/firebase/gma/ad_view.h" - -#if FIREBASE_PLATFORM_ANDROID -#include "gma/src/android/ad_view_internal_android.h" -#elif FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS -#include "gma/src/ios/ad_view_internal_ios.h" -#else -#include "gma/src/stub/ad_view_internal_stub.h" -#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS, - // FIREBASE_PLATFORM_TVOS - -namespace firebase { -namespace gma { -namespace internal { - -AdViewInternal::AdViewInternal(AdView* base) - : base_(base), - future_data_(kAdViewFnCount), - ad_listener_(nullptr), - ad_size_(0, 0), - bounding_box_listener_(nullptr), - paid_event_listener_(nullptr) {} - -AdViewInternal::~AdViewInternal() { - ad_listener_ = nullptr; - bounding_box_listener_ = nullptr; - paid_event_listener_ = nullptr; - base_ = nullptr; -} - -AdViewInternal* AdViewInternal::CreateInstance(AdView* base) { -#if FIREBASE_PLATFORM_ANDROID - return new AdViewInternalAndroid(base); -#elif FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS - return new AdViewInternalIOS(base); -#else - return new AdViewInternalStub(base); -#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS, - // FIREBASE_PLATFORM_TVOS -} - -void AdViewInternal::SetAdListener(AdListener* listener) { - MutexLock lock(listener_mutex_); - ad_listener_ = listener; -} - -void AdViewInternal::SetBoundingBoxListener( - AdViewBoundingBoxListener* listener) { - MutexLock lock(listener_mutex_); - bounding_box_listener_ = listener; -} - -void AdViewInternal::SetPaidEventListener(PaidEventListener* listener) { - MutexLock lock(listener_mutex_); - paid_event_listener_ = listener; -} - -void AdViewInternal::NotifyListenerOfBoundingBoxChange(BoundingBox box) { - MutexLock lock(listener_mutex_); - if (bounding_box_listener_ != nullptr) { - bounding_box_listener_->OnBoundingBoxChanged(base_, box); - } -} - -void AdViewInternal::NotifyListenerAdClicked() { - MutexLock lock(listener_mutex_); - if (ad_listener_ != nullptr) { - ad_listener_->OnAdClicked(); - } -} - -void AdViewInternal::NotifyListenerAdClosed() { - MutexLock lock(listener_mutex_); - if (ad_listener_ != nullptr) { - ad_listener_->OnAdClosed(); - } -} - -void AdViewInternal::NotifyListenerAdImpression() { - MutexLock lock(listener_mutex_); - if (ad_listener_ != nullptr) { - ad_listener_->OnAdImpression(); - } -} - -void AdViewInternal::NotifyListenerAdOpened() { - MutexLock lock(listener_mutex_); - if (ad_listener_ != nullptr) { - ad_listener_->OnAdOpened(); - } -} - -void AdViewInternal::NotifyListenerOfPaidEvent(const AdValue& ad_value) { - MutexLock lock(listener_mutex_); - if (paid_event_listener_ != nullptr) { - paid_event_listener_->OnPaidEvent(ad_value); - } -} - -Future AdViewInternal::GetLastResult(AdViewFn fn) { - FIREBASE_ASSERT(fn != kAdViewFnLoadAd); - return static_cast&>( - future_data_.future_impl.LastResult(fn)); -} - -Future AdViewInternal::GetLoadAdLastResult() { - return static_cast&>( - future_data_.future_impl.LastResult(kAdViewFnLoadAd)); -} - -void AdViewInternal::update_ad_size_dimensions(int width, int height) { - ad_size_.width_ = width; - ad_size_.height_ = height; -} - -} // namespace internal -} // namespace gma -} // namespace firebase diff --git a/gma/src/common/ad_view_internal.h b/gma/src/common/ad_view_internal.h deleted file mode 100644 index 6ac369114f..0000000000 --- a/gma/src/common/ad_view_internal.h +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_COMMON_AD_VIEW_INTERNAL_H_ -#define FIREBASE_GMA_SRC_COMMON_AD_VIEW_INTERNAL_H_ - -#include "app/src/include/firebase/future.h" -#include "app/src/include/firebase/internal/mutex.h" -#include "gma/src/common/gma_common.h" -#include "gma/src/include/firebase/gma/ad_view.h" - -namespace firebase { -namespace gma { -namespace internal { - -// Constants representing each AdView function that returns a Future. -enum AdViewFn { - kAdViewFnInitialize, - kAdViewFnLoadAd, - kAdViewFnHide, - kAdViewFnShow, - kAdViewFnPause, - kAdViewFnResume, - kAdViewFnDestroy, - kAdViewFnDestroyOnDelete, - kAdViewFnSetPosition, - kAdViewFnCount -}; - -class AdViewInternal { - public: - // Create an instance of whichever subclass of AdViewInternal is - // appropriate for the current platform. - static AdViewInternal* CreateInstance(AdView* base); - - // Virtual destructor is required. - virtual ~AdViewInternal(); - - // Initializes this object and any platform-specific helpers that it uses. - virtual Future Initialize(AdParent parent, const char* ad_unit_id, - const AdSize& size) = 0; - - // Initiates an ad request. - virtual Future LoadAd(const AdRequest& request) = 0; - - // Retrieves the @ref AdView's current onscreen size and location. - virtual BoundingBox bounding_box() const = 0; - - // Sets an AdListener for this ad view. - virtual void SetAdListener(AdListener* listener); - - // Sets a listener to be invoked when the Ad's bounding box - // changes size or location. - virtual void SetBoundingBoxListener(AdViewBoundingBoxListener* listener); - - // Sets a listener to be invoked when this ad is estimated to have earned - // money. - virtual void SetPaidEventListener(PaidEventListener* listener); - - /// Moves the @ref AdView so that its top-left corner is located at - /// (x, y). Coordinates are in pixels from the top-left corner of the screen. - /// - virtual Future SetPosition(int x, int y) = 0; - - /// Moves the @ref AdView so that it's located at the given predefined - /// position. - virtual Future SetPosition(AdView::Position position) = 0; - - // Hides the AdView. - virtual Future Hide() = 0; - - // Displays the AdView. - virtual Future Show() = 0; - - // Pauses any background processes associated with the AdView. - virtual Future Pause() = 0; - - // Resumes from a pause. - virtual Future Resume() = 0; - - // Cleans up any resources used by this object in preparation for a delete. - virtual Future Destroy() = 0; - - // Notifies the Bounding Box listener (if one exists) that the AdView's - // bounding box has changed. - void NotifyListenerOfBoundingBoxChange(BoundingBox box); - - // Notifies the Ad listener (if one exists) that an event has occurred. - void NotifyListenerAdClicked(); - void NotifyListenerAdClosed(); - void NotifyListenerAdImpression(); - void NotifyListenerAdOpened(); - - // Notifies the Paid Event listener (if one exists) that a paid event has - // occurred. - void NotifyListenerOfPaidEvent(const AdValue& ad_value); - - // Retrieves the most recent Future for a given function. - Future GetLastResult(AdViewFn fn); - - // Retrieves the most recent AdResult future for the LoadAd function. - Future GetLoadAdLastResult(); - - // Returns if the AdView has been initialized. - virtual bool is_initialized() const = 0; - - // Returns the size of the loaded ad. - AdSize ad_size() const { return ad_size_; } - - protected: - friend class firebase::gma::AdView; - friend class firebase::gma::GmaInternal; - - // Used by CreateInstance() to create an appropriate one for the current - // platform. - explicit AdViewInternal(AdView* base); - - // Invoked after an AdView has been loaded go reflect the loaded Ad's - // dimensions. These may differ from the requested dimensions if the AdSize - // was one of the adaptive size types. - void update_ad_size_dimensions(int width, int height); - - // A pointer back to the AdView class that created us. - AdView* base_; - - // Future data used to synchronize asynchronous calls. - FutureData future_data_; - - // Listener for AdView Lifecycle event callbacks. - AdListener* ad_listener_; - - // Tracks the size of the AdView. - AdSize ad_size_; - - // Listener for changes in the AdView's bounding box due to - // changes in the AdView's position and visibility. - AdViewBoundingBoxListener* bounding_box_listener_; - - // Listener for any paid events which occur on the AdView. - PaidEventListener* paid_event_listener_; - - // Lock object for accessing listener_. - Mutex listener_mutex_; -}; - -} // namespace internal -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_COMMON_AD_VIEW_INTERNAL_H_ diff --git a/gma/src/common/full_screen_ad_event_listener.cc b/gma/src/common/full_screen_ad_event_listener.cc deleted file mode 100644 index 0a04218167..0000000000 --- a/gma/src/common/full_screen_ad_event_listener.cc +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/common/full_screen_ad_event_listener.h" - -#include "app/src/include/firebase/internal/mutex.h" - -namespace firebase { -namespace gma { -namespace internal { - -void FullScreenAdEventListener::SetFullScreenContentListener( - FullScreenContentListener* listener) { - MutexLock lock(listener_mutex_); - full_screen_content_listener_ = listener; -} - -void FullScreenAdEventListener::SetPaidEventListener( - PaidEventListener* listener) { - MutexLock lock(listener_mutex_); - paid_event_listener_ = listener; -} - -void FullScreenAdEventListener::NotifyListenerOfAdClickedFullScreenContent() { - MutexLock lock(listener_mutex_); - if (full_screen_content_listener_ != nullptr) { - full_screen_content_listener_->OnAdClicked(); - } -} - -void FullScreenAdEventListener::NotifyListenerOfAdDismissedFullScreenContent() { - MutexLock lock(listener_mutex_); - if (full_screen_content_listener_ != nullptr) { - full_screen_content_listener_->OnAdDismissedFullScreenContent(); - } -} - -void FullScreenAdEventListener::NotifyListenerOfAdFailedToShowFullScreenContent( - const AdError& ad_error) { - MutexLock lock(listener_mutex_); - if (full_screen_content_listener_ != nullptr) { - full_screen_content_listener_->OnAdFailedToShowFullScreenContent(ad_error); - } -} - -void FullScreenAdEventListener::NotifyListenerOfAdImpression() { - MutexLock lock(listener_mutex_); - if (full_screen_content_listener_ != nullptr) { - full_screen_content_listener_->OnAdImpression(); - } -} - -void FullScreenAdEventListener::NotifyListenerOfAdShowedFullScreenContent() { - MutexLock lock(listener_mutex_); - if (full_screen_content_listener_ != nullptr) { - full_screen_content_listener_->OnAdShowedFullScreenContent(); - } -} - -void FullScreenAdEventListener::NotifyListenerOfPaidEvent( - const AdValue& ad_value) { - MutexLock lock(listener_mutex_); - if (paid_event_listener_ != nullptr) { - paid_event_listener_->OnPaidEvent(ad_value); - } -} - -} // namespace internal -} // namespace gma -} // namespace firebase diff --git a/gma/src/common/full_screen_ad_event_listener.h b/gma/src/common/full_screen_ad_event_listener.h deleted file mode 100644 index 868d77b902..0000000000 --- a/gma/src/common/full_screen_ad_event_listener.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2022 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_COMMON_FULL_SCREEN_AD_EVENT_LISTENER_H_ -#define FIREBASE_GMA_SRC_COMMON_FULL_SCREEN_AD_EVENT_LISTENER_H_ - -#include "app/src/include/firebase/internal/mutex.h" -#include "gma/src/common/gma_common.h" - -namespace firebase { -namespace gma { -namespace internal { - -// Listener class used by both InterstitialAds and RewardedAds. -class FullScreenAdEventListener { - public: - FullScreenAdEventListener() - : full_screen_content_listener_(nullptr), paid_event_listener_(nullptr) {} - - // Sets the @ref FullScreenContentListener to receive events about UI - // and presentation state. - void SetFullScreenContentListener(FullScreenContentListener* listener); - - // Sets the @ref PaidEventListener to receive information about paid events. - void SetPaidEventListener(PaidEventListener* listener); - - // Notifies the FullScreenContentListener (if one exists) that an event has - // occurred. - virtual void NotifyListenerOfAdClickedFullScreenContent(); - virtual void NotifyListenerOfAdDismissedFullScreenContent(); - virtual void NotifyListenerOfAdFailedToShowFullScreenContent( - const AdError& ad_error); - virtual void NotifyListenerOfAdImpression(); - virtual void NotifyListenerOfAdShowedFullScreenContent(); - - // Notify the PaidEventListener (if one exists) that a paid event has - // occurred. - virtual void NotifyListenerOfPaidEvent(const AdValue& ad_value); - - protected: - // Reference to the listener to which this object sends full screen event - // callbacks. - FullScreenContentListener* full_screen_content_listener_; - - // Reference to the listener to which this object sends ad payout - // event callbacks. - PaidEventListener* paid_event_listener_; - - // Lock object for accessing listener_. - Mutex listener_mutex_; -}; - -} // namespace internal -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_COMMON_FULL_SCREEN_AD_EVENT_LISTENER_H_ diff --git a/gma/src/common/gma_common.cc b/gma/src/common/gma_common.cc deleted file mode 100644 index 777d099030..0000000000 --- a/gma/src/common/gma_common.cc +++ /dev/null @@ -1,436 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/common/gma_common.h" - -#include - -#include -#include - -#include "app/src/cleanup_notifier.h" -#include "app/src/include/firebase/version.h" -#include "app/src/util.h" -#include "gma/src/common/ad_view_internal.h" -#include "gma/src/common/native_ad_internal.h" -#include "gma/src/include/firebase/gma.h" -#include "gma/src/include/firebase/gma/ad_view.h" -#include "gma/src/include/firebase/gma/internal/native_ad.h" -#include "gma/src/include/firebase/gma/internal/query_info.h" -#include "gma/src/include/firebase/gma/interstitial_ad.h" -#include "gma/src/include/firebase/gma/rewarded_ad.h" -#include "gma/src/include/firebase/gma/types.h" - -FIREBASE_APP_REGISTER_CALLBACKS( - gma, - { - if (app == ::firebase::App::GetInstance()) { - firebase::InitResult result; - firebase::gma::Initialize(*app, &result); - return result; - } - return kInitResultSuccess; - }, - { - if (app == ::firebase::App::GetInstance()) { - firebase::gma::Terminate(); - } - }, - false); - -namespace firebase { -namespace gma { - -DEFINE_FIREBASE_VERSION_STRING(FirebaseGma); - -static CleanupNotifier* g_cleanup_notifier = nullptr; -const char kGmaModuleName[] = "gma"; - -// Error messages used for completing futures. These match the error codes in -// the AdError enumeration in the C++ API. -const char* kAdAlreadyInitializedErrorMessage = "Ad is already initialized."; -const char* kAdCouldNotParseAdRequestErrorMessage = - "Could Not Parse AdRequest."; -const char* kAdLoadInProgressErrorMessage = "Ad is currently loading."; -const char* kAdUninitializedErrorMessage = "Ad has not been fully initialized."; -const char* kImageUrlMalformedErrorMessage = - "Image URL is malformed or missing."; -const char* kUnsupportedVariantTypeErrorMessage = "Unsupported variant type."; -const char* kRecordImpressionFailureErrorMessage = - "Failed to record impression."; - -// GmaInternal -void GmaInternal::CompleteLoadAdFutureSuccess( - FutureCallbackData* callback_data, - const ResponseInfoInternal& response_info_internal) { - callback_data->future_data->future_impl.CompleteWithResult( - callback_data->future_handle, static_cast(kAdErrorCodeNone), "", - AdResult(ResponseInfo(response_info_internal))); - delete callback_data; -} - -void GmaInternal::CompleteLoadAdFutureFailure( - FutureCallbackData* callback_data, int error_code, - const std::string& error_message, - const AdErrorInternal& ad_error_internal) { - callback_data->future_data->future_impl.CompleteWithResult( - callback_data->future_handle, static_cast(error_code), - error_message.c_str(), AdResult(CreateAdError(ad_error_internal))); - // This method is responsible for disposing of the callback data struct. - delete callback_data; -} - -void GmaInternal::CompleteLoadImageFutureSuccess( - FutureCallbackData* callback_data, - const std::vector& img_data) { - callback_data->future_data->future_impl.CompleteWithResult( - callback_data->future_handle, static_cast(kAdErrorCodeNone), "", - ImageResult(img_data)); - delete callback_data; -} - -void GmaInternal::CompleteLoadImageFutureFailure( - FutureCallbackData* callback_data, int error_code, - const std::string& error_message) { - callback_data->future_data->future_impl.CompleteWithResult( - callback_data->future_handle, static_cast(error_code), - error_message.c_str(), ImageResult()); - // This method is responsible for disposing of the callback data struct. - delete callback_data; -} - -void GmaInternal::CompleteCreateQueryInfoFutureSuccess( - FutureCallbackData* callback_data, - const std::string& query_info_data) { - callback_data->future_data->future_impl.CompleteWithResult( - callback_data->future_handle, static_cast(kAdErrorCodeNone), "", - QueryInfoResult(query_info_data)); - delete callback_data; -} - -void GmaInternal::CompleteCreateQueryInfoFutureFailure( - FutureCallbackData* callback_data, int error_code, - const std::string& error_message) { - callback_data->future_data->future_impl.CompleteWithResult( - callback_data->future_handle, static_cast(error_code), - error_message.c_str(), QueryInfoResult()); - // This method is responsible for disposing of the callback data struct. - delete callback_data; -} - -AdError GmaInternal::CreateAdError(const AdErrorInternal& ad_error_internal) { - return AdError(ad_error_internal); -} - -void GmaInternal::UpdateAdViewInternalAdSizeDimensions( - internal::AdViewInternal* ad_view_internal, int width, int height) { - assert(ad_view_internal); - ad_view_internal->update_ad_size_dimensions(width, height); -} - -void GmaInternal::InsertNativeInternalImage( - internal::NativeAdInternal* native_ad_internal, - const NativeAdImageInternal& native_image_internal, - const std::string& image_type, const bool& clear_existing_images) { - assert(native_ad_internal); - - if (clear_existing_images) { - native_ad_internal->clear_existing_images(); - } - NativeAdImage image_asset = NativeAdImage(native_image_internal); - native_ad_internal->insert_image(image_asset, image_type); -} - -// AdInspectorClosedListener -AdInspectorClosedListener::~AdInspectorClosedListener() {} - -// AdResult -AdResult::AdResult() : is_successful_(true) {} -AdResult::AdResult(const AdError& ad_error) - : is_successful_(false), ad_error_(ad_error) {} -AdResult::AdResult(const ResponseInfo& response_info) - : is_successful_(true), response_info_(response_info) {} - -AdResult::~AdResult() {} -bool AdResult::is_successful() const { return is_successful_; } -const AdError& AdResult::ad_error() const { return ad_error_; } -const ResponseInfo& AdResult::response_info() const { return response_info_; } - -// ImageResult -ImageResult::ImageResult() : is_successful_(false) {} -ImageResult::ImageResult(const std::vector& image_info) - : is_successful_(true), image_info_(image_info) {} - -ImageResult::~ImageResult() {} -bool ImageResult::is_successful() const { return is_successful_; } -const std::vector& ImageResult::image() const { - return image_info_; -} - -// QueryInfoResult -QueryInfoResult::QueryInfoResult() : is_successful_(false) {} -QueryInfoResult::QueryInfoResult(const std::string& query_info) - : is_successful_(true), query_info_(query_info) {} - -QueryInfoResult::~QueryInfoResult() {} -bool QueryInfoResult::is_successful() const { return is_successful_; } -const std::string& QueryInfoResult::query_info() const { return query_info_; } - -// AdSize -// Hardcoded values are from publicly available documentation: -// https://developers.google.com/android/reference/com/google/android/gms/ads/AdSize -// A dynamic resolution of thes values creates a lot of Android code, -// and these are standards that are not likely to change. -const AdSize AdSize::kBanner(/*width=*/320, /*height=*/50); -const AdSize AdSize::kFullBanner(468, 60); -const AdSize AdSize::kLargeBanner(320, 100); -const AdSize AdSize::kLeaderboard(728, 90); -const AdSize AdSize::kMediumRectangle(300, 250); - -AdSize::AdSize(uint32_t width, uint32_t height) - : orientation_(AdSize::kOrientationCurrent), - width_(width), - height_(height), - type_(AdSize::kTypeStandard) {} - -AdSize AdSize::GetAnchoredAdaptiveBannerAdSize(uint32_t width, - Orientation orientation) { - AdSize ad_size(width, 0); - ad_size.type_ = AdSize::kTypeAnchoredAdaptive; - ad_size.orientation_ = orientation; - return ad_size; -} - -AdSize AdSize::GetLandscapeAnchoredAdaptiveBannerAdSize(uint32_t width) { - return GetAnchoredAdaptiveBannerAdSize(width, AdSize::kOrientationLandscape); -} - -AdSize AdSize::GetPortraitAnchoredAdaptiveBannerAdSize(uint32_t width) { - return GetAnchoredAdaptiveBannerAdSize(width, AdSize::kOrientationPortrait); -} - -AdSize AdSize::GetCurrentOrientationAnchoredAdaptiveBannerAdSize( - uint32_t width) { - return GetAnchoredAdaptiveBannerAdSize(width, AdSize::kOrientationCurrent); -} - -AdSize AdSize::GetCurrentOrientationInlineAdaptiveBannerAdSize(int width) { - AdSize ad_size(width, 0); - ad_size.type_ = AdSize::kTypeInlineAdaptive; - ad_size.orientation_ = AdSize::kOrientationCurrent; - return ad_size; -} - -AdSize AdSize::GetInlineAdaptiveBannerAdSize(int width, int max_height) { - AdSize ad_size(width, max_height); - ad_size.type_ = AdSize::kTypeInlineAdaptive; - return ad_size; -} - -AdSize AdSize::GetLandscapeInlineAdaptiveBannerAdSize(int width) { - AdSize ad_size(width, 0); - ad_size.type_ = AdSize::kTypeInlineAdaptive; - ad_size.orientation_ = AdSize::kOrientationLandscape; - return ad_size; -} - -AdSize AdSize::GetPortraitInlineAdaptiveBannerAdSize(int width) { - AdSize ad_size(width, 0); - ad_size.type_ = AdSize::kTypeInlineAdaptive; - ad_size.orientation_ = AdSize::kOrientationPortrait; - return ad_size; -} - -bool AdSize::is_equal(const AdSize& ad_size) const { - return (type_ == ad_size.type_) && (width_ == ad_size.width_) && - (height_ == ad_size.height_) && (orientation_ == ad_size.orientation_); -} - -bool AdSize::operator==(const AdSize& rhs) const { return is_equal(rhs); } - -bool AdSize::operator!=(const AdSize& rhs) const { return !is_equal(rhs); } - -// AdRequest -// Method implementations of AdRequest which are platform independent. -AdRequest::AdRequest() {} -AdRequest::~AdRequest() {} - -AdRequest::AdRequest(const char* content_url) { set_content_url(content_url); } - -void AdRequest::add_extra(const char* adapter_class_name, const char* extra_key, - const char* extra_value) { - if (adapter_class_name != nullptr && extra_key != nullptr && - extra_value != nullptr) { - extras_[std::string(adapter_class_name)][std::string(extra_key)] = - std::string(extra_value); - } -} - -void AdRequest::add_keyword(const char* keyword) { - if (keyword != nullptr) { - keywords_.insert(std::string(keyword)); - } -} - -void AdRequest::set_content_url(const char* content_url) { - if (content_url == nullptr) { - return; - } - std::string url(content_url); - if (url.size() <= 512) { - content_url_ = url; - } -} - -void AdRequest::add_neighboring_content_urls( - const std::vector& neighboring_content_urls) { - for (auto urls = neighboring_content_urls.begin(); - urls != neighboring_content_urls.end(); ++urls) { - neighboring_content_urls_.insert(*urls); - } -} - -// Non-inline implementation of the virtual destructors, to prevent -// their vtables from being emitted in each translation unit. -AdapterResponseInfo::~AdapterResponseInfo() {} -AdListener::~AdListener() {} -AdViewBoundingBoxListener::~AdViewBoundingBoxListener() {} -FullScreenContentListener::~FullScreenContentListener() {} -PaidEventListener::~PaidEventListener() {} -UserEarnedRewardListener::~UserEarnedRewardListener() {} - -void RegisterTerminateOnDefaultAppDestroy() { - if (!AppCallback::GetEnabledByName(kGmaModuleName)) { - // It's possible to initialize GMA without firebase::App so only register - // for cleanup notifications if the default app exists. - App* app = App::GetInstance(); - if (app) { - CleanupNotifier* cleanup_notifier = CleanupNotifier::FindByOwner(app); - assert(cleanup_notifier); - cleanup_notifier->RegisterObject(const_cast(kGmaModuleName), - [](void*) { - if (firebase::gma::IsInitialized()) { - firebase::gma::Terminate(); - } - }); - } - } -} - -void UnregisterTerminateOnDefaultAppDestroy() { - if (!AppCallback::GetEnabledByName(kGmaModuleName)) { - App* app = App::GetInstance(); - if (app) { - CleanupNotifier* cleanup_notifier = CleanupNotifier::FindByOwner(app); - assert(cleanup_notifier); - cleanup_notifier->UnregisterObject(const_cast(kGmaModuleName)); - } - } -} - -CleanupNotifier* GetOrCreateCleanupNotifier() { - if (!g_cleanup_notifier) { - g_cleanup_notifier = new CleanupNotifier(); - } - return g_cleanup_notifier; -} - -void DestroyCleanupNotifier() { - delete g_cleanup_notifier; - g_cleanup_notifier = nullptr; -} - -const char* GetRequestAgentString() { - // This is a string that can be used to uniquely identify requests coming - // from this version of the library. - return "firebase-cpp-api." FIREBASE_VERSION_NUMBER_STRING; -} - -// Mark a future as complete. -void CompleteFuture(int error, const char* error_msg, - SafeFutureHandle handle, FutureData* future_data) { - if (future_data->future_impl.ValidFuture(handle)) { - future_data->future_impl.Complete(handle, error, error_msg); - } -} - -// For calls that aren't asynchronous, we can create and complete at the -// same time. -Future CreateAndCompleteFuture(int fn_idx, int error, - const char* error_msg, - FutureData* future_data) { - SafeFutureHandle handle = CreateFuture(fn_idx, future_data); - CompleteFuture(error, error_msg, handle, future_data); - return MakeFuture(&future_data->future_impl, handle); -} - -Future CreateAndCompleteFutureWithResult(int fn_idx, int error, - const char* error_msg, - FutureData* future_data, - const AdResult& result) { - SafeFutureHandle handle = - CreateFuture(fn_idx, future_data); - CompleteFuture(error, error_msg, handle, future_data, result); - return MakeFuture(&future_data->future_impl, handle); -} - -Future CreateAndCompleteFutureWithImageResult( - int fn_idx, int error, const char* error_msg, FutureData* future_data, - const ImageResult& result) { - SafeFutureHandle handle = - CreateFuture(fn_idx, future_data); - CompleteFuture(error, error_msg, handle, future_data, result); - return MakeFuture(&future_data->future_impl, handle); -} - -Future CreateAndCompleteFutureWithQueryInfoResult( - int fn_idx, int error, const char* error_msg, FutureData* future_data, - const QueryInfoResult& result) { - SafeFutureHandle handle = - CreateFuture(fn_idx, future_data); - CompleteFuture(error, error_msg, handle, future_data, result); - return MakeFuture(&future_data->future_impl, handle); -} - -FutureCallbackData* CreateVoidFutureCallbackData( - int fn_idx, FutureData* future_data) { - return new FutureCallbackData{ - future_data, future_data->future_impl.SafeAlloc(fn_idx)}; -} - -FutureCallbackData* CreateAdResultFutureCallbackData( - int fn_idx, FutureData* future_data) { - return new FutureCallbackData{ - future_data, - future_data->future_impl.SafeAlloc(fn_idx, AdResult())}; -} - -FutureCallbackData* CreateImageResultFutureCallbackData( - int fn_idx, FutureData* future_data) { - return new FutureCallbackData{ - future_data, - future_data->future_impl.SafeAlloc(fn_idx, ImageResult())}; -} - -FutureCallbackData* CreateQueryInfoResultFutureCallbackData( - int fn_idx, FutureData* future_data) { - return new FutureCallbackData{ - future_data, future_data->future_impl.SafeAlloc( - fn_idx, QueryInfoResult())}; -} - -} // namespace gma -} // namespace firebase diff --git a/gma/src/common/gma_common.h b/gma/src/common/gma_common.h deleted file mode 100644 index 8d2619152d..0000000000 --- a/gma/src/common/gma_common.h +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_COMMON_GMA_COMMON_H_ -#define FIREBASE_GMA_SRC_COMMON_GMA_COMMON_H_ - -#include - -#include -#include -#include -#include - -#include "app/src/cleanup_notifier.h" -#include "app/src/reference_counted_future_impl.h" -#include "gma/src/include/firebase/gma/internal/native_ad.h" -#include "gma/src/include/firebase/gma/internal/query_info.h" -#include "gma/src/include/firebase/gma/types.h" - -namespace firebase { -namespace gma { - -// Error messages used for completing futures. These match the error codes in -// the AdErrorCode enumeration in the C++ API. -extern const char* kAdAlreadyInitializedErrorMessage; -extern const char* kAdCouldNotParseAdRequestErrorMessage; -extern const char* kAdLoadInProgressErrorMessage; -extern const char* kAdUninitializedErrorMessage; -extern const char* kImageUrlMalformedErrorMessage; -extern const char* kUnsupportedVariantTypeErrorMessage; -extern const char* kRecordImpressionFailureErrorMessage; - -namespace internal { -class AdViewInternal; -class NativeAdInternal; -} // namespace internal - -// Determine whether GMA is initialized. -bool IsInitialized(); - -// Registers a cleanup task for this module if auto-initialization is disabled. -void RegisterTerminateOnDefaultAppDestroy(); - -// Unregisters the cleanup task for this module if auto-initialization is -// disabled. -void UnregisterTerminateOnDefaultAppDestroy(); - -// Get the cleanup notifier for the GMA module, creating one if it doesn't -// exist. This allows all objects that depend upon GMA's lifecycle to be -// cleaned up if the module is terminated. -CleanupNotifier* GetOrCreateCleanupNotifier(); - -// Destroy the cleanup notifier. -void DestroyCleanupNotifier(); - -// Returns the request agent string for this library. -const char* GetRequestAgentString(); - -// Hold backing data for returned Futures. -struct FutureData { - explicit FutureData(int num_functions_that_return_futures) - : future_impl(num_functions_that_return_futures) {} - - // Handle calls from Futures that the API returns. - ReferenceCountedFutureImpl future_impl; -}; - -// Create a future and update the corresponding last result. -template -SafeFutureHandle CreateFuture(int fn_idx, FutureData* future_data); - -// Mark a future as complete. -void CompleteFuture(int error, const char* error_msg, - SafeFutureHandle handle, FutureData* future_data); - -template -void CompleteFuture(int error, const char* error_msg, - SafeFutureHandle handle, FutureData* future_data, - const T& result); - -// For calls that aren't asynchronous, create and complete the future at the -// same time. -Future CreateAndCompleteFuture(int fn_idx, int error, - const char* error_msg, - FutureData* future_data); - -// For calls that aren't asynchronous, create and complete a future with a -// result at the same time. -Future CreateAndCompleteFutureWithResult(int fn_idx, int error, - const char* error_msg, - FutureData* future_data, - const AdResult& result); - -// For calls that aren't asynchronous, create and complete a future with a -// result at the same time. -Future CreateAndCompleteFutureWithImageResult( - int fn_idx, int error, const char* error_msg, FutureData* future_data, - const ImageResult& result); - -// For calls that aren't asynchronous, create and complete a future with a -// result at the same time. -Future CreateAndCompleteFutureWithQueryInfoResult( - int fn_idx, int error, const char* error_msg, FutureData* future_data, - const QueryInfoResult& result); - -template -struct FutureCallbackData { - FutureData* future_data; - SafeFutureHandle future_handle; -}; - -// Constructs a FutureCallbackData instance to handle operations that return -// void Futures. -FutureCallbackData* CreateVoidFutureCallbackData(int fn_idx, - FutureData* future_data); - -// Constructs a FutureCallbackData instance to handle results from LoadAd -// requests. -FutureCallbackData* CreateAdResultFutureCallbackData( - int fn_idx, FutureData* future_data); - -// Constructs a FutureCallbackData instance to handle results from LoadImage -// requests. -FutureCallbackData* CreateImageResultFutureCallbackData( - int fn_idx, FutureData* future_data); - -// Constructs a FutureCallbackData instance to handle results from -// createQueryInfo requests. -FutureCallbackData* CreateQueryInfoResultFutureCallbackData( - int fn_idx, FutureData* future_data); - -// Template function implementations. -template -SafeFutureHandle CreateFuture(int fn_idx, FutureData* future_data) { - return future_data->future_impl.SafeAlloc(fn_idx); -} -template -void CompleteFuture(int error, const char* error_msg, - SafeFutureHandle handle, FutureData* future_data, - const T& result) { - future_data->future_impl.CompleteWithResult(handle, error, error_msg, result); -} - -// A class that allows access to private/protected GMA structures for Java -// callbacks. This is achieved via friend relationships with those classes. -class GmaInternal { - public: - // Completes an AdResult future with a successful result. - static void CompleteLoadAdFutureSuccess( - FutureCallbackData* callback_data, - const ResponseInfoInternal& response_info); - - // Completes an AdResult future as an error given the AdErrorInternal object. - static void CompleteLoadAdFutureFailure( - FutureCallbackData* callback_data, int error_code, - const std::string& error_message, - const AdErrorInternal& ad_error_internal); - - // Completes an ImageResult future with a successful result. - static void CompleteLoadImageFutureSuccess( - FutureCallbackData* callback_data, - const std::vector& img_data); - - // Completes an ImageResult future as an error. - static void CompleteLoadImageFutureFailure( - FutureCallbackData* callback_data, int error_code, - const std::string& error_message); - - // Completes an QueryInfoResult future with a successful result. - static void CompleteCreateQueryInfoFutureSuccess( - FutureCallbackData* callback_data, - const std::string& query_info_data); - - // Completes an QueryInfoResult future as an error. - static void CompleteCreateQueryInfoFutureFailure( - FutureCallbackData* callback_data, int error_code, - const std::string& error_message); - - // Constructs and returns an AdError object given an AdErrorInternal object. - static AdError CreateAdError(const AdErrorInternal& ad_error_internal); - - // Construct and return an AdapterStatus with the given values. - static AdapterStatus CreateAdapterStatus(const std::string& description, - bool is_initialized, int latency) { - AdapterStatus status; - status.description_ = description; - status.is_initialized_ = is_initialized; - status.latency_ = latency; - return status; - } - - // Construct and return an AdapterInitializationStatus with the given - // statuses. - static AdapterInitializationStatus CreateAdapterInitializationStatus( - const std::map& status_map) { - AdapterInitializationStatus init_status; - init_status.adapter_status_map_ = status_map; - return init_status; - } - - // Update the AdViewInternal's AdSize width and height after it has been - // loaded as AdViews with adaptive AdSizes may have varying dimensions. - // This is done through the GmaInternal since it's a friend of AdViewInternal. - static void UpdateAdViewInternalAdSizeDimensions( - internal::AdViewInternal* ad_view_internal, int width, int height); - - // Add to the NativeAdInternal's image assets, after the native ad has loaded. - // This is done through the GmaInternal since it's a friend of - // NativeAdInternal. - static void InsertNativeInternalImage( - internal::NativeAdInternal* native_ad_internal, - const NativeAdImageInternal& native_image_internal, - const std::string& image_type, const bool& clear_existing_images); -}; - -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_COMMON_GMA_COMMON_H_ diff --git a/gma/src/common/interstitial_ad.cc b/gma/src/common/interstitial_ad.cc deleted file mode 100644 index 212eb5bda3..0000000000 --- a/gma/src/common/interstitial_ad.cc +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/include/firebase/gma/interstitial_ad.h" - -#include "app/src/assert.h" -#include "app/src/include/firebase/future.h" -#include "gma/src/common/gma_common.h" -#include "gma/src/common/interstitial_ad_internal.h" - -namespace firebase { -namespace gma { - -InterstitialAd::InterstitialAd() { - FIREBASE_ASSERT(gma::IsInitialized()); - internal_ = internal::InterstitialAdInternal::CreateInstance(this); - - GetOrCreateCleanupNotifier()->RegisterObject(this, [](void* object) { - LogWarning("InterstitialAd must be deleted before gma::Terminate."); - InterstitialAd* interstitial_ad = reinterpret_cast(object); - delete interstitial_ad->internal_; - interstitial_ad->internal_ = nullptr; - }); -} - -InterstitialAd::~InterstitialAd() { - GetOrCreateCleanupNotifier()->UnregisterObject(this); - delete internal_; -} - -// Initialize must be called before any other methods in the namespace. This -// method asserts that Initialize() has been invoked and allowed to complete. -static bool CheckIsInitialized(internal::InterstitialAdInternal* internal) { - FIREBASE_ASSERT(internal); - return internal->is_initialized(); -} - -Future InterstitialAd::Initialize(AdParent parent) { - return internal_->Initialize(parent); -} - -Future InterstitialAd::InitializeLastResult() const { - return internal_->GetLastResult(internal::kInterstitialAdFnInitialize); -} - -Future InterstitialAd::LoadAd(const char* ad_unit_id, - const AdRequest& request) { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFutureWithResult( - firebase::gma::internal::kInterstitialAdFnLoadAd, - kAdErrorCodeUninitialized, kAdUninitializedErrorMessage, - &internal_->future_data_, AdResult()); - } - - return internal_->LoadAd(ad_unit_id, request); -} - -Future InterstitialAd::LoadAdLastResult() const { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFutureWithResult( - firebase::gma::internal::kInterstitialAdFnLoadAd, - kAdErrorCodeUninitialized, kAdUninitializedErrorMessage, - &internal_->future_data_, AdResult()); - } - return internal_->GetLoadAdLastResult(); -} - -Future InterstitialAd::Show() { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFuture( - firebase::gma::internal::kInterstitialAdFnShow, - kAdErrorCodeUninitialized, kAdUninitializedErrorMessage, - &internal_->future_data_); - } - return internal_->Show(); -} - -Future InterstitialAd::ShowLastResult() const { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFuture( - firebase::gma::internal::kInterstitialAdFnShow, - kAdErrorCodeUninitialized, kAdUninitializedErrorMessage, - &internal_->future_data_); - } - return internal_->GetLastResult(internal::kInterstitialAdFnShow); -} - -void InterstitialAd::SetFullScreenContentListener( - FullScreenContentListener* listener) { - internal_->SetFullScreenContentListener(listener); -} - -void InterstitialAd::SetPaidEventListener(PaidEventListener* listener) { - internal_->SetPaidEventListener(listener); -} - -} // namespace gma -} // namespace firebase diff --git a/gma/src/common/interstitial_ad_internal.cc b/gma/src/common/interstitial_ad_internal.cc deleted file mode 100644 index 1e46716760..0000000000 --- a/gma/src/common/interstitial_ad_internal.cc +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/common/interstitial_ad_internal.h" - -#include "app/src/include/firebase/future.h" -#include "app/src/include/firebase/internal/mutex.h" -#include "app/src/include/firebase/internal/platform.h" -#include "app/src/reference_counted_future_impl.h" -#include "gma/src/include/firebase/gma/interstitial_ad.h" - -#if FIREBASE_PLATFORM_ANDROID -#include "gma/src/android/interstitial_ad_internal_android.h" -#elif FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS -#include "gma/src/ios/interstitial_ad_internal_ios.h" -#else -#include "gma/src/stub/interstitial_ad_internal_stub.h" -#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS, - // FIREBASE_PLATFORM_TVOS - -namespace firebase { -namespace gma { -namespace internal { - -InterstitialAdInternal::InterstitialAdInternal(InterstitialAd* base) - : base_(base), future_data_(kInterstitialAdFnCount) {} - -InterstitialAdInternal* InterstitialAdInternal::CreateInstance( - InterstitialAd* base) { -#if FIREBASE_PLATFORM_ANDROID - return new InterstitialAdInternalAndroid(base); -#elif FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS - return new InterstitialAdInternalIOS(base); -#else - return new InterstitialAdInternalStub(base); -#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS, - // FIREBASE_PLATFORM_TVOS -} - -Future InterstitialAdInternal::GetLastResult(InterstitialAdFn fn) { - return static_cast&>( - future_data_.future_impl.LastResult(fn)); -} - -Future InterstitialAdInternal::GetLoadAdLastResult() { - return static_cast&>( - future_data_.future_impl.LastResult(kInterstitialAdFnLoadAd)); -} - -} // namespace internal -} // namespace gma -} // namespace firebase diff --git a/gma/src/common/interstitial_ad_internal.h b/gma/src/common/interstitial_ad_internal.h deleted file mode 100644 index 54b71e0f00..0000000000 --- a/gma/src/common/interstitial_ad_internal.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_COMMON_INTERSTITIAL_AD_INTERNAL_H_ -#define FIREBASE_GMA_SRC_COMMON_INTERSTITIAL_AD_INTERNAL_H_ - -#include "app/src/include/firebase/future.h" -#include "app/src/include/firebase/internal/mutex.h" -#include "gma/src/common/full_screen_ad_event_listener.h" -#include "gma/src/common/gma_common.h" -#include "gma/src/include/firebase/gma/interstitial_ad.h" - -namespace firebase { -namespace gma { -namespace internal { - -// Constants representing each InterstitialAd function that returns a Future. -enum InterstitialAdFn { - kInterstitialAdFnInitialize, - kInterstitialAdFnLoadAd, - kInterstitialAdFnShow, - kInterstitialAdFnCount -}; - -class InterstitialAdInternal : public FullScreenAdEventListener { - public: - // Create an instance of whichever subclass of InterstitialAdInternal is - // appropriate for the current platform. - static InterstitialAdInternal* CreateInstance(InterstitialAd* base); - - // Virtual destructor is required. - virtual ~InterstitialAdInternal() = default; - - // Initializes this object and any platform-specific helpers that it uses. - virtual Future Initialize(AdParent parent) = 0; - - // Initiates an ad request. - virtual Future LoadAd(const char* ad_unit_id, - const AdRequest& request) = 0; - - // Displays an interstitial ad. - virtual Future Show() = 0; - - // Retrieves the most recent Future for a given function. - Future GetLastResult(InterstitialAdFn fn); - - // Retrieves the most recent AdResult future for the LoadAd function. - Future GetLoadAdLastResult(); - - // Returns true if the InterstitialAd has been initialized. - virtual bool is_initialized() const = 0; - - protected: - friend class firebase::gma::InterstitialAd; - - // Used by CreateInstance() to create an appropriate one for the current - // platform. - explicit InterstitialAdInternal(InterstitialAd* base); - - // A pointer back to the InterstitialAd class that created us. - InterstitialAd* base_; - - // Future data used to synchronize asynchronous calls. - FutureData future_data_; -}; - -} // namespace internal -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_COMMON_INTERSTITIAL_AD_INTERNAL_H_ diff --git a/gma/src/common/native_ad.cc b/gma/src/common/native_ad.cc deleted file mode 100644 index 8a1a62e9a5..0000000000 --- a/gma/src/common/native_ad.cc +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/include/firebase/gma/internal/native_ad.h" - -#include "app/src/assert.h" -#include "app/src/include/firebase/future.h" -#include "app/src/include/firebase/variant.h" -#include "gma/src/common/gma_common.h" -#include "gma/src/common/native_ad_internal.h" - -namespace firebase { -namespace gma { - -NativeAd::NativeAd() { - FIREBASE_ASSERT(gma::IsInitialized()); - internal_ = internal::NativeAdInternal::CreateInstance(this); - - GetOrCreateCleanupNotifier()->RegisterObject(this, [](void* object) { - LogWarning("NativeAd must be deleted before gma::Terminate."); - NativeAd* native_ad = reinterpret_cast(object); - delete native_ad->internal_; - native_ad->internal_ = nullptr; - }); -} - -NativeAd::~NativeAd() { - FIREBASE_ASSERT(internal_); - - GetOrCreateCleanupNotifier()->UnregisterObject(this); - delete internal_; -} - -// Initialize must be called before any other methods in the namespace. This -// method asserts that Initialize() has been invoked and allowed to complete. -static bool CheckIsInitialized(internal::NativeAdInternal* internal) { - FIREBASE_ASSERT(internal); - return internal->is_initialized(); -} - -Future NativeAd::Initialize(AdParent parent) { - return internal_->Initialize(parent); -} - -Future NativeAd::InitializeLastResult() const { - return internal_->GetLastResult(internal::kNativeAdFnInitialize); -} - -Future NativeAd::LoadAd(const char* ad_unit_id, - const AdRequest& request) { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFutureWithResult( - firebase::gma::internal::kNativeAdFnLoadAd, kAdErrorCodeUninitialized, - kAdUninitializedErrorMessage, &internal_->future_data_, AdResult()); - } - - return internal_->LoadAd(ad_unit_id, request); -} - -Future NativeAd::LoadAdLastResult() const { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFutureWithResult( - firebase::gma::internal::kNativeAdFnLoadAd, kAdErrorCodeUninitialized, - kAdUninitializedErrorMessage, &internal_->future_data_, AdResult()); - } - return internal_->GetLoadAdLastResult(); -} - -void NativeAd::SetAdListener(AdListener* listener) { - internal_->SetAdListener(listener); -} - -const NativeAdImage& NativeAd::icon() const { return internal_->icon(); } - -const std::vector& NativeAd::images() const { - return internal_->images(); -} - -const NativeAdImage& NativeAd::adchoices_icon() const { - return internal_->adchoices_icon(); -} - -Future NativeAd::RecordImpression(const Variant& impression_data) { - if (!impression_data.is_map()) { - return CreateAndCompleteFuture( - firebase::gma::internal::kNativeAdFnRecordImpression, - kAdErrorCodeInvalidArgument, kUnsupportedVariantTypeErrorMessage, - &internal_->future_data_); - } - return internal_->RecordImpression(impression_data); -} - -Future NativeAd::RecordImpressionLastResult() const { - return internal_->GetLastResult( - firebase::gma::internal::kNativeAdFnRecordImpression); -} - -Future NativeAd::PerformClick(const Variant& click_data) { - if (!click_data.is_map()) { - return CreateAndCompleteFuture( - firebase::gma::internal::kNativeAdFnPerformClick, - kAdErrorCodeInvalidArgument, kUnsupportedVariantTypeErrorMessage, - &internal_->future_data_); - } - return internal_->PerformClick(click_data); -} - -Future NativeAd::PerformClickLastResult() const { - return internal_->GetLastResult( - firebase::gma::internal::kNativeAdFnPerformClick); -} - -} // namespace gma -} // namespace firebase diff --git a/gma/src/common/native_ad_image_internal.h b/gma/src/common/native_ad_image_internal.h deleted file mode 100644 index 15b89ec881..0000000000 --- a/gma/src/common/native_ad_image_internal.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_COMMON_NATIVE_AD_IMAGE_INTERNAL_H_ -#define FIREBASE_GMA_SRC_COMMON_NATIVE_AD_IMAGE_INTERNAL_H_ - -#include - -#include "app/src/include/firebase/future.h" -#include "gma/src/common/gma_common.h" -#include "gma/src/include/firebase/gma/internal/native_ad.h" - -namespace firebase { -namespace gma { - -#if FIREBASE_PLATFORM_ANDROID -typedef jobject NativeSdkNativeAdImage; -#elif FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS -typedef NSObject* NativeSdkNativeAdImage; -#else -typedef void* NativeSdkNativeAdImage; -#endif - -enum NativeAdImageFn { kNativeAdImageFnLoadImage, kNativeImageFnCount }; - -struct NativeAdImageInternal { - // Default constructor. - NativeAdImageInternal() : future_data(kNativeImageFnCount) { - native_ad_image = nullptr; - helper = nullptr; - callback_data = nullptr; - } - - // A cached value of native ad image URI. - std::string uri; - - // A cached value of native ad image scale. - double scale; - - // Future data used to synchronize asynchronous calls. - FutureData future_data; - - // native_ad_image is a reference to a NativeAdImage object returned by the - // iOS or Android GMA SDK. - NativeSdkNativeAdImage native_ad_image; - - // helper is a reference to a download helper object. - NativeSdkNativeAdImage helper; - - // Contains information to asynchronously complete the LoadImage Future. - FutureCallbackData* callback_data; - - Mutex mutex; -}; - -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_COMMON_NATIVE_AD_IMAGE_INTERNAL_H_ diff --git a/gma/src/common/native_ad_internal.cc b/gma/src/common/native_ad_internal.cc deleted file mode 100644 index 78d9e07abd..0000000000 --- a/gma/src/common/native_ad_internal.cc +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/common/native_ad_internal.h" - -#include - -#include "app/src/include/firebase/future.h" -#include "app/src/include/firebase/internal/mutex.h" -#include "app/src/include/firebase/internal/platform.h" -#include "app/src/reference_counted_future_impl.h" -#include "gma/src/include/firebase/gma/internal/native_ad.h" - -#if FIREBASE_PLATFORM_ANDROID -#include "gma/src/android/native_ad_internal_android.h" -#elif FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS -#include "gma/src/ios/native_ad_internal_ios.h" -#else -#include "gma/src/stub/native_ad_internal_stub.h" -#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS, - // FIREBASE_PLATFORM_TVOS - -namespace firebase { -namespace gma { -namespace internal { - -NativeAdInternal::NativeAdInternal(NativeAd* base) - : base_(base), future_data_(kNativeAdFnCount), ad_listener_(nullptr) {} - -NativeAdInternal* NativeAdInternal::CreateInstance(NativeAd* base) { -#if FIREBASE_PLATFORM_ANDROID - return new NativeAdInternalAndroid(base); -#elif FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS - return new NativeAdInternalIOS(base); -#else - return new NativeAdInternalStub(base); -#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS, - // FIREBASE_PLATFORM_TVOS -} - -Future NativeAdInternal::GetLastResult(NativeAdFn fn) { - return static_cast&>( - future_data_.future_impl.LastResult(fn)); -} - -Future NativeAdInternal::GetLoadAdLastResult() { - return static_cast&>( - future_data_.future_impl.LastResult(kNativeAdFnLoadAd)); -} - -void NativeAdInternal::SetAdListener(AdListener* listener) { - MutexLock lock(listener_mutex_); - ad_listener_ = listener; -} - -void NativeAdInternal::NotifyListenerAdClicked() { - MutexLock lock(listener_mutex_); - if (ad_listener_ != nullptr) { - ad_listener_->OnAdClicked(); - } -} - -void NativeAdInternal::NotifyListenerAdClosed() { - MutexLock lock(listener_mutex_); - if (ad_listener_ != nullptr) { - ad_listener_->OnAdClosed(); - } -} - -void NativeAdInternal::NotifyListenerAdImpression() { - MutexLock lock(listener_mutex_); - if (ad_listener_ != nullptr) { - ad_listener_->OnAdImpression(); - } -} - -void NativeAdInternal::NotifyListenerAdOpened() { - MutexLock lock(listener_mutex_); - if (ad_listener_ != nullptr) { - ad_listener_->OnAdOpened(); - } -} - -void NativeAdInternal::insert_image(const NativeAdImage& image, - const std::string& image_type) { - if (image_type == "icon") { - icon_ = image; - } else if (image_type == "adchoices_icon") { - adchoices_icon_ = image; - } else { - images_.push_back(image); - } -} - -void NativeAdInternal::clear_existing_images() { images_.clear(); } - -} // namespace internal -} // namespace gma -} // namespace firebase diff --git a/gma/src/common/native_ad_internal.h b/gma/src/common/native_ad_internal.h deleted file mode 100644 index cb9dd822d4..0000000000 --- a/gma/src/common/native_ad_internal.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_COMMON_NATIVE_AD_INTERNAL_H_ -#define FIREBASE_GMA_SRC_COMMON_NATIVE_AD_INTERNAL_H_ - -#include -#include - -#include "app/src/include/firebase/future.h" -#include "app/src/include/firebase/internal/mutex.h" -#include "app/src/include/firebase/variant.h" -#include "gma/src/common/gma_common.h" -#include "gma/src/include/firebase/gma/internal/native_ad.h" - -namespace firebase { -namespace gma { -namespace internal { - -// Constants representing each NativeAd function that returns a Future. -enum NativeAdFn { - kNativeAdFnInitialize, - kNativeAdFnLoadAd, - kNativeAdFnRecordImpression, - kNativeAdFnPerformClick, - kNativeAdFnCount -}; - -class NativeAdInternal { - public: - // Create an instance of whichever subclass of NativeAdInternal is - // appropriate for the current platform. - static NativeAdInternal* CreateInstance(NativeAd* base); - - // Virtual destructor is required. - virtual ~NativeAdInternal() = default; - - // Initializes this object and any platform-specific helpers that it uses. - virtual Future Initialize(AdParent parent) = 0; - - // Initiates an ad request. - virtual Future LoadAd(const char* ad_unit_id, - const AdRequest& request) = 0; - - // Retrieves the most recent Future for a given function. - Future GetLastResult(NativeAdFn fn); - - // Retrieves the most recent AdResult future for the LoadAd function. - Future GetLoadAdLastResult(); - - // Sets an AdListener for this ad view. - virtual void SetAdListener(AdListener* listener); - - // Notifies the Ad listener (if one exists) that an event has occurred. - void NotifyListenerAdClicked(); - void NotifyListenerAdClosed(); - void NotifyListenerAdImpression(); - void NotifyListenerAdOpened(); - - // Returns true if the NativeAd has been initialized. - virtual bool is_initialized() const = 0; - - // Returns the associated icon asset of the native ad. - const NativeAdImage& icon() const { return icon_; } - - // Returns the associated image assets of the native ad. - const std::vector& images() const { return images_; } - - // Returns the associated icon asset of the native ad. - const NativeAdImage& adchoices_icon() const { return adchoices_icon_; } - - // Only used by allowlisted ad units. - virtual Future RecordImpression(const Variant& impression_data) = 0; - - // Only used by allowlisted ad units. - virtual Future PerformClick(const Variant& click_data) = 0; - - protected: - friend class firebase::gma::NativeAd; - friend class firebase::gma::NativeAdImage; - friend class firebase::gma::GmaInternal; - - // Used by CreateInstance() to create an appropriate one for the current - // platform. - explicit NativeAdInternal(NativeAd* base); - - // Invoked after a native ad has been loaded to fill native ad image assets. - void insert_image(const NativeAdImage& ad_image, - const std::string& image_type); - - // Invoked before filling native ad image assets. - void clear_existing_images(); - - // A pointer back to the NativeAd class that created us. - NativeAd* base_; - - // Future data used to synchronize asynchronous calls. - FutureData future_data_; - - // Listener for NativeAd Lifecycle event callbacks. - AdListener* ad_listener_; - - // Tracks the native ad icon asset. - NativeAdImage icon_; - - // Tracks the native ad image assets. - std::vector images_; - - // Tracks the native ad choices icon asset. - NativeAdImage adchoices_icon_; - - // Lock object for accessing ad_listener_. - Mutex listener_mutex_; -}; - -} // namespace internal -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_COMMON_NATIVE_AD_INTERNAL_H_ diff --git a/gma/src/common/query_info.cc b/gma/src/common/query_info.cc deleted file mode 100644 index e5ce519c3f..0000000000 --- a/gma/src/common/query_info.cc +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/include/firebase/gma/internal/query_info.h" - -#include "app/src/assert.h" -#include "app/src/include/firebase/future.h" -#include "gma/src/common/gma_common.h" -#include "gma/src/common/query_info_internal.h" -#include "gma/src/include/firebase/gma/types.h" - -namespace firebase { -namespace gma { - -QueryInfo::QueryInfo() { - FIREBASE_ASSERT(gma::IsInitialized()); - internal_ = internal::QueryInfoInternal::CreateInstance(this); - - GetOrCreateCleanupNotifier()->RegisterObject(this, [](void* object) { - LogWarning("QueryInfo must be deleted before gma::Terminate."); - QueryInfo* query_info = reinterpret_cast(object); - delete query_info->internal_; - query_info->internal_ = nullptr; - }); -} - -QueryInfo::~QueryInfo() { - FIREBASE_ASSERT(internal_); - - GetOrCreateCleanupNotifier()->UnregisterObject(this); - delete internal_; -} - -// Initialize must be called before any other methods in the namespace. This -// method asserts that Initialize() has been invoked and allowed to complete. -static bool CheckIsInitialized(internal::QueryInfoInternal* internal) { - FIREBASE_ASSERT(internal); - return internal->is_initialized(); -} - -Future QueryInfo::Initialize(AdParent parent) { - return internal_->Initialize(parent); -} - -Future QueryInfo::InitializeLastResult() const { - return internal_->GetInitializeLastResult(); -} - -Future QueryInfo::CreateQueryInfo(AdFormat format, - const AdRequest& request) { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFutureWithQueryInfoResult( - firebase::gma::internal::kQueryInfoFnCreateQueryInfo, - kAdErrorCodeUninitialized, kAdUninitializedErrorMessage, - &internal_->future_data_, QueryInfoResult()); - } - - return internal_->CreateQueryInfo(format, request); -} - -Future QueryInfo::CreateQueryInfoLastResult() const { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFutureWithQueryInfoResult( - firebase::gma::internal::kQueryInfoFnCreateQueryInfo, - kAdErrorCodeUninitialized, kAdUninitializedErrorMessage, - &internal_->future_data_, QueryInfoResult()); - } - return internal_->CreateQueryInfoLastResult( - internal::kQueryInfoFnCreateQueryInfo); -} - -Future QueryInfo::CreateQueryInfoWithAdUnit( - AdFormat format, const AdRequest& request, const char* ad_unit_id) { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFutureWithQueryInfoResult( - firebase::gma::internal::kQueryInfoFnCreateQueryInfoWithAdUnit, - kAdErrorCodeUninitialized, kAdUninitializedErrorMessage, - &internal_->future_data_, QueryInfoResult()); - } - - return internal_->CreateQueryInfoWithAdUnit(format, request, ad_unit_id); -} - -Future QueryInfo::CreateQueryInfoWithAdUnitLastResult() const { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFutureWithQueryInfoResult( - firebase::gma::internal::kQueryInfoFnCreateQueryInfoWithAdUnit, - kAdErrorCodeUninitialized, kAdUninitializedErrorMessage, - &internal_->future_data_, QueryInfoResult()); - } - return internal_->CreateQueryInfoLastResult( - internal::kQueryInfoFnCreateQueryInfoWithAdUnit); -} - -} // namespace gma -} // namespace firebase diff --git a/gma/src/common/query_info_internal.cc b/gma/src/common/query_info_internal.cc deleted file mode 100644 index ef5d0fa6ec..0000000000 --- a/gma/src/common/query_info_internal.cc +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/common/query_info_internal.h" - -#include - -#include "app/src/include/firebase/future.h" -#include "app/src/include/firebase/internal/mutex.h" -#include "app/src/include/firebase/internal/platform.h" -#include "app/src/reference_counted_future_impl.h" -#include "gma/src/include/firebase/gma/internal/query_info.h" -#include "gma/src/include/firebase/gma/types.h" - -#if FIREBASE_PLATFORM_ANDROID -#include "gma/src/android/query_info_internal_android.h" -#elif FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS -#include "gma/src/ios/query_info_internal_ios.h" -#else -#include "gma/src/stub/query_info_internal_stub.h" -#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS, - // FIREBASE_PLATFORM_TVOS - -namespace firebase { -namespace gma { -namespace internal { - -QueryInfoInternal::QueryInfoInternal(QueryInfo* base) - : base_(base), future_data_(kQueryInfoFnCount) {} - -QueryInfoInternal* QueryInfoInternal::CreateInstance(QueryInfo* base) { -#if FIREBASE_PLATFORM_ANDROID - return new QueryInfoInternalAndroid(base); -#elif FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS - return new QueryInfoInternalIOS(base); -#else - return new QueryInfoInternalStub(base); -#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS, - // FIREBASE_PLATFORM_TVOS -} - -Future QueryInfoInternal::GetInitializeLastResult() { - return static_cast&>( - future_data_.future_impl.LastResult(kQueryInfoFnInitialize)); -} - -Future QueryInfoInternal::CreateQueryInfoLastResult( - QueryInfoFn fn) { - return static_cast&>( - future_data_.future_impl.LastResult(fn)); -} - -} // namespace internal -} // namespace gma -} // namespace firebase diff --git a/gma/src/common/query_info_internal.h b/gma/src/common/query_info_internal.h deleted file mode 100644 index 828be152cc..0000000000 --- a/gma/src/common/query_info_internal.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_COMMON_QUERY_INFO_INTERNAL_H_ -#define FIREBASE_GMA_SRC_COMMON_QUERY_INFO_INTERNAL_H_ - -#include - -#include "app/src/include/firebase/future.h" -#include "app/src/include/firebase/internal/mutex.h" -#include "gma/src/common/gma_common.h" -#include "gma/src/include/firebase/gma/internal/query_info.h" - -namespace firebase { -namespace gma { -namespace internal { - -// Constants representing each NativeAd function that returns a Future. -enum QueryInfoFn { - kQueryInfoFnInitialize, - kQueryInfoFnCreateQueryInfo, - kQueryInfoFnCreateQueryInfoWithAdUnit, - kQueryInfoFnCount -}; - -class QueryInfoInternal { - public: - // Create an instance of whichever subclass of QueryInfoInternal is - // appropriate for the current platform. - static QueryInfoInternal* CreateInstance(QueryInfo* base); - - // Virtual destructor is required. - virtual ~QueryInfoInternal() = default; - - // Initializes this object and any platform-specific helpers that it uses. - virtual Future Initialize(AdParent parent) = 0; - - // Retrieves the most recent Future for Initialize(). - Future GetInitializeLastResult(); - - // Initiates queryInfo creation for the given ad format and request. - virtual Future CreateQueryInfo(AdFormat format, - const AdRequest& request) = 0; - - // Initiates queryInfo creation for the given ad format, request and ad unit. - virtual Future CreateQueryInfoWithAdUnit( - AdFormat format, const AdRequest& request, const char* ad_unit_id) = 0; - - // Retrieves the most recent QueryInfo future for the given create function. - Future CreateQueryInfoLastResult(QueryInfoFn fn); - - // Returns true if the QueryInfo has been initialized. - virtual bool is_initialized() const = 0; - - protected: - friend class firebase::gma::QueryInfo; - friend class firebase::gma::GmaInternal; - - // Used by CreateInstance() to create an appropriate one for the current - // platform. - explicit QueryInfoInternal(QueryInfo* base); - - // A pointer back to the QueryInfo class that created us. - QueryInfo* base_; - - // Future data used to synchronize asynchronous calls. - FutureData future_data_; -}; - -} // namespace internal -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_COMMON_QUERY_INFO_INTERNAL_H_ diff --git a/gma/src/common/rewarded_ad.cc b/gma/src/common/rewarded_ad.cc deleted file mode 100644 index 2733aae451..0000000000 --- a/gma/src/common/rewarded_ad.cc +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/include/firebase/gma/rewarded_ad.h" - -#include "app/src/assert.h" -#include "app/src/include/firebase/future.h" -#include "gma/src/common/gma_common.h" -#include "gma/src/common/rewarded_ad_internal.h" - -namespace firebase { -namespace gma { - -RewardedAd::RewardedAd() { - FIREBASE_ASSERT(gma::IsInitialized()); - internal_ = internal::RewardedAdInternal::CreateInstance(this); - - GetOrCreateCleanupNotifier()->RegisterObject(this, [](void* object) { - LogWarning("RewardedAd must be deleted before gma::Terminate."); - RewardedAd* rewarded_ad = reinterpret_cast(object); - delete rewarded_ad->internal_; - rewarded_ad->internal_ = nullptr; - }); -} - -RewardedAd::~RewardedAd() { - GetOrCreateCleanupNotifier()->UnregisterObject(this); - delete internal_; -} - -// Initialize must be called before any other methods in the namespace. This -// method asserts that Initialize() has been invoked and allowed to complete. -static bool CheckIsInitialized(internal::RewardedAdInternal* internal) { - FIREBASE_ASSERT(internal); - return internal->is_initialized(); -} - -Future RewardedAd::Initialize(AdParent parent) { - return internal_->Initialize(parent); -} - -Future RewardedAd::InitializeLastResult() const { - return internal_->GetLastResult(internal::kRewardedAdFnInitialize); -} - -Future RewardedAd::LoadAd(const char* ad_unit_id, - const AdRequest& request) { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFutureWithResult( - firebase::gma::internal::kRewardedAdFnLoadAd, kAdErrorCodeUninitialized, - kAdUninitializedErrorMessage, &internal_->future_data_, AdResult()); - } - return internal_->LoadAd(ad_unit_id, request); -} - -Future RewardedAd::LoadAdLastResult() const { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFutureWithResult( - firebase::gma::internal::kRewardedAdFnLoadAd, kAdErrorCodeUninitialized, - kAdUninitializedErrorMessage, &internal_->future_data_, AdResult()); - } - return internal_->GetLoadAdLastResult(); -} - -Future RewardedAd::Show(UserEarnedRewardListener* listener) { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFuture( - firebase::gma::internal::kRewardedAdFnShow, kAdErrorCodeUninitialized, - kAdUninitializedErrorMessage, &internal_->future_data_); - } - return internal_->Show(listener); -} - -Future RewardedAd::ShowLastResult() const { - if (!CheckIsInitialized(internal_)) { - return CreateAndCompleteFuture( - firebase::gma::internal::kRewardedAdFnShow, kAdErrorCodeUninitialized, - kAdUninitializedErrorMessage, &internal_->future_data_); - } - return internal_->GetLastResult(internal::kRewardedAdFnShow); -} - -void RewardedAd::SetFullScreenContentListener( - FullScreenContentListener* listener) { - internal_->SetFullScreenContentListener(listener); -} - -void RewardedAd::SetPaidEventListener(PaidEventListener* listener) { - internal_->SetPaidEventListener(listener); -} - -void RewardedAd::SetServerSideVerificationOptions( - const ServerSideVerificationOptions& options) { - internal_->SetServerSideVerificationOptions(options); -} - -} // namespace gma -} // namespace firebase diff --git a/gma/src/common/rewarded_ad_internal.cc b/gma/src/common/rewarded_ad_internal.cc deleted file mode 100644 index 39030a02cc..0000000000 --- a/gma/src/common/rewarded_ad_internal.cc +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/common/rewarded_ad_internal.h" - -#include "app/src/include/firebase/future.h" -#include "app/src/include/firebase/internal/mutex.h" -#include "app/src/include/firebase/internal/platform.h" -#include "app/src/reference_counted_future_impl.h" -#include "gma/src/include/firebase/gma/rewarded_ad.h" - -#if FIREBASE_PLATFORM_ANDROID -#include "gma/src/android/rewarded_ad_internal_android.h" -#elif FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS -#include "gma/src/ios/rewarded_ad_internal_ios.h" -#else -#include "gma/src/stub/rewarded_ad_internal_stub.h" -#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS, - // FIREBASE_PLATFORM_TVOS - -#include - -namespace firebase { -namespace gma { -namespace internal { - -RewardedAdInternal::RewardedAdInternal(RewardedAd* base) - : base_(base), - future_data_(kRewardedAdFnCount), - user_earned_reward_listener_(nullptr) {} - -RewardedAdInternal* RewardedAdInternal::CreateInstance(RewardedAd* base) { -#if FIREBASE_PLATFORM_ANDROID - return new RewardedAdInternalAndroid(base); -#elif FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS - return new RewardedAdInternalIOS(base); -#else - return new RewardedAdInternalStub(base); -#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS, - // FIREBASE_PLATFORM_TVOS -} - -void RewardedAdInternal::NotifyListenerOfUserEarnedReward( - const std::string& type, int64_t amount) { - MutexLock lock(listener_mutex_); - if (user_earned_reward_listener_ != nullptr) { - user_earned_reward_listener_->OnUserEarnedReward(AdReward(type, amount)); - } -} - -Future RewardedAdInternal::GetLastResult(RewardedAdFn fn) { - return static_cast&>( - future_data_.future_impl.LastResult(fn)); -} - -Future RewardedAdInternal::GetLoadAdLastResult() { - return static_cast&>( - future_data_.future_impl.LastResult(kRewardedAdFnLoadAd)); -} - -void RewardedAdInternal::SetServerSideVerificationOptions( - const RewardedAd::ServerSideVerificationOptions& - serverSideVerificationOptions) { - serverSideVerificationOptions_ = serverSideVerificationOptions; -} - -} // namespace internal -} // namespace gma -} // namespace firebase diff --git a/gma/src/common/rewarded_ad_internal.h b/gma/src/common/rewarded_ad_internal.h deleted file mode 100644 index 2897468ac2..0000000000 --- a/gma/src/common/rewarded_ad_internal.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_COMMON_REWARDED_AD_INTERNAL_H_ -#define FIREBASE_GMA_SRC_COMMON_REWARDED_AD_INTERNAL_H_ - -#include - -#include "app/src/include/firebase/future.h" -#include "gma/src/common/full_screen_ad_event_listener.h" -#include "gma/src/common/gma_common.h" -#include "gma/src/include/firebase/gma/rewarded_ad.h" - -namespace firebase { -namespace gma { -namespace internal { - -// Constants representing each RewardedAd function that returns a Future. -enum RewardedAdFn { - kRewardedAdFnInitialize, - kRewardedAdFnLoadAd, - kRewardedAdFnShow, - kRewardedAdFnCount -}; - -class RewardedAdInternal : public FullScreenAdEventListener { - public: - // Create an instance of whichever subclass of RewardedAdInternal is - // appropriate for the current platform. - static RewardedAdInternal* CreateInstance(RewardedAd* base); - - // Virtual destructor is required. - virtual ~RewardedAdInternal() = default; - - // Initializes this object and any platform-specific helpers that it uses. - virtual Future Initialize(AdParent parent) = 0; - - // Initiates an ad request. - virtual Future LoadAd(const char* ad_unit_id, - const AdRequest& request) = 0; - - // Displays an interstitial ad. - virtual Future Show(UserEarnedRewardListener* listener) = 0; - - /// Notifies the UserEarnedRewardListener (if one exists) than a reward - /// event has occurred. - void NotifyListenerOfUserEarnedReward(const std::string& type, - int64_t amount); - - // Retrieves the most recent Future for a given function. - Future GetLastResult(RewardedAdFn fn); - - // Retrieves the most recent AdResult future for the LoadAd function. - Future GetLoadAdLastResult(); - - // Returns true if the RewardedAd has been initialized. - virtual bool is_initialized() const = 0; - - /// Sets the server side verification options. - void SetServerSideVerificationOptions( - const RewardedAd::ServerSideVerificationOptions& - serverSideVerificationOptions); - - protected: - friend class firebase::gma::RewardedAd; - - // Used by CreateInstance() to create an appropriate one for the current - // platform. - explicit RewardedAdInternal(RewardedAd* base); - - // A pointer back to the RewardedAd class that created us. - RewardedAd* base_; - - // Future data used to synchronize asynchronous calls. - FutureData future_data_; - - // Reference to the listener to which this object sends user earned - // reward event callbacks. - UserEarnedRewardListener* user_earned_reward_listener_; - - // Options for RewardedAd server-side verification callbacks. - RewardedAd::ServerSideVerificationOptions serverSideVerificationOptions_; -}; - -} // namespace internal -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_COMMON_REWARDED_AD_INTERNAL_H_ diff --git a/gma/src/common/ump/consent_info.cc b/gma/src/common/ump/consent_info.cc deleted file mode 100644 index 334a11d735..0000000000 --- a/gma/src/common/ump/consent_info.cc +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "firebase/gma/ump/consent_info.h" - -#include "app/src/assert.h" -#include "firebase/app.h" -#include "firebase/gma/ump.h" -#include "firebase/internal/platform.h" -#include "gma/src/common/ump/consent_info_internal.h" - -namespace firebase { -namespace gma { -namespace ump { - -ConsentInfo* ConsentInfo::s_instance_ = nullptr; - -ConsentInfo* ConsentInfo::GetInstance(const ::firebase::App& app, - ::firebase::InitResult* init_result_out) { - if (s_instance_) { - if (init_result_out) *init_result_out = kInitResultSuccess; - return s_instance_; - } -#if FIREBASE_PLATFORM_ANDROID - return GetInstance(app.GetJNIEnv(), app.activity(), init_result_out); -#else // !FIREBASE_PLATFORM_ANDROID - return GetInstance(init_result_out); -#endif // FIREBASE_PLATFORM_ANDROID -} - -#if FIREBASE_PLATFORM_ANDROID -ConsentInfo* ConsentInfo::GetInstance() { return s_instance_; } - -ConsentInfo* ConsentInfo::GetInstance(JNIEnv* jni_env, jobject activity, - ::firebase::InitResult* init_result_out) { -#else // !FIREBASE_PLATFORM_ANDROID -ConsentInfo* ConsentInfo::GetInstance(::firebase::InitResult* init_result_out) { -#endif - if (s_instance_) { - if (init_result_out) *init_result_out = kInitResultSuccess; - return s_instance_; - } - - ConsentInfo* consent_info = new ConsentInfo(); -#if FIREBASE_PLATFORM_ANDROID - InitResult result = consent_info->Initialize(jni_env, activity); -#else - InitResult result = consent_info->Initialize(); -#endif - if (init_result_out) *init_result_out = result; - if (result != kInitResultSuccess) { - delete consent_info; - return nullptr; - } - return consent_info; -} - -ConsentInfo::ConsentInfo() { - internal_ = nullptr; -#if FIREBASE_PLATFORM_ANDROID - java_vm_ = nullptr; -#endif - s_instance_ = this; -} - -ConsentInfo::~ConsentInfo() { - if (internal_) { - delete internal_; - internal_ = nullptr; - } - s_instance_ = nullptr; -} - -#if FIREBASE_PLATFORM_ANDROID -InitResult ConsentInfo::Initialize(JNIEnv* jni_env, jobject activity) { - FIREBASE_ASSERT(!internal_); - internal_ = internal::ConsentInfoInternal::CreateInstance(jni_env, activity); - return internal_ ? kInitResultSuccess : kInitResultFailedMissingDependency; -} -#else -InitResult ConsentInfo::Initialize() { - FIREBASE_ASSERT(!internal_); - internal_ = internal::ConsentInfoInternal::CreateInstance(); - return kInitResultSuccess; -} -#endif - -// Below this, everything is a passthrough to ConsentInfoInternal. If there is -// no internal_ pointer (e.g. it's been cleaned up), return default values and -// invalid futures. - -ConsentStatus ConsentInfo::GetConsentStatus() { - if (!internal_) return kConsentStatusUnknown; - return internal_->GetConsentStatus(); -} - -ConsentFormStatus ConsentInfo::GetConsentFormStatus() { - if (!internal_) return kConsentFormStatusUnknown; - return internal_->GetConsentFormStatus(); -} - -Future ConsentInfo::RequestConsentInfoUpdate( - const ConsentRequestParameters& params) { - if (!internal_) return Future(); - return internal_->RequestConsentInfoUpdate(params); -} - -Future ConsentInfo::RequestConsentInfoUpdateLastResult() { - if (!internal_) return Future(); - return internal_->RequestConsentInfoUpdateLastResult(); -} - -Future ConsentInfo::LoadConsentForm() { - if (!internal_) return Future(); - return internal_->LoadConsentForm(); -} - -Future ConsentInfo::LoadConsentFormLastResult() { - if (!internal_) return Future(); - return internal_->LoadConsentFormLastResult(); -} - -Future ConsentInfo::ShowConsentForm(FormParent parent) { - if (!internal_) return Future(); - return internal_->ShowConsentForm(parent); -} - -Future ConsentInfo::ShowConsentFormLastResult() { - if (!internal_) return Future(); - return internal_->ShowConsentFormLastResult(); -} - -Future ConsentInfo::LoadAndShowConsentFormIfRequired(FormParent parent) { - if (!internal_) return Future(); - return internal_->LoadAndShowConsentFormIfRequired(parent); -} - -Future ConsentInfo::LoadAndShowConsentFormIfRequiredLastResult() { - if (!internal_) return Future(); - return internal_->LoadAndShowConsentFormIfRequiredLastResult(); -} - -PrivacyOptionsRequirementStatus -ConsentInfo::GetPrivacyOptionsRequirementStatus() { - if (!internal_) return kPrivacyOptionsRequirementStatusUnknown; - return internal_->GetPrivacyOptionsRequirementStatus(); -} - -Future ConsentInfo::ShowPrivacyOptionsForm(FormParent parent) { - if (!internal_) return Future(); - return internal_->ShowPrivacyOptionsForm(parent); -} - -Future ConsentInfo::ShowPrivacyOptionsFormLastResult() { - if (!internal_) return Future(); - return internal_->ShowPrivacyOptionsFormLastResult(); -} - -bool ConsentInfo::CanRequestAds() { - if (!internal_) return false; - return internal_->CanRequestAds(); -} - -void ConsentInfo::Reset() { - if (!internal_) return; - internal_->Reset(); -} - -} // namespace ump -} // namespace gma -} // namespace firebase diff --git a/gma/src/common/ump/consent_info_internal.cc b/gma/src/common/ump/consent_info_internal.cc deleted file mode 100644 index 3a3e9cd4b8..0000000000 --- a/gma/src/common/ump/consent_info_internal.cc +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/common/ump/consent_info_internal.h" - -#include "app/src/include/firebase/internal/platform.h" - -namespace firebase { -namespace gma { -namespace ump { -namespace internal { - -ConsentInfoInternal::ConsentInfoInternal() : futures_(kConsentInfoFnCount) {} - -ConsentInfoInternal::~ConsentInfoInternal() {} - -const char* ConsentInfoInternal::GetConsentRequestErrorMessage( - ConsentRequestError error_code) { - switch (error_code) { - case kConsentRequestSuccess: - return "Success"; - case kConsentRequestErrorInvalidAppId: -#if FIREBASE_PLATFORM_ANDROID - return "Missing or invalid com.google.android.gms.ads.APPLICATION_ID in " - "AndroidManifest.xml"; -#elif FIREBASE_PLATFORM_IOS - return "Missing or invalid GADApplicationidentifier in Info.plist"; -#else - return "Missing or invalid App ID"; -#endif - case kConsentRequestErrorNetwork: - return "Network error"; - case kConsentRequestErrorInternal: - return "Internal error"; - case kConsentRequestErrorMisconfiguration: - return "A misconfiguration exists in the UI"; - case kConsentRequestErrorUnknown: - return "Unknown error"; - case kConsentRequestErrorInvalidOperation: - return "Invalid operation"; - case kConsentRequestErrorOperationInProgress: - return "Operation already in progress. Please wait for it to finish by " - "checking RequestConsentInfoUpdateLastResult()."; - default: - return "Bad error code"; - } -} - -const char* ConsentInfoInternal::GetConsentFormErrorMessage( - ConsentFormError error_code) { - switch (error_code) { - case kConsentFormSuccess: - return "Success"; - case kConsentFormErrorTimeout: - return "Timed out"; - case kConsentFormErrorUnavailable: - return "The form is unavailable."; - case kConsentFormErrorInternal: - return "Internal error"; - case kConsentFormErrorUnknown: - return "Unknown error"; - case kConsentFormErrorAlreadyUsed: - return "The form was already used"; - case kConsentFormErrorInvalidOperation: - return "Invalid operation"; - case kConsentFormErrorOperationInProgress: - return "Operation already in progress. Please wait for it to finish by " - "checking LoadFormLastResult() or ShowFormLastResult()."; - default: - return "Bad error code"; - } -} - -} // namespace internal -} // namespace ump -} // namespace gma -} // namespace firebase diff --git a/gma/src/common/ump/consent_info_internal.h b/gma/src/common/ump/consent_info_internal.h deleted file mode 100644 index 94d87a5ec0..0000000000 --- a/gma/src/common/ump/consent_info_internal.h +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_COMMON_UMP_CONSENT_INFO_INTERNAL_H_ -#define FIREBASE_GMA_SRC_COMMON_UMP_CONSENT_INFO_INTERNAL_H_ - -#include "app/src/cleanup_notifier.h" -#include "app/src/reference_counted_future_impl.h" -#include "firebase/future.h" -#include "firebase/gma/ump.h" -#include "firebase/gma/ump/types.h" -#include "firebase/internal/platform.h" - -#if FIREBASE_PLATFORM_ANDROID -#include -#endif - -namespace firebase { -namespace gma { -namespace ump { -namespace internal { - -// Constants representing each ConsentInfo function that returns a Future. -enum ConsentInfoFn { - kConsentInfoFnRequestConsentInfoUpdate, - kConsentInfoFnLoadConsentForm, - kConsentInfoFnShowConsentForm, - kConsentInfoFnLoadAndShowConsentFormIfRequired, - kConsentInfoFnShowPrivacyOptionsForm, - kConsentInfoFnCount -}; - -class ConsentInfoInternal { - public: - virtual ~ConsentInfoInternal(); - - // Implemented in platform-specific code to instantiate a - // platform-specific subclass. -#if FIREBASE_PLATFORM_ANDROID - static ConsentInfoInternal* CreateInstance(JNIEnv* jni_env, jobject activity); -#else - static ConsentInfoInternal* CreateInstance(); -#endif - - virtual ConsentStatus GetConsentStatus() = 0; - virtual ConsentFormStatus GetConsentFormStatus() = 0; - - virtual Future RequestConsentInfoUpdate( - const ConsentRequestParameters& params) = 0; - Future RequestConsentInfoUpdateLastResult() { - return static_cast&>( - futures()->LastResult(kConsentInfoFnRequestConsentInfoUpdate)); - } - virtual Future LoadConsentForm() = 0; - - Future LoadConsentFormLastResult() { - return static_cast&>( - futures()->LastResult(kConsentInfoFnLoadConsentForm)); - } - - virtual Future ShowConsentForm(FormParent parent) = 0; - - Future ShowConsentFormLastResult() { - return static_cast&>( - futures()->LastResult(kConsentInfoFnShowConsentForm)); - } - - virtual Future LoadAndShowConsentFormIfRequired(FormParent parent) = 0; - - Future LoadAndShowConsentFormIfRequiredLastResult() { - return static_cast&>( - futures()->LastResult(kConsentInfoFnLoadAndShowConsentFormIfRequired)); - } - - virtual PrivacyOptionsRequirementStatus - GetPrivacyOptionsRequirementStatus() = 0; - - virtual Future ShowPrivacyOptionsForm(FormParent parent) = 0; - - Future ShowPrivacyOptionsFormLastResult() { - return static_cast&>( - futures()->LastResult(kConsentInfoFnShowPrivacyOptionsForm)); - } - - virtual bool CanRequestAds() = 0; - - virtual void Reset() = 0; - - protected: - ConsentInfoInternal(); - - static const char* GetConsentRequestErrorMessage( - ConsentRequestError error_code); - - static const char* GetConsentFormErrorMessage(ConsentFormError error_code); - - SafeFutureHandle CreateFuture() { return futures()->SafeAlloc(); } - SafeFutureHandle CreateFuture(ConsentInfoFn fn_idx) { - return futures()->SafeAlloc(fn_idx); - } - - // Complete a Future with the given error code. - void CompleteFuture(SafeFutureHandle handle, ConsentRequestError error, - const char* message = nullptr) { - return futures()->Complete( - handle, error, - message ? message : GetConsentRequestErrorMessage(error)); - } - // Complete the future with the given error code. - void CompleteFuture(SafeFutureHandle handle, ConsentFormError error, - const char* message = nullptr) { - return futures()->Complete( - handle, error, message ? message : GetConsentFormErrorMessage(error)); - } - - ReferenceCountedFutureImpl* futures() { return &futures_; } - CleanupNotifier* cleanup() { return &cleanup_; } - - private: - ReferenceCountedFutureImpl futures_; - CleanupNotifier cleanup_; -}; - -} // namespace internal -} // namespace ump -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_COMMON_UMP_CONSENT_INFO_INTERNAL_H_ diff --git a/gma/src/include/firebase/gma.h b/gma/src/include/firebase/gma.h deleted file mode 100644 index 0d95f536f5..0000000000 --- a/gma/src/include/firebase/gma.h +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_H_ -#define FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_H_ - -#include "firebase/internal/platform.h" - -#if FIREBASE_PLATFORM_ANDROID -#include -#endif // FIREBASE_PLATFORM_ANDROID - -#include - -#include "firebase/app.h" -#include "firebase/gma/ad_view.h" -#include "firebase/gma/internal/native_ad.h" -#include "firebase/gma/internal/query_info.h" -#include "firebase/gma/interstitial_ad.h" -#include "firebase/gma/rewarded_ad.h" -#include "firebase/gma/types.h" -#include "firebase/internal/common.h" - -#if !defined(DOXYGEN) && !defined(SWIG) -FIREBASE_APP_REGISTER_CALLBACKS_REFERENCE(gma) -#endif // !defined(DOXYGEN) && !defined(SWIG) - -namespace firebase { -// In the GMA docs, link to firebase::Future in the Firebase C++ docs. -#if defined(DOXYGEN_ADMOB) -/// @brief The Google Mobile Ads C++ SDK uses this class to return results from -/// asynchronous operations. All C++ functions and method calls that operate -/// asynchronously return a %Future, and provide a "LastResult" -/// function to retrieve the most recent %Future result. -/// -/// The Google Mobile Ads C++ SDK uses this class from the Firebase C++ SDK to -/// return results from asynchronous operations. For more information, see the -/// Firebase -/// C++ SDK documentation. -template -class Future { - // Empty class (used for documentation only). -}; - -/// @brief Firebase App class. For more information, see the Firebase -/// C++ SDK documentation. -class App { - // Empty class (used for documentation only). -}; - -#endif // defined(DOXYGEN_ADMOB) - -/// @brief API for Google Mobile Ads with Firebase. -/// -/// The GMA API allows you to load and display mobile ads using the Google -/// Mobile Ads SDK. Each ad format has its own header file. -/// -/// @deprecated **The Google Mobile Ads (GMA) C++ SDK is _deprecated_ as of June -/// 17, 2024 and should not be adopted in projects that don't already use it. It -/// will enter _End-of-Maintenance (EoM)_ on June 17, 2025. Note that versions -/// of the SDK released before the EoM date will continue to function, but no -/// further bug fixes or changes will be released after the EoM date.** -/// -/// Instead of the Google Mobile Ads C++ SDK, consider using the -/// [iOS](/docs/admob/ios/quick-start) and -/// [Android](/docs/admob/android/quick-start) SDKs from AdMob. For support, -/// reach out to the [Google Mobile Ads SDK Technical -/// Forum](https://groups.google.com/g/google-admob-ads-sdk). -namespace gma { - -/// Initializes Google Mobile Ads (GMA) via Firebase. -/// -/// @param[in] app The Firebase app for which to initialize mobile ads. -/// -/// @param[out] init_result_out Optional: If provided, write the basic init -/// result here. kInitResultSuccess if initialization succeeded, or -/// kInitResultFailedMissingDependency on Android if Google Play services is not -/// available on the current device and the Google Mobile Ads SDK requires -/// Google Play services (for example, when using 'play-services-ads-lite'). -/// Note that this does not include the adapter initialization status, which is -/// returned in the Future. -/// -/// @return If init_result_out is kInitResultSuccess, this Future will contain -/// the initialization status of each adapter once initialization is complete. -/// Otherwise, the returned Future will have kFutureStatusInvalid. -/// -/// @deprecated The Google Mobile Ads C++ SDK is now deprecated. Please see -/// the [SDK reference -/// documentation]( -/// /admob/cpp/reference/namespace/firebase/gma) -/// for more information. -FIREBASE_DEPRECATED Future Initialize( - const ::firebase::App& app, InitResult* init_result_out = nullptr); - -#if FIREBASE_PLATFORM_ANDROID || defined(DOXYGEN) -/// Initializes Google Mobile Ads (GMA) without Firebase for Android. -/// -/// The arguments to @ref Initialize are platform-specific so the caller must do -/// something like this: -/// @code -/// #if defined(__ANDROID__) -/// firebase::gma::Initialize(jni_env, activity); -/// #else -/// firebase::gma::Initialize(); -/// #endif -/// @endcode -/// -/// @param[in] jni_env JNIEnv pointer. -/// @param[in] activity Activity used to start the application. -/// @param[out] init_result_out Optional: If provided, write the basic init -/// result here. kInitResultSuccess if initialization succeeded, or -/// kInitResultFailedMissingDependency on Android if Google Play services is not -/// available on the current device and the Google Mobile Ads SDK requires -/// Google Play services (for example, when using 'play-services-ads-lite'). -/// Note that this does not include the adapter initialization status, which is -/// returned in the Future. -/// -/// @return If init_result_out is kInitResultSuccess, this Future will contain -/// the initialization status of each adapter once initialization is complete. -/// Otherwise, the returned Future will have kFutureStatusInvalid. -/// -/// @deprecated The Google Mobile Ads C++ SDK is now deprecated. Please see -/// https://developers.google.com/admob/cpp/reference/namespace/firebase/gma -/// for more information. -FIREBASE_DEPRECATED Future Initialize( - JNIEnv* jni_env, jobject activity, InitResult* init_result_out = nullptr); - -#endif // defined(__ANDROID__) || defined(DOXYGEN) -#if !FIREBASE_PLATFORM_ANDROID || defined(DOXYGEN) -/// Initializes Google Mobile Ads (GMA) without Firebase for iOS. -/// -/// @param[out] init_result_out Optional: If provided, write the basic init -/// result here. kInitResultSuccess if initialization succeeded, or -/// kInitResultFailedMissingDependency on Android if Google Play services is not -/// available on the current device and the Google Mobile Ads SDK requires -/// Google Play services (for example, when using 'play-services-ads-lite'). -/// Note that this does not include the adapter initialization status, which is -/// returned in the Future. -/// -/// @return If init_result_out is kInitResultSuccess, this Future -/// will contain the initialization status of each adapter once initialization -/// is complete. Otherwise, the returned Future will have -/// kFutureStatusInvalid. -/// -/// @deprecated The Google Mobile Ads C++ SDK is now deprecated. Please see -/// https://developers.google.com/admob/cpp/reference/namespace/firebase/gma -/// for more information. -FIREBASE_DEPRECATED Future Initialize( - InitResult* init_result_out = nullptr); -#endif // !defined(__ANDROID__) || defined(DOXYGEN) - -/// Get the Future returned by a previous call to -/// @ref firebase::gma::Initialize(). -Future InitializeLastResult(); - -/// Get the current adapter initialization status. You can poll this method to -/// check which adapters have been initialized. -AdapterInitializationStatus GetInitializationStatus(); - -/// Disables automated SDK crash reporting on iOS. If not called, the SDK -/// records the original exception handler if available and registers a new -/// exception handler. The new exception handler only reports SDK related -/// exceptions and calls the recorded original exception handler. -/// -/// This method has no effect on Android. -void DisableSDKCrashReporting(); - -/// Disables mediation adapter initialization on iOS during initialization of -/// the GMA SDK. Calling this method may negatively impact your ad -/// performance and should only be called if you will not use GMA SDK -/// controlled mediation during this app session. This method must be called -/// before initializing the GMA SDK or loading ads and has no effect once the -/// SDK has been initialized. -/// -/// This method has no effect on Android. -void DisableMediationInitialization(); - -/// Sets the global @ref RequestConfiguration that will be used for -/// every @ref AdRequest during the app's session. -/// -/// @param[in] request_configuration The request configuration that should be -/// applied to all ad requests. -void SetRequestConfiguration(const RequestConfiguration& request_configuration); - -/// Gets the global RequestConfiguration. -/// -/// @return the currently active @ref RequestConfiguration that's being -/// used for every ad request. -/// @note: on iOS, the -/// @ref RequestConfiguration::tag_for_child_directed_treatment and -/// @ref RequestConfiguration::tag_for_under_age_of_consent fields will be set -/// to RequestConfiguration.kChildDirectedTreatmentUnspecified, and -/// RequestConfiguration.kUnderAgeOfConsentUnspecified, respectfully. -RequestConfiguration GetRequestConfiguration(); - -/// Opens the ad inspector UI. -/// -/// @param[in] parent The platform-specific UI element that will host the -/// ad inspector. For iOS this should be the window's -/// UIViewController. For Android this is the -/// Activity Context which the GMA SDK is running in. -/// @param[in] listener The listener will be invoked when the user closes -/// the ad inspector UI. @ref firebase::gma::Initialize(). must be called -/// prior to this function. -void OpenAdInspector(AdParent parent, AdInspectorClosedListener* listener); - -/// Controls whether the Google Mobile Ads SDK Same App Key is enabled. -/// -/// This function must be invoked after GMA has been initialized. The value set -/// persists across app sessions. The key is enabled by default. -/// -/// This operation is supported on iOS only. This is a no-op on Android -/// systems. -/// -/// @param[in] is_enabled whether the Google Mobile Ads SDK Same App Key is -/// enabled. -void SetIsSameAppKeyEnabled(bool is_enabled); - -/// @brief Terminate GMA. -/// -/// Frees resources associated with GMA that were allocated during -/// @ref firebase::gma::Initialize(). -void Terminate(); - -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_H_ diff --git a/gma/src/include/firebase/gma/ad_view.h b/gma/src/include/firebase/gma/ad_view.h deleted file mode 100644 index d2d73db67d..0000000000 --- a/gma/src/include/firebase/gma/ad_view.h +++ /dev/null @@ -1,272 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_AD_VIEW_H_ -#define FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_AD_VIEW_H_ - -#include "firebase/future.h" -#include "firebase/gma/types.h" -#include "firebase/internal/common.h" - -namespace firebase { -namespace gma { - -namespace internal { -// Forward declaration for platform-specific data, implemented in each library. -class AdViewInternal; -} // namespace internal - -class AdViewBoundingBoxListener; -struct BoundingBox; - -/// @brief Loads and displays Google Mobile Ads AdView ads. -/// -/// Each AdView object corresponds to a single GMA ad placement of a specified -/// size. There are methods to load an ad, move it, show it and hide it, and -/// retrieve the bounds of the ad onscreen. -/// -/// AdView objects provide information about their current state through -/// Futures. Methods like @ref Initialize, @ref LoadAd, and @ref Hide each have -/// a corresponding @ref Future from which the result of the last call can be -/// determined. The two variants of @ref SetPosition share a single result -/// @ref Future, since they're essentially the same action. -/// -/// For example, you could initialize, load, and show an AdView while -/// checking the result of the previous action at each step as follows: -/// -/// @code -/// namespace gma = ::firebase::gma; -/// gma::AdView* ad_view = new gma::AdView(); -/// ad_view->Initialize(ad_parent, "YOUR_AD_UNIT_ID", desired_ad_size) -/// @endcode -/// -/// Then, later: -/// -/// @code -/// if (ad_view->InitializeLastResult().status() == -/// ::firebase::kFutureStatusComplete && -/// ad_view->InitializeLastResult().error() == -/// firebase::gma::kAdErrorCodeNone) { -/// ad_view->LoadAd(your_ad_request); -/// } -/// @endcode -/// -/// @deprecated The Google Mobile Ads C++ SDK is now deprecated. Please see -/// https://developers.google.com/admob/cpp/reference/namespace/firebase/gma -/// for more information. -class AdView { - public: - /// The possible screen positions for a @ref AdView, configured via - /// @ref SetPosition. - enum Position { - /// The position isn't one of the predefined screen locations. - kPositionUndefined = -1, - /// Top of the screen, horizontally centered. - kPositionTop = 0, - /// Bottom of the screen, horizontally centered. - kPositionBottom, - /// Top-left corner of the screen. - kPositionTopLeft, - /// Top-right corner of the screen. - kPositionTopRight, - /// Bottom-left corner of the screen. - kPositionBottomLeft, - /// Bottom-right corner of the screen. - kPositionBottomRight, - }; - - /// Creates an uninitialized @ref AdView object. - /// @ref Initialize must be called before the object is used. - FIREBASE_DEPRECATED AdView(); - - ~AdView(); - - /// Initializes the @ref AdView object. - /// @param[in] parent The platform-specific UI element that will host the ad. - /// @param[in] ad_unit_id The ad unit ID to use when requesting ads. - /// @param[in] size The desired ad size for the ad. - FIREBASE_DEPRECATED Future Initialize(AdParent parent, - const char* ad_unit_id, - const AdSize& size); - - /// Returns a @ref Future that has the status of the last call to - /// @ref Initialize. - FIREBASE_DEPRECATED Future InitializeLastResult() const; - - /// Begins an asynchronous request for an ad. If successful, the ad will - /// automatically be displayed in the AdView. - /// @param[in] request An AdRequest struct with information about the request - /// to be made (such as targeting info). - Future LoadAd(const AdRequest& request); - - /// Returns a @ref Future containing the status of the last call to - /// @ref LoadAd. - Future LoadAdLastResult() const; - - /// Retrieves the @ref AdView's current onscreen size and location. - /// - /// @return The current size and location. Values are in pixels, and location - /// coordinates originate from the top-left corner of the screen. - BoundingBox bounding_box() const; - - /// Sets an AdListener for this ad view. - /// - /// @param[in] listener An AdListener object which will be invoked - /// when lifecycle events occur on this AdView. - void SetAdListener(AdListener* listener); - - /// Sets a listener to be invoked when the Ad's bounding box - /// changes size or location. - /// - /// @param[in] listener A AdViewBoundingBoxListener object which will be - /// invoked when the ad changes size, shape, or position. - void SetBoundingBoxListener(AdViewBoundingBoxListener* listener); - - /// Sets a listener to be invoked when this ad is estimated to have earned - /// money. - /// - /// @param[in] listener A PaidEventListener object to be invoked when a - /// paid event occurs on the ad. - void SetPaidEventListener(PaidEventListener* listener); - - /// Moves the @ref AdView so that its top-left corner is located at - /// (x, y). Coordinates are in pixels from the top-left corner of the screen. - /// - /// When built for Android, the library will not display an ad on top of or - /// beneath an Activity's status bar. If a call to SetPosition - /// would result in an overlap, the @ref AdView is placed just below the - /// status bar, so no overlap occurs. - /// @param[in] x The desired horizontal coordinate. - /// @param[in] y The desired vertical coordinate. - /// - /// @return a @ref Future which will be completed when this move operation - /// completes. - Future SetPosition(int x, int y); - - /// Moves the @ref AdView so that it's located at the given predefined - /// position. - /// - /// @param[in] position The predefined position to which to move the - /// @ref AdView. - /// - /// @return a @ref Future which will be completed when this move operation - /// completes. - Future SetPosition(Position position); - - /// Returns a @ref Future containing the status of the last call to either - /// version of @ref SetPosition. - Future SetPositionLastResult() const; - - /// Hides the AdView. - Future Hide(); - - /// Returns a @ref Future containing the status of the last call to - /// @ref Hide. - Future HideLastResult() const; - - /// Shows the @ref AdView. - Future Show(); - - /// Returns a @ref Future containing the status of the last call to - /// @ref Show. - Future ShowLastResult() const; - - /// Pauses the @ref AdView. Should be called whenever the C++ engine - /// pauses or the application loses focus. - Future Pause(); - - /// Returns a @ref Future containing the status of the last call to - /// @ref Pause. - Future PauseLastResult() const; - - /// Resumes the @ref AdView after pausing. - Future Resume(); - - /// Returns a @ref Future containing the status of the last call to - /// @ref Resume. - Future ResumeLastResult() const; - - /// Cleans up and deallocates any resources used by the @ref AdView. - /// You must call this asynchronous operation before this object's destructor - /// is invoked or risk leaking device resources. - Future Destroy(); - - /// Returns a @ref Future containing the status of the last call to - /// @ref Destroy. - Future DestroyLastResult() const; - - /// Returns the AdSize of the AdView. - /// - /// @return An @ref AdSize object representing the size of the ad. If this - /// view has not been initialized then the AdSize will be 0,0. - AdSize ad_size() const; - - protected: - /// Pointer to a listener for AdListener events. - AdListener* ad_listener_; - - /// Pointer to a listener for BoundingBox events. - AdViewBoundingBoxListener* ad_view_bounding_box_listener_; - - /// Pointer to a listener for paid events. - PaidEventListener* paid_event_listener_; - - private: - // An internal, platform-specific implementation object that this class uses - // to interact with the Google Mobile Ads SDKs for iOS and Android. - internal::AdViewInternal* internal_; -}; - -/// A listener class that developers can extend and pass to an @ref AdView -/// object's @ref AdView::SetBoundingBoxListener method to be notified of -/// changes to the size of the Ad's bounding box. -class AdViewBoundingBoxListener { - public: - virtual ~AdViewBoundingBoxListener(); - - /// This method is called when the @ref AdView object's bounding box - /// changes. - /// - /// @param[in] ad_view The view whose bounding box changed. - /// @param[in] box The new bounding box. - virtual void OnBoundingBoxChanged(AdView* ad_view, BoundingBox box) = 0; -}; - -/// @brief The screen location and dimensions of an AdView once it has been -/// initialized. -struct BoundingBox { - /// Default constructor which initializes all member variables to 0. - BoundingBox() - : height(0), width(0), x(0), y(0), position(AdView::kPositionUndefined) {} - - /// Height of the ad in pixels. - int height; - /// Width of the ad in pixels. - int width; - /// Horizontal position of the ad in pixels from the left. - int x; - /// Vertical position of the ad in pixels from the top. - int y; - - /// The position of the AdView if one has been set as the target position, or - /// kPositionUndefined otherwise. - AdView::Position position; -}; - -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_AD_VIEW_H_ diff --git a/gma/src/include/firebase/gma/internal/README.md b/gma/src/include/firebase/gma/internal/README.md deleted file mode 100644 index ce08eafee1..0000000000 --- a/gma/src/include/firebase/gma/internal/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# Firebase C++ Open Source Development - -**NOTE: For internal use only.** - -This folder contains experimental header files that are internal and experimental. -Users shouldn't expect any stability guarantees for code in this folder, and any public usage is discouraged and is not supported. diff --git a/gma/src/include/firebase/gma/internal/native_ad.h b/gma/src/include/firebase/gma/internal/native_ad.h deleted file mode 100644 index a35d8f90b4..0000000000 --- a/gma/src/include/firebase/gma/internal/native_ad.h +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_INTERNAL_NATIVE_AD_H_ -#define FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_INTERNAL_NATIVE_AD_H_ - -#include -#include - -#include "firebase/future.h" -#include "firebase/gma/types.h" -#include "firebase/internal/common.h" -#include "firebase/variant.h" - -// Doxygen breaks trying to parse this file, and since it is internal logic, -// it doesn't need to be included in the generated documentation. -#ifndef DOXYGEN - -namespace firebase { -namespace gma { - -namespace internal { -// Forward declaration for platform-specific data, implemented in each library. -class NativeAdInternal; -} // namespace internal - -struct NativeAdImageInternal; - -class GmaInternal; -class NativeAdImage; -class ImageResult; - -class NativeAd { - public: - NativeAd(); - ~NativeAd(); - - /// Initialize the NativeAd object. - /// parent: The platform-specific UI element that will host the ad. - Future Initialize(AdParent parent); - - /// Returns a Future containing the status of the last call to - /// Initialize. - Future InitializeLastResult() const; - - /// Begins an asynchronous request for an ad. - /// - /// ad_unit_id: The ad unit ID to use in loading the ad. - /// request: An AdRequest struct with information about the request - /// to be made (such as targeting info). - Future LoadAd(const char* ad_unit_id, const AdRequest& request); - - /// Returns a Future containing the status of the last call to - /// LoadAd. - Future LoadAdLastResult() const; - - /// Sets an AdListener for this native ad. - /// - /// @param[in] listener An AdListener object which will be invoked - /// when lifecycle events occur on this NativeAd. - void SetAdListener(AdListener* listener); - - /// Returns the associated icon asset of the native ad. - const NativeAdImage& icon() const; - - /// Returns the associated image assets of the native ad. - const std::vector& images() const; - - // Returns the associated adchoices icon asset of the native ad. - const NativeAdImage& adchoices_icon() const; - - /// Only allowlisted ad units use this api. - Future RecordImpression(const Variant& impression_data); - - /// Returns a Future containing the status of the last call to - /// RecordImpression. - Future RecordImpressionLastResult() const; - - /// Only allowlisted ad units use this api. - Future PerformClick(const Variant& click_data); - - /// Returns a Future containing the status of the last call to - /// PerformClick. - Future PerformClickLastResult() const; - - private: - // An internal, platform-specific implementation object that this class uses - // to interact with the Google Mobile Ads SDKs for iOS and Android. - internal::NativeAdInternal* internal_; -}; - -/// Information about the result of a load image operation. -class ImageResult { - public: - /// Default Constructor. - ImageResult(); - - /// Destructor. - virtual ~ImageResult(); - - /// Returns true if the operation was successful. - bool is_successful() const; - - /// If the ImageResult::is_successful() returned false, then the - /// vector returned via this method will contain no contextual - /// information. - const std::vector& image() const; - - private: - friend class GmaInternal; - - /// Constructor invoked upon successful image load. - explicit ImageResult(const std::vector& image_info); - - /// Denotes if the ImageResult represents a success or an error. - bool is_successful_; - - /// Contains the loaded image asset. - std::vector image_info_; -}; - -class NativeAdImage { - public: - /// Default Constructor. - NativeAdImage(); - - /// Copy Constructor. - NativeAdImage(const NativeAdImage& source_native_image); - - /// Returns the image scale, which denotes the ratio of pixels to dp. - double scale() const; - - /// Returns the image uri. - const std::string& image_uri() const; - - /// Begins an asynchronous request for loading an image asset. - Future LoadImage() const; - - // Returns a Future containing the status of the last call to - // LoadImage. - Future LoadImageLastResult() const; - - virtual ~NativeAdImage(); - - /// Assignment operator. - NativeAdImage& operator=(const NativeAdImage& obj); - - private: - friend class NativeAd; - friend class GmaInternal; - - explicit NativeAdImage(const NativeAdImageInternal& native_ad_image_internal); - - // An internal, platform-specific implementation object that this class uses - // to interact with the Google Mobile Ads SDKs for iOS and Android. - NativeAdImageInternal* internal_; -}; - -} // namespace gma -} // namespace firebase - -#endif // DOXYGEN - -#endif // FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_INTERNAL_NATIVE_AD_H_ diff --git a/gma/src/include/firebase/gma/internal/query_info.h b/gma/src/include/firebase/gma/internal/query_info.h deleted file mode 100644 index b2d77959dc..0000000000 --- a/gma/src/include/firebase/gma/internal/query_info.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_INTERNAL_QUERY_INFO_H_ -#define FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_INTERNAL_QUERY_INFO_H_ - -#include - -#include "firebase/future.h" -#include "firebase/gma/types.h" - -// Doxygen breaks trying to parse this file, and since it is internal logic, -// it doesn't need to be included in the generated documentation. -#ifndef DOXYGEN - -namespace firebase { -namespace gma { - -namespace internal { -// Forward declaration for platform-specific data, implemented in each library. -class QueryInfoInternal; -} // namespace internal - -class GmaInternal; -class QueryInfoResult; - -class QueryInfo { - public: - QueryInfo(); - ~QueryInfo(); - - /// Initialize the QueryInfo object. - /// parent: The platform-specific application context. - Future Initialize(AdParent parent); - - /// Returns a Future containing the status of the last call to - /// Initialize. - Future InitializeLastResult() const; - - /// Begins an asynchronous request for creating a query info string. - /// - /// format: The format of the ad for which the query info is being created. - /// request: An AdRequest struct with information about the request - /// to be made (such as targeting info). - Future CreateQueryInfo(AdFormat format, - const AdRequest& request); - - /// Returns a Future containing the status of the last call to - /// CreateQueryInfo. - Future CreateQueryInfoLastResult() const; - - /// Begins an asynchronous request for creating a query info string. - /// - /// format: The format of the ad for which the query info is being created. - /// request: An AdRequest struct with information about the request - /// to be made (such as targeting info). - /// ad_unit_id: The ad unit ID to use in loading the ad. - Future CreateQueryInfoWithAdUnit(AdFormat format, - const AdRequest& request, - const char* ad_unit_id); - - /// Returns a Future containing the status of the last call to - /// CreateQueryInfoWithAdUnit. - Future CreateQueryInfoWithAdUnitLastResult() const; - - private: - // An internal, platform-specific implementation object that this class uses - // to interact with the Google Mobile Ads SDKs for iOS and Android. - internal::QueryInfoInternal* internal_; -}; - -/// Information about the result of a create queryInfo operation. -class QueryInfoResult { - public: - /// Default Constructor. - QueryInfoResult(); - - /// Destructor. - virtual ~QueryInfoResult(); - - /// Returns true if the operation was successful. - bool is_successful() const; - - /// If the QueryInfoResult::is_successful() returned false, then the - /// string returned via this method will contain no contextual - /// information. - const std::string& query_info() const; - - private: - friend class GmaInternal; - - /// Constructor invoked upon successful query info generation. - explicit QueryInfoResult(const std::string& query_info); - - /// Denotes if the QueryInfoResult represents a success or an error. - bool is_successful_; - - /// Contains the full query info string. - std::string query_info_; -}; - -} // namespace gma -} // namespace firebase - -#endif // DOXYGEN - -#endif // FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_INTERNAL_QUERY_INFO_H_ diff --git a/gma/src/include/firebase/gma/interstitial_ad.h b/gma/src/include/firebase/gma/interstitial_ad.h deleted file mode 100644 index 4173209f42..0000000000 --- a/gma/src/include/firebase/gma/interstitial_ad.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_INTERSTITIAL_AD_H_ -#define FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_INTERSTITIAL_AD_H_ - -#include "firebase/future.h" -#include "firebase/gma/types.h" -#include "firebase/internal/common.h" - -namespace firebase { -namespace gma { - -namespace internal { -// Forward declaration for platform-specific data, implemented in each library. -class InterstitialAdInternal; -} // namespace internal - -/// @brief Loads and displays Google Mobile Ads interstitial ads. -/// -/// @ref InterstitialAd is a single-use object that can load and show a -/// single GMA interstitial ad. -/// -/// InterstitialAd objects provide information about their current state -/// through Futures. @ref Initialize, @ref LoadAd, and @ref Show each have a -/// corresponding @ref Future from which you can determine result of the -/// previous call. -/// -/// Here's how one might initialize, load, and show an interstitial ad while -/// checking against the result of the previous action at each step: -/// -/// @code -/// namespace gma = ::firebase::gma; -/// gma::InterstitialAd* interstitial = new gma::InterstitialAd(); -/// interstitial->Initialize(ad_parent); -/// @endcode -/// -/// Then, later: -/// -/// @code -/// if (interstitial->InitializeLastResult().status() == -/// ::firebase::kFutureStatusComplete && -/// interstitial->InitializeLastResult().error() == -/// firebase::gma::kAdErrorCodeNone) { -/// interstitial->LoadAd( "YOUR_AD_UNIT_ID", my_ad_request); -/// } -/// @endcode -/// -/// And after that: -/// -/// @code -/// if (interstitial->LoadAdLastResult().status() == -/// ::firebase::kFutureStatusComplete && -/// interstitial->LoadAdLastResult().error() == -/// firebase::gma::kAdErrorCodeNone)) { -/// interstitial->Show(); -/// } -/// @endcode -/// -/// @deprecated The Google Mobile Ads C++ SDK is now deprecated. Please see -/// https://developers.google.com/admob/cpp/reference/namespace/firebase/gma -/// for more information. -class InterstitialAd { - public: - /// Creates an uninitialized @ref InterstitialAd object. - /// @ref Initialize must be called before the object is used. - FIREBASE_DEPRECATED InterstitialAd(); - - ~InterstitialAd(); - - /// Initialize the @ref InterstitialAd object. - /// @param[in] parent The platform-specific UI element that will host the ad. - FIREBASE_DEPRECATED Future Initialize(AdParent parent); - - /// Returns a @ref Future containing the status of the last call to - /// @ref Initialize. - FIREBASE_DEPRECATED Future InitializeLastResult() const; - - /// Begins an asynchronous request for an ad. - /// - /// @param[in] ad_unit_id The ad unit ID to use in loading the ad. - /// @param[in] request An AdRequest struct with information about the request - /// to be made (such as targeting info). - Future LoadAd(const char* ad_unit_id, const AdRequest& request); - - /// Returns a @ref Future containing the status of the last call to - /// @ref LoadAd. - Future LoadAdLastResult() const; - - /// Shows the @ref InterstitialAd. This should not be called unless an ad has - /// already been loaded. - Future Show(); - - /// Returns a @ref Future containing the status of the last call to - /// @ref Show. - Future ShowLastResult() const; - - /// Sets the @ref FullScreenContentListener for this @ref InterstitialAd. - /// - /// @param[in] listener A valid @ref FullScreenContentListener to receive - /// callbacks. - void SetFullScreenContentListener(FullScreenContentListener* listener); - - /// Registers a callback to be invoked when this ad is estimated to have - /// earned money - /// - /// @param[in] listener A valid @ref PaidEventListener to receive callbacks. - void SetPaidEventListener(PaidEventListener* listener); - - private: - // An internal, platform-specific implementation object that this class uses - // to interact with the Google Mobile Ads SDKs for iOS and Android. - internal::InterstitialAdInternal* internal_; -}; - -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_INTERSTITIAL_AD_H_ diff --git a/gma/src/include/firebase/gma/rewarded_ad.h b/gma/src/include/firebase/gma/rewarded_ad.h deleted file mode 100644 index 6aaafbb798..0000000000 --- a/gma/src/include/firebase/gma/rewarded_ad.h +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_REWARDED_AD_H_ -#define FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_REWARDED_AD_H_ - -#include - -#include "firebase/future.h" -#include "firebase/gma/types.h" -#include "firebase/internal/common.h" - -namespace firebase { -namespace gma { - -namespace internal { -// Forward declaration for platform-specific data, implemented in each library. -class RewardedAdInternal; -} // namespace internal - -/// @brief Loads and displays Google Mobile Ads rewarded ads. -/// -/// @ref RewardedAd is a single-use object that can load and show a -/// single GMA rewarded ad. -/// -/// RewardedAd objects provide information about their current state -/// through Futures. @ref Initialize, @ref LoadAd, and @ref Show each have a -/// corresponding @ref Future from which you can determine result of the -/// previous call. -/// -/// Here's how one might initialize, load, and show an rewarded ad while -/// checking against the result of the previous action at each step: -/// -/// @code -/// namespace gma = ::firebase::gma; -/// gma::RewardedAd* rewarded = new gma::RewardedAd(); -/// rewarded->Initialize(ad_parent); -/// @endcode -/// -/// Then, later: -/// -/// @code -/// if (rewarded->InitializeLastResult().status() == -/// ::firebase::kFutureStatusComplete && -/// rewarded->InitializeLastResult().error() == -/// firebase::gma::kAdErrorCodeNone) { -/// rewarded->LoadAd( "YOUR_AD_UNIT_ID", my_ad_request); -/// } -/// @endcode -/// -/// And after that: -/// -/// @code -/// if (rewarded->LoadAdLastResult().status() == -/// ::firebase::kFutureStatusComplete && -/// rewarded->LoadAdLastResult().error() == -/// firebase::gma::kAdErrorCodeNone)) { -/// rewarded->Show(&my_user_earned_reward_listener); -/// } -/// @endcode -/// -/// @deprecated The Google Mobile Ads C++ SDK is now deprecated. Please see -/// https://developers.google.com/admob/cpp/reference/namespace/firebase/gma -/// for more information. -class RewardedAd { - public: - /// Options for RewardedAd server-side verification callbacks. Set options on - /// a RewardedAd object using the @ref SetServerSideVerificationOptions - /// method. - struct ServerSideVerificationOptions { - /// Custom data to be included in server-side verification callbacks. - std::string custom_data; - - /// User id to be used in server-to-server reward callbacks. - std::string user_id; - }; - - /// Creates an uninitialized @ref RewardedAd object. - /// @ref Initialize must be called before the object is used. - FIREBASE_DEPRECATED RewardedAd(); - - ~RewardedAd(); - - /// Initialize the @ref RewardedAd object. - /// @param[in] parent The platform-specific UI element that will host the ad. - FIREBASE_DEPRECATED Future Initialize(AdParent parent); - - /// Returns a @ref Future containing the status of the last call to - /// @ref Initialize. - FIREBASE_DEPRECATED Future InitializeLastResult() const; - - /// Begins an asynchronous request for an ad. - /// - /// @param[in] ad_unit_id The ad unit ID to use in loading the ad. - /// @param[in] request An AdRequest struct with information about the request - /// to be made (such as targeting info). - Future LoadAd(const char* ad_unit_id, const AdRequest& request); - - /// Returns a @ref Future containing the status of the last call to - /// @ref LoadAd. - Future LoadAdLastResult() const; - - /// Shows the @ref RewardedAd. This should not be called unless an ad has - /// already been loaded. - /// - /// @param[in] listener The @ref UserEarnedRewardListener to be notified when - /// user earns a reward. - Future Show(UserEarnedRewardListener* listener); - - /// Returns a @ref Future containing the status of the last call to - /// @ref Show. - Future ShowLastResult() const; - - /// Sets the @ref FullScreenContentListener for this @ref RewardedAd. - /// - /// @param[in] listener A valid @ref FullScreenContentListener to receive - /// callbacks. - void SetFullScreenContentListener(FullScreenContentListener* listener); - - /// Registers a callback to be invoked when this ad is estimated to have - /// earned money - /// - /// @param[in] listener A valid @ref PaidEventListener to receive callbacks. - void SetPaidEventListener(PaidEventListener* listener); - - /// Sets the server side verification options. - /// - /// @param[in] serverSideVerificationOptions A @ref - /// ServerSideVerificationOptions object containing custom data and a user - /// Id. - void SetServerSideVerificationOptions( - const ServerSideVerificationOptions& serverSideVerificationOptions); - - private: - // An internal, platform-specific implementation object that this class uses - // to interact with the Google Mobile Ads SDKs for iOS and Android. - internal::RewardedAdInternal* internal_; -}; - -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_REWARDED_AD_H_ diff --git a/gma/src/include/firebase/gma/types.h b/gma/src/include/firebase/gma/types.h deleted file mode 100644 index be568f2146..0000000000 --- a/gma/src/include/firebase/gma/types.h +++ /dev/null @@ -1,959 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_TYPES_H_ -#define FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_TYPES_H_ - -#include -#include -#include -#include -#include - -#include "firebase/future.h" -#include "firebase/internal/platform.h" - -#if FIREBASE_PLATFORM_ANDROID -#include -#elif FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS -extern "C" { -#include -} // extern "C" -#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS, - // FIREBASE_PLATFORM_TVOS - -namespace firebase { -namespace gma { - -struct AdErrorInternal; -struct AdapterResponseInfoInternal; -struct BoundingBox; -struct ResponseInfoInternal; - -class AdapterResponseInfo; -class AdViewBoundingBoxListener; -class GmaInternal; -class AdView; -class InterstitialAd; -class PaidEventListener; -class ResponseInfo; - -namespace internal { -class AdViewInternal; -} - -/// This is a platform specific datatype that is required to create -/// a Google Mobile Ads ad. -/// -/// The following defines the datatype on each platform: -///
    -///
  • Android: A `jobject` which references an Android Activity.
  • -///
  • iOS: An `id` which references an iOS UIView.
  • -///
-#if FIREBASE_PLATFORM_ANDROID -/// An Android Activity from Java. -typedef jobject AdParent; -#elif FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS -/// A pointer to an iOS UIView. -typedef id AdParent; -#else -/// A void pointer for stub classes. -typedef void* AdParent; -#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS, - // FIREBASE_PLATFORM_TVOS - -/// Error codes returned by Future::error(). -enum AdErrorCode { - /// Call completed successfully. - kAdErrorCodeNone, - /// The ad has not been fully initialized. - kAdErrorCodeUninitialized, - /// The ad is already initialized (repeat call). - kAdErrorCodeAlreadyInitialized, - /// A call has failed because an ad is currently loading. - kAdErrorCodeLoadInProgress, - /// A call to load an ad has failed due to an internal SDK error. - kAdErrorCodeInternalError, - /// A call to load an ad has failed due to an invalid request. - kAdErrorCodeInvalidRequest, - /// A call to load an ad has failed due to a network error. - kAdErrorCodeNetworkError, - /// A call to load an ad has failed because no ad was available to serve. - kAdErrorCodeNoFill, - /// An attempt has been made to show an ad on an Android Activity that has - /// no window token (such as one that's not done initializing). - kAdErrorCodeNoWindowToken, - /// An attempt to load an Ad Network extras class for an ad request has - /// failed. - kAdErrorCodeAdNetworkClassLoadError, - /// The ad server experienced a failure processing the request. - kAdErrorCodeServerError, - /// The current device’s OS is below the minimum required version. - kAdErrorCodeOSVersionTooLow, - /// The request was unable to be loaded before being timed out. - kAdErrorCodeTimeout, - /// Will not send request because the interstitial object has already been - /// used. - kAdErrorCodeInterstitialAlreadyUsed, - /// The mediation response was invalid. - kAdErrorCodeMediationDataError, - /// Error finding or creating a mediation ad network adapter. - kAdErrorCodeMediationAdapterError, - /// Attempting to pass an invalid ad size to an adapter. - kAdErrorCodeMediationInvalidAdSize, - /// Invalid argument error. - kAdErrorCodeInvalidArgument, - /// Received invalid response. - kAdErrorCodeReceivedInvalidResponse, - /// Will not send a request because the rewarded ad object has already been - /// used. - kAdErrorCodeRewardedAdAlreadyUsed, - /// A mediation ad network adapter received an ad request, but did not fill. - /// The adapter’s error is included as an underlyingError. - kAdErrorCodeMediationNoFill, - /// Will not send request because the ad object has already been used. - kAdErrorCodeAdAlreadyUsed, - /// Will not send request because the application identifier is missing. - kAdErrorCodeApplicationIdentifierMissing, - /// Android Ad String is invalid. - kAdErrorCodeInvalidAdString, - /// The ad can not be shown when app is not in the foreground. - kAdErrorCodeAppNotInForeground, - /// A mediation adapter failed to show the ad. - kAdErrorCodeMediationShowError, - /// The ad is not ready to be shown. - kAdErrorCodeAdNotReady, - /// Ad is too large for the scene. - kAdErrorCodeAdTooLarge, - /// Attempted to present ad from a non-main thread. This is an internal - /// error which should be reported to support if encountered. - kAdErrorCodeNotMainThread, - /// A debug operation failed because the device is not in test mode. - kAdErrorCodeNotInTestMode, - /// An attempt to load the Ad Inspector failed. - kAdErrorCodeInspectorFailedToLoad, - /// The request to show the Ad Inspector failed because it's already open. - kAdErrorCodeInsepctorAlreadyOpen, - /// Error processing image url. - kAdErrorCodeImageUrlMalformed, - /// Fallback error for any unidentified cases. - kAdErrorCodeUnknown, -}; - -#if !defined(DOXYGEN) -/// Format of the ad being requested. Currently used only for internal updates. -enum AdFormat { - /// App open ad format. - kAdFormatAppOpen, - /// Banner ad format. - kAdFormatBanner, - /// Interstitial ad format. - kAdFormatInterstitial, - /// Native ad format. - kAdFormatNative, - /// Rewarded ad format. - kAdFormatRewarded, - /// Rewarded interstitial ad format. - kAdFormatRewardedInterstitial, -}; -#endif // !defined(DOXYGEN) - -/// A listener for receiving notifications during the lifecycle of a BannerAd. -class AdListener { - public: - virtual ~AdListener(); - - /// Called when a click is recorded for an ad. - virtual void OnAdClicked() {} - - /// Called when the user is about to return to the application after clicking - /// on an ad. - virtual void OnAdClosed() {} - - /// Called when an impression is recorded for an ad. - virtual void OnAdImpression() {} - - /// Called when an ad opens an overlay that covers the screen. - virtual void OnAdOpened() {} -}; - -/// Information about why an ad operation failed. -class AdError { - public: - /// Default Constructor. - AdError(); - - /// Copy Constructor. - AdError(const AdError& ad_error); - - /// Destructor. - virtual ~AdError(); - - /// Assignment operator. - AdError& operator=(const AdError& obj); - - /// Retrieves an AdError which represents the cause of this error. - /// - /// @return a pointer to an adError which represents the cause of this - /// AdError. If there was no cause then nullptr is returned. - std::unique_ptr GetCause() const; - - /// Gets the error's code. - AdErrorCode code() const; - - /// Gets the domain of the error. - const std::string& domain() const; - - /// Gets the message describing the error. - const std::string& message() const; - - /// Gets the ResponseInfo if an error occurred during a loadAd operation. - /// The ResponseInfo will have empty fields if this AdError does not - /// represent an error stemming from a load ad operation. - const ResponseInfo& response_info() const; - - /// Returns a log friendly string version of this object. - virtual const std::string& ToString() const; - - /// A domain string which represents an undefined error domain. - /// - /// The GMA SDK returns this domain for domain() method invocations when - /// converting error information from legacy mediation adapter callbacks. - static const char* const kUndefinedDomain; - - private: - friend class AdapterResponseInfo; - friend class GmaInternal; - friend class AdView; - friend class InterstitialAd; - - /// Constructor used when building results in Ad event callbacks. - explicit AdError(const AdErrorInternal& ad_error_internal); - - // Collection of response from adapters if this Result is due to a loadAd - // operation. - ResponseInfo* response_info_; - - // An internal, platform-specific implementation object that this class uses - // to interact with the Google Mobile Ads SDKs for iOS and Android. - AdErrorInternal* internal_; -}; - -/// Information about an ad response. -class ResponseInfo { - public: - /// Constructor creates an uninitialized ResponseInfo. - ResponseInfo(); - - /// Gets the AdapterResponseInfo objects for the ad response. - /// - /// @return a vector of AdapterResponseInfo objects containing metadata for - /// each adapter included in the ad response. - const std::vector& adapter_responses() const { - return adapter_responses_; - } - - /// A class name that identifies the ad network that returned the ad. - /// Returns an empty string if the ad failed to load. - const std::string& mediation_adapter_class_name() const { - return mediation_adapter_class_name_; - } - - /// Gets the response ID string for the loaded ad. Returns an empty - /// string if the ad fails to load. - const std::string& response_id() const { return response_id_; } - - /// Gets a log friendly string version of this object. - const std::string& ToString() const { return to_string_; } - - private: - friend class AdError; - friend class GmaInternal; - - explicit ResponseInfo(const ResponseInfoInternal& internal); - - std::vector adapter_responses_; - std::string mediation_adapter_class_name_; - std::string response_id_; - std::string to_string_; -}; - -/// Information about the result of an ad operation. -class AdResult { - public: - /// Default Constructor. - AdResult(); - - /// Constructor. - explicit AdResult(const AdError& ad_error); - - /// Destructor. - virtual ~AdResult(); - - /// Returns true if the operation was successful. - bool is_successful() const; - - /// An object representing an error which occurred during an ad operation. - /// If the @ref AdResult::is_successful() returned true, then the - /// @ref AdError object returned via this method will contain no contextual - /// information. - const AdError& ad_error() const; - - /// For debugging and logging purposes, successfully loaded ads provide a - /// ResponseInfo object which contains information about the adapter which - /// loaded the ad. If the ad failed to load then the object returned from - /// this method will have default values. Information about the error - /// should be retrieved via @ref AdResult::ad_error() instead. - const ResponseInfo& response_info() const; - - private: - friend class GmaInternal; - - /// Constructor invoked upon successful ad load. This contains response - /// information from the adapter which loaded the ad. - explicit AdResult(const ResponseInfo& response_info); - - /// Denotes if the @ref AdResult represents a success or an error. - bool is_successful_; - - /// Information about the error. Will be a default-constructed @ref AdError - /// if this result represents a success. - AdError ad_error_; - - /// Information from the adapter which loaded the ad. - ResponseInfo response_info_; -}; - -/// A snapshot of a mediation adapter's initialization status. -class AdapterStatus { - public: - AdapterStatus() : is_initialized_(false), latency_(0) {} - - /// Detailed description of the status. - /// - /// This method should only be used for informational purposes, such as - /// logging. Use @ref is_initialized to make logical decisions regarding an - /// adapter's status. - const std::string& description() const { return description_; } - - /// Returns the adapter's initialization state. - bool is_initialized() const { return is_initialized_; } - - /// The adapter's initialization latency in milliseconds. - /// 0 if initialization has not yet ended. - int latency() const { return latency_; } - -#if !defined(DOXYGEN) - // Equality operator for testing. - bool operator==(const AdapterStatus& rhs) const { - return (description() == rhs.description() && - is_initialized() == rhs.is_initialized() && - latency() == rhs.latency()); - } -#endif // !defined(DOXYGEN) - - private: - friend class GmaInternal; - std::string description_; - bool is_initialized_; - int latency_; -}; - -/// An immutable snapshot of the GMA SDK’s initialization status, categorized -/// by mediation adapter. -class AdapterInitializationStatus { - public: - /// Initialization status of each known ad network, keyed by its adapter's - /// class name. - std::map GetAdapterStatusMap() const { - return adapter_status_map_; - } -#if !defined(DOXYGEN) - // Equality operator for testing. - bool operator==(const AdapterInitializationStatus& rhs) const { - return (GetAdapterStatusMap() == rhs.GetAdapterStatusMap()); - } -#endif // !defined(DOXYGEN) - - private: - friend class GmaInternal; - std::map adapter_status_map_; -}; - -/// Listener to be invoked when the Ad Inspector has been closed. -class AdInspectorClosedListener { - public: - virtual ~AdInspectorClosedListener(); - - /// Called when the user clicked the ad. The AdResult contains the status of - /// the operation, including details of the error if one occurred. - virtual void OnAdInspectorClosed(const AdResult& ad_result) = 0; -}; - -/// @brief Response information for an individual ad network contained within -/// a @ref ResponseInfo object. -class AdapterResponseInfo { - public: - /// Destructor - ~AdapterResponseInfo(); - - /// @brief Information about the result including whether an error - /// occurred, and any contextual information about that error. - /// - /// @return the error that occurred while rendering the ad. If no error - /// occurred then the AdResult's successful method will return true. - AdResult ad_result() const { return ad_result_; } - - /// Returns a string representation of a class name that identifies the ad - /// network adapter. - const std::string& adapter_class_name() const { return adapter_class_name_; } - - /// Amount of time the ad network spent loading an ad. - /// - /// @return number of milliseconds the network spent loading an ad. This value - /// is 0 if the network did not make a load attempt. - int64_t latency_in_millis() const { return latency_; } - - /// A log friendly string version of this object. - const std::string& ToString() const { return to_string_; } - - private: - friend class ResponseInfo; - - /// Constructs an Adapter Response Info Object. - explicit AdapterResponseInfo(const AdapterResponseInfoInternal& internal); - - AdResult ad_result_; - std::string adapter_class_name_; - int64_t latency_; - std::string to_string_; -}; - -/// The size of a banner ad. -class AdSize { - public: - /// Denotes the orientation of the AdSize. - enum Orientation { - /// AdSize should reflect the current orientation of the device. - kOrientationCurrent = 0, - - /// AdSize will be adaptively formatted in Landscape mode. - kOrientationLandscape, - - /// AdSize will be adaptively formatted in Portrait mode. - kOrientationPortrait - }; - - /// Denotes the type size object that the @ref AdSize represents. - enum Type { - /// The standard AdSize type of a set height and width. - kTypeStandard = 0, - - /// An adaptive size anchored to a portion of the screen. - kTypeAnchoredAdaptive, - - /// An adaptive size intended to be embedded in scrollable content. - kTypeInlineAdaptive, - }; - - /// Mobile Marketing Association (MMA) banner ad size (320x50 - /// density-independent pixels). - static const AdSize kBanner; - - /// Interactive Advertising Bureau (IAB) full banner ad size - /// (468x60 density-independent pixels). - static const AdSize kFullBanner; - - /// Taller version of kBanner. Typically 320x100. - static const AdSize kLargeBanner; - - /// Interactive Advertising Bureau (IAB) leaderboard ad size - /// (728x90 density-independent pixels). - static const AdSize kLeaderboard; - - /// Interactive Advertising Bureau (IAB) medium rectangle ad size - /// (300x250 density-independent pixels). - static const AdSize kMediumRectangle; - - /// Creates a new AdSize. - /// - /// @param[in] width The width of the ad in density-independent pixels. - /// @param[in] height The height of the ad in density-independent pixels. - AdSize(uint32_t width, uint32_t height); - - /// @brief Creates an AdSize with the given width and a Google-optimized - /// height to create a banner ad in landscape mode. - /// - /// @param[in] width The width of the ad in density-independent pixels. - /// - /// @return an AdSize with the given width and a Google-optimized height - /// to create a banner ad. The size returned will have an aspect ratio - /// similar to BANNER, suitable for anchoring near the top or bottom of - /// your app. The exact size of the ad returned can be retrieved by calling - /// @ref AdView::ad_size once the ad has been loaded. - static AdSize GetLandscapeAnchoredAdaptiveBannerAdSize(uint32_t width); - - /// @brief Creates an AdSize with the given width and a Google-optimized - /// height to create a banner ad in portrait mode. - /// - /// @param[in] width The width of the ad in density-independent pixels. - /// - /// @return an AdSize with the given width and a Google-optimized height - /// to create a banner ad. The size returned will have an aspect ratio - /// similar to BANNER, suitable for anchoring near the top or bottom - /// of your app. The exact size of the ad returned can be retrieved by - /// calling @ref AdView::ad_size once the ad has been loaded. - static AdSize GetPortraitAnchoredAdaptiveBannerAdSize(uint32_t width); - - /// @brief Creates an AdSize with the given width and a Google-optimized - /// height to create a banner ad given the current orientation. - /// - /// @param[in] width The width of the ad in density-independent pixels. - /// - /// @return an AdSize with the given width and a Google-optimized height - /// to create a banner ad. The size returned will have an aspect ratio - /// similar to AdSize, suitable for anchoring near the top or bottom of - /// your app. The exact size of the ad returned can be retrieved by calling - /// @ref AdView::ad_size once the ad has been loaded. - static AdSize GetCurrentOrientationAnchoredAdaptiveBannerAdSize( - uint32_t width); - - /// @brief This ad size is most suitable for banner ads given a maximum - /// height. - /// - /// This AdSize allows Google servers to choose an optimal ad size with - /// a height less than or equal to the max height given in - /// - /// @param[in] width The width of the ad in density-independent pixels. - /// @param[in] max_height The maximum height that a loaded ad will have. Must - /// be - /// at least 32 dp, but a maxHeight of 50 dp or higher is recommended. - /// - /// @return an AdSize with the given width and a height that is always 0. - /// The exact size of the ad returned can be retrieved by calling - /// @ref AdView::ad_size once the ad has been loaded. - static AdSize GetInlineAdaptiveBannerAdSize(int width, int max_height); - - /// @brief Creates an AdSize with the given width and the device’s - /// landscape height. - /// - /// This ad size allows Google servers to choose an optimal ad size with - /// a height less than or equal to the height of the screen in landscape - /// orientation. - /// - /// @param[in] width The width of the ad in density-independent pixels. - /// - /// @return an AdSize with the given width and a height that is always 0. - /// The exact size of the ad returned can be retrieved by calling - /// @ref AdView::ad_size once the ad has been loaded. - static AdSize GetLandscapeInlineAdaptiveBannerAdSize(int width); - - /// @brief Creates an AdSize with the given width and the device’s - /// portrait height. - /// - /// This ad size allows Google servers to choose an optimal ad size with - /// a height less than or equal to the height of the screen in portrait - /// orientation. - /// - /// @param[in] width The width of the ad in density-independent pixels. - /// - /// @return an AdSize with the given width and a height that is always 0. - /// The exact size of the ad returned can be retrieved by calling - /// @ref AdView::ad_size once the ad has been loaded. - static AdSize GetPortraitInlineAdaptiveBannerAdSize(int width); - - /// @brief A convenience method to return an inline adaptive banner ad size - /// given the current interface orientation. - /// - /// This AdSize allows Google servers to choose an optimal ad size with a - /// height less than or equal to the height of the screen in the requested - /// orientation. - /// - /// @param[in] width The width of the ad in density-independent pixels. - /// - /// @return an AdSize with the given width and a height that is always 0. - /// The exact size of the ad returned can be retrieved by calling - /// @ref AdView::ad_size once the ad has been loaded. - static AdSize GetCurrentOrientationInlineAdaptiveBannerAdSize(int width); - - /// Comparison operator. - /// - /// @return true if `rhs` refers to the same AdSize as `this`. - bool operator==(const AdSize& rhs) const; - - /// Comparison operator. - /// - /// @return true if `rhs` refers to a different AdSize as `this`. - bool operator!=(const AdSize& rhs) const; - - /// The width of the region represented by this AdSize. Value is in - /// density-independent pixels. - uint32_t width() const { return width_; } - - /// The height of the region represented by this AdSize. Value is in - /// density-independent pixels. - uint32_t height() const { return height_; } - - /// The AdSize orientation. - Orientation orientation() const { return orientation_; } - - /// The AdSize type, either standard size or adaptive. - Type type() const { return type_; } - - private: - friend class firebase::gma::internal::AdViewInternal; - - /// Returns an Anchor Adaptive AdSize Object given a width and orientation. - static AdSize GetAnchoredAdaptiveBannerAdSize(uint32_t width, - Orientation orientation); - - /// Returns true if the AdSize parameter is equivalient to this AdSize object. - bool is_equal(const AdSize& ad_size) const; - - /// Denotes the orientation for anchored adaptive AdSize objects. - Orientation orientation_; - - /// Advertisement width in platform-indepenent pixels. - uint32_t width_; - - /// Advertisement width in platform-indepenent pixels. - uint32_t height_; - - /// The type of AdSize (standard or adaptive) - Type type_; -}; - -/// Contains targeting information used to fetch an ad. -class AdRequest { - public: - /// Creates an @ref AdRequest with no custom configuration. - AdRequest(); - - /// Creates an @ref AdRequest with the optional content URL. - /// - /// When requesting an ad, apps may pass the URL of the content they are - /// serving. This enables keyword targeting to match the ad with the content. - /// - /// The URL is ignored if null or the number of characters exceeds 512. - /// - /// @param[in] content_url the url of the content being viewed. - explicit AdRequest(const char* content_url); - - ~AdRequest(); - - /// The content URL targeting information. - /// - /// @return the content URL for the @ref AdRequest. The string will be empty - /// if no content URL has been configured. - const std::string& content_url() const { return content_url_; } - - /// A Map of adapter class names to their collection of extra parameters, as - /// configured via @ref add_extra. - const std::map >& extras() - const { - return extras_; - } - - /// Keywords which will help GMA to provide targeted ads, as added by - /// @ref add_keyword. - const std::unordered_set& keywords() const { return keywords_; } - - /// Returns the set of neighboring content URLs or an empty set if no URLs - /// were set via @ref add_neighboring_content_urls(). - const std::unordered_set& neighboring_content_urls() const { - return neighboring_content_urls_; - } - - /// Add a network extra for the associated ad mediation adapter. - /// - /// Appends an extra to the corresponding list of extras for the ad mediation - /// adapter. Each ad mediation adapter can have multiple extra strings. - /// - /// @param[in] adapter_class_name the class name of the ad mediation adapter - /// for which to add the extra. - /// @param[in] extra_key a key which will be passed to the corresponding ad - /// mediation adapter. - /// @param[in] extra_value the value associated with extra_key. - void add_extra(const char* adapter_class_name, const char* extra_key, - const char* extra_value); - - /// Adds a keyword for targeting purposes. - /// - /// Multiple keywords may be added via repeated invocations of this method. - /// - /// @param[in] keyword a string that GMA will use to aid in targeting ads. - void add_keyword(const char* keyword); - - /// When requesting an ad, apps may pass the URL of the content they are - /// serving. This enables keyword targeting to match the ad with the content. - /// - /// The URL is ignored if null or the number of characters exceeds 512. - /// - /// @param[in] content_url the url of the content being viewed. - void set_content_url(const char* content_url); - - /// Adds to the list of URLs which represent web content near an ad. - /// - /// Promotes brand safety and allows displayed ads to have an app level - /// rating (MA, T, PG, etc) that is more appropriate to neighboring content. - /// - /// Subsequent invocations append to the existing list. - /// - /// @param[in] neighboring_content_urls neighboring content URLs to be - /// attached to the existing neighboring content URLs. - void add_neighboring_content_urls( - const std::vector& neighboring_content_urls); - - private: - std::string content_url_; - std::map > extras_; - std::unordered_set keywords_; - std::unordered_set neighboring_content_urls_; -}; - -/// Describes a reward credited to a user for interacting with a RewardedAd. -class AdReward { - public: - /// Creates an @ref AdReward. - AdReward(const std::string& type, int64_t amount) - : amount_(amount), type_(type) {} - - /// Returns the reward amount. - int64_t amount() const { return amount_; } - - /// Returns the type of the reward. - const std::string& type() const { return type_; } - - private: - const int64_t amount_; - const std::string type_; -}; - -/// The monetary value earned from an ad. -class AdValue { - public: - /// Allowed constants for @ref precision_type(). - enum PrecisionType { - /// An ad value with unknown precision. - kAdValuePrecisionUnknown = 0, - /// An ad value estimated from aggregated data. - kAdValuePrecisionEstimated, - /// A publisher-provided ad value, such as manual CPMs in a mediation group. - kAdValuePrecisionPublisherProvided = 2, - /// The precise value paid for this ad. - kAdValuePrecisionPrecise = 3 - }; - - /// Constructor - AdValue(const char* currency_code, PrecisionType precision_type, - int64_t value_micros) - : currency_code_(currency_code), - precision_type_(precision_type), - value_micros_(value_micros) {} - - /// The value's ISO 4217 currency code. - const std::string& currency_code() const { return currency_code_; } - - /// The precision of the reported ad value. - PrecisionType precision_type() const { return precision_type_; } - - /// The ad's value in micro-units, where 1,000,000 micro-units equal one - /// unit of the currency. - int64_t value_micros() const { return value_micros_; } - - private: - const std::string currency_code_; - const PrecisionType precision_type_; - const int64_t value_micros_; -}; - -/// @brief Listener to be invoked when ads show and dismiss full screen content, -/// such as a fullscreen ad experience or an in-app browser. -class FullScreenContentListener { - public: - virtual ~FullScreenContentListener(); - - /// Called when the user clicked the ad. - virtual void OnAdClicked() {} - - /// Called when the ad dismissed full screen content. - virtual void OnAdDismissedFullScreenContent() {} - - /// Called when the ad failed to show full screen content. - /// - /// @param[in] ad_error An object containing detailed information - /// about the error. - virtual void OnAdFailedToShowFullScreenContent(const AdError& ad_error) {} - - /// Called when an impression is recorded for an ad. - virtual void OnAdImpression() {} - - /// Called when the ad showed the full screen content. - virtual void OnAdShowedFullScreenContent() {} -}; - -/// Listener to be invoked when ads have been estimated to earn money. -class PaidEventListener { - public: - virtual ~PaidEventListener(); - - /// Called when an ad is estimated to have earned money. - virtual void OnPaidEvent(const AdValue& value) {} -}; - -/// @brief Global configuration that will be used for every @ref AdRequest. -/// Set the configuration via @ref SetRequestConfiguration. -struct RequestConfiguration { - /// A maximum ad content rating, which may be configured via - /// @ref max_ad_content_rating. - enum MaxAdContentRating { - /// No content rating has been specified. - kMaxAdContentRatingUnspecified = -1, - - /// Content suitable for general audiences, including families. - kMaxAdContentRatingG, - - /// Content suitable only for mature audiences. - kMaxAdContentRatingMA, - - /// Content suitable for most audiences with parental guidance. - kMaxAdContentRatingPG, - - /// Content suitable for teen and older audiences. - kMaxAdContentRatingT - }; - - /// Specify whether you would like your app to be treated as child-directed - /// for purposes of the Children’s Online Privacy Protection Act (COPPA). - /// Values defined here may be configured via - /// @ref tag_for_child_directed_treatment. - enum TagForChildDirectedTreatment { - /// Indicates that ad requests will include no indication of how you would - /// like your app treated with respect to COPPA. - kChildDirectedTreatmentUnspecified = -1, - - /// Indicates that your app should not be treated as child-directed for - /// purposes of the Children’s Online Privacy Protection Act (COPPA). - kChildDirectedTreatmentFalse, - - /// Indicates that your app should be treated as child-directed for purposes - /// of the Children’s Online Privacy Protection Act (COPPA). - kChildDirectedTreatmentTrue - }; - - /// Configuration values to mark your app to receive treatment for users in - /// the European Economic Area (EEA) under the age of consent. Values defined - /// here should be configured via @ref tag_for_under_age_of_consent. - enum TagForUnderAgeOfConsent { - /// Indicates that the publisher has not specified whether the ad request - /// should receive treatment for users in the European Economic Area (EEA) - /// under the age of consent. - kUnderAgeOfConsentUnspecified = -1, - - /// Indicates the publisher specified that the ad request should not receive - /// treatment for users in the European Economic Area (EEA) under the age of - /// consent. - kUnderAgeOfConsentFalse, - - /// Indicates the publisher specified that the ad request should receive - /// treatment for users in the European Economic Area (EEA) under the age of - /// consent. - kUnderAgeOfConsentTrue - }; - - /// Sets a maximum ad content rating. GMA ads returned for your app will - /// have a content rating at or below that level. - MaxAdContentRating max_ad_content_rating; - - /// @brief Allows you to specify whether you would like your app - /// to be treated as child-directed for purposes of the Children’s Online - /// Privacy Protection Act (COPPA) - - /// http://business.ftc.gov/privacy-and-security/childrens-privacy. - /// - /// If you set this value to - /// RequestConfiguration.kChildDirectedTreatmentTrue, you will indicate - /// that your app should be treated as child-directed for purposes of the - /// Children’s Online Privacy Protection Act (COPPA). - /// - /// If you set this value to - /// RequestConfiguration.kChildDirectedTreatmentFalse, you will indicate - /// that your app should not be treated as child-directed for purposes of the - /// Children’s Online Privacy Protection Act (COPPA). - /// - /// If you do not set this value, or set this value to - /// RequestConfiguration.kChildDirectedTreatmentUnspecified, ad requests will - /// include no indication of how you would like your app treated with respect - /// to COPPA. - /// - /// By setting this value, you certify that this notification is accurate and - /// you are authorized to act on behalf of the owner of the app. You - /// understand that abuse of this setting may result in termination of your - /// Google account. - /// - /// @note: it may take some time for this designation to be fully implemented - /// in applicable Google services. - /// - TagForChildDirectedTreatment tag_for_child_directed_treatment; - - /// This value allows you to mark your app to receive treatment for users in - /// the European Economic Area (EEA) under the age of consent. This feature is - /// designed to help facilitate compliance with the General Data Protection - /// Regulation (GDPR). Note that you may have other legal obligations under - /// GDPR. Please review the European Union's guidance and consult with your - /// own legal counsel. Please remember that Google's tools are designed to - /// facilitate compliance and do not relieve any particular publisher of its - /// obligations under the law. - /// - /// When using this feature, a Tag For Users under the Age of Consent in - /// Europe (TFUA) parameter will be included in all ad requests. This - /// parameter disables personalized advertising, including remarketing, for - /// that specific ad request. It also disables requests to third-party ad - /// vendors, such as ad measurement pixels and third-party ad servers. - /// - /// If you set this value to RequestConfiguration.kUnderAgeOfConsentTrue, you - /// will indicate that you want your app to be handled in a manner suitable - /// for users under the age of consent. - /// - /// If you set this value to RequestConfiguration.kUnderAgeOfConsentFalse, - /// you will indicate that you don't want your app to be handled in a manner - /// suitable for users under the age of consent. - /// - /// If you do not set this value, or set this value to - /// kUnderAgeOfConsentUnspecified, your app will include no indication of how - /// you would like your app to be handled in a manner suitable for users under - /// the age of consent. - TagForUnderAgeOfConsent tag_for_under_age_of_consent; - - /// Sets a list of test device IDs corresponding to test devices which will - /// always request test ads. - std::vector test_device_ids; -}; - -/// Listener to be invoked when the user earned a reward. -class UserEarnedRewardListener { - public: - virtual ~UserEarnedRewardListener(); - /// Called when the user earned a reward. The app is responsible for - /// crediting the user with the reward. - /// - /// @param[in] reward the @ref AdReward that should be granted to the user. - virtual void OnUserEarnedReward(const AdReward& reward) {} -}; - -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_TYPES_H_ diff --git a/gma/src/include/firebase/gma/ump.h b/gma/src/include/firebase/gma/ump.h deleted file mode 100644 index 26e90d630b..0000000000 --- a/gma/src/include/firebase/gma/ump.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_UMP_H_ -#define FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_UMP_H_ - -#include "firebase/gma/ump/consent_info.h" -#include "firebase/gma/ump/types.h" - -#endif // FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_UMP_H_ diff --git a/gma/src/include/firebase/gma/ump/consent_info.h b/gma/src/include/firebase/gma/ump/consent_info.h deleted file mode 100644 index 40b80baef3..0000000000 --- a/gma/src/include/firebase/gma/ump/consent_info.h +++ /dev/null @@ -1,308 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_UMP_CONSENT_INFO_H_ -#define FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_UMP_CONSENT_INFO_H_ - -#include "firebase/app.h" -#include "firebase/future.h" -#include "firebase/gma/ump/types.h" -#include "firebase/internal/common.h" -#include "firebase/internal/platform.h" - -#if FIREBASE_PLATFORM_ANDROID -#include -#endif // FIREBASE_PLATFORM_ANDROID - -namespace firebase { -namespace gma { -/// @brief API for User Messaging Platform. -/// -/// The User Messaging Platform (UMP) SDK is Google’s option to handle user -/// privacy and consent in mobile apps. -/// -/// @deprecated The firebase::gma::ump namespace has been deprecated and -/// renamed to firebase::ump. -namespace ump { - -namespace internal { -// Forward declaration for platform-specific data, implemented in each library. -class ConsentInfoInternal; -} // namespace internal - -/// @brief Consent Information class for the User Messaging Platform SDK. -/// -/// The User Messaging Platform (UMP) SDK is Google’s option to handle user -/// privacy and consent in mobile apps. -/// -/// This class contains all of the methods necessary for obtaining -/// consent from the user. -/// -/// @deprecated This class has been moved to the firebase::ump namespace. -class ConsentInfo { - public: - /// Shut down the User Messaging Platform Consent SDK. - ~ConsentInfo(); - - /// Initializes the User Messaging Platform Consent SDK. - /// - /// @param[in] app Any Firebase App instance. - /// - /// @param[out] init_result_out Optional: If provided, write the basic init - /// result here. kInitResultSuccess if initialization succeeded, or - /// kInitResultFailedMissingDependency on Android if there are Android - /// dependencies missing. - /// - /// @return A pointer to the ConsentInfo instance if UMP was successfully - /// initialized, nullptr otherwise. Each call to GetInstance() will return the - /// same pointer; when you are finished using the SDK, you can delete the - /// pointer and the UMP SDK will shut down. - /// - /// @deprecated This class has been moved to the firebase::ump namespace. - FIREBASE_DEPRECATED - static ConsentInfo* GetInstance(const ::firebase::App& app, - InitResult* init_result_out = nullptr); - -#if FIREBASE_PLATFORM_ANDROID || defined(DOXYGEN) - /// Initializes the User Messaging Platform Consent SDK without Firebase for - /// Android. - /// - /// The arguments to GetInstance() are platform-specific so the caller must - /// do something like this: - /// @code - /// #if defined(__ANDROID__) - /// consent_info = firebase::gma::ump::ConsentInfo::GetInstance(jni_env, - /// activity); - /// #else - /// consent_info = firebase::gma::ump::GetInstance(); - /// #endif - /// @endcode - /// - /// @param[in] jni_env JNIEnv pointer. - /// @param[in] activity Activity used to start the application. - /// @param[out] init_result_out Optional: If provided, write the basic init - /// result here. kInitResultSuccess if initialization succeeded, or - /// kInitResultFailedMissingDependency on Android if there are Android - /// dependencies missing. - /// - /// @return A pointer to the ConsentInfo instance if UMP was successfully - /// initialized, nullptr otherwise. Each call to GetInstance() will return the - /// same pointer; when you are finished using the SDK, you can delete the - /// pointer and the UMP SDK will shut down. - FIREBASE_DEPRECATED - static ConsentInfo* GetInstance(JNIEnv* jni_env, jobject activity, - InitResult* init_result_out = nullptr); - -#if !defined(DOXYGEN) - // On Android, this convenience function exists so you can easily get the - // existing ConsentInfo instance after it's first initialized. Returns nullptr - // if no instance has been created yet; make sure you have called - // GetInstance(JNIEnv*, jobject) first. - FIREBASE_DEPRECATED - static ConsentInfo* GetInstance(); -#endif // defined(DOXYGEN) -#endif // FIREBASE_PLATFORM_ANDROID || defined(DOXYGEN) - -#if !FIREBASE_PLATFORM_ANDROID || defined(DOXYGEN) - /// Initializes User Messaging Platform for iOS without Firebase. - /// - /// @param[out] init_result_out Optional: If provided, write the basic init - /// result here. kInitResultSuccess if initialization succeeded, or - /// kInitResultFailedMissingDependency if a dependency is missing. On iOS, - /// this will always return kInitResultSuccess, as missing dependencies would - /// have caused a linker error at build time. - /// - /// @return A pointer to the ConsentInfo instance. Each call to GetInstance() - /// will return the same pointer; when you are finished using the SDK, you can - /// delete the pointer, and the UMP SDK will shut down. - /// - /// @note Once any overload of ConsentInfo::GetInstance has been called, you - /// can use this method to obtain the same instance again. - /// - /// @deprecated This class has been moved to the firebase::ump namespace. - FIREBASE_DEPRECATED - static ConsentInfo* GetInstance(InitResult* init_result_out = nullptr); -#endif // !defined(__ANDROID__) || defined(DOXYGEN) - - /// The user’s consent status. This value defaults to kConsentStatusUnknown - /// until RequestConsentInfoUpdate() is called, and defaults to the previous - /// session’s value until RequestConsentInfoUpdate() completes. - /// - /// @deprecated This class has been moved to the firebase::ump namespace. - FIREBASE_DEPRECATED - ConsentStatus GetConsentStatus(); - - /// Requests consent information update. Must be called in every app session - /// before checking the user’s consent status or loading a consent form. After - /// calling this method, GetConsentStatus() and CanRequestAds() will be - /// updated immediately to hold the consent state from the previous app - /// session, if one exists. GetConsentStatus() and CanRequestAds() may be - /// updated again immediately before the returned future is completed. - /// - /// @deprecated This class has been moved to the firebase::ump namespace. - FIREBASE_DEPRECATED - Future RequestConsentInfoUpdate(const ConsentRequestParameters& params); - - /// Get the Future from the most recent call to RequestConsentInfoUpdate(). - /// - /// @deprecated This class has been moved to the firebase::ump namespace. - FIREBASE_DEPRECATED - Future RequestConsentInfoUpdateLastResult(); - - /// Consent form status. This value defaults to kConsentFormStatusUnknown and - /// requires a call to RequestConsentInfoUpdate() to update. - /// - /// @deprecated This class has been moved to the firebase::ump namespace. - FIREBASE_DEPRECATED - ConsentFormStatus GetConsentFormStatus(); - - /// Loads a consent form. Returns an error if the consent form is unavailable - /// or cannot be loaded. - /// - /// @deprecated This class has been moved to the firebase::ump namespace. - FIREBASE_DEPRECATED - Future LoadConsentForm(); - - /// Get the Future from the most recent call to LoadConsentForm(). - /// - /// @deprecated This class has been moved to the firebase::ump namespace. - FIREBASE_DEPRECATED - Future LoadConsentFormLastResult(); - - /// Presents the full screen consent form using the given FormParent, which is - /// defined as an Activity on Android and a UIViewController on iOS. The form - /// will be dismissed and the Future will be completed after the user selects - /// an option. - /// - /// GetConsentStatus() and CanRequestAds() are updated when the returned - /// Future is completed. - /// - /// @param[in] parent A FormParent, which is an Activity object on Android and - /// a UIViewController object on iOS. - /// - /// @note You must call LoadConsentForm() and wait for it to complete before - /// calling this method. - /// - /// @deprecated This class has been moved to the firebase::ump namespace. - FIREBASE_DEPRECATED - Future ShowConsentForm(FormParent parent); - - /// Get the Future from the most recent call to ShowConsentForm(). - /// - /// @deprecated This class has been moved to the firebase::ump namespace. - FIREBASE_DEPRECATED - Future ShowConsentFormLastResult(); - - /// Loads a consent form and immediately presents it using the given - /// FormParent, if ConsentStatus is kConsentStatusRequired. The FormParent is - /// defined as an Activity on Android and a UIViewController on iOS. The - /// Future will be completed successfully after the user selects an option - /// (and the form is dismissed), or if the form is not required. The Future - /// will be completed with an error if the form fails to load or show. - /// - /// GetConsentStatus() and CanRequestAds() will be updated prior to the Future - /// being completed. - /// - /// @param[in] parent A FormParent, which is an Activity object on Android and - /// a UIViewController object on iOS. - /// - /// @deprecated This class has been moved to the firebase::ump namespace. - FIREBASE_DEPRECATED - Future LoadAndShowConsentFormIfRequired(FormParent parent); - - /// Get the Future from the most recent call to - /// LoadAndShowConsentFormIfRequired(). - /// - /// @deprecated This class has been moved to the firebase::ump namespace. - FIREBASE_DEPRECATED - Future LoadAndShowConsentFormIfRequiredLastResult(); - - /// Check whether the privacy options form needs to be displayed. - /// This is updated by RequestConsentInfoUpdate(). - /// - /// @deprecated This class has been moved to the firebase::ump namespace. - FIREBASE_DEPRECATED - PrivacyOptionsRequirementStatus GetPrivacyOptionsRequirementStatus(); - - /// If GetPrivacyOptionsRequirementStatus() is - /// kPrivacyOptionsRequirementStatusRequired, presents a privacy options form - /// from the provided FormParent, which is defined as an Activity on Android - /// and a UIViewController on iOS. - /// - /// This method should only be called in response to a user input to request a - /// privacy options form to be shown. - /// - /// The future completes when the user selects an option and dismisses the - /// form or is completed immediately with an error code if no form is - /// presented. The privacy options form is preloaded by the SDK automatically - /// when a form becomes available. If no form has been preloaded, the SDK will - /// try to load one asynchronously. - /// - /// @param[in] parent A FormParent, which is an Activity object on Android and - /// a UIViewController object on iOS. - /// - /// @deprecated This class has been moved to the firebase::ump namespace. - FIREBASE_DEPRECATED - Future ShowPrivacyOptionsForm(FormParent parent); - - /// Get the Future from the most recent call to ShowPrivacyOptionsForm(). - /// - /// @deprecated This class has been moved to the firebase::ump namespace. - FIREBASE_DEPRECATED - Future ShowPrivacyOptionsFormLastResult(); - - /// Indicates whether the app has completed the necessary steps for gathering - /// updated user consent. Returns true if RequestConsentInfoUpdate() has been - /// called and GetConsentStatus returns either kConsentStatusNotRequired or - /// kConsentStatusObtained. - /// - /// @deprecated This class has been moved to the firebase::ump namespace. - FIREBASE_DEPRECATED - bool CanRequestAds(); - - /// Clears all consent state from persistent storage. This can be used in - /// development to simulate a new installation. - /// - /// @deprecated This class has been moved to the firebase::ump namespace. - FIREBASE_DEPRECATED - void Reset(); - - private: - ConsentInfo(); -#if FIREBASE_PLATFORM_ANDROID - InitResult Initialize(JNIEnv* jni_env, jobject activity); -#else - InitResult Initialize(); -#endif // FIREBASE_PLATFORM_ANDROID - void Terminate(); - - static ConsentInfo* s_instance_; - -#if FIREBASE_PLATFORM_ANDROID - JavaVM* java_vm() { return java_vm_; } - JavaVM* java_vm_; -#endif - - // An internal, platform-specific implementation object that this class uses - // to interact with the User Messaging Platform SDKs for iOS and Android. - internal::ConsentInfoInternal* internal_; -}; - -} // namespace ump -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_UMP_CONSENT_INFO_H_ diff --git a/gma/src/include/firebase/gma/ump/types.h b/gma/src/include/firebase/gma/ump/types.h deleted file mode 100644 index cce119f56b..0000000000 --- a/gma/src/include/firebase/gma/ump/types.h +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_UMP_TYPES_H_ -#define FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_UMP_TYPES_H_ - -#include -#include -#include - -#include "firebase/internal/common.h" -#include "firebase/internal/platform.h" - -#if FIREBASE_PLATFORM_ANDROID -#include -#elif FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS -extern "C" { -#include -} // extern "C" -#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS, - // FIREBASE_PLATFORM_TVOS - -namespace firebase { -namespace gma { -namespace ump { - -/// Debug values for testing geography. -/// -/// @deprecated This enum has been moved to the firebase::ump namespace. -enum ConsentDebugGeography { - /// Disable geography debugging. - kConsentDebugGeographyDisabled = 0, - /// Geography appears as in EEA (European Economic Area) for debug devices. - kConsentDebugGeographyEEA, - /// Geography appears as not in EEA for debug devices. - kConsentDebugGeographyNonEEA -}; - -/// Debug settings for `ConsentInfo::RequestConsentInfoUpdate()`. These let you -/// force a specific geographic location. Be sure to include debug device IDs to -/// enable this on hardware. Debug features are always enabled for simulators. -/// -/// @deprecated This struct has been moved to the firebase::ump namespace. -struct ConsentDebugSettings { - /// Create a default debug setting, with debugging disabled. - ConsentDebugSettings() : debug_geography(kConsentDebugGeographyDisabled) {} - - /// The geographical location, for debugging. - ConsentDebugGeography debug_geography; - /// A list of all device IDs that are allowed to use debug settings. You can - /// obtain this from the device log after running with debug settings enabled. - std::vector debug_device_ids; -}; - -/// Parameters for the `ConsentInfo::RequestConsentInfoUpdate()` operation. -/// -/// @deprecated This struct has been moved to the firebase::ump namespace. -struct ConsentRequestParameters { - ConsentRequestParameters() : tag_for_under_age_of_consent(false) {} - - /// Debug settings for the consent request. - ConsentDebugSettings debug_settings; - - /// Whether the user is under the age of consent. - bool tag_for_under_age_of_consent; -}; - -/// This is a platform specific datatype that is required to show a consent form -/// on screen. -/// -/// The following defines the datatype on each platform: -///
    -///
  • Android: A `jobject` which references an Android Activity.
  • -///
  • iOS: An `id` which references an iOS UIViewController.
  • -///
-#if FIREBASE_PLATFORM_ANDROID -/// An Android Activity from Java. -typedef jobject FormParent; -#elif FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS -/// A pointer to an iOS UIViewController. -typedef id FormParent; -#else -/// A void pointer for stub classes. -typedef void* FormParent; -#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS, - // FIREBASE_PLATFORM_TVOS - -/// Consent status values. -/// -/// @deprecated This enum has been moved to the firebase::ump namespace. -enum ConsentStatus { - /// Unknown status, e.g. prior to calling Request, or if the request fails. - kConsentStatusUnknown = 0, - /// Consent is required, but not obtained - kConsentStatusRequired, - /// Consent is not required - kConsentStatusNotRequired, - /// Consent was required, and has been obtained - kConsentStatusObtained -}; - -/// Errors that can occur during a RequestConsentInfoUpdate operation. -/// -/// @deprecated This enum has been moved to the firebase::ump namespace. -enum ConsentRequestError { - /// The operation succeeded. - kConsentRequestSuccess = 0, - /// Invalid GMA App ID specified in AndroidManifest.xml or Info.plist. - kConsentRequestErrorInvalidAppId, - /// A network error occurred. - kConsentRequestErrorNetwork, - /// An internal error occurred. - kConsentRequestErrorInternal, - /// A misconfiguration exists in the UI. - kConsentRequestErrorMisconfiguration, - /// An unknown error occurred. - kConsentRequestErrorUnknown, - /// An invalid operation occurred. Try again. - kConsentRequestErrorInvalidOperation, - /// The operation is already in progress. Use - /// `ConsentInfo::RequestConsentInfoUpdateLastResult()` - /// to get the status. - kConsentRequestErrorOperationInProgress -}; - -/// Status of the consent form, whether it is available to show or not. -/// -/// @deprecated This enum has been moved to the firebase::ump namespace. -enum ConsentFormStatus { - /// Status is unknown. Call `ConsentInfo::RequestConsentInfoUpdate()` to - /// update this. - kConsentFormStatusUnknown = 0, - /// The consent form is unavailable. Call `ConsentInfo::LoadConsentForm()` to - /// load it. - kConsentFormStatusUnavailable, - /// The consent form is available. Call `ConsentInfo::ShowConsentForm()` to - /// display it. - kConsentFormStatusAvailable, -}; - -/// Errors when loading or showing the consent form. -/// -/// @deprecated This enum has been moved to the firebase::ump namespace. -enum ConsentFormError { - /// The operation succeeded. - kConsentFormSuccess = 0, - /// The load request timed out. Try again. - kConsentFormErrorTimeout, - /// An internal error occurred. - kConsentFormErrorInternal, - /// An unknown error occurred. - kConsentFormErrorUnknown, - /// The form is unavailable. - kConsentFormErrorUnavailable, - /// This form was already used. - kConsentFormErrorAlreadyUsed, - /// An invalid operation occurred. Try again. - kConsentFormErrorInvalidOperation, - /// The operation is already in progress. Call - /// `ConsentInfo::LoadConsentFormLastResult()` or - /// `ConsentInfo::ShowConsentFormLastResult()` to get the status. - kConsentFormErrorOperationInProgress -}; - -/// Whether the privacy options need to be displayed. -/// -/// @deprecated This enum has been moved to the firebase::ump namespace. -enum PrivacyOptionsRequirementStatus { - /// Privacy options requirement status is unknown. Call - /// `ConsentInfo::RequestConsentInfoUpdate()` to update. - kPrivacyOptionsRequirementStatusUnknown = 0, - /// Privacy options are not required to be shown. - kPrivacyOptionsRequirementStatusNotRequired, - /// Privacy options must be shown. Call - /// `ConsentInfo::ShowPrivacyOptionsForm()` to fulfil this requirement. - kPrivacyOptionsRequirementStatusRequired -}; - -} // namespace ump -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_INCLUDE_FIREBASE_GMA_UMP_TYPES_H_ diff --git a/gma/src/ios/.clang-format b/gma/src/ios/.clang-format deleted file mode 100644 index 9d159247d5..0000000000 --- a/gma/src/ios/.clang-format +++ /dev/null @@ -1,2 +0,0 @@ -DisableFormat: true -SortIncludes: false diff --git a/gma/src/ios/FADAdSize.h b/gma/src/ios/FADAdSize.h deleted file mode 100644 index 2b6dc9e013..0000000000 --- a/gma/src/ios/FADAdSize.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import - -// TODO(@dellabitta): remove the extern "C" block once b/228589822 has been -// resolved. -extern "C" { -#import -} - -#include "gma/src/include/firebase/gma/types.h" - -NS_ASSUME_NONNULL_BEGIN - -namespace firebase { -namespace gma { - -/// Returns a GADAdSize from a gma::AdSize. -GADAdSize GADSizeFromCppAdSize(const AdSize& ad_size); - -} // namespace gma -} // namespace firebase - -NS_ASSUME_NONNULL_END diff --git a/gma/src/ios/FADAdSize.mm b/gma/src/ios/FADAdSize.mm deleted file mode 100644 index 8dd5390c6f..0000000000 --- a/gma/src/ios/FADAdSize.mm +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import "gma/src/ios/FADAdSize.h" - -#include "gma/src/common/gma_common.h" - -namespace firebase { -namespace gma { - -GADAdSize GADSizeFromCppAdSize(const AdSize& ad_size) { - switch (ad_size.type()) { - case AdSize::kTypeAnchoredAdaptive: - switch (ad_size.orientation()) { - case AdSize::kOrientationLandscape: - return GADLandscapeAnchoredAdaptiveBannerAdSizeWithWidth(ad_size.width()); - case AdSize::kOrientationPortrait: - return GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth(ad_size.width()); - case AdSize::kOrientationCurrent: - return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(ad_size.width()); - default: - FIREBASE_ASSERT_MESSAGE(true, "Unknown AdSize Orientation"); - } - break; - case AdSize::kTypeInlineAdaptive: - if (ad_size.height() != 0) { - return GADInlineAdaptiveBannerAdSizeWithWidthAndMaxHeight(ad_size.width(), - ad_size.height()); - } - switch (ad_size.orientation()) { - case AdSize::kOrientationLandscape: - return GADLandscapeInlineAdaptiveBannerAdSizeWithWidth(ad_size.width()); - case AdSize::kOrientationPortrait: - return GADPortraitInlineAdaptiveBannerAdSizeWithWidth(ad_size.width()); - case AdSize::kOrientationCurrent: - return GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(ad_size.width()); - default: - FIREBASE_ASSERT_MESSAGE(true, "Unknown AdSize Orientation"); - } - break; - case AdSize::kTypeStandard: - return GADAdSizeFromCGSize(CGSizeMake(ad_size.width(), ad_size.height())); - break; - default: - FIREBASE_ASSERT_MESSAGE(true, "Unknown AdSize Type"); - } -} - -} // namespace gma -} // namespace firebase diff --git a/gma/src/ios/FADAdView.h b/gma/src/ios/FADAdView.h deleted file mode 100644 index 85771db357..0000000000 --- a/gma/src/ios/FADAdView.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import -#import - -#include "gma/src/ios/ad_view_internal_ios.h" - -NS_ASSUME_NONNULL_BEGIN - -@interface FADAdView : UIView - -/// The banner view's BoundingBox. -@property(nonatomic, readonly) firebase::gma::BoundingBox boundingBox; - -/// Unavailable (NSObject). -- (instancetype)init NS_UNAVAILABLE; - -/// Unavailable (UIView). -- (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE; - -/// Unavailable (UIView). -- (instancetype)initWithCoder:(NSCoder *)coder NS_UNAVAILABLE; - -/// Designated Initializer. Returns a FADAdView object with the publisher-provided UIView (the -/// parent view of FADAdView), ad unit ID, ad size, and AdViewInternalIOS object. -- (instancetype)initWithView:(UIView *)view - adUnitID:(NSString *)adUnitID - adSize:(firebase::gma::AdSize)adSize - internalAdView:(firebase::gma::internal::AdViewInternalIOS *)cppAdView // NOLINT - NS_DESIGNATED_INITIALIZER; - -/// Requests a banner ad. -- (void)loadRequest:(GADRequest *)request; - -/// Hides the banner view. -- (void)hide; - -/// Shows the banner view. -- (void)show; - -/// Destroys the banner view. -- (void)destroy; - -/// Moves the banner view to an X coordinate and a Y coordinate. -- (void)moveAdViewToXCoordinate:(int)x yCoordinate:(int)y; - -/// Moves the banner view to a AdView::Position. -- (void)moveAdViewToPosition:(firebase::gma::AdView::Position)position; // NOLINT - -@end - -NS_ASSUME_NONNULL_END diff --git a/gma/src/ios/FADAdView.mm b/gma/src/ios/FADAdView.mm deleted file mode 100644 index 445735b022..0000000000 --- a/gma/src/ios/FADAdView.mm +++ /dev/null @@ -1,306 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/ios/FADAdView.h" - -#import "gma/src/ios/FADAdSize.h" -#import "gma/src/ios/gma_ios.h" - -namespace gma = firebase::gma; - -@interface FADAdView () { - /// The publisher-provided view that is the parent view of the banner view. - UIView *__weak _parentView; - - /// The banner view. - GADBannerView *_adView; - - /// The current horizontal layout constraint for the banner view. - NSLayoutConstraint *_adViewHorizontalLayoutConstraint; - - /// The current vertical layout constraint for the banner view. - NSLayoutConstraint *_adViewVerticalLayoutConstraint; - - /// The banner view's ad unit ID. - NSString *_adUnitID; - - /// The banner view's ad size. - GADAdSize _adSize; - - /// The AdViewInternalIOS object. - gma::internal::AdViewInternalIOS *_cppAdView; - - /// Indicates if the ad loaded. - BOOL _adLoaded; -} - -@end - -@implementation FADAdView - -firebase::gma::AdView::Position _position; - -#pragma mark - Initialization - -- (instancetype)initWithView:(UIView *)view - adUnitID:(NSString *)adUnitID - adSize:(firebase::gma::AdSize)adSize - internalAdView:(firebase::gma::internal::AdViewInternalIOS *)cppAdView { - GADAdSize gadsize = GADSizeFromCppAdSize(adSize); - CGRect frame = CGRectMake(0, 0, gadsize.size.width, gadsize.size.height); - self = [super initWithFrame:frame]; - if (self) { - _parentView = view; - _adUnitID = [adUnitID copy]; - _adSize = gadsize; - _cppAdView = cppAdView; - [self setUpAdView]; - } - return self; -} - -/// Called from the designated initializer. Sets up a banner view. -- (void)setUpAdView { - _adView = [[GADBannerView alloc] initWithAdSize:_adSize]; - _adView.adUnitID = _adUnitID; - _adView.delegate = self; - __unsafe_unretained typeof(self) weakSelf = self; - _adView.paidEventHandler = ^void(GADAdValue *_Nonnull adValue) { - // Establish the strong self reference - __strong typeof(self) strongSelf = weakSelf; - if (strongSelf) { - strongSelf->_cppAdView->NotifyListenerOfPaidEvent( - firebase::gma::ConvertGADAdValueToCppAdValue(adValue)); - } - }; - - // The FADAdView is hidden until the publisher calls Show(). - self.hidden = YES; - - [self addSubview:_adView]; - _adView.translatesAutoresizingMaskIntoConstraints = NO; - - // Add layout constraints to center the banner view vertically and horizontally. - NSDictionary *viewDictionary = NSDictionaryOfVariableBindings(_adView); - NSArray *verticalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_adView]|" - options:0 - metrics:nil - views:viewDictionary]; - [self addConstraints:verticalConstraints]; - NSArray *horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_adView]|" - options:0 - metrics:nil - views:viewDictionary]; - [self addConstraints:horizontalConstraints]; - - UIView *strongView = _parentView; - _adView.rootViewController = strongView.window.rootViewController; - [strongView addSubview:self]; - self.translatesAutoresizingMaskIntoConstraints = NO; - [self updateAdViewLayoutConstraintsWithPosition:(gma::AdView::kPositionTopLeft) - xCoordinate:0 - yCoordinate:0]; -} - -#pragma mark - Property Accessor Methods - -- (gma::BoundingBox)boundingBox { - gma::BoundingBox box; - if (!_adView) { - return box; - } - // Map the width and height and the x and y coordinates of the BoundingBox to pixel values using - // the scale factor associated with the device's screen. - CGFloat scale = [UIScreen mainScreen].scale; - CGRect standardizedRect = CGRectStandardize(self.frame); - box.width = standardizedRect.size.width * scale; - box.height = standardizedRect.size.height * scale; - box.x = standardizedRect.origin.x * scale; - box.y = standardizedRect.origin.y * scale; - box.position = _position; - return box; -} - -#pragma mark - Public Methods - -- (void)loadRequest:(GADRequest *)request { - // Make the ad request. - [_adView loadRequest:request]; -} - -- (void)hide { - self.hidden = YES; -} - -- (void)show { - self.hidden = NO; - gma::BoundingBox bounding_box = self.boundingBox; - _cppAdView->set_bounding_box(bounding_box); - _cppAdView->NotifyListenerOfBoundingBoxChange(bounding_box); -} - -- (void)destroy { - [_adView removeFromSuperview]; - _adView.delegate = nil; - _adView = nil; -} - -- (void)moveAdViewToXCoordinate:(int)x yCoordinate:(int)y { - // The moveAdViewToXCoordinate:yCoordinate: method gets the x-coordinate and y-coordinate in - // pixels. Need to convert the pixels to points before updating the view's layout - // constraints. - _position = firebase::gma::AdView::kPositionUndefined; - CGFloat scale = [UIScreen mainScreen].scale; - CGFloat xPoints = x / scale; - CGFloat yPoints = y / scale; - [self updateAdViewLayoutConstraintsWithPosition:(_position) - xCoordinate:xPoints - yCoordinate:yPoints]; -} - -- (void)moveAdViewToPosition:(gma::AdView::Position)position { - [self updateAdViewLayoutConstraintsWithPosition:position xCoordinate:0 yCoordinate:0]; -} - -#pragma mark - Private Methods - -/// Updates the layout constraints for the view. -- (void)updateAdViewLayoutConstraintsWithPosition:(gma::AdView::Position)position - xCoordinate:(CGFloat)x - yCoordinate:(CGFloat)y { - NSLayoutAttribute verticalLayoutAttribute = NSLayoutAttributeNotAnAttribute; - NSLayoutAttribute horizontalLayoutAttribute = NSLayoutAttributeNotAnAttribute; - - _position = position; - switch (position) { - case gma::AdView::kPositionTop: - verticalLayoutAttribute = NSLayoutAttributeTop; - horizontalLayoutAttribute = NSLayoutAttributeCenterX; - break; - case gma::AdView::kPositionBottom: - verticalLayoutAttribute = NSLayoutAttributeBottom; - horizontalLayoutAttribute = NSLayoutAttributeCenterX; - break; - case gma::AdView::kPositionUndefined: - case gma::AdView::kPositionTopLeft: - verticalLayoutAttribute = NSLayoutAttributeTop; - horizontalLayoutAttribute = NSLayoutAttributeLeft; - break; - case gma::AdView::kPositionTopRight: - verticalLayoutAttribute = NSLayoutAttributeTop; - horizontalLayoutAttribute = NSLayoutAttributeRight; - break; - case gma::AdView::kPositionBottomLeft: - verticalLayoutAttribute = NSLayoutAttributeBottom; - horizontalLayoutAttribute = NSLayoutAttributeLeft; - break; - case gma::AdView::kPositionBottomRight: - verticalLayoutAttribute = NSLayoutAttributeBottom; - horizontalLayoutAttribute = NSLayoutAttributeRight; - break; - default: - break; - } - - // Remove the existing vertical and horizontal layout constraints for the banner view, if they - // exist. - UIView *strongView = _parentView; - if (_adViewVerticalLayoutConstraint && _adViewHorizontalLayoutConstraint) { - NSArray *AdViewLayoutConstraints = - @[ _adViewVerticalLayoutConstraint, _adViewHorizontalLayoutConstraint ]; - [strongView removeConstraints:AdViewLayoutConstraints]; - } - - // Set the vertical and horizontal layout constraints for the banner view. - _adViewVerticalLayoutConstraint = [NSLayoutConstraint constraintWithItem:self - attribute:verticalLayoutAttribute - relatedBy:NSLayoutRelationEqual - toItem:strongView - attribute:verticalLayoutAttribute - multiplier:1 - constant:y]; - [strongView addConstraint:_adViewVerticalLayoutConstraint]; - _adViewHorizontalLayoutConstraint = - [NSLayoutConstraint constraintWithItem:self - attribute:horizontalLayoutAttribute - relatedBy:NSLayoutRelationEqual - toItem:strongView - attribute:horizontalLayoutAttribute - multiplier:1 - constant:x]; - [strongView addConstraint:_adViewHorizontalLayoutConstraint]; - [self setNeedsLayout]; -} - -/// This method gets called when the observer is notified that the application -/// is active again (i.e. when the user returns to the application from Safari -/// or the App Store). -- (void)applicationDidBecomeActive:(NSNotification *)notification { - // Remove the observer that was registered in the adViewWillLeaveApplication: callback. - [[NSNotificationCenter defaultCenter] removeObserver:self - name:UIApplicationDidBecomeActiveNotification - object:nil]; -} - -#pragma mark - UIView - -- (void)layoutSubviews { - [super layoutSubviews]; - gma::BoundingBox bounding_box = self.boundingBox; - _cppAdView->set_bounding_box(bounding_box); - _cppAdView->NotifyListenerOfBoundingBoxChange(bounding_box); -} - -#pragma mark - GADBannerViewDelegate - -- (void)bannerViewDidReceiveAd:(nonnull GADBannerView *)bannerView { - NSInteger width = (NSInteger)(floor(bannerView.intrinsicContentSize.width)); - NSInteger height = (NSInteger)(floor(bannerView.intrinsicContentSize.height)); - _adLoaded = YES; - _cppAdView->AdViewDidReceiveAd(width, height, bannerView.responseInfo); -} - -- (void)bannerView:(nonnull GADBannerView *)bannerView - didFailToReceiveAdWithError:(nonnull NSError *)error { - _cppAdView->AdViewDidFailToReceiveAdWithError(error); -} - -- (void)bannerViewDidRecordClick:(nonnull GADBannerView *)bannerView { - _cppAdView->NotifyListenerAdClicked(); -} - -- (void)bannerViewDidRecordImpression:(nonnull GADBannerView *)bannerView { - _cppAdView->NotifyListenerAdImpression(); -} - -// Note that the following callbacks are only called on in-app overlay events. -// See https://www.googblogs.com/google-mobile-ads-sdk-a-note-on-ad-click-events/ -// and https://groups.google.com/g/google-admob-ads-sdk/c/lzdt5szxSVU -- (void)bannerViewWillPresentScreen:(nonnull GADBannerView *)bannerView { - gma::BoundingBox bounding_box = self.boundingBox; - _cppAdView->set_bounding_box(bounding_box); - _cppAdView->NotifyListenerOfBoundingBoxChange(bounding_box); - _cppAdView->NotifyListenerAdOpened(); -} - -- (void)bannerViewDidDismissScreen:(nonnull GADBannerView *)bannerView { - gma::BoundingBox bounding_box = self.boundingBox; - _cppAdView->set_bounding_box(bounding_box); - _cppAdView->NotifyListenerOfBoundingBoxChange(bounding_box); - _cppAdView->NotifyListenerAdClosed(); -} - -@end diff --git a/gma/src/ios/FADInterstitialDelegate.h b/gma/src/ios/FADInterstitialDelegate.h deleted file mode 100644 index 2db153187e..0000000000 --- a/gma/src/ios/FADInterstitialDelegate.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// An Objective-C++ wrapper class that conforms to the GADInterstitialDelegate protocol. When the -// delegate for receiving state change messages from a GADInterstitial is notified, this wrapper -// class forwards the notification to the InterstitialAdInternalIOS object to handle the state -// changes for an interstitial ad. - -#import -#import - -namespace firebase { -namespace gma { -namespace internal { -class InterstitialAdInternalIOS; -} // namespace internal -} // namespace gma -} // namespace firebase - -NS_ASSUME_NONNULL_BEGIN - -@interface FADInterstitialDelegate : NSObject - -/// Returns a FADInterstitialDelegate object with InterstitialAdInternalIOS. -- (FADInterstitialDelegate *)initWithInternalInterstitialAd: - (firebase::gma::internal::InterstitialAdInternalIOS *)interstitialAd; - -@end - -NS_ASSUME_NONNULL_END diff --git a/gma/src/ios/FADInterstitialDelegate.mm b/gma/src/ios/FADInterstitialDelegate.mm deleted file mode 100644 index 8e0a34b5f7..0000000000 --- a/gma/src/ios/FADInterstitialDelegate.mm +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import "gma/src/ios/FADInterstitialDelegate.h" - -#include "gma/src/ios/ad_error_ios.h" -#include "gma/src/ios/interstitial_ad_internal_ios.h" - -@interface FADInterstitialDelegate () { - /// The InterstitialAdInternalIOS object. - firebase::gma::internal::InterstitialAdInternalIOS *_interstitialAd; -} -@end - -@implementation FADInterstitialDelegate : NSObject - -#pragma mark - Initialization - -- (instancetype)initWithInternalInterstitialAd: - (firebase::gma::internal::InterstitialAdInternalIOS *)interstitialAd { - self = [super init]; - if (self) { - _interstitialAd = interstitialAd; - } - - return self; -} - -#pragma mark - GADFullScreenContentDelegate - -// Capture GMA iOS Full screen events and forward them to our C++ -// translation layer. -- (void)adDidRecordImpression:(nonnull id)ad { - _interstitialAd->NotifyListenerOfAdImpression(); -} - -- (void)adDidRecordClick:(nonnull id)ad { - _interstitialAd->NotifyListenerOfAdClickedFullScreenContent(); -} - -- (void)ad:(nonnull id)ad - didFailToPresentFullScreenContentWithError:(nonnull NSError *)error { - firebase::gma::AdErrorInternal ad_error_internal; - ad_error_internal.ad_error_type = - firebase::gma::AdErrorInternal::kAdErrorInternalFullScreenContentError; - ad_error_internal.is_successful = false; - ad_error_internal.native_ad_error = error; - // Invoke GmaInternal, a friend of AdResult, to have it access its - // protected constructor with the AdError data. - const firebase::gma::AdError &ad_error = - firebase::gma::GmaInternal::CreateAdError(ad_error_internal); - _interstitialAd->NotifyListenerOfAdFailedToShowFullScreenContent(ad_error); -} - -- (void)adWillPresentFullScreenContent:(nonnull id)ad { - _interstitialAd->NotifyListenerOfAdShowedFullScreenContent(); -} - -- (void)adDidDismissFullScreenContent:(nonnull id)ad { - _interstitialAd->NotifyListenerOfAdDismissedFullScreenContent(); -} - -@end diff --git a/gma/src/ios/FADNativeDelegate.h b/gma/src/ios/FADNativeDelegate.h deleted file mode 100644 index e68e533c56..0000000000 --- a/gma/src/ios/FADNativeDelegate.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// An Objective-C++ wrapper class that conforms to the GADNativeAdLoaderDelegate protocol. When the -// delegate for receiving state change messages from a GADNativeAd is notified, this wrapper -// class forwards the notification to the NativeAdInternalIOS object to handle the state -// changes for an native ad. - -#import -#import - -namespace firebase { -namespace gma { -namespace internal { -class NativeAdInternalIOS; -} // namespace internal -} // namespace gma -} // namespace firebase - -NS_ASSUME_NONNULL_BEGIN - -@interface FADNativeDelegate : NSObject - -/// Returns a FADNativeDelegate object with NativeAdInternalIOS. -- (FADNativeDelegate *)initWithInternalNativeAd: - (firebase::gma::internal::NativeAdInternalIOS *)nativeAd; - -@end - -NS_ASSUME_NONNULL_END diff --git a/gma/src/ios/FADNativeDelegate.mm b/gma/src/ios/FADNativeDelegate.mm deleted file mode 100644 index b8984f81c3..0000000000 --- a/gma/src/ios/FADNativeDelegate.mm +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import "gma/src/ios/FADNativeDelegate.h" - -#include "gma/src/ios/ad_error_ios.h" -#include "gma/src/ios/native_ad_internal_ios.h" - -@interface FADNativeDelegate () { - /// The NativeAdInternalIOS object. - firebase::gma::internal::NativeAdInternalIOS *_nativeAd; -} -@end - -@implementation FADNativeDelegate : NSObject - -#pragma mark - Initialization - -- (instancetype)initWithInternalNativeAd:(firebase::gma::internal::NativeAdInternalIOS *)nativeAd { - self = [super init]; - if (self) { - _nativeAd = nativeAd; - } - - return self; -} - -#pragma mark GADAdLoaderDelegate implementation - -- (void)adLoader:(GADAdLoader *)adLoader didFailToReceiveAdWithError:(NSError *)error { - _nativeAd->NativeAdDidFailToReceiveAdWithError(error); -} - -#pragma mark GADNativeAdLoaderDelegate implementation - -- (void)adLoader:(GADAdLoader *)adLoader didReceiveNativeAd:(GADNativeAd *)nativeAd { - _nativeAd->NativeAdDidReceiveAd(nativeAd); -} - -#pragma mark GADNativeAdDelegate implementation - -- (void)nativeAdDidRecordClick:(nonnull GADNativeAd *)nativeAd { - _nativeAd->NotifyListenerAdClicked(); -} - -- (void)nativeAdDidRecordImpression:(nonnull GADNativeAd *)nativeAd { - _nativeAd->NotifyListenerAdImpression(); -} - -- (void)nativeAdWillPresentScreen:(nonnull GADNativeAd *)nativeAd { - _nativeAd->NotifyListenerAdOpened(); -} - -- (void)nativeAdDidDismissScreen:(nonnull GADNativeAd *)nativeAd { - _nativeAd->NotifyListenerAdClosed(); -} - -@end diff --git a/gma/src/ios/FADRequest.h b/gma/src/ios/FADRequest.h deleted file mode 100644 index 4a2e7c4b7f..0000000000 --- a/gma/src/ios/FADRequest.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import -#import - -#include - -#include "gma/src/include/firebase/gma/types.h" - -NS_ASSUME_NONNULL_BEGIN - -namespace firebase { -namespace gma { - -/// Returns a GADRequest from a gma::AdRequest. -/// Converts instances of the AdRequest struct used by the C++ wrapper to -/// to Mobile Ads SDK GADRequest objects. -/// -/// @param[in] request The AdRequest struct to be converted into a -/// GAdRequest. -/// @param[out] error kAdErrorCodeNone on success, or another error if -/// problems occurred. -/// @param[out] error_message a string representation of any error that -/// occurs. -/// @return On success, a pointer to a GADRequest object representing the -/// AdRequest, or nullptr on error. -GADRequest* GADRequestFromCppAdRequest(const AdRequest& adRequest, - gma::AdErrorCode* error, - std::string* error_message); - -// Converts the iOS error codes from an AdRequest to the CPP platform -// independent error codes defined in AdErrorCode. -AdErrorCode MapAdRequestErrorCodeToCPPErrorCode(GADErrorCode error_code); - -// Converts the iOS error codes from attempting to show a full screen -// ad into the platform independent error codes defined in AdError. -AdErrorCode MapFullScreenContentErrorCodeToCPPErrorCode( - GADPresentationErrorCode error_code); - -// Converts the platform independent ad format defined in AdFormat to the iOS -// ad format. -GADAdFormat MapCPPAdFormatToGADAdformat(AdFormat format); - -} // namespace gma -} // namespace firebase - -NS_ASSUME_NONNULL_END diff --git a/gma/src/ios/FADRequest.mm b/gma/src/ios/FADRequest.mm deleted file mode 100644 index c2393ef710..0000000000 --- a/gma/src/ios/FADRequest.mm +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import "gma/src/ios/FADRequest.h" - -#include "app/src/util_ios.h" -#include "gma/src/common/gma_common.h" - -#include "app/src/log.h" - -namespace firebase { -namespace gma { - -GADRequest* GADRequestFromCppAdRequest(const AdRequest& adRequest, gma::AdErrorCode* error, - std::string* error_message) { - FIREBASE_ASSERT(error); - FIREBASE_ASSERT(error_message); - *error = kAdErrorCodeNone; - - // Create the GADRequest. - GADRequest* gadRequest = [GADRequest request]; - - // Keywords. - const std::unordered_set& keywords = adRequest.keywords(); - if (keywords.size() > 0) { - NSMutableArray* gadKeywords = [[NSMutableArray alloc] init]; - for (auto keyword = keywords.begin(); keyword != keywords.end(); ++keyword) { - [gadKeywords addObject:util::StringToNSString(*keyword)]; - } - gadRequest.keywords = gadKeywords; - } - - // Extras. - const std::map>& extras = adRequest.extras(); - for (auto adapter_iter = extras.begin(); adapter_iter != extras.end(); ++adapter_iter) { - const std::string adapterClassName = adapter_iter->first; - // Attempt to resolve the custom class. - Class extrasClass = NSClassFromString(util::StringToNSString(adapterClassName)); - if (extrasClass == nil) { - *error_message = "Failed to resolve extras class: "; - error_message->append(adapterClassName); - LogError(error_message->c_str()); - *error = kAdErrorCodeAdNetworkClassLoadError; - return nullptr; - } - - // Attempt allocate a object of the class, and check to see if it's - // of an expected type. - id gadExtrasId = [[extrasClass alloc] init]; - if (![gadExtrasId isKindOfClass:[GADExtras class]]) { - *error_message = "Failed to load extras class inherited from GADExtras: "; - error_message->append(adapterClassName); - LogError(error_message->c_str()); - *error = kAdErrorCodeAdNetworkClassLoadError; - return nullptr; - } - - // Add the key/value dictionary to the object. - // adpter_iter->second is a std::map of the key/value pairs. - if (!adapter_iter->second.empty()) { - NSMutableDictionary* additionalParameters = [[NSMutableDictionary alloc] init]; - for (auto extra_iter = adapter_iter->second.begin(); extra_iter != adapter_iter->second.end(); - ++extra_iter) { - NSString* key = util::StringToNSString(extra_iter->first); - NSString* value = util::StringToNSString(extra_iter->second); - additionalParameters[key] = value; - } - - GADExtras* gadExtras = (GADExtras*)gadExtrasId; - gadExtras.additionalParameters = additionalParameters; - [gadRequest registerAdNetworkExtras:gadExtras]; - } - } - - // Content URL - if (!adRequest.content_url().empty()) { - gadRequest.contentURL = util::StringToNSString(adRequest.content_url()); - } - - // Neighboring Content URLs - if (!adRequest.neighboring_content_urls().empty()) { - gadRequest.neighboringContentURLStrings = - util::StringUnorderedSetToNSMutableArray(adRequest.neighboring_content_urls()); - } - - // Set the request agent string so requests originating from this library can - // be tracked and reported on as a group. - gadRequest.requestAgent = @(GetRequestAgentString()); - - return gadRequest; -} - -AdErrorCode MapAdRequestErrorCodeToCPPErrorCode(GADErrorCode error_code) { - // iOS error code sourced from - // https://developers.google.com/admob/ios/api/reference/Enums/GADErrorCode - switch (error_code) { - case GADErrorInvalidRequest: // 0 - return kAdErrorCodeInvalidRequest; - case GADErrorNoFill: // 1 - return kAdErrorCodeNoFill; - case GADErrorNetworkError: // 2 - return kAdErrorCodeNetworkError; - case GADErrorServerError: // 3 - return kAdErrorCodeServerError; - case GADErrorOSVersionTooLow: // 4 - return kAdErrorCodeOSVersionTooLow; - case GADErrorTimeout: // 5 - return kAdErrorCodeTimeout; - // no error 6. - case GADErrorMediationDataError: // 7 - return kAdErrorCodeMediationDataError; - case GADErrorMediationAdapterError: // 8 - return kAdErrorCodeMediationAdapterError; - case GADErrorMediationNoFill: // 9 - return kAdErrorCodeMediationNoFill; - case GADErrorMediationInvalidAdSize: // 10 - return kAdErrorCodeMediationInvalidAdSize; - case GADErrorInternalError: // 11 - return kAdErrorCodeInternalError; - case GADErrorInvalidArgument: // 12 - return kAdErrorCodeInvalidArgument; - case GADErrorReceivedInvalidResponse: // 13 - return kAdErrorCodeReceivedInvalidResponse; - case GADErrorAdAlreadyUsed: // 19 (no error #s 14-18) - return kAdErrorCodeAdAlreadyUsed; - case GADErrorApplicationIdentifierMissing: // 20 - return kAdErrorCodeApplicationIdentifierMissing; - default: - return kAdErrorCodeUnknown; - } -} - -AdErrorCode MapFullScreenContentErrorCodeToCPPErrorCode(GADPresentationErrorCode error_code) { - // iOS error code sourced from - // https://developers.google.com/admob/ios/api/reference/Enums/GADPresentationErrorCode - switch (error_code) { - case GADPresentationErrorCodeAdNotReady: // 15 - return kAdErrorCodeAdNotReady; - case GADPresentationErrorCodeAdTooLarge: // 16 - return kAdErrorCodeAdTooLarge; - case GADPresentationErrorCodeInternal: // 17 - return kAdErrorCodeInternalError; - case GADPresentationErrorCodeAdAlreadyUsed: // 18 - return kAdErrorCodeAdAlreadyUsed; - case GADPresentationErrorNotMainThread: // 21 - return kAdErrorCodeNotMainThread; - case GADPresentationErrorMediation: // 22 - return kAdErrorCodeMediationShowError; - default: - return kAdErrorCodeUnknown; - } -} - -GADAdFormat MapCPPAdFormatToGADAdformat(AdFormat format) { - switch (format) { - case kAdFormatBanner: - return GADAdFormatBanner; - case kAdFormatInterstitial: - return GADAdFormatInterstitial; - case kAdFormatRewarded: - return GADAdFormatRewarded; - case kAdFormatRewardedInterstitial: - return GADAdFormatRewardedInterstitial; - case kAdFormatNative: - return GADAdFormatNative; - case kAdFormatAppOpen: - return GADAdFormatAppOpen; - default: - return GADAdFormatBanner; - } -} - -} // namespace gma -} // namespace firebase diff --git a/gma/src/ios/FADRewardedAdDelegate.h b/gma/src/ios/FADRewardedAdDelegate.h deleted file mode 100644 index 1534b8f588..0000000000 --- a/gma/src/ios/FADRewardedAdDelegate.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// An Objective-C++ wrapper class that conforms to the -// GADRewardedAdDelegate protocol. When the delegate for receiving state -// change messages from a GADRewardedAd is notified, this wrapper class -// forwards the notification to the RewardedAdInternalIOS object to handle -// the state changes for an rewarded ad. - -#import -#import - -namespace firebase { -namespace gma { -namespace internal { -class RewardedAdInternalIOS; -} // namespace internal -} // namespace gma -} // namespace firebase - -NS_ASSUME_NONNULL_BEGIN - -@interface FADRewardedAdDelegate : NSObject - -/// Returns a FADInterstitialDelegate object with InterstitialAdInternalIOS. -- (FADRewardedAdDelegate *)initWithInternalRewardedAd: - (firebase::gma::internal::RewardedAdInternalIOS *)rewardedAd; - -@end - -NS_ASSUME_NONNULL_END diff --git a/gma/src/ios/FADRewardedAdDelegate.mm b/gma/src/ios/FADRewardedAdDelegate.mm deleted file mode 100644 index e657e9123d..0000000000 --- a/gma/src/ios/FADRewardedAdDelegate.mm +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import "gma/src/ios/FADRewardedAdDelegate.h" - -#include "gma/src/ios/ad_error_ios.h" -#include "gma/src/ios/rewarded_ad_internal_ios.h" - -@interface FADRewardedAdDelegate () { - /// The RewardedAdInternalIOS object. - firebase::gma::internal::RewardedAdInternalIOS *_rewardedAd; -} -@end - -@implementation FADRewardedAdDelegate : NSObject - -#pragma mark - Initialization - -- (instancetype)initWithInternalRewardedAd: - (firebase::gma::internal::RewardedAdInternalIOS *)rewardedAd { - self = [super init]; - if (self) { - _rewardedAd = rewardedAd; - } - - return self; -} - -#pragma mark - GADFullScreenContentDelegate - -// Capture GMA iOS Full screen events and forward them to our C++ -// translation layer. -- (void)adDidRecordImpression:(nonnull id)ad { - _rewardedAd->NotifyListenerOfAdImpression(); -} - -- (void)adDidRecordClick:(nonnull id)ad { - _rewardedAd->NotifyListenerOfAdClickedFullScreenContent(); -} - -- (void)ad:(nonnull id)ad - didFailToPresentFullScreenContentWithError:(nonnull NSError *)error { - firebase::gma::AdErrorInternal ad_error_internal; - ad_error_internal.ad_error_type = - firebase::gma::AdErrorInternal::kAdErrorInternalFullScreenContentError; - ad_error_internal.is_successful = false; - ad_error_internal.native_ad_error = error; - // Invoke GmaInternal, a friend of AdResult, to have it access its - // protected constructor with the AdError data. - const firebase::gma::AdError &ad_error = - firebase::gma::GmaInternal::CreateAdError(ad_error_internal); - _rewardedAd->NotifyListenerOfAdFailedToShowFullScreenContent(ad_error); -} - -- (void)adWillPresentFullScreenContent:(nonnull id)ad { - _rewardedAd->NotifyListenerOfAdShowedFullScreenContent(); -} - -- (void)adDidDismissFullScreenContent:(nonnull id)ad { - _rewardedAd->NotifyListenerOfAdDismissedFullScreenContent(); -} - -@end diff --git a/gma/src/ios/GADNativeAdCpp.h b/gma/src/ios/GADNativeAdCpp.h deleted file mode 100644 index d1b521f4b7..0000000000 --- a/gma/src/ios/GADNativeAdCpp.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import -#import -#import - -@interface GADNativeAd() - -/// AdChoices icon image. -@property(nonatomic, readonly, strong, nullable) GADNativeAdImage *adChoicesIcon; - -/// Used only by allowlisted ad units. Provide a dictionary containing click data. -- (void)performClickWithData:(nonnull NSDictionary *)clickData; - -/// Used only by allowlisted ad units. Provide a dictionary containing impression data. Returns YES -/// if the impression is successfully recorded, otherwise returns NO. -- (BOOL)recordImpressionWithData:(nonnull NSDictionary *)impressionData; - -@end - diff --git a/gma/src/ios/ad_error_ios.h b/gma/src/ios/ad_error_ios.h deleted file mode 100644 index 8839928b27..0000000000 --- a/gma/src/ios/ad_error_ios.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_IOS_AD_ERROR_IOS_H_ -#define FIREBASE_GMA_SRC_IOS_AD_ERROR_IOS_H_ - -extern "C" { -#include -} // extern "C" - -#import -#import - -#include "gma/src/common/ad_error_internal.h" - -#endif // FIREBASE_GMA_SRC_IOS_AD_ERROR_IOS_H_ diff --git a/gma/src/ios/ad_error_ios.mm b/gma/src/ios/ad_error_ios.mm deleted file mode 100644 index f18baa4c51..0000000000 --- a/gma/src/ios/ad_error_ios.mm +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -extern "C" { -#include -} // extern "C" - -#import "gma/src/ios/FADRequest.h" - -#include - -#include "app/src/assert.h" -#include "app/src/util_ios.h" -#include "gma/src/common/ad_error_internal.h" -#include "gma/src/include/firebase/gma.h" -#include "gma/src/ios/ad_error_ios.h" -#include "gma/src/ios/response_info_ios.h" - - -namespace firebase { -namespace gma { - -const char* const AdError::kUndefinedDomain = "undefined"; - -AdError::AdError() { - // Default constructor is available for Future creation. - // Initialize it with some helpful debug values in the case - // an AdError makes it to the application in this default state. - internal_ = new AdErrorInternal(); - internal_->is_successful = false; - internal_->ad_error_type = AdErrorInternal::kAdErrorInternalWrapperError; - internal_->code = kAdErrorCodeUninitialized; - internal_->domain = "SDK"; - internal_->message = "This AdError has not be initialized."; - internal_->to_string = internal_->message; - internal_->native_ad_error = nullptr; - - // While most data is passed into this object through the AdErrorInternal - // structure (above), the response_info_ is constructed when parsing - // the j_ad_error itself. - response_info_ = new ResponseInfo(); -} - -AdError::AdError(const AdErrorInternal& ad_error_internal) { - internal_ = new AdErrorInternal(); - - internal_->is_successful = ad_error_internal.is_successful; - internal_->ad_error_type = ad_error_internal.ad_error_type; - internal_->native_ad_error = nullptr; - response_info_ = new ResponseInfo(); - - // AdErrors can be returned on success, or for errors encountered in the C++ - // SDK wrapper, or in the iOS GMA SDK. The structure is populated - // differently across these three scenarios. - if (internal_->is_successful) { - internal_->code = kAdErrorCodeNone; - internal_->message = ""; - internal_->domain = ""; - internal_->to_string = ""; - } else if (internal_->ad_error_type == AdErrorInternal::kAdErrorInternalWrapperError) { - // Wrapper errors come with prepopulated code, domain, etc, fields. - internal_->code = ad_error_internal.code; - internal_->domain = ad_error_internal.domain; - internal_->message = ad_error_internal.message; - internal_->to_string = ad_error_internal.to_string; - } else { - FIREBASE_ASSERT(ad_error_internal.native_ad_error); - - // AdErrors based on GMA iOS SDK errors will fetch code, domain, - // message, and to_string values from the ObjC object. - internal_->native_ad_error = ad_error_internal.native_ad_error; - - // Error Code. Map the iOS GMA SDK error codes to our - // platform-independent C++ SDK error codes. - switch (internal_->ad_error_type) { - case AdErrorInternal::kAdErrorInternalFullScreenContentError: - // Full screen content errors have their own error codes. - internal_->code = MapFullScreenContentErrorCodeToCPPErrorCode( - (GADPresentationErrorCode)internal_->native_ad_error.code); - break; - case AdErrorInternal::kAdErrorInternalOpenAdInspectorError: - // OpenAdInspector errors are all internal errors on iOS. - internal_->code = kAdErrorCodeInternalError; - break; - default: - internal_->code = - MapAdRequestErrorCodeToCPPErrorCode((GADErrorCode)internal_->native_ad_error.code); - } - - internal_->domain = util::NSStringToString(internal_->native_ad_error.domain); - internal_->message = util::NSStringToString(internal_->native_ad_error.localizedDescription); - - // Errors from LoadAd attempts have extra data pertaining to adapter - // responses. - if (internal_->ad_error_type == AdErrorInternal::kAdErrorInternalLoadAdError) { - ResponseInfoInternal response_info_internal = ResponseInfoInternal( - {ad_error_internal.native_ad_error.userInfo[GADErrorUserInfoKeyResponseInfo]}); - *response_info_ = ResponseInfo(response_info_internal); - } - - NSString* ns_to_string = [[NSString alloc] - initWithFormat:@"Received error with " - "domain: %@, code: %ld, message: %@", - internal_->native_ad_error.domain, (long)internal_->native_ad_error.code, - internal_->native_ad_error.localizedDescription]; - internal_->to_string = util::NSStringToString(ns_to_string); - } -} - -AdError::AdError(const AdError& ad_result) : AdError() { - // Reuse the assignment operator. - this->response_info_ = new ResponseInfo(); - *this = ad_result; -} - -AdError::~AdError() { - FIREBASE_ASSERT(internal_); - FIREBASE_ASSERT(response_info_); - - internal_->native_ad_error = nil; - delete internal_; - internal_ = nullptr; - - delete response_info_; - response_info_ = nullptr; -} - -AdError& AdError::operator=(const AdError& ad_result) { - FIREBASE_ASSERT(ad_result.internal_); - FIREBASE_ASSERT(internal_); - FIREBASE_ASSERT(response_info_); - FIREBASE_ASSERT(ad_result.response_info_); - - AdErrorInternal* preexisting_internal = internal_; - { - MutexLock(ad_result.internal_->mutex); - MutexLock(internal_->mutex); - internal_ = new AdErrorInternal(); - - internal_->native_ad_error = ad_result.internal_->native_ad_error; - - internal_->is_successful = ad_result.internal_->is_successful; - internal_->ad_error_type = ad_result.internal_->ad_error_type; - internal_->code = ad_result.internal_->code; - internal_->domain = ad_result.internal_->domain; - internal_->message = ad_result.internal_->message; - internal_->to_string = ad_result.internal_->to_string; - - *response_info_ = *ad_result.response_info_; - } - - // Deleting the internal deletes the mutex within it, so we have to delete - // the internal after the mutex lock leaves scope. - preexisting_internal->native_ad_error = nullptr; - delete preexisting_internal; - - return *this; -} - -std::unique_ptr AdError::GetCause() const { - FIREBASE_ASSERT(internal_); - - NSError* cause = internal_->native_ad_error.userInfo[NSUnderlyingErrorKey]; - if (cause == nil) { - return std::unique_ptr(nullptr); - } else { - AdErrorInternal ad_error_internal; - ad_error_internal.native_ad_error = cause; - return std::unique_ptr(new AdError(ad_error_internal)); - } -} - -/// Gets the error's code. -AdErrorCode AdError::code() const { - FIREBASE_ASSERT(internal_); - return internal_->code; -} - -/// Gets the domain of the error. -const std::string& AdError::domain() const { - FIREBASE_ASSERT(internal_); - return internal_->domain; -} - -/// Gets the message describing the error. -const std::string& AdError::message() const { - FIREBASE_ASSERT(internal_); - return internal_->message; -} - -const ResponseInfo& AdError::response_info() const { - FIREBASE_ASSERT(response_info_); - return *response_info_; -} - -/// Returns a log friendly string version of this object. -const std::string& AdError::ToString() const { - FIREBASE_ASSERT(internal_); - return internal_->to_string; -} - -} // namespace gma -} // namespace firebase diff --git a/gma/src/ios/ad_response_info_ios.h b/gma/src/ios/ad_response_info_ios.h deleted file mode 100644 index 2eb984554d..0000000000 --- a/gma/src/ios/ad_response_info_ios.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_IOS_AD_RESPONSE_INFO_IOS_H_ -#define FIREBASE_GMA_SRC_IOS_AD_RESPONSE_INFO_IOS_H_ - -extern "C" { -#include -} // extern "C" - -#import - -namespace firebase { -namespace gma { - -struct AdapterResponseInfoInternal { - GADAdNetworkResponseInfo* ad_network_response_info; -}; - -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_IOS_AD_RESPONSE_INFO_IOS_H_ diff --git a/gma/src/ios/ad_view_internal_ios.h b/gma/src/ios/ad_view_internal_ios.h deleted file mode 100644 index 026dc33554..0000000000 --- a/gma/src/ios/ad_view_internal_ios.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_IOS_AD_VIEW_INTERNAL_IOS_H_ -#define FIREBASE_GMA_SRC_IOS_AD_VIEW_INTERNAL_IOS_H_ - -extern "C" { -#include -} // extern "C" - -#ifdef __OBJC__ -#import -#endif // __OBJC__ - -#include "app/src/include/firebase/internal/mutex.h" -#include "gma/src/common/ad_view_internal.h" - -namespace firebase { -namespace gma { -namespace internal { - -class AdViewInternalIOS : public AdViewInternal { - public: - explicit AdViewInternalIOS(AdView* base); - ~AdViewInternalIOS(); - - Future Initialize(AdParent parent, const char* ad_unit_id, - const AdSize& size) override; - Future LoadAd(const AdRequest& request) override; - BoundingBox bounding_box() const override; - Future SetPosition(int x, int y) override; - Future SetPosition(AdView::Position position) override; - Future Hide() override; - Future Show() override; - Future Pause() override; - Future Resume() override; - Future Destroy() override; - bool is_initialized() const override { return initialized_; } - void set_bounding_box(const BoundingBox& bounding_box) { - bounding_box_ = bounding_box; - } - -#ifdef __OBJC__ - void AdViewDidReceiveAd(int width, int height, - GADResponseInfo* gad_response_info); - void AdViewDidFailToReceiveAdWithError(NSError* gad_error); -#endif // __OBJC__ - - private: - /// Contains information to asynchronously complete the LoadAd Future. - FutureCallbackData* ad_load_callback_data_; - - /// The FADAdView object. Declared as an "id" type to avoid referencing an - /// Objective-C++ class in this header. - id ad_view_; - - /// A cached bounding box from the last update, accessible for processes - /// running on non-UI threads. - BoundingBox bounding_box_; - - /// A mutex used to handle the destroy behavior, as it is asynchronous, - /// and needs to be waited on in the destructor. - Mutex destroy_mutex_; - - /// Prevents duplicate invocations of initialize on the AdView. - bool initialized_; - - // Mutex to guard against concurrent operations; - Mutex mutex_; -}; - -} // namespace internal -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_IOS_AD_VIEW_INTERNAL_IOS_H_ diff --git a/gma/src/ios/ad_view_internal_ios.mm b/gma/src/ios/ad_view_internal_ios.mm deleted file mode 100644 index 4f239766bf..0000000000 --- a/gma/src/ios/ad_view_internal_ios.mm +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/ios/ad_view_internal_ios.h" - -#import "gma/src/ios/FADAdView.h" -#import "gma/src/ios/FADRequest.h" -#import "gma/src/ios/gma_ios.h" - -#include "app/src/util_ios.h" -#include "gma/src/ios/response_info_ios.h" - -namespace firebase { -namespace gma { -namespace internal { - -AdViewInternalIOS::AdViewInternalIOS(AdView* base) - : AdViewInternal(base), - ad_load_callback_data_(nil), - ad_view_(nil), - destroy_mutex_(Mutex::kModeNonRecursive), - initialized_(false) {} - -AdViewInternalIOS::~AdViewInternalIOS() { - if (ad_load_callback_data_ != nil) { - delete ad_load_callback_data_; - ad_load_callback_data_ = nil; - } - - id ad_view = ad_view_; - ad_view_ = nil; - - void (^destroyBlock)() = ^{ - if (ad_view) { - // Remove the FADAdView (i.e. the container view of GADAdView) - // from the superview. - [ad_view removeFromSuperview]; - [ad_view destroy]; - } - }; - - util::DispatchAsyncSafeMainQueue(destroyBlock); -} - -Future AdViewInternalIOS::Initialize(AdParent parent, const char* ad_unit_id, - const AdSize& size) { - firebase::MutexLock lock(mutex_); - const SafeFutureHandle future_handle = - future_data_.future_impl.SafeAlloc(kAdViewFnInitialize); - Future future = MakeFuture(&future_data_.future_impl, future_handle); - - if (initialized_) { - CompleteFuture(kAdErrorCodeAlreadyInitialized, kAdAlreadyInitializedErrorMessage, future_handle, - &future_data_); - } else { - initialized_ = true; - - // Guard against parameter object destruction before the async operation - // executes (below). - AdParent local_ad_parent = parent; - NSString* local_ad_unit_id = @(ad_unit_id); - ad_size_ = size; - - dispatch_async(dispatch_get_main_queue(), ^{ - ad_view_ = [[FADAdView alloc] initWithView:local_ad_parent - adUnitID:local_ad_unit_id - adSize:ad_size_ - internalAdView:this]; - CompleteFuture(kAdErrorCodeNone, nullptr, future_handle, &future_data_); - }); - } - return future; -} - -Future AdViewInternalIOS::LoadAd(const AdRequest& request) { - firebase::MutexLock lock(mutex_); - FutureCallbackData* callback_data = - CreateAdResultFutureCallbackData(kAdViewFnLoadAd, &future_data_); - Future future = MakeFuture(&future_data_.future_impl, callback_data->future_handle); - - if (ad_load_callback_data_ != nil) { - CompleteLoadAdInternalError(callback_data, kAdErrorCodeLoadInProgress, - kAdLoadInProgressErrorMessage); - return future; - } - // Persist a pointer to the callback data so that we may use it after the iOS - // SDK returns the AdResult. - ad_load_callback_data_ = callback_data; - - // Guard against parameter object destruction before the async operation - // executes (below). - AdRequest local_ad_request = request; - - dispatch_async(dispatch_get_main_queue(), ^{ - AdErrorCode error_code = kAdErrorCodeNone; - std::string error_message; - - // Create a GADRequest from a gma::AdRequest. - GADRequest* ad_request = - GADRequestFromCppAdRequest(local_ad_request, &error_code, &error_message); - if (ad_request == nullptr) { - if (error_code == kAdErrorCodeNone) { - error_code = kAdErrorCodeInternalError; - error_message = kAdCouldNotParseAdRequestErrorMessage; - } - CompleteLoadAdInternalError(ad_load_callback_data_, error_code, error_message.c_str()); - ad_load_callback_data_ = nil; - } else { - // Make the AdView ad request. - [(GADBannerView*)ad_view_ loadRequest:ad_request]; - } - }); - return future; -} - -Future AdViewInternalIOS::SetPosition(int x, int y) { - firebase::MutexLock lock(mutex_); - const firebase::SafeFutureHandle future_handle = - future_data_.future_impl.SafeAlloc(kAdViewFnSetPosition); - Future future = MakeFuture(&future_data_.future_impl, future_handle); - - dispatch_async(dispatch_get_main_queue(), ^{ - AdErrorCode error = kAdErrorCodeUninitialized; - const char* error_msg = kAdUninitializedErrorMessage; - if (ad_view_) { - [ad_view_ moveAdViewToXCoordinate:x yCoordinate:y]; - error = kAdErrorCodeNone; - error_msg = nullptr; - } - CompleteFuture(error, error_msg, future_handle, &future_data_); - }); - return future; -} - -Future AdViewInternalIOS::SetPosition(AdView::Position position) { - firebase::MutexLock lock(mutex_); - const firebase::SafeFutureHandle future_handle = - future_data_.future_impl.SafeAlloc(kAdViewFnSetPosition); - Future future = MakeFuture(&future_data_.future_impl, future_handle); - - // Guard against parameter object destruction before the async operation - // executes (below). - AdView::Position local_position = position; - - dispatch_async(dispatch_get_main_queue(), ^{ - AdErrorCode error = kAdErrorCodeUninitialized; - const char* error_msg = kAdUninitializedErrorMessage; - if (ad_view_) { - [ad_view_ moveAdViewToPosition:local_position]; - error = kAdErrorCodeNone; - error_msg = nullptr; - } - CompleteFuture(error, error_msg, future_handle, &future_data_); - }); - return future; -} - -Future AdViewInternalIOS::Hide() { - firebase::MutexLock lock(mutex_); - const SafeFutureHandle future_handle = - future_data_.future_impl.SafeAlloc(kAdViewFnHide); - Future future = MakeFuture(&future_data_.future_impl, future_handle); - - dispatch_async(dispatch_get_main_queue(), ^{ - [ad_view_ hide]; - CompleteFuture(kAdErrorCodeNone, nullptr, future_handle, &future_data_); - }); - return future; -} - -Future AdViewInternalIOS::Show() { - firebase::MutexLock lock(mutex_); - const firebase::SafeFutureHandle future_handle = - future_data_.future_impl.SafeAlloc(kAdViewFnShow); - Future future = MakeFuture(&future_data_.future_impl, future_handle); - - dispatch_async(dispatch_get_main_queue(), ^{ - [ad_view_ show]; - CompleteFuture(kAdErrorCodeNone, nullptr, future_handle, &future_data_); - }); - return future; -} - -/// This method is part of the C++ interface and is used only on Android. -Future AdViewInternalIOS::Pause() { - firebase::MutexLock lock(mutex_); - // Required method. No-op. - return CreateAndCompleteFuture(kAdViewFnPause, kAdErrorCodeNone, nullptr, &future_data_); -} - -/// This method is part of the C++ interface and is used only on Android. -Future AdViewInternalIOS::Resume() { - firebase::MutexLock lock(mutex_); - // Required method. No-op. - return CreateAndCompleteFuture(kAdViewFnResume, kAdErrorCodeNone, nullptr, &future_data_); -} - -/// Cleans up any resources created in AdViewInternalIOS. -Future AdViewInternalIOS::Destroy() { - firebase::MutexLock lock(mutex_); - destroy_mutex_.Acquire(); - - const firebase::SafeFutureHandle future_handle = - future_data_.future_impl.SafeAlloc(kAdViewFnDestroy); - - if (ad_load_callback_data_ != nil) { - delete ad_load_callback_data_; - ad_load_callback_data_ = nil; - } - - // Consistent with Android SDK which returns a final bounding box of - // -1 values upon deletion. - bounding_box_.width = bounding_box_.height = bounding_box_.x = bounding_box_.y = -1; - bounding_box_.position = AdView::kPositionUndefined; - NotifyListenerOfBoundingBoxChange(bounding_box_); - - id ad_view = ad_view_; - ad_view_ = nil; - - void (^destroyBlock)() = ^{ - if (ad_view) { - // Remove the FADAdView (i.e. the container view of GADAdView) - // from the superview. - [ad_view removeFromSuperview]; - [ad_view destroy]; - } - - CompleteFuture(kAdErrorCodeNone, nullptr, future_handle, &future_data_); - destroy_mutex_.Release(); - }; - - util::DispatchAsyncSafeMainQueue(destroyBlock); - return MakeFuture(&future_data_.future_impl, future_handle); -} - -BoundingBox AdViewInternalIOS::bounding_box() const { return bounding_box_; } - -void AdViewInternalIOS::AdViewDidReceiveAd(int width, int height, - GADResponseInfo* gad_response_info) { - firebase::MutexLock lock(mutex_); - update_ad_size_dimensions(width, height); - - if (ad_load_callback_data_ != nil) { - CompleteLoadAdInternalSuccess(ad_load_callback_data_, - ResponseInfoInternal({gad_response_info})); - ad_load_callback_data_ = nil; - } -} - -void AdViewInternalIOS::AdViewDidFailToReceiveAdWithError(NSError* error) { - firebase::MutexLock lock(mutex_); - FIREBASE_ASSERT(error); - if (ad_load_callback_data_ != nil) { - CompleteAdResultError(ad_load_callback_data_, error, - /*is_load_ad_error=*/true); - ad_load_callback_data_ = nil; - } -} - -} // namespace internal -} // namespace gma -} // namespace firebase diff --git a/gma/src/ios/adapter_response_info_ios.h b/gma/src/ios/adapter_response_info_ios.h deleted file mode 100644 index 2bd16f73e5..0000000000 --- a/gma/src/ios/adapter_response_info_ios.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_IOS_ADAPTER_RESPONSE_INFO_IOS_H_ -#define FIREBASE_GMA_SRC_IOS_ADAPTER_RESPONSE_INFO_IOS_H_ - -extern "C" { -#include -} // extern "C" - -#import - -namespace firebase { -namespace gma { - -struct AdapterResponseInfoInternal { - GADAdNetworkResponseInfo* ad_network_response_info; -}; - -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_IOS_ADAPTER_RESPONSE_INFO_IOS_H_ diff --git a/gma/src/ios/adapter_response_info_ios.mm b/gma/src/ios/adapter_response_info_ios.mm deleted file mode 100644 index 8210cc497a..0000000000 --- a/gma/src/ios/adapter_response_info_ios.mm +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -extern "C" { -#include -} // extern "C" - -#include - -#include "app/src/include/firebase/internal/mutex.h" -#include "app/src/util_ios.h" -#include "app/src/assert.h" -#include "gma/src/include/firebase/gma.h" -#include "gma/src/include/firebase/gma/types.h" -#include "gma/src/ios/ad_error_ios.h" -#include "gma/src/ios/adapter_response_info_ios.h" - -namespace firebase { -namespace gma { - -AdapterResponseInfo::AdapterResponseInfo(const AdapterResponseInfoInternal& internal) - : ad_result_() { - FIREBASE_ASSERT(internal.ad_network_response_info); - - if (internal.ad_network_response_info.error != nil) { - AdErrorInternal ad_error_internal; - ad_error_internal.native_ad_error = internal.ad_network_response_info.error; - AdError ad_error = AdError(ad_error_internal); - if (ad_error.code() != kAdErrorCodeNone) { - ad_result_ = AdResult(AdError(ad_error_internal)); - } - } - - adapter_class_name_ = - util::NSStringToString(internal.ad_network_response_info.adNetworkClassName); - - // ObjC latency is an NSInterval, which is in seconds. Convert to millis. - latency_ = (int64_t)(internal.ad_network_response_info.latency) * (int64_t)1000; - - to_string_ = util::NSStringToString(internal.ad_network_response_info.description); -} - -} // namespace gma -} // namespace firebase diff --git a/gma/src/ios/gma_ios.h b/gma/src/ios/gma_ios.h deleted file mode 100644 index 2c32aca310..0000000000 --- a/gma/src/ios/gma_ios.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_IOS_GMA_IOS_H_ -#define FIREBASE_GMA_SRC_IOS_GMA_IOS_H_ - -extern "C" { -#include -} // extern "C" - -#import -#import - -#include -#include "gma/src/common/gma_common.h" -#include "gma/src/include/firebase/gma/types.h" - -namespace firebase { -namespace gma { - -// Completes AdResult futures for successful ad loads. -void CompleteLoadAdInternalSuccess( - FutureCallbackData* callback_data, - const ResponseInfoInternal& response_info_internal); - -// Resolves LoadAd errors that exist in the C++ SDK before they reach the iOS -// SDK. -void CompleteLoadAdInternalError(FutureCallbackData* callback_data, - AdErrorCode error_code, - const char* error_message); - -// Completes ImageResult futures for successful image loads. -void CompleteLoadImageInternalSuccess( - FutureCallbackData* callback_data, - const std::vector& img_data); - -// Pipes query info generation errors that exist in the C++ SDK. -void CompleteQueryInfoInternalError( - FutureCallbackData* callback_data, - int error_code, - const char* error_message); - -// Completes QueryInfoResult futures for successful query info generation. -void CompleteQueryInfoInternalSuccess( - FutureCallbackData* callback_data, - NSString* query_info); - -// Resolves LoadImage errors that exist in the C++ SDK before initiating image -// loads. -void CompleteLoadImageInternalError( - FutureCallbackData* callback_data, - int error_code, - const char* error_message); - -// Parses information from the NSError to populate an AdResult -// and completes the AdResult Future on iOS. -void CompleteAdResultError(FutureCallbackData* callback_data, - NSError* error, bool is_load_ad_error); - -// Converts the iOS GMA GADAdValue structure into a CPP -// firebase::gma::Advalue structure. -AdValue ConvertGADAdValueToCppAdValue(GADAdValue* gad_value); - -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_IOS_GMA_IOS_H_ diff --git a/gma/src/ios/gma_ios.mm b/gma/src/ios/gma_ios.mm deleted file mode 100644 index 47b185d228..0000000000 --- a/gma/src/ios/gma_ios.mm +++ /dev/null @@ -1,411 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import "gma/src/ios/gma_ios.h" - -#include -#include -#include "gma/src/include/firebase/gma.h" - -#import -#import -#import - -#import "gma/src/ios/FADRequest.h" - -#include "app/src/include/firebase/app.h" -#include "app/src/include/firebase/future.h" -#include "app/src/include/firebase/internal/mutex.h" -#include "app/src/log.h" -#include "app/src/util_ios.h" -#include "gma/src/common/gma_common.h" -#include "gma/src/include/firebase/gma/types.h" -#include "gma/src/ios/ad_error_ios.h" -#include "gma/src/ios/adapter_response_info_ios.h" -#include "gma/src/ios/response_info_ios.h" - -namespace firebase { -namespace gma { - -static const ::firebase::App* g_app = nullptr; - -static bool g_initialized = false; - -// Constants representing each GMA function that returns a Future. -enum GmaFn { - kGmaFnInitialize, - kGmaFnCount, -}; - -static ReferenceCountedFutureImpl* g_future_impl = nullptr; -// Mutex for creation/deletion of a g_future_impl. -static Mutex g_future_impl_mutex; // NOLINT - -// Take an iOS GADInitializationStatus object and populate our own -// AdapterInitializationStatus class. -static AdapterInitializationStatus PopulateAdapterInitializationStatus( - GADInitializationStatus* init_status) { - if (!init_status) return GmaInternal::CreateAdapterInitializationStatus({}); - - std::map adapter_status_map; - - NSDictionary* status_dict = init_status.adapterStatusesByClassName; - for (NSString* key in status_dict) { - GADAdapterStatus* status = [status_dict objectForKey:key]; - AdapterStatus adapter_status = GmaInternal::CreateAdapterStatus( - util::NSStringToString(status.description), - status.state == GADAdapterInitializationStateReady, status.latency); - adapter_status_map[util::NSStringToString(key)] = adapter_status; - } - return GmaInternal::CreateAdapterInitializationStatus(adapter_status_map); -} - -static Future InitializeGma() { - MutexLock lock(g_future_impl_mutex); - FIREBASE_ASSERT(g_future_impl); - - SafeFutureHandle handle = - g_future_impl->SafeAlloc(kGmaFnInitialize); - [GADMobileAds.sharedInstance - startWithCompletionHandler:^(GADInitializationStatus* _Nonnull status) { - // GAD initialization has completed, with adapter initialization status. - AdapterInitializationStatus adapter_status = PopulateAdapterInitializationStatus(status); - { - MutexLock lock(g_future_impl_mutex); - // Check if g_future_impl still exists; if not, Terminate() was called, ignore the - // result of this callback. - if (g_future_impl) { - g_future_impl->CompleteWithResult(handle, 0, "", adapter_status); - } - } - }]; - return MakeFuture(g_future_impl, handle); -} - -Future Initialize(InitResult* init_result_out) { - FIREBASE_ASSERT(!g_initialized); - g_initialized = true; - - { - MutexLock lock(g_future_impl_mutex); - g_future_impl = new ReferenceCountedFutureImpl(kGmaFnCount); - } - - RegisterTerminateOnDefaultAppDestroy(); - if (init_result_out) { - *init_result_out = kInitResultSuccess; - } - return InitializeGma(); -} - -Future Initialize(const ::firebase::App& app, - InitResult* init_result_out) { - FIREBASE_ASSERT(!g_initialized); - g_initialized = true; - { - MutexLock lock(g_future_impl_mutex); - g_future_impl = new ReferenceCountedFutureImpl(kGmaFnCount); - } - g_app = &app; - RegisterTerminateOnDefaultAppDestroy(); - if (init_result_out) { - *init_result_out = kInitResultSuccess; - } - return InitializeGma(); -} - -bool IsInitialized() { return g_initialized; } - -void DisableSDKCrashReporting() { [GADMobileAds.sharedInstance disableSDKCrashReporting]; } - -void DisableMediationInitialization() { - [GADMobileAds.sharedInstance disableMediationInitialization]; -} - -void SetRequestConfiguration(const RequestConfiguration& request_configuration) { - GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = - util::StringVectorToNSMutableArray(request_configuration.test_device_ids); - - switch (request_configuration.max_ad_content_rating) { - case RequestConfiguration::kMaxAdContentRatingG: - GADMobileAds.sharedInstance.requestConfiguration.maxAdContentRating = - GADMaxAdContentRatingGeneral; - break; - case RequestConfiguration::kMaxAdContentRatingPG: - GADMobileAds.sharedInstance.requestConfiguration.maxAdContentRating = - GADMaxAdContentRatingParentalGuidance; - break; - case RequestConfiguration::kMaxAdContentRatingT: - GADMobileAds.sharedInstance.requestConfiguration.maxAdContentRating = - GADMaxAdContentRatingTeen; - break; - case RequestConfiguration::kMaxAdContentRatingMA: - GADMobileAds.sharedInstance.requestConfiguration.maxAdContentRating = - GADMaxAdContentRatingMatureAudience; - break; - case RequestConfiguration::kMaxAdContentRatingUnspecified: - default: - // Do not set this value, which has significance in the iOS SDK. - break; - } - - switch (request_configuration.tag_for_child_directed_treatment) { - case RequestConfiguration::kChildDirectedTreatmentFalse: - GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment = [NSNumber numberWithBool:NO]; - break; - case RequestConfiguration::kChildDirectedTreatmentTrue: - GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment = [NSNumber numberWithBool:YES]; - break; - default: - case RequestConfiguration::kChildDirectedTreatmentUnspecified: - // Do not set this value, which has significance in the iOS SDK. - break; - } - - switch (request_configuration.tag_for_under_age_of_consent) { - case RequestConfiguration::kUnderAgeOfConsentFalse: - GADMobileAds.sharedInstance.requestConfiguration.tagForUnderAgeOfConsent = [NSNumber numberWithBool:NO]; - break; - case RequestConfiguration::kUnderAgeOfConsentTrue: - GADMobileAds.sharedInstance.requestConfiguration.tagForUnderAgeOfConsent = [NSNumber numberWithBool:YES]; - break; - default: - case RequestConfiguration::kUnderAgeOfConsentUnspecified: - // Do not set this value, which has significance in the iOS SDK. - break; - } -} - -RequestConfiguration GetRequestConfiguration() { - RequestConfiguration request_configuration; - - GADMaxAdContentRating content_rating = - GADMobileAds.sharedInstance.requestConfiguration.maxAdContentRating; - if (content_rating == GADMaxAdContentRatingGeneral) { - request_configuration.max_ad_content_rating = RequestConfiguration::kMaxAdContentRatingG; - } else if (content_rating == GADMaxAdContentRatingParentalGuidance) { - request_configuration.max_ad_content_rating = RequestConfiguration::kMaxAdContentRatingPG; - } else if (content_rating == GADMaxAdContentRatingTeen) { - request_configuration.max_ad_content_rating = RequestConfiguration::kMaxAdContentRatingT; - } else if (content_rating == GADMaxAdContentRatingMatureAudience) { - request_configuration.max_ad_content_rating = RequestConfiguration::kMaxAdContentRatingMA; - } else { - request_configuration.max_ad_content_rating = - RequestConfiguration::kMaxAdContentRatingUnspecified; - } - - request_configuration.tag_for_under_age_of_consent = - RequestConfiguration::kUnderAgeOfConsentUnspecified; - request_configuration.tag_for_child_directed_treatment = - RequestConfiguration::kChildDirectedTreatmentUnspecified; - - util::NSArrayOfNSStringToVectorOfString( - GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers, - &request_configuration.test_device_ids); - - return request_configuration; -} - -void OpenAdInspector(AdParent ad_parent, AdInspectorClosedListener* listener) { - dispatch_async(dispatch_get_main_queue(), ^{ - [GADMobileAds.sharedInstance - presentAdInspectorFromViewController:(UIViewController*)ad_parent - completionHandler:^(NSError* error) { - // Error will be non-nil if there was an issue and the inspector was - // not displayed. - AdResult ad_result; - if (error != nil) { - AdErrorInternal ad_error_internal; - ad_error_internal.ad_error_type = - AdErrorInternal::kAdErrorInternalOpenAdInspectorError; - ad_error_internal.native_ad_error = error; - ad_error_internal.is_successful = false; - ad_result = AdResult(GmaInternal::CreateAdError(ad_error_internal)); - } - - listener->OnAdInspectorClosed(ad_result); - }]; - }); -} - -void SetIsSameAppKeyEnabled(bool is_enabled) { - dispatch_async(dispatch_get_main_queue(), ^{ - if (is_enabled) { - [GADMobileAds.sharedInstance.requestConfiguration setPublisherFirstPartyIDEnabled:YES]; - } else { - [GADMobileAds.sharedInstance.requestConfiguration setPublisherFirstPartyIDEnabled:NO]; - } - }); -} - -Future InitializeLastResult() { - MutexLock lock(g_future_impl_mutex); - return g_future_impl ? static_cast&>( - g_future_impl->LastResult(kGmaFnInitialize)) - : Future(); -} - -AdapterInitializationStatus GetInitializationStatus() { - if (g_initialized) { - GADInitializationStatus* status = GADMobileAds.sharedInstance.initializationStatus; - return PopulateAdapterInitializationStatus(status); - } else { - // Returns an empty map. - return PopulateAdapterInitializationStatus(nil); - } -} - -void Terminate() { - FIREBASE_ASSERT(g_initialized); - - { - MutexLock lock(g_future_impl_mutex); - delete g_future_impl; - g_future_impl = nullptr; - } - - UnregisterTerminateOnDefaultAppDestroy(); - DestroyCleanupNotifier(); - g_initialized = false; - g_app = nullptr; -} - -const ::firebase::App* GetApp() { return g_app; } - -// Constructs AdResult objects based on the encountered error, beit one that -// originated from C++ SDK Wrapper or an error returned from the iOS GMA SDK. -void CompleteAdResultError(FutureCallbackData* callback_data, NSError* error, - bool is_load_ad_error, AdErrorCode error_code, - const char* error_message) { - FIREBASE_ASSERT(callback_data); - FIREBASE_ASSERT(error_message); - - std::string future_error_message; - AdErrorInternal ad_error_internal; - - ad_error_internal.native_ad_error = error; - ad_error_internal.is_successful = false; - ad_error_internal.code = error_code; - - // Further result configuration is based on success/failure. - if (error != nullptr) { - // The iOS SDK returned an error. The NSError object will be used by the - // AdError implementation to populate its fields. - ad_error_internal.is_successful = false; - if (is_load_ad_error) { - ad_error_internal.ad_error_type = AdErrorInternal::kAdErrorInternalLoadAdError; - } else { - ad_error_internal.ad_error_type = AdErrorInternal::kAdErrorInternalAdError; - } - } else { - FIREBASE_ASSERT_MESSAGE(ad_error_internal.code != kAdErrorCodeNone, - "GMA CompleteAdResultError couldn't determine the type of error"); - - // C++ SDK iOS GMA Wrapper encountered an error. - ad_error_internal.ad_error_type = AdErrorInternal::kAdErrorInternalWrapperError; - ad_error_internal.message = std::string(error_message); - ad_error_internal.domain = "SDK"; - ad_error_internal.to_string = std::string("Internal error: ") + ad_error_internal.message; - future_error_message = ad_error_internal.message; - } - - GmaInternal::CompleteLoadAdFutureFailure(callback_data, ad_error_internal.code, - future_error_message, ad_error_internal); -} - -void CompleteLoadAdInternalSuccess(FutureCallbackData* callback_data, - const ResponseInfoInternal& response_info_internal) { - FIREBASE_ASSERT(callback_data); - - GmaInternal::CompleteLoadAdFutureSuccess(callback_data, response_info_internal); -} - -void CompleteLoadAdInternalError(FutureCallbackData* callback_data, - AdErrorCode error_code, const char* error_message) { - FIREBASE_ASSERT(callback_data); - FIREBASE_ASSERT(error_message); - - CompleteAdResultError(callback_data, /*error=*/nullptr, - /*is_load_ad_error=*/false, error_code, error_message); -} - -void CompleteLoadImageInternalSuccess(FutureCallbackData* callback_data, - const std::vector& img_data) { - FIREBASE_ASSERT(callback_data); - - GmaInternal::CompleteLoadImageFutureSuccess(callback_data, img_data); -} - -void CompleteLoadImageInternalError(FutureCallbackData* callback_data, - int error_code, const char* error_message) { - FIREBASE_ASSERT(callback_data); - FIREBASE_ASSERT(error_message); - - GmaInternal::CompleteLoadImageFutureFailure(callback_data, error_code, std::string(error_message)); -} - -void CompleteQueryInfoInternalSuccess(FutureCallbackData* callback_data, - NSString* query_info) { - FIREBASE_ASSERT(callback_data); - - GmaInternal::CompleteCreateQueryInfoFutureSuccess(callback_data, - util::NSStringToString(query_info)); -} - -void CompleteQueryInfoInternalError(FutureCallbackData* callback_data, - int error_code, const char* error_message) { - FIREBASE_ASSERT(callback_data); - FIREBASE_ASSERT(error_message); - - GmaInternal::CompleteCreateQueryInfoFutureFailure(callback_data, error_code, - std::string(error_message)); -} - -void CompleteAdResultError(FutureCallbackData* callback_data, NSError* gad_error, - bool is_load_ad_error) { - FIREBASE_ASSERT(callback_data); - - AdErrorCode error_code = MapAdRequestErrorCodeToCPPErrorCode((GADErrorCode)gad_error.code); - CompleteAdResultError(callback_data, gad_error, is_load_ad_error, error_code, - util::NSStringToString(gad_error.localizedDescription).c_str()); -} - -AdValue ConvertGADAdValueToCppAdValue(GADAdValue* gad_value) { - FIREBASE_ASSERT(gad_value); - - AdValue::PrecisionType precision_type; - switch (gad_value.precision) { - default: - case GADAdValuePrecisionUnknown: - precision_type = AdValue::kAdValuePrecisionUnknown; - break; - case GADAdValuePrecisionEstimated: - precision_type = AdValue::kAdValuePrecisionEstimated; - break; - case GADAdValuePrecisionPublisherProvided: - precision_type = AdValue::kAdValuePrecisionPublisherProvided; - break; - case GADAdValuePrecisionPrecise: - precision_type = AdValue::kAdValuePrecisionPrecise; - break; - } - - return AdValue(util::NSStringToString(gad_value.currencyCode).c_str(), precision_type, - (int64_t)gad_value.value.longLongValue); -} - -} // namespace gma -} // namespace firebase diff --git a/gma/src/ios/interstitial_ad_internal_ios.h b/gma/src/ios/interstitial_ad_internal_ios.h deleted file mode 100644 index 6c7d69faa9..0000000000 --- a/gma/src/ios/interstitial_ad_internal_ios.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_IOS_INTERSTITIAL_AD_INTERNAL_IOS_H_ -#define FIREBASE_GMA_SRC_IOS_INTERSTITIAL_AD_INTERNAL_IOS_H_ - -#ifdef __OBJC__ -#import "gma/src/ios/FADInterstitialDelegate.h" -#endif // __OBJC__ - -extern "C" { -#include -} // extern "C" - -#include "app/src/include/firebase/internal/mutex.h" -#include "gma/src/common/interstitial_ad_internal.h" - -namespace firebase { -namespace gma { -namespace internal { - -class InterstitialAdInternalIOS : public InterstitialAdInternal { - public: - explicit InterstitialAdInternalIOS(InterstitialAd* base); - ~InterstitialAdInternalIOS(); - - Future Initialize(AdParent parent) override; - Future LoadAd(const char* ad_unit_id, - const AdRequest& request) override; - Future Show() override; - -#ifdef __OBJC__ - void InterstitialDidReceiveAd(GADInterstitialAd* ad); - void InterstitialDidFailToReceiveAdWithError(NSError* gad_error); - void InterstitialWillPresentScreen(); - void InterstitialDidDismissScreen(); -#endif // __OBJC__ - - bool is_initialized() const override { return initialized_; } - - private: - /// Prevents duplicate invocations of initialize on the Interstitial Ad. - bool initialized_; - - /// Contains information to asynchronously complete the LoadAd Future. - FutureCallbackData* ad_load_callback_data_; - - /// The GADInterstitialAd object. Declared as an "id" type to avoid - /// referencing an Objective-C class in this header. - id interstitial_; - - /// The publisher-provided view (UIView) that's the parent view of the - /// interstitial ad. Declared as an "id" type to avoid referencing an - /// Objective-C class in this header. - id parent_view_; - - /// The FADInterstitialDelegate object that conforms to the - /// GADInterstitialDelegate protocol. Declared as an "id" type to avoid - /// referencing an Objective-C++ class in this header. - id interstitial_delegate_; - - // Mutex to guard against concurrent operations; - Mutex mutex_; -}; - -} // namespace internal -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_IOS_INTERSTITIAL_AD_INTERNAL_IOS_H_ diff --git a/gma/src/ios/interstitial_ad_internal_ios.mm b/gma/src/ios/interstitial_ad_internal_ios.mm deleted file mode 100644 index f21c3c74f1..0000000000 --- a/gma/src/ios/interstitial_ad_internal_ios.mm +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/ios/interstitial_ad_internal_ios.h" - -#import "gma/src/ios/FADRequest.h" -#import "gma/src/ios/gma_ios.h" - -#include "app/src/util_ios.h" -#include "gma/src/ios/response_info_ios.h" - -namespace firebase { -namespace gma { -namespace internal { - -InterstitialAdInternalIOS::InterstitialAdInternalIOS(InterstitialAd *base) - : InterstitialAdInternal(base), - initialized_(false), - ad_load_callback_data_(nil), - interstitial_(nil), - parent_view_(nil), - interstitial_delegate_(nil) {} - -InterstitialAdInternalIOS::~InterstitialAdInternalIOS() { - firebase::MutexLock lock(mutex_); - ((GADInterstitialAd *)interstitial_).fullScreenContentDelegate = nil; - interstitial_delegate_ = nil; - interstitial_ = nil; - if (ad_load_callback_data_ != nil) { - delete ad_load_callback_data_; - ad_load_callback_data_ = nil; - } -} - -Future InterstitialAdInternalIOS::Initialize(AdParent parent) { - firebase::MutexLock lock(mutex_); - const SafeFutureHandle future_handle = - future_data_.future_impl.SafeAlloc(kInterstitialAdFnInitialize); - Future future = MakeFuture(&future_data_.future_impl, future_handle); - - if (initialized_) { - CompleteFuture(kAdErrorCodeAlreadyInitialized, kAdAlreadyInitializedErrorMessage, future_handle, - &future_data_); - } else { - initialized_ = true; - parent_view_ = (UIView *)parent; - CompleteFuture(kAdErrorCodeNone, nullptr, future_handle, &future_data_); - } - return future; -} - -Future InterstitialAdInternalIOS::LoadAd(const char *ad_unit_id, - const AdRequest &request) { - firebase::MutexLock lock(mutex_); - FutureCallbackData *callback_data = - CreateAdResultFutureCallbackData(kInterstitialAdFnLoadAd, &future_data_); - Future future = MakeFuture(&future_data_.future_impl, callback_data->future_handle); - - if (ad_load_callback_data_ != nil) { - CompleteLoadAdInternalError(callback_data, kAdErrorCodeLoadInProgress, - kAdLoadInProgressErrorMessage); - return future; - } - - // Persist a pointer to the callback data so that we may use it after the iOS - // SDK returns the AdResult. - ad_load_callback_data_ = callback_data; - - interstitial_delegate_ = [[FADInterstitialDelegate alloc] initWithInternalInterstitialAd:this]; - - // Guard against parameter object destruction before the async operation - // executes (below). - AdRequest local_ad_request = request; - NSString *local_ad_unit_id = @(ad_unit_id); - - dispatch_async(dispatch_get_main_queue(), ^{ - // Create a GADRequest from a gma::AdRequest. - AdErrorCode error_code = kAdErrorCodeNone; - std::string error_message; - GADRequest *ad_request = - GADRequestFromCppAdRequest(local_ad_request, &error_code, &error_message); - if (ad_request == nullptr) { - if (error_code == kAdErrorCodeNone) { - error_code = kAdErrorCodeInternalError; - error_message = kAdCouldNotParseAdRequestErrorMessage; - } - CompleteLoadAdInternalError(ad_load_callback_data_, error_code, error_message.c_str()); - ad_load_callback_data_ = nil; - } else { - // Make the interstitial ad request. - [GADInterstitialAd loadWithAdUnitID:local_ad_unit_id - request:ad_request - completionHandler:^(GADInterstitialAd *ad, NSError *error) // NO LINT - { - if (error) { - InterstitialDidFailToReceiveAdWithError(error); - } else { - InterstitialDidReceiveAd(ad); - } - }]; - } - }); - - return future; -} - -Future InterstitialAdInternalIOS::Show() { - firebase::MutexLock lock(mutex_); - const firebase::SafeFutureHandle future_handle = - future_data_.future_impl.SafeAlloc(kInterstitialAdFnShow); - Future future = MakeFuture(&future_data_.future_impl, future_handle); - dispatch_async(dispatch_get_main_queue(), ^{ - AdErrorCode error_code = kAdErrorCodeLoadInProgress; - const char *error_message = kAdLoadInProgressErrorMessage; - if (interstitial_ == nil) { - error_code = kAdErrorCodeUninitialized; - error_message = kAdUninitializedErrorMessage; - } else { - [interstitial_ presentFromRootViewController:[parent_view_ window].rootViewController]; - error_code = kAdErrorCodeNone; - error_message = nullptr; - } - CompleteFuture(error_code, error_message, future_handle, &future_data_); - }); - return future; -} - -void InterstitialAdInternalIOS::InterstitialDidReceiveAd(GADInterstitialAd *ad) { - firebase::MutexLock lock(mutex_); - interstitial_ = ad; - ad.fullScreenContentDelegate = interstitial_delegate_; - ad.paidEventHandler = ^void(GADAdValue *_Nonnull adValue) { - NotifyListenerOfPaidEvent(firebase::gma::ConvertGADAdValueToCppAdValue(adValue)); - }; - - if (ad_load_callback_data_ != nil) { - CompleteLoadAdInternalSuccess(ad_load_callback_data_, ResponseInfoInternal({ad.responseInfo})); - ad_load_callback_data_ = nil; - } -} - -void InterstitialAdInternalIOS::InterstitialDidFailToReceiveAdWithError(NSError *gad_error) { - firebase::MutexLock lock(mutex_); - FIREBASE_ASSERT(gad_error); - if (ad_load_callback_data_ != nil) { - CompleteAdResultError(ad_load_callback_data_, gad_error, /*is_load_ad_error=*/true); - ad_load_callback_data_ = nil; - } -} - -} // namespace internal -} // namespace gma -} // namespace firebase diff --git a/gma/src/ios/native_ad_image_ios.h b/gma/src/ios/native_ad_image_ios.h deleted file mode 100644 index 6f6ebf3a40..0000000000 --- a/gma/src/ios/native_ad_image_ios.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_IOS_NATIVE_AD_IMAGE_IOS_H_ -#define FIREBASE_GMA_SRC_IOS_NATIVE_AD_IMAGE_IOS_H_ - -extern "C" { -#include -} // extern "C" - -#import -#import - -#include "gma/src/common/native_ad_image_internal.h" - - -#endif // FIREBASE_GMA_SRC_IOS_NATIVE_AD_IMAGE_IOS_H_ diff --git a/gma/src/ios/native_ad_image_ios.mm b/gma/src/ios/native_ad_image_ios.mm deleted file mode 100644 index f74153379d..0000000000 --- a/gma/src/ios/native_ad_image_ios.mm +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -extern "C" { -#include -} // extern "C" - -#import "gma/src/ios/FADRequest.h" -#import "gma/src/ios/gma_ios.h" - -#include -#include - -#include "app/src/assert.h" -#include "app/src/util_ios.h" -#include "gma/src/common/native_ad_image_internal.h" -#include "gma/src/include/firebase/gma.h" -#include "gma/src/ios/native_ad_image_ios.h" - -namespace firebase { -namespace gma { - -// A simple helper function for performing asynchronous network requests, used -// for downloading static assets. -static void DownloadHelper(FutureCallbackData* callback_data, const std::string url, - const std::map& headers) { - NSMutableURLRequest* url_request = [[NSMutableURLRequest alloc] init]; - url_request.URL = [NSURL URLWithString:@(url.c_str())]; - - const char* method = "GET"; - url_request.HTTPMethod = @(method); - - // Default HTTP timeout of 1 minute. - url_request.timeoutInterval = 60; - - // Set all the headers. - for (auto i = headers.begin(); i != headers.end(); ++i) { - [url_request addValue:@(i->second.c_str()) forHTTPHeaderField:@(i->first.c_str())]; - } - - @try { - [[NSURLSession.sharedSession - dataTaskWithRequest:url_request - completionHandler:^(NSData* __nullable data, NSURLResponse* __nullable response, - NSError* __nullable error) { - if(error) { - CompleteLoadImageInternalError(callback_data, kAdErrorCodeNetworkError, - util::NSStringToString([error localizedDescription]).c_str()); - } else { - unsigned char* response_stream = const_cast( - reinterpret_cast([data bytes])); - int response_len = static_cast([data length]); - std::vector img_data = - std::vector(response_stream, response_stream + response_len); - CompleteLoadImageInternalSuccess(callback_data, img_data); - } - }] resume]; - } @catch (NSException* e) { - CompleteLoadImageInternalError(callback_data, kAdErrorCodeInternalError, - util::NSStringToString(e.reason).c_str()); - } - - return; -} - -NativeAdImage::NativeAdImage() { - // Initialize the default constructor with some helpful debug values in the - // case a NativeAdImage makes it to the application in this default state. - internal_ = new NativeAdImageInternal(); - internal_->scale = 0; - internal_->uri = "This NativeAdImage has not been initialized."; - internal_->native_ad_image = nullptr; -} - -NativeAdImage::NativeAdImage(const NativeAdImageInternal& native_ad_image_internal) { - internal_ = new NativeAdImageInternal(); - internal_->native_ad_image = nullptr; - - FIREBASE_ASSERT(native_ad_image_internal.native_ad_image); - - internal_->native_ad_image = native_ad_image_internal.native_ad_image; - GADNativeAdImage* gad_native_image = (GADNativeAdImage*)native_ad_image_internal.native_ad_image; - - FIREBASE_ASSERT(gad_native_image); - - internal_->uri = util::NSStringToString(gad_native_image.imageURL.absoluteString); - internal_->scale = (double)gad_native_image.scale; -} - -NativeAdImage::NativeAdImage(const NativeAdImage& source_native_image) : NativeAdImage() { - // Reuse the assignment operator. - *this = source_native_image; -} - -NativeAdImage::~NativeAdImage() { - FIREBASE_ASSERT(internal_); - - internal_->native_ad_image = nil; - internal_->helper = nil; - internal_->callback_data = nullptr; - - delete internal_; - internal_ = nullptr; -} - -NativeAdImage& NativeAdImage::operator=(const NativeAdImage& r_native_image) { - FIREBASE_ASSERT(r_native_image.internal_); - FIREBASE_ASSERT(internal_); - - NativeAdImageInternal* preexisting_internal = internal_; - { - MutexLock(r_native_image.internal_->mutex); - MutexLock(internal_->mutex); - internal_ = new NativeAdImageInternal(); - - internal_->native_ad_image = r_native_image.internal_->native_ad_image; - internal_->uri = r_native_image.internal_->uri; - internal_->scale = r_native_image.internal_->scale; - } - - // Deleting the internal deletes the mutex within it, so we have to delete - // the internal after the mutex lock leaves scope. - preexisting_internal->native_ad_image = nullptr; - delete preexisting_internal; - - return *this; -} - -/// Gets the native ad image URI. -const std::string& NativeAdImage::image_uri() const { - FIREBASE_ASSERT(internal_); - return internal_->uri; -} - -/// Gets the image scale, which denotes the ratio of pixels to dp. -double NativeAdImage::scale() const { - FIREBASE_ASSERT(internal_); - return internal_->scale; -} - -/// Triggers the auto loaded image and returns an ImageResult future. -Future NativeAdImage::LoadImage() const { - firebase::MutexLock lock(internal_->mutex); - - if (internal_->uri.empty()) { - return CreateAndCompleteFutureWithImageResult( - kNativeAdImageFnLoadImage, - kAdErrorCodeImageUrlMalformed, kImageUrlMalformedErrorMessage, - &internal_->future_data, ImageResult()); - } - - if (internal_->callback_data != nil) { - return CreateAndCompleteFutureWithImageResult( - kNativeAdImageFnLoadImage, - kAdErrorCodeLoadInProgress, kAdLoadInProgressErrorMessage, - &internal_->future_data, ImageResult()); - } - - // Persist a pointer to the callback data so that we can reject duplicate LoadImage requests - // while a download is in progress. - internal_->callback_data = - CreateImageResultFutureCallbackData(kNativeAdImageFnLoadImage, - &internal_->future_data); - - Future future = MakeFuture(&internal_->future_data.future_impl, - internal_->callback_data->future_handle); - - std::map headers; - firebase::gma::DownloadHelper(internal_->callback_data, internal_->uri, headers); - - return future; -} - -Future NativeAdImage::LoadImageLastResult() const { - return static_cast&>( - internal_->future_data.future_impl.LastResult( - kNativeAdImageFnLoadImage)); -} - -} // namespace gma -} // namespace firebase diff --git a/gma/src/ios/native_ad_internal_ios.h b/gma/src/ios/native_ad_internal_ios.h deleted file mode 100644 index f2caae4cc1..0000000000 --- a/gma/src/ios/native_ad_internal_ios.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_IOS_NATIVE_AD_INTERNAL_IOS_H_ -#define FIREBASE_GMA_SRC_IOS_NATIVE_AD_INTERNAL_IOS_H_ - -#ifdef __OBJC__ -#import "gma/src/ios/FADNativeDelegate.h" -#endif // __OBJC__ - -extern "C" { -#include -} // extern "C" - -#include "app/src/include/firebase/internal/mutex.h" -#include "gma/src/common/native_ad_internal.h" - -namespace firebase { -namespace gma { -namespace internal { - -class NativeAdInternalIOS : public NativeAdInternal { - public: - explicit NativeAdInternalIOS(NativeAd* base); - ~NativeAdInternalIOS(); - - Future Initialize(AdParent parent) override; - Future LoadAd(const char* ad_unit_id, - const AdRequest& request) override; - bool is_initialized() const override { return initialized_; } - Future RecordImpression(const Variant& impression_data) override; - Future PerformClick(const Variant& click_data) override; - -#ifdef __OBJC__ - NSDictionary* variantmap_to_nsdictionary(const Variant &variant_data); - void NativeAdDidReceiveAd(GADNativeAd* ad); - void NativeAdDidFailToReceiveAdWithError(NSError* gad_error); -#endif // __OBJC__ - - private: - /// Prevents duplicate invocations of initialize on the Native Ad. - bool initialized_; - - /// Contains information to asynchronously complete the LoadAd Future. - FutureCallbackData* ad_load_callback_data_; - - /// The GADNativeAd object. Declared as an "id" type to avoid - /// referencing an Objective-C class in this header. - id native_ad_; - - /// The publisher-provided view (UIView) that's the parent view of the - /// native ad. Declared as an "id" type to avoid referencing an - /// Objective-C class in this header. - id parent_view_; - - /// The delegate object to listen for callbacks. Declared as an "id" - /// type to avoid referencing an Objective-C++ class in this header. - id native_ad_delegate_; - - /// The GADAdloader object used to load a native ad. Declared as an "id" type - /// to avoid referencing an Objective-C class in this header. A strong - /// reference to the GADAdLoader must be maintained during the ad loading. - id ad_loader_; - - // Mutex to guard against concurrent operations; - Mutex mutex_; -}; - -} // namespace internal -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_IOS_NATIVE_AD_INTERNAL_IOS_H_ diff --git a/gma/src/ios/native_ad_internal_ios.mm b/gma/src/ios/native_ad_internal_ios.mm deleted file mode 100644 index 9723450e6e..0000000000 --- a/gma/src/ios/native_ad_internal_ios.mm +++ /dev/null @@ -1,267 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -extern "C" { -#include -} // extern "C" - -#include "gma/src/ios/native_ad_internal_ios.h" - -#import "gma/src/ios/FADRequest.h" -#import "gma/src/ios/GADNativeAdCpp.h" -#import "gma/src/ios/gma_ios.h" - -#include "app/src/util_ios.h" -#include "gma/src/ios/response_info_ios.h" -#include "gma/src/ios/native_ad_image_ios.h" - -namespace firebase { -namespace gma { -namespace internal { - -NativeAdInternalIOS::NativeAdInternalIOS(NativeAd *base) - : NativeAdInternal(base), - initialized_(false), - ad_load_callback_data_(nil), - native_ad_(nil), - parent_view_(nil), - native_ad_delegate_(nil), - ad_loader_(nil) {} - -NativeAdInternalIOS::~NativeAdInternalIOS() { - firebase::MutexLock lock(mutex_); - native_ad_delegate_ = nil; - native_ad_ = nil; - ad_loader_ = nil; - if (ad_load_callback_data_ != nil) { - delete ad_load_callback_data_; - ad_load_callback_data_ = nil; - } -} - -Future NativeAdInternalIOS::Initialize(AdParent parent) { - firebase::MutexLock lock(mutex_); - const SafeFutureHandle future_handle = - future_data_.future_impl.SafeAlloc(kNativeAdFnInitialize); - Future future = MakeFuture(&future_data_.future_impl, future_handle); - - if (initialized_) { - CompleteFuture(kAdErrorCodeAlreadyInitialized, kAdAlreadyInitializedErrorMessage, future_handle, - &future_data_); - } else { - initialized_ = true; - parent_view_ = (UIView *)parent; - CompleteFuture(kAdErrorCodeNone, nullptr, future_handle, &future_data_); - } - return future; -} - -Future NativeAdInternalIOS::RecordImpression(const Variant& impression_data) { - firebase::MutexLock lock(mutex_); - if (!initialized_) { - return CreateAndCompleteFuture(kNativeAdFnRecordImpression, - kAdErrorCodeUninitialized, - kAdUninitializedErrorMessage, &future_data_); - } - - NSDictionary *impression_payload = variantmap_to_nsdictionary(impression_data); - if (impression_payload == nullptr) { - return CreateAndCompleteFuture( - kNativeAdFnRecordImpression, kAdErrorCodeInvalidArgument, - kUnsupportedVariantTypeErrorMessage, &future_data_); - } - - const SafeFutureHandle future_handle = - future_data_.future_impl.SafeAlloc(kNativeAdFnRecordImpression); - Future future = MakeFuture(&future_data_.future_impl, future_handle); - - dispatch_async(dispatch_get_main_queue(), ^{ - bool recorded = [(GADNativeAd*)native_ad_ recordImpressionWithData:impression_payload]; - if(recorded) { - CompleteFuture(kAdErrorCodeNone, nullptr, future_handle, &future_data_); - } else { - CompleteFuture(kAdErrorCodeInvalidRequest, kRecordImpressionFailureErrorMessage, - future_handle, &future_data_); - } - }); - - return future; -} - -Future NativeAdInternalIOS::PerformClick(const Variant& click_data) { - firebase::MutexLock lock(mutex_); - if (!initialized_) { - return CreateAndCompleteFuture(kNativeAdFnPerformClick, - kAdErrorCodeUninitialized, - kAdUninitializedErrorMessage, &future_data_); - } - - NSDictionary *click_payload = variantmap_to_nsdictionary(click_data); - if (click_payload == nullptr) { - return CreateAndCompleteFuture( - kNativeAdFnPerformClick, kAdErrorCodeInvalidArgument, - kUnsupportedVariantTypeErrorMessage, &future_data_); - } - - const SafeFutureHandle future_handle = - future_data_.future_impl.SafeAlloc(kNativeAdFnPerformClick); - Future future = MakeFuture(&future_data_.future_impl, future_handle); - - dispatch_async(dispatch_get_main_queue(), ^{ - [(GADNativeAd*)native_ad_ performClickWithData:click_payload]; - CompleteFuture(kAdErrorCodeNone, nullptr, future_handle, &future_data_); - }); - - return future; -} - -NSDictionary* NativeAdInternalIOS::variantmap_to_nsdictionary(const Variant &variant_data) { - if (!variant_data.is_map()) { - return nullptr; - } - - NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; - - for (const auto& kvp : variant_data.map()) { - const Variant& key = kvp.first; - const Variant& value = kvp.second; - - if (!key.is_string()) { - return nullptr; - } - - if (value.is_int64()) { - [dict setObject:[NSNumber numberWithLongLong:value.int64_value()] - forKey:@(key.string_value())]; - } else if (value.is_double()) { - [dict setObject:[NSNumber numberWithDouble:value.double_value()] - forKey:@(key.string_value())]; - } else if (value.is_string()) { - [dict setObject:@(value.string_value()) - forKey:@(key.string_value())]; - } else if (value.is_map()) { - NSDictionary *val_dict = variantmap_to_nsdictionary(value); - [dict setObject:val_dict - forKey:@(key.string_value())]; - } else { - // Unsupported value type. - return nullptr; - } - } - - NSDictionary *ret = [dict copy]; - return ret; -} - -Future NativeAdInternalIOS::LoadAd(const char *ad_unit_id, const AdRequest &request) { - firebase::MutexLock lock(mutex_); - FutureCallbackData *callback_data = - CreateAdResultFutureCallbackData(kNativeAdFnLoadAd, &future_data_); - Future future = MakeFuture(&future_data_.future_impl, callback_data->future_handle); - - if (ad_load_callback_data_ != nil) { - CompleteLoadAdInternalError(callback_data, kAdErrorCodeLoadInProgress, - kAdLoadInProgressErrorMessage); - return future; - } - - // Persist a pointer to the callback data so that we may use it after the iOS - // SDK returns the AdResult. - ad_load_callback_data_ = callback_data; - - native_ad_delegate_ = [[FADNativeDelegate alloc] initWithInternalNativeAd:this]; - - // Guard against parameter object destruction before the async operation - // executes (below). - AdRequest local_ad_request = request; - NSString *local_ad_unit_id = @(ad_unit_id); - - dispatch_async(dispatch_get_main_queue(), ^{ - // Create a GADRequest from a gma::AdRequest. - AdErrorCode error_code = kAdErrorCodeNone; - std::string error_message; - GADRequest *ad_request = - GADRequestFromCppAdRequest(local_ad_request, &error_code, &error_message); - if (ad_request == nullptr) { - if (error_code == kAdErrorCodeNone) { - error_code = kAdErrorCodeInternalError; - error_message = kAdCouldNotParseAdRequestErrorMessage; - } - CompleteLoadAdInternalError(ad_load_callback_data_, error_code, error_message.c_str()); - ad_load_callback_data_ = nil; - } else { - GADAdLoader *adLoader = - [[GADAdLoader alloc] initWithAdUnitID:local_ad_unit_id - rootViewController:[parent_view_ window].rootViewController - adTypes:@[ GADAdLoaderAdTypeNative ] - options:nil]; - adLoader.delegate = native_ad_delegate_; - [adLoader loadRequest:ad_request]; - // Have to keep a persistent reference to GADAdLoader until the ad finishes loading. - ad_loader_ = adLoader; - } - }); - - return future; -} - -void NativeAdInternalIOS::NativeAdDidReceiveAd(GADNativeAd *ad) { - firebase::MutexLock lock(mutex_); - ad.delegate = native_ad_delegate_; - native_ad_ = ad; - - NSObject *gad_icon = ad.icon; - if (gad_icon != nil) - { - NativeAdImageInternal icon_internal; - icon_internal.native_ad_image = gad_icon; - GmaInternal::InsertNativeInternalImage(this, icon_internal, "icon", true ); - } - - NSObject *gad_choices_icon = ad.adChoicesIcon; - if (gad_choices_icon != nil) - { - NativeAdImageInternal adchoices_icon_internal; - adchoices_icon_internal.native_ad_image = gad_choices_icon; - GmaInternal::InsertNativeInternalImage(this, adchoices_icon_internal, "adchoices_icon", true ); - } - - NSArray *gad_images = ad.images; - for(NSObject *gad_image in gad_images) - { - NativeAdImageInternal image_internal; - image_internal.native_ad_image = gad_image; - GmaInternal::InsertNativeInternalImage(this, image_internal, "image", false ); - } - - if (ad_load_callback_data_ != nil) { - CompleteLoadAdInternalSuccess(ad_load_callback_data_, ResponseInfoInternal({ad.responseInfo})); - ad_load_callback_data_ = nil; - } -} - -void NativeAdInternalIOS::NativeAdDidFailToReceiveAdWithError(NSError *gad_error) { - firebase::MutexLock lock(mutex_); - FIREBASE_ASSERT(gad_error); - if (ad_load_callback_data_ != nil) { - CompleteAdResultError(ad_load_callback_data_, gad_error, /*is_load_ad_error=*/true); - ad_load_callback_data_ = nil; - } -} - -} // namespace internal -} // namespace gma -} // namespace firebase diff --git a/gma/src/ios/query_info_internal_ios.h b/gma/src/ios/query_info_internal_ios.h deleted file mode 100644 index 3b32e2b4ef..0000000000 --- a/gma/src/ios/query_info_internal_ios.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_IOS_QUERY_INFO_INTERNAL_IOS_H_ -#define FIREBASE_GMA_SRC_IOS_QUERY_INFO_INTERNAL_IOS_H_ - -#ifdef __OBJC__ -#import -#import -#endif // __OBJC__ - -extern "C" { -#include -} // extern "C" - -#include "app/src/include/firebase/internal/mutex.h" -#include "gma/src/common/query_info_internal.h" - -namespace firebase { -namespace gma { -namespace internal { - -class QueryInfoInternalIOS : public QueryInfoInternal { - public: - explicit QueryInfoInternalIOS(QueryInfo* base); - ~QueryInfoInternalIOS(); - - Future Initialize(AdParent parent) override; - Future CreateQueryInfo(AdFormat format, - const AdRequest& request) override; - Future CreateQueryInfoWithAdUnit( - AdFormat format, const AdRequest& request, - const char* ad_unit_id) override; - bool is_initialized() const override { return initialized_; } - -#ifdef __OBJC__ - void CreateQueryInfoSucceeded(GADQueryInfo *query_info); - void CreateQueryInfoFailedWithError(NSError *gad_error); -#endif // __OBJC__ - - private: - /// Prevents duplicate invocations of initialize on the Native Ad. - bool initialized_; - - /// Contains information to asynchronously complete the createQueryInfo - /// Future. - FutureCallbackData* query_info_callback_data_; - - /// The publisher-provided view (UIView) that's the parent view of the ad. - /// Declared as an "id" type to avoid referencing an Objective-C class in this - /// header. - id parent_view_; - - // Mutex to guard against concurrent operations; - Mutex mutex_; -}; - -} // namespace internal -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_IOS_QUERY_INFO_INTERNAL_IOS_H_ diff --git a/gma/src/ios/query_info_internal_ios.mm b/gma/src/ios/query_info_internal_ios.mm deleted file mode 100644 index c9385b1ca1..0000000000 --- a/gma/src/ios/query_info_internal_ios.mm +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -extern "C" { -#include -} // extern "C" - -#include "gma/src/ios/query_info_internal_ios.h" - -#import "gma/src/ios/FADRequest.h" -#import "gma/src/ios/gma_ios.h" - -#include "app/src/util_ios.h" -#include "gma/src/ios/response_info_ios.h" - -namespace firebase { -namespace gma { -namespace internal { - -QueryInfoInternalIOS::QueryInfoInternalIOS(QueryInfo *base) - : QueryInfoInternal(base), - initialized_(false), - query_info_callback_data_(nil), - parent_view_(nil) {} - -QueryInfoInternalIOS::~QueryInfoInternalIOS() { - firebase::MutexLock lock(mutex_); - if (query_info_callback_data_ != nil) { - delete query_info_callback_data_; - query_info_callback_data_ = nil; - } -} - -Future QueryInfoInternalIOS::Initialize(AdParent parent) { - firebase::MutexLock lock(mutex_); - const SafeFutureHandle future_handle = - future_data_.future_impl.SafeAlloc(kQueryInfoFnInitialize); - Future future = MakeFuture(&future_data_.future_impl, future_handle); - - if (initialized_) { - CompleteFuture(kAdErrorCodeAlreadyInitialized, kAdAlreadyInitializedErrorMessage, future_handle, - &future_data_); - } else { - initialized_ = true; - parent_view_ = (UIView *)parent; - CompleteFuture(kAdErrorCodeNone, nullptr, future_handle, &future_data_); - } - return future; -} - -Future QueryInfoInternalIOS::CreateQueryInfo(AdFormat format, - const AdRequest &request) { - firebase::MutexLock lock(mutex_); - FutureCallbackData *callback_data = - CreateQueryInfoResultFutureCallbackData(kQueryInfoFnCreateQueryInfo, &future_data_); - Future future = - MakeFuture(&future_data_.future_impl, callback_data->future_handle); - - if (query_info_callback_data_ != nil) { - CompleteQueryInfoInternalError(callback_data, kAdErrorCodeLoadInProgress, - kAdLoadInProgressErrorMessage); - return future; - } - - // Persist a pointer to the callback data so that we may use it after the iOS - // SDK returns the QueryInfo. - query_info_callback_data_ = callback_data; - - // Guard against parameter object destruction before the async operation - // executes (below). - AdRequest local_ad_request = request; - - dispatch_async(dispatch_get_main_queue(), ^{ - // Create a GADRequest from a gma::AdRequest. - AdErrorCode error_code = kAdErrorCodeNone; - std::string error_message; - GADRequest *ad_request = - GADRequestFromCppAdRequest(local_ad_request, &error_code, &error_message); - if (ad_request == nullptr) { - if (error_code == kAdErrorCodeNone) { - error_code = kAdErrorCodeInternalError; - error_message = kAdCouldNotParseAdRequestErrorMessage; - } - CompleteQueryInfoInternalError(query_info_callback_data_, error_code, error_message.c_str()); - query_info_callback_data_ = nil; - } else { - // Make the create query info request. - [GADQueryInfo - createQueryInfoWithRequest:ad_request - adFormat:MapCPPAdFormatToGADAdformat(format) - completionHandler:^(GADQueryInfo *query_info, NSError *error) // NO LINT - { - if (error) { - CreateQueryInfoFailedWithError(error); - } else { - CreateQueryInfoSucceeded(query_info); - } - }]; - } - }); - - return future; -} - -Future QueryInfoInternalIOS::CreateQueryInfoWithAdUnit(AdFormat format, - const AdRequest &request, - const char *ad_unit_id) { - firebase::MutexLock lock(mutex_); - FutureCallbackData *callback_data = - CreateQueryInfoResultFutureCallbackData(kQueryInfoFnCreateQueryInfoWithAdUnit, &future_data_); - Future future = - MakeFuture(&future_data_.future_impl, callback_data->future_handle); - - if (query_info_callback_data_ != nil) { - CompleteQueryInfoInternalError(callback_data, kAdErrorCodeLoadInProgress, - kAdLoadInProgressErrorMessage); - return future; - } - - // Persist a pointer to the callback data so that we may use it after the iOS - // SDK returns the QueryInfo. - query_info_callback_data_ = callback_data; - - // Guard against parameter object destruction before the async operation - // executes (below). - AdRequest local_ad_request = request; - NSString *local_ad_unit_id = @(ad_unit_id); - - dispatch_async(dispatch_get_main_queue(), ^{ - // Create a GADRequest from a gma::AdRequest. - AdErrorCode error_code = kAdErrorCodeNone; - std::string error_message; - GADRequest *ad_request = - GADRequestFromCppAdRequest(local_ad_request, &error_code, &error_message); - if (ad_request == nullptr) { - if (error_code == kAdErrorCodeNone) { - error_code = kAdErrorCodeInternalError; - error_message = kAdCouldNotParseAdRequestErrorMessage; - } - CompleteQueryInfoInternalError(query_info_callback_data_, error_code, error_message.c_str()); - query_info_callback_data_ = nil; - } else { - // Make the create query info request. - [GADQueryInfo - createQueryInfoWithRequest:ad_request - adFormat:MapCPPAdFormatToGADAdformat(format) - adUnitID:local_ad_unit_id - completionHandler:^(GADQueryInfo *query_info, NSError *error) // NO LINT - { - if (error) { - CreateQueryInfoFailedWithError(error); - } else { - CreateQueryInfoSucceeded(query_info); - } - }]; - } - }); - - return future; -} - -void QueryInfoInternalIOS::CreateQueryInfoSucceeded(GADQueryInfo *query_info) { - firebase::MutexLock lock(mutex_); - - if (query_info_callback_data_ != nil) { - CompleteQueryInfoInternalSuccess(query_info_callback_data_, query_info.query); - query_info_callback_data_ = nil; - } -} - -void QueryInfoInternalIOS::CreateQueryInfoFailedWithError(NSError *gad_error) { - firebase::MutexLock lock(mutex_); - FIREBASE_ASSERT(gad_error); - if (query_info_callback_data_ != nil) { - AdErrorCode error_code = MapAdRequestErrorCodeToCPPErrorCode((GADErrorCode)gad_error.code); - CompleteQueryInfoInternalError(query_info_callback_data_, error_code, - util::NSStringToString(gad_error.localizedDescription).c_str()); - query_info_callback_data_ = nil; - } -} - -} // namespace internal -} // namespace gma -} // namespace firebase diff --git a/gma/src/ios/response_info_ios.h b/gma/src/ios/response_info_ios.h deleted file mode 100644 index 8d424b1b6e..0000000000 --- a/gma/src/ios/response_info_ios.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_IOS_RESPONSE_INFO_IOS_H_ -#define FIREBASE_GMA_SRC_IOS_RESPONSE_INFO_IOS_H_ - -#import - -namespace firebase { -namespace gma { - -struct ResponseInfoInternal { - GADResponseInfo* gad_response_info; -}; - -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_IOS_RESPONSE_INFO_IOS_H_ diff --git a/gma/src/ios/response_info_ios.mm b/gma/src/ios/response_info_ios.mm deleted file mode 100644 index 230a794048..0000000000 --- a/gma/src/ios/response_info_ios.mm +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/ios/response_info_ios.h" - -#include -#include - -#include "gma/src/include/firebase/gma.h" -#include "gma/src/include/firebase/gma/types.h" -#include "gma/src/ios/adapter_response_info_ios.h" - -#include "app/src/include/firebase/internal/mutex.h" -#include "app/src/util_ios.h" -#include "gma/src/ios/ad_error_ios.h" - -namespace firebase { -namespace gma { - -ResponseInfo::ResponseInfo() { to_string_ = "This ResponseInfo has not been initialized."; } - -ResponseInfo::ResponseInfo(const ResponseInfoInternal& response_info_internal) { - if (response_info_internal.gad_response_info == nil) { - return; - } - - response_id_ = - util::NSStringToString(response_info_internal.gad_response_info.responseIdentifier); - - mediation_adapter_class_name_ = - util::NSStringToString(response_info_internal.gad_response_info.loadedAdNetworkResponseInfo.adNetworkClassName); - - NSEnumerator* enumerator = - [response_info_internal.gad_response_info.adNetworkInfoArray objectEnumerator]; - - GADAdNetworkResponseInfo* gad_response_info; - while (gad_response_info = [enumerator nextObject]) { - AdapterResponseInfoInternal adapter_response_info_internal; - adapter_response_info_internal.ad_network_response_info = gad_response_info; - adapter_responses_.push_back(AdapterResponseInfo(adapter_response_info_internal)); - } - - NSString* to_string = - [[NSString alloc] initWithFormat:@"ResponseInfo " - "response_id: %@, mediation_adapter_classname : %@, " - "adapter_response_info: %@", - response_info_internal.gad_response_info.responseIdentifier, - response_info_internal.gad_response_info.loadedAdNetworkResponseInfo.adNetworkClassName, - response_info_internal.gad_response_info.adNetworkInfoArray]; - to_string_ = util::NSStringToString(to_string); -} - -} // namespace gma -} // namespace firebase diff --git a/gma/src/ios/rewarded_ad_internal_ios.h b/gma/src/ios/rewarded_ad_internal_ios.h deleted file mode 100644 index 2c41b607fc..0000000000 --- a/gma/src/ios/rewarded_ad_internal_ios.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_IOS_REWARDED_AD_INTERNAL_IOS_H_ -#define FIREBASE_GMA_SRC_IOS_REWARDED_AD_INTERNAL_IOS_H_ - -#ifdef __OBJC__ -#import "gma/src/ios/FADRewardedAdDelegate.h" -#endif // __OBJC__ - -extern "C" { -#include -} // extern "C" - -#include "app/src/include/firebase/internal/mutex.h" -#include "gma/src/common/rewarded_ad_internal.h" - -namespace firebase { -namespace gma { -namespace internal { - -class RewardedAdInternalIOS : public RewardedAdInternal { - public: - explicit RewardedAdInternalIOS(RewardedAd* base); - ~RewardedAdInternalIOS(); - - Future Initialize(AdParent parent) override; - Future LoadAd(const char* ad_unit_id, - const AdRequest& request) override; - Future Show(UserEarnedRewardListener* listener) override; - bool is_initialized() const override { return initialized_; } - -#ifdef __OBJC__ - void RewardedAdDidReceiveAd(GADRewardedAd* ad); - void RewardedAdDidFailToReceiveAdWithError(NSError* gad_error); - void RewardedAdWillPresentScreen(); - void RewardedAdDidDismissScreen(); -#endif // __OBJC__ - - private: - /// Prevents duplicate invocations of initialize on the Rewarded Ad. - bool initialized_; - - /// Contains information to asynchronously complete the LoadAd Future. - FutureCallbackData* ad_load_callback_data_; - - /// The GADRewardedAd object. Declared as an "id" type to avoid - /// referencing an Objective-C class in this header. - id rewarded_ad_; - - /// The publisher-provided view (UIView) that's the parent view of the - /// rewarded ad. Declared as an "id" type to avoid referencing an - /// Objective-C class in this header. - id parent_view_; - - /// The delegate object to listen for callbacks. Declared as an "id" - /// type to avoid referencing an Objective-C++ class in this header. - id rewarded_ad_delegate_; - - // Mutex to guard against concurrent operations; - Mutex mutex_; -}; - -} // namespace internal -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_IOS_REWARDED_AD_INTERNAL_IOS_H_ diff --git a/gma/src/ios/rewarded_ad_internal_ios.mm b/gma/src/ios/rewarded_ad_internal_ios.mm deleted file mode 100644 index 0a376401de..0000000000 --- a/gma/src/ios/rewarded_ad_internal_ios.mm +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/ios/rewarded_ad_internal_ios.h" - -#import "gma/src/ios/FADRequest.h" -#import "gma/src/ios/gma_ios.h" - -#include "app/src/util_ios.h" -#include "gma/src/ios/response_info_ios.h" - -namespace firebase { -namespace gma { -namespace internal { - -RewardedAdInternalIOS::RewardedAdInternalIOS(RewardedAd *base) - : RewardedAdInternal(base), - initialized_(false), - ad_load_callback_data_(nil), - rewarded_ad_(nil), - parent_view_(nil), - rewarded_ad_delegate_(nil) {} - -RewardedAdInternalIOS::~RewardedAdInternalIOS() { - firebase::MutexLock lock(mutex_); - // Clean up any resources created in RewardedAdInternalIOS. - ((GADRewardedAd *)rewarded_ad_).fullScreenContentDelegate = nil; - rewarded_ad_delegate_ = nil; - rewarded_ad_ = nil; - if (ad_load_callback_data_ != nil) { - delete ad_load_callback_data_; - ad_load_callback_data_ = nil; - } -} - -Future RewardedAdInternalIOS::Initialize(AdParent parent) { - firebase::MutexLock lock(mutex_); - const SafeFutureHandle future_handle = - future_data_.future_impl.SafeAlloc(kRewardedAdFnInitialize); - - if (initialized_) { - CompleteFuture(kAdErrorCodeAlreadyInitialized, kAdAlreadyInitializedErrorMessage, future_handle, - &future_data_); - } else { - initialized_ = true; - parent_view_ = (UIView *)parent; - CompleteFuture(kAdErrorCodeNone, nullptr, future_handle, &future_data_); - } - return MakeFuture(&future_data_.future_impl, future_handle); -} - -Future RewardedAdInternalIOS::LoadAd(const char *ad_unit_id, const AdRequest &request) { - firebase::MutexLock lock(mutex_); - FutureCallbackData *callback_data = - CreateAdResultFutureCallbackData(kRewardedAdFnLoadAd, &future_data_); - SafeFutureHandle future_handle = callback_data->future_handle; - - if (ad_load_callback_data_ != nil) { - CompleteLoadAdInternalError(callback_data, kAdErrorCodeLoadInProgress, - kAdLoadInProgressErrorMessage); - return MakeFuture(&future_data_.future_impl, future_handle); - } - - // Persist a pointer to the callback data so that we may use it after the iOS - // SDK returns the AdResult. - ad_load_callback_data_ = callback_data; - - rewarded_ad_delegate_ = [[FADRewardedAdDelegate alloc] initWithInternalRewardedAd:this]; - - // Guard against parameter object destruction before the async operation - // executes (below). - AdRequest local_ad_request = request; - NSString *local_ad_unit_id = @(ad_unit_id); - - dispatch_async(dispatch_get_main_queue(), ^{ - // Create a GADRequest from a gma::AdRequest. - AdErrorCode error_code = kAdErrorCodeNone; - std::string error_message; - GADRequest *ad_request = - GADRequestFromCppAdRequest(local_ad_request, &error_code, &error_message); - if (ad_request == nullptr) { - if (error_code == kAdErrorCodeNone) { - error_code = kAdErrorCodeInternalError; - error_message = kAdCouldNotParseAdRequestErrorMessage; - } - CompleteLoadAdInternalError(ad_load_callback_data_, error_code, error_message.c_str()); - ad_load_callback_data_ = nil; - } else { - // Make the rewarded ad request. - [GADRewardedAd loadWithAdUnitID:local_ad_unit_id - request:ad_request - completionHandler:^(GADRewardedAd *ad, NSError *error) { - if (error) { - RewardedAdDidFailToReceiveAdWithError(error); - } else { - RewardedAdDidReceiveAd(ad); - } - }]; - } - }); - - return MakeFuture(&future_data_.future_impl, future_handle); -} - -Future RewardedAdInternalIOS::Show(UserEarnedRewardListener *listener) { - firebase::MutexLock lock(mutex_); - const firebase::SafeFutureHandle handle = - future_data_.future_impl.SafeAlloc(kRewardedAdFnShow); - user_earned_reward_listener_ = listener; - - dispatch_async(dispatch_get_main_queue(), ^{ - AdErrorCode error_code = kAdErrorCodeLoadInProgress; - const char *error_message = kAdLoadInProgressErrorMessage; - if (rewarded_ad_ == nil) { - error_code = kAdErrorCodeUninitialized; - error_message = kAdUninitializedErrorMessage; - } else { - [rewarded_ad_ presentFromRootViewController:[parent_view_ window].rootViewController - userDidEarnRewardHandler:^{ - GADAdReward *reward = ((GADRewardedAd *)rewarded_ad_).adReward; - NotifyListenerOfUserEarnedReward(util::NSStringToString(reward.type), - reward.amount.integerValue); - }]; - error_code = kAdErrorCodeNone; - error_message = nullptr; - } - CompleteFuture(error_code, error_message, handle, &future_data_); - }); - return MakeFuture(&future_data_.future_impl, handle); -} - -void RewardedAdInternalIOS::RewardedAdDidReceiveAd(GADRewardedAd *ad) { - firebase::MutexLock lock(mutex_); - rewarded_ad_ = ad; - ad.fullScreenContentDelegate = rewarded_ad_delegate_; - ad.paidEventHandler = ^void(GADAdValue *_Nonnull adValue) { - NotifyListenerOfPaidEvent(firebase::gma::ConvertGADAdValueToCppAdValue(adValue)); - }; - - if (ad_load_callback_data_ != nil) { - CompleteLoadAdInternalSuccess(ad_load_callback_data_, ResponseInfoInternal({ad.responseInfo})); - ad_load_callback_data_ = nil; - } -} - -void RewardedAdInternalIOS::RewardedAdDidFailToReceiveAdWithError(NSError *gad_error) { - firebase::MutexLock lock(mutex_); - FIREBASE_ASSERT(gad_error); - if (ad_load_callback_data_ != nil) { - CompleteAdResultError(ad_load_callback_data_, gad_error, - /*is_load_ad_error=*/true); - ad_load_callback_data_ = nil; - } -} - -} // namespace internal -} // namespace gma -} // namespace firebase diff --git a/gma/src/ios/ump/consent_info_internal_ios.h b/gma/src/ios/ump/consent_info_internal_ios.h deleted file mode 100644 index 6e860edb40..0000000000 --- a/gma/src/ios/ump/consent_info_internal_ios.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_IOS_UMP_CONSENT_INFO_INTERNAL_IOS_H_ -#define FIREBASE_GMA_SRC_IOS_UMP_CONSENT_INFO_INTERNAL_IOS_H_ - -#include - -#include "firebase/internal/mutex.h" -#include "gma/src/common/ump/consent_info_internal.h" - -namespace firebase { -namespace gma { -namespace ump { -namespace internal { - -class ConsentInfoInternalIos : public ConsentInfoInternal { - public: - ConsentInfoInternalIos(); - ~ConsentInfoInternalIos() override; - - ConsentStatus GetConsentStatus() override; - Future RequestConsentInfoUpdate( - const ConsentRequestParameters& params) override; - - ConsentFormStatus GetConsentFormStatus() override; - Future LoadConsentForm() override; - Future ShowConsentForm(FormParent parent) override; - - Future LoadAndShowConsentFormIfRequired(FormParent parent) override; - - PrivacyOptionsRequirementStatus GetPrivacyOptionsRequirementStatus() override; - Future ShowPrivacyOptionsForm(FormParent parent) override; - - bool CanRequestAds() override; - - void Reset() override; - - private: - static ConsentInfoInternalIos* s_instance; - static firebase::Mutex s_instance_mutex; - static unsigned int s_instance_tag; - - void SetLoadedForm(UMPConsentForm *form) { - loaded_form_ = form; - } - - UMPConsentForm *loaded_form_; -}; - -} // namespace internal -} // namespace ump -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_IOS_UMP_CONSENT_INFO_INTERNAL_IOS_H_ diff --git a/gma/src/ios/ump/consent_info_internal_ios.mm b/gma/src/ios/ump/consent_info_internal_ios.mm deleted file mode 100644 index c4ea199eca..0000000000 --- a/gma/src/ios/ump/consent_info_internal_ios.mm +++ /dev/null @@ -1,369 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/ios/ump/consent_info_internal_ios.h" - -#include "app/src/assert.h" -#include "app/src/thread.h" -#include "app/src/util_ios.h" - -namespace firebase { -namespace gma { -namespace ump { -namespace internal { - -ConsentInfoInternalIos* ConsentInfoInternalIos::s_instance = nullptr; -firebase::Mutex ConsentInfoInternalIos::s_instance_mutex; -unsigned int ConsentInfoInternalIos::s_instance_tag = 0; - -// This explicitly implements the constructor for the outer class, -// ConsentInfoInternal. -ConsentInfoInternal* ConsentInfoInternal::CreateInstance() { return new ConsentInfoInternalIos(); } - -ConsentInfoInternalIos::ConsentInfoInternalIos() : loaded_form_(nil) { - MutexLock lock(s_instance_mutex); - FIREBASE_ASSERT(s_instance == nullptr); - s_instance = this; - // Increment this with each created instance, to ensure that any leftover - // callbacks don't run if a new instance is created. - s_instance_tag++; -} - -ConsentInfoInternalIos::~ConsentInfoInternalIos() { - MutexLock lock(s_instance_mutex); - s_instance = nullptr; -} - -static ConsentRequestError CppRequestErrorFromIosRequestError(NSInteger code) { - switch (code) { - case UMPRequestErrorCodeInternal: - return kConsentRequestErrorInternal; - case UMPRequestErrorCodeInvalidAppID: - return kConsentRequestErrorInvalidAppId; - case UMPRequestErrorCodeMisconfiguration: - return kConsentRequestErrorMisconfiguration; - case UMPRequestErrorCodeNetwork: - return kConsentRequestErrorNetwork; - default: - LogWarning("GMA: Unknown UMPRequestErrorCode returned by UMP iOS SDK: %d", (int)code); - return kConsentRequestErrorUnknown; - } -} - -static ConsentFormError CppFormErrorFromIosFormError(NSInteger code) { - switch (code) { - case UMPFormErrorCodeInternal: - return kConsentFormErrorInternal; - case UMPFormErrorCodeAlreadyUsed: - return kConsentFormErrorAlreadyUsed; - case UMPFormErrorCodeUnavailable: - return kConsentFormErrorUnavailable; - case UMPFormErrorCodeTimeout: - return kConsentFormErrorTimeout; - case UMPFormErrorCodeInvalidViewController: - return kConsentFormErrorInvalidOperation; - default: - LogWarning("GMA: Unknown UMPFormErrorCode returned by UMP iOS SDK: %d", (int)code); - return kConsentFormErrorUnknown; - } -} - -Future ConsentInfoInternalIos::RequestConsentInfoUpdate( - const ConsentRequestParameters& params) { - MutexLock lock(s_instance_mutex); - if (RequestConsentInfoUpdateLastResult().status() == kFutureStatusPending) { - // This operation is already in progress. - // Return a future with an error - this will not override the Fn entry. - SafeFutureHandle error_handle = CreateFuture(); - CompleteFuture(error_handle, kConsentRequestErrorOperationInProgress); - return MakeFuture(futures(), error_handle); - } - - SafeFutureHandle handle = CreateFuture(kConsentInfoFnRequestConsentInfoUpdate); - - UMPRequestParameters* ios_parameters = [[UMPRequestParameters alloc] init]; - ios_parameters.tagForUnderAgeOfConsent = params.tag_for_under_age_of_consent ? YES : NO; - UMPDebugSettings* ios_debug_settings = [[UMPDebugSettings alloc] init]; - bool has_debug_settings = false; - - switch (params.debug_settings.debug_geography) { - case kConsentDebugGeographyEEA: - ios_debug_settings.geography = UMPDebugGeographyEEA; - has_debug_settings = true; - break; - case kConsentDebugGeographyNonEEA: - ios_debug_settings.geography = UMPDebugGeographyNotEEA; - has_debug_settings = true; - break; - case kConsentDebugGeographyDisabled: - ios_debug_settings.geography = UMPDebugGeographyDisabled; - break; - } - if (params.debug_settings.debug_device_ids.size() > 0) { - ios_debug_settings.testDeviceIdentifiers = - firebase::util::StringVectorToNSMutableArray(params.debug_settings.debug_device_ids); - has_debug_settings = true; - } - if (has_debug_settings) { - ios_parameters.debugSettings = ios_debug_settings; - } - - unsigned int callback_instance_tag; - callback_instance_tag = s_instance_tag; - - util::DispatchAsyncSafeMainQueue(^{ - MutexLock lock(s_instance_mutex); - if (!s_instance || s_instance_tag != callback_instance_tag) { - // Instance changed or was invalidated, don't call the iOS method any more. - return; - } - [UMPConsentInformation.sharedInstance - requestConsentInfoUpdateWithParameters:ios_parameters - completionHandler:^(NSError* _Nullable error) { - MutexLock lock(s_instance_mutex); - if (s_instance && s_instance_tag == callback_instance_tag) { - if (!error) { - CompleteFuture(handle, kConsentRequestSuccess); - } else { - CompleteFuture(handle, - CppRequestErrorFromIosRequestError(error.code), - error.localizedDescription.UTF8String); - } - } - }]; - }); - - return MakeFuture(futures(), handle); -} - -ConsentStatus ConsentInfoInternalIos::GetConsentStatus() { - UMPConsentStatus ios_status = UMPConsentInformation.sharedInstance.consentStatus; - switch (ios_status) { - case UMPConsentStatusNotRequired: - return kConsentStatusNotRequired; - case UMPConsentStatusRequired: - return kConsentStatusRequired; - case UMPConsentStatusObtained: - return kConsentStatusObtained; - case UMPConsentStatusUnknown: - return kConsentStatusUnknown; - default: - LogWarning("GMA: Unknown UMPConsentStatus returned by UMP iOS SDK: %d", (int)ios_status); - return kConsentStatusUnknown; - } -} - -ConsentFormStatus ConsentInfoInternalIos::GetConsentFormStatus() { - UMPFormStatus ios_status = UMPConsentInformation.sharedInstance.formStatus; - switch (ios_status) { - case UMPFormStatusAvailable: - return kConsentFormStatusAvailable; - case UMPFormStatusUnavailable: - return kConsentFormStatusUnavailable; - case UMPFormStatusUnknown: - return kConsentFormStatusUnknown; - default: - LogWarning("GMA: Unknown UMPFormConsentStatus returned by UMP iOS SDK: %d", (int)ios_status); - return kConsentFormStatusUnknown; - } -} - -Future ConsentInfoInternalIos::LoadConsentForm() { - MutexLock lock(s_instance_mutex); - if (LoadConsentFormLastResult().status() == kFutureStatusPending) { - // This operation is already in progress. - // Return a future with an error - this will not override the Fn entry. - SafeFutureHandle error_handle = CreateFuture(); - CompleteFuture(error_handle, kConsentFormErrorOperationInProgress); - return MakeFuture(futures(), error_handle); - } - - SafeFutureHandle handle = CreateFuture(kConsentInfoFnLoadConsentForm); - loaded_form_ = nil; - - unsigned int callback_instance_tag; - callback_instance_tag = s_instance_tag; - - util::DispatchAsyncSafeMainQueue(^{ - MutexLock lock(s_instance_mutex); - if (!s_instance || s_instance_tag != callback_instance_tag) { - // Instance changed or was invalidated, don't call the iOS method any more. - return; - } - [UMPConsentForm - loadWithCompletionHandler:^(UMPConsentForm* _Nullable form, NSError* _Nullable error) { - MutexLock lock(s_instance_mutex); - if (s_instance && s_instance_tag == callback_instance_tag) { - if (form) { - SetLoadedForm(form); - CompleteFuture(handle, kConsentFormSuccess, "Success"); - } else if (error) { - CompleteFuture(handle, CppFormErrorFromIosFormError(error.code), - error.localizedDescription.UTF8String); - } else { - CompleteFuture(handle, kConsentFormErrorUnknown, "An unknown error occurred."); - } - } - }]; - }); - return MakeFuture(futures(), handle); -} - -Future ConsentInfoInternalIos::ShowConsentForm(FormParent parent) { - MutexLock lock(s_instance_mutex); - if (ShowConsentFormLastResult().status() == kFutureStatusPending) { - // This operation is already in progress. - // Return a future with an error - this will not override the Fn entry. - SafeFutureHandle error_handle = CreateFuture(); - CompleteFuture(error_handle, kConsentFormErrorOperationInProgress); - return MakeFuture(futures(), error_handle); - } - SafeFutureHandle handle = CreateFuture(kConsentInfoFnShowConsentForm); - - if (!loaded_form_) { - CompleteFuture(handle, kConsentFormErrorInvalidOperation, - "You must call LoadConsentForm() prior to calling ShowConsentForm()."); - } else { - unsigned int callback_instance_tag; - callback_instance_tag = s_instance_tag; - - util::DispatchAsyncSafeMainQueue(^{ - MutexLock lock(s_instance_mutex); - if (!s_instance || s_instance_tag != callback_instance_tag) { - // Instance changed or was invalidated, don't call the iOS method any more. - return; - } - [loaded_form_ presentFromViewController:parent - completionHandler:^(NSError* _Nullable error) { - MutexLock lock(s_instance_mutex); - if (s_instance && s_instance_tag == callback_instance_tag) { - if (!error) { - CompleteFuture(handle, kConsentRequestSuccess); - } else { - CompleteFuture(handle, CppFormErrorFromIosFormError(error.code), - error.localizedDescription.UTF8String); - } - } - }]; - }); - } - return MakeFuture(futures(), handle); -} - -Future ConsentInfoInternalIos::LoadAndShowConsentFormIfRequired(FormParent parent) { - MutexLock lock(s_instance_mutex); - if (LoadAndShowConsentFormIfRequiredLastResult().status() == kFutureStatusPending) { - // This operation is already in progress. - // Return a future with an error - this will not override the Fn entry. - SafeFutureHandle error_handle = CreateFuture(); - CompleteFuture(error_handle, kConsentFormErrorOperationInProgress); - return MakeFuture(futures(), error_handle); - } - - SafeFutureHandle handle = CreateFuture(kConsentInfoFnLoadAndShowConsentFormIfRequired); - - unsigned int callback_instance_tag; - callback_instance_tag = s_instance_tag; - - util::DispatchAsyncSafeMainQueue(^{ - MutexLock lock(s_instance_mutex); - if (!s_instance || s_instance_tag != callback_instance_tag) { - // Instance changed or was invalidated, don't call the iOS method any more. - return; - } - [UMPConsentForm - loadAndPresentIfRequiredFromViewController:parent - completionHandler:^(NSError* _Nullable error) { - MutexLock lock(s_instance_mutex); - if (s_instance && s_instance_tag == callback_instance_tag) { - if (!error) { - CompleteFuture(handle, kConsentRequestSuccess); - } else { - CompleteFuture(handle, - CppFormErrorFromIosFormError(error.code), - error.localizedDescription.UTF8String); - } - } - }]; - }); - return MakeFuture(futures(), handle); -} - -PrivacyOptionsRequirementStatus ConsentInfoInternalIos::GetPrivacyOptionsRequirementStatus() { - UMPPrivacyOptionsRequirementStatus ios_status = - UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus; - switch (ios_status) { - case UMPPrivacyOptionsRequirementStatusRequired: - return kPrivacyOptionsRequirementStatusRequired; - case UMPPrivacyOptionsRequirementStatusNotRequired: - return kPrivacyOptionsRequirementStatusNotRequired; - case UMPPrivacyOptionsRequirementStatusUnknown: - return kPrivacyOptionsRequirementStatusUnknown; - default: - LogWarning("GMA: Unknown UMPPrivacyOptionsRequirementStatus returned by UMP iOS SDK: %d", - (int)ios_status); - return kPrivacyOptionsRequirementStatusUnknown; - } -} - -Future ConsentInfoInternalIos::ShowPrivacyOptionsForm(FormParent parent) { - MutexLock lock(s_instance_mutex); - if (ShowPrivacyOptionsFormLastResult().status() == kFutureStatusPending) { - // This operation is already in progress. - // Return a future with an error - this will not override the Fn entry. - SafeFutureHandle error_handle = CreateFuture(); - CompleteFuture(error_handle, kConsentFormErrorOperationInProgress); - return MakeFuture(futures(), error_handle); - } - - SafeFutureHandle handle = CreateFuture(kConsentInfoFnShowPrivacyOptionsForm); - unsigned int callback_instance_tag; - callback_instance_tag = s_instance_tag; - - util::DispatchAsyncSafeMainQueue(^{ - MutexLock lock(s_instance_mutex); - if (!s_instance || s_instance_tag != callback_instance_tag) { - // Instance changed or was invalidated, don't call the iOS method any more. - return; - } - [UMPConsentForm - presentPrivacyOptionsFormFromViewController:parent - completionHandler:^(NSError* _Nullable error) { - MutexLock lock(s_instance_mutex); - if (s_instance && s_instance_tag == callback_instance_tag) { - if (!error) { - CompleteFuture(handle, kConsentRequestSuccess); - } else { - CompleteFuture(handle, - CppFormErrorFromIosFormError(error.code), - error.localizedDescription.UTF8String); - } - } - }]; - }); - return MakeFuture(futures(), handle); -} - -bool ConsentInfoInternalIos::CanRequestAds() { - return (UMPConsentInformation.sharedInstance.canRequestAds == YES ? true : false); -} - -void ConsentInfoInternalIos::Reset() { [UMPConsentInformation.sharedInstance reset]; } - -} // namespace internal -} // namespace ump -} // namespace gma -} // namespace firebase diff --git a/gma/src/stub/ad_error_stub.cc b/gma/src/stub/ad_error_stub.cc deleted file mode 100644 index 2508c46b5c..0000000000 --- a/gma/src/stub/ad_error_stub.cc +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "gma/src/common/ad_error_internal.h" -#include "gma/src/include/firebase/gma.h" -#include "gma/src/include/firebase/gma/types.h" - -namespace firebase { -namespace gma { - -const char* const AdError::kUndefinedDomain = "undefined"; - -AdError::AdError() {} - -AdError::AdError(const AdErrorInternal& ad_error_internal) {} - -AdError::AdError(const AdError& ad_error) : AdError() {} - -AdError::~AdError() {} - -AdError& AdError::operator=(const AdError& obj) { return *this; } - -std::unique_ptr AdError::GetCause() const { - return std::unique_ptr(nullptr); -} - -/// Gets the error's code. -AdErrorCode AdError::code() const { return kAdErrorCodeNone; } - -/// Gets the domain of the error. -const std::string& AdError::domain() const { - static const std::string empty; - return empty; -} - -/// Gets the message describing the error. -const std::string& AdError::message() const { - static const std::string empty; - return empty; -} - -/// Gets the ResponseInfo if an loadAd error occurred, with a collection of -/// information from each adapter. -const ResponseInfo& AdError::response_info() const { - static const ResponseInfo empty; - return empty; -} - -/// Returns a log friendly string version of this object. -const std::string& AdError::ToString() const { - static const std::string empty; - return empty; -} - -} // namespace gma -} // namespace firebase diff --git a/gma/src/stub/ad_view_internal_stub.h b/gma/src/stub/ad_view_internal_stub.h deleted file mode 100644 index 7ef509a20b..0000000000 --- a/gma/src/stub/ad_view_internal_stub.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_STUB_AD_VIEW_INTERNAL_STUB_H_ -#define FIREBASE_GMA_SRC_STUB_AD_VIEW_INTERNAL_STUB_H_ - -#include "gma/src/common/ad_view_internal.h" - -namespace firebase { -namespace gma { -namespace internal { - -/// Stub version of AdViewInternal, for use on desktop platforms. GMA is -/// forbidden on desktop, so this version creates and immediately completes the -/// Future for each method. -class AdViewInternalStub : public AdViewInternal { - public: - explicit AdViewInternalStub(AdView* base) : AdViewInternal(base) {} - - ~AdViewInternalStub() override {} - - Future Initialize(AdParent parent, const char* ad_unit_id, - const AdSize& size) override { - return CreateAndCompleteFutureStub(kAdViewFnInitialize); - } - - Future LoadAd(const AdRequest& request) override { - return CreateAndCompleteAdResultFutureStub(kAdViewFnLoadAd); - } - - BoundingBox bounding_box() const override { return BoundingBox(); } - - Future SetPosition(int x, int y) override { - return CreateAndCompleteFutureStub(kAdViewFnSetPosition); - } - - Future SetPosition(AdView::Position position) override { - return CreateAndCompleteFutureStub(kAdViewFnSetPosition); - } - - Future Hide() override { - return CreateAndCompleteFutureStub(kAdViewFnHide); - } - - Future Show() override { - return CreateAndCompleteFutureStub(kAdViewFnShow); - } - - Future Pause() override { - return CreateAndCompleteFutureStub(kAdViewFnPause); - } - - Future Resume() override { - return CreateAndCompleteFutureStub(kAdViewFnResume); - } - - Future Destroy() override { - return CreateAndCompleteFutureStub(kAdViewFnDestroy); - } - - bool is_initialized() const override { return true; } - - AdSize ad_size() const { return AdSize(0, 0); } - - private: - Future CreateAndCompleteFutureStub(AdViewFn fn) { - return CreateAndCompleteFuture(fn, kAdErrorCodeNone, nullptr, - &future_data_); - } - - Future CreateAndCompleteAdResultFutureStub(AdViewFn fn) { - return CreateAndCompleteFutureWithResult(fn, kAdErrorCodeNone, nullptr, - &future_data_, AdResult()); - } -}; - -} // namespace internal -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_STUB_AD_VIEW_INTERNAL_STUB_H_ diff --git a/gma/src/stub/adapter_response_info_stub.cc b/gma/src/stub/adapter_response_info_stub.cc deleted file mode 100644 index 5ce5fdc351..0000000000 --- a/gma/src/stub/adapter_response_info_stub.cc +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "gma/src/include/firebase/gma.h" -#include "gma/src/include/firebase/gma/types.h" - -namespace firebase { -namespace gma { - -struct AdapterResponseInfoInternal { - int stub; -}; - -AdapterResponseInfo::AdapterResponseInfo( - const AdapterResponseInfoInternal& internal) {} - -} // namespace gma -} // namespace firebase diff --git a/gma/src/stub/gma_stub.cc b/gma/src/stub/gma_stub.cc deleted file mode 100644 index f0c9ea7890..0000000000 --- a/gma/src/stub/gma_stub.cc +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "app/src/include/firebase/app.h" -#include "app/src/include/firebase/future.h" -#include "app/src/include/firebase/internal/mutex.h" -#include "app/src/include/firebase/version.h" -#include "gma/src/common/gma_common.h" -#include "gma/src/include/firebase/gma.h" - -namespace firebase { -namespace gma { - -DEFINE_FIREBASE_VERSION_STRING(FirebaseGma); - -static const firebase::App* g_app = nullptr; -static bool g_initialized = false; - -// Constants representing each GMA function that returns a Future. -enum GmaFn { - kGmaFnInitialize, - kGmaFnCount, -}; - -static ReferenceCountedFutureImpl* g_future_impl = nullptr; - -static Future CreateAndCompleteInitializeStub() { - FIREBASE_ASSERT(g_future_impl); - - // Return an AdapterInitializationStatus with one placeholder adapter. - SafeFutureHandle handle = - g_future_impl->SafeAlloc(kGmaFnInitialize); - std::map adapter_map; - adapter_map["stub"] = - GmaInternal::CreateAdapterStatus("stub adapter", true, 100); - - AdapterInitializationStatus adapter_init_status = - GmaInternal::CreateAdapterInitializationStatus(adapter_map); - g_future_impl->CompleteWithResult(handle, 0, "", adapter_init_status); - return MakeFuture(g_future_impl, handle); -} - -Future Initialize(const ::firebase::App& app, - InitResult* init_result_out) { - FIREBASE_ASSERT(!g_initialized); - g_future_impl = new ReferenceCountedFutureImpl(kGmaFnCount); - - (void)app; - g_app = &app; - g_initialized = true; - RegisterTerminateOnDefaultAppDestroy(); - if (init_result_out) { - *init_result_out = kInitResultSuccess; - } - return CreateAndCompleteInitializeStub(); -} - -Future Initialize(InitResult* init_result_out) { - FIREBASE_ASSERT(!g_initialized); - g_future_impl = new ReferenceCountedFutureImpl(kGmaFnCount); - - g_initialized = true; - g_app = nullptr; - RegisterTerminateOnDefaultAppDestroy(); - if (init_result_out) { - *init_result_out = kInitResultSuccess; - } - return CreateAndCompleteInitializeStub(); -} - -Future InitializeLastResult() { - return g_future_impl - ? static_cast&>( - g_future_impl->LastResult(kGmaFnInitialize)) - : Future(); -} - -AdapterInitializationStatus GetInitializationStatus() { - Future result = InitializeLastResult(); - if (result.status() != firebase::kFutureStatusComplete) { - return GmaInternal::CreateAdapterInitializationStatus({}); - } else { - return *result.result(); - } -} - -void DisableSDKCrashReporting() {} - -void DisableMediationInitialization() {} - -bool IsInitialized() { return g_initialized; } - -void SetRequestConfiguration( - const RequestConfiguration& request_configuration) {} - -RequestConfiguration GetRequestConfiguration() { - return RequestConfiguration(); -} - -void OpenAdInspector(AdParent parent, AdInspectorClosedListener* listener) {} -void SetIsSameAppKeyEnabled(bool is_enabled) {} - -void Terminate() { - FIREBASE_ASSERT(g_initialized); - - delete g_future_impl; - g_future_impl = nullptr; - - UnregisterTerminateOnDefaultAppDestroy(); - DestroyCleanupNotifier(); - g_initialized = false; - g_app = nullptr; -} - -const ::firebase::App* GetApp() { return g_app; } - -} // namespace gma -} // namespace firebase diff --git a/gma/src/stub/interstitial_ad_internal_stub.h b/gma/src/stub/interstitial_ad_internal_stub.h deleted file mode 100644 index 96c4882fb7..0000000000 --- a/gma/src/stub/interstitial_ad_internal_stub.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_STUB_INTERSTITIAL_AD_INTERNAL_STUB_H_ -#define FIREBASE_GMA_SRC_STUB_INTERSTITIAL_AD_INTERNAL_STUB_H_ - -#include "gma/src/common/interstitial_ad_internal.h" - -namespace firebase { -namespace gma { -namespace internal { - -/// Stub version of InterstitialAdInternal, for use on desktop platforms. GMA -/// is forbidden on desktop, so this version creates and immediately completes -/// the Future for each method. -class InterstitialAdInternalStub : public InterstitialAdInternal { - public: - explicit InterstitialAdInternalStub(InterstitialAd* base) - : InterstitialAdInternal(base) {} - - ~InterstitialAdInternalStub() override {} - - Future Initialize(AdParent parent) override { - return CreateAndCompleteFutureStub(kInterstitialAdFnInitialize); - } - - Future LoadAd(const char* ad_unit_id, - const AdRequest& request) override { - return CreateAndCompleteAdResultFutureStub(kInterstitialAdFnLoadAd); - } - - Future Show() override { - return CreateAndCompleteFutureStub(kInterstitialAdFnShow); - } - - bool is_initialized() const override { return true; } - - private: - Future CreateAndCompleteFutureStub(InterstitialAdFn fn) { - CreateAndCompleteFuture(fn, kAdErrorCodeNone, nullptr, &future_data_); - return GetLastResult(fn); - } - - Future CreateAndCompleteAdResultFutureStub(InterstitialAdFn fn) { - return CreateAndCompleteFutureWithResult(fn, kAdErrorCodeNone, nullptr, - &future_data_, AdResult()); - } -}; - -} // namespace internal -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_STUB_INTERSTITIAL_AD_INTERNAL_STUB_H_ diff --git a/gma/src/stub/native_ad_image_stub.cc b/gma/src/stub/native_ad_image_stub.cc deleted file mode 100644 index 7b70e60e1d..0000000000 --- a/gma/src/stub/native_ad_image_stub.cc +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "gma/src/common/native_ad_image_internal.h" -#include "gma/src/include/firebase/gma.h" -#include "gma/src/include/firebase/gma/internal/native_ad.h" - -namespace firebase { -namespace gma { - -NativeAdImage::NativeAdImage() {} - -NativeAdImage::NativeAdImage( - const NativeAdImageInternal& native_ad_image_internal) {} - -NativeAdImage::~NativeAdImage() {} - -NativeAdImage::NativeAdImage(const NativeAdImage& ad_image) : NativeAdImage() {} - -NativeAdImage& NativeAdImage::operator=(const NativeAdImage& obj) { - return *this; -} - -/// Gets the image scale, which denotes the ratio of pixels to dp. -double NativeAdImage::scale() const { - static const double empty = 0.0; - return empty; -} - -/// Gets the native ad image URI. -const std::string& NativeAdImage::image_uri() const { - static const std::string empty; - return empty; -} - -Future NativeAdImage::LoadImage() const { - return CreateAndCompleteFutureWithImageResult( - kNativeAdImageFnLoadImage, kAdErrorCodeNone, nullptr, - &internal_->future_data, ImageResult()); -} - -Future NativeAdImage::LoadImageLastResult() const { - return CreateAndCompleteFutureWithImageResult( - kNativeAdImageFnLoadImage, kAdErrorCodeNone, nullptr, - &internal_->future_data, ImageResult()); -} - -} // namespace gma -} // namespace firebase diff --git a/gma/src/stub/native_ad_internal_stub.h b/gma/src/stub/native_ad_internal_stub.h deleted file mode 100644 index 4aa7c92b7b..0000000000 --- a/gma/src/stub/native_ad_internal_stub.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_STUB_NATIVE_AD_INTERNAL_STUB_H_ -#define FIREBASE_GMA_SRC_STUB_NATIVE_AD_INTERNAL_STUB_H_ - -#include "gma/src/common/native_ad_internal.h" - -namespace firebase { -namespace gma { -namespace internal { - -/// Stub version of NativeAdInternal, for use on desktop platforms. GMA -/// is forbidden on desktop, so this version creates and immediately completes -/// the Future for each method. -class NativeAdInternalStub : public NativeAdInternal { - public: - explicit NativeAdInternalStub(NativeAd* base) : NativeAdInternal(base) {} - - ~NativeAdInternalStub() override {} - - Future Initialize(AdParent parent) override { - return CreateAndCompleteFutureStub(kNativeAdFnInitialize); - } - - Future LoadAd(const char* ad_unit_id, - const AdRequest& request) override { - return CreateAndCompleteAdResultFutureStub(kNativeAdFnLoadAd); - } - - Future RecordImpression(const Variant& impression_data) override { - return CreateAndCompleteFutureStub(kNativeAdFnRecordImpression); - } - - Future PerformClick(const Variant& click_data) override { - return CreateAndCompleteFutureStub(kNativeAdFnPerformClick); - } - - bool is_initialized() const override { return true; } - - private: - Future CreateAndCompleteFutureStub(NativeAdFn fn) { - CreateAndCompleteFuture(fn, kAdErrorCodeNone, nullptr, &future_data_); - return GetLastResult(fn); - } - - Future CreateAndCompleteAdResultFutureStub(NativeAdFn fn) { - return CreateAndCompleteFutureWithResult(fn, kAdErrorCodeNone, nullptr, - &future_data_, AdResult()); - } -}; - -} // namespace internal -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_STUB_NATIVE_AD_INTERNAL_STUB_H_ diff --git a/gma/src/stub/query_info_internal_stub.h b/gma/src/stub/query_info_internal_stub.h deleted file mode 100644 index 81c6669f36..0000000000 --- a/gma/src/stub/query_info_internal_stub.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_STUB_QUERY_INFO_INTERNAL_STUB_H_ -#define FIREBASE_GMA_SRC_STUB_QUERY_INFO_INTERNAL_STUB_H_ - -#include "gma/src/common/query_info_internal.h" - -namespace firebase { -namespace gma { -namespace internal { - -/// Stub version of QueryInfoInternal, for use on desktop platforms. GMA -/// is forbidden on desktop, so this version creates and immediately completes -/// the Future for each method. -class QueryInfoInternalStub : public QueryInfoInternal { - public: - explicit QueryInfoInternalStub(QueryInfo* base) : QueryInfoInternal(base) {} - - ~QueryInfoInternalStub() override {} - - Future Initialize(AdParent parent) override { - return CreateAndCompleteFutureStub(kQueryInfoFnInitialize); - } - - Future CreateQueryInfo(AdFormat format, - const AdRequest& request) override { - return CreateAndCompleteQueryInfoFutureStub(kQueryInfoFnCreateQueryInfo); - } - - Future CreateQueryInfoWithAdUnit( - AdFormat format, const AdRequest& request, - const char* ad_unit_id) override { - return CreateAndCompleteQueryInfoFutureStub( - kQueryInfoFnCreateQueryInfoWithAdUnit); - } - - bool is_initialized() const override { return true; } - - private: - Future CreateAndCompleteFutureStub(QueryInfoFn fn) { - CreateAndCompleteFuture(fn, kAdErrorCodeNone, nullptr, &future_data_); - return GetInitializeLastResult(); - } - - Future CreateAndCompleteQueryInfoFutureStub(QueryInfoFn fn) { - return CreateAndCompleteFutureWithQueryInfoResult( - fn, kAdErrorCodeNone, nullptr, &future_data_, QueryInfoResult()); - } -}; - -} // namespace internal -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_STUB_QUERY_INFO_INTERNAL_STUB_H_ diff --git a/gma/src/stub/response_info_stub.cc b/gma/src/stub/response_info_stub.cc deleted file mode 100644 index 65c7add24a..0000000000 --- a/gma/src/stub/response_info_stub.cc +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "gma/src/include/firebase/gma.h" -#include "gma/src/include/firebase/gma/types.h" - -namespace firebase { -namespace gma { - -struct ResponseInfoInternal { - int stub; -}; - -ResponseInfo::ResponseInfo() {} - -ResponseInfo::ResponseInfo(const ResponseInfoInternal& response_info_internal) { -} - -} // namespace gma -} // namespace firebase diff --git a/gma/src/stub/rewarded_ad_internal_stub.h b/gma/src/stub/rewarded_ad_internal_stub.h deleted file mode 100644 index 80a8747991..0000000000 --- a/gma/src/stub/rewarded_ad_internal_stub.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_STUB_REWARDED_AD_INTERNAL_STUB_H_ -#define FIREBASE_GMA_SRC_STUB_REWARDED_AD_INTERNAL_STUB_H_ - -#include "gma/src/common/rewarded_ad_internal.h" - -namespace firebase { -namespace gma { -namespace internal { - -/// Stub version of RewardedAdInternal, for use on desktop platforms. GMA -/// is forbidden on desktop, so this version creates and immediately completes -/// the Future for each method. -class RewardedAdInternalStub : public RewardedAdInternal { - public: - explicit RewardedAdInternalStub(RewardedAd* base) - : RewardedAdInternal(base) {} - - ~RewardedAdInternalStub() override {} - - Future Initialize(AdParent parent) override { - return CreateAndCompleteFutureStub(kRewardedAdFnInitialize); - } - - Future LoadAd(const char* ad_unit_id, - const AdRequest& request) override { - return CreateAndCompleteAdResultFutureStub(kRewardedAdFnLoadAd); - } - - virtual Future Show(UserEarnedRewardListener* listener) { - return CreateAndCompleteFutureStub(kRewardedAdFnShow); - } - - bool is_initialized() const override { return true; } - - private: - Future CreateAndCompleteFutureStub(RewardedAdFn fn) { - CreateAndCompleteFuture(fn, kAdErrorCodeNone, nullptr, &future_data_); - return GetLastResult(fn); - } - - Future CreateAndCompleteAdResultFutureStub(RewardedAdFn fn) { - return CreateAndCompleteFutureWithResult(fn, kAdErrorCodeNone, nullptr, - &future_data_, AdResult()); - } -}; - -} // namespace internal -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_STUB_REWARDED_AD_INTERNAL_STUB_H_ diff --git a/gma/src/stub/ump/consent_info_internal_stub.cc b/gma/src/stub/ump/consent_info_internal_stub.cc deleted file mode 100644 index 6bc92ec08c..0000000000 --- a/gma/src/stub/ump/consent_info_internal_stub.cc +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gma/src/stub/ump/consent_info_internal_stub.h" - -#include "app/src/thread.h" - -namespace firebase { -namespace gma { -namespace ump { -namespace internal { - -// This explicitly implements the constructor for the outer class, -// ConsentInfoInternal. -ConsentInfoInternal* ConsentInfoInternal::CreateInstance() { - return new ConsentInfoInternalStub(); -} - -ConsentInfoInternalStub::ConsentInfoInternalStub() - : consent_status_(kConsentStatusUnknown), - consent_form_status_(kConsentFormStatusUnknown), - privacy_options_requirement_status_( - kPrivacyOptionsRequirementStatusUnknown), - under_age_of_consent_(false), - debug_geo_(kConsentDebugGeographyDisabled) {} - -ConsentInfoInternalStub::~ConsentInfoInternalStub() {} - -Future ConsentInfoInternalStub::RequestConsentInfoUpdate( - const ConsentRequestParameters& params) { - SafeFutureHandle handle = - CreateFuture(kConsentInfoFnRequestConsentInfoUpdate); - - // See the header file for an explanation of these default settings. - ConsentStatus new_consent_status = kConsentStatusObtained; - PrivacyOptionsRequirementStatus new_privacy_req = - kPrivacyOptionsRequirementStatusNotRequired; - // Simulate consent status based on debug geo. - if (params.debug_settings.debug_geography == kConsentDebugGeographyEEA) { - new_consent_status = kConsentStatusRequired; - } else if (params.debug_settings.debug_geography == - kConsentDebugGeographyNonEEA) { - new_consent_status = kConsentStatusNotRequired; - } - - consent_status_ = new_consent_status; - under_age_of_consent_ = params.tag_for_under_age_of_consent; - consent_form_status_ = - (under_age_of_consent_ || consent_status_ != kConsentStatusRequired) - ? kConsentFormStatusUnavailable - : kConsentFormStatusAvailable; - debug_geo_ = params.debug_settings.debug_geography; - privacy_options_requirement_status_ = - kPrivacyOptionsRequirementStatusNotRequired; - - CompleteFuture(handle, kConsentRequestSuccess); - return MakeFuture(futures(), handle); -} - -Future ConsentInfoInternalStub::LoadConsentForm() { - SafeFutureHandle handle = CreateFuture(kConsentInfoFnLoadConsentForm); - - if (consent_form_status_ != kConsentFormStatusAvailable) { - CompleteFuture(handle, kConsentFormErrorUnavailable); - return MakeFuture(futures(), handle); - } - CompleteFuture(handle, kConsentFormSuccess); - return MakeFuture(futures(), handle); -} - -Future ConsentInfoInternalStub::ShowConsentForm(FormParent parent) { - SafeFutureHandle handle = CreateFuture(kConsentInfoFnShowConsentForm); - - consent_status_ = kConsentStatusObtained; - - if (debug_geo_ == kConsentDebugGeographyEEA) { - privacy_options_requirement_status_ = - kPrivacyOptionsRequirementStatusRequired; - } else if (debug_geo_ == kConsentDebugGeographyNonEEA) { - privacy_options_requirement_status_ = - kPrivacyOptionsRequirementStatusNotRequired; - } else { // no debug option - privacy_options_requirement_status_ = - kPrivacyOptionsRequirementStatusNotRequired; - } - - CompleteFuture(handle, kConsentRequestSuccess); - return MakeFuture(futures(), handle); -} - -Future ConsentInfoInternalStub::LoadAndShowConsentFormIfRequired( - FormParent parent) { - SafeFutureHandle handle = - CreateFuture(kConsentInfoFnLoadAndShowConsentFormIfRequired); - - if (consent_status_ == kConsentStatusRequired && - consent_form_status_ != kConsentFormStatusAvailable) { - CompleteFuture(handle, kConsentFormErrorUnavailable); - return MakeFuture(futures(), handle); - } - - if (consent_status_ == kConsentStatusRequired) { - consent_status_ = kConsentStatusObtained; - if (debug_geo_ == kConsentDebugGeographyEEA) { - privacy_options_requirement_status_ = - kPrivacyOptionsRequirementStatusRequired; - } else if (debug_geo_ == kConsentDebugGeographyNonEEA) { - privacy_options_requirement_status_ = - kPrivacyOptionsRequirementStatusNotRequired; - } else { // no debug option - privacy_options_requirement_status_ = - kPrivacyOptionsRequirementStatusNotRequired; - } - } - CompleteFuture(handle, kConsentRequestSuccess); - return MakeFuture(futures(), handle); -} - -PrivacyOptionsRequirementStatus -ConsentInfoInternalStub::GetPrivacyOptionsRequirementStatus() { - return privacy_options_requirement_status_; -} - -Future ConsentInfoInternalStub::ShowPrivacyOptionsForm( - FormParent parent) { - SafeFutureHandle handle = - CreateFuture(kConsentInfoFnShowPrivacyOptionsForm); - - if (consent_status_ == kConsentStatusObtained) { - consent_status_ = kConsentStatusRequired; - privacy_options_requirement_status_ = - kPrivacyOptionsRequirementStatusNotRequired; - } - CompleteFuture(handle, kConsentRequestSuccess); - return MakeFuture(futures(), handle); -} - -bool ConsentInfoInternalStub::CanRequestAds() { - bool consent_status_ok = (consent_status_ == kConsentStatusObtained || - consent_status_ == kConsentStatusNotRequired); - bool privacy_options_ok = (privacy_options_requirement_status_ != - kPrivacyOptionsRequirementStatusUnknown); - return consent_status_ok && privacy_options_ok; -} - -void ConsentInfoInternalStub::Reset() { - consent_status_ = kConsentStatusUnknown; - consent_form_status_ = kConsentFormStatusUnknown; -} - -} // namespace internal -} // namespace ump -} // namespace gma -} // namespace firebase diff --git a/gma/src/stub/ump/consent_info_internal_stub.h b/gma/src/stub/ump/consent_info_internal_stub.h deleted file mode 100644 index 83368de284..0000000000 --- a/gma/src/stub/ump/consent_info_internal_stub.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIREBASE_GMA_SRC_STUB_UMP_CONSENT_INFO_INTERNAL_STUB_H_ -#define FIREBASE_GMA_SRC_STUB_UMP_CONSENT_INFO_INTERNAL_STUB_H_ - -#include "gma/src/common/ump/consent_info_internal.h" - -namespace firebase { -namespace gma { -namespace ump { -namespace internal { - -// The stub interface implements a few specific workflows, for testing: -// -// Before requesting: consent and privacy options requirement will be Unknown. -// -// After requesting: -// -// If debug_geography == EEA, consent will be Required, privacy options -// NotRequired. After calling ShowConsentForm() or -// LoadAndShowConsentFormIfRequired(), it will change to change to Obtained and -// privacy options will become Required, and when the privacy options form is -// shown, consent will go back to Required. -// -// If debug_geography == NonEEA, consent will be NotRequired. No privacy options -// form is required. -// -// If debug_geography == Disabled, consent will be Obtained and privacy options -// will be NotRequired. -// -// If tag_for_under_age_of_consent = true, LoadConsentForm and -// LoadAndShowConsentFormIfRequired will fail with kConsentFormErrorUnavailable. -// -// CanRequestAds returns true if consent is NotRequired or Obtained. -class ConsentInfoInternalStub : public ConsentInfoInternal { - public: - ConsentInfoInternalStub(); - ~ConsentInfoInternalStub() override; - - ConsentStatus GetConsentStatus() override { return consent_status_; } - ConsentFormStatus GetConsentFormStatus() override { - return consent_form_status_; - } - - Future RequestConsentInfoUpdate( - const ConsentRequestParameters& params) override; - Future LoadConsentForm() override; - Future ShowConsentForm(FormParent parent) override; - - Future LoadAndShowConsentFormIfRequired(FormParent parent) override; - - PrivacyOptionsRequirementStatus GetPrivacyOptionsRequirementStatus() override; - Future ShowPrivacyOptionsForm(FormParent parent) override; - - bool CanRequestAds() override; - - void Reset() override; - - private: - ConsentStatus consent_status_; - ConsentFormStatus consent_form_status_; - PrivacyOptionsRequirementStatus privacy_options_requirement_status_; - ConsentDebugGeography debug_geo_; - bool under_age_of_consent_; -}; - -} // namespace internal -} // namespace ump -} // namespace gma -} // namespace firebase - -#endif // FIREBASE_GMA_SRC_STUB_UMP_CONSENT_INFO_INTERNAL_STUB_H_ diff --git a/gma/src_java/com/google/firebase/gma/internal/cpp/AdInspectorHelper.java b/gma/src_java/com/google/firebase/gma/internal/cpp/AdInspectorHelper.java deleted file mode 100644 index 9d7e1add66..0000000000 --- a/gma/src_java/com/google/firebase/gma/internal/cpp/AdInspectorHelper.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2022 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.firebase.gma.internal.cpp; - -import android.util.Log; -import com.google.android.gms.ads.AdError; -import com.google.android.gms.ads.AdInspectorError; -import com.google.android.gms.ads.MobileAds; -import com.google.android.gms.ads.OnAdInspectorClosedListener; - -/** Helper class for listening to AdInspector closed events. */ -public final class AdInspectorHelper implements OnAdInspectorClosedListener { - /** - * Pointer to the C++ AdInspectorClosedListener object to invoke when the AdInspector has been - * closed. - */ - private long mNativeCallbackPtr; - - /** Constructor. */ - AdInspectorHelper(long nativeCallbackPtr) { - mNativeCallbackPtr = nativeCallbackPtr; - } - - /** Method that the Android GMA SDK invokes when the AdInspector has been closed. */ - @Override - public void onAdInspectorClosed(AdInspectorError error) { - adInspectorClosedCallback(mNativeCallbackPtr, error); - } - - /** - * Native callback to which will signal the customer's application that the AdInspector has been - * closed. A null AdError signifies success. - */ - public static native void adInspectorClosedCallback(long nativeCallbackPtr, AdError error); -} diff --git a/gma/src_java/com/google/firebase/gma/internal/cpp/AdRequestHelper.java b/gma/src_java/com/google/firebase/gma/internal/cpp/AdRequestHelper.java deleted file mode 100644 index a06d0a4674..0000000000 --- a/gma/src_java/com/google/firebase/gma/internal/cpp/AdRequestHelper.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.firebase.gma.internal.cpp; - -import java.util.Calendar; -import java.util.Date; - -/** - * Helper class to make interactions between the GMA C++ wrapper and Java AdRequest objects cleaner. - * This involves translating calls coming from C++ into their (typically more complicated) Java - * equivalents. - */ -public class AdRequestHelper { - public AdRequestHelper() {} - - /** - * Creates a {@link java.lang.Date} from the provided date information. - * - * @param year The year to use in creating the Date object - * @param month The month to use in creating the Date object - * @param day The day to use in creating the Date object - * @return A Date object with the appropriate date - */ - public Date createDate(int year, int month, int day) { - try { - Calendar cal = Calendar.getInstance(); - cal.setLenient(false); - cal.set(year, month - 1, day); - return cal.getTime(); - } catch (IllegalArgumentException e) { - return null; - } - } -} diff --git a/gma/src_java/com/google/firebase/gma/internal/cpp/AdViewHelper.java b/gma/src_java/com/google/firebase/gma/internal/cpp/AdViewHelper.java deleted file mode 100644 index 5c91977228..0000000000 --- a/gma/src_java/com/google/firebase/gma/internal/cpp/AdViewHelper.java +++ /dev/null @@ -1,658 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.firebase.gma.internal.cpp; - -import android.app.Activity; -import android.graphics.drawable.ColorDrawable; -import android.os.Handler; -import android.os.Looper; -import android.util.Log; -import android.view.Gravity; -import android.view.View; -import android.view.ViewGroup.LayoutParams; -import android.view.ViewTreeObserver; -import android.widget.PopupWindow; -import com.google.android.gms.ads.AdListener; -import com.google.android.gms.ads.AdRequest; -import com.google.android.gms.ads.AdSize; -import com.google.android.gms.ads.AdValue; -import com.google.android.gms.ads.AdView; -import com.google.android.gms.ads.LoadAdError; -import com.google.android.gms.ads.OnPaidEventListener; -import com.google.android.gms.ads.ResponseInfo; -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * Helper class to make interactions between the GMA C++ wrapper and Java AdView objects cleaner. - * It's designed to wrap and adapt a single instance of AdView, translate calls coming from C++ into - * their (typically more complicated) Java equivalents, and convert the Java listener patterns into - * game engine-friendly state machine polling. - */ -public class AdViewHelper implements ViewTreeObserver.OnPreDrawListener { - // It's possible to attempt to show a popup when an activity doesn't have focus. This value - // controls the number of times the AdViewHelper object checks for activity window focus - // before timing out. Assuming 10ms per retry this value attempts to retry for 2 minutes before - // timing out. - private static final int POPUP_SHOW_RETRY_COUNT = 12000; - - // C++ nullptr for use with the callbacks. - private static final long CPP_NULLPTR = 0; - - // The number of milliseconds to wait before attempting to create a PopUpWindow to hold an ad. - private static final int WEBVIEW_DELAY_MILLISECONDS = 200; - - // Pointer to the AdViewInternalAndroid object that created this object. - private long mAdViewInternalPtr; - - // The GMA SDK AdView associated with this helper. - private AdView mAdView; - - // Flag indicating whether an ad is showing in mAdView. - private boolean mAdViewContainsAd; - - // Flag indicating that the Bounding Box listener callback should be invoked - // the next time mAdView's OnPreDrawListener gets an OnPreDraw event. - private AtomicBoolean mNotifyBoundingBoxListenerOnNextDraw; - - // The {@link Activity} this helper uses to display its {@link AdView}. - private Activity mActivity; - - // The ad unit ID to use for the {@link AdView}. - private String mAdUnitId; - - // Pointer to a FutureCallbackData in the C++ wrapper that will be used to - // complete the Future associated with the latest call to LoadAd. - private long mLoadAdCallbackDataPtr; - - // Synchronization object for thread safe access to: - // * mAdViewInternalPtr - // * mLoadAdCallbackDataPtr - private final Object mAdViewLock; - - // {@link PopupWindow } that will contain the {@link AdView}. This is done to - // guarantee the ad is drawn properly even when the application uses a - // {@link android.app.NativeActivity}. - private PopupWindow mPopUp; - - // Runnable that is trigged to show the Ad {@link PopupWindow}. - // When this is set to null, the popup should not be shown. - private Runnable mPopUpRunnable; - - // Lock used to synchronize the state of the popup window. - private final Object mPopUpLock; - - // Number of times the AdViewHelper object has attempted to show the popup window before the - // activity has focus. - private int mPopUpShowRetryCount; - - // Flag indicating whether the {@link AdView} is currently intended to be - // positioned with (x,y) coordinates rather than one of the pre-defined - // positions (such as ConstantsHelper.AD_VIEW_POSITION_TOP_LEFT). - private boolean mShouldUseXYForPosition; - - // The user's desired pre-defined position for the {@link AdView}. - private int mDesiredPosition; - - // The user's desired pre-defined X coordinate for the {@link AdView}. - private int mDesiredX; - - // The user's desired pre-defined Y coordinate for the {@link AdView}. - private int mDesiredY; - - /** - * Constructor. - */ - public AdViewHelper(long AdViewInternalPtr, AdView adView) { - mAdViewInternalPtr = AdViewInternalPtr; - mAdView = adView; - mDesiredPosition = ConstantsHelper.AD_VIEW_POSITION_TOP_LEFT; - mShouldUseXYForPosition = false; - mAdViewContainsAd = false; - mNotifyBoundingBoxListenerOnNextDraw = new AtomicBoolean(false); - mAdViewLock = new Object(); - mPopUpLock = new Object(); - mPopUpShowRetryCount = 0; - } - - /** - * Initializes the {@link AdView}. This stores the activity for use with - * callback and load operations. - */ - - public void initialize(Activity activity) { - mActivity = activity; - } - - /** - * Destroy/deallocate the {@link PopupWindow} and {@link AdView}. - */ - public void destroy(final long callbackDataPtr, final boolean destructor_invocation) { - // If the Activity isn't initialized, or already Destroyed, then there's - // nothing to destroy. - if (mActivity != null) { - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - // Stop any attempts to show the popup window. - synchronized (mPopUpLock) { - mPopUpRunnable = null; - } - - if (mAdView != null) { - mAdView.setAdListener(null); - mAdView.setOnPaidEventListener(null); - mAdView.destroy(); - mAdView = null; - } - - synchronized (mPopUpLock) { - if (mPopUp != null) { - mPopUp.dismiss(); - mPopUp = null; - } - } - synchronized (mAdViewLock) { - if (destructor_invocation == false) { - notifyBoundingBoxChanged(mAdViewInternalPtr); - } - mAdViewInternalPtr = CPP_NULLPTR; - } - mActivity = null; - if (destructor_invocation) { - // AdViews's C++ destructor does not pass a future - // to callback and complete, but the reference to this object - // which should be released. - releaseAdViewGlobalReferenceCallback(callbackDataPtr); - } else { - completeAdViewFutureCallback(callbackDataPtr, ConstantsHelper.CALLBACK_ERROR_NONE, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE); - } - } - }); - } else { - if (callbackDataPtr != CPP_NULLPTR) { - completeAdViewFutureCallback(callbackDataPtr, ConstantsHelper.CALLBACK_ERROR_NONE, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE); - } - } - } - - /** - * Loads an ad for the underlying AdView object. - */ - public void loadAd(long callbackDataPtr, final AdRequest request) { - if (mActivity == null) { - return; - } - - synchronized (mAdViewLock) { - if (mLoadAdCallbackDataPtr != CPP_NULLPTR) { - completeAdViewLoadAdInternalError(callbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS); - return; - } - mLoadAdCallbackDataPtr = callbackDataPtr; - } - - if (mAdView == null) { - synchronized (mAdViewLock) { - completeAdViewLoadAdInternalError(mLoadAdCallbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); - mLoadAdCallbackDataPtr = CPP_NULLPTR; - } - } else { - mAdView.loadAd(request); - } - } - - /** - * Hides the {@link AdView}. - */ - public void hide(final long callbackDataPtr) { - if (mActivity == null) { - return; - } - - int errorCode; - String errorMessage; - - synchronized (mPopUpLock) { - // Stop any attempts to show the popup window. - mPopUpRunnable = null; - - if (mAdView == null || mPopUp == null) { - errorCode = ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED; - } else { - errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; - mPopUp.dismiss(); - mPopUp = null; - } - } - - completeAdViewFutureCallback(callbackDataPtr, errorCode, errorMessage); - } - - /** - * Shows the {@link AdView}. - */ - public void show(final long callbackDataPtr) { - if (mActivity == null) { - return; - } - updatePopUpLocation(callbackDataPtr); - } - - /** - * Pauses the {@link AdView}. - */ - public void pause(final long callbackDataPtr) { - if (mActivity == null) { - return; - } else if (mAdView != null) { - mAdView.pause(); - } - completeAdViewFutureCallback(callbackDataPtr, ConstantsHelper.CALLBACK_ERROR_NONE, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE); - } - - /** - * Resume the {@link AdView} (from a pause). - */ - public void resume(final long callbackDataPtr) { - if (mActivity == null) { - return; - } else if (mAdView != null) { - mAdView.resume(); - } - - completeAdViewFutureCallback(callbackDataPtr, ConstantsHelper.CALLBACK_ERROR_NONE, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE); - } - - /** - * Moves the {@link AdView} to the provided (x,y) screen coordinates. - */ - public void moveTo(final long callbackDataPtr, int x, int y) { - if (mActivity == null) { - return; - } - - synchronized (mPopUpLock) { - mShouldUseXYForPosition = true; - mDesiredX = x; - mDesiredY = y; - if (mPopUp != null) { - updatePopUpLocation(callbackDataPtr); - } - } - } - - /** - * Moves the {@link AdView} to the provided screen position. - */ - public void moveTo(final long callbackDataPtr, final int position) { - if (mActivity == null) { - return; - } - - synchronized (mPopUpLock) { - mShouldUseXYForPosition = false; - mDesiredPosition = position; - if (mPopUp != null) { - updatePopUpLocation(callbackDataPtr); - } - } - } - - /** - * Returns an integer array consisting of the current onscreen width, height, x-coordinate, and - * y-coordinate of the {@link AdView}. These values make up the AdView's BoundingBox. - */ - public int[] getBoundingBox() { - synchronized (mPopUpLock) { - int width = -1; - int height = -1; - int x = -1; - int y = -1; - if (mPopUp != null) { - int[] onScreenLocation = new int[2]; - mPopUp.getContentView().getLocationOnScreen(onScreenLocation); - x = onScreenLocation[0]; - y = onScreenLocation[1]; - - if (mAdView != null) { - if (mPopUp.isShowing()) { - width = mAdView.getWidth(); - height = mAdView.getHeight(); - } else { - width = height = 0; - } - } - } - return new int[] {width, height, x, y}; - } - } - - /** - * Returns an integer representation of the AdView's position. - */ - public int getPosition() { - if (mAdView == null || mShouldUseXYForPosition) { - return ConstantsHelper.AD_VIEW_POSITION_UNDEFINED; - } - return mDesiredPosition; - } - - /** - * Displays the {@link PopupWindow} that contains the {@link AdView}, in accordance with the - * parameters of the last call to MoveTo. - * - *

This method must be called on the UI Thread. - * - * @return true if successful, false otherwise. - */ - private boolean updatePopUpLocation(final long callbackDataPtr) { - if (mActivity == null) { - return false; - } - final View view = mActivity.findViewById(android.R.id.content); - if (view == null) { - return false; - } - - // If mActivity's content view doesn't have a window token, it will be - // impossible to update or display the popup later in this method. This is - // a rare case caused by mActivity spinning up or winding down, but it will - // cause the WindowManager to crash. - final View root = view.getRootView(); - if (root == null || root.getWindowToken() == null) { - return false; - } - - synchronized (mPopUpLock) { - if (mPopUp != null) { - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - synchronized (mPopUpLock) { - // Any change in visibility or position results in the dismissal of the popup (if - // one is being displayed) and creation of a fresh one. - mPopUp.dismiss(); - mPopUp = null; - } - } - }); - } - - mPopUpShowRetryCount = 0; - mPopUpRunnable = new Runnable() { - @Override - public void run() { - int errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; - String errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; - // If the Activity's window doesn't currently have focus it's not - // possible to display the popup window. Poll the focus after a delay of 10ms and try - // to show the popup again. - if (!mActivity.hasWindowFocus()) { - synchronized (mPopUpLock) { - if (mPopUpRunnable == null) { - errorCode = ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED; - } else { - if (mPopUpShowRetryCount < POPUP_SHOW_RETRY_COUNT) { - mPopUpShowRetryCount++; - new Handler().postDelayed(mPopUpRunnable, 10); - return; - } - errorCode = ConstantsHelper.CALLBACK_ERROR_NO_WINDOW_TOKEN; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NO_WINDOW_TOKEN; - } - } - } - - if (mAdView == null) { - errorCode = ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED; - } - - if (errorCode != ConstantsHelper.CALLBACK_ERROR_NONE) { - completeAdViewFutureCallback(callbackDataPtr, errorCode, errorMessage); - return; - } else if (mPopUp == null) { - mPopUp = new PopupWindow(mAdView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - mPopUp.setBackgroundDrawable(new ColorDrawable(0xFF000000)); // Black - mAdView.getViewTreeObserver().addOnPreDrawListener(AdViewHelper.this); - - if (mShouldUseXYForPosition) { - mPopUp.showAtLocation(root, Gravity.NO_GRAVITY, mDesiredX, mDesiredY); - } else { - switch (mDesiredPosition) { - case ConstantsHelper.AD_VIEW_POSITION_TOP: - mPopUp.showAtLocation(root, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); - break; - case ConstantsHelper.AD_VIEW_POSITION_BOTTOM: - mPopUp.showAtLocation(root, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); - break; - case ConstantsHelper.AD_VIEW_POSITION_TOP_LEFT: - mPopUp.showAtLocation(root, Gravity.TOP | Gravity.LEFT, 0, 0); - break; - case ConstantsHelper.AD_VIEW_POSITION_TOP_RIGHT: - mPopUp.showAtLocation(root, Gravity.TOP | Gravity.RIGHT, 0, 0); - break; - case ConstantsHelper.AD_VIEW_POSITION_BOTTOM_LEFT: - mPopUp.showAtLocation(root, Gravity.BOTTOM | Gravity.LEFT, 0, 0); - break; - case ConstantsHelper.AD_VIEW_POSITION_BOTTOM_RIGHT: - mPopUp.showAtLocation(root, Gravity.BOTTOM | Gravity.RIGHT, 0, 0); - break; - default: - mPopUp.showAtLocation(root, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); - break; - } - } - } - - completeAdViewFutureCallback(callbackDataPtr, errorCode, errorMessage); - mNotifyBoundingBoxListenerOnNextDraw.set(true); - } - }; - } - - // TODO(b/31391149): This delay is a workaround for b/31391149, and should be removed once - // that bug is resolved. - Handler mainHandler = new Handler(Looper.getMainLooper()); - mainHandler.postDelayed(mPopUpRunnable, WEBVIEW_DELAY_MILLISECONDS); - - return true; - } - - public class AdViewListener extends AdListener implements OnPaidEventListener { - @Override - public void onAdClicked() { - synchronized (mAdViewLock) { - if (mAdViewInternalPtr != CPP_NULLPTR) { - notifyAdClicked(mAdViewInternalPtr); - } - } - super.onAdClicked(); - } - - @Override - public void onAdClosed() { - synchronized (mAdViewLock) { - if (mAdViewInternalPtr != CPP_NULLPTR) { - notifyAdClosed(mAdViewInternalPtr); - mNotifyBoundingBoxListenerOnNextDraw.set(true); - } - } - super.onAdClosed(); - } - - @Override - public void onAdFailedToLoad(LoadAdError loadAdError) { - synchronized (mAdViewLock) { - if (mLoadAdCallbackDataPtr != CPP_NULLPTR) { - completeAdViewLoadAdError( - mLoadAdCallbackDataPtr, loadAdError, loadAdError.getCode(), loadAdError.getMessage()); - mLoadAdCallbackDataPtr = CPP_NULLPTR; - } - } - super.onAdFailedToLoad(loadAdError); - } - - @Override - public void onAdImpression() { - synchronized (mAdViewLock) { - if (mAdViewInternalPtr != CPP_NULLPTR) { - notifyAdImpression(mAdViewInternalPtr); - } - } - super.onAdImpression(); - } - - @Override - public void onAdLoaded() { - synchronized (mAdViewLock) { - if (mAdView != null) { - mAdViewContainsAd = true; - } - if (mLoadAdCallbackDataPtr != CPP_NULLPTR) { - AdSize adSize = mAdView.getAdSize(); - completeAdViewLoadedAd(mLoadAdCallbackDataPtr, mAdViewInternalPtr, adSize.getWidth(), - adSize.getHeight(), mAdView.getResponseInfo()); - mLoadAdCallbackDataPtr = CPP_NULLPTR; - } - // Only update the bounding box if the banner view is already visible. - if (mPopUp != null && mPopUp.isShowing()) { - // Loading an ad can sometimes cause the bounds to change. - mNotifyBoundingBoxListenerOnNextDraw.set(true); - } - } - super.onAdLoaded(); - } - - @Override - public void onAdOpened() { - synchronized (mAdViewLock) { - if (mAdViewInternalPtr != CPP_NULLPTR) { - notifyAdOpened(mAdViewInternalPtr); - } - mNotifyBoundingBoxListenerOnNextDraw.set(true); - } - super.onAdOpened(); - } - - public void onPaidEvent(AdValue value) { - synchronized (mAdViewLock) { - if (mAdViewInternalPtr != CPP_NULLPTR) { - notifyPaidEvent(mAdViewInternalPtr, value.getCurrencyCode(), value.getPrecisionType(), - value.getValueMicros()); - } - } - } - } - - /** - * Implementation of ViewTreeObserver.OnPreDrawListener's onPreDraw method. This gets called when - * mAdView is about to be redrawn, and checks a flag before invoking the native callback that - * tells the C++ side a Bounding Box change has occurred and the AdView::Listener (if there is - * one) needs to be notified. - * - *

By invoking the listener callback here, hooked into the draw loop, the AdViewHelper - * object can be sure that any movements of mAdView have been completed and the layout and screen - * position have been recalculated by the time the notification happens, preventing stale data - * from getting to the Listener. - */ - @Override - public boolean onPreDraw() { - if (mNotifyBoundingBoxListenerOnNextDraw.compareAndSet(true, false)) { - if (mAdView != null && mAdViewInternalPtr != CPP_NULLPTR) { - notifyBoundingBoxChanged(mAdViewInternalPtr); - } - } - // Returning true tells Android to continue the draw as normal. - return true; - } - - /** - * Native callback to instruct the C++ wrapper to complete the corresponding future. - */ - public static native void completeAdViewFutureCallback( - long nativeInternalPtr, int errorCode, String errorMessage); - - /** - * Native callback to instruct the C++ wrapper to release its global reference on this - * object. - */ - public static native void releaseAdViewGlobalReferenceCallback(long nativeInternalPtr); - - /** - * Native callback invoked upon successfully loading an ad. - */ - public static native void completeAdViewLoadedAd(long nativeInternalPtr, long mAdViewInternalPtr, - int width, int height, ResponseInfo responseInfo); - - /** - * Native callback upon encountering an error loading an Ad Request. Returns - * Android Google Mobile Ads SDK error codes. - **/ - public static native void completeAdViewLoadAdError( - long nativeInternalPtr, LoadAdError error, int errorCode, String errorMessage); - - /** - * Native callback upon encountering a wrapper/internal error when - * processing a Load Ad Request. Returns an integer representing - * firebase::gma::AdError codes. - */ - public static native void completeAdViewLoadAdInternalError( - long nativeInternalPtr, int gmaErrorCode, String errorMessage); - - /** - * Native callback to notify the C++ wrapper that the Ad's Bounding Box has changed. - */ - public static native void notifyBoundingBoxChanged(long nativeInternalPtr); - - /** - * Native callback to notify the C++ wrapper of an ad clicked event - */ - public static native void notifyAdClicked(long nativeInternalPtr); - - /** - * Native callback to notify the C++ wrapper of an ad closed event - */ - public static native void notifyAdClosed(long nativeInternalPtr); - - /** - * Native callback to notify the C++ wrapper of an ad impression event - */ - public static native void notifyAdImpression(long nativeInternalPtr); - - /** - * Native callback to notify the C++ wrapper of an ad opened event - */ - public static native void notifyAdOpened(long nativeInternalPtr); - - /** - * Native callback to notify the C++ wrapper that a paid event has occurred. - */ - public static native void notifyPaidEvent( - long nativeInternalPtr, String currencyCode, int precisionType, long valueMicros); -} diff --git a/gma/src_java/com/google/firebase/gma/internal/cpp/ConsentInfoHelper.java b/gma/src_java/com/google/firebase/gma/internal/cpp/ConsentInfoHelper.java deleted file mode 100644 index 4b2bf1852b..0000000000 --- a/gma/src_java/com/google/firebase/gma/internal/cpp/ConsentInfoHelper.java +++ /dev/null @@ -1,312 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.firebase.gma.internal.cpp; - -import android.app.Activity; -import android.content.Context; -import android.util.Log; -import com.google.android.ump.ConsentDebugSettings; -import com.google.android.ump.ConsentForm; -import com.google.android.ump.ConsentForm.OnConsentFormDismissedListener; -import com.google.android.ump.ConsentInformation; -import com.google.android.ump.ConsentInformation.OnConsentInfoUpdateFailureListener; -import com.google.android.ump.ConsentInformation.OnConsentInfoUpdateSuccessListener; -import com.google.android.ump.ConsentInformation.PrivacyOptionsRequirementStatus; -import com.google.android.ump.ConsentRequestParameters; -import com.google.android.ump.FormError; -import com.google.android.ump.UserMessagingPlatform; -import com.google.android.ump.UserMessagingPlatform.OnConsentFormLoadFailureListener; -import com.google.android.ump.UserMessagingPlatform.OnConsentFormLoadSuccessListener; -import java.util.ArrayList; - -/** - * Helper class to make interactions between the GMA UMP C++ wrapper and the Android UMP API. - */ -public class ConsentInfoHelper { - // C++ nullptr for use with the callbacks. - private static final long CPP_NULLPTR = 0; - - // Synchronization object for thread safe access to: - private final Object mLock = new Object(); - // Pointer to the internal ConsentInfoInternalAndroid C++ object. - // This can be reset back to 0 by calling disconnect(). - private long mInternalPtr = 0; - // The Activity that this was initialized with. - private Activity mActivity = null; - // The loaded consent form, if any. - private ConsentForm mConsentForm = null; - - // Create our own local passthrough version of these enum object values - // as integers, to make it easier for the C++ SDK to access them. - public static final int PRIVACY_OPTIONS_REQUIREMENT_UNKNOWN = - PrivacyOptionsRequirementStatus.UNKNOWN.ordinal(); - public static final int PRIVACY_OPTIONS_REQUIREMENT_REQUIRED = - PrivacyOptionsRequirementStatus.REQUIRED.ordinal(); - public static final int PRIVACY_OPTIONS_REQUIREMENT_NOT_REQUIRED = - PrivacyOptionsRequirementStatus.NOT_REQUIRED.ordinal(); - - // Enum values for tracking which function we are calling back. - // Ensure these are incremental starting at 0. - // These don't have to match ConsentInfoFn, as the C++ code will - // use these Java enums directly. - public static final int FUNCTION_REQUEST_CONSENT_INFO_UPDATE = 0; - public static final int FUNCTION_LOAD_CONSENT_FORM = 1; - public static final int FUNCTION_SHOW_CONSENT_FORM = 2; - public static final int FUNCTION_LOAD_AND_SHOW_CONSENT_FORM_IF_REQUIRED = 3; - public static final int FUNCTION_SHOW_PRIVACY_OPTIONS_FORM = 4; - public static final int FUNCTION_COUNT = 5; - - public ConsentInfoHelper(long consentInfoInternalPtr, Activity activity) { - synchronized (mLock) { - mInternalPtr = consentInfoInternalPtr; - mActivity = activity; - // Test the callbacks and fail quickly if something's wrong. - completeFuture(-1, CPP_NULLPTR, CPP_NULLPTR, 0, null); - } - } - - public int getConsentStatus() { - ConsentInformation consentInfo = UserMessagingPlatform.getConsentInformation(mActivity); - return consentInfo.getConsentStatus(); - } - - public void requestConsentInfoUpdate(final long futureHandle, boolean tagForUnderAgeOfConsent, - int debugGeography, ArrayList debugIdList) { - synchronized (mLock) { - if (mInternalPtr == 0) - return; - } - final int functionId = FUNCTION_REQUEST_CONSENT_INFO_UPDATE; - - ConsentDebugSettings.Builder debugSettingsBuilder = null; - - // Only create and use debugSettingsBuilder if a debug option is set. - if (debugGeography != ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_DISABLED) { - debugSettingsBuilder = - new ConsentDebugSettings.Builder(mActivity).setDebugGeography(debugGeography); - } - if (debugIdList != null && debugIdList.size() > 0) { - if (debugSettingsBuilder == null) { - debugSettingsBuilder = new ConsentDebugSettings.Builder(mActivity); - } - for (int i = 0; i < debugIdList.size(); i++) { - debugSettingsBuilder = debugSettingsBuilder.addTestDeviceHashedId(debugIdList.get(i)); - } - } - ConsentRequestParameters.Builder paramsBuilder = - new ConsentRequestParameters.Builder().setTagForUnderAgeOfConsent(tagForUnderAgeOfConsent); - - if (debugSettingsBuilder != null) { - paramsBuilder = paramsBuilder.setConsentDebugSettings(debugSettingsBuilder.build()); - } - - final ConsentRequestParameters params = paramsBuilder.build(); - - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - ConsentInformation consentInfo = UserMessagingPlatform.getConsentInformation(mActivity); - consentInfo.requestConsentInfoUpdate(mActivity, params, - new OnConsentInfoUpdateSuccessListener() { - @Override - public void onConsentInfoUpdateSuccess() { - synchronized (mLock) { - if (mInternalPtr == 0) - return; - completeFuture(functionId, mInternalPtr, futureHandle, 0, null); - } - } - }, - new OnConsentInfoUpdateFailureListener() { - @Override - public void onConsentInfoUpdateFailure(FormError formError) { - synchronized (mLock) { - if (mInternalPtr == 0) - return; - completeFuture(functionId, mInternalPtr, futureHandle, formError.getErrorCode(), - formError.getMessage()); - } - } - }); - } - }); - } - - public void loadConsentForm(final long futureHandle) { - synchronized (mLock) { - if (mInternalPtr == 0) - return; - } - final int functionId = FUNCTION_LOAD_CONSENT_FORM; - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - UserMessagingPlatform.loadConsentForm(mActivity, - new OnConsentFormLoadSuccessListener() { - @Override - public void onConsentFormLoadSuccess(ConsentForm form) { - synchronized (mLock) { - if (mInternalPtr == 0) - return; - mConsentForm = form; - completeFuture(functionId, mInternalPtr, futureHandle, 0, null); - } - } - }, - new OnConsentFormLoadFailureListener() { - @Override - public void onConsentFormLoadFailure(FormError formError) { - synchronized (mLock) { - if (mInternalPtr == 0) - return; - mConsentForm = null; - completeFuture(functionId, mInternalPtr, futureHandle, formError.getErrorCode(), - formError.getMessage()); - } - } - }); - } - }); - } - - public boolean showConsentForm(final long futureHandle, final Activity activity) { - synchronized (mLock) { - if (mInternalPtr == 0) - return false; - } - final int functionId = FUNCTION_SHOW_CONSENT_FORM; - ConsentForm consentForm; - synchronized (mLock) { - if (mConsentForm == null) { - // Consent form was not loaded, return an error. - return false; - } - consentForm = mConsentForm; - mConsentForm = null; - } - final ConsentForm consentFormForThread = consentForm; - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - consentFormForThread.show(activity, new OnConsentFormDismissedListener() { - @Override - public void onConsentFormDismissed(FormError formError) { - synchronized (mLock) { - if (mInternalPtr == 0) - return; - if (formError == null) { - completeFuture(functionId, mInternalPtr, futureHandle, 0, null); - } else { - completeFuture(functionId, mInternalPtr, futureHandle, formError.getErrorCode(), - formError.getMessage()); - } - } - } - }); - } - }); - // Consent form is loaded. - return true; - } - - public void loadAndShowConsentFormIfRequired(final long futureHandle, final Activity activity) { - synchronized (mLock) { - if (mInternalPtr == 0) - return; - } - final int functionId = FUNCTION_LOAD_AND_SHOW_CONSENT_FORM_IF_REQUIRED; - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - UserMessagingPlatform.loadAndShowConsentFormIfRequired( - activity, new OnConsentFormDismissedListener() { - @Override - public void onConsentFormDismissed(FormError formError) { - synchronized (mLock) { - if (mInternalPtr == 0) - return; - if (formError == null) { - completeFuture(functionId, mInternalPtr, futureHandle, 0, null); - } else { - completeFuture(functionId, mInternalPtr, futureHandle, formError.getErrorCode(), - formError.getMessage()); - } - } - } - }); - } - }); - } - - public int getPrivacyOptionsRequirementStatus() { - ConsentInformation consentInfo = UserMessagingPlatform.getConsentInformation(mActivity); - return consentInfo.getPrivacyOptionsRequirementStatus().ordinal(); - } - - public void showPrivacyOptionsForm(final long futureHandle, final Activity activity) { - synchronized (mLock) { - if (mInternalPtr == 0) - return; - } - final int functionId = FUNCTION_SHOW_PRIVACY_OPTIONS_FORM; - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - UserMessagingPlatform.showPrivacyOptionsForm( - activity, new OnConsentFormDismissedListener() { - @Override - public void onConsentFormDismissed(FormError formError) { - synchronized (mLock) { - if (mInternalPtr == 0) - return; - if (formError == null) { - completeFuture(functionId, mInternalPtr, futureHandle, 0, null); - } else { - completeFuture(functionId, mInternalPtr, futureHandle, formError.getErrorCode(), - formError.getMessage()); - } - } - } - }); - } - }); - } - - public boolean canRequestAds() { - ConsentInformation consentInfo = UserMessagingPlatform.getConsentInformation(mActivity); - return consentInfo.canRequestAds(); - } - - public boolean isConsentFormAvailable() { - ConsentInformation consentInfo = UserMessagingPlatform.getConsentInformation(mActivity); - return consentInfo.isConsentFormAvailable(); - } - - public void reset() { - ConsentInformation consentInfo = UserMessagingPlatform.getConsentInformation(mActivity); - consentInfo.reset(); - } - - /** Disconnect the helper from the native object. */ - public void disconnect() { - synchronized (mLock) { - mInternalPtr = CPP_NULLPTR; - } - } - public static native void completeFuture( - int futureFn, long nativeInternalPtr, long futureHandle, int errorCode, String errorMessage); -} diff --git a/gma/src_java/com/google/firebase/gma/internal/cpp/ConstantsHelper.java b/gma/src_java/com/google/firebase/gma/internal/cpp/ConstantsHelper.java deleted file mode 100644 index 71da84ff2b..0000000000 --- a/gma/src_java/com/google/firebase/gma/internal/cpp/ConstantsHelper.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.firebase.gma.internal.cpp; - -/** Helper class containing constants that are shared across the various GMA ad formats. */ -public final class ConstantsHelper { - /** Error codes used in completing futures. These match the AdError enumeration in the C++ API. */ - public static final int CALLBACK_ERROR_NONE = 0; - - public static final int CALLBACK_ERROR_UNINITIALIZED = 1; - - public static final int CALLBACK_ERROR_ALREADY_INITIALIZED = 2; - - public static final int CALLBACK_ERROR_LOAD_IN_PROGRESS = 3; - - public static final int CALLBACK_ERROR_INTERNAL_ERROR = 4; - - public static final int CALLBACK_ERROR_INVALID_REQUEST = 5; - - public static final int CALLBACK_ERROR_NETWORK_ERROR = 6; - - public static final int CALLBACK_ERROR_NO_FILL = 7; - - public static final int CALLBACK_ERROR_NO_WINDOW_TOKEN = 8; - - public static final int CALLBACK_ERROR_UNKNOWN = 9; - - /** - * Error messages used for completing futures. These match the error codes in the AdError - * enumeration in the C++ API. - */ - public static final String CALLBACK_ERROR_MESSAGE_NONE = ""; - - public static final String CALLBACK_ERROR_MESSAGE_UNINITIALIZED = - "Ad has not been fully initialized."; - - public static final String CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED = - "Ad is already initialized."; - - public static final String CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS = "Ad is currently loading."; - - public static final String CALLBACK_ERROR_MESSAGE_INTERNAL_ERROR = - "An internal SDK error occurred."; - - public static final String CALLBACK_ERROR_MESSAGE_INVALID_REQUEST = "Invalid ad request."; - - public static final String CALLBACK_ERROR_MESSAGE_NETWORK_ERROR = "A network error occurred."; - - public static final String CALLBACK_ERROR_MESSAGE_NO_FILL = "No ad was available to serve."; - - public static final String CALLBACK_ERROR_MESSAGE_NO_WINDOW_TOKEN = - "Android Activity does not have a window token."; - - public static final String CALLBACK_ERROR_MESSAGE_UNKNOWN = "Unknown error occurred."; - - /** - * Ad view positions (matches the AdView::Position and NativeExpressAdView::Position enumerations - * in the public C++ API). - */ - public static final int AD_VIEW_POSITION_UNDEFINED = -1; - - public static final int AD_VIEW_POSITION_TOP = 0; - - public static final int AD_VIEW_POSITION_BOTTOM = 1; - - public static final int AD_VIEW_POSITION_TOP_LEFT = 2; - - public static final int AD_VIEW_POSITION_TOP_RIGHT = 3; - - public static final int AD_VIEW_POSITION_BOTTOM_LEFT = 4; - - public static final int AD_VIEW_POSITION_BOTTOM_RIGHT = 5; - - /** - * Ad formats (matches the firebase::gma::AdFormat and com.google.android.gms.ads.AdFormat - * enumerations ). - */ - public static final int AD_FORMAT_UNDEFINED = -1; - - public static final int AD_FORMAT_APP_OPEN_AD = 0; - - public static final int AD_FORMAT_BANNER = 1; - - public static final int AD_FORMAT_INTERSTITIAL = 2; - - public static final int AD_FORMAT_NATIVE = 3; - - public static final int AD_FORMAT_REWARDED = 4; - - public static final int AD_FORMAT_REWARDED_INTERSTITIAL = 5; -} diff --git a/gma/src_java/com/google/firebase/gma/internal/cpp/DownloadHelper.java b/gma/src_java/com/google/firebase/gma/internal/cpp/DownloadHelper.java deleted file mode 100644 index 8b1b5dc9b1..0000000000 --- a/gma/src_java/com/google/firebase/gma/internal/cpp/DownloadHelper.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.firebase.gma.internal.cpp; - -import android.os.AsyncTask; -import java.io.ByteArrayOutputStream; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; - -/** - * Helper class to make interactions between the GMA C++ wrapper and Java objects cleaner. It's - * designed to download static ad assets from network. - */ -public class DownloadHelper { - // C++ nullptr for use with the callbacks. - private static final long CPP_NULLPTR = 0; - - // URL to download the asset from. - private URL url; - - // Request headers. - private final HashMap headers; - - // HTTP response code. - private int responseCode; - - // Error message. - private String errorMessage; - - // Error code. - private int errorCode; - - // Pointer to a FutureCallbackData in the C++ wrapper that will be used to - // complete the Future associated with the latest call to LoadImage. - private long mDownloadCallbackDataPtr; - - // Synchronization object for thread safe access to: - // * mDownloadCallbackDataPtr - private final Object mDownloadLock; - - // Create a new DownloadHelper with a default URL. - public DownloadHelper(String urlString) throws MalformedURLException { - this.headers = new HashMap<>(); - setUrl(urlString); - - mDownloadLock = new Object(); - errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; - - // Test the callbacks and fail quickly if something's wrong. - completeNativeImageFutureCallback(CPP_NULLPTR, 0, ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE); - } - - // Set the URL to the given string, or null if it can't be parsed. - public void setUrl(String urlString) throws MalformedURLException { - this.url = new URL(urlString); - } - - // Get the previously-set URL. - public URL getUrl() { - return this.url; - } - - // Add a header key-value pair. - public void addHeader(String key, String value) { - this.headers.put(key, value); - } - - // Clear previously-set headers. - public void clearHeaders() { - this.headers.clear(); - } - - // Get the response code returned by the server, after download() is finished. - public int getResponseCode() { - return this.responseCode; - } - - /** Triggers an async HTTP GET request to the given URL, with the given headers. */ - public void download(long callbackDataPtr) { - synchronized (mDownloadLock) { - if (mDownloadCallbackDataPtr != CPP_NULLPTR) { - completeNativeLoadImageError(callbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS); - return; - } - mDownloadCallbackDataPtr = callbackDataPtr; - } - - try { - /** Invokes download as an async background task. */ - new DownloadFilesTask().execute(); - } catch (Exception ex) { - completeNativeLoadImageError( - callbackDataPtr, ConstantsHelper.CALLBACK_ERROR_INTERNAL_ERROR, ex.getMessage()); - } - - return; - } - - /** Performs Download task in a background worker thread. */ - private class DownloadFilesTask extends AsyncTask { - protected byte[] doInBackground(Void... params) { - HttpURLConnection connection = null; - ByteArrayOutputStream bytestream = null; - try { - connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("GET"); - for (Map.Entry entry : headers.entrySet()) { - connection.setRequestProperty(entry.getKey(), entry.getValue()); - } - - responseCode = connection.getResponseCode(); - - if (responseCode != HttpURLConnection.HTTP_OK) { - errorCode = ConstantsHelper.CALLBACK_ERROR_NETWORK_ERROR; - errorMessage = connection.getResponseMessage(); - - connection.disconnect(); - return null; - } - - InputStream inputStream = connection.getInputStream(); - bytestream = new ByteArrayOutputStream(); - int ch = 0; - - // Buffer to read 1024 bytes in at a time. - byte[] buffer = new byte[1024]; - while ((ch = inputStream.read(buffer)) != -1) { - bytestream.write(buffer, 0, ch); - } - byte imgdata[] = bytestream.toByteArray(); - - bytestream.close(); - connection.disconnect(); - - return imgdata; - } catch (Exception ex) { - errorCode = ConstantsHelper.CALLBACK_ERROR_INVALID_REQUEST; - errorMessage = ex.getMessage(); - } - - try { - if (bytestream != null) { - bytestream.close(); - } - if (connection != null) { - connection.disconnect(); - } - } catch (Exception ex) { - // Connection and bytestream close exceptions can be ignored as download errors are already - // recorded. - } - return null; - } - - protected void onPostExecute(byte[] result) { - synchronized (mDownloadLock) { - if (mDownloadCallbackDataPtr != CPP_NULLPTR) { - if (errorCode != ConstantsHelper.CALLBACK_ERROR_NONE) { - completeNativeLoadImageError(mDownloadCallbackDataPtr, errorCode, errorMessage); - } else { - completeNativeLoadedImage(mDownloadCallbackDataPtr, result); - } - } - } - } - } - - /** Native callback to instruct the C++ wrapper to complete the corresponding future. */ - public static native void completeNativeImageFutureCallback( - long nativeImagePtr, int errorCode, String errorMessage); - - /** Native callback invoked upon successfully downloading an image. */ - public static native void completeNativeLoadedImage(long nativeImagePtr, byte[] image); - - /** Native callback upon encountering an error downloading an image. */ - public static native void completeNativeLoadImageError( - long nativeImagePtr, int errorCode, String errorMessage); -} diff --git a/gma/src_java/com/google/firebase/gma/internal/cpp/GmaInitializationHelper.java b/gma/src_java/com/google/firebase/gma/internal/cpp/GmaInitializationHelper.java deleted file mode 100644 index 85aee3c383..0000000000 --- a/gma/src_java/com/google/firebase/gma/internal/cpp/GmaInitializationHelper.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.firebase.gma.internal.cpp; - -import android.content.Context; -import com.google.android.gms.ads.MobileAds; -import com.google.android.gms.ads.initialization.InitializationStatus; -import com.google.android.gms.ads.initialization.OnInitializationCompleteListener; - -/** Helper class for initializing the Google Mobile Ads SDK. */ -public final class GmaInitializationHelper { - public static void initializeGma(Context context) { - MobileAds.initialize(context, new OnInitializationCompleteListener() { - @Override - public void onInitializationComplete(InitializationStatus initializationStatus) { - initializationCompleteCallback(initializationStatus); - } - }); - } - - public static native void initializationCompleteCallback( - InitializationStatus initializationStatus); -} diff --git a/gma/src_java/com/google/firebase/gma/internal/cpp/InterstitialAdHelper.java b/gma/src_java/com/google/firebase/gma/internal/cpp/InterstitialAdHelper.java deleted file mode 100644 index e08d82345a..0000000000 --- a/gma/src_java/com/google/firebase/gma/internal/cpp/InterstitialAdHelper.java +++ /dev/null @@ -1,319 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.firebase.gma.internal.cpp; - -import android.app.Activity; -import android.util.Log; -import com.google.android.gms.ads.AdError; -import com.google.android.gms.ads.AdRequest; -import com.google.android.gms.ads.AdValue; -import com.google.android.gms.ads.FullScreenContentCallback; -import com.google.android.gms.ads.LoadAdError; -import com.google.android.gms.ads.OnPaidEventListener; -import com.google.android.gms.ads.ResponseInfo; -import com.google.android.gms.ads.interstitial.InterstitialAd; -import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback; - -/** - * Helper class to make interactions between the GMA C++ wrapper and Java {@link InterstitialAd} - * objects cleaner. It's designed to wrap and adapt a single instance of {@link InterstitialAd}, - * translate calls coming from C++ into their (typically more complicated) Java equivalents. - */ -public class InterstitialAdHelper { - // C++ nullptr for use with the callbacks. - private static final long CPP_NULLPTR = 0; - - // Pointer to the InterstitialAdInternalAndroid object that created this - // object. - private long mInterstitialAdInternalPtr; - - // The GMA SDK {@link InterstitialAd} associated with this helper. - private InterstitialAd mInterstitial; - - // Synchronization object for thread safe access to: - // * mInterstitial - // * mInterstitialAdInternalPtr - // * mLoadAdCallbackDataPtr - private final Object mInterstitialLock; - - // The {@link Activity} this helper uses to display its - // {@link InterstitialAd}. - private Activity mActivity; - - // The ad unit ID to use for the {@link InterstitialAd}. - private String mAdUnitId; - - // Pointer to a FutureCallbackData in the C++ wrapper that will be used to - // complete the Future associated with the latest call to LoadAd. - private long mLoadAdCallbackDataPtr; - - /** - * Constructor. - */ - public InterstitialAdHelper(long interstitialAdInternalPtr) { - mInterstitialAdInternalPtr = interstitialAdInternalPtr; - mInterstitialLock = new Object(); - - // Test the callbacks and fail quickly if something's wrong. - completeInterstitialAdFutureCallback( - CPP_NULLPTR, 0, ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE); - } - - /** - * Initializes the {@link InterstitialAd}. This creates the corresponding GMA SDK {@link - * InterstitialAd} object and sets it up. - */ - public void initialize(final long callbackDataPtr, Activity activity) { - mActivity = activity; - - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - int errorCode; - String errorMessage; - if (mInterstitial == null) { - try { - errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; - } catch (IllegalStateException e) { - mInterstitial = null; - // This exception can be thrown if the ad unit ID was already set. - errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; - } - } else { - errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; - } - completeInterstitialAdFutureCallback(callbackDataPtr, errorCode, errorMessage); - } - }); - } - - /** Disconnect the helper from the interstital ad. */ - public void disconnect() { - synchronized (mInterstitialLock) { - mInterstitialAdInternalPtr = CPP_NULLPTR; - mLoadAdCallbackDataPtr = CPP_NULLPTR; - } - - if (mActivity == null) { - return; - } - - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - synchronized (mInterstitialLock) { - if (mInterstitial != null) { - mInterstitial.setFullScreenContentCallback(null); - mInterstitial.setOnPaidEventListener(null); - mInterstitial = null; - } - } - } - }); - } - - /** Loads an ad for the underlying {@link InterstitialAd} object. */ - public void loadAd(long callbackDataPtr, String adUnitId, final AdRequest request) { - if (mActivity == null) { - return; - } - synchronized (mInterstitialLock) { - if (mLoadAdCallbackDataPtr != CPP_NULLPTR) { - completeInterstitialLoadAdInternalError(callbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS); - return; - } - mLoadAdCallbackDataPtr = callbackDataPtr; - } - - mAdUnitId = adUnitId; - - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - if (mActivity == null) { - synchronized (mInterstitialLock) { - completeInterstitialLoadAdInternalError(mLoadAdCallbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); - mLoadAdCallbackDataPtr = CPP_NULLPTR; - } - } else { - try { - InterstitialAd.load(mActivity, mAdUnitId, request, new InterstitialAdListener()); - } catch (IllegalStateException e) { - synchronized (mInterstitialLock) { - completeInterstitialLoadAdInternalError(mLoadAdCallbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); - mLoadAdCallbackDataPtr = CPP_NULLPTR; - } - } - } - } - }); - } - - /** Shows a previously loaded ad. */ - public void show(final long callbackDataPtr) { - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - synchronized (mInterstitialLock) { - int errorCode; - String errorMessage; - if (mAdUnitId == null) { - errorCode = ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED; - } else if (mInterstitial == null) { - errorCode = ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS; - } else { - errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; - mInterstitial.show(mActivity); - } - completeInterstitialAdFutureCallback(callbackDataPtr, errorCode, errorMessage); - } - } - }); - } - - private class InterstitialAdFullScreenContentListener - extends FullScreenContentCallback implements OnPaidEventListener { - @Override - public void onAdClicked() { - synchronized (mInterstitialLock) { - if (mInterstitialAdInternalPtr != CPP_NULLPTR) { - notifyAdClickedFullScreenContentEvent(mInterstitialAdInternalPtr); - } - } - } - - @Override - public void onAdDismissedFullScreenContent() { - synchronized (mInterstitialLock) { - if (mInterstitialAdInternalPtr != CPP_NULLPTR) { - notifyAdDismissedFullScreenContentEvent(mInterstitialAdInternalPtr); - } - } - } - - @Override - public void onAdFailedToShowFullScreenContent(AdError error) { - synchronized (mInterstitialLock) { - if (mInterstitialAdInternalPtr != CPP_NULLPTR) { - notifyAdFailedToShowFullScreenContentEvent(mInterstitialAdInternalPtr, error); - } - } - } - - @Override - public void onAdImpression() { - synchronized (mInterstitialLock) { - if (mInterstitialAdInternalPtr != CPP_NULLPTR) { - notifyAdImpressionEvent(mInterstitialAdInternalPtr); - } - } - } - - @Override - public void onAdShowedFullScreenContent() { - synchronized (mInterstitialLock) { - if (mInterstitialAdInternalPtr != CPP_NULLPTR) { - notifyAdShowedFullScreenContentEvent(mInterstitialAdInternalPtr); - } - } - } - - public void onPaidEvent(AdValue value) { - synchronized (mInterstitialLock) { - notifyPaidEvent(mInterstitialAdInternalPtr, value.getCurrencyCode(), - value.getPrecisionType(), value.getValueMicros()); - } - } - } - - private class InterstitialAdListener extends InterstitialAdLoadCallback { - @Override - public void onAdFailedToLoad(LoadAdError loadAdError) { - synchronized (mInterstitialLock) { - if (mLoadAdCallbackDataPtr != CPP_NULLPTR) { - completeInterstitialLoadAdError( - mLoadAdCallbackDataPtr, loadAdError, loadAdError.getCode(), loadAdError.getMessage()); - mLoadAdCallbackDataPtr = CPP_NULLPTR; - } - } - } - - @Override - public void onAdLoaded(InterstitialAd ad) { - synchronized (mInterstitialLock) { - mInterstitial = ad; - InterstitialAdFullScreenContentListener listener = - new InterstitialAdFullScreenContentListener(); - mInterstitial.setFullScreenContentCallback(listener); - mInterstitial.setOnPaidEventListener(listener); - if (mLoadAdCallbackDataPtr != CPP_NULLPTR) { - completeInterstitialLoadedAd(mLoadAdCallbackDataPtr, ad.getResponseInfo()); - mLoadAdCallbackDataPtr = CPP_NULLPTR; - } - } - } - } - - /** Native callback to instruct the C++ wrapper to complete the corresponding future. */ - public static native void completeInterstitialAdFutureCallback( - long nativeInternalPtr, int errorCode, String errorMessage); - - /** Native callback invoked upon successfully loading an ad. */ - public static native void completeInterstitialLoadedAd( - long nativeInternalPtr, ResponseInfo responseInfo); - - /** - * Native callback upon encountering an error loading an Ad Request. Returns Android Google Mobile - * Ads SDK error codes. - */ - public static native void completeInterstitialLoadAdError( - long nativeInternalPtr, LoadAdError error, int errorCode, String errorMessage); - - /** - * Native callback upon encountering a wrapper/internal error when processing an Ad Request. - * Returns integers representing firebase::gma::AdError codes. - */ - public static native void completeInterstitialLoadAdInternalError( - long nativeInternalPtr, int gmaErrorCode, String errorMessage); - - /** Native callbacks to notify the C++ wrapper of ad events */ - public static native void notifyAdClickedFullScreenContentEvent(long nativeInternalPtr); - - public static native void notifyAdDismissedFullScreenContentEvent(long nativeInternalPtr); - - public static native void notifyAdFailedToShowFullScreenContentEvent( - long nativeInternalPtr, AdError adError); - - public static native void notifyAdImpressionEvent(long nativeInternalPtr); - - public static native void notifyAdShowedFullScreenContentEvent(long nativeInternalPtr); - - public static native void notifyPaidEvent( - long nativeInternalPtr, String currencyCode, int precisionType, long valueMicros); -} diff --git a/gma/src_java/com/google/firebase/gma/internal/cpp/NativeAdHelper.java b/gma/src_java/com/google/firebase/gma/internal/cpp/NativeAdHelper.java deleted file mode 100644 index a2829e8bcb..0000000000 --- a/gma/src_java/com/google/firebase/gma/internal/cpp/NativeAdHelper.java +++ /dev/null @@ -1,338 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.firebase.gma.internal.cpp; - -import android.app.Activity; -import android.os.Bundle; -import com.google.android.gms.ads.AdListener; -import com.google.android.gms.ads.AdLoader; -import com.google.android.gms.ads.AdRequest; -import com.google.android.gms.ads.LoadAdError; -import com.google.android.gms.ads.ResponseInfo; -import com.google.android.gms.ads.nativead.NativeAd; -import java.util.List; - -/** - * Helper class to make interactions between the GMA C++ wrapper and Java objects cleaner. It's - * designed to wrap and adapt a single instance of NativeAd, translate calls coming from C++ into - * their (typically more complicated) Java equivalents. - */ -public class NativeAdHelper { - // C++ nullptr for use with the callbacks. - private static final long CPP_NULLPTR = 0; - - // Pointer to the NativeAdInternalAndroid object that created this - // object. - private long mNativeAdInternalPtr; - - // The GMA SDK NativeAd associated with this helper. - private NativeAd mNative; - - // Synchronization object for thread safe access to: - // * mNative - // * mNativeAdInternalPtr - // * mLoadAdCallbackDataPtr - private final Object mNativeLock; - - // The Activity this helper uses to display its NativeAd. - private Activity mActivity; - - // The ad unit ID to use for the NativeAd. - private String mAdUnitId; - - // Pointer to a FutureCallbackData in the C++ wrapper that will be used to - // complete the Future associated with the latest call to LoadAd. - private long mLoadAdCallbackDataPtr; - - /** Constructor. */ - public NativeAdHelper(long nativeAdInternalPtr) { - mNativeAdInternalPtr = nativeAdInternalPtr; - mNativeLock = new Object(); - - // Test the callbacks and fail quickly if something's wrong. - completeNativeAdFutureCallback(CPP_NULLPTR, 0, ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE); - } - - /** - * Initializes the NativeAd. This creates the corresponding GMA SDK NativeAd object and sets it - * up. - */ - public void initialize(final long callbackDataPtr, Activity activity) { - mActivity = activity; - - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - int errorCode; - String errorMessage; - if (mNative == null) { - try { - errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; - } catch (IllegalStateException e) { - mNative = null; - // This exception can be thrown if the ad unit ID was already set. - errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; - } - } else { - errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; - } - completeNativeAdFutureCallback(callbackDataPtr, errorCode, errorMessage); - } - }); - } - - /** Disconnect the helper from the native ad. */ - public void disconnect() { - synchronized (mNativeLock) { - mNativeAdInternalPtr = CPP_NULLPTR; - mLoadAdCallbackDataPtr = CPP_NULLPTR; - } - - if (mActivity == null) { - return; - } - - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - synchronized (mNativeLock) { - if (mNative != null) { - mNative = null; - } - } - } - }); - } - - /** Record Impression for allowlisted ad units. */ - public void recordImpression(final long callbackDataPtr, final Bundle payload) { - if (mActivity == null) { - return; - } - - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - synchronized (mNativeLock) { - int errorCode; - String errorMessage; - if (mAdUnitId == null) { - errorCode = ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED; - } else if (mNative == null) { - errorCode = ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS; - } else { - errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; - mNative.recordImpression(payload); - } - completeNativeAdFutureCallback(callbackDataPtr, errorCode, errorMessage); - } - } - }); - } - - /** Perform click for allowlisted ad units. */ - public void performClick(final long callbackDataPtr, final Bundle payload) { - if (mActivity == null) { - return; - } - - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - synchronized (mNativeLock) { - int errorCode; - String errorMessage; - if (mAdUnitId == null) { - errorCode = ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED; - } else if (mNative == null) { - errorCode = ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS; - } else { - errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; - mNative.performClick(payload); - } - completeNativeAdFutureCallback(callbackDataPtr, errorCode, errorMessage); - } - } - }); - } - - /** Loads an ad for the underlying NativeAd object. */ - public void loadAd(long callbackDataPtr, String adUnitId, final AdRequest request) { - if (mActivity == null) { - return; - } - synchronized (mNativeLock) { - if (mLoadAdCallbackDataPtr != CPP_NULLPTR) { - completeNativeLoadAdInternalError(callbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS); - return; - } - mLoadAdCallbackDataPtr = callbackDataPtr; - } - - mAdUnitId = adUnitId; - - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - if (mActivity == null) { - synchronized (mNativeLock) { - completeNativeLoadAdInternalError(mLoadAdCallbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); - mLoadAdCallbackDataPtr = CPP_NULLPTR; - } - } else { - try { - AdLoader.Builder adLoaderBuilder = new AdLoader.Builder(mActivity, mAdUnitId); - NativeAdListener listener = new NativeAdListener(); - adLoaderBuilder.forNativeAd(listener); - adLoaderBuilder.withAdListener(listener); - AdLoader adLoader = adLoaderBuilder.build(); - adLoader.loadAd(request); - } catch (IllegalStateException e) { - synchronized (mNativeLock) { - completeNativeLoadAdInternalError(mLoadAdCallbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); - mLoadAdCallbackDataPtr = CPP_NULLPTR; - } - } - } - } - }); - } - - private class NativeAdListener extends AdListener implements NativeAd.OnNativeAdLoadedListener { - @Override - public void onAdFailedToLoad(LoadAdError loadAdError) { - synchronized (mNativeLock) { - if (mLoadAdCallbackDataPtr != CPP_NULLPTR) { - completeNativeLoadAdError( - mLoadAdCallbackDataPtr, loadAdError, loadAdError.getCode(), loadAdError.getMessage()); - mLoadAdCallbackDataPtr = CPP_NULLPTR; - } - } - } - - public void onNativeAdLoaded(NativeAd ad) { - synchronized (mNativeLock) { - mNative = ad; - if (mLoadAdCallbackDataPtr != CPP_NULLPTR) { - List imgList = ad.getImages(); - NativeAd.Image[] imgArray = new NativeAd.Image[imgList.size()]; - imgArray = imgList.toArray(imgArray); - - NativeAd.Image adChoicesIcon = null; - NativeAd.AdChoicesInfo adChoicesInfo = ad.getAdChoicesInfo(); - if (adChoicesInfo != null) { - List adChoicesImgList = adChoicesInfo.getImages(); - if (!adChoicesImgList.isEmpty()) { - // Gets only the first image to keep the api in sync with its ios counterpart. - adChoicesIcon = adChoicesImgList.get(0); - } - } - - completeNativeLoadedAd(mLoadAdCallbackDataPtr, mNativeAdInternalPtr, ad.getIcon(), - imgArray, adChoicesIcon, ad.getResponseInfo()); - mLoadAdCallbackDataPtr = CPP_NULLPTR; - } - } - } - - @Override - public void onAdClicked() { - synchronized (mNativeLock) { - if (mNativeAdInternalPtr != CPP_NULLPTR) { - notifyAdClicked(mNativeAdInternalPtr); - } - } - } - - @Override - public void onAdImpression() { - synchronized (mNativeLock) { - if (mNativeAdInternalPtr != CPP_NULLPTR) { - notifyAdImpression(mNativeAdInternalPtr); - } - } - } - - @Override - public void onAdClosed() { - synchronized (mNativeLock) { - if (mNativeAdInternalPtr != CPP_NULLPTR) { - notifyAdClosed(mNativeAdInternalPtr); - } - } - } - - @Override - public void onAdOpened() { - synchronized (mNativeLock) { - if (mNativeAdInternalPtr != CPP_NULLPTR) { - notifyAdOpened(mNativeAdInternalPtr); - } - } - } - } - - /** Native callback to instruct the C++ wrapper to complete the corresponding future. */ - public static native void completeNativeAdFutureCallback( - long nativeInternalPtr, int errorCode, String errorMessage); - - /** Native callback invoked upon successfully loading an ad. */ - public static native void completeNativeLoadedAd(long nativeInternalPtr, - long mNativeAdInternalPtr, NativeAd.Image icon, NativeAd.Image[] images, - NativeAd.Image adChoicesIcon, ResponseInfo responseInfo); - - /** - * Native callback upon encountering an error loading an Ad Request. Returns Android Google Mobile - * Ads SDK error codes. - */ - public static native void completeNativeLoadAdError( - long nativeInternalPtr, LoadAdError error, int errorCode, String errorMessage); - - /** - * Native callback upon encountering a wrapper/internal error when processing an Ad Request. - * Returns integers representing firebase::gma::AdError codes. - */ - public static native void completeNativeLoadAdInternalError( - long nativeInternalPtr, int gmaErrorCode, String errorMessage); - - /** Native callback to notify the C++ wrapper of an ad clicked event */ - public static native void notifyAdClicked(long nativeInternalPtr); - - /** Native callback to notify the C++ wrapper of an ad closed event */ - public static native void notifyAdClosed(long nativeInternalPtr); - - /** Native callback to notify the C++ wrapper of an ad impression event */ - public static native void notifyAdImpression(long nativeInternalPtr); - - /** Native callback to notify the C++ wrapper of an ad opened event */ - public static native void notifyAdOpened(long nativeInternalPtr); -} diff --git a/gma/src_java/com/google/firebase/gma/internal/cpp/QueryInfoHelper.java b/gma/src_java/com/google/firebase/gma/internal/cpp/QueryInfoHelper.java deleted file mode 100644 index 644e905d05..0000000000 --- a/gma/src_java/com/google/firebase/gma/internal/cpp/QueryInfoHelper.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.firebase.gma.internal.cpp; - -import android.app.Activity; -import com.google.android.gms.ads.AdFormat; -import com.google.android.gms.ads.AdRequest; -import com.google.android.gms.ads.query.QueryInfo; -import com.google.android.gms.ads.query.QueryInfoGenerationCallback; - -/** - * Helper class to make interactions between the GMA C++ wrapper and Java objects cleaner. It's - * designed to wrap and adapt a single instance of QueryInfo, translate calls coming from C++ into - * their (typically more complicated) Java equivalents. - */ -public class QueryInfoHelper { - // C++ nullptr for use with the callbacks. - private static final long CPP_NULLPTR = 0; - - // Pointer to the QueryInfoInternalAndroid object that created this - // object. - private long queryInfoInternalPtr; - - // The GMA SDK QueryInfo associated with this helper. - private QueryInfo gmaQueryInfo; - - // Synchronization object for thread safe access to: - // * queryInfoInternalPtr - // * createQueryInfoCallbackDataPtr - private final Object queryInfoLock; - - // The Activity this helper uses to generate the QueryInfo. - private Activity activity; - - // Pointer to a FutureCallbackData in the C++ wrapper that will be used to - // complete the Future associated with the latest call to CreateQueryInfo. - private long createQueryInfoCallbackDataPtr; - - /** Constructor. */ - public QueryInfoHelper(long queryInfoInternalPtr) { - this.queryInfoInternalPtr = queryInfoInternalPtr; - queryInfoLock = new Object(); - - // Test the callbacks and fail quickly if something's wrong. - completeQueryInfoFutureCallback(CPP_NULLPTR, 0, ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE); - } - - /** - * Initializes the QueryInfoHelper. This creates the corresponding GMA SDK NativeAd object and - * sets it up. - */ - public void initialize(final long callbackDataPtr, Activity activity) { - this.activity = activity; - - this.activity.runOnUiThread(new Runnable() { - @Override - public void run() { - int errorCode; - String errorMessage; - if (gmaQueryInfo == null) { - try { - errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; - } catch (IllegalStateException e) { - gmaQueryInfo = null; - errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; - } - } else { - errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; - } - completeQueryInfoFutureCallback(callbackDataPtr, errorCode, errorMessage); - } - }); - } - - /** Disconnect the helper from the query info. */ - public void disconnect() { - synchronized (queryInfoLock) { - queryInfoInternalPtr = CPP_NULLPTR; - createQueryInfoCallbackDataPtr = CPP_NULLPTR; - } - - if (activity == null) { - return; - } - - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - synchronized (queryInfoLock) { - if (gmaQueryInfo != null) { - gmaQueryInfo = null; - } - } - } - }); - } - - private AdFormat getAdFormat(int format) { - switch (format) { - case ConstantsHelper.AD_FORMAT_BANNER: - return AdFormat.BANNER; - case ConstantsHelper.AD_FORMAT_INTERSTITIAL: - return AdFormat.INTERSTITIAL; - case ConstantsHelper.AD_FORMAT_REWARDED: - return AdFormat.REWARDED; - case ConstantsHelper.AD_FORMAT_NATIVE: - return AdFormat.NATIVE; - case ConstantsHelper.AD_FORMAT_REWARDED_INTERSTITIAL: - return AdFormat.REWARDED_INTERSTITIAL; - default: - return AdFormat.APP_OPEN_AD; - } - } - - /** Creates a query info for the underlying QueryInfo object. */ - public void createQueryInfo( - long callbackDataPtr, int format, String adUnitId, final AdRequest request) { - if (activity == null) { - return; - } - synchronized (queryInfoLock) { - if (createQueryInfoCallbackDataPtr != CPP_NULLPTR) { - completeCreateQueryInfoError(callbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS); - return; - } - createQueryInfoCallbackDataPtr = callbackDataPtr; - } - - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - if (activity == null) { - synchronized (queryInfoLock) { - completeCreateQueryInfoError(createQueryInfoCallbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); - createQueryInfoCallbackDataPtr = CPP_NULLPTR; - } - } else { - try { - AdFormat adFormat = getAdFormat(format); - if (adUnitId != null && !adUnitId.isEmpty()) { - QueryInfo.generate(activity, adFormat, request, adUnitId, new QueryInfoListener()); - } else { - QueryInfo.generate(activity, adFormat, request, new QueryInfoListener()); - } - } catch (IllegalStateException e) { - synchronized (queryInfoLock) { - completeCreateQueryInfoError(createQueryInfoCallbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); - createQueryInfoCallbackDataPtr = CPP_NULLPTR; - } - } - } - } - }); - } - - private class QueryInfoListener extends QueryInfoGenerationCallback { - @Override - public void onFailure(String errorMessage) { - synchronized (queryInfoLock) { - if (createQueryInfoCallbackDataPtr != CPP_NULLPTR) { - completeCreateQueryInfoError(createQueryInfoCallbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_INVALID_REQUEST, errorMessage); - createQueryInfoCallbackDataPtr = CPP_NULLPTR; - } - } - } - - @Override - public void onSuccess(QueryInfo queryInfo) { - synchronized (queryInfoLock) { - gmaQueryInfo = queryInfo; - if (createQueryInfoCallbackDataPtr != CPP_NULLPTR) { - completeCreateQueryInfoSuccess(createQueryInfoCallbackDataPtr, queryInfo.getQuery()); - createQueryInfoCallbackDataPtr = CPP_NULLPTR; - } - } - } - } - - /** Native callback to instruct the C++ wrapper to complete the corresponding future. */ - public static native void completeQueryInfoFutureCallback( - long internalPtr, int errorCode, String errorMessage); - - /** Native callback invoked upon successfully generating a QueryInfo. */ - public static native void completeCreateQueryInfoSuccess( - long createQueryInfoInternalPtr, String query); - - /** - * Native callback invoked upon error generating a QueryInfo. Also used for wrapper/internal - * errors when processing a query info generation request. Returns integers representing - * firebase::gma::AdError codes. - */ - public static native void completeCreateQueryInfoError( - long createQueryInfoInternalPtr, int gmaErrorCode, String errorMessage); -} diff --git a/gma/src_java/com/google/firebase/gma/internal/cpp/RewardedAdHelper.java b/gma/src_java/com/google/firebase/gma/internal/cpp/RewardedAdHelper.java deleted file mode 100644 index 3e78901d2f..0000000000 --- a/gma/src_java/com/google/firebase/gma/internal/cpp/RewardedAdHelper.java +++ /dev/null @@ -1,345 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.firebase.gma.internal.cpp; - -import android.app.Activity; -import android.util.Log; -import com.google.android.gms.ads.AdError; -import com.google.android.gms.ads.AdRequest; -import com.google.android.gms.ads.AdValue; -import com.google.android.gms.ads.FullScreenContentCallback; -import com.google.android.gms.ads.LoadAdError; -import com.google.android.gms.ads.OnPaidEventListener; -import com.google.android.gms.ads.OnUserEarnedRewardListener; -import com.google.android.gms.ads.ResponseInfo; -import com.google.android.gms.ads.rewarded.RewardItem; -import com.google.android.gms.ads.rewarded.RewardedAd; -import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback; -import com.google.android.gms.ads.rewarded.ServerSideVerificationOptions; - -/** - * Helper class to make interactions between the GMA C++ wrapper and Java {@link RewardedAd} objects - * cleaner. It's designed to wrap and adapt a single instance of {@link RewardedAd}, translate calls - * coming from C++ into their (typically more complicated) Java equivalents. - */ -public class RewardedAdHelper { - // C++ nullptr for use with the callbacks. - private static final long CPP_NULLPTR = 0; - - // Pointer to the RewardedAdInternalAndroid object that created this - // object. - private long mRewardedAdInternalPtr; - - // The GMA SDK {@link RewardedAd} associated with this helper. - private RewardedAd mRewarded; - - // Synchronization object for thread safe access to: - // * mRewarded - // * mRewardedAdInternalPtr - // * mLoadAdCallbackDataPtr - private final Object mRewardedLock; - - // The {@link Activity} this helper uses to display its - // {@link RewardedAd}. - private Activity mActivity; - - // The ad unit ID to use for the {@link RewardedAd}. - private String mAdUnitId; - - // Pointer to a FutureCallbackData in the C++ wrapper that will be used to - // complete the Future associated with the latest call to LoadAd. - private long mLoadAdCallbackDataPtr; - - /** Constructor. */ - public RewardedAdHelper(long rewardedAdInternalPtr) { - mRewardedAdInternalPtr = rewardedAdInternalPtr; - mRewardedLock = new Object(); - - // Test the callbacks and fail quickly if something's wrong. - completeRewardedAdFutureCallback(CPP_NULLPTR, 0, ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE); - } - - /** - * Initializes the {@link RewardedAd}. This creates the corresponding GMA SDK {@link RewardedAd} - * object and sets it up. - */ - public void initialize(final long callbackDataPtr, Activity activity) { - mActivity = activity; - - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - int errorCode; - String errorMessage; - synchronized (mRewardedLock) { - if (mRewarded == null) { - try { - errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; - } catch (IllegalStateException e) { - mRewarded = null; - // This exception can be thrown if the ad unit ID was already set. - errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; - } - } else { - errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; - } - completeRewardedAdFutureCallback(callbackDataPtr, errorCode, errorMessage); - } - } - }); - } - - /** Disconnect the helper from the interstital ad. */ - public void disconnect() { - synchronized (mRewardedLock) { - mRewardedAdInternalPtr = CPP_NULLPTR; - mLoadAdCallbackDataPtr = CPP_NULLPTR; - } - - if (mActivity == null) { - return; - } - - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - synchronized (mRewardedLock) { - if (mRewarded != null) { - mRewarded.setFullScreenContentCallback(null); - mRewarded.setOnPaidEventListener(null); - mRewarded = null; - } - } - } - }); - } - - /** Loads an ad for the underlying {@link RewardedAd} object. */ - public void loadAd(long callbackDataPtr, String adUnitId, final AdRequest request) { - if (mActivity == null) { - return; - } - synchronized (mRewardedLock) { - if (mLoadAdCallbackDataPtr != CPP_NULLPTR) { - completeRewardedLoadAdInternalError(callbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS); - return; - } - mLoadAdCallbackDataPtr = callbackDataPtr; - } - - mAdUnitId = adUnitId; - - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - synchronized (mRewardedLock) { - if (mActivity == null) { - completeRewardedLoadAdInternalError(mLoadAdCallbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); - mLoadAdCallbackDataPtr = CPP_NULLPTR; - } else { - try { - RewardedAd.load(mActivity, mAdUnitId, request, new RewardedAdListener()); - } catch (IllegalStateException e) { - completeRewardedLoadAdInternalError(mLoadAdCallbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); - mLoadAdCallbackDataPtr = CPP_NULLPTR; - } - } - } - } - }); - } - - /** - * Shows a previously loaded ad. - */ - public void show(final long callbackDataPtr, final String verificationCustomData, - final String verificationUserId) { - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - synchronized (mRewardedLock) { - int errorCode; - String errorMessage; - if (mAdUnitId == null) { - errorCode = ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED; - } else if (mRewarded == null) { - errorCode = ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS; - } else { - errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; - if (!verificationCustomData.isEmpty() || !verificationUserId.isEmpty()) { - ServerSideVerificationOptions options = new ServerSideVerificationOptions.Builder() - .setCustomData(verificationCustomData) - .setUserId(verificationUserId) - .build(); - mRewarded.setServerSideVerificationOptions(options); - } - mRewarded.show(mActivity, new UserEarnedRewardListener()); - } - completeRewardedAdFutureCallback(callbackDataPtr, errorCode, errorMessage); - } - } - }); - } - - private class UserEarnedRewardListener implements OnUserEarnedRewardListener { - @Override - public void onUserEarnedReward(RewardItem rewardItem) { - synchronized (mRewardedLock) { - if (mRewardedAdInternalPtr != CPP_NULLPTR) { - notifyUserEarnedRewardEvent( - mRewardedAdInternalPtr, rewardItem.getType(), rewardItem.getAmount()); - } - } - } - } - - private class RewardedAdFullScreenContentListener - extends FullScreenContentCallback implements OnPaidEventListener { - @Override - public void onAdClicked() { - synchronized (mRewardedLock) { - if (mRewardedAdInternalPtr != CPP_NULLPTR) { - notifyAdClickedFullScreenContentEvent(mRewardedAdInternalPtr); - } - } - } - - @Override - public void onAdDismissedFullScreenContent() { - synchronized (mRewardedLock) { - if (mRewardedAdInternalPtr != CPP_NULLPTR) { - notifyAdDismissedFullScreenContentEvent(mRewardedAdInternalPtr); - } - } - } - - @Override - public void onAdFailedToShowFullScreenContent(AdError error) { - synchronized (mRewardedLock) { - if (mRewardedAdInternalPtr != CPP_NULLPTR) { - notifyAdFailedToShowFullScreenContentEvent(mRewardedAdInternalPtr, error); - } - } - } - - @Override - public void onAdImpression() { - synchronized (mRewardedLock) { - if (mRewardedAdInternalPtr != CPP_NULLPTR) { - notifyAdImpressionEvent(mRewardedAdInternalPtr); - } - } - } - - @Override - public void onAdShowedFullScreenContent() { - synchronized (mRewardedLock) { - if (mRewardedAdInternalPtr != CPP_NULLPTR) { - notifyAdShowedFullScreenContentEvent(mRewardedAdInternalPtr); - } - } - } - - public void onPaidEvent(AdValue value) { - synchronized (mRewardedLock) { - if (mRewardedAdInternalPtr != CPP_NULLPTR) { - notifyPaidEvent(mRewardedAdInternalPtr, value.getCurrencyCode(), value.getPrecisionType(), - value.getValueMicros()); - } - } - } - } - - private class RewardedAdListener extends RewardedAdLoadCallback { - @Override - public void onAdFailedToLoad(LoadAdError loadAdError) { - synchronized (mRewardedLock) { - if (mLoadAdCallbackDataPtr != CPP_NULLPTR) { - completeRewardedLoadAdError( - mLoadAdCallbackDataPtr, loadAdError, loadAdError.getCode(), loadAdError.getMessage()); - mLoadAdCallbackDataPtr = CPP_NULLPTR; - } - } - } - - @Override - public void onAdLoaded(RewardedAd ad) { - synchronized (mRewardedLock) { - if (mLoadAdCallbackDataPtr != CPP_NULLPTR) { - mRewarded = ad; - RewardedAdFullScreenContentListener listener = new RewardedAdFullScreenContentListener(); - mRewarded.setFullScreenContentCallback(listener); - mRewarded.setOnPaidEventListener(listener); - completeRewardedLoadedAd(mLoadAdCallbackDataPtr, mRewarded.getResponseInfo()); - mLoadAdCallbackDataPtr = CPP_NULLPTR; - } - } - } - } - - /** Native callback to instruct the C++ wrapper to complete the corresponding future. */ - public static native void completeRewardedAdFutureCallback( - long nativeInternalPtr, int errorCode, String errorMessage); - - /** Native callback invoked upon successfully loading an ad. */ - public static native void completeRewardedLoadedAd( - long nativeInternalPtr, ResponseInfo responseInfo); - - /** - * Native callback upon encountering an error loading an Ad Request. Returns Android Google Mobile - * Ads SDK error codes. - */ - public static native void completeRewardedLoadAdError( - long nativeInternalPtr, LoadAdError error, int errorCode, String errorMessage); - - /** - * Native callback upon encountering a wrapper/internal error when processing an Ad Request. - * Returns integers representing firebase::gma::AdError codes. - */ - public static native void completeRewardedLoadAdInternalError( - long nativeInternalPtr, int gmaErrorCode, String errorMessage); - - /** Native callbacks to notify the C++ wrapper of ad events */ - public static native void notifyUserEarnedRewardEvent( - long mRewardedAdInternalPtr, String type, int amount); - - public static native void notifyAdClickedFullScreenContentEvent(long nativeInternalPtr); - - public static native void notifyAdDismissedFullScreenContentEvent(long nativeInternalPtr); - - public static native void notifyAdFailedToShowFullScreenContentEvent( - long nativeInternalPtr, AdError adError); - - public static native void notifyAdImpressionEvent(long nativeInternalPtr); - - public static native void notifyAdShowedFullScreenContentEvent(long nativeInternalPtr); - - public static native void notifyPaidEvent( - long nativeInternalPtr, String currencyCode, int precisionType, long valueMicros); -} diff --git a/ios_pod/Podfile b/ios_pod/Podfile index f81729bd8a..378e034804 100644 --- a/ios_pod/Podfile +++ b/ios_pod/Podfile @@ -5,7 +5,6 @@ use_frameworks! target 'GetPods' do pod 'Firebase/Core', '11.14.0' - pod 'Google-Mobile-Ads-SDK', '11.2.0' pod 'GoogleUserMessagingPlatform', '2.3.0' pod 'Firebase/Analytics', '11.14.0' pod 'Firebase/AppCheck', '11.14.0' diff --git a/release_build_files/Android/firebase_dependencies.gradle b/release_build_files/Android/firebase_dependencies.gradle index 142de79cc7..c9d1fc0584 100644 --- a/release_build_files/Android/firebase_dependencies.gradle +++ b/release_build_files/Android/firebase_dependencies.gradle @@ -27,8 +27,6 @@ def firebaseDependenciesMap = [ 'dynamic_links' : ['com.google.firebase:firebase-dynamic-links'], 'firestore' : ['com.google.firebase:firebase-firestore'], 'functions' : ['com.google.firebase:firebase-functions'], - 'gma' : ['com.google.android.gms:play-services-ads:23.0.0', - 'com.google.android.ump:user-messaging-platform:2.2.0'], 'installations' : ['com.google.firebase:firebase-installations'], 'invites' : ['com.google.firebase:firebase-invites'], // Messaging has an additional local dependency to include. @@ -75,9 +73,6 @@ class Dependencies { def getFunctions() { libSet.add('functions') } - def getGma() { - libSet.add('gma') - } def getInstallations() { libSet.add('installations') } diff --git a/release_build_files/CMakeLists.txt b/release_build_files/CMakeLists.txt index 594440937d..1d7f4c692c 100644 --- a/release_build_files/CMakeLists.txt +++ b/release_build_files/CMakeLists.txt @@ -96,7 +96,6 @@ add_firebase_target(firebase_database) add_firebase_target(firebase_dynamic_links) add_firebase_target(firebase_firestore) add_firebase_target(firebase_functions) -add_firebase_target(firebase_gma) add_firebase_target(firebase_installations) add_firebase_target(firebase_messaging) add_firebase_target(firebase_performance) diff --git a/release_build_files/readme.md b/release_build_files/readme.md index 3bcfdb908b..9ddaf5d6d3 100644 --- a/release_build_files/readme.md +++ b/release_build_files/readme.md @@ -10,7 +10,6 @@ on *iOS* and *Android*: * Firebase Dynamic Links (deprecated SDK) * Cloud Firestore * Firebase Functions -* Google Mobile Ads (deprecated SDK) * Firebase Installations * Firebase Instance ID (deprecated SDK) * Firebase Realtime Database @@ -131,14 +130,6 @@ Firebase Functions | libfirebase_functions | | (Maven package) | | com.google.firebase:firebase-auth | | (Maven package) -Google Mobile Ads | libfirebase_gma.a -| | libfirebase_app.a -| | com.google.firebase:firebase-analytics -| | (Maven package) -| | com.google.android.gms:play-services-ads:23.0.0 -| | (Maven package) -| | com.google.android.ump:user-messaging-platform:2.2.0 -| | (Maven package) Firebase Installations | libfirebase_installations.a | | libfirebase_app.a | | com.google.firebase:firebase-installations @@ -208,7 +199,6 @@ firebaseCpp.dependencies { dynamicLinks firestore functions - gma installations messaging remoteConfig @@ -258,11 +248,6 @@ Firebase Functions | firebase_functions.xcframework | | firebase.xcframework | | Firebase/Functions Cocoapod (11.14.0) | | Firebase/Auth Cocoapod (11.14.0) -Google Mobile Ads | firebase_gma.xcframework -| | firebase.xcframework -| | Firebase/CoreOnly Cocoapod (11.14.0) -| | Google-Mobile-Ads-SDK Cocoapod (11.2.0) -| | GoogleUserMessagingPlatform Cocoapod (2.3.0) Firebase Installations | firebase_installations.xcframework | | firebase.xcframework | | FirebaseInstallations Cocoapod (11.14.0) @@ -325,11 +310,6 @@ Firebase Functions | libfirebase_functions.a | | libfirebase_auth.a (optional) | | Firebase/Functions Cocoapod (11.14.0) | | Firebase/Auth Cocoapod (11.14.0) -Google Mobile Ads | libfirebase_gma.a -| | libfirebase_app.a -| | Firebase/CoreOnly Cocoapod (11.14.0) -| | Google-Mobile-Ads-SDK Cocoapod (11.2.0) -| | GoogleUserMessagingPlatform Cocoapod (2.3.0) Firebase Installations | libfirebase_installations.a | | libfirebase_app.a | | FirebaseInstallations Cocoapod (11.14.0) @@ -397,8 +377,6 @@ Firebase Analytics (stub) | libfirebase_analytics.a | | libfirebase_app.a Firebase Dynamic Links (stub) | libfirebase_dynamic_links.a | | libfirebase_app.a -Google Mobile Ads (stub) | libfirebase_gma.a -| | libfirebase_app.a Firebase Installations (stub) | libfirebase_installations.a | | libfirebase_app.a Firebase Cloud Messaging (stub) | libfirebase_messaging.a @@ -442,8 +420,6 @@ Firebase Analytics (stub) | firebase_analytics.framework | | firebase.framework Firebase Dynamic Links (stub) | firebase_dynamic_links.framework | | firebase.framework -Google Mobile Ads (stub) | libfirebase_gma.a -| | libfirebase_app.a Firebase Installations (stub) | firebase_installations.framework | | firebase.framework Firebase Cloud Messaging (stub) | firebase_messaging.framework @@ -488,8 +464,6 @@ Firebase Analytics (stub) | firebase_analytics.lib | | firebase_app.lib Firebase Dynamic Links (stub) | firebase_dynamic_links.lib | | firebase_app.lib -Google Mobile Ads (stub) | firebase_gma.lib -| | firebase_app.lib Firebase Installations (stub) | firebase_installations.lib | | firebase_app.lib Firebase Cloud Messaging (stub) | firebase_messaging.lib @@ -631,24 +605,11 @@ Firestore | Required Functions | Required Installations | Not Required Instance ID | Required -Google Mobile Ads | Not required (usually; see below) Realtime Database | Required Remote Config | Required Storage | Required User Messaging Platform | Not required -#### A note on Google Mobile Ads and Google Play services - -Most versions of the Google Mobile Ads SDK for Android can work properly without -Google Play services. However, if you are using the -`com.google.android.gms:play-services-ads-lite` dependency instead of the -standard `com.google.firebase:firebase-ads` dependency, Google Play services -WILL be required in your specific case. - -GMA initialization will only return `kInitResultFailedMissingDependency` when -Google Play services is unavailable AND you are using -`com.google.android.gms:play-services-ads-lite`. - ### Desktop project setup To use desktop workflow support, you must have an Android or iOS project set up @@ -683,6 +644,9 @@ code. provides a more direct way for Firebase to interact with your specified AppDelegate. See "Platform Notes > iOS Method Swizzling > Specifying Your AppDelegate Class Directly (iOS)" for details. + - Google Mobile Ads (GMA) has been removed from the Firebase C++ SDK. + It was previously deprecated. For more information, see the + [SDK documentation](https://developers.google.com/admob/cpp/sdk). ### 12.8.0 - Changes diff --git a/scripts/gha-encrypted/gma/GoogleService-Info.plist.gpg b/scripts/gha-encrypted/gma/GoogleService-Info.plist.gpg deleted file mode 100644 index 65b703ce7e..0000000000 Binary files a/scripts/gha-encrypted/gma/GoogleService-Info.plist.gpg and /dev/null differ diff --git a/scripts/gha-encrypted/gma/google-services.json.gpg b/scripts/gha-encrypted/gma/google-services.json.gpg deleted file mode 100644 index c46f596425..0000000000 Binary files a/scripts/gha-encrypted/gma/google-services.json.gpg and /dev/null differ diff --git a/scripts/gha/build_ios_tvos.py b/scripts/gha/build_ios_tvos.py index 77e7cd5796..434c30610a 100644 --- a/scripts/gha/build_ios_tvos.py +++ b/scripts/gha/build_ios_tvos.py @@ -51,10 +51,9 @@ 'supported_targets' : ('firebase_analytics', 'firebase_app_check', 'firebase_auth', 'firebase_database', 'firebase_dynamic_links', 'firebase_firestore', - 'firebase_functions', 'firebase_gma', - 'firebase_installations', 'firebase_messaging', - 'firebase_remote_config', 'firebase_storage', - 'firebase_ump'), + 'firebase_functions', 'firebase_installations', + 'firebase_messaging', 'firebase_remote_config', + 'firebase_storage', 'firebase_ump'), 'device': { 'architectures' : ['arm64'], 'toolchain' : 'cmake/toolchains/ios.cmake', @@ -591,9 +590,9 @@ def parse_cmdline_args(): default=( 'firebase_analytics', 'firebase_app_check', 'firebase_auth', 'firebase_database', 'firebase_dynamic_links', 'firebase_firestore', - 'firebase_functions', 'firebase_gma', - 'firebase_installations', 'firebase_messaging', - 'firebase_remote_config', 'firebase_storage', 'firebase_ump'), + 'firebase_functions', 'firebase_installations', + 'firebase_messaging', 'firebase_remote_config', + 'firebase_storage', 'firebase_ump'), help='List of CMake build targets') parser.add_argument('-o', '--os', nargs='+', default=('ios', 'tvos'), help='List of operating systems to build for.') diff --git a/scripts/gha/integration_testing/build_testapps.json b/scripts/gha/integration_testing/build_testapps.json index 4e0c479144..f20b0ccbeb 100755 --- a/scripts/gha/integration_testing/build_testapps.json +++ b/scripts/gha/integration_testing/build_testapps.json @@ -98,20 +98,6 @@ ], "provision": "Firebase_Dev_Wildcard.mobileprovision" }, - { - "name": "gma", - "full_name": "FirebaseGma", - "bundle_id": "com.google.ios.admob.testapp", - "ios_target": "integration_test", - "tvos_target": "", - "has_uitests": true, - "testapp_path": "gma/integration_test", - "frameworks": [ - "firebase_gma.xcframework", - "firebase.xcframework" - ], - "provision": "Google_Development.mobileprovision" - }, { "name": "ump", "full_name": "FirebaseUmp", @@ -273,7 +259,6 @@ "'dynamic_links' : ['com.google.firebase:firebase-dynamic-links:[0,)'],", "'firestore' : ['com.google.firebase:firebase-firestore:[0,)'],", "'functions' : ['com.google.firebase:firebase-functions:[0,)'],", - "'gma' : ['com.google.firebase:firebase-ads:[0,)',", "'instance_id' : ['com.google.firebase:firebase-iid:[0,)'],", "'messaging' : ['com.google.firebase.messaging.cpp:firebase_messaging_cpp@aar',", "'com.google.firebase:firebase-messaging:[0,)'],", diff --git a/scripts/gha/print_matrix_configuration.py b/scripts/gha/print_matrix_configuration.py index 3dd900d1c2..bdb32afd31 100644 --- a/scripts/gha/print_matrix_configuration.py +++ b/scripts/gha/print_matrix_configuration.py @@ -134,7 +134,7 @@ } }, "config": { - "apis": "analytics,app_check,auth,database,dynamic_links,firestore,functions,gma,installations,messaging,remote_config,storage", + "apis": "analytics,app_check,auth,database,dynamic_links,firestore,functions,installations,messaging,remote_config,storage", "mobile_test_on": "real,virtual" } }, @@ -316,9 +316,11 @@ def scan_changes_in_file(parm_key, auto_diff, path, requested_api_list): change_lines = [l for l in change_lines if len(l) > 20] changed_apis = set() for line in change_lines: - if ("Google-Mobile-Ads" in line or "GoogleUserMessagingPlatform" in line or - "play-services-ads" in line or "user-messaging-platform" in line): - changed_apis.add("gma") + if ("GoogleUserMessagingPlatform" in line or + "user-messaging-platform" in line): + # This is for UMP, not GMA, so keep it if UMP is in requested_api_list + if "ump" in requested_api_list: + changed_apis.add("ump") else: changed_apis.update(requested_api_list) break diff --git a/scripts/gha/report_build_status.py b/scripts/gha/report_build_status.py index 8c41169f33..0823c4704f 100644 --- a/scripts/gha/report_build_status.py +++ b/scripts/gha/report_build_status.py @@ -191,8 +191,6 @@ def format_errors(all_errors, severity, event): if product == 'missing_log': product_name = 'missing logs' - elif product == 'gma': - product_name = product.upper() elif product == 'ump': product_name = product.upper() else: @@ -726,9 +724,11 @@ def main(argv): else: test_name_str = test_name + product_display_name = product.replace("_", " ").title() + print("| %d | %s | %s | %s | %s %s
   Logs: %s |" % ( test_list[test_id]['count'], latest, - product, platform, + product_display_name, platform, test_name_str, severity, " ".join(link_list))) else: print("%d\t%s\t%s\t%s\t%s\t%s" % (test_list[test_id]['count'], latest, severity, product, platform, test_name)) diff --git a/scripts/gha/ui_testing/uitest_android/app/src/androidTest/java/com/google/firebase/uitest/UITest.java b/scripts/gha/ui_testing/uitest_android/app/src/androidTest/java/com/google/firebase/uitest/UITest.java index 40a46427e3..0add3168aa 100644 --- a/scripts/gha/ui_testing/uitest_android/app/src/androidTest/java/com/google/firebase/uitest/UITest.java +++ b/scripts/gha/ui_testing/uitest_android/app/src/androidTest/java/com/google/firebase/uitest/UITest.java @@ -41,78 +41,12 @@ public class UITest { private static final String TAG = "UITestResult"; - private static final String GMA_PACKAGE = "com.google.android.admob.testapp"; - private static final String MESSAGING_PACKAGE = "com.google.firebase.cpp.messaging.testapp"; private static final int DEFAULT_TIMEOUT = 5000; private static final int WAIT_UI_TIMEOUT = 30000; - @Test - public void testGMA() throws UiObjectNotFoundException, InterruptedException { - // Start from the home screen & Launch the app - UiDevice device = UiDevice.getInstance(getInstrumentation()); - device.pressHome(); - launchApp(GMA_PACKAGE); - device.wait(Until.hasObject(By.pkg(GMA_PACKAGE).depth(0)), - DEFAULT_TIMEOUT); // Wait for the app to appear - Log.e(TAG, "GMA launched"); - - // 1 TestAdViewAdOpenedAdClosed - UiObject2 reference = device.wait(Until.findObject(By.text("Test Ad")), 60 * 1000); - Assert.assertNotNull(reference); - Log.e(TAG, "TestAdVie loaded"); - Thread.sleep(DEFAULT_TIMEOUT); - // click on the bottom of the "Test Ad" TextView, where the Ad present - int x = reference.getVisibleBounds().centerX(); - int y = reference.getVisibleBounds().bottom + 5; - device.click(x, y); - Thread.sleep(DEFAULT_TIMEOUT); - device.pressBack(); // back to testapp - Log.e(TAG, "TestAdViewAdClick closed"); - - Thread.sleep(DEFAULT_TIMEOUT); - - // 2 TestInterstitialAdLoadAndShow - reference = device.wait(Until.findObject(By.text("Test Ad")), WAIT_UI_TIMEOUT); - Assert.assertNotNull(reference); - Log.e(TAG, "InterstitialAd2 loaded"); - Thread.sleep(DEFAULT_TIMEOUT); - // click the center point of the device, where the Ad present - x = device.getDisplayWidth() / 2; - y = device.getDisplayHeight() / 2; - device.click(x, y); - Log.e(TAG, "InterstitialAd2 clicked"); - Thread.sleep(DEFAULT_TIMEOUT); - device.pressBack(); // back to testapp - Thread.sleep(DEFAULT_TIMEOUT); - // click the top left corner close bottom. - // Use "Test Ad" TextView bottom position as the reference - x = reference.getVisibleBounds().bottom; - y = reference.getVisibleBounds().bottom; - device.click(x, y); - Log.e(TAG, "InterstitialAd2 closed"); - - Thread.sleep(DEFAULT_TIMEOUT); - - // 3 TestRewardedAdLoadAndShow - reference = device.wait(Until.findObject(By.text("Test Ad")), WAIT_UI_TIMEOUT); - Assert.assertNotNull(reference); - Log.e(TAG, "RewardedAd loaded"); - // click the top right corner close bottom. - x = device.getDisplayWidth() - reference.getVisibleBounds().bottom; - y = reference.getVisibleBounds().bottom; - Thread.sleep(30 * 1000); - device.click(x, y); - Log.e(TAG, "RewardedAd closed"); - - // Finish GMA Tests - Thread.sleep(60 * 1000); - // reference = device.wait(Until.findObject(By.text("Test Ad")), WAIT_UI_TIMEOUT); - // Assert.assertNull(reference); - } - private void launchApp(String packageName) { Context context = getApplicationContext(); Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName); diff --git a/scripts/gha/ui_testing/uitest_apple/FirebaseCppUITestAppUITests/FirebaseCppUITestAppUITests.swift b/scripts/gha/ui_testing/uitest_apple/FirebaseCppUITestAppUITests/FirebaseCppUITestAppUITests.swift index 708606fce9..65cac05d61 100644 --- a/scripts/gha/ui_testing/uitest_apple/FirebaseCppUITestAppUITests/FirebaseCppUITestAppUITests.swift +++ b/scripts/gha/ui_testing/uitest_apple/FirebaseCppUITestAppUITests/FirebaseCppUITestAppUITests.swift @@ -21,115 +21,6 @@ import XCTest class FirebaseCppUITestAppUITests: XCTestCase { - func testGMA() { - // Launch this Helper App - let helperApp = XCUIApplication() - - // Periodically check and dismiss dialogs with "Allow" or "OK" - Timer.scheduledTimer(withTimeInterval: 5, repeats: true) { (_) in -#if os(iOS) - NSLog("finding springboard ...") - let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard") - for button in [springboard.buttons["Open"], springboard.buttons["Allow"], springboard.buttons["OK"]] { - if button.exists { - NSLog("Dismissing system dialog") - button.tap() - } - } -#elseif os(tvOS) - NSLog("finding pineboard ...") - let pineboard = XCUIApplication(bundleIdentifier: "com.apple.PineBoard") - for button in [pineboard.buttons["Open"], pineboard.buttons["Allow"], pineboard.buttons["OK"]] { - if button.exists { - NSLog("Dismissing system dialog") - let remote: XCUIRemote = XCUIRemote.shared - remote.press(.select) - } - } -#endif - } - - // Launch UI Test App - helperApp.launch() - // Wait until UI Test App open Integration Test App - helperApp.wait(for: .runningBackground, timeout: 20) - - // Wait until Integration Test App closed (testing finished) - let expectation = XCTestExpectation(description: "Integration Test App closed") - Timer.scheduledTimer(withTimeInterval: 5, repeats: true) { (_) in - if helperApp.state == .runningForeground { - NSLog("Integration Test App closed... UI Test App back to foreground...") - expectation.fulfill() - } else { - NSLog("Testing... UI Test App in background...") - } - } - - - // Start Automated UI Test - let app = XCUIApplication(bundleIdentifier: "com.google.ios.admob.testapp") - - // 1. TestAdViewAdOpenedAdClosed - var reference = app.staticTexts["Test mode"] - XCTAssertTrue(reference.waitForExistence(timeout: 60)) - // Click on the center point of the "Test Ad" TextView, where the Ad present - var x = (reference.frame.origin.x + reference.frame.width)/2 - var y = (reference.frame.origin.y + reference.frame.height)/2 - sleep(5) // Wait until button hittable - let ad_view = app.findElement(at: CGPoint(x: x, y: y)) - ad_view.tap() - sleep(5) - app.activate() - - sleep(5) - - // 2. TestInterstitialAdLoadAndShow - reference = app.staticTexts["Test mode"] - XCTAssertTrue(reference.waitForExistence(timeout: 60)) - // Click the center point of the device, where the Ad present - x = app.frame.width/2 - y = app.frame.height/2 - sleep(5) // Wait until button hittable - let interstitial_ad = app.findElement(at: CGPoint(x: x, y: y)) - interstitial_ad.tap() - sleep(5) - app.activate() - sleep(5) - // Click the top left corner close bottom. - // Use "Test Ad" TextView bottom position as the reference - x = (reference.frame.origin.y + reference.frame.height)/2 - y = (reference.frame.origin.y + reference.frame.height)/2 - sleep(5) // Wait until button hittable - let interstitial_ad_close_button = app.findElement(at: CGPoint(x: x, y: y)) - interstitial_ad_close_button.tap() - - sleep(5) - - // 3. TestRewardedAdLoadAndShow - reference = app.staticTexts["Test mode"] - XCTAssertTrue(reference.waitForExistence(timeout: 60)) - // Click the top right corner close bottom. - x = app.frame.width - (reference.frame.origin.y + reference.frame.height)/2 - y = (reference.frame.origin.y + reference.frame.height)/2 - sleep(15) // Wait until button hittable - let rewarded_ad_close_button = app.findElement(at: CGPoint(x: x, y: y)) - rewarded_ad_close_button.tap() - - let close_video_button = app.webViews.staticTexts["CLOSE VIDEO"] - if close_video_button.waitForExistence(timeout: 5) { - sleep(5) - close_video_button.tap() - sleep(5) - rewarded_ad_close_button.tap() - } - - // Finish GMA Tests - sleep(60) - reference = app.staticTexts["Test mode"] - XCTAssertFalse(reference.exists) - app.terminate() - } - } extension XCUIApplication { diff --git a/scripts/update_android_ios_dependencies.py b/scripts/update_android_ios_dependencies.py index f29e3ec07f..c8517f5e4f 100644 --- a/scripts/update_android_ios_dependencies.py +++ b/scripts/update_android_ios_dependencies.py @@ -185,18 +185,6 @@ def get_files(dirs_and_files, file_extension, file_name=None, 'FirebaseStorage', ] -# List of GMA pods we are also interested in. -PODS_GMA = [ - 'Google-Mobile-Ads-SDK', - 'GoogleUserMessagingPlatform' -] - -ANDROID_GMA_PACKAGES = [ - 'firebase-ads', - 'play-services-ads', - 'user-messaging-platform', -] - def get_pod_versions(specs_repo, pods=PODS, ignore_pods=None, allow_experimental=False): """Get available pods and their versions from the specs repo @@ -727,8 +715,6 @@ def parse_cmdline_args(): parser.add_argument('--ignore_android_packages', nargs='+', default=(), help='Ignore Android packages which have any of the items ' 'specified in this list as substrings.') - parser.add_argument('--include_gma', action='store_true', - help='Also update GMA dependencies') parser.add_argument('--depfiles', nargs='+', default=('Android/firebase_dependencies.gradle', 'release_build_files/Android/firebase_dependencies.gradle'), @@ -775,7 +761,7 @@ def main(): if not args.skip_ios: latest_pod_versions_map = get_latest_pod_versions( args.specs_repo, - (PODS + PODS_GMA) if args.include_gma else PODS, + PODS, set(args.ignore_ios_pods), args.allow_experimental) pod_files = get_files(args.podfiles, file_extension='', file_name='Podfile', ignore_directories=set(args.ignore_directories)) @@ -786,11 +772,8 @@ def main(): modify_readme_file_pods(readme_file, latest_pod_versions_map, args.dryrun) if not args.skip_android: - ignore_android_packages = set(args.ignore_android_packages) - if not args.include_gma: - ignore_android_packages.update(ANDROID_GMA_PACKAGES) latest_android_versions_map = get_latest_maven_versions( - ignore_android_packages, args.allow_experimental) + set(args.ignore_android_packages), args.allow_experimental) dep_files = get_files(args.depfiles, file_extension='.gradle', file_name='firebase_dependencies.gradle', ignore_directories=set(args.ignore_directories)) diff --git a/settings.gradle b/settings.gradle index ad2d909d3d..759afe58eb 100644 --- a/settings.gradle +++ b/settings.gradle @@ -14,8 +14,6 @@ include ':app', ':firestore', ':firestore:firestore_resources', ':functions', - ':gma', - ':gma:gma_resources', ':installations', ':messaging', ':messaging:messaging_java', diff --git a/setup_integration_tests.py b/setup_integration_tests.py index 6565df3d4d..93fa787aa0 100755 --- a/setup_integration_tests.py +++ b/setup_integration_tests.py @@ -40,7 +40,6 @@ 'firestore/integration_test', 'firestore/integration_test_internal', 'functions/integration_test', - 'gma/integration_test', 'installations/integration_test', 'messaging/integration_test', 'remote_config/integration_test',