Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@cg021
Copy link
Contributor

@cg021 cg021 commented Jun 3, 2020

Description

Add JNI method onDisplayPlatformView for hybrid composition in the engine.

Related Issues

flutter/flutter#58288

Tests

I added the following tests:

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the contributor guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the C++, Objective-C, Java style guides for the engine.
  • I read the tree hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation.
  • All existing and new tests are passing.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read handling breaking changes.

@auto-assign auto-assign bot requested a review from iskakaushik June 3, 2020 17:00
@cg021 cg021 removed the request for review from iskakaushik June 3, 2020 17:04
@cg021 cg021 force-pushed the jni-58288 branch 3 times, most recently from f458492 to 0af2713 Compare June 3, 2020 20:21
@cg021 cg021 requested a review from blasten June 3, 2020 21:06
}
}

public void onDisplayPlatformView(int viewId, int x, int y, int width, int height) {}
Copy link

Choose a reason for hiding this comment

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

this one could be removed in this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed


@SuppressWarnings("unused")
@UiThread
private void onDisplayPlatformView(int viewId, int x, int y, int width, int height) {
Copy link

Choose a reason for hiding this comment

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

move this method below // ----- End Engine Lifecycle Support ---- since onDisplayPlatformView isn't related to the engine lifecycle.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@Nullable private Long nativePlatformViewId;
@Nullable private AccessibilityDelegate accessibilityDelegate;
@Nullable private PlatformMessageHandler platformMessageHandler;
@Nullable private PlatformViewsController platformViewsController;
Copy link

Choose a reason for hiding this comment

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

we need to add a setter for this in FlutterJNI.

}

@Override
public void onDisplayPlatformView(int viewId, int x, int y, int width, int height) {
Copy link

Choose a reason for hiding this comment

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

Actually, we won't need this method here. Instead call flutterJni.setPlatformViewsController(platformViewsController) below flutterJNI.addEngineLifecycleListener(engineLifecycleListener);.

/** Lifecycle callback invoked before a hot restart of the Flutter engine. */
void onPreEngineRestart();

void onDisplayPlatformView(int viewId, int x, int y, int width, int height);
Copy link

Choose a reason for hiding this comment

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

this can be removed as well.

flutterLoader.ensureInitializationComplete(context, dartVmArgs);

flutterJNI.addEngineLifecycleListener(engineLifecycleListener);
flutterJni.setPlatformViewsController(platformViewsController);
Copy link

Choose a reason for hiding this comment

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

my mistake: flutterJNI

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 bad, I should have caught that- should be fixed now

@blasten
Copy link

blasten commented Jun 3, 2020

One last thing, let's add a test to https://github.com/flutter/engine/blob/077918dcfdd9a1c34d235f23f45d1c89514203ce/shell/platform/android/test/io/flutter/embedding/engine/FlutterJNITest.java.

The test case can ensure that platformViewsController.onDisplayPlatformView is called when onDisplayPlatformView is called.

Later on, we can continue extending the cases as we progress through the implementation.

assertEquals(1, callbackInvocationCount.get());

// --- Execute Test ---
flutterJNI.onDisplayPlatformView(0, 0, 0, 0, 0);
Copy link

@blasten blasten Jun 3, 2020

Choose a reason for hiding this comment

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

hmm. I think this needs to go in a separate @Test. Something like:

@Test
public void onDisplayPlatformView__callsPlatformViewsController() {
  FlutterJNI flutterJNI = new FlutterJNI();
  flutterJNI.setPlatformViewsController(new PlatformViewsController() {
      // Override onDisplayPlatformView and increase counter.
  });

  flutterJNI.onDisplayPlatformView(/*viewId=*/ 1, /*x=*/ 10, /*y=*/ 20, /*width=*/ 100, /*height=*/ 200);

  // assert that PlatformViewsController#onDisplayPlatformView  was called with the same arguments passed above.
}

Copy link

Choose a reason for hiding this comment

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

Typically unit tests are testing a single "unit" of functionality. Here the "unit" is that PlatformViewsController#onDisplayPlatformView is called.

Copy link

@blasten blasten Jun 3, 2020

Choose a reason for hiding this comment

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

Also, bonus point if we check that it's called with the right arguments. e.g. the id, x, y, width, height should match the ones you passed, so I would actually give some real values to the call:

 flutterJNI.onDisplayPlatformView(/*viewId=*/ 1, /*x=*/ 10, /*y=*/ 20, /*width=*/ 100, /*height=*/ 200);

Then, collect this values in the overridden method and assert that they are the same as the one you passed.

Copy link

Choose a reason for hiding this comment

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

You can use Mockito to achieve this. See:

PlatformViewsController platformViewsController = mock(PlatformViewsController.class);

int counter = 0;

FlutterJNI flutterJNI = new FlutterJNI();
flutterJNI.setPlatformViewsController(new PlatformViewsController() {
Copy link

Choose a reason for hiding this comment

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

If you are using Mockito, then this can be simplified a bit. e.g.

import static org.mockito.Mockito.verify;
@Test 
public void onDisplayPlatformView__callsPlatformViewsController() {
  PlatformViewsController platformViewsController = mock(PlatformViewsController.class);

  FlutterJNI flutterJNI = new FlutterJNI();
  flutterJNI.setPlatformViewsController(platformViewsController);

  // --- Execute Test ---
  flutterJNI.onDisplayPlatformView(/*viewId=*/ 1, /*x=*/ 10, /*y=*/ 20, /*width=*/ 100, /*height=*/ 200);

  // --- Verify Results ---
  verify(platformViewsController, times(1)).onDisplayPlatformView(/*viewId=*/ 1, /*x=*/ 10, /*y=*/ 20, /*width=*/ 100, /*height=*/ 200);
}

Copy link

@blasten blasten left a comment

Choose a reason for hiding this comment

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

LGTM

@cg021 cg021 merged commit c8ab763 into flutter:master Jun 4, 2020
@cg021 cg021 deleted the jni-58288 branch June 4, 2020 16:20
@blasten
Copy link

blasten commented Jun 4, 2020

blasten pushed a commit that referenced this pull request Jun 4, 2020
blasten pushed a commit that referenced this pull request Jun 4, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 4, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 4, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 4, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants