android / privacy-sandbox-samples

Apache License 2.0
128 stars 51 forks source link

Serving SurfaceView in RecyclerView #94

Closed RomanDorofeyev closed 4 days ago

RomanDorofeyev commented 6 months ago

I'm trying to understand how to use Sandboxed ads in the feed (RecyclerView) but faced a couple of issues:

  1. When the SurfaceView not added to the view tree I got the exception:
    java.lang.IllegalArgumentException: Field params should have the entry for the key (android.app.sdksandbox.extra.WIDTH_IN_PIXELS) with positive integer value
                    at android.app.sdksandbox.SdkSandboxManager.requestSurfacePackage(SdkSandboxManager.java:570)

    As I understand all the fields below are required:

            Bundle params = new Bundle();
              params.putInt(EXTRA_WIDTH_IN_PIXELS, mClientView.getWidth());
              params.putInt(EXTRA_HEIGHT_IN_PIXELS, mClientView.getHeight());
              params.putInt(EXTRA_DISPLAY_ID, getDisplay().getDisplayId());
              params.putBinder(EXTRA_HOST_TOKEN, mClientView.getHostToken());

    The question is how to preload the ad if the SurfaceView is not added to the view tree and those data cannot be retrieved?

  2. When the SurfaceView added to the view tree I can see the ad provided by sandboxed SDK in RecyclerView, but once RecyclerView scrolled away the ad item and get back - the SurfaceView is empty. Screenshot 2024-01-10 at 15 30 32 Screenshot 2024-01-10 at 15 30 40

    The question is how to restore SurfaceView content when RecyclerView scrolled back?

slinny commented 5 months ago

Please refer to the jetpack UI libraries link to show UI from the SDK runtime instead of using requestSurfacePackage.

RomanDorofeyev commented 5 months ago

@slinny is there any sample or detailed doc for that?

Once the UI libraries go into Beta, we plan to deprecate the SDK runtime platform APIs related to UI presentation, namely SdkSandboxManager.requestSurfacePackage() and SandbxedSdkProvider.getView()

Or probably you know when UI library will go into beta?

notmariazoe commented 2 months ago

@RomanDorofeyev have you checked the code in the dev-preview-main branch of the sample? You should have updated examples there.

RomanDorofeyev commented 2 months ago

@notmariazoe I did! But I was checking java repo, probably kotlin is more up-to-date, will check it also. Thanks!

notmariazoe commented 2 months ago

Definitely, let me know how it goes.

On Thu, May 23, 2024 at 2:28 PM Roman Do @.***> wrote:

@notmariazoe https://github.com/notmariazoe I did! But I was checking java repo, probably kotlin is more up-to-date, will check it also. Thanks!

— Reply to this email directly, view it on GitHub https://github.com/android/privacy-sandbox-samples/issues/94#issuecomment-2127111183, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQI3VXBP2CIFWGIIROIHRTLZDXVHZAVCNFSM6AAAAABBU4R4FKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRXGEYTCMJYGM . You are receiving this because you were mentioned.Message ID: @.***>