public class NetworkingRulesEngine( internal val networkRepository: NetworkRepository, internal val logger: NetworkStatusLogger = NetworkStatusLogger.Logging, private val networkingRules: NetworkingRules = NetworkingRules.Conservative ) { public fun preferredNetwork(requestType: RequestType): NetworkStatus? { val networks = networkRepository.networkStatus.value return networkingRules.getPreferredNetwork(networks, requestType) } public fun checkValidRequest( requestType: RequestType, currentNetworkType: NetworkType? ): RequestCheck { return networkingRules.checkValidRequest(requestType, currentNetworkType ?: NetworkType.Unknown("unknown")) } public fun isHighBandwidthRequest(requestType: RequestType): Boolean { return networkingRules.isHighBandwidthRequest(requestType) } @Suppress("UNUSED_PARAMETER") public fun reportConnectionFailure(inetSocketAddress: InetSocketAddress, networkType: NetworkType?) { // TODO check for no internet on BLE and other scenarios } }
Networking Rules that bridges between app specific rules and specific network actions, like opening a network socket.