Skip to content

Commit c3ac210

Browse files
update dependencies
1 parent 5011448 commit c3ac210

File tree

13 files changed

+45
-51
lines changed

13 files changed

+45
-51
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ dependencies {
4242
testImplementation 'androidx.test.ext:junit:1.1.3'
4343
testImplementation 'com.googlecode.junit-toolbox:junit-toolbox:2.4'
4444
testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0'
45-
testImplementation 'io.mockk:mockk:1.13.1'
45+
testImplementation 'io.mockk:mockk:1.13.2'
4646
testImplementation 'junit:junit:4.13.2'
4747
testImplementation 'org.mockito:mockito-core:4.8.0'
48-
testImplementation 'org.robolectric:robolectric:4.9-alpha-1'
48+
testImplementation 'org.robolectric:robolectric:4.9'
4949
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
5050
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
5151
// Android Test Dependencies

app/build.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#Build Properties
2-
#Tue Sep 27 11:23:37 EDT 2022
2+
#Sun Oct 02 11:20:18 EDT 2022
33
version_minor=0
44
version_store=61
55
version_patch=9
6-
version_build=2
6+
version_build=3
77
version_major=3

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2121
android:installLocation="auto">
2222

23+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
24+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
2325
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
2426
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
2527

26-
<uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION" />
27-
2828
<application
2929
android:allowBackup="true"
3030
android:fullBackupContent="true"

app/src/main/kotlin/com/vrem/wifianalyzer/permission/SystemPermission.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package com.vrem.wifianalyzer.permission
1919

2020
import android.annotation.TargetApi
2121
import android.app.Activity
22-
import android.content.Context
2322
import android.location.LocationManager
2423
import android.os.Build
2524
import com.vrem.annotation.OpenClass
@@ -29,7 +28,7 @@ import com.vrem.util.buildMinVersionP
2928
class SystemPermission(private val activity: Activity) {
3029
fun enabled(): Boolean =
3130
try {
32-
val locationManager = activity.getSystemService(Context.LOCATION_SERVICE) as LocationManager
31+
val locationManager = activity.getSystemService(LocationManager::class.java)
3332
locationEnabled(locationManager) || networkProviderEnabled(locationManager) || gpsProviderEnabled(
3433
locationManager
3534
)

app/src/main/kotlin/com/vrem/wifianalyzer/wifi/manager/WiFiManagerWrapper.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class WiFiManagerWrapper(
6666
listOf()
6767
}
6868

69+
@Suppress("DEPRECATION")
6970
fun wiFiInfo(): WifiInfo? =
7071
try {
7172
wifiManager.connectionInfo

app/src/main/kotlin/com/vrem/wifianalyzer/wifi/scanner/Cache.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ internal data class CacheKey(val bssid: String, val ssid: String)
3030
@OpenClass
3131
internal class Cache {
3232
private val scanResults: ArrayDeque<List<ScanResult>> = ArrayDeque(MAXIMUM)
33-
private var wifiInfo: WifiInfo? = null
3433
private var count: Int = COUNT_MIN
34+
var wifiInfo: WifiInfo? = null
3535

3636
fun scanResults(): List<CacheResult> =
3737
combineCache()
@@ -42,14 +42,13 @@ internal class Cache {
4242
.values
4343
.toList()
4444

45-
fun add(scanResults: List<ScanResult>, wifiInfo: WifiInfo?) {
45+
fun add(scanResults: List<ScanResult>) {
4646
count = if (count >= MAXIMUM * FACTOR) COUNT_MIN else count + 1
4747
val size = size()
4848
while (this.scanResults.size >= size) {
4949
this.scanResults.removeLastOrNull()
5050
}
5151
this.scanResults.addFirst(scanResults)
52-
this.wifiInfo = wifiInfo
5352
}
5453

5554
fun first(): List<ScanResult> = scanResults.first()
@@ -73,8 +72,6 @@ internal class Cache {
7372
}
7473
} else MINIMUM
7574

76-
fun wifiInfo(): WifiInfo? = wifiInfo
77-
7875
private fun calculate(first: Boolean, element: ScanResult, accumulator: CacheResult?): Int {
7976
val average: Int = if (first) element.level else (accumulator!!.average + element.level) / DENOMINATOR
8077
return (if (sizeAvailable) average else average - SIZE * (count + count % FACTOR) / DENOMINATOR)

app/src/main/kotlin/com/vrem/wifianalyzer/wifi/scanner/ScannerCallback.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ internal class ScannerCallback(private val wiFiManagerWrapper: WiFiManagerWrappe
2525
Callback {
2626

2727
override fun onSuccess() {
28-
cache.add(wiFiManagerWrapper.scanResults(), wiFiManagerWrapper.wiFiInfo())
28+
cache.add(wiFiManagerWrapper.scanResults())
29+
cache.wifiInfo = wiFiManagerWrapper.wiFiInfo()
2930
}
3031

3132
}

app/src/main/kotlin/com/vrem/wifianalyzer/wifi/scanner/Transformer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fun WifiInfo.ipV4Address(): Int = ipAddress
3232
internal class Transformer(private val cache: Cache) {
3333

3434
internal fun transformWifiInfo(): WiFiConnection {
35-
val wifiInfo: WifiInfo? = cache.wifiInfo()
35+
val wifiInfo: WifiInfo? = cache.wifiInfo
3636
return if (wifiInfo == null || wifiInfo.networkId == -1) {
3737
WiFiConnection.EMPTY
3838
} else {

app/src/test/kotlin/com/vrem/wifianalyzer/permission/SystemPermissionTest.kt

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package com.vrem.wifianalyzer.permission
1919

2020
import android.app.Activity
21-
import android.content.Context
2221
import android.location.LocationManager
2322
import android.os.Build
2423
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -49,15 +48,15 @@ class SystemPermissionTest {
4948
@Test
5049
fun testEnabledWhenGPSProviderIsEnabled() {
5150
// setup
52-
whenever(activity.getSystemService(Context.LOCATION_SERVICE)).thenReturn(locationManager)
51+
whenever(activity.getSystemService(LocationManager::class.java)).thenReturn(locationManager)
5352
whenever(locationManager.isLocationEnabled).thenReturn(false)
5453
whenever(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)).thenReturn(false)
5554
whenever(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)).thenReturn(true)
5655
// execute
5756
val actual = fixture.enabled()
5857
// validate
5958
assertTrue(actual)
60-
verify(activity).getSystemService(Context.LOCATION_SERVICE)
59+
verify(activity).getSystemService(LocationManager::class.java)
6160
verify(locationManager).isLocationEnabled
6261
verify(locationManager).isProviderEnabled(LocationManager.NETWORK_PROVIDER)
6362
verify(locationManager).isProviderEnabled(LocationManager.GPS_PROVIDER)
@@ -66,43 +65,43 @@ class SystemPermissionTest {
6665
@Test
6766
fun testEnabledWhenLocationEnabled() {
6867
// setup
69-
whenever(activity.getSystemService(Context.LOCATION_SERVICE)).thenReturn(locationManager)
68+
whenever(activity.getSystemService(LocationManager::class.java)).thenReturn(locationManager)
7069
whenever(locationManager.isLocationEnabled).thenReturn(true)
7170
// execute
7271
val actual = fixture.enabled()
7372
// validate
7473
assertTrue(actual)
75-
verify(activity).getSystemService(Context.LOCATION_SERVICE)
74+
verify(activity).getSystemService(LocationManager::class.java)
7675
verify(locationManager).isLocationEnabled
7776
}
7877

7978
@Test
8079
fun testEnabledWhenNetworkProviderEnabled() {
8180
// setup
82-
whenever(activity.getSystemService(Context.LOCATION_SERVICE)).thenReturn(locationManager)
81+
whenever(activity.getSystemService(LocationManager::class.java)).thenReturn(locationManager)
8382
whenever(locationManager.isLocationEnabled).thenReturn(false)
8483
whenever(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)).thenReturn(true)
8584
// execute
8685
val actual = fixture.enabled()
8786
// validate
8887
assertTrue(actual)
89-
verify(activity).getSystemService(Context.LOCATION_SERVICE)
88+
verify(activity).getSystemService(LocationManager::class.java)
9089
verify(locationManager).isLocationEnabled
9190
verify(locationManager).isProviderEnabled(LocationManager.NETWORK_PROVIDER)
9291
}
9392

9493
@Test
9594
fun testEnabledWhenAllProvidersAreDisabled() {
9695
// setup
97-
whenever(activity.getSystemService(Context.LOCATION_SERVICE)).thenReturn(locationManager)
96+
whenever(activity.getSystemService(LocationManager::class.java)).thenReturn(locationManager)
9897
whenever(locationManager.isLocationEnabled).thenReturn(false)
9998
whenever(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)).thenReturn(false)
10099
whenever(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)).thenReturn(false)
101100
// execute
102101
val actual = fixture.enabled()
103102
// validate
104103
assertFalse(actual)
105-
verify(activity).getSystemService(Context.LOCATION_SERVICE)
104+
verify(activity).getSystemService(LocationManager::class.java)
106105
verify(locationManager).isLocationEnabled
107106
verify(locationManager).isProviderEnabled(LocationManager.NETWORK_PROVIDER)
108107
verify(locationManager).isProviderEnabled(LocationManager.GPS_PROVIDER)
@@ -111,15 +110,15 @@ class SystemPermissionTest {
111110
@Test
112111
fun testEnabledWhenAllProvidersThrowException() {
113112
// setup
114-
whenever(activity.getSystemService(Context.LOCATION_SERVICE)).thenReturn(locationManager)
113+
whenever(activity.getSystemService(LocationManager::class.java)).thenReturn(locationManager)
115114
whenever(locationManager.isLocationEnabled).thenThrow(RuntimeException::class.java)
116115
whenever(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)).thenThrow(RuntimeException::class.java)
117116
whenever(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)).thenThrow(RuntimeException::class.java)
118117
// execute
119118
val actual = fixture.enabled()
120119
// validate
121120
assertFalse(actual)
122-
verify(activity).getSystemService(Context.LOCATION_SERVICE)
121+
verify(activity).getSystemService(LocationManager::class.java)
123122
verify(locationManager).isLocationEnabled
124123
verify(locationManager).isProviderEnabled(LocationManager.NETWORK_PROVIDER)
125124
verify(locationManager).isProviderEnabled(LocationManager.GPS_PROVIDER)
@@ -128,11 +127,11 @@ class SystemPermissionTest {
128127
@Test
129128
fun testEnabled() {
130129
// setup
131-
whenever(activity.getSystemService(Context.LOCATION_SERVICE)).thenThrow(RuntimeException::class.java)
130+
whenever(activity.getSystemService(LocationManager::class.java)).thenThrow(RuntimeException::class.java)
132131
// execute
133132
val actual = fixture.enabled()
134133
// validate
135134
assertFalse(actual)
136-
verify(activity).getSystemService(Context.LOCATION_SERVICE)
135+
verify(activity).getSystemService(LocationManager::class.java)
137136
}
138137
}

app/src/test/kotlin/com/vrem/wifianalyzer/wifi/scanner/CacheTest.kt

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package com.vrem.wifianalyzer.wifi.scanner
1919

2020
import android.net.wifi.ScanResult
21-
import android.net.wifi.WifiInfo
2221
import com.nhaarman.mockitokotlin2.*
2322
import com.vrem.wifianalyzer.MainContextHelper
2423
import com.vrem.wifianalyzer.wifi.band.WiFiRange
@@ -28,7 +27,6 @@ import org.junit.Before
2827
import org.junit.Test
2928

3029
class CacheTest {
31-
private val wifiInfo: WifiInfo = mock()
3230
private val scanResult1: ScanResult = mock()
3331
private val scanResult2: ScanResult = mock()
3432
private val scanResult3: ScanResult = mock()
@@ -56,7 +54,7 @@ class CacheTest {
5654
// setup
5755
val scanResults = listOf<ScanResult>()
5856
// execute
59-
fixture.add(scanResults, wifiInfo)
57+
fixture.add(scanResults)
6058
// validate
6159
assertEquals(scanResults, fixture.first())
6260
}
@@ -70,7 +68,7 @@ class CacheTest {
7068
for (i in 0 until cacheSize) {
7169
val scanResults = listOf<ScanResult>()
7270
expected.add(scanResults)
73-
fixture.add(scanResults, wifiInfo)
71+
fixture.add(scanResults)
7472
}
7573
// validate
7674
assertEquals(cacheSize, expected.size)
@@ -117,10 +115,9 @@ class CacheTest {
117115
whenever(settings.cacheOff()).thenReturn(true)
118116
val scanResults = listOf<ScanResult>()
119117
// execute
120-
fixture.add(scanResults, wifiInfo)
118+
fixture.add(scanResults)
121119
// validate
122120
assertEquals(scanResults, fixture.first())
123-
assertEquals(wifiInfo, fixture.wifiInfo())
124121
verify(settings).cacheOff()
125122
}
126123

@@ -134,7 +131,7 @@ class CacheTest {
134131
for (i in 0 until count) {
135132
val scanResults = listOf<ScanResult>()
136133
expected.add(scanResults)
137-
fixture.add(scanResults, wifiInfo)
134+
fixture.add(scanResults)
138135
}
139136
// validate
140137
assertEquals(count, expected.size)
@@ -189,10 +186,9 @@ class CacheTest {
189186
whenever(configuration.sizeAvailable).thenReturn(false)
190187
val scanResults = listOf<ScanResult>()
191188
// execute
192-
fixture.add(scanResults, wifiInfo)
189+
fixture.add(scanResults)
193190
// validate
194191
assertEquals(scanResults, fixture.first())
195-
assertEquals(wifiInfo, fixture.wifiInfo())
196192
}
197193

198194
@Test
@@ -205,7 +201,7 @@ class CacheTest {
205201
for (i in 0 until cacheSize) {
206202
val scanResults = listOf<ScanResult>()
207203
expected.add(scanResults)
208-
fixture.add(scanResults, wifiInfo)
204+
fixture.add(scanResults)
209205
}
210206
// validate
211207
assertEquals(cacheSize, expected.size)
@@ -283,11 +279,11 @@ class CacheTest {
283279
scanResult6.level = -10
284280

285281
var result = 0
286-
fixture.add(listOf(scanResult1, scanResult4), wifiInfo)
282+
fixture.add(listOf(scanResult1, scanResult4))
287283
result++
288-
fixture.add(listOf(scanResult2, scanResult5), wifiInfo)
284+
fixture.add(listOf(scanResult2, scanResult5))
289285
result++
290-
fixture.add(listOf(scanResult3, scanResult6), wifiInfo)
286+
fixture.add(listOf(scanResult3, scanResult6))
291287
result++
292288

293289
return result

0 commit comments

Comments
 (0)