Repository navigation
Fixed
- A separate bus created with
new NetStatusBus()can now be initialized on its own.initrecorded the starting type throughNetworkUtils.getNetType(), and the system network callbacks typed every change through the singleton's application, so callinginiton a separate bus threwIllegalStateExceptionunlessNetStatusBus.getInstance()had been initialized as well.initand both callbacks now query theConnectivityManagerof the application given to that bus'sinit. The singleton behaves the same as before.
Build
-
CI now runs Android Lint on the library (
:netbuslib:lintDebug) with warnings treated as errors, and uploads the lint report when it fails.GradleDependencyis disabled because the library's AndroidX versions are kept low on purpose so the host app's newer versions win. -
Removed two version checks lint flagged as always true with
minSdk 21(SDK_INT >= LOLLIPOPininit,@RequiresApi(LOLLIPOP)on the internal pre-7.0 callback). No behavior change. -
CI now also runs Android Lint on the sample app (
:app:lintDebug, warnings as errors;GradleDependencyandOldTargetApidisabled, the latter because its result depends on the newest SDK platform installed on the build machine); both lint reports are uploaded when either fails. -
The JitPack/Maven publication now also ships a
-javadoc.jarnext to the-sources.jar(withJavadocJar()on thereleasevariant), so IDEs can show the library's docs without the sources. The jar is rendered by AGP's Dokka-basedjavaDocReleaseGeneration. -
New
:netbuslib:javadocLinttask runs the JDKjavadocwith-Xdoclint:all -Werroron the public API; CI runs it together withjavaDocReleaseJar, and the Maven-local publication check also requires the-javadoc.jar. -
New
:netbuslib:japicmptask checks that the library stays binary compatible with the last release (1.2.0, fetched from JitPack) using japicmp. Only breaking changes to public or protected API fail it; additions pass. CI runs it and uploads the report when it fails. The baseline version (apiBaselineVersioninnetbuslib/build.gradle) is bumped after each release.
Tests
-
NetworkUtils.getNetType,isNetworkAvailableandisVpnActiveare now unit tested on both code paths. Their logic moved into package-private overloads that take theConnectivityManagerand the SDK level, so a mockedConnectivityManagercan drive the Android 6.0+ (NetworkCapabilities) and pre-6.0 (NetworkInfo) branches; on the JVMBuild.VERSION.SDK_INTis 0, so the 6.0+ branch never ran in tests before. The 16 new tests cover theonLostcase where the lost network is still reported as active (#6, #9), a VPN without a declared transport falling back to its underlying network (skipping the lost one and networks without capabilities), networks withoutINTERNET, and captive-portal Wi-Fi still counting as available. Public API and behavior are unchanged. -
NetworkUtils.isInternetValidated,isMeteredandgetMobileGenerationare now unit tested on every SDK branch too, using the same kind of package-private seams (isActiveNetworkValidated/isActiveNetworkMeteredtake theConnectivityManagerand SDK level,mobileGenerationtakes theTelephonyManagerand SDK level). The 14 new tests cover no network or vanished capabilities (not validated, counted as metered), captive-portal and LAN-only networks that are connected but not validated,TEMPORARILY_NOT_METEREDonly trusted from Android 11, the pre-6.0 fallbacks (isNetworkAvailableandisActiveNetworkMetered()),getDataNetworkType()on Android 7.0+ versusgetNetworkType()below, and aSecurityExceptionfromTelephonyManagerreturningUNKNOWN. Public API and behavior are unchanged. -
The system network callbacks are now unit tested:
DefaultNetworkCallbackImpl(Android 7.0+) and the pre-7.0NetworkCallbackImpltake theConnectivityManagerand SDK level, so 10 new tests drive them with mocks. They cover typingonAvailablefrom that network's own capabilities, the switch to cellular with noonLostand a lateonLostof the old network being ignored (#4), repeated capability changes delivered once, vanished capabilities or lostINTERNETreported asNONE, a VPN resolved through the bus's manager, the pre-7.0onLostwhile the lost network is still reported as active (#6, #9), the pre-6.0NetworkInfopath, and a separate bus going throughinit, callback registration and a change reachinggetCurrentNetType()and the LiveData. Addsandroidx.arch.core:core-testingas a test-only dependency.NetworkUtils.getNetType(ConnectivityManager, Network, int)is now public andNetworkUtils.typeOf(ConnectivityManager, NetworkCapabilities, int)is new; both are@RestrictTo(LIBRARY)internals, not supported API. japicmp passes (additions only).
Documentation
- Public API Javadoc is doclint-clean (was 30 warnings): added the missing
@param/@return/@throwstags onNetStatusBus,NetworkUtilsandNetSubscribe.mode(), and comments onNetStatusReceiver.unRegisterObserver/unRegisterAllObserverandConstrants.SETTING_REQUEST_CODE.NetworkUtilsand the deprecatedConstrantsnow declare their public no-arg constructor explicitly so it can carry a comment; the API is unchanged.
Sample app
- Sample app lint is clean (was 19 warnings): UI text moved to
strings.xml(no string literals in layouts orsetText), content descriptions on the network status images, monochrome layer for the adaptive launcher icons (Android 13 themed icons),FragmentContainerViewas the fragment container, no redundant white background on the fragment, andVectorPathsuppressed on the one static 120dp icon. The fiveGradleDependencywarnings are handled by disabling that check, as in the library. - Sample
targetSdkraised from 34 to 35. On Android 15 the sample's theme opts out of the enforced edge-to-edge layout (values-v35), since its simple layouts don't handle window insets; the screens look the same as before.