Skip to content

Add the plugin registry and PrebidMobile.registerPlugin (plugin system, step 1) - #1054

Merged
mdanylov-sigma merged 2 commits into
masterfrom
claude/prebid-android-implementation-eb1930
Nov 5, 2026
Merged

mdanylov-sigma merged 2 commits into
masterfrom
claude/prebid-android-implementation-eb1930

Conversation

@mdanylov-sigma

@mdanylov-sigma mdanylov-sigma commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Android counterpart of prebid/prebid-mobile-ios#1424, part of prebid/prebid-mobile-ios#461. This is Step 1 of the Android delivery plan (III.14) in 4 - Core Design - Android Implementation: the registry core, the unified registration functions, and renderers moved onto them. It branches from master and doesn't depend on #1024 (Step 2).

Section numbers below (III.x) refer to that doc.

What it adds

  • PrebidPluginInfo (public, org.prebid.mobile.api.plugin): plugin identity, a name and a version with value equality (III.5).
  • PluginCapability<P> (public): what a plugin registers as. Only the SDK defines capabilities; this PR adds RENDERER only (III.3).
  • PrebidMobile.registerPlugin(plugin, capability), unregisterPlugin(plugin, capability) and containsPlugin(plugin, capability) (III.3, III.12). Java infers P from the capability, so a plugin of the wrong type doesn't compile, and there is no runtime cast. iOS checks the type at runtime instead.
  • PluginRegistry<P>, a public class marked @RestrictTo(LIBRARY_GROUP) (III.4). A registry keeps registration order, ignores a second plugin with the same identity (the first one stays), supports a capacity, and calls the plugin's callbacks outside its lock. A plugin is active once its onRegister returns. If onRegister throws an exception, the registration is rolled back and the exception is logged. This includes checked exceptions, which Kotlin code can throw without declaring them. If onRegister throws an Error, such as NoClassDefFoundError from a missing optional dependency, the registration is rolled back too, and the Error propagates. An exception from onUnregister is logged and not propagated, and it doesn't stop removeAll. A process-wide sequence orders plugins across capabilities.
  • PrebidMobilePluginRegister stores renderers in PluginCapability.RENDERER.getRegistry() instead of its own HashMap (III.10). Renderers are still identified by name only. Selection (name + isSupportRenderingFor + exact version, else PrebidRenderer) and the event listener calls are unchanged.

Where this differs from the doc, and why

  1. Deprecations are in this PR, not in Step 4 (III.12). The iOS reviewer asked to deprecate the renderer methods in the same release that ships the replacement, so this PR does the same on Android. Deprecated, to be removed in 4.0: PrebidMobile.registerPluginRenderer, unregisterPluginRenderer and containsPluginRenderer, plus PrebidMobilePluginRegister.registerPlugin, unregisterPlugin and containsPlugin(PrebidMobilePluginRenderer). On Android, containsPluginRenderer and containsPlugin(…, RENDERER) both match by name, so the deprecation message needs no note about it. On iOS, the old method matched the instance.
  2. The SDK's own renderer is registered only if it isn't registered yet (III.10). SdkInitializer registered a new PrebidRenderer on every init. Now that duplicates are ignored, a second init after a failed one would log the duplicate warning. This is the same fix the iOS review asked for. If the renderer already registered under that name isn't the SDK's own PrebidRenderer class, init keeps it as the default renderer and logs a warning.
  3. PrebidPluginInfo.toString() (III.5). It is the name alone when the version is empty, so renderer log lines don't end in a slash ([renderer] Plugin VendorRenderer/ is not registered). Same as iOS.
  4. PluginCapability.getName() and toString(). They read the name from the capability's registry, so a capability's name and the [name] prefix in its logs can't differ. Same as iOS; the doc's capability has no name.
  5. PluginRegistry.Entry has getters instead of public fields (III.4), following the getX() style of III.1. The registry also has removeAll(), which the @VisibleForTesting method PrebidMobilePluginRegister.unregisterAllPlugins() needs. It calls every onUnregister and keeps going if one of them throws.
  6. Log lines (III.4). A rejected plugin is logged as a warning that names the reason (same identity, or capacity reached). Messages are logged outside the lock, because a custom PrebidLogger is app code. Registering and unregistering are logged at debug level.

Kept as the doc asks:

  • The removal model of III.4: remove calls onUnregister right away, even while onRegister is still running. The iOS review dropped the deferred-unregister states for the same model.
  • The contract is documented on the PrebidMobile methods: register during SDK setup; unregistering is best-effort; registering or unregistering the same plugin concurrently, or from inside its own callbacks, is not supported.
  • No java.util.function, Optional or java.time in the API (III.6). The registry declares its own Identify and Lifecycle interfaces.

Behavior changes

  • A renderer whose name is already registered is now ignored with a warning. On master it replaced the registered renderer. To replace a renderer, unregister it first. After init, a publisher renderer named PrebidRenderer can no longer replace the SDK default. One registered before init now stays the default renderer, and init logs a warning; on master, init replaced it. The doc (III.13) asks for this to be in the release notes.
  • getRTBListOfRenderersFor and ext.prebid.sdk.renderers list renderers in registration order. On master they followed HashMap order.
  • The register is thread-safe. On master it was an unsynchronized HashMap.

With no plugin registered, the bid request is unchanged.

Doc questions (III.15)

  • Q1, @RestrictTo vs. package placement: uses @RestrictTo(LIBRARY_GROUP), as the doc proposes.
  • Q2, renderer default registration: PrebidRenderer is still registered first in SdkInitializer.init's try block, so start-up order doesn't change.
  • Q3, thread safety: plugin callbacks and identify run outside the lock. Renderers have no lifecycle callbacks.
  • Q5, naming: uses registerPlugin(plugin, capability), which matches the iOS Objective-C selector registerPlugin:as:. Nothing is released yet, so renaming is cheap.
  • Q6, Pluggable User ID Providers #936 #1024 coordination: Step 2 is Pluggable User ID Providers #936 #1024 rebased on this.

Not in this PR

Tests

  • New PluginRegistryTest (23) and PrebidPluginInfoTest (3) cover the registry: order, identity, capacity, callbacks that call back into the registry, and the sequence across registries. They also cover:
    • the rollback when onRegister throws an unchecked exception, a checked exception or an Error, and that a failed registration doesn't take up capacity;
    • an onUnregister that throws an unchecked or a checked exception, from remove and from removeAll;
    • snapshots and concurrent registration.
  • New PluginRegistrationTest (14) covers registerPlugin with RENDERER: the duplicate-name warning, replacing a renderer by unregistering it first, unregistering by name, the deprecated methods going through the capability, registration order in getRTBListOfRenderersFor and in the ext.prebid.sdk.renderers JSON, default and fallback renderer selection, event listeners, a renderer with a null name, and unregisterAllPlugins.
  • SdkInitializerTest: a second registerSdkRenderer() keeps the first renderer and logs no warning. An app renderer registered under the name PrebidRenderer stays the default, and registerSdkRenderer() logs a warning naming its class.
  • Some existing tests registered a fake PrebidRenderer over one that an earlier test class had left registered. They relied on replace-on-duplicate, so, as III.14 asks, their helpers now unregister the same name first: DisplayViewTest, MediationBannerViewTest, PluginRendererFactoryTest, InterstitialAdUnitTest, RewardedAdUnitTest, and the AdMob and MAX interstitial and rewarded tests. PrebidMobilePluginRegisterTest passes unchanged.
  • The internal test app's custom renderer screens use PrebidMobile.registerPlugin(…, PluginCapability.RENDERER).

Results (local, JDK 21; CI uses JDK 17):

  • :PrebidMobile-core:testReleaseUnitTest: 1533 tests, 0 failures
  • :PrebidMobile-admobAdapters:testReleaseUnitTest: 54 tests, 0 failures
  • :PrebidMobile-maxAdapters:testReleaseUnitTest: 122 tests, 0 failures
  • The GAM and Next-Gen event handler test sources compile. PrebidInternalTestApp, PrebidDemoJava and PrebidDemoKotlin compile.
  • Not run on a device or emulator

🤖 Generated with Claude Code

…m, step 1)

Android counterpart of prebid/prebid-mobile-ios#1424, following Step 1 of
the Android delivery plan (III.14) in "4 - Core Design - Android
Implementation".

- PrebidPluginInfo, PluginCapability<P> (RENDERER) and PluginRegistry<P>
  in org.prebid.mobile.api.plugin.
- PrebidMobile.registerPlugin / unregisterPlugin / containsPlugin.
- PrebidMobilePluginRegister stores renderers in the RENDERER registry.
- The renderer registration methods on PrebidMobile and
  PrebidMobilePluginRegister are deprecated, as on iOS.
- SdkInitializer registers PrebidRenderer only when it isn't registered.

Behavior change: a renderer whose name is already registered is ignored
with a warning instead of replacing the registered one. Renderers are
listed in registration order, and the register is thread-safe. Tests
that registered a fake PrebidRenderer over one left by another test now
unregister it first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
if (onRegister != null) {
try {
onRegister.call(plugin);
} catch (RuntimeException exception) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rollback only covers RuntimeException. Kotlin has no checked exceptions, so a Kotlin plugin's onRegister can throw e.g. IOException, and a vendor SDK with a missing optional dependency throws NoClassDefFoundError, an Error. In both cases:

  • the exception escapes PrebidMobile.registerPlugin;
  • the registration stays reserved but never becomes active, so containsPlugin returns false;
  • the same identity can never register again ("already registered"), and the dead entry counts against capacity.

Nothing reaches this in this PR, because RENDERER has no callbacks. It becomes reachable in Step 2, when EXTENDED_IDS wires in ExtendedIdProvider::onRegister. The Javadoc already promises the rollback, so please fix it here: catch Exception, and roll back in a finally so an Error also removes the registration before it propagates. If you'd rather defer it, please track it as an explicit Step 2 item.


try {
onUnregister.call(entry.plugin);
} catch (RuntimeException exception) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue: a Kotlin plugin's onUnregister can throw a checked exception, which escapes this catch (RuntimeException). From remove it escapes PrebidMobile.unregisterPlugin. From removeAll it stops the loop, so the remaining plugins never get onUnregister. Please catch Exception here.

static void registerSdkRenderer() {
PrebidRenderer renderer = new PrebidRenderer();

if (PrebidMobile.containsPlugin(renderer, PluginCapability.RENDERER)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is by name only. A renderer named PrebidRenderer that the app registered before init now silently stays as the default renderer; on master, init replaced it (last-wins). That contradicts spec III.10 and the PR description, which say an app renderer can no longer silently replace the SDK default. Please log a warning when the registered PrebidRenderer isn't the SDK's own PrebidRenderer class, or correct the claim in the description.

Review fixes for the plugin registry:

- PluginRegistry.add catches Exception instead of RuntimeException, so a
  checked exception from Kotlin code is logged and rolled back too. The
  rollback runs in a finally block, so an Error (e.g. NoClassDefFoundError)
  also frees the identity and the capacity slot before it propagates.
- onUnregister failures are caught as Exception, so a checked exception
  neither escapes unregisterPlugin nor stops removeAll.
- SdkInitializer logs a warning when the renderer registered under the
  name PrebidRenderer is not the SDK's own class. It stays the default,
  where on master init replaced it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@YuriyVelichko YuriyVelichko left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@YuriyVelichkoPI YuriyVelichkoPI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mdanylov-sigma
mdanylov-sigma merged commit 18e416d into master Nov 5, 2026
6 checks passed
@mdanylov-sigma
mdanylov-sigma deleted the claude/prebid-android-implementation-eb1930 branch November 5, 2026 12:26
mdanylov-sigma added a commit that referenced this pull request Nov 5, 2026
#1054 made registerPlugin() ignore a renderer whose name is already
registered. Two tests added by #1050 register a fake under the default
renderer's name without unregistering it first, so the real renderer
ran and the mock controller was never called. Their cleanup then
removed the default renderer, so InterstitialAdUnitTest also failed in a
full run. Both fail on master (18e416d). Unregister first, as the tests
#1054 updated already do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mdanylov-sigma added a commit that referenced this pull request Nov 5, 2026
#1054 made registerPlugin() ignore a renderer whose name is already
registered. Two tests added by #1050 register a fake under the default
renderer's name without unregistering it first, so the real renderer
ran and the mock controller was never called. Their cleanup then
removed the default renderer, so InterstitialAdUnitTest also failed in a
full run. Both fail on master (18e416d). Unregister first, as the tests
#1054 updated already do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mdanylov-sigma added a commit that referenced this pull request Nov 12, 2026
#1054 made registerPlugin() ignore a renderer whose name is already
registered. Two tests added by #1050 register a fake under the default
renderer's name without unregistering it first, so the real renderer
ran and the mock controller was never called. Their cleanup then
removed the default renderer, so InterstitialAdUnitTest also failed in a
full run. Both fail on master (18e416d). Unregister first, as the tests
#1054 updated already do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 4432c9c)
mdanylov-sigma added a commit that referenced this pull request Nov 14, 2026
… it twice

#1054 ignores a plugin renderer whose name is already registered, so the
fake Prebid renderer that #1050's tests register was dropped, and
InterstitialAdUnitTest and RewardedAdUnitTest failed on master. Unregister
it first. Test-only, identical to the same change in #1055 and #1057, so
whichever merges first makes the others' copy a no-op.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
YuriyVelichkoPI pushed a commit that referenced this pull request Nov 29, 2026
…line (#1055)

* Always complete fetchDemand: report SDK-not-ready, add a request deadline

Fixes #1053.

- BidLoader.load() no longer returns silently while the SDK is not
  initialized: it reports the new SDK_NOT_INITIALIZED result
  (ResultCode and FetchDemandResult), and still schedules auto refresh.
- Each bid request gets a deadline (connect + read timeout + 1 s). If it
  hasn't finished by then, it is cancelled and reported as TIMEOUT. A late
  result is dropped, so the listener is called once per request.
- Redirected connections now get the same connect/read timeouts as the
  first one; without them they could block forever.
- destroy() still cancels without calling the listener (now documented).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Fix the mediation invalid-ad-object test that passed without running

The test passed a non-null delegate, so fetchDemand() never hit the
INVALID_AD_OBJECT check. It went on to BidLoader.load(), which used to
return silently while the SDK wasn't initialized, so the assertion in the
listener never ran. Now that load() reports SDK_NOT_INITIALIZED, the
listener runs and the test failed. Pass a null delegate as the test
intends, and verify the listener is called.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Replace the default renderer in two #1050 tests broken by #1054

#1054 made registerPlugin() ignore a renderer whose name is already
registered. Two tests added by #1050 register a fake under the default
renderer's name without unregistering it first, so the real renderer
ran and the mock controller was never called. Their cleanup then
removed the default renderer, so InterstitialAdUnitTest also failed in a
full run. Both fail on master (18e416d). Unregister first, as the tests
#1054 updated already do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants