munim-wifi 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/MunimWifi.podspec +31 -0
- package/README.md +591 -0
- package/android/CMakeLists.txt +32 -0
- package/android/build.gradle +148 -0
- package/android/fix-prefab.gradle +51 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +6 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/munimwifi/HybridMunimWifi.kt +283 -0
- package/android/src/main/java/com/munimwifi/MunimWifiPackage.kt +20 -0
- package/ios/Bridge.h +8 -0
- package/ios/HybridMunimWifi.swift +222 -0
- package/lib/commonjs/index.js +216 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/specs/munim-wifi.nitro.js +6 -0
- package/lib/commonjs/specs/munim-wifi.nitro.js.map +1 -0
- package/lib/module/index.js +198 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/specs/munim-wifi.nitro.js +4 -0
- package/lib/module/specs/munim-wifi.nitro.js.map +1 -0
- package/lib/typescript/src/index.d.ts +120 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/specs/munim-wifi.nitro.d.ts +118 -0
- package/lib/typescript/src/specs/munim-wifi.nitro.d.ts.map +1 -0
- package/nitro.json +24 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/MunimWifi+autolinking.cmake +85 -0
- package/nitrogen/generated/android/MunimWifi+autolinking.gradle +27 -0
- package/nitrogen/generated/android/MunimWifiOnLoad.cpp +44 -0
- package/nitrogen/generated/android/MunimWifiOnLoad.hpp +25 -0
- package/nitrogen/generated/android/c++/JChannelInfo.hpp +61 -0
- package/nitrogen/generated/android/c++/JHybridMunimWifiSpec.cpp +262 -0
- package/nitrogen/generated/android/c++/JHybridMunimWifiSpec.hpp +78 -0
- package/nitrogen/generated/android/c++/JLocation.hpp +61 -0
- package/nitrogen/generated/android/c++/JScanOptions.hpp +61 -0
- package/nitrogen/generated/android/c++/JVariant_NullType_ChannelInfo.cpp +26 -0
- package/nitrogen/generated/android/c++/JVariant_NullType_ChannelInfo.hpp +71 -0
- package/nitrogen/generated/android/c++/JVariant_NullType_Double.cpp +26 -0
- package/nitrogen/generated/android/c++/JVariant_NullType_Double.hpp +69 -0
- package/nitrogen/generated/android/c++/JVariant_NullType_String.cpp +26 -0
- package/nitrogen/generated/android/c++/JVariant_NullType_String.hpp +70 -0
- package/nitrogen/generated/android/c++/JVariant_NullType_WifiNetwork.cpp +26 -0
- package/nitrogen/generated/android/c++/JVariant_NullType_WifiNetwork.hpp +73 -0
- package/nitrogen/generated/android/c++/JWifiFingerprint.hpp +89 -0
- package/nitrogen/generated/android/c++/JWifiNetwork.hpp +86 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimwifi/ChannelInfo.kt +41 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimwifi/HybridMunimWifiSpec.kt +107 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimwifi/Location.kt +41 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimwifi/MunimWifiOnLoad.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimwifi/ScanOptions.kt +41 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimwifi/Variant_NullType_ChannelInfo.kt +59 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimwifi/Variant_NullType_Double.kt +59 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimwifi/Variant_NullType_String.kt +59 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimwifi/Variant_NullType_WifiNetwork.kt +59 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimwifi/WifiFingerprint.kt +44 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimwifi/WifiNetwork.kt +59 -0
- package/nitrogen/generated/ios/MunimWifi+autolinking.rb +60 -0
- package/nitrogen/generated/ios/MunimWifi-Swift-Cxx-Bridge.cpp +105 -0
- package/nitrogen/generated/ios/MunimWifi-Swift-Cxx-Bridge.hpp +653 -0
- package/nitrogen/generated/ios/MunimWifi-Swift-Cxx-Umbrella.hpp +64 -0
- package/nitrogen/generated/ios/MunimWifiAutolinking.mm +33 -0
- package/nitrogen/generated/ios/MunimWifiAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridMunimWifiSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridMunimWifiSpecSwift.hpp +189 -0
- package/nitrogen/generated/ios/swift/ChannelInfo.swift +35 -0
- package/nitrogen/generated/ios/swift/Func_void_WifiFingerprint.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__variant_nitro__NullType__ChannelInfo_.swift +59 -0
- package/nitrogen/generated/ios/swift/Func_void_std__variant_nitro__NullType__WifiNetwork_.swift +59 -0
- package/nitrogen/generated/ios/swift/Func_void_std__variant_nitro__NullType__double_.swift +59 -0
- package/nitrogen/generated/ios/swift/Func_void_std__variant_nitro__NullType__std__string_.swift +59 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_WifiNetwork_.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_std__string_.swift +47 -0
- package/nitrogen/generated/ios/swift/HybridMunimWifiSpec.swift +68 -0
- package/nitrogen/generated/ios/swift/HybridMunimWifiSpec_cxx.swift +382 -0
- package/nitrogen/generated/ios/swift/Location.swift +47 -0
- package/nitrogen/generated/ios/swift/ScanOptions.swift +47 -0
- package/nitrogen/generated/ios/swift/Variant_NullType_ChannelInfo.swift +18 -0
- package/nitrogen/generated/ios/swift/Variant_NullType_Double.swift +18 -0
- package/nitrogen/generated/ios/swift/Variant_NullType_String.swift +18 -0
- package/nitrogen/generated/ios/swift/Variant_NullType_WifiNetwork.swift +18 -0
- package/nitrogen/generated/ios/swift/WifiFingerprint.swift +52 -0
- package/nitrogen/generated/ios/swift/WifiNetwork.swift +103 -0
- package/nitrogen/generated/shared/c++/ChannelInfo.hpp +87 -0
- package/nitrogen/generated/shared/c++/HybridMunimWifiSpec.cpp +33 -0
- package/nitrogen/generated/shared/c++/HybridMunimWifiSpec.hpp +90 -0
- package/nitrogen/generated/shared/c++/Location.hpp +87 -0
- package/nitrogen/generated/shared/c++/ScanOptions.hpp +87 -0
- package/nitrogen/generated/shared/c++/WifiFingerprint.hpp +97 -0
- package/nitrogen/generated/shared/c++/WifiNetwork.hpp +112 -0
- package/package.json +122 -0
- package/src/index.ts +221 -0
- package/src/specs/munim-wifi.nitro.ts +140 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
repositories {
|
|
3
|
+
google()
|
|
4
|
+
mavenCentral()
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
dependencies {
|
|
8
|
+
classpath "com.android.tools.build:gradle:8.8.0"
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
def reactNativeArchitectures() {
|
|
13
|
+
def value = rootProject.getProperties().get("reactNativeArchitectures")
|
|
14
|
+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
def isNewArchitectureEnabled() {
|
|
18
|
+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
apply plugin: "com.android.library"
|
|
22
|
+
apply plugin: 'org.jetbrains.kotlin.android'
|
|
23
|
+
apply from: '../nitrogen/generated/android/MunimWifi+autolinking.gradle'
|
|
24
|
+
apply from: "./fix-prefab.gradle"
|
|
25
|
+
|
|
26
|
+
if (isNewArchitectureEnabled()) {
|
|
27
|
+
apply plugin: "com.facebook.react"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
def getExtOrDefault(name) {
|
|
31
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["MunimWifi_" + name]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
def getExtOrIntegerDefault(name) {
|
|
35
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["MunimWifi_" + name]).toInteger()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
android {
|
|
39
|
+
namespace "com.munimwifi"
|
|
40
|
+
|
|
41
|
+
ndkVersion getExtOrDefault("ndkVersion")
|
|
42
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
43
|
+
|
|
44
|
+
defaultConfig {
|
|
45
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
46
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
47
|
+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
48
|
+
|
|
49
|
+
externalNativeBuild {
|
|
50
|
+
cmake {
|
|
51
|
+
cppFlags "-frtti -fexceptions -Wall -Wextra -fstack-protector-all"
|
|
52
|
+
arguments "-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
|
|
53
|
+
abiFilters (*reactNativeArchitectures())
|
|
54
|
+
|
|
55
|
+
buildTypes {
|
|
56
|
+
debug {
|
|
57
|
+
cppFlags "-O1 -g"
|
|
58
|
+
}
|
|
59
|
+
release {
|
|
60
|
+
cppFlags "-O2"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
externalNativeBuild {
|
|
68
|
+
cmake {
|
|
69
|
+
path "CMakeLists.txt"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
packagingOptions {
|
|
74
|
+
excludes = [
|
|
75
|
+
"META-INF",
|
|
76
|
+
"META-INF/**",
|
|
77
|
+
"**/libc++_shared.so",
|
|
78
|
+
"**/libfbjni.so",
|
|
79
|
+
"**/libjsi.so",
|
|
80
|
+
"**/libfolly_json.so",
|
|
81
|
+
"**/libfolly_runtime.so",
|
|
82
|
+
"**/libglog.so",
|
|
83
|
+
"**/libhermes.so",
|
|
84
|
+
"**/libhermes-executor-debug.so",
|
|
85
|
+
"**/libhermes_executor.so",
|
|
86
|
+
"**/libreactnative.so",
|
|
87
|
+
"**/libreactnativejni.so",
|
|
88
|
+
"**/libturbomodulejsijni.so",
|
|
89
|
+
"**/libreact_nativemodule_core.so",
|
|
90
|
+
"**/libjscexecutor.so"
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
buildFeatures {
|
|
95
|
+
buildConfig true
|
|
96
|
+
prefab true
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
buildTypes {
|
|
100
|
+
release {
|
|
101
|
+
minifyEnabled false
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
lintOptions {
|
|
106
|
+
disable "GradleCompatible"
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
compileOptions {
|
|
110
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
111
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
sourceSets {
|
|
115
|
+
main {
|
|
116
|
+
if (isNewArchitectureEnabled()) {
|
|
117
|
+
java.srcDirs += [
|
|
118
|
+
// React Codegen files
|
|
119
|
+
"${project.buildDir}/generated/source/codegen/java"
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
repositories {
|
|
127
|
+
mavenCentral()
|
|
128
|
+
google()
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
dependencies {
|
|
133
|
+
// For < 0.71, this will be from the local maven repo
|
|
134
|
+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
135
|
+
//noinspection GradleDynamicVersion
|
|
136
|
+
implementation "com.facebook.react:react-native:+"
|
|
137
|
+
|
|
138
|
+
// Add a dependency on NitroModules
|
|
139
|
+
implementation project(":react-native-nitro-modules")
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (isNewArchitectureEnabled()) {
|
|
143
|
+
react {
|
|
144
|
+
jsRootDir = file("../src/")
|
|
145
|
+
libraryName = "MunimWifi"
|
|
146
|
+
codegenJavaPackageName = "com.munimwifi"
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
tasks.configureEach { task ->
|
|
2
|
+
// Make sure that we generate our prefab publication file only after having built the native library
|
|
3
|
+
// so that not a header publication file, but a full configuration publication will be generated, which
|
|
4
|
+
// will include the .so file
|
|
5
|
+
|
|
6
|
+
def prefabConfigurePattern = ~/^prefab(.+)ConfigurePackage$/
|
|
7
|
+
def matcher = task.name =~ prefabConfigurePattern
|
|
8
|
+
if (matcher.matches()) {
|
|
9
|
+
def variantName = matcher[0][1]
|
|
10
|
+
task.outputs.upToDateWhen { false }
|
|
11
|
+
task.dependsOn("externalNativeBuild${variantName}")
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
afterEvaluate {
|
|
16
|
+
def abis = reactNativeArchitectures()
|
|
17
|
+
rootProject.allprojects.each { proj ->
|
|
18
|
+
if (proj === rootProject) return
|
|
19
|
+
|
|
20
|
+
def dependsOnThisLib = proj.configurations.findAll { it.canBeResolved }.any { config ->
|
|
21
|
+
config.dependencies.any { dep ->
|
|
22
|
+
dep.group == project.group && dep.name == project.name
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (!dependsOnThisLib && proj != project) return
|
|
26
|
+
|
|
27
|
+
if (!proj.plugins.hasPlugin('com.android.application') && !proj.plugins.hasPlugin('com.android.library')) {
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
def variants = proj.android.hasProperty('applicationVariants') ? proj.android.applicationVariants : proj.android.libraryVariants
|
|
32
|
+
// Touch the prefab_config.json files to ensure that in ExternalNativeJsonGenerator.kt we will re-trigger the prefab CLI to
|
|
33
|
+
// generate a libnameConfig.cmake file that will contain our native library (.so).
|
|
34
|
+
// See this condition: https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:build-system/gradle-core/src/main/java/com/android/build/gradle/tasks/ExternalNativeJsonGenerator.kt;l=207-219?q=createPrefabBuildSystemGlue
|
|
35
|
+
variants.all { variant ->
|
|
36
|
+
def variantName = variant.name
|
|
37
|
+
abis.each { abi ->
|
|
38
|
+
def searchDir = new File(proj.projectDir, ".cxx/${variantName}")
|
|
39
|
+
if (!searchDir.exists()) return
|
|
40
|
+
def matches = []
|
|
41
|
+
searchDir.eachDir { randomDir ->
|
|
42
|
+
def prefabFile = new File(randomDir, "${abi}/prefab_config.json")
|
|
43
|
+
if (prefabFile.exists()) matches << prefabFile
|
|
44
|
+
}
|
|
45
|
+
matches.each { prefabConfig ->
|
|
46
|
+
prefabConfig.setLastModified(System.currentTimeMillis())
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
2
|
+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
|
3
|
+
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
|
4
|
+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
|
5
|
+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
|
6
|
+
</manifest>
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
package com.munimwifi
|
|
2
|
+
|
|
3
|
+
import android.Manifest
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import android.content.pm.PackageManager
|
|
6
|
+
import android.net.wifi.ScanResult
|
|
7
|
+
import android.net.wifi.WifiManager
|
|
8
|
+
import android.os.Build
|
|
9
|
+
import android.util.Log
|
|
10
|
+
import androidx.core.app.ActivityCompat
|
|
11
|
+
import com.margelo.nitro.NitroModules
|
|
12
|
+
import com.margelo.nitro.munimwifi.HybridMunimWifiSpec
|
|
13
|
+
import java.util.concurrent.ConcurrentHashMap
|
|
14
|
+
|
|
15
|
+
class HybridMunimWifi : HybridMunimWifiSpec() {
|
|
16
|
+
private val TAG = "HybridMunimWifi"
|
|
17
|
+
private var wifiManager: WifiManager? = null
|
|
18
|
+
private val scanResults = ConcurrentHashMap<String, ScanResult>()
|
|
19
|
+
private var isScanning = false
|
|
20
|
+
|
|
21
|
+
private fun getWifiManager(): WifiManager? {
|
|
22
|
+
if (wifiManager == null) {
|
|
23
|
+
val context = NitroModules.applicationContext ?: return null
|
|
24
|
+
wifiManager = context.getSystemService(Context.WIFI_SERVICE) as? WifiManager
|
|
25
|
+
}
|
|
26
|
+
return wifiManager
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private fun hasPermission(permission: String): Boolean {
|
|
30
|
+
val context = NitroModules.applicationContext ?: return false
|
|
31
|
+
return ActivityCompat.checkSelfPermission(
|
|
32
|
+
context,
|
|
33
|
+
permission
|
|
34
|
+
) == PackageManager.PERMISSION_GRANTED
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private fun checkLocationPermission(): Boolean {
|
|
38
|
+
return hasPermission(Manifest.permission.ACCESS_FINE_LOCATION) ||
|
|
39
|
+
hasPermission(Manifest.permission.ACCESS_COARSE_LOCATION)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private fun getFrequencyChannel(frequency: Int): Int {
|
|
43
|
+
return when {
|
|
44
|
+
frequency in 2412..2484 -> ((frequency - 2412) / 5) + 1 // 2.4 GHz channels 1-14
|
|
45
|
+
frequency in 5170..5825 -> ((frequency - 5170) / 5) + 36 // 5 GHz channels
|
|
46
|
+
else -> 0
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private fun convertScanResult(scanResult: ScanResult): com.margelo.nitro.munimwifi.WifiNetwork {
|
|
51
|
+
val channel = getFrequencyChannel(scanResult.frequency)
|
|
52
|
+
val isSecure = scanResult.capabilities.contains("WPA") ||
|
|
53
|
+
scanResult.capabilities.contains("WEP") ||
|
|
54
|
+
scanResult.capabilities.contains("EAP")
|
|
55
|
+
|
|
56
|
+
return com.margelo.nitro.munimwifi.WifiNetwork(
|
|
57
|
+
ssid = scanResult.SSID ?: "",
|
|
58
|
+
bssid = scanResult.BSSID ?: "",
|
|
59
|
+
rssi = scanResult.level,
|
|
60
|
+
frequency = scanResult.frequency,
|
|
61
|
+
channel = channel,
|
|
62
|
+
capabilities = scanResult.capabilities,
|
|
63
|
+
isSecure = isSecure,
|
|
64
|
+
timestamp = System.currentTimeMillis()
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
override fun isWifiEnabled(): Boolean {
|
|
69
|
+
return getWifiManager()?.isWifiEnabled ?: false
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
override fun requestWifiPermission(): Boolean {
|
|
73
|
+
return checkLocationPermission()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
override fun scanNetworks(
|
|
77
|
+
maxResults: Double?,
|
|
78
|
+
timeout: Double?
|
|
79
|
+
): List<com.margelo.nitro.munimwifi.WifiNetwork> {
|
|
80
|
+
val manager = getWifiManager() ?: return emptyList()
|
|
81
|
+
|
|
82
|
+
if (!checkLocationPermission()) {
|
|
83
|
+
Log.w("MunimWifi", "Location permission not granted")
|
|
84
|
+
return emptyList()
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (!manager.isWifiEnabled) {
|
|
88
|
+
Log.w("MunimWifi", "Wi-Fi is not enabled")
|
|
89
|
+
return emptyList()
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
val success = manager.startScan()
|
|
94
|
+
if (!success) {
|
|
95
|
+
Log.w("MunimWifi", "Failed to start Wi-Fi scan")
|
|
96
|
+
return emptyList()
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Wait for scan to complete (max 10 seconds)
|
|
100
|
+
val maxWaitTime = (timeout?.toLong() ?: 10000L).coerceAtMost(10000L)
|
|
101
|
+
val startTime = System.currentTimeMillis()
|
|
102
|
+
while (System.currentTimeMillis() - startTime < maxWaitTime) {
|
|
103
|
+
val results = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
104
|
+
if (hasPermission(Manifest.permission.ACCESS_FINE_LOCATION)) {
|
|
105
|
+
manager.scanResults
|
|
106
|
+
} else {
|
|
107
|
+
emptyList()
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
manager.scanResults
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (results.isNotEmpty()) {
|
|
114
|
+
scanResults.clear()
|
|
115
|
+
results.forEach { result ->
|
|
116
|
+
val ssid = result.SSID ?: ""
|
|
117
|
+
if (ssid.isNotEmpty()) {
|
|
118
|
+
scanResults[ssid] = result
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
val networks = scanResults.values.map { convertScanResult(it) }
|
|
123
|
+
val max = maxResults?.toInt() ?: networks.size
|
|
124
|
+
return networks.take(max)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
Thread.sleep(100)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
Log.w("MunimWifi", "Scan timeout")
|
|
131
|
+
return emptyList()
|
|
132
|
+
} catch (e: SecurityException) {
|
|
133
|
+
Log.e("MunimWifi", "Security exception during scan", e)
|
|
134
|
+
return emptyList()
|
|
135
|
+
} catch (e: Exception) {
|
|
136
|
+
Log.e("MunimWifi", "Error scanning networks", e)
|
|
137
|
+
return emptyList()
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
override fun startScan(maxResults: Double?, timeout: Double?) {
|
|
142
|
+
isScanning = true
|
|
143
|
+
val manager = getWifiManager() ?: return
|
|
144
|
+
|
|
145
|
+
if (!checkLocationPermission()) {
|
|
146
|
+
Log.w("MunimWifi", "Location permission not granted")
|
|
147
|
+
isScanning = false
|
|
148
|
+
return
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (!manager.isWifiEnabled) {
|
|
152
|
+
Log.w("MunimWifi", "Wi-Fi is not enabled")
|
|
153
|
+
isScanning = false
|
|
154
|
+
return
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
try {
|
|
158
|
+
manager.startScan()
|
|
159
|
+
} catch (e: Exception) {
|
|
160
|
+
Log.e("MunimWifi", "Error starting scan", e)
|
|
161
|
+
isScanning = false
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
override fun stopScan() {
|
|
166
|
+
isScanning = false
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
override fun getSSIDs(): List<String> {
|
|
170
|
+
val manager = getWifiManager() ?: return emptyList()
|
|
171
|
+
val results = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
172
|
+
if (hasPermission(Manifest.permission.ACCESS_FINE_LOCATION)) {
|
|
173
|
+
manager.scanResults
|
|
174
|
+
} else {
|
|
175
|
+
emptyList()
|
|
176
|
+
}
|
|
177
|
+
} else {
|
|
178
|
+
manager.scanResults
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return results.mapNotNull { it.SSID }.distinct()
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
override fun getWifiFingerprint(): com.margelo.nitro.munimwifi.WifiFingerprint {
|
|
185
|
+
val manager = getWifiManager() ?: return com.margelo.nitro.munimwifi.WifiFingerprint(
|
|
186
|
+
networks = emptyList(),
|
|
187
|
+
timestamp = System.currentTimeMillis()
|
|
188
|
+
)
|
|
189
|
+
val results = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
190
|
+
if (hasPermission(Manifest.permission.ACCESS_FINE_LOCATION)) {
|
|
191
|
+
manager.scanResults
|
|
192
|
+
} else {
|
|
193
|
+
emptyList()
|
|
194
|
+
}
|
|
195
|
+
} else {
|
|
196
|
+
manager.scanResults
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
val networks = results.map { convertScanResult(it) }
|
|
200
|
+
|
|
201
|
+
return com.margelo.nitro.munimwifi.WifiFingerprint(
|
|
202
|
+
networks = networks,
|
|
203
|
+
timestamp = System.currentTimeMillis()
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
override fun getRSSI(ssid: String): Double? {
|
|
208
|
+
val manager = getWifiManager() ?: return null
|
|
209
|
+
val results = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
210
|
+
if (hasPermission(Manifest.permission.ACCESS_FINE_LOCATION)) {
|
|
211
|
+
manager.scanResults
|
|
212
|
+
} else {
|
|
213
|
+
emptyList()
|
|
214
|
+
}
|
|
215
|
+
} else {
|
|
216
|
+
manager.scanResults
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
val network = results.find { it.SSID == ssid }
|
|
220
|
+
return network?.level?.toDouble()
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
override fun getBSSID(ssid: String): String? {
|
|
224
|
+
val manager = getWifiManager() ?: return null
|
|
225
|
+
val results = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
226
|
+
if (hasPermission(Manifest.permission.ACCESS_FINE_LOCATION)) {
|
|
227
|
+
manager.scanResults
|
|
228
|
+
} else {
|
|
229
|
+
emptyList()
|
|
230
|
+
}
|
|
231
|
+
} else {
|
|
232
|
+
manager.scanResults
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
val network = results.find { it.SSID == ssid }
|
|
236
|
+
return network?.BSSID
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
override fun getChannelInfo(ssid: String): com.margelo.nitro.munimwifi.ChannelInfo? {
|
|
240
|
+
val manager = getWifiManager() ?: return null
|
|
241
|
+
val results = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
242
|
+
if (hasPermission(Manifest.permission.ACCESS_FINE_LOCATION)) {
|
|
243
|
+
manager.scanResults
|
|
244
|
+
} else {
|
|
245
|
+
emptyList()
|
|
246
|
+
}
|
|
247
|
+
} else {
|
|
248
|
+
manager.scanResults
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
val network = results.find { it.SSID == ssid } ?: return null
|
|
252
|
+
val channel = getFrequencyChannel(network.frequency)
|
|
253
|
+
|
|
254
|
+
return com.margelo.nitro.munimwifi.ChannelInfo(
|
|
255
|
+
channel = channel,
|
|
256
|
+
frequency = network.frequency
|
|
257
|
+
)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
override fun getNetworkInfo(ssid: String): com.margelo.nitro.munimwifi.WifiNetwork? {
|
|
261
|
+
val manager = getWifiManager() ?: return null
|
|
262
|
+
val results = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
263
|
+
if (hasPermission(Manifest.permission.ACCESS_FINE_LOCATION)) {
|
|
264
|
+
manager.scanResults
|
|
265
|
+
} else {
|
|
266
|
+
emptyList()
|
|
267
|
+
}
|
|
268
|
+
} else {
|
|
269
|
+
manager.scanResults
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
val network = results.find { it.SSID == ssid } ?: return null
|
|
273
|
+
return convertScanResult(network)
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
override fun addListener(eventName: String) {
|
|
277
|
+
Log.d(TAG, "Adding listener for event: $eventName")
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
override fun removeListeners(count: Double) {
|
|
281
|
+
Log.d(TAG, "Removing $count listeners")
|
|
282
|
+
}
|
|
283
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
package com.munimwifi;
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.NativeModule;
|
|
4
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
5
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider;
|
|
6
|
+
import com.facebook.react.TurboReactPackage;
|
|
7
|
+
import com.margelo.nitro.munimwifi.MunimWifiOnLoad;
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
public class MunimWifiPackage : TurboReactPackage() {
|
|
11
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? = null
|
|
12
|
+
|
|
13
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = ReactModuleInfoProvider { emptyMap() }
|
|
14
|
+
|
|
15
|
+
companion object {
|
|
16
|
+
init {
|
|
17
|
+
MunimWifiOnLoad.initializeNative();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|