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

POC - RNG Emulator #387

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

POC - RNG Emulator #387

wants to merge 3 commits into from

Conversation

yschimke
Copy link
Contributor

@yschimke yschimke commented May 27, 2024

ClientMain (Client -> gRPC -> Server) spits out a similar PNG for SimplePreview, that running on an emulator does.

Quick and dirty POC for an alternative approach to #176

  • Runs the emulator controller gRPC that is used by Android Studio as well as https://github.com/google/android-emulator-webrtc
  • Implements a few methods of that controller getGps, setGps, getBattery, getScreenshot
  • Implements a custom gRPC service for launching a Compose preview
  • Server and Client running separately communicating with Square Wire gRPC

Current Hacks

  • The server should run as a typical Main method, instead of piggybacking on Robolectric Junit runners, but this was simpler for constructing
  • Should maintain different Robolectric sandboxes concurrently
  • Should support client providing the classpath with current classes, instead of limited to current project

Todo (after some discussion)

  • Cleanup and comment code
  • demonstrate it working with correct threading and a main with different sandboxes
  • implement enough to get the web rtc running and events
  • demonstrate running as a VS code preview?

@yschimke
Copy link
Contributor Author

yschimke commented May 27, 2024

Actually maybe the text is missing?

a.png
image

emulator
image

@yschimke
Copy link
Contributor Author

For discussion only at the moment, happy to close, but wanted to see if it's viable.

@takahirom
Copy link
Owner

@yschimke
Looks amazing.
How can we try this? I found some main methods and test code.

Maybe like this?

./gradlew emulator-server:testDebugUnitTest

And then run the emulator-client test main() in Android Studio?

@yschimke
Copy link
Contributor Author

At the moment it's clunky. I'm running the server in junit temporarily. It saves implementing all the sandbox config logic for a POC.

So run the testServer unit test method, it will print out it's started on port 8080.

Then run ClientMain. I had to turn off building the project on launch otherwise it waits for the unit test to finish which never does.

Sorry it's in such a rough state, but wanted to discuss the approach first

@takahirom
Copy link
Owner

I believe the main point would be to provide an interface shared with the Android Emulator. It sounds very promising. I tried using the android-emulator-webrtc, but setting it up with SSL and CORS is a bit difficult. It would be great if we could avoid these issues for users.

@yschimke
Copy link
Contributor Author

@takahirom what I might try is a minimal project, outside roborazzi. One composable, one preview. Implement there and include a web page, showing android-emulator-webrtc.

This is probably a slow burner project, but wanted to see if it aligns with what you were envisioning.

@takahirom
Copy link
Owner

Thanks. I think there are two use cases for the RNG emulator:

  • When we run instrumentation tests, we can observe the emulator's behavior. This approach is very intuitive for debugging the tests.
  • I would like to debug the app's implementation, similar to how we do with a standard emulator.

Sharing an interface with the emulator isn't necessary, but it would be intuitive to use the emulator in the usual way for debugging. There may be some challenges, however. If this becomes a blocker, we can proceed without the interface.

@yschimke
Copy link
Contributor Author

@takahirom I like that scope, it actually brings it inline with the POC. running within the test runner actually makes sense then.

So maybe at the start of a run, I'll print out the URL for a hosted webserver, and opening that will show you the internal progress?

@takahirom
Copy link
Owner

@yschimke

I'll print out the URL for a hosted webserver, and opening that will show you the internal progress?

Sounds good! So, you might run two servers, like a gRPC server and a web server, right?

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.

2 participants