Repository navigation
Add DisplayInfo and EDID encoding to expose display attributes without a raw EDID - #3415
Conversation
Add the inverse of the existing get*/is* parsers so an EDID byte array can be built from field values: newEdidTemplate, set* encoders for the encodable header fields, a serial-number descriptor (getProductSerialNumber/ setProductSerialNumber), generic setDescriptor/setDescriptorText writers for all four descriptor slots, and updateChecksum. Extract the byte-offset magic numbers into named constants and use them in the existing getters. Tests cover value round-trips, byte round-trips for the injective fields, the four-slot descriptor writers, and the synthesize-then-reparse path.
DisplayInfo is a public interface exposing the decoded EDID fields plus getEdid()/isEdidSynthetic(). DisplayInfoImpl (not public API) backs it: it is constructed either from a raw EDID, decoding fields on demand, or from field values for a display that reports its attributes without an EDID (such as a built-in macOS Retina panel), in which case getEdid() lazily synthesizes a spec-compliant EDID via EdidUtil and isEdidSynthetic() is true. Keeping the multi-arg constructor on the non-API impl rather than the public interface lets the synthetic field set evolve without breaking compatibility.
Display now exposes the decoded DisplayInfo and a flag indicating whether its EDID was synthesized from reported attributes rather than read from the display. AbstractDisplay wraps a DisplayInfo (instantiating DisplayInfoImpl) so every platform implementation inherits the new methods unchanged; a new protected constructor accepts a DisplayInfo for the synthetic case.
The new Display/DisplayInfo methods are binary-compatible-breaking additions to a public interface, so bump the development version from 7.3.3-SNAPSHOT to 7.4.0-SNAPSHOT and update the CHANGELOG and snapshot doc links accordingly.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
✅ Files skipped from review due to trivial changes (3)
🚧 Files skipped from review as they are similar to previous changes (5)
📜 Recent review details⏰ Context from checks skipped due to timeout. (10)
📝 WalkthroughWalkthroughThe PR adds ChangesDisplayInfo API and EDID encoding
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3415 +/- ##
============================================
+ Coverage 74.96% 75.19% +0.22%
Complexity 76 76
============================================
Files 579 580 +1
Lines 21401 21581 +180
Branches 3564 3580 +16
============================================
+ Hits 16044 16227 +183
- Misses 3326 3329 +3
+ Partials 2031 2025 -6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
README.md (1)
54-55: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse the same trailing-slash style for both snapshot links. The FFM URL includes a trailing slash and redirects, while the JNA URL does not; matching the format keeps the docs consistent.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@README.md` around lines 54 - 55, The snapshot links in the README are inconsistent because the JNA and FFM URLs use different trailing-slash styles. Update the JNA link to match the same trailing-slash format used by the FFM link so both references are consistent and located together in the snapshot list.oshi-common/src/test/java/oshi/util/EdidUtilTest.java (1)
103-194: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd boundary cases for the encoder contracts.
These tests miss the cases that currently break round-trip behavior: unsigned byte values like
hcm=200, and length-valid serials such as"41424344"or non-alphanumeric 4-character strings. Add assertions for those when tightening the setters/getters.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@oshi-common/src/test/java/oshi/util/EdidUtilTest.java` around lines 103 - 194, The EdidUtilTest coverage is missing boundary encoder-contract cases that can break round-trips for unsigned byte fields and alternative 4-character serial encodings. Extend testFieldRoundTrip and/or testSetSerialNo to verify EdidUtil.setHcm/getHcm with a high unsigned value like 200, and to cover serial round-trips for a length-valid hex string such as "41424344" plus a non-alphanumeric 4-character value, using the existing EdidUtil setter/getter methods to confirm the contract still holds.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@oshi-common/src/main/java/oshi/util/EdidUtil.java`:
- Around line 118-123: Treat EDID one-byte fields as unsigned in the relevant
getters/setters and enforce range checks so values above 255 are rejected
instead of wrapping. Update the EDID accessors in EdidUtil, especially getYear
and the related setters/parsers for height/width/year fields, to mask bytes with
an unsigned conversion before arithmetic and to validate input ranges before
writing. Make sure the round-trip behavior for methods like getYear and the
HCM/year setters stays consistent with the stored EDID bytes.
- Around line 318-340: Validate the inputs in setManufacturerID and setProductID
before writing into the EDID buffer: reject manufacturer IDs that are not
exactly three uppercase A-Z letters, and reject product IDs that do not fit in
an unsigned 16-bit value. Keep the encoding logic unchanged for valid values,
but throw an error or otherwise fail fast on malformed inputs so the synthetic
EDID created by EdidUtil round-trips cleanly through getManufacturerID and
getProductID.
- Around line 354-368: The serial number handling in EdidUtil.setSerialNo is too
permissive and allows inputs that do not round-trip through getSerialNo().
Tighten the validation so only 8-character hex values that correspond to a
numeric serial and 4-character printable serials that will be preserved verbatim
are accepted, and reject ambiguous cases like hex-looking ASCII strings or
non-alphanumeric 4-character values. Update the parsing/validation logic in
setSerialNo and keep the mapping consistent with getSerialNo and
SERIAL_NUMBER_OFFSET.
---
Nitpick comments:
In `@oshi-common/src/test/java/oshi/util/EdidUtilTest.java`:
- Around line 103-194: The EdidUtilTest coverage is missing boundary
encoder-contract cases that can break round-trips for unsigned byte fields and
alternative 4-character serial encodings. Extend testFieldRoundTrip and/or
testSetSerialNo to verify EdidUtil.setHcm/getHcm with a high unsigned value like
200, and to cover serial round-trips for a length-valid hex string such as
"41424344" plus a non-alphanumeric 4-character value, using the existing
EdidUtil setter/getter methods to confirm the contract still holds.
In `@README.md`:
- Around line 54-55: The snapshot links in the README are inconsistent because
the JNA and FFM URLs use different trailing-slash styles. Update the JNA link to
match the same trailing-slash format used by the FFM link so both references are
consistent and located together in the snapshot list.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 23e2ef77-52c9-49ea-9a88-543d0ac8f19d
📒 Files selected for processing (18)
CHANGELOG.mdREADME.mdoshi-benchmark/pom.xmloshi-common/pom.xmloshi-common/src/main/java/oshi/hardware/Display.javaoshi-common/src/main/java/oshi/hardware/DisplayInfo.javaoshi-common/src/main/java/oshi/hardware/DisplayInfoImpl.javaoshi-common/src/main/java/oshi/hardware/common/AbstractDisplay.javaoshi-common/src/main/java/oshi/util/EdidUtil.javaoshi-common/src/test/java/oshi/hardware/DisplayInfoImplTest.javaoshi-common/src/test/java/oshi/util/EdidUtilTest.javaoshi-core-ffm/pom.xmloshi-core/pom.xmloshi-demo/pom.xmloshi-dist/pom.xmloshi-metrics/pom.xmlpom.xmlsrc/site/markdown/index.md
📜 Review details
⏰ Context from checks skipped due to timeout. (14)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 26, windows-latest
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 21, windows-latest
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Test JDK 26, macos-latest
- GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Test JDK 26, ubuntu-latest
- GitHub Check: Analyze (java)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
- GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.
Applied to files:
oshi-common/src/main/java/oshi/hardware/DisplayInfo.javaoshi-common/src/main/java/oshi/hardware/Display.javaoshi-common/src/main/java/oshi/hardware/DisplayInfoImpl.javaoshi-common/src/main/java/oshi/hardware/common/AbstractDisplay.javaoshi-common/src/main/java/oshi/util/EdidUtil.java
🪛 ast-grep (0.44.0)
oshi-common/src/main/java/oshi/util/EdidUtil.java
[warning] 514-514: Use a randomly-generated IV
Context: byte[] bytes = text.getBytes(StandardCharsets.US_ASCII);
Note: [CWE-329] Generation of Predictable IV with CBC Mode.
(random-iv)
🪛 markdownlint-cli2 (0.22.1)
CHANGELOG.md
[warning] 3-3: Heading levels should only increment by one level at a time
Expected: h2; Actual: h5
(MD001, heading-increment)
🔇 Additional comments (17)
pom.xml (1)
7-7: LGTM!oshi-benchmark/pom.xml (1)
8-8: LGTM!oshi-common/pom.xml (1)
8-8: LGTM!oshi-core-ffm/pom.xml (1)
8-8: LGTM!src/site/markdown/index.md (1)
54-55: 📐 Maintainability & Code QualityInconsistent trailing slash in snapshot URLs.
Line 54 (JNA) omits the trailing slash while Line 55 (FFM) includes it. Verify both URLs resolve correctly and prefer a consistent format.
oshi-core/pom.xml (1)
8-8: LGTM!oshi-demo/pom.xml (1)
8-8: LGTM!oshi-dist/pom.xml (1)
8-8: LGTM!oshi-metrics/pom.xml (1)
8-8: LGTM!CHANGELOG.md (1)
1-9: LGTM!oshi-common/src/main/java/oshi/util/EdidUtil.java (1)
27-60: LGTM!Also applies to: 73-94, 107-110, 131-145, 175-181, 234-307, 370-378, 396-411, 433-540
oshi-common/src/main/java/oshi/hardware/DisplayInfo.java (1)
1-130: LGTM!oshi-common/src/main/java/oshi/hardware/DisplayInfoImpl.java (1)
1-230: LGTM!oshi-common/src/main/java/oshi/hardware/Display.java (1)
31-62: LGTM!oshi-common/src/main/java/oshi/hardware/common/AbstractDisplay.java (1)
9-56: LGTM!oshi-common/src/test/java/oshi/util/EdidUtilTest.java (1)
10-12: LGTM!Also applies to: 60-60, 166-184
oshi-common/src/test/java/oshi/hardware/DisplayInfoImplTest.java (1)
1-80: LGTM!
EdidUtil: - Read year/Hcm/Vcm as unsigned bytes so values above 127 don't sign-extend. - Validate setManufacturerID (three A-Z letters), setProductID (0-FFFF), setYear (1990-2245), and setHcm/setVcm (0-255), failing fast on inputs that would not round-trip. - Tighten setSerialNo to accept only values that reproduce verbatim through getSerialNo, rejecting hex-looking ASCII and non-alphanumeric 4-char strings. - getModel returns an empty string instead of crashing (NPE/assert) when the EDID has no monitor-name descriptor, and getProductSerialNumber returns an empty string rather than null when absent, both matching getSerialNo. DisplayInfoImpl: replace the double-checked lock in getEdid() with a synchronized accessor whose single branch is reachable both ways. Tests: cover the synthetic-instance getters, analog/empty-serial paths, the new validation and unsigned-byte boundary cases, getModel-absent and negative descriptor-type rendering, and the AbstractDisplay DisplayInfo constructor / isEdidSynthetic. Docs: make the JNA snapshot link trailing slash consistent with the FFM link.
005ee0a to
6532b47
Compare
…c() (#3438) Consolidate display data access under Display.getDisplayInfo(): - Deprecate Display.getEdid() (javadoc points to getDisplayInfo().getEdid(); scheduled for removal in the next major version). Java 8 target, so plain @deprecated with the since/removal intent documented in the @deprecated tag. - Remove Display.isEdidSynthetic(). It was added in #3415 during this (still unreleased) 7.4.0 cycle, so removing it now avoids shipping then deprecating a redundant method; DisplayInfo.isEdidSynthetic() remains the accessor. - Migrate internal consumers (DisplayTest, OsHwTextPanel demo) to getDisplayInfo().getEdid(); AbstractDisplayTest keeps getEdid() coverage via @SuppressWarnings until removal. - CHANGELOG: correct the #3415 entry and add the deprecation note.
Summary
Groundwork for #3404 (built-in macOS Retina panels expose no EDID). This adds a way to surface decoded display attributes whether or not a raw EDID is available, without changing any existing behavior. The macOS implementation that actually populates Retina panels is deferred to a follow-on PR.
EdidUtil
Adds the inverse of the existing
get*/is*parsers so an EDID can be built from field values:newEdidTemplate(),set*encoders for the encodable header fields, andupdateChecksum()getProductSerialNumber()/setProductSerialNumber()for the serial-number (0xFF) descriptor, distinct from the numericgetSerialNo()in bytes 12-15setDescriptor(slot, ...)/setDescriptorText(slot, ...)covering all four descriptor slotsA literal
edid -> value -> edidround trip isn't achievable for every field (e.g. the serial number's char-or-hex rendering, or a single digital bit), so the tests assert value round-trips for each field, exact byte round-trips for the injective fields, and a full synthesize-then-reparse path.DisplayInfo
New
DisplayInfopublic interface exposing the decoded EDID fields plusgetEdid()andisEdidSynthetic(). The backingDisplayInfoImpl(not public API) is built either from a raw EDID (fields decoded on demand) or from field values, in which case it lazily synthesizes a spec-compliant EDID and reportsisEdidSynthetic() == true. A synthesized EDID re-parses to the same values it was built from, so it is interchangeable with a real EDID forEdidUtildecoding; it carries only those values, not the extra detail a real panel's EDID may include.Keeping the multi-arg constructor on the non-API impl rather than on the public interface lets the synthetic field set grow without a compatibility break.
Display
DisplaygainsgetDisplayInfo()andisEdidSynthetic().AbstractDisplaywraps aDisplayInfo, so every platform implementation inherits both methods unchanged; a new protected constructor accepts aDisplayInfofor the synthetic case.Because these add methods to a public interface, the development version is bumped to 7.4.0-SNAPSHOT.
Part of #3404; the macOS Retina implementation will follow in a separate PR.
Summary by CodeRabbit