diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index f1834b3d1c..cdd35932d9 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -51,6 +51,9 @@ jobs: architecture: ${{ fromJson(needs.prepare_matrix.outputs.matrix_architecture) }} python_version: ${{ fromJson(needs.prepare_matrix.outputs.matrix_python_version) }} steps: + - uses: lukka/get-cmake@latest + with: + cmakeVersion: "~3.31.0" - name: setup Xcode version (macos) if: runner.os == 'macOS' run: sudo xcode-select -s /Applications/Xcode_${{ env.xcodeVersion }}.app/Contents/Developer diff --git a/.github/workflows/build-report.yml b/.github/workflows/build-report.yml index 9af62a6bf8..3fdb21d135 100644 --- a/.github/workflows/build-report.yml +++ b/.github/workflows/build-report.yml @@ -5,6 +5,8 @@ on: schedule: - cron: "0 21 * * *" # 9pm UTC = 1pm PST / 2pm PDT, 12 hours after testapps run +permissions: write-all + env: GITHUB_TOKEN: ${{ github.token }} numDays: 7 diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index c1ee5375f0..06b3422adf 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -4,6 +4,8 @@ on: pull_request: types: [opened, reopened, synchronize, labeled, unlabeled] +permissions: write-all + env: triggerLabelFull: "tests-requested: full" triggerLabelQuick: "tests-requested: quick" @@ -51,6 +53,9 @@ jobs: # This check succeeds if Doxygen documentation generates without errors. runs-on: ubuntu-22.04 steps: + - uses: lukka/get-cmake@latest + with: + cmakeVersion: "~3.31.0" - uses: actions/checkout@v3 with: submodules: false diff --git a/.github/workflows/checks_secure.yml b/.github/workflows/checks_secure.yml index c919b374b6..9bd167d0b5 100644 --- a/.github/workflows/checks_secure.yml +++ b/.github/workflows/checks_secure.yml @@ -5,6 +5,8 @@ on: pull_request_target: types: [synchronize] +permissions: write-all + concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} cancel-in-progress: true diff --git a/.github/workflows/cpp-packaging.yml b/.github/workflows/cpp-packaging.yml index 706a30515a..525062c493 100644 --- a/.github/workflows/cpp-packaging.yml +++ b/.github/workflows/cpp-packaging.yml @@ -90,6 +90,9 @@ jobs: # Binutils 2.35.1 released Sep 19, 2020 binutils_version: "2.35.1" steps: + - uses: lukka/get-cmake@latest + with: + cmakeVersion: "~3.31.0" - name: setup Xcode version (macos) if: runner.os == 'macOS' run: sudo xcode-select -s /Applications/Xcode_${{ env.xcodeVersion }}.app/Contents/Developer @@ -188,6 +191,9 @@ jobs: runs-on: macos-13 if: ${{ github.event.inputs.downloadPublicVersion == '' && github.event.inputs.downloadPreviousRun == '' }} steps: + - uses: lukka/get-cmake@latest + with: + cmakeVersion: "~3.31.0" - name: Store git credentials for all git commands # Forces all git commands to use authenticated https, to prevent throttling. shell: bash @@ -248,6 +254,9 @@ jobs: strategy: fail-fast: false steps: + - uses: lukka/get-cmake@latest + with: + cmakeVersion: "~3.31.0" - name: Force Java 11 shell: bash run: echo "JAVA_HOME=${JAVA_HOME_11_X64}" >> $GITHUB_ENV @@ -352,6 +361,9 @@ jobs: architecture: "arm64" steps: + - uses: lukka/get-cmake@latest + with: + cmakeVersion: "~3.31.0" - name: Store git credentials for all git commands # Forces all git commands to use authenticated https, to prevent throttling. shell: bash diff --git a/.github/workflows/desktop.yml b/.github/workflows/desktop.yml index fa1b792cad..36754a1361 100644 --- a/.github/workflows/desktop.yml +++ b/.github/workflows/desktop.yml @@ -95,6 +95,9 @@ jobs: - xcode_version: "11.7" architecture: "arm64" steps: + - uses: lukka/get-cmake@latest + with: + cmakeVersion: "~3.31.0" - name: Store git credentials for all git commands # Forces all git commands to use authenticated https, to prevent throttling. shell: bash @@ -296,6 +299,9 @@ jobs: strategy: fail-fast: false steps: + - uses: lukka/get-cmake@latest + with: + cmakeVersion: "~3.31.0" - uses: actions/checkout@v3 with: ref: ${{needs.check_and_prepare.outputs.github_ref}} diff --git a/.github/workflows/integration_tests.yml b/.github/workflows/integration_tests.yml index ac88fb96dd..ebf18b5d29 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' + default: 'analytics,app_check,auth,database,dynamic_links,firestore,functions,gma,installations,messaging,remote_config,storage,ump' required: true operating_systems: description: 'CSV of VMs to run on' @@ -192,7 +192,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" + apis="analytics,app_check,auth,database,dynamic_links,functions,gma,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. @@ -286,6 +286,9 @@ jobs: ssl_variant: openssl arch: arm64 steps: + - uses: lukka/get-cmake@latest + with: + cmakeVersion: "~3.31.0" - uses: actions/checkout@v3 with: ref: ${{needs.check_and_prepare.outputs.github_ref}} @@ -350,7 +353,7 @@ jobs: elif [[ "${{ github.event.inputs.firestore_dep_source }}" ]]; then additional_flags+=(--cmake_flag=-DFIRESTORE_DEP_SOURCE=${{ github.event.inputs.firestore_dep_source }}) fi - python scripts/gha/build_testapps.py --p Desktop \ + VERBOSE=1 python scripts/gha/build_testapps.py --p Desktop \ --t ${{ needs.check_and_prepare.outputs.apis }} \ --output_directory "${{ github.workspace }}" \ --artifact_name "desktop-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.ssl_variant }}" \ @@ -424,6 +427,9 @@ jobs: matrix: os: ${{ fromJson(needs.check_and_prepare.outputs.matrix_os) }} steps: + - uses: lukka/get-cmake@latest + with: + cmakeVersion: "~3.31.0" - uses: actions/checkout@v3 with: ref: ${{needs.check_and_prepare.outputs.github_ref}} @@ -535,6 +541,9 @@ jobs: matrix: os: [macos-13] steps: + - uses: lukka/get-cmake@latest + with: + cmakeVersion: "~3.31.0" - uses: actions/checkout@v3 with: ref: ${{needs.check_and_prepare.outputs.github_ref}} @@ -640,6 +649,9 @@ jobs: matrix: os: [macos-13] steps: + - uses: lukka/get-cmake@latest + with: + cmakeVersion: "~3.31.0" - uses: actions/checkout@v3 with: ref: ${{needs.check_and_prepare.outputs.github_ref}} @@ -913,7 +925,7 @@ jobs: distribution: 'temurin' java-version: '11' - name: Run Android integration tests on Emulator locally - timeout-minutes: 180 + timeout-minutes: 240 if: steps.device-info.outputs.device_type == 'virtual' run: | python scripts/gha/test_simulator.py --testapp_dir testapps \ @@ -1090,7 +1102,7 @@ jobs: security list-keychains -d user -s tmp-keychain security default-keychain -s tmp-keychain - name: Run iOS integration tests on Simulator locally - timeout-minutes: 180 + timeout-minutes: 240 if: steps.device-info.outputs.device_type == 'virtual' run: | python scripts/gha/test_simulator.py --testapp_dir testapps \ @@ -1101,7 +1113,7 @@ jobs: - id: ftl_test if: steps.device-info.outputs.device_type == 'ftl' uses: FirebaseExtended/github-actions/firebase-test-lab@v1.4 - timeout-minutes: 120 + timeout-minutes: 180 with: credentials_json: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_CREDENTIALS }} testapp_dir: testapps diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index 45dbe79caf..942fdf6090 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -44,6 +44,9 @@ jobs: os: [ 'macos-13' ] xcode_version: ${{ fromJson(needs.prepare_matrix.outputs.matrix_xcode_version) }} steps: + - uses: lukka/get-cmake@latest + with: + cmakeVersion: "~3.31.0" - name: Store git credentials for all git commands # Forces all git commands to use authenticated https, to prevent throttling. shell: bash diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index b39ad3e279..20590ab7d2 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -13,6 +13,8 @@ on: schedule: - cron: "0 16 * * 1" # Mondays, 4pm UTC = 9am PST / 10am PDT +permissions: write-all + env: defaultBranchPattern: "feature_branch/*" defaultMainBranch: "main" diff --git a/Android/firebase_dependencies.gradle b/Android/firebase_dependencies.gradle index ac7691f9a6..1cc13c4ed3 100644 --- a/Android/firebase_dependencies.gradle +++ b/Android/firebase_dependencies.gradle @@ -39,7 +39,8 @@ def firebaseDependenciesMap = [ 'performance' : ['com.google.firebase:firebase-perf'], 'remote_config' : ['com.google.firebase:firebase-config'], 'storage' : ['com.google.firebase:firebase-storage'], - 'testlab' : [] + 'testlab' : [], + 'ump' : ['com.google.android.ump:user-messaging-platform:2.2.0'] ] // A map of library to the gradle resources that they depend upon. @@ -53,7 +54,8 @@ def firebaseResourceDependenciesMap = [ 'firestore' : [':firestore:firestore_resources'], 'gma' : [':gma:gma_resources'], 'remote_config' : [':remote_config:remote_config_resources'], - 'storage' : [':storage:storage_resources'] + 'storage' : [':storage:storage_resources'], + 'ump' : [':ump:ump_resources'] ] def setResourceDependencies(String subproject) { @@ -116,6 +118,9 @@ class Dependencies { def getStorage() { libSet.add('storage') } + def getUmp() { + libSet.add('ump') + } } // Extension to handle which Firebase C++ dependencies are being added to the diff --git a/CMakeLists.txt b/CMakeLists.txt index 439ea7d5c7..9b683ebc95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,8 @@ option(FIREBASE_INCLUDE_FUNCTIONS ${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 "Include the Firebase Installations library." ${FIREBASE_INCLUDE_LIBRARY_DEFAULT}) @@ -123,9 +125,10 @@ if(FIREBASE_CPP_BUILD_TESTS OR FIREBASE_CPP_BUILD_STUB_TESTS) endif() if (PLATFORM STREQUAL TVOS OR PLATFORM STREQUAL SIMULATOR_TVOS) - # GMA and FDL are not supported on tvOS. + # GMA, 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() # Occasionally ANDROID is not being set correctly when invoked by gradle, so @@ -630,6 +633,9 @@ endif() if (FIREBASE_INCLUDE_GMA) add_subdirectory(gma) endif() +if (FIREBASE_INCLUDE_UMP) + add_subdirectory(ump) +endif() if (FIREBASE_INCLUDE_INSTALLATIONS) add_subdirectory(installations) endif() diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 4aefc3a36c..9b2d0b333a 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -566,6 +566,10 @@ if (IOS) ${FIREBASE_SOURCE_DIR}/storage/src/include/firebase/storage/listener.h ${FIREBASE_SOURCE_DIR}/storage/src/include/firebase/storage/metadata.h ${FIREBASE_SOURCE_DIR}/storage/src/include/firebase/storage/storage_reference.h) + set(ump_HDRS + ${FIREBASE_SOURCE_DIR}/ump/src/include/firebase/ump.h + ${FIREBASE_SOURCE_DIR}/ump/src/include/firebase/ump/consent_info.h + ${FIREBASE_SOURCE_DIR}/ump/src/include/firebase/ump/types.h) list(APPEND framework_HDRS src/include/firebase/internal/platform.h @@ -580,7 +584,9 @@ if (IOS) ${installations_HDRS} ${messaging_HDRS} ${remote_config_HDRS} - ${storage_HDRS}) + ${storage_HDRS} + ${ump_HDRS} + ) # add framework header files to target target_sources(firebase_app PRIVATE ${framework_HDRS}) diff --git a/build_scripts/ios/build.sh b/build_scripts/ios/build.sh index 12ac66e93b..c466d35af7 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) +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) # build default value buildpath="ios_build" diff --git a/build_scripts/packaging.conf b/build_scripts/packaging.conf index fd082f4b54..8f1ee6f401 100644 --- a/build_scripts/packaging.conf +++ b/build_scripts/packaging.conf @@ -3,4 +3,4 @@ # 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 -remote_config storage) +remote_config storage ump) diff --git a/gma/src/include/firebase/gma/ump/consent_info.h b/gma/src/include/firebase/gma/ump/consent_info.h index 8f69918ed0..40b80baef3 100644 --- a/gma/src/include/firebase/gma/ump/consent_info.h +++ b/gma/src/include/firebase/gma/ump/consent_info.h @@ -20,6 +20,7 @@ #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 @@ -32,6 +33,9 @@ namespace gma { /// /// 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 { @@ -46,6 +50,8 @@ class ConsentInfoInternal; /// /// 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. @@ -64,6 +70,9 @@ class ConsentInfo { /// 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); @@ -93,6 +102,7 @@ class ConsentInfo { /// 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); @@ -101,6 +111,7 @@ class ConsentInfo { // 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) @@ -120,12 +131,18 @@ class ConsentInfo { /// /// @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 @@ -134,20 +151,35 @@ class ConsentInfo { /// 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 @@ -163,9 +195,15 @@ class ConsentInfo { /// /// @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 @@ -180,14 +218,23 @@ class ConsentInfo { /// /// @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 @@ -206,19 +253,31 @@ class ConsentInfo { /// /// @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: diff --git a/gma/src/include/firebase/gma/ump/types.h b/gma/src/include/firebase/gma/ump/types.h index 0684858582..cce119f56b 100644 --- a/gma/src/include/firebase/gma/ump/types.h +++ b/gma/src/include/firebase/gma/ump/types.h @@ -21,6 +21,7 @@ #include #include +#include "firebase/internal/common.h" #include "firebase/internal/platform.h" #if FIREBASE_PLATFORM_ANDROID @@ -37,6 +38,8 @@ 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, @@ -49,6 +52,8 @@ enum ConsentDebugGeography { /// 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) {} @@ -61,6 +66,8 @@ struct ConsentDebugSettings { }; /// 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) {} @@ -92,6 +99,8 @@ typedef void* FormParent; // 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, @@ -104,6 +113,8 @@ enum ConsentStatus { }; /// 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, @@ -126,6 +137,8 @@ enum ConsentRequestError { }; /// 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. @@ -139,6 +152,8 @@ enum ConsentFormStatus { }; /// 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, @@ -161,6 +176,8 @@ enum ConsentFormError { }; /// 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. diff --git a/release_build_files/Android/firebase_dependencies.gradle b/release_build_files/Android/firebase_dependencies.gradle index ede4076af2..6a6ab2740b 100644 --- a/release_build_files/Android/firebase_dependencies.gradle +++ b/release_build_files/Android/firebase_dependencies.gradle @@ -39,7 +39,8 @@ def firebaseDependenciesMap = [ 'performance' : ['com.google.firebase:firebase-perf'], 'remote_config' : ['com.google.firebase:firebase-config'], 'storage' : ['com.google.firebase:firebase-storage'], - 'testlab' : [] + 'testlab' : [], + 'ump' : ['com.google.android.ump:user-messaging-platform:2.2.0'] ] // Handles adding the Firebase C++ dependencies as properties. @@ -98,6 +99,9 @@ class Dependencies { def getTestlab() { libSet.add('testlab') } + def getUmp() { + libSet.add('ump') + } } // Extension to handle which Firebase C++ dependencies are being added to the diff --git a/release_build_files/CMakeLists.txt b/release_build_files/CMakeLists.txt index e9e341e0aa..594440937d 100644 --- a/release_build_files/CMakeLists.txt +++ b/release_build_files/CMakeLists.txt @@ -103,6 +103,7 @@ add_firebase_target(firebase_performance) add_firebase_target(firebase_remote_config) add_firebase_target(firebase_storage) add_firebase_target(firebase_testlab) +add_firebase_target(firebase_ump) # Auth on Linux desktop has an additional dependency on libsecret, # which needs to be added. If it cannot be found, we don't want to diff --git a/release_build_files/readme.md b/release_build_files/readme.md index ae6d754b2c..48e1b565ba 100644 --- a/release_build_files/readme.md +++ b/release_build_files/readme.md @@ -10,12 +10,13 @@ on *iOS* and *Android*: * Firebase Dynamic Links (deprecated SDK) * Cloud Firestore * Firebase Functions -* Google Mobile Ads (with User Messaging Platform) +* Google Mobile Ads (deprecated SDK) * Firebase Installations * Firebase Instance ID (deprecated SDK) * Firebase Realtime Database * Firebase Remote Config * Firebase Storage +* User Messaging Platform ## Desktop Workflow Implementations @@ -174,6 +175,12 @@ Firebase Storage | libfirebase_storage.a | | (Maven package) | | com.google.firebase:firebase-auth | | (Maven package) +User Messaging Platform | libfirebase_ump.a +| | libfirebase_app.a +| | com.google.firebase:firebase-analytics +| | (Maven package) +| | com.google.android.ump:user-messaging-platform:2.2.0 +| | (Maven package) Google Play services module| com.google.android.gms:play-services-base:18.6.0 | | (Maven package) @@ -206,6 +213,7 @@ firebaseCpp.dependencies { messaging remoteConfig storage + ump } ``` @@ -274,6 +282,10 @@ Firebase Storage | firebase_storage.xcframework | | firebase.xcframework | | Firebase/Storage Cocoapod (11.10.0) | | Firebase/Auth Cocoapod (11.10.0) +User Messaging Platform | firebase_ump.xcframework +| | firebase.xcframework +| | Firebase/CoreOnly Cocoapod (11.10.0) +| | GoogleUserMessagingPlatform Cocoapod (2.3.0) Important: Each version of the Firebase C++ SDK supports a specific version of the Firebase iOS SDK. Please ensure that you reference the Cocoapod versions @@ -337,6 +349,10 @@ Firebase Storage | libfirebase_storage.a | | libfirebase_auth.a | | Firebase/Storage Cocoapod (11.10.0) | | Firebase/Auth Cocoapod (11.10.0) +User Messaging Platform | libfirebase_ump.a +| | libfirebase_app.a +| | Firebase/CoreOnly Cocoapod (11.10.0) +| | GoogleUserMessagingPlatform Cocoapod (2.3.0) Important: Each version of the Firebase C++ SDK supports a specific version of the Firebase iOS SDK. Please ensure that you reference the Cocoapod versions @@ -387,6 +403,8 @@ Firebase Installations (stub) | libfirebase_installations.a | | libfirebase_app.a Firebase Cloud Messaging (stub) | libfirebase_messaging.a | | libfirebase_app.a +User Messaging Platform (stub) | libfirebase_ump.a +| | libfirebase_app.a The provided libraries have been tested using GCC 4.8.0, GCC 7.2.0, and Clang 5.0 on Ubuntu. When building C++ desktop apps on Linux, you will need to link @@ -430,6 +448,8 @@ Firebase Installations (stub) | firebase_installations.framework | | firebase.framework Firebase Cloud Messaging (stub) | firebase_messaging.framework | | firebase.framework +User Messaging Platform (stub) | libfirebase_ump.a +| | libfirebase_app.a The provided libraries have been tested using Xcode 14.1. When building C++ desktop apps on OS X, you will need to link the `gssapi_krb5` and `pthread` @@ -474,6 +494,8 @@ Firebase Installations (stub) | firebase_installations.lib | | firebase_app.lib Firebase Cloud Messaging (stub) | firebase_messaging.lib | | firebase_app.lib +User Messaging Platform (stub) | firebase_ump.lib +| | firebase_app.lib The provided libraries have been tested using Visual Studio 2019. When building C++ desktop apps on Windows, you will need to link the following @@ -577,21 +599,22 @@ initialization status. These can be used without Google Play services. The table below summarizes whether Google Play services is required by each Firebase C++ library. -Firebase C++ Library | Google Play services required? --------------------- | --------------------------------- -Analytics | Not required -App Check | Not required -Cloud Messaging | Required -Auth | Required -Dynamic Links | Required -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 +Firebase C++ Library | Google Play services required? +------------------------ | --------------------------------- +Analytics | Not required +App Check | Not required +Cloud Messaging | Required +Auth | Required +Dynamic Links | Required +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 @@ -631,6 +654,13 @@ workflow use only during the development of your app, not for publicly shipping code. ## Release Notes +### 12.8.0 +- Changes + - UMP: Moved the User Messaging Platform SDK to its own top-level + library and to the firebase::ump namespace. The version in the + GMA library (in firebase::gma::ump) has been deprecated and will + be removed soon. + ### 12.7.0 - Changes - General (iOS): Update to Firebase Cocoapods version 11.10.0. diff --git a/scripts/gha-encrypted/ump/GoogleService-Info.plist.gpg b/scripts/gha-encrypted/ump/GoogleService-Info.plist.gpg new file mode 100644 index 0000000000..65b703ce7e Binary files /dev/null and b/scripts/gha-encrypted/ump/GoogleService-Info.plist.gpg differ diff --git a/scripts/gha-encrypted/ump/google-services.json.gpg b/scripts/gha-encrypted/ump/google-services.json.gpg new file mode 100644 index 0000000000..c46f596425 Binary files /dev/null and b/scripts/gha-encrypted/ump/google-services.json.gpg differ diff --git a/scripts/gha/build_ios_tvos.py b/scripts/gha/build_ios_tvos.py index d314024e58..77e7cd5796 100644 --- a/scripts/gha/build_ios_tvos.py +++ b/scripts/gha/build_ios_tvos.py @@ -53,7 +53,8 @@ 'firebase_dynamic_links', 'firebase_firestore', 'firebase_functions', 'firebase_gma', 'firebase_installations', 'firebase_messaging', - 'firebase_remote_config', 'firebase_storage'), + 'firebase_remote_config', 'firebase_storage', + 'firebase_ump'), 'device': { 'architectures' : ['arm64'], 'toolchain' : 'cmake/toolchains/ios.cmake', @@ -592,7 +593,7 @@ def parse_cmdline_args(): 'firebase_dynamic_links', 'firebase_firestore', 'firebase_functions', 'firebase_gma', 'firebase_installations', 'firebase_messaging', - 'firebase_remote_config', 'firebase_storage'), + '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 aa57936b3d..4e0c479144 100755 --- a/scripts/gha/integration_testing/build_testapps.json +++ b/scripts/gha/integration_testing/build_testapps.json @@ -112,6 +112,19 @@ ], "provision": "Google_Development.mobileprovision" }, + { + "name": "ump", + "full_name": "FirebaseUmp", + "bundle_id": "com.google.ios.admob.testapp", + "ios_target": "integration_test", + "tvos_target": "", + "testapp_path": "ump/integration_test", + "frameworks": [ + "firebase_ump.xcframework", + "firebase.xcframework" + ], + "provision": "Google_Development.mobileprovision" + }, { "name": "installations", "full_name": "FirebaseInstallations", diff --git a/scripts/gha/print_matrix_configuration.py b/scripts/gha/print_matrix_configuration.py index e41c70f5ac..4d07dbfd44 100644 --- a/scripts/gha/print_matrix_configuration.py +++ b/scripts/gha/print_matrix_configuration.py @@ -205,25 +205,24 @@ "emulator_latest": [ {"type": "virtual", "image":"system-images;android-32;google_apis;x86_64"} ], "emulator_32bit": [ {"type": "virtual", "image":"system-images;android-30;google_apis;x86"} ], "ios_min": [ - # Slightly different OS versions because of limited FTL selection. - {"type": "ftl", "device": "model=iphone8,version=14.7"}, - {"type": "ftl", "device": "model=iphone11pro,version=14.7"}, - {"type": "ftl", "device": "model=iphone12pro,version=14.8"}, - ], - "ios_target": [ # Slightly different OS versions because of limited FTL selection. {"type": "ftl", "device": "model=iphone13pro,version=15.7"}, {"type": "ftl", "device": "model=iphone8,version=15.7"}, ], - "ios_latest": [ + "ios_target": [ + # Slightly different OS versions because of limited FTL selection. {"type": "ftl", "device": "model=iphone14pro,version=16.6"}, {"type": "ftl", "device": "model=iphone11pro,version=16.6"}, {"type": "ftl", "device": "model=iphone8,version=16.6"}, {"type": "ftl", "device": "model=ipad10,version=16.6"}, ], - "simulator_min": [ {"type": "virtual", "name":"iPhone 15 Pro Max", "version":"17.0.1"} ], + "ios_latest": [ + {"type": "ftl", "device": "model=iphone15,version=18.0"}, + {"type": "ftl", "device": "model=iphone15pro,version=18.0"}, + ], + "simulator_min": [ {"type": "virtual", "name":"iPhone 15 Pro Max", "version":"17.2"} ], "simulator_target": [ {"type": "virtual", "name":"iPhone 15 Pro Max", "version":"17.2"} ], - "simulator_latest": [ {"type": "virtual", "name":"iPhone 15 Plus", "version":"17.4"} ], + "simulator_latest": [ {"type": "virtual", "name":"iPhone 15 Pro", "version":"17.4"} ], "tvos_simulator": [ {"type": "virtual", "name":"Apple TV", "version":"16.1"} ], } diff --git a/scripts/gha/report_build_status.py b/scripts/gha/report_build_status.py index 38a280da46..29cf437343 100644 --- a/scripts/gha/report_build_status.py +++ b/scripts/gha/report_build_status.py @@ -193,6 +193,8 @@ def format_errors(all_errors, severity, event): product_name = 'missing logs' elif product == 'gma': product_name = product.upper() + elif product == 'ump': + product_name = product.upper() else: product_name = product.replace('_', ' ').title() @@ -664,6 +666,7 @@ def main(argv): latest = latest.replace(" ", " ") product = product.replace("_", " ") product = product.upper() if product == "gma" else product.title() + product = product.upper() if product == "ump" else product.title() if len(test_list[test_id]['links']) > 0: latest = "[%s](%s)" % (latest, test_list[test_id]['links'][-1]) diff --git a/settings.gradle b/settings.gradle index 0ec81050fc..ad2d909d3d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -22,4 +22,6 @@ include ':app', ':remote_config', ':remote_config:remote_config_resources', ':storage', - ':storage:storage_resources' \ No newline at end of file + ':storage:storage_resources', + ':ump', + ':ump:ump_resources' diff --git a/setup_integration_tests.py b/setup_integration_tests.py index 7c37e12fc8..6565df3d4d 100755 --- a/setup_integration_tests.py +++ b/setup_integration_tests.py @@ -45,6 +45,7 @@ 'messaging/integration_test', 'remote_config/integration_test', 'storage/integration_test', + 'ump/integration_test', ] destinations = sys.argv[1:] if len(sys.argv) > 1 else DEFAULT_DESTINATIONS diff --git a/ump/CMakeLists.txt b/ump/CMakeLists.txt new file mode 100644 index 0000000000..2739decefa --- /dev/null +++ b/ump/CMakeLists.txt @@ -0,0 +1,114 @@ +# 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_ump library + +# Common source files used by all platforms +set(common_SRCS + src/common/consent_info.cc + src/common/consent_info_internal.cc +) + +# Define the resource build needed for Android +firebase_cpp_gradle(":ump:ump_resources:generateDexJarRelease" + "${CMAKE_CURRENT_LIST_DIR}/ump_resources/build/ump_resources_lib.jar") +binary_to_array("ump_resources" + "${CMAKE_CURRENT_LIST_DIR}/ump_resources/build/ump_resources_lib.jar" + "firebase_ump" + "${FIREBASE_GEN_FILE_DIR}/ump") + +# Source files used by the Android implementation. +set(android_SRCS + ${ump_resources_source} + src/android/consent_info_internal_android.cc +) + +# Source files used by the iOS implementation. +set(ios_SRCS + src/ios/consent_info_internal_ios.mm +) + +# Source files used by the stub implementation. +set(stub_SRCS + src/stub/consent_info_internal_stub.cc +) + +if(ANDROID) + set(ump_platform_SRCS + "${android_SRCS}") +elseif(IOS) + set(ump_platform_SRCS + "${ios_SRCS}") +else() + set(ump_platform_SRCS + "${stub_SRCS}") +endif() + +add_library(firebase_ump STATIC + ${common_SRCS} + ${ump_platform_SRCS}) + +set_property(TARGET firebase_ump PROPERTY FOLDER "Firebase Cpp") + +# Set up the dependency on Firebase App. +target_link_libraries(firebase_ump + 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_ump + PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/src/include + PRIVATE + ${FIREBASE_CPP_SDK_ROOT_DIR} +) +target_compile_definitions(firebase_ump + 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(ump) +elseif(IOS) + # UMP for iOS uses weak references, which requires enabling Automatic + # Reference Counting (ARC). Also enable BitCode. + target_compile_options(firebase_ump + PUBLIC "-fobjc-arc" "-fembed-bitcode") + target_link_libraries(firebase_ump + PUBLIC "-fembed-bitcode") + + setup_pod_headers( + firebase_ump + POD_NAMES + GoogleUserMessagingPlatform + ) + + # UMP expects the header files to be in a subfolder, so set up a symlink to + # accomplish that. + symlink_pod_headers(firebase_ump GoogleUserMessagingPlatform UserMessagingPlatform) + + if (FIREBASE_XCODE_TARGET_FORMAT STREQUAL "frameworks") + set_target_properties(firebase_ump PROPERTIES + FRAMEWORK TRUE + ) + endif() +endif() + +cpp_pack_library(firebase_ump "") +cpp_pack_public_headers() diff --git a/ump/build.gradle b/ump/build.gradle new file mode 100644 index 0000000000..d2f9f50f9f --- /dev/null +++ b/ump/build.gradle @@ -0,0 +1,90 @@ +// 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_ump' + // 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_UMP=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('ump') + setupDexDependencies(':ump:ump_resources') + preBuild.dependsOn(':app:build') +} diff --git a/ump/integration_test/AndroidManifest.xml b/ump/integration_test/AndroidManifest.xml new file mode 100644 index 0000000000..8aa98a1958 --- /dev/null +++ b/ump/integration_test/AndroidManifest.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ump/integration_test/CMakeLists.txt b/ump/integration_test/CMakeLists.txt new file mode 100644 index 0000000000..5db68bc397 --- /dev/null +++ b/ump/integration_test/CMakeLists.txt @@ -0,0 +1,242 @@ +# 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_ump firebase_app) +set(gtest_libs gtest gmock) +target_link_libraries(${integration_test_target_name} ${firebase_libs} + ${gtest_libs} ${ADDITIONAL_LIBS}) diff --git a/ump/integration_test/Images.xcassets/AppIcon.appiconset/Contents.json b/ump/integration_test/Images.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000000..d8db8d65fd --- /dev/null +++ b/ump/integration_test/Images.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,98 @@ +{ + "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/ump/integration_test/Images.xcassets/LaunchImage.launchimage/Contents.json b/ump/integration_test/Images.xcassets/LaunchImage.launchimage/Contents.json new file mode 100644 index 0000000000..6f870a4629 --- /dev/null +++ b/ump/integration_test/Images.xcassets/LaunchImage.launchimage/Contents.json @@ -0,0 +1,51 @@ +{ + "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/ump/integration_test/Info.plist b/ump/integration_test/Info.plist new file mode 100644 index 0000000000..d2403b9c2c --- /dev/null +++ b/ump/integration_test/Info.plist @@ -0,0 +1,39 @@ + + + + + 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 + CFBundleURLTypes + + + CFBundleURLSchemes + + REPLACE_WITH_REVERSED_CLIENT_ID + firebase-game-loop + firebase-ui-test + + + + + diff --git a/ump/integration_test/LaunchScreen.storyboard b/ump/integration_test/LaunchScreen.storyboard new file mode 100644 index 0000000000..673e0f7e68 --- /dev/null +++ b/ump/integration_test/LaunchScreen.storyboard @@ -0,0 +1,7 @@ + + + + + + + diff --git a/ump/integration_test/LibraryManifest.xml b/ump/integration_test/LibraryManifest.xml new file mode 100644 index 0000000000..a5db8d174d --- /dev/null +++ b/ump/integration_test/LibraryManifest.xml @@ -0,0 +1,23 @@ + + + + + + + diff --git a/ump/integration_test/Podfile b/ump/integration_test/Podfile new file mode 100644 index 0000000000..bb14f01810 --- /dev/null +++ b/ump/integration_test/Podfile @@ -0,0 +1,17 @@ +source 'https://github.com/CocoaPods/Specs.git' +platform :ios, '13.0' +# Firebase UMP test application. +use_frameworks! :linkage => :static + +target 'integration_test' do + platform :ios, '13.0' + pod 'Firebase/CoreOnly', '11.10.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/ump/integration_test/build.gradle b/ump/integration_test/build.gradle new file mode 100644 index 0000000000..2b6eec4e30 --- /dev/null +++ b/ump/integration_test/build.gradle @@ -0,0 +1,102 @@ +// 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 { + ump +} + +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) diff --git a/ump/integration_test/empty.swift b/ump/integration_test/empty.swift new file mode 100644 index 0000000000..b637790955 --- /dev/null +++ b/ump/integration_test/empty.swift @@ -0,0 +1,9 @@ +// +// empty.swift +// integration_test +// +// Created by David Della Bitta on 5/12/22. +// Copyright © 2022 Google. All rights reserved. +// + +import Foundation diff --git a/ump/integration_test/googletest.cmake b/ump/integration_test/googletest.cmake new file mode 100644 index 0000000000..a643a3e2f2 --- /dev/null +++ b/ump/integration_test/googletest.cmake @@ -0,0 +1,35 @@ +# 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/ump/integration_test/gradle.properties b/ump/integration_test/gradle.properties new file mode 100644 index 0000000000..ac891ac594 --- /dev/null +++ b/ump/integration_test/gradle.properties @@ -0,0 +1,2 @@ +android.useAndroidX = true +org.gradle.jvmargs=-Xmx2560m diff --git a/ump/integration_test/gradle/wrapper/gradle-wrapper.jar b/ump/integration_test/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..8c0fb64a86 Binary files /dev/null and b/ump/integration_test/gradle/wrapper/gradle-wrapper.jar differ diff --git a/ump/integration_test/gradle/wrapper/gradle-wrapper.properties b/ump/integration_test/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..2eb04a3b17 --- /dev/null +++ b/ump/integration_test/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#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/ump/integration_test/gradlew b/ump/integration_test/gradlew new file mode 100755 index 0000000000..06eaee39e2 --- /dev/null +++ b/ump/integration_test/gradlew @@ -0,0 +1,178 @@ +#!/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/ump/integration_test/gradlew.bat b/ump/integration_test/gradlew.bat new file mode 100644 index 0000000000..51923e981d --- /dev/null +++ b/ump/integration_test/gradlew.bat @@ -0,0 +1,104 @@ +@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/ump/integration_test/integration_test.xcodeproj/project.pbxproj b/ump/integration_test/integration_test.xcodeproj/project.pbxproj new file mode 100644 index 0000000000..3f0c3ff6ad --- /dev/null +++ b/ump/integration_test/integration_test.xcodeproj/project.pbxproj @@ -0,0 +1,383 @@ +// !$*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/ump/integration_test/proguard.pro b/ump/integration_test/proguard.pro new file mode 100644 index 0000000000..2d04b8a9a5 --- /dev/null +++ b/ump/integration_test/proguard.pro @@ -0,0 +1,2 @@ +-ignorewarnings +-keep,includedescriptorclasses public class com.google.firebase.example.LoggingUtils { * ; } diff --git a/ump/integration_test/res/layout/main.xml b/ump/integration_test/res/layout/main.xml new file mode 100644 index 0000000000..56e8488b7a --- /dev/null +++ b/ump/integration_test/res/layout/main.xml @@ -0,0 +1,28 @@ + + + + + diff --git a/ump/integration_test/res/values/strings.xml b/ump/integration_test/res/values/strings.xml new file mode 100644 index 0000000000..cc3d8f9217 --- /dev/null +++ b/ump/integration_test/res/values/strings.xml @@ -0,0 +1,20 @@ + + + + Firebase UMP Integration Test + diff --git a/ump/integration_test/settings.gradle b/ump/integration_test/settings.gradle new file mode 100644 index 0000000000..7e56f6228e --- /dev/null +++ b/ump/integration_test/settings.gradle @@ -0,0 +1,41 @@ +// 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/ump/integration_test/src/integration_test.cc b/ump/integration_test/src/integration_test.cc new file mode 100644 index 0000000000..97ff0c3976 --- /dev/null +++ b/ump/integration_test/src/integration_test.cc @@ -0,0 +1,836 @@ +// 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/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 { + +// Sample test device IDs to use in making the request. +// You can replace these with actual device IDs for UMP tests +// to work on hardware devices. +const std::vector kTestDeviceIDs = { + "2077ef9a63d2b398840261c8221a0c9b", "098fe087d987c9a878965454a65654d7"}; + +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 FirebaseUmpTest : public FirebaseTest { + public: + FirebaseUmpTest() : 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); + + static void SetUpTestSuite(); + static void TearDownTestSuite(); + + void SetUp() override; + void TearDown() override; + + protected: + static firebase::App* shared_app_; + firebase::ump::ConsentInfo* consent_info_; +}; + +firebase::App* FirebaseUmpTest::shared_app_ = nullptr; + +void FirebaseUmpTest::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) +} + +void FirebaseUmpTest::TearDownTestSuite() { + LogDebug("Shutdown Firebase App."); + delete shared_app_; + shared_app_ = nullptr; +} + +void FirebaseUmpTest::InitializeUmp(ResetOption reset) { + using firebase::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 FirebaseUmpTest::TerminateUmp(ResetOption reset) { + if (consent_info_) { + if (reset == kReset) { + consent_info_->Reset(); + } + delete consent_info_; + consent_info_ = nullptr; + } +} + +void FirebaseUmpTest::SetUp() { + InitializeUmp(); + ASSERT_NE(consent_info_, nullptr); +} + +void FirebaseUmpTest::TearDown() { TerminateUmp(); } + +// Tests for User Messaging Platform +TEST_F(FirebaseUmpTest, 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(FirebaseUmpTest, TestUmpDefaultsToUnknownStatus) { + EXPECT_EQ(consent_info_->GetConsentStatus(), + firebase::ump::kConsentStatusUnknown); + EXPECT_EQ(consent_info_->GetConsentFormStatus(), + firebase::ump::kConsentFormStatusUnknown); + EXPECT_EQ(consent_info_->GetPrivacyOptionsRequirementStatus(), + firebase::ump::kPrivacyOptionsRequirementStatusUnknown); + EXPECT_FALSE(consent_info_->CanRequestAds()); +} + +// Tests for User Messaging Platform +TEST_F(FirebaseUmpTest, TestUmpGetInstanceIsAlwaysEqual) { + using firebase::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(FirebaseUmpTest, TestUmpRequestConsentInfoUpdate) { + using firebase::ump::ConsentRequestParameters; + using firebase::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::ump::kConsentRequestSuccess, + firebase::ump::kConsentRequestErrorNetwork}); + // Retry only network errors. + EXPECT_NE(future.error(), firebase::ump::kConsentRequestErrorNetwork); + + FLAKY_TEST_SECTION_END(); + + EXPECT_NE(consent_info_->GetConsentStatus(), + firebase::ump::kConsentStatusUnknown); + EXPECT_NE(consent_info_->GetConsentFormStatus(), + firebase::ump::kConsentFormStatusUnknown); + EXPECT_NE(consent_info_->GetPrivacyOptionsRequirementStatus(), + firebase::ump::kPrivacyOptionsRequirementStatusUnknown); +} + +TEST_F(FirebaseUmpTest, TestUmpRequestConsentInfoUpdateDebugEEA) { + using firebase::ump::ConsentDebugSettings; + using firebase::ump::ConsentRequestParameters; + using firebase::ump::ConsentStatus; + + FLAKY_TEST_SECTION_BEGIN(); + + ConsentRequestParameters params; + params.tag_for_under_age_of_consent = false; + params.debug_settings.debug_geography = + firebase::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::ump::kConsentRequestSuccess, + firebase::ump::kConsentRequestErrorNetwork}); + // Retry only network errors. + EXPECT_NE(future.error(), firebase::ump::kConsentRequestErrorNetwork); + + FLAKY_TEST_SECTION_END(); + + EXPECT_EQ(consent_info_->GetConsentStatus(), + firebase::ump::kConsentStatusRequired); +} + +TEST_F(FirebaseUmpTest, TestUmpRequestConsentInfoUpdateDebugNonEEA) { + using firebase::ump::ConsentDebugSettings; + using firebase::ump::ConsentRequestParameters; + using firebase::ump::ConsentStatus; + + FLAKY_TEST_SECTION_BEGIN(); + + ConsentRequestParameters params; + params.tag_for_under_age_of_consent = false; + params.debug_settings.debug_geography = + firebase::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::ump::kConsentRequestSuccess, + firebase::ump::kConsentRequestErrorNetwork}); + // Retry only network errors. + EXPECT_NE(future.error(), firebase::ump::kConsentRequestErrorNetwork); + + FLAKY_TEST_SECTION_END(); + + EXPECT_THAT(consent_info_->GetConsentStatus(), + AnyOf(Eq(firebase::ump::kConsentStatusNotRequired), + Eq(firebase::ump::kConsentStatusRequired))); +} + +TEST_F(FirebaseUmpTest, TestUmpLoadForm) { + using firebase::ump::ConsentDebugSettings; + using firebase::ump::ConsentFormStatus; + using firebase::ump::ConsentRequestParameters; + using firebase::ump::ConsentStatus; + + ConsentRequestParameters params; + params.tag_for_under_age_of_consent = false; + params.debug_settings.debug_geography = + firebase::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::ump::kConsentStatusRequired); + + EXPECT_EQ(consent_info_->GetConsentFormStatus(), + firebase::ump::kConsentFormStatusAvailable); + + // Load the form. Run this step with retry in case of network timeout. + WaitForCompletion( + RunWithRetry([&]() { return consent_info_->LoadConsentForm(); }), + "LoadConsentForm", + {firebase::ump::kConsentFormSuccess, + firebase::ump::kConsentFormErrorTimeout}); + + firebase::Future future = consent_info_->LoadConsentFormLastResult(); + + EXPECT_EQ(consent_info_->GetConsentFormStatus(), + firebase::ump::kConsentFormStatusAvailable); + + if (future.error() == firebase::ump::kConsentFormErrorTimeout) { + LogWarning("Timed out after multiple tries, but passing anyway."); + } +} + +TEST_F(FirebaseUmpTest, TestUmpShowForm) { + TEST_REQUIRES_USER_INTERACTION; + + using firebase::ump::ConsentDebugSettings; + using firebase::ump::ConsentFormStatus; + using firebase::ump::ConsentRequestParameters; + using firebase::ump::ConsentStatus; + + ConsentRequestParameters params; + params.tag_for_under_age_of_consent = false; + params.debug_settings.debug_geography = + firebase::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::ump::kConsentStatusRequired); + + EXPECT_EQ(consent_info_->GetConsentFormStatus(), + firebase::ump::kConsentFormStatusAvailable); + + WaitForCompletion(consent_info_->LoadConsentForm(), "LoadConsentForm"); + + EXPECT_EQ(consent_info_->GetConsentFormStatus(), + firebase::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::ump::kConsentStatusObtained); +} + +TEST_F(FirebaseUmpTest, TestUmpLoadFormUnderAgeOfConsent) { + SKIP_TEST_ON_IOS_SIMULATOR; + + using firebase::ump::ConsentDebugSettings; + using firebase::ump::ConsentFormStatus; + using firebase::ump::ConsentRequestParameters; + using firebase::ump::ConsentStatus; + + FLAKY_TEST_SECTION_BEGIN(); + + ConsentRequestParameters params; + params.tag_for_under_age_of_consent = true; + params.debug_settings.debug_geography = + firebase::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::ump::kConsentRequestSuccess, + firebase::ump::kConsentRequestErrorNetwork}); + // Retry only network errors. + EXPECT_NE(future.error(), firebase::ump::kConsentRequestErrorNetwork); + + FLAKY_TEST_SECTION_END(); + + firebase::Future load_future = consent_info_->LoadConsentForm(); + WaitForCompletion(load_future, "LoadConsentForm", + {firebase::ump::kConsentFormErrorUnavailable, + firebase::ump::kConsentFormErrorTimeout, + firebase::ump::kConsentFormSuccess}); +} + +TEST_F(FirebaseUmpTest, TestUmpLoadFormUnavailableDebugNonEEA) { + using firebase::ump::ConsentDebugSettings; + using firebase::ump::ConsentFormStatus; + using firebase::ump::ConsentRequestParameters; + using firebase::ump::ConsentStatus; + + FLAKY_TEST_SECTION_BEGIN(); + + ConsentRequestParameters params; + params.tag_for_under_age_of_consent = false; + params.debug_settings.debug_geography = + firebase::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::ump::kConsentRequestSuccess, + firebase::ump::kConsentRequestErrorNetwork}); + // Retry only network errors. + EXPECT_NE(future.error(), firebase::ump::kConsentRequestErrorNetwork); + + FLAKY_TEST_SECTION_END(); + + if (consent_info_->GetConsentStatus() != + firebase::ump::kConsentStatusRequired) { + WaitForCompletion(consent_info_->LoadConsentForm(), "LoadConsentForm", + firebase::ump::kConsentFormErrorUnavailable); + } +} + +TEST_F(FirebaseUmpTest, TestUmpLoadAndShowIfRequiredDebugNonEEA) { + using firebase::ump::ConsentDebugSettings; + using firebase::ump::ConsentRequestParameters; + using firebase::ump::ConsentStatus; + + FLAKY_TEST_SECTION_BEGIN(); + + ConsentRequestParameters params; + params.tag_for_under_age_of_consent = false; + params.debug_settings.debug_geography = + firebase::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::ump::kConsentRequestSuccess, + firebase::ump::kConsentRequestErrorNetwork}); + // Retry only network errors. + EXPECT_NE(future.error(), firebase::ump::kConsentRequestErrorNetwork); + + FLAKY_TEST_SECTION_END(); + + EXPECT_THAT(consent_info_->GetConsentStatus(), + AnyOf(Eq(firebase::ump::kConsentStatusNotRequired), + Eq(firebase::ump::kConsentStatusRequired))); + + if (consent_info_->GetConsentStatus() == + firebase::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(FirebaseUmpTest, TestUmpLoadAndShowIfRequiredDebugEEA) { + using firebase::ump::ConsentDebugSettings; + using firebase::ump::ConsentRequestParameters; + using firebase::ump::ConsentStatus; + + TEST_REQUIRES_USER_INTERACTION; + + ConsentRequestParameters params; + params.tag_for_under_age_of_consent = false; + params.debug_settings.debug_geography = + firebase::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::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::ump::kConsentStatusObtained); +} + +TEST_F(FirebaseUmpTest, TestUmpPrivacyOptions) { + using firebase::ump::ConsentDebugSettings; + using firebase::ump::ConsentRequestParameters; + using firebase::ump::ConsentStatus; + using firebase::ump::PrivacyOptionsRequirementStatus; + + TEST_REQUIRES_USER_INTERACTION; + + ConsentRequestParameters params; + params.tag_for_under_age_of_consent = false; + params.debug_settings.debug_geography = + firebase::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::ump::kConsentStatusRequired); + + EXPECT_FALSE(consent_info_->CanRequestAds()); + + WaitForCompletion(consent_info_->LoadAndShowConsentFormIfRequired( + app_framework::GetWindowController()), + "LoadAndShowConsentFormIfRequired"); + + EXPECT_EQ(consent_info_->GetConsentStatus(), + firebase::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::ump::kPrivacyOptionsRequirementStatusRequired); + + firebase::Future future = consent_info_->ShowPrivacyOptionsForm( + app_framework::GetWindowController()); + + EXPECT_TRUE(future == consent_info_->ShowPrivacyOptionsFormLastResult()); + + WaitForCompletion(future, "ShowPrivacyOptionsForm"); +} + +TEST_F(FirebaseUmpTest, TestCanRequestAdsNonEEA) { + using firebase::ump::ConsentDebugSettings; + using firebase::ump::ConsentRequestParameters; + using firebase::ump::ConsentStatus; + + ConsentRequestParameters params; + params.tag_for_under_age_of_consent = false; + params.debug_settings.debug_geography = + firebase::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::ump::kConsentStatusNotRequired), + Eq(firebase::ump::kConsentStatusRequired))); + + if (consent_info_->GetConsentStatus() == + firebase::ump::kConsentStatusNotRequired) { + EXPECT_TRUE(consent_info_->CanRequestAds()); + } +} + +TEST_F(FirebaseUmpTest, TestCanRequestAdsEEA) { + using firebase::ump::ConsentDebugSettings; + using firebase::ump::ConsentRequestParameters; + using firebase::ump::ConsentStatus; + + ConsentRequestParameters params; + params.tag_for_under_age_of_consent = false; + params.debug_settings.debug_geography = + firebase::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::ump::kConsentStatusRequired); + + EXPECT_FALSE(consent_info_->CanRequestAds()); +} + +TEST_F(FirebaseUmpTest, TestUmpCleanupWithDelay) { + // Ensure that if ConsentInfo is deleted after a delay, Futures are + // properly invalidated. + using firebase::ump::ConsentFormStatus; + using firebase::ump::ConsentRequestParameters; + using firebase::ump::ConsentStatus; + + ConsentRequestParameters params; + params.tag_for_under_age_of_consent = false; + params.debug_settings.debug_geography = + firebase::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(FirebaseUmpTest, TestUmpCleanupRaceCondition) { + // Ensure that if ConsentInfo is deleted immediately, operations + // (and their Futures) are properly invalidated. + + using firebase::ump::ConsentFormStatus; + using firebase::ump::ConsentRequestParameters; + using firebase::ump::ConsentStatus; + + ConsentRequestParameters params; + params.tag_for_under_age_of_consent = false; + params.debug_settings.debug_geography = + firebase::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(FirebaseUmpTest, TestUmpCallbacksOnWrongInstance) { + // Ensure that if ConsentInfo is deleted and then recreated, stale + // callbacks don't call into the new instance and cause crashes. + using firebase::ump::ConsentFormStatus; + using firebase::ump::ConsentRequestParameters; + using firebase::ump::ConsentStatus; + + ConsentRequestParameters params; + params.tag_for_under_age_of_consent = false; + params.debug_settings.debug_geography = + firebase::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(FirebaseUmpTest, TestUmpMethodsReturnOperationInProgress) { + SKIP_TEST_ON_DESKTOP; + SKIP_TEST_ON_IOS_SIMULATOR; // LoadAndShowConsentFormIfRequired + // is too quick on simulator. + + using firebase::ump::ConsentFormStatus; + using firebase::ump::ConsentRequestParameters; + using firebase::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::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::ump::kConsentRequestErrorOperationInProgress); + WaitForCompletion(future_request_1, "RequestConsentInfoUpdate first", + {firebase::ump::kConsentRequestSuccess, + firebase::ump::kConsentRequestErrorNetwork}); + + consent_info_->Reset(); + + FLAKY_TEST_SECTION_END(); +} + +TEST_F(FirebaseUmpTest, TestUmpMethodsReturnOperationInProgressWithUI) { + SKIP_TEST_ON_DESKTOP; + TEST_REQUIRES_USER_INTERACTION; + + using firebase::ump::ConsentFormStatus; + using firebase::ump::ConsentRequestParameters; + using firebase::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::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::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::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::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::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::ump::kConsentFormErrorOperationInProgress); + WaitForCompletion(future_load_and_show_1, + "LoadAndShowConsentFormIfRequired first"); +} + +} // namespace firebase_testapp_automated diff --git a/ump/src/android/consent_info_internal_android.cc b/ump/src/android/consent_info_internal_android.cc new file mode 100644 index 0000000000..93b8ae05bb --- /dev/null +++ b/ump/src/android/consent_info_internal_android.cc @@ -0,0 +1,669 @@ +/* + * 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 "ump/src/android/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 "ump/ump_resources.h" + +namespace firebase { +namespace ump { +namespace internal { + +ConsentInfoInternalAndroid* ConsentInfoInternalAndroid::s_instance = nullptr; +firebase::Mutex ConsentInfoInternalAndroid::s_instance_mutex; + +::firebase::Mutex g_cached_ump_embedded_files_mutex; +std::vector<::firebase::internal::EmbeddedFile>* g_cached_ump_embedded_files = + nullptr; + +// 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/ump/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_); + + // Ensure we only load these files once. + { + MutexLock lock( + ::firebase::ump::internal::g_cached_ump_embedded_files_mutex); + if (::firebase::ump::internal::g_cached_ump_embedded_files == nullptr) { + ::firebase::ump::internal::g_cached_ump_embedded_files = + new std::vector(); + *::firebase::ump::internal::g_cached_ump_embedded_files = + util::CacheEmbeddedFiles(env, activity, + firebase::internal::EmbeddedFile::ToVector( + firebase_ump::ump_resources_filename, + firebase_ump::ump_resources_data, + firebase_ump::ump_resources_size)); + } + } + const std::vector& embedded_files = + *::firebase::ump::internal::g_cached_ump_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("UMP: 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( + "UMP: 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("UMP: 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("UMP: 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 firebase diff --git a/ump/src/android/consent_info_internal_android.h b/ump/src/android/consent_info_internal_android.h new file mode 100644 index 0000000000..f5ab3b8916 --- /dev/null +++ b/ump/src/android/consent_info_internal_android.h @@ -0,0 +1,155 @@ +/* + * 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_UMP_SRC_ANDROID_CONSENT_INFO_INTERNAL_ANDROID_H_ +#define FIREBASE_UMP_SRC_ANDROID_CONSENT_INFO_INTERNAL_ANDROID_H_ + +#include + +#include "app/src/util_android.h" +#include "firebase/internal/mutex.h" +#include "ump/src/common/consent_info_internal.h" + +namespace firebase { +namespace ump { + +// clang-format off +#define UMP_INITIALIZATION_HELPER_METHODS(X) \ + X(InitializeUmp, "initializeUmp", "(Landroid/content/Context;)V", \ + util::kMethodTypeStatic) +// clang-format on + +METHOD_LOOKUP_DECLARATION(ump_initialization_helper, + UMP_INITIALIZATION_HELPER_METHODS); + +// Needed when UMP is initialized without Firebase. +JNIEnv* GetJNI(); + +// Retrieves the activity used to initialize UMP. +jobject GetActivity(); + +// Register the native callbacks needed by the Futures. +bool RegisterNatives(); + +// Release classes registered by this module. +void ReleaseClasses(JNIEnv* env); + +namespace internal { +extern ::firebase::Mutex g_cached_ump_embedded_files_mutex; +extern std::vector<::firebase::internal::EmbeddedFile>* + g_cached_ump_embedded_files; + +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 firebase + +#endif // FIREBASE_UMP_SRC_ANDROID_CONSENT_INFO_INTERNAL_ANDROID_H_ diff --git a/ump/src/common/consent_info.cc b/ump/src/common/consent_info.cc new file mode 100644 index 0000000000..a93872484c --- /dev/null +++ b/ump/src/common/consent_info.cc @@ -0,0 +1,182 @@ +/* + * 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/ump/consent_info.h" + +#include "app/src/assert.h" +#include "firebase/app.h" +#include "firebase/internal/platform.h" +#include "firebase/ump.h" +#include "ump//src/common/consent_info_internal.h" + +namespace firebase { +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 firebase diff --git a/ump/src/common/consent_info_internal.cc b/ump/src/common/consent_info_internal.cc new file mode 100644 index 0000000000..ca6f4677f6 --- /dev/null +++ b/ump/src/common/consent_info_internal.cc @@ -0,0 +1,88 @@ +/* + * 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 "ump/src/common/consent_info_internal.h" + +#include "app/src/include/firebase/internal/platform.h" + +namespace firebase { +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 firebase diff --git a/ump/src/common/consent_info_internal.h b/ump/src/common/consent_info_internal.h new file mode 100644 index 0000000000..0578478653 --- /dev/null +++ b/ump/src/common/consent_info_internal.h @@ -0,0 +1,140 @@ +/* + * 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_UMP_SRC_COMMON_CONSENT_INFO_INTERNAL_H_ +#define FIREBASE_UMP_SRC_COMMON_CONSENT_INFO_INTERNAL_H_ + +#include "app/src/cleanup_notifier.h" +#include "app/src/reference_counted_future_impl.h" +#include "firebase/future.h" +#include "firebase/internal/platform.h" +#include "firebase/ump.h" +#include "firebase/ump/types.h" + +#if FIREBASE_PLATFORM_ANDROID +#include +#endif + +namespace firebase { +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 firebase + +#endif // FIREBASE_UMP_SRC_COMMON_CONSENT_INFO_INTERNAL_H_ diff --git a/ump/src/include/firebase/ump.h b/ump/src/include/firebase/ump.h new file mode 100644 index 0000000000..bd33f1f238 --- /dev/null +++ b/ump/src/include/firebase/ump.h @@ -0,0 +1,23 @@ +/* + * 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_UMP_SRC_INCLUDE_FIREBASE_UMP_H_ +#define FIREBASE_UMP_SRC_INCLUDE_FIREBASE_UMP_H_ + +#include "firebase/ump/consent_info.h" +#include "firebase/ump/types.h" + +#endif // FIREBASE_UMP_SRC_INCLUDE_FIREBASE_UMP_H_ diff --git a/ump/src/include/firebase/ump/consent_info.h b/ump/src/include/firebase/ump/consent_info.h new file mode 100644 index 0000000000..10d670c821 --- /dev/null +++ b/ump/src/include/firebase/ump/consent_info.h @@ -0,0 +1,247 @@ +/* + * 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_UMP_SRC_INCLUDE_FIREBASE_UMP_CONSENT_INFO_H_ +#define FIREBASE_UMP_SRC_INCLUDE_FIREBASE_UMP_CONSENT_INFO_H_ + +#include "firebase/app.h" +#include "firebase/future.h" +#include "firebase/internal/platform.h" +#include "firebase/ump/types.h" + +#if FIREBASE_PLATFORM_ANDROID +#include +#endif // FIREBASE_PLATFORM_ANDROID + +namespace firebase { +/// @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. +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. +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. + 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::ump::ConsentInfo::GetInstance(jni_env, + /// activity); + /// #else + /// consent_info = firebase::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. + 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. + 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. + 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. + 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. + Future RequestConsentInfoUpdate(const ConsentRequestParameters& params); + + /// Get the Future from the most recent call to RequestConsentInfoUpdate(). + Future RequestConsentInfoUpdateLastResult(); + + /// Consent form status. This value defaults to kConsentFormStatusUnknown and + /// requires a call to RequestConsentInfoUpdate() to update. + ConsentFormStatus GetConsentFormStatus(); + + /// Loads a consent form. Returns an error if the consent form is unavailable + /// or cannot be loaded. + Future LoadConsentForm(); + + /// Get the Future from the most recent call to LoadConsentForm(). + 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. + Future ShowConsentForm(FormParent parent); + + /// Get the Future from the most recent call to ShowConsentForm(). + 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. + Future LoadAndShowConsentFormIfRequired(FormParent parent); + + /// Get the Future from the most recent call to + /// LoadAndShowConsentFormIfRequired(). + Future LoadAndShowConsentFormIfRequiredLastResult(); + + /// Check whether the privacy options form needs to be displayed. + /// This is updated by RequestConsentInfoUpdate(). + 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. + Future ShowPrivacyOptionsForm(FormParent parent); + + /// Get the Future from the most recent call to ShowPrivacyOptionsForm(). + 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. + bool CanRequestAds(); + + /// Clears all consent state from persistent storage. This can be used in + /// development to simulate a new installation. + 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 firebase + +#endif // FIREBASE_UMP_SRC_INCLUDE_FIREBASE_UMP_CONSENT_INFO_H_ diff --git a/ump/src/include/firebase/ump/types.h b/ump/src/include/firebase/ump/types.h new file mode 100644 index 0000000000..d376bff85d --- /dev/null +++ b/ump/src/include/firebase/ump/types.h @@ -0,0 +1,177 @@ +/* + * 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_UMP_SRC_INCLUDE_FIREBASE_UMP_TYPES_H_ +#define FIREBASE_UMP_SRC_INCLUDE_FIREBASE_UMP_TYPES_H_ + +#include +#include +#include + +#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 ump { + +/// Debug values for testing geography. +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. +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. +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. +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. +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. +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. +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. +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 firebase + +#endif // FIREBASE_UMP_SRC_INCLUDE_FIREBASE_UMP_TYPES_H_ diff --git a/ump/src/ios/.clang-format b/ump/src/ios/.clang-format new file mode 100644 index 0000000000..9d159247d5 --- /dev/null +++ b/ump/src/ios/.clang-format @@ -0,0 +1,2 @@ +DisableFormat: true +SortIncludes: false diff --git a/ump/src/ios/consent_info_internal_ios.h b/ump/src/ios/consent_info_internal_ios.h new file mode 100644 index 0000000000..f1db540258 --- /dev/null +++ b/ump/src/ios/consent_info_internal_ios.h @@ -0,0 +1,67 @@ +/* + * 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_UMP_SRC_IOS_CONSENT_INFO_INTERNAL_IOS_H_ +#define FIREBASE_UMP_SRC_IOS_CONSENT_INFO_INTERNAL_IOS_H_ + +#include + +#include "firebase/internal/mutex.h" +#include "ump/src/common/consent_info_internal.h" + +namespace firebase { +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 firebase + +#endif // FIREBASE_UMP_SRC_IOS_CONSENT_INFO_INTERNAL_IOS_H_ diff --git a/ump/src/ios/consent_info_internal_ios.mm b/ump/src/ios/consent_info_internal_ios.mm new file mode 100644 index 0000000000..9bb15f1f1a --- /dev/null +++ b/ump/src/ios/consent_info_internal_ios.mm @@ -0,0 +1,367 @@ +/* + * 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 "ump/src/ios/consent_info_internal_ios.h" + +#include "app/src/assert.h" +#include "app/src/thread.h" +#include "app/src/util_ios.h" + +namespace firebase { +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("UMP: 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("UMP: 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("UMP: 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("UMP: 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("UMP: 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 firebase diff --git a/ump/src/stub/consent_info_internal_stub.cc b/ump/src/stub/consent_info_internal_stub.cc new file mode 100644 index 0000000000..a0a4c4f4da --- /dev/null +++ b/ump/src/stub/consent_info_internal_stub.cc @@ -0,0 +1,165 @@ +/* + * 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 "ump/src/stub/consent_info_internal_stub.h" + +#include "app/src/thread.h" + +namespace firebase { +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 firebase diff --git a/ump/src/stub/consent_info_internal_stub.h b/ump/src/stub/consent_info_internal_stub.h new file mode 100644 index 0000000000..9da0655e0d --- /dev/null +++ b/ump/src/stub/consent_info_internal_stub.h @@ -0,0 +1,84 @@ +/* + * 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_UMP_SRC_STUB_CONSENT_INFO_INTERNAL_STUB_H_ +#define FIREBASE_UMP_SRC_STUB_CONSENT_INFO_INTERNAL_STUB_H_ + +#include "ump/src/common/consent_info_internal.h" + +namespace firebase { +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 firebase + +#endif // FIREBASE_SRC_STUB_CONSENT_INFO_INTERNAL_STUB_H_ diff --git a/ump/src_java/com/google/firebase/ump/internal/cpp/ConsentInfoHelper.java b/ump/src_java/com/google/firebase/ump/internal/cpp/ConsentInfoHelper.java new file mode 100644 index 0000000000..637d24fae2 --- /dev/null +++ b/ump/src_java/com/google/firebase/ump/internal/cpp/ConsentInfoHelper.java @@ -0,0 +1,312 @@ +/* + * 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.ump.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 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/ump/ump_resources/AndroidManifest.xml b/ump/ump_resources/AndroidManifest.xml new file mode 100644 index 0000000000..66236bd0d6 --- /dev/null +++ b/ump/ump_resources/AndroidManifest.xml @@ -0,0 +1,6 @@ + + + + + diff --git a/ump/ump_resources/build.gradle b/ump/ump_resources/build.gradle new file mode 100644 index 0000000000..042ccd2266 --- /dev/null +++ b/ump/ump_resources/build.gradle @@ -0,0 +1,69 @@ +// 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/ump/internal/cpp'] + } + } + } +} + +dependencies { + implementation platform('com.google.firebase:firebase-bom:33.11.0') + implementation 'com.google.firebase:firebase-analytics' + implementation 'com.google.android.ump:user-messaging-platform:2.2.0' +} + +afterEvaluate { + generateReleaseBuildConfig.enabled = false +} + +apply from: "$rootDir/android_build_files/extract_and_dex.gradle" +extractAndDexAarFile('ump_resources')