# Monetisation — ads, Pro and the Play Console Foto Dup Finder is **freemium**: - **Free tier** — every duplicate-finding feature, plus one anchored adaptive AdMob banner at the bottom of the scanner screen. - **Pro tier** — the same features with no banner. A one-time, non-consumable Play Billing product `pro_no_ads`. There is no subscription, no trial, no feature gate and no account. Photo processing remains entirely on-device; the only network traffic is AdMob/UMP and Google Play Billing. ## 1. Dependencies and why | Dependency | Version | Why | |---|---|---| | `com.google.android.gms:play-services-ads` | 25.5.0 | Stable Google Mobile Ads (legacy) SDK; `minSdk 24`, `compileSdk 34+` | | `com.google.android.ump:user-messaging-platform` | 4.0.0 | Consent form / privacy options for EEA, UK, Switzerland and US states | | `com.android.billingclient:billing-ktx` | 9.1.0 | Play Billing; one-time products, pending purchases, acknowledgement | **Legacy vs Next-Gen ads SDK.** Google now recommends the GMA Next-Gen SDK (`com.google.android.libraries.ads.mobile.sdk:ads-mobile-sdk:1.5.0`). This app uses the stable legacy SDK because its API is widely documented, it has the smaller permission set (`READ_BASIC_PHONE_STATE` is not needed) and it is sufficient for one banner. Treat a Next-Gen migration as a separate, tested change — the initialization and ad-request APIs differ. ## 2. AdMob setup 1. Create an **AdMob account** and add an **Android app** linked to the new Play listing (`de.softwareapp_hb.fotodup.finder.free`). The AdMob App ID is tied to that package; do not reuse the old paid app's AdMob app unless the Play listing is the same. 2. Create one **Banner** ad unit. Copy: - the **App ID** (`ca-app-pub-…~…`); - the **banner unit ID** (`ca-app-pub-…/…`). 3. Put both in `local.properties` (git-ignored) or pass them to Gradle: ```properties admob.appId=ca-app-pub-XXXXXXXXXXXXXXXX~YYYYYYYYYY admob.bannerUnitId=ca-app-pub-XXXXXXXXXXXXXXXX/NNNNNNNNNN ``` The defaults in `app/build.gradle.kts` are Google's public **test** ids; they are safe to click but produce no revenue. The build logs a warning while they are in use. 4. Create a **UMP message** under *Privacy & messaging* in AdMob, publish it, and test it with a debug device. The app calls `requestConsentInfoUpdate()` → `loadAndShowConsentFormIfRequired()` before `MobileAds.initialize()`. 5. Optional but recommended: publish an `app-ads.txt` on the developer website that Play points to. It is a website file, not an app asset. ## 3. Play Console setup ### 3.1 Publish the new listing as a free app The freemium build uses **`applicationId = de.softwareapp_hb.fotodup.finder.free`**, so it is a **new Play listing**, separate from the old paid app at `de.softwareapp_hb.fotodup.finder`. Create the new app as **Free** from the start — new apps are free by default. Do **not** change the old paid listing's price; it can remain for existing customers or be unpublished once they have migrated. This avoids Play's irreversible paid → free change entirely. ### 3.2 Create the in-app product 1. *Monetise > Products > In-app products > Create product*. 2. Product ID: **`pro_no_ads`** (must exactly match `ProProduct.ID`). 3. Type: **One-time product** (non-consumable). 4. Set a price; the app displays Play's localized `formattedPrice`, so no code change is needed to change it. 5. **Activate** the product. An inactive product is not returned by `queryProductDetailsAsync()`. ### 3.3 Test purchases 1. Add a **license tester** under *Setup > License testing*. 2. Upload the freemium build to an **internal testing** track. 3. Install from the internal-testing link with the tester account. 4. Test: buy, cancel, pending (if available), restore, reinstall, and a second device with the same account. 5. Use a **promo code** or license-tester purchase, never a real charge, for your own end-to-end check. Billing cannot be tested from a local debug APK signed with a debug key and not installed through Play; `BillingClient` will report `BILLING_UNAVAILABLE` or `SERVICE_DISCONNECTED`. ## 4. App configuration `app/build.gradle.kts` reads three values, in order: Gradle property (`-Padmob.appId=...`), `local.properties`, then the default test value. | Key | BuildConfig / manifest | Default | |---|---|---| | `admob.appId` | `manifestPlaceholders["admobAppId"]` → AdMob `APPLICATION_ID` meta-data | Google test app id | | `admob.bannerUnitId` | `BuildConfig.ADMOB_BANNER_UNIT_ID` | Google test adaptive-banner unit | | `legacyPro.cutoffEpochMs` | `BuildConfig.LEGACY_PRO_CUTOFF_EPOCH_MS` | `0` (disabled) | `local.properties.example` is the template. Never commit the real file. ## 5. Code map | Class | Role | |---|---| | `monetization/ProProduct.kt` | product id + SharedPreferences keys | | `monetization/ProStore.kt` | Billing connection, product query, purchase, acknowledgement, restore, local cache, legacy migration | | `monetization/ProState.kt` | UI state (`isPro`, `priceText`, `billingAvailable`, `purchaseInProgress`, `message`) | | `monetization/LegacyPro.kt` | pure install-time cutoff predicate | | `monetization/AdsController.kt` | UMP consent + `MobileAds.initialize` + privacy options | | `monetization/AdsState.kt` | `initialized`, `canRequestAds`, `privacyOptionsRequired`, `error` | | `monetization/AdPolicy.kt` | pure banner gate | | `ui/ads/BannerAdSlot.kt` | one adaptive `AdView`, lifecycle, destroy on dispose | | `ui/pro/ProSheet.kt` | benefits, price, buy, restore, pending/unavailable | | `ui/scanner/ScannerScreen.kt` | bottom slot, Options menu entry, sheet visibility | `FotoDupApplication` creates `ProStore` and `AdsController` next to `ScanController`. `MainActivity` starts consent/ads only for a non-Pro install and refreshes purchases on resume. ## 6. Consent and purchase flows ### Consent 1. `ConsentInformation.requestConsentInfoUpdate(activity, params, ...)`. 2. On success, `UserMessagingPlatform.loadAndShowConsentFormIfRequired(activity)`. 3. Read `canRequestAds()` and `privacyOptionsRequirementStatus`. 4. Only then `MobileAds.initialize(appContext)`. 5. The banner is composed only when `AdPolicy.shouldShowBanner(...)` is true. 6. If UMP requires it, the Options menu shows **Privacy options**, which calls `showPrivacyOptionsForm()`. If the consent request fails (offline, no Play services), the app keeps working and does not request an ad unless UMP already has a usable answer. ### Purchase 1. `ProSheet` calls `ScannerViewModel.purchasePro(activity)`. 2. `ProStore.purchase()` queries product details if needed, then `launchBillingFlow(activity, params)`. 3. `onPurchasesUpdated()` filters `pro_no_ads` and requires `PURCHASED`. 4. Pro is granted locally, cached, and the banner disappears immediately. 5. If the purchase is not acknowledged, `KEY_PENDING_ACK` stores the token; `acknowledgePurchase()` is retried on the next refresh. 6. On app resume, `queryPurchasesAsync()` reconciles the cache with Play. ## 7. Grandfathering paid customers The app was previously sold as a paid app. Play Billing cannot tell an install whether it was bought as a paid app, so `LegacyPro` compares `PackageInfo.firstInstallTime` with a cutoff: ```properties # Epoch milliseconds of the first freemium release. legacyPro.cutoffEpochMs=1793491200000 # 2026-11-01T00:00:00Z ``` Because the freemium build has a **new applicationId** (`de.softwareapp_hb.fotodup.finder.free`), its own first-install time can never predate the cutoff. `ProStore` therefore reads the earliest first-install time of: - the new freemium package; and - the old paid package `de.softwareapp_hb.fotodup.finder`, declared in `` in the manifest. - An install before the cutoff is granted Pro and the decision is persisted in `KEY_ORIGIN_RESOLVED` / `KEY_LEGACY_PRO`. - A later successful Play query cannot revoke that grant. - A cutoff of `0` disables the migration. - The old paid app must still be installed the first time the freemium app runs. Uninstalling the old app first, clearing app data, or a restore that resets `firstInstallTime` loses the signal. For those users, use a promo code or a manual support flow. A server-side purchase history would be stronger, but it contradicts the no-account, no-backend design. Set the cutoff **before** uploading the first freemium build. If the app was never actually sold, leaving it at `0` is correct. ## 8. Play Console declarations and Data Safety The freemium build **does** contain ads and **does** use the advertising ID. These answers change from the pre-freemium listing. | Console item | Answer | |---|---| | **Ads** (*App content*) | **Yes, my app contains ads** | | **Advertising ID** | **Yes** — the ads SDK merges `AD_ID` and the Privacy Sandbox permissions | | **Data safety** | Google Mobile Ads collects/shares data for advertising, analytics and fraud prevention (see below) | | **Photo and video permissions** | unchanged: only `READ_MEDIA_IMAGES` / selected-photos access; the ad SDK never reads photos | | **App access** | still “all functionality available without special access”; no login | | **Content rating** | re-confirm; the app is a general-purpose utility, not child-directed | | **Permissions audit** | re-audit the **merged release manifest**; expect `INTERNET`, `ACCESS_NETWORK_STATE`, `AD_ID`, `ACCESS_ADSERVICES_*`, `WAKE_LOCK`, `com.android.vending.BILLING` and the framework's dynamic-receiver permission in addition to the photo/notification/FGS set | Google's published disclosure for the Mobile Ads SDK lists: - **IP address** — may be used to estimate general location; - **user product interactions** — app launch, taps, video views; - **diagnostic information** — launch time, hang rate, energy usage; - **device and account identifiers** — Android advertising ID, app set ID, and identifiers related to signed-in accounts where applicable. All of it is encrypted in transit with TLS. Ad ID collection is optional at the manifest level; this app keeps it because the free tier relies on advertising. The in-app **Privacy options** entry point and Android's ad-ID controls give users a way to change their choice. `PRIVACY.md` must stay consistent with these answers. Purchases are handled entirely by Google Play; the app never receives payment details. ## 9. Testing matrix | Case | How | |---|---| | Test banner | Debug build with the default test ids; a Play-services device shows a “Test Ad” label | | No banner for Pro | `DebugProToggle.GRANT_PRO`, or a license-tester purchase | | Consent required | UMP debug geography / test device; see the UMP docs | | Privacy options | Menu appears only when `privacyOptionsRequirementStatus == REQUIRED` | | Purchase | Internal testing track + license tester | | Cancel | Reopen the Play sheet and press back | | Restore | Reinstall, then **Restore purchase** with the same account | | Pending | Use a delayed-payment test instrument if available; Pro must not activate | | Offline Pro | Turn on airplane mode after a purchase; the cached entitlement keeps ads off | | Refund/revoke | Refund in the Console, reopen the app; a successful Play query removes Pro unless legacy | | Billing unavailable | AOSP AVD with no Play services; the sheet says purchases are unavailable and the scanner still works | | Ad load failure | No network; the banner is absent, the app does not crash | For UMP testing outside the EEA, temporarily add a debug-only `ConsentDebugSettings` in `AdsController.ensureInitialized()` before the update: ```kotlin val debugSettings = ConsentDebugSettings.Builder(activity) .setDebugGeography(ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA) .addTestDeviceHashedId("YOUR-HASHED-ID") // from the UMP logcat line .build() val params = ConsentRequestParameters.Builder() .setConsentDebugSettings(debugSettings) .build() ``` Keep it behind `BuildConfig.DEBUG` and remove it before a release build; the production path must not force a geography. ## 10. Troubleshooting | Symptom | Check | |---|---| | “Banner failed to load” | AdMob app id / unit id, network, test device, UMP `canRequestAds()` | | No ad view at all | `isPro`, `AdsState.canRequestAds`, `AdsState.initialized`; the gate is intentional | | `APPLICATION_ID` missing crash | `admob.appId` placeholder / manifest meta-data | | `BILLING_UNAVAILABLE` | Play Store installed/updated, app installed from Play internal testing, license tester | | `queryProductDetails` returns nothing | product `pro_no_ads` exists and is **active**, app uploaded to a testing track | | Purchase granted but ads return | successful Play query found no purchase (refund/account mismatch) and the install is not legacy | | Purchase not acknowledged | check `KEY_PENDING_ACK`; the next refresh retries; Play refunds after 3 days | | Privacy options missing | UMP says the form is not required in this region | | Ads load on a Pro device | `ProStore` cache/query, then `MainActivity` skip logic; check `DebugProToggle` state | ## 11. Limitations - Entitlement is **client-side** and can be tampered with on a rooted device. This is the deliberate cost of having no account/backend. - A paid customer who uninstalls the old app before the first freemium launch, or who uninstalls/reinstalls the new app, clears data, or restores to a device that resets `firstInstallTime`, may lose the legacy grant. Use a promo code/support flow for those users. - The legacy ads SDK is in maintenance mode; migrating to GMA Next-Gen is a future change with a different API. - Store screenshots and the feature graphic predate the banner and Pro sheet; the listing needs a re-shoot before the freemium release. - The AOSP emulators used for tablet screenshots have no Play services, so ads and Billing cannot be validated there.