Injected wifi-p2p-manager

This commit is contained in:
s-ayush2903 2020-11-17 00:18:56 +05:30
parent 03ee5065d0
commit 6935fa6141
No known key found for this signature in database
GPG Key ID: B4341DD08B2371CB
5 changed files with 18 additions and 9 deletions

View File

@ -15,7 +15,7 @@ jobs:
coverageReport:
strategy:
matrix:
api-level: [21, 21]
api-level: [21, 27, 27, 21]
fail-fast: false
runs-on: macOS-latest
steps:

View File

@ -21,14 +21,15 @@ package org.kiwix.kiwixmobile.di.modules
import android.content.Context
import android.location.LocationManager
import android.net.wifi.WifiManager
import android.net.wifi.p2p.WifiP2pManager
import dagger.Module
import dagger.Provides
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.core.zim_manager.MountPointProducer
import org.kiwix.kiwixmobile.di.KiwixScope
import org.kiwix.kiwixmobile.zim_manager.Fat32Checker
import org.kiwix.kiwixmobile.zim_manager.FileWritingFileSystemChecker
import org.kiwix.kiwixmobile.zim_manager.MountFileSystemChecker
import org.kiwix.kiwixmobile.core.zim_manager.MountPointProducer
@Module
object KiwixModule {
@ -52,4 +53,9 @@ object KiwixModule {
sharedPreferenceUtil,
listOf(MountFileSystemChecker(mountPointProducer), FileWritingFileSystemChecker())
)
@Provides
@KiwixScope
fun providesWiFiP2pManager(context: Context): WifiP2pManager =
context.getSystemService(Context.WIFI_P2P_SERVICE) as WifiP2pManager
}

View File

@ -21,10 +21,11 @@ package org.kiwix.kiwixmobile.di.modules
import android.app.NotificationManager
import android.app.Service
import android.content.Context
import android.net.wifi.p2p.WifiP2pManager
import dagger.Module
import dagger.Provides
import org.kiwix.kiwixlib.Library
import org.kiwix.kiwixlib.JNIKiwixServer
import org.kiwix.kiwixlib.Library
import org.kiwix.kiwixmobile.di.ServiceScope
import org.kiwix.kiwixmobile.webserver.WebServerHelper
import org.kiwix.kiwixmobile.webserver.wifi_hotspot.HotspotNotificationManager

View File

@ -19,7 +19,6 @@ package org.kiwix.kiwixmobile.localFileTransfer
import android.app.Activity
import android.content.BroadcastReceiver
import android.content.Context
import android.content.IntentFilter
import android.net.Uri
import android.net.wifi.WpsInfo
@ -61,7 +60,8 @@ import javax.inject.Inject
class WifiDirectManager @Inject constructor(
private val activity: Activity,
private val sharedPreferenceUtil: SharedPreferenceUtil,
private val alertDialogShower: AlertDialogShower
private val alertDialogShower: AlertDialogShower,
private val manager: WifiP2pManager
) : ChannelListener, PeerListListener, ConnectionInfoListener, P2pEventListener {
var callbacks: Callbacks? = null
@ -74,12 +74,14 @@ class WifiDirectManager @Inject constructor(
// Whether channel has retried connecting previously
private var shouldRetry = true
// @Inject
// lateinit var manager: WifiP2pManager
// Overall manager of Wifi p2p connections for the module
// Initialize as Nullable WifiP2pManager to counter Kt. TypeCastException on API 27;
// See: https://github.com/kiwix/kiwix-android/issues/2488
private val manager: WifiP2pManager? by lazy(LazyThreadSafetyMode.NONE) {
activity.getSystemService(Context.WIFI_P2P_SERVICE) as WifiP2pManager?
}
// private val manager: WifiP2pManager? by lazy(LazyThreadSafetyMode.NONE) {
// activity.getSystemService(Context.WIFI_P2P_SERVICE) as WifiP2pManager?
// }
// Interface to the device's underlying wifi-p2p framework
private var channel: Channel? = null

View File

@ -26,8 +26,8 @@ import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import org.kiwix.kiwixlib.JNIKiwixException;
import org.kiwix.kiwixlib.Library;
import org.kiwix.kiwixlib.JNIKiwixServer;
import org.kiwix.kiwixlib.Library;
import org.kiwix.kiwixmobile.core.utils.ServerUtils;
import org.kiwix.kiwixmobile.webserver.wifi_hotspot.IpAddressCallbacks;