-
Notifications
You must be signed in to change notification settings - Fork 626
Add uploadScreenshot to FirebaseAppDistributionTesterApiClient #3814
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
Conversation
Coverage Report 1Affected Products
Test Logs
Notes |
Size Report 1Affected Products
Test Logs
Notes |
String.format("upload/v1alpha/%s:uploadArtifact?type=SCREENSHOT", feedbackName); | ||
ByteArrayOutputStream stream = new ByteArrayOutputStream(); | ||
screenshot.compress(Bitmap.CompressFormat.PNG, /* quality= */ 100, stream); | ||
byte[] bytes = stream.toByteArray(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's pretty inefficient. You're first writing the bitmap to a ByteArrayOutputStream, then copy it into a byte array and then eventually send it to the HTTP connection's output stream. So the image ends up in memory multiple times. At least on low-end devices this might be noticible.
It might make sense to refactor the TesterHttpClient
to either directly accept a Bitmap (although that would be kinda ugly breaking encapsulation) or a lambda to provide the data. Maybe the method would have a parameter Consumer<OutputStream>
, so the labda would be stream -> screenshot.compress(Bitmap.CompressFormat.PNG, /* quality= */ 100, stream)
Also, currently the TesterHttpClient
wraps the connections output stream in a GZIPOutputStream
and sets the header Content-Encoding: gzip
which would waste CPU trying to compress an already compressed bitmap. So the API exposed for the bitmap upload should not do that.
Sorry to not notice this in the previous PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. I added a bespoke interface to allow us to handle the IOExceptions in the http client class though.
please rebase |
92ce55d
to
6b48593
Compare
import java.io.UnsupportedEncodingException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.zip.GZIPOutputStream; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you now never compress and data. I think that's probably OK, since all our API calls (except the screenshot upload which does it's own compression) tend to have pretty small payloads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I figure this seems OK for now and we can always revisit.
No description provided.