Add deeper network connectivity: WiFi info/scan/connect, Bonjour, WiFi Direct, USB, network-type events#5021
Merged
Merged
Conversation
…jour, WiFi Direct, USB, network type events
New core API surface under com.codename1.io.{wifi,bonjour,usb} plus
NetworkManager.addNetworkTypeListener. Each API surface is implemented
on Android (WifiManager / NsdManager / WifiP2pManager / UsbManager /
ConnectivityManager), iOS (CaptiveNetwork / NEHotspotConfiguration /
NSNetService / SCNetworkReachability), and JavaSE (best-effort
NetworkInterface + simulated scan results + JmDNS hook).
The maven plugin builders auto-inject the matching Android permissions
(ACCESS_WIFI_STATE, CHANGE_WIFI_STATE, ACCESS_NETWORK_STATE,
CHANGE_NETWORK_STATE, ACCESS_FINE_LOCATION, NEARBY_WIFI_DEVICES,
CHANGE_WIFI_MULTICAST_STATE, usb.host feature) and iOS
entitlements/Info.plist strings (wifi-info, HotspotConfiguration,
NSLocalNetworkUsageDescription, NSBonjourServices) only when the
relevant classes are referenced from the classpath -- so apps that
never touch these APIs see no manifest, entitlement, or Info.plist
change.
The Objective-C native bridge is gated by CN1_INCLUDE_WIFI_INFO,
CN1_INCLUDE_HOTSPOT, and CN1_INCLUDE_BONJOUR defines that IPhoneBuilder
flips on only when the corresponding API surface is referenced. Stock
apps therefore ship without any CaptiveNetwork, NetworkExtension, or
NSNetServiceBrowser symbols and pass Apple's API-usage scan cleanly.
The simulator prints a one-shot warning the first time each API is
called, listing the permissions/entitlements production builds will
need; a JVM shutdown hook summarises everything used during the run.
Documented in docs/developer-guide/Network-Connectivity.asciidoc.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The Android port compiles against the API 25 android.jar shipped in cn1-binaries, so the named constants Build.VERSION_CODES.Q (29) and Build.VERSION_CODES.S (31) and the WifiNetworkSpecifier class don't exist at build time. Switch to integer SDK_INT comparisons and reach WifiNetworkSpecifier.Builder via reflection so the file builds on the legacy SDK while the runtime path still works on Android 10+. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
Cloudflare Preview
|
Older javac (the JavaSE simulator port compiles at -source 1.7; the Android port at -source 1.6) requires anonymous-inner-class captures to be on final locals. Java 8's effectively-final inference is not in play. Hoist the captured Throwable / int into named final locals before referencing them from the inner class. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Collaborator
Author
|
Compared 20 screenshots: 20 matched. |
Contributor
|
Developer Guide build artifacts are available for download from this workflow run:
Developer Guide quality checks: |
…pter Vale (Microsoft style) and LanguageTool (US-English) each surface build-breaking issues. Apply the recommended substitutions: - Microsoft.Wordiness: "All of these" -> "These" - Microsoft.Adverbs: drop "accidentally" / "silently" - Microsoft.Auto: "auto-injected" -> "injected automatically" - Microsoft.Contractions: does not -> doesn't, cannot -> can't, will not -> won't, are not -> aren't, It is -> It's - LanguageTool MORFOLOGIK_RULE_EN_US: normalises -> normalizes, synthesised -> synthesized Verified locally with vale (10 -> 0 issues) and grepping for the British spellings (2 -> 0). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Collaborator
Author
|
Compared 110 screenshots: 110 matched. Native Android coverage
✅ Native Android screenshot tests passed. Native Android coverage
Benchmark ResultsDetailed Performance Metrics
|
Collaborator
Author
|
Compared 11 screenshots: 11 matched. |
ParparVM mangles each public static Java method into a C symbol but the .m file that calls it still needs a prototype. Without the include the clang compiler emits "call to undeclared function" -- a hard error under ISO C99+. Mirror the existing pattern used for IOSImplementation / IOSBiometrics / IOSSecureStorage / IOSNfc and pull in the generated header. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The default-encoding String/byte[] constructor and the no-locale toLowerCase / toUpperCase / String.format methods are flagged as high-priority SpotBugs violations under the quality gate. Pin every new call site to UTF-8 / Locale.US. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…connectivity helpers AndroidConnectivity and AndroidUsb hold platform BroadcastReceivers and NetworkCallbacks in static fields, populated when the first listener registers and torn down when the last detaches. The lifecycle matches AndroidImplementation's existing EDT-scoped cache pattern, which is already excluded for the same SpotBugs categories. Scope the new exclusion narrowly to these two classes. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
… block The empty 'if (targetSDKVersionInt >= 33 && !contains(INTERNET))' block was placeholder for a never-needed double-check. INTERNET is already in basePermissions and Bonjour over IPv6 multicast inherits it transparently. Drop the dead conditional. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Collaborator
Author
|
Compared 110 screenshots: 110 matched. Benchmark Results
Build and Run Timing
Detailed Performance Metrics
|
Collaborator
Author
|
Compared 110 screenshots: 110 matched. Benchmark Results
Build and Run Timing
Detailed Performance Metrics
|
…e, UnnecessaryImport) - NetworkManager.fireNetworkTypeChange: convert indexed for to foreach - CodenameOneImplementation: drop java.* qualifiers on Map / InputStream / OutputStream / IOException now that the imports are already in scope - BonjourService: drop the unused java.util.Hashtable import Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
✅ Continuous Quality ReportTest & Coverage
Static Analysis
Generated automatically by the PR CI workflow. |
…PI 21+ on Android Addresses review feedback on PR #5021: 1) Encapsulation: drop the IOImpl backdoor that exposed CodenameOneImplementation publicly. Instead each new API group has a narrow platform interface (WifiPlatform, WifiDirectPlatform, BonjourPlatform, UsbPlatform, NetworkTypePlatform) obtained from Display.getInstance().getXxxPlatform(). CodenameOneImplementation only carries small createXxxPlatform() factories; each port returns its concrete subclass, so the base implementation stays modular. 2) Old-device safety: AndroidConnectivity held static fields of type ConnectivityManager.NetworkCallback (API 21) which would fail class verification on KitKat (minSdkVersion 19). The Lollipop-only bits now live in *Lollipop helper classes that are only referenced from inside Build.VERSION.SDK_INT guards, so the KitKat verifier never loads them. 3) NetworkManager.isConnected(): cheap EDT-safe reachability check that returns false only when NETWORK_TYPE_NONE, avoiding the HTTP probe against autoDetectURL. 4) Documentation: - Drop the version "Codename One 8" mention. - Clarify JmDNS belongs in the application's executable-jar / simulator profile, not in the cn1app common pom (which would ship JmDNS to devices that already have native mDNS). - Replace the deinitializeImpl() lifecycle note with a battery- drain warning -- deinitializeImpl is internal API and shouldn't show up in developer docs. - Add a quick-check example for NetworkManager.isConnected(). 5) SpotBugs exclusion comment: rewrite the rationale to explain why LI_LAZY_INIT_* doesn't apply (EDT-bound install pattern, no actual race) instead of just "matches existing convention". Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ories
The empty 'new WifiPlatform() {}' anonymous classes I used as defaults
were instance inner classes that implicitly captured the enclosing
CodenameOneImplementation. Drop 'abstract' from each platform base class
so the default can be 'new WifiPlatform()' directly (no enclosing-this
capture). Move the NetworkTypePlatform fallback that bridges to the
legacy access-point API into a named static nested class for the same
reason.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The em-dash-style '--' inside the previous commit's exclude comment is illegal inside an XML <!-- comment --> (the parser reads it as the start of the closing delimiter). SpotBugs silently rejected the entire exclude file, which surfaced as a long list of pre-existing ST_WRITE_TO_STATIC / NP_BOOLEAN_RETURN_NULL / LI_LAZY_INIT_* findings in AndroidImplementation suddenly failing CI for this PR. Replace the offending '--' with ':' so the file parses again. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…y helpers * AndroidUsbPlatform.UsbStream: marked static; the inner class never reads outer state so pinning the platform instance for the stream's lifetime is unnecessary. Added a tiny staticUsb() shim so the static nested class can fetch UsbManager from AndroidImplementation context. * IOSWifiPlatform.scan / IOSBonjourPlatform.startBrowse: moved the anonymous Runnable into a private static helper so it no longer carries an implicit reference to the enclosing platform instance. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
UnnecessaryFullyQualifiedName: Display is already imported at the top of NetworkManager.java; the three new call sites for getCurrentNetworkType / install / uninstall don't need the package prefix. Co-Authored-By: Claude Opus 4.7 (1M context) <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.
Summary
Adds a new set of APIs under
com.codename1.io.{wifi,bonjour,usb}plusNetworkManager.addNetworkTypeListenerfor apps that need more than HTTP. Each API surface is implemented natively on Android, iOS, and (best-effort) the JavaSE simulator, with auto-injection of all matching Android permissions and iOS entitlements / Info.plist strings based on classpath scanning.What's new
com.codename1.io.wifi.WiFi-getCurrentSSID(),getBSSID(),getGateway(),getIp(),scan(...),connect(SSID, password, security).com.codename1.io.wifi.WiFiDirect- peer-to-peer (Android only).com.codename1.io.bonjour.{BonjourBrowser, BonjourPublisher}- mDNS / zeroconf.com.codename1.io.usb.Usb- USB host (Android only).NetworkManager.addNetworkTypeListener(NetworkTypeListener)+NETWORK_TYPE_*constants +getCurrentNetworkType().Platform implementations
WifiManager/ConnectivityManager/WifiNetworkSpecifier(API 29+) + legacyWifiConfigurationfallback /NsdManager/WifiP2pManager/UsbManager.CNCopySupportedInterfaces+CNCopyCurrentNetworkInfofor SSID/BSSID,getifaddrsfor IP/gateway,NEHotspotConfigurationfor connect,NSNetServiceBrowser/NSNetServicefor Bonjour,SCNetworkReachabilityfor type tracking. Scan / WiFi Direct / USB reportUnsupportedOperationException.NetworkInterface, returns fabricated scan results, no-op connect with logging, optional JmDNS Bonjour, prints required production permissions on first call + a summary at JVM shutdown.Build-tool auto-injection
The maven plugin scanners (
AndroidGradleBuilder/IPhoneBuilder) detect the new API usage and inject:ACCESS_WIFI_STATE,CHANGE_WIFI_STATE,ACCESS_NETWORK_STATE,CHANGE_NETWORK_STATE,ACCESS_FINE_LOCATION(maxSdkVersion=32),NEARBY_WIFI_DEVICES(targetSDK>=33),CHANGE_WIFI_MULTICAST_STATEfor Bonjour,android.hardware.usb.hostfeature for USB.com.apple.developer.networking.wifi-infoentitlement,com.apple.developer.networking.HotspotConfigurationentitlement (only whenWiFi.connectis referenced),NSLocationWhenInUseUsageDescription,NSLocalNetworkUsageDescription,NSBonjourServicesarray (defaulted to_http._tcp.; configurable viaios.NSBonjourServices).Objective-C gating
All entitlement-requiring iOS native code is
#ifdef'd behind three new defines and only switched on by IPhoneBuilder when the corresponding API surface is referenced:CN1_INCLUDE_WIFI_INFO-CNCopyCurrentNetworkInfo(CaptiveNetwork)CN1_INCLUDE_HOTSPOT-NEHotspotConfigurationManager(NetworkExtension.framework)CN1_INCLUDE_BONJOUR-NSNetServiceBrowser/NSNetServiceApps that never reference the new packages compile without any of these symbols -- so Apple's API-usage scanner does not flag them and no dangling entitlements need explanation during App Store review. Mirrors the existing
CN1_INCLUDE_NFCpattern.Documentation
docs/developer-guide/Network-Connectivity.asciidocwith quick-starts for each API, per-platform notes, required permissions/entitlements tables, simulator behaviour, and lifecycle guidance.developer-guide.asciidocbetween NFC and signing.Companion PR
The cloud build server has a divergent copy of
IPhoneBuilder.java/AndroidGradleBuilder.javathat must be updated in lockstep. That's tracked in: https://github.com/codenameone/BuildDaemon/pull/83Test plan
mvn -pl core,ios,android,codenameone-maven-plugin install)com.codename1.io.wifi.WiFi.getCurrentSSID()and confirm AndroidManifest.xml gainsACCESS_WIFI_STATE/ACCESS_NETWORK_STATE, iOS entitlements gainscom.apple.developer.networking.wifi-info, Info.plist gainsNSLocationWhenInUseUsageDescription, andIOSNative.mflipsCN1_INCLUDE_WIFI_INFOonBonjourBrowserand confirmNSLocalNetworkUsageDescription+NSBonjourServicesland in Info.plist andCN1_INCLUDE_BONJOURis enabled🤖 Generated with Claude Code