Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[interactive_media_ads] Adds initial Android implementation #6733

Open
wants to merge 80 commits into
base: main
Choose a base branch
from

Conversation

bparrishMines
Copy link
Contributor

@bparrishMines bparrishMines commented May 15, 2024

Android implementation for flutter/flutter#134228

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@bparrishMines bparrishMines changed the title Ima android [interactive_media_ads] Initial Android implementation May 20, 2024
@bparrishMines bparrishMines changed the title [interactive_media_ads] Initial Android implementation [interactive_media_ads] Adds initial Android implementation May 20, 2024

// org.jetbrains.kotlin:kotlin-bom artifact purpose is to align kotlin stdlib and related code versions.
// See: https://youtrack.jetbrains.com/issue/KT-55297/kotlin-stdlib-should-declare-constraints-on-kotlin-stdlib-jdk8-and-kotlin-stdlib-jdk7
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.10"))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the same line added to camera_android_camerax: https://github.com/flutter/packages/blob/main/packages/camera/camera_android_camerax/android/build.gradle#L77

This fixed the build failure when adding the 'com.google.ads.interactivemedia.v3:interactivemedia:3.33.0' dependency.

// of waiting for the main thread to run it.
internal open fun runOnMainThread(callback: Runnable) {
Handler(Looper.getMainLooper()).post { callback.run() }
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was added to the registrar to make it easier to handle and test callback methods on the correct thread.

Comment on lines 60 to 66
override fun setVolume(pigeon_instance: VideoAdPlayer, value: Long) {
(pigeon_instance as VideoAdPlayerImpl).savedVolume = value.toInt()
}

override fun setAdProgress(pigeon_instance: VideoAdPlayer, progress: VideoProgressUpdate) {
(pigeon_instance as VideoAdPlayerImpl).savedAdProgress = progress
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Custom methods added since VideoAdPlayer.getVolume and VideoAdPlayer.getAdProgress require a synchronous callback method.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's worth adding this as a code comment to these methods. It would be good to have it clarify why it's not calling api.foo in addition to saving the value.

@bparrishMines bparrishMines marked this pull request as ready for review May 23, 2024 19:13
Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

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

(I only briefly skimmed the tests.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we use InteractiveMediaAdsLibrary.g.kt? I thought it was only Java that prevented using the extra suffix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. I forgot that we only did that because of the limitations of Java and Obj-c.

AdError.AdErrorCode.INVALID_ARGUMENTS -> AdErrorCode.INVALID_ARGUMENTS
AdError.AdErrorCode.PLAYLIST_NO_CONTENT_TRACKING -> AdErrorCode.PLAYLIST_NO_CONTENT_TRACKING
AdError.AdErrorCode.UNEXPECTED_ADS_LOADED_EVENT -> AdErrorCode.UNEXPECTED_ADS_LOADED_EVENT
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this doesn't handle the case where a new error code is added upstream. It seems like it would probably even fail to compile if that happened?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My intention was for this to break compilation when a new enum is added. Since this uses a pinned version of the IMA SDK, we can add a new enum to the code generation whenever we bump the version.

We add an unknown enum in the webview_flutter implementations, but I assumed we did that because it uses a system library and not a pinned SDK.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since this uses a pinned version of the IMA SDK

It doesn't really though, because of optimistic upgrades. Because of the way Gradle works, unless we want to make the entire build fail on conflicts (which would be a large hammer) we don't actually have any control over whether we get the version listed in build.gradle.

Comment on lines 60 to 66
override fun setVolume(pigeon_instance: VideoAdPlayer, value: Long) {
(pigeon_instance as VideoAdPlayerImpl).savedVolume = value.toInt()
}

override fun setAdProgress(pigeon_instance: VideoAdPlayer, progress: VideoProgressUpdate) {
(pigeon_instance as VideoAdPlayerImpl).savedAdProgress = progress
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's worth adding this as a code comment to these methods. It would be good to have it clarify why it's not calling api.foo in addition to saving the value.

) onError,
void Function(
VideoView,
MediaPlayer,
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't some of these be more readable without the trailing comma? Or would the inconsistency hurt readability?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, it does make it more readable. I removed the trailing commas

// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// // ignore_for_file: avoid_unused_constructor_parameters
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is everything in this file commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This uses features from #6371, so it would break tests without it commented out. But I'll go ahead and uncomment it for now so it can be reviewed while I still wait for #6371 to land.

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

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

LGTM once the remaining comment about the enum fallback is resolved.

@stuartmorgan stuartmorgan added the triage-android Should be looked at in Android triage label Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform-android triage-android Should be looked at in Android triage
Projects
None yet
2 participants