Repository navigation
Conversation
…sis capability * Write the EXIF offset tags alongside the timestamps EXIF timestamps are local time with nothing to say where that was, so two pictures taken in different timezones cannot be ordered against each other and one taken in the overlapping hour is ambiguous. Exif 2.31 added OffsetTime, OffsetTimeOriginal and OffsetTimeDigitized to answer it; all three go in beside the timestamps they qualify. removeTimestamp clears them too. A picture stripped of when it was taken but still carrying the timezone it was taken in has given away roughly where in the world that was, which is most of what stripping the timestamp was for. getAttribute is package-private rather than public: the tags with a meaning worth exposing already have named accessors. * Record where a CameraX video was taken Camera2 and the legacy backend have always called MediaRecorder.setLocation, and FileOutputOptions.Builder.setLocation was simply never called - so the same recording came out of CameraX with no location at all, which is the sort of difference between backends nobody goes looking for. The read has to be the non-blocking one. getGPSLocation waits briefly for a fix and is marked WorkerThread for it, while a CameraX recording starts on the main thread because that is where CameraX binds, so getLastKnownGPSLocation takes the fix the system already has or nothing. VideoQualityDeviceTest reads the finished file back rather than asking whether a recording happened: the location, the orientation, the resolution, and the codec profile declared in the bitstream. It pushes a known location through a mock provider, because waiting on a real fix makes the test a coin toss - a device indoors has none and the test could only skip. That needs the mock_location app op, and says so when it does not have it. * Say when a backend cannot analyze frames FrameStream hands the backend an ImageReader surface and waits for YUV planes to read back. The legacy backend cannot produce those: the original Camera API reports preview frames as bytes to a callback, and the only way to forward them is to draw them onto the consumer's surface, which is why video streams work there and frame analysis does not. Accepting the call and never honouring it is the worst of the options, because a caller waiting on frames that cannot arrive cannot tell that from a camera that is merely slow - it waits for a timeout and blames the camera. isFrameAnalysis- Supported answers the question, and startFrameAnalysis refuses outright rather than hanging. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Stop the device tests blaming the backend for a sleeping screen A camera needs a visible window to put its preview in, so on a dozing or locked device the host activity never reaches STARTED - and CameraX, which binds its use cases to that lifecycle, correctly declines to open. Camera2 has no such gate and opens anyway. The result was a suite that reported one backend working and another broken on the same device, when the real answer was that nobody had woken the phone up. Worse, withOpenCamera assumed rather than asserted, so all six CameraX tests skipped and the run looked clean. On a Pixel 7 Pro that hid the whole backend for as long as the screen was off, at thirty seconds a test. CameraTestActivity now turns the screen on and asks the keyguard to stand aside, so a plain connectedAndroidTest is as reliable as a carefully prepared one. A camera that still will not open is a failure, and the message reports the screen and keyguard state so the next person does not have to guess. DeviceState skips only for the one case the activity cannot fix: a device locked with a real PIN. From a sleeping Pixel 7 Pro the matrix went from six skipped and one failing in 5m48s to green in 1m36s. * Fit a played video with the same centre-crop as a preview VideoView hand-rolled the scale, the translation and the rotation twice over - once for files and once for streams - working in integers, swapping width and height by hand for the sideways orientations, and carrying a one-pixel correction for the difference between 90 and 270 degrees. TransformMath.center- Crop does the same job for every camera preview in the library, and does it in floating point against a rotated rectangle, so the two did not agree: a video and the preview it was recorded through were fitted to the same view by different arithmetic. Both overloads now go through centerCrop and asTextureTransform, exactly as CameraXMath does. 148 lines become 32, and the behaviour is the one that is already tested and already shipping on three backends. The test for the emulator crash is noted where it happens: reading YUV_420_888 images from the emulated camera under SwiftShader takes the API 28 emulator process down, which fails framesReachAnAnalyzer and aborts the rest of the run. It passes on hardware. * Skip the frame-analysis test on the emulator image that crashes on it Reading YUV_420_888 images from the emulated camera under SwiftShader takes the API 28 emulator process down with it. That failed framesReachAnAnalyzer and then aborted every test after it, so the image reported five tests out of eighteen and nobody could tell which half had not run. Skipped there, with the reason in the message. It passes on hardware on all three backends, so there is nothing here for the library to fix. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Building the ML Kit client is what reaches for the barcode model, and it throws IllegalStateException when ML Kit was never initialised - a vision dependency delivered through Play services, which an app can ship without. That exception came straight out of enterBarcodeScanner, so a camera library crashed an app over a missing model. The CameraX backend already declined the same failure in startBarcodeScanner, with a comment saying it used to take the whole app down; this is the path the other two backends take. enterBarcodeScanner now returns whether scanning started. The Compose wrapper says so in the log rather than discarding it, since a caller waiting on barcodes that can never arrive has no other way to tell that from a camera pointed at nothing. The resource suite grows the two entry points it was missing. Streams are the most expensive thing the library hands out - an encoder, a reader, two pipes and a thread each - and the most likely to be opened repeatedly, since every reconnection is a new one. The scanner is the one entry point that attaches a detector to a running session. Both are now cycled ten times and asserted to hold nothing, which is what caught the crash above. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Test the three places that had no test at all The planes-to-NV21 conversion, which turns a camera's three planes into the one buffer the JPEG encoder wants. It fails quietly: reading a luma row at its stride instead of its width shears the picture, taking the chroma planes in the wrong order swaps the colours, ignoring the chroma pixel stride tints it. None of that throws and the capture still writes a file. FakeImage could only build a single-plane frame, which is enough to measure one and not to convert one, so this path had never run - it now builds both the planar and semi-planar layouts with padded luma rows, poisons the padding so reading it shows up, and the result is checked byte for byte. The conversion turns out to be correct. The audio player's background thread, which is where everything the class does lives: reading the header the recorder sent, sizing a buffer from it, opening an AudioTrack, draining the stream and reporting the end. Nothing drove it, so a stream that ended without telling anyone, or one left open, looked exactly like a passing suite. And the scanned contact and licence wrappers, whose list getters were only ever asked for empty lists - so the wrapping loops never ran. They are given lists of deliberately different lengths now, because a wrapper that walked or sized the wrong collection passes every assertion when the lists are all the same length. * Run the unit suite at two API levels, and enforce the coverage floor Every test class was pinned to API 37, so every SDK_INT check in the library ran one way only and the other branch was dead by construction. They now run at 29 and 37, which is 805 tests instead of 403 and the library verified at two API levels rather than one. Three fragment classes needed a permission granted to get there. androidx.core guards a not-exported receiver with a permission it declares in its own manifest, and a library's unit-test manifest does not merge that in, so registering the fragment's receiver failed at 29 for a reason belonging to the test environment rather than to the fragment. Worth being straight about what this bought: five lines. The uncovered code is not SDK-gated branches, it is provoked failure - the catch blocks around CameraX's own futures, the extension paths that need vendor hardware to decline, the recording-finalize timeout. Covering those needs a seam to inject failures through, which is a change to production code and a decision for a human. The run at two API levels is worth keeping on its own merits. The whole-library floor goes from 63% to 70% of lines and 45% to 51% of branches, which is just under where unit tests alone now stand. CI was not running that check at all, so the floor it enforced was nothing; it runs now, which is what makes the floor a ratchet instead of a comment. * Walk more of the CameraX surface in the harness Thirteen of the backend's fifty public methods were never called by either test. The harness now asks the camera everything it can be asked - readiness, the exposure bounds it does not publish, the relative orientation, whether it can snapshot while recording, whether it tracks faces - and toggles the lens and the torch. Face detection is asserted against its documented contract rather than against a guess about the fake camera: the return value says whether the camera is now in the state that was asked for, so it has to agree with what the camera says it can do, and stopping has to succeed either way. startRecording, attachSurface and detachSurface stay out, and the class comment now says why rather than leaving the next person to find out: each binds a second output, CameraX shares a stream by copying it through an OpenGL processor, and there is no GL off a device - it dies in the GL initializer before reaching anything worth asserting. The device matrix covers them on hardware, on all three backends. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Second of four stacked PRs, based on
pr/1-foundation. The diff here is only this group's four commits.OffsetTime,OffsetTimeOriginalandOffsetTimeDigitizednow go in beside the timestamps they qualify, andremoveTimestampclears them too — a picture stripped of when it was taken but still carrying its timezone has given away roughly where in the world that was.FileOutputOptions.Builder.setLocationwas simply never called, while camera2 and legacy have always calledMediaRecorder.setLocation— so the same recording came out of CameraX with no location at all. Proven both ways on hardware: with the line,+37.4220-122.0840/; without it, nothing. The read has to be the non-blocking one, since a CameraX recording starts on the main thread.FrameStreamhands the backend an ImageReader surface and waits for YUV planes. The legacy backend cannot produce those — it reports preview frames as bytes and can only draw them onto a surface, which is why video streams work there and frame analysis does not. Accepting the call and never honouring it is the worst option, because a caller waiting on frames that cannot arrive cannot tell that from a slow camera.isFrameAnalysisSupported()answers, andstartFrameAnalysisrefuses outright.withOpenCameraassumed rather than asserted, so all six CameraX tests skipped and the run looked clean — on a dozing Pixel 7 Pro that hid the whole backend, at thirty seconds a test, because CameraX binds to the host lifecycle and declines while Camera2 opens anyway. The test activity now turns the screen on; a camera that still will not open is a failure. VideoView also stops hand-rolling its own scale, translation and rotation twice over and goes through the sameTransformMath.centerCropas every preview — 148 lines become 32, and a video no longer gets different arithmetic from the preview it was recorded through.