Skip to content

Commit faa6f6b

Browse files
add device information
1 parent da5c1c3 commit faa6f6b

9 files changed

Lines changed: 167 additions & 22 deletions

File tree

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-
#Sat Nov 28 11:55:25 EST 2020
2+
#Sat Nov 28 14:29:47 EST 2020
33
version_minor=0
44
version_store=54
55
version_patch=2
6-
version_build=8
6+
version_build=9
77
version_major=3

app/src/main/kotlin/com/vrem/wifianalyzer/about/AboutFragment.kt

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ package com.vrem.wifianalyzer.about
2020
import android.app.Activity
2121
import android.app.AlertDialog
2222
import android.content.ActivityNotFoundException
23+
import android.content.Context
2324
import android.content.Intent
2425
import android.content.pm.PackageInfo
2526
import android.content.pm.PackageManager.NameNotFoundException
2627
import android.net.Uri
28+
import android.net.wifi.WifiManager
2729
import android.os.Build
2830
import android.os.Bundle
2931
import android.view.LayoutInflater
@@ -39,6 +41,7 @@ import com.vrem.util.readFile
3941
import com.vrem.wifianalyzer.MainContext.INSTANCE
4042
import com.vrem.wifianalyzer.R
4143
import com.vrem.wifianalyzer.databinding.AboutContentBinding
44+
import com.vrem.wifianalyzer.wifi.scanner.WiFiManagerWrapper
4245
import java.text.SimpleDateFormat
4346
import java.util.*
4447

@@ -56,6 +59,18 @@ class AboutFragment : Fragment() {
5659
binding.aboutCopyright.text = copyright()
5760
binding.aboutVersionInfo.text = version(activity)
5861
binding.aboutPackageName.text = activity.packageName
62+
binding.aboutDevice.text = device()
63+
binding.aboutWiFi.text = wiFi(activity)
64+
}
65+
66+
private fun device(): String =
67+
Build.MANUFACTURER + " - " + Build.BRAND + " - " + Build.MODEL
68+
69+
private fun wiFi(activity: FragmentActivity): String {
70+
val wiFiManagerWrapper = wiFiManagerWrapper(activity)
71+
return String.EMPTY + activity.getText(R.string.wifi_band_2ghz) +
72+
ifElse(wiFiManagerWrapper.is5GHzBandSupported(), "|" + activity.getText(R.string.wifi_band_5ghz)) +
73+
ifElse(wiFiManagerWrapper.is6GHzBandSupported(), "|" + activity.getText(R.string.wifi_band_6ghz))
5974
}
6075

6176
private fun setOnClicks(binding: AboutContentBinding, activity: FragmentActivity) {
@@ -75,8 +90,8 @@ class AboutFragment : Fragment() {
7590
private fun version(activity: FragmentActivity): String {
7691
val configuration = INSTANCE.configuration
7792
return applicationVersion(activity) +
78-
configuration.sizeAvailable.let { "S" } +
79-
configuration.largeScreen.let { "L" } +
93+
ifElse(configuration.sizeAvailable, "S") +
94+
ifElse(configuration.largeScreen, "L") +
8095
" (" + Build.VERSION.RELEASE + "-" + Build.VERSION.SDK_INT + ")"
8196
}
8297

@@ -129,6 +144,17 @@ class AboutFragment : Fragment() {
129144
}
130145
}
131146

147+
private fun wiFiManagerWrapper(activity: FragmentActivity): WiFiManagerWrapper =
148+
WiFiManagerWrapper(activity.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager)
149+
150+
private fun ifElse(condition: Boolean, value: String) =
151+
if (condition) {
152+
value
153+
} else {
154+
String.EMPTY
155+
}
156+
157+
132158
companion object {
133159
private const val YEAR_FORMAT = "yyyy"
134160
}

app/src/main/kotlin/com/vrem/wifianalyzer/wifi/accesspoint/AccessPointDetail.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class AccessPointDetail {
7979
}
8080

8181
private fun setSecurityImage(view: View, wiFiDetail: WiFiDetail) =
82-
view.findViewById<ImageView>(R.id.securityImage).let {
82+
view.findViewById<ImageView>(R.id.securityImage)?.let {
8383
val security = wiFiDetail.security
8484
it.tag = security.imageResource
8585
it.setImageResource(security.imageResource)
@@ -99,19 +99,19 @@ class AccessPointDetail {
9999
}
100100

101101
private fun setWiFiStandardImage(view: View, wiFiSignal: WiFiSignal) =
102-
view.findViewById<ImageView>(R.id.wiFiStandardImage).let {
102+
view.findViewById<ImageView>(R.id.wiFiStandardImage)?.let {
103103
it.tag = wiFiSignal.wiFiStandard.imageResource
104104
it.setImageResource(wiFiSignal.wiFiStandard.imageResource)
105105
}
106106

107107
private fun setLevelText(view: View, wiFiSignal: WiFiSignal) =
108-
view.findViewById<TextView>(R.id.level).let {
108+
view.findViewById<TextView>(R.id.level)?.let {
109109
it.text = "${wiFiSignal.level}dBm"
110110
it.setTextColor(view.context.compatColor(wiFiSignal.strength.colorResource))
111111
}
112112

113113
private fun setLevelImage(view: View, wiFiSignal: WiFiSignal) =
114-
view.findViewById<ImageView>(R.id.levelImage).let {
114+
view.findViewById<ImageView>(R.id.levelImage)?.let {
115115
val strength = wiFiSignal.strength
116116
it.tag = strength.imageResource
117117
it.setImageResource(strength.imageResource)

app/src/main/kotlin/com/vrem/wifianalyzer/wifi/accesspoint/ConnectionView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class ConnectionView(
9292
}
9393

9494
private fun attachPopup(view: View, wiFiDetail: WiFiDetail) {
95-
view.findViewById<View>(R.id.attachPopup).let {
95+
view.findViewById<View>(R.id.attachPopup)?.let {
9696
accessPointPopup.attach(it, wiFiDetail)
9797
accessPointPopup.attach(view.findViewById(R.id.ssid), wiFiDetail)
9898
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import android.net.wifi.ScanResult
2121
import android.net.wifi.WifiInfo
2222
import android.net.wifi.WifiManager
2323
import com.vrem.annotation.OpenClass
24+
import com.vrem.util.buildMinVersionL
25+
import com.vrem.util.buildMinVersionR
2426

2527
@OpenClass
2628
internal class WiFiManagerWrapper(private val wifiManager: WifiManager, private val wiFiSwitch: WiFiSwitch = WiFiSwitch(wifiManager)) {
@@ -67,5 +69,24 @@ internal class WiFiManagerWrapper(private val wifiManager: WifiManager, private
6769
null
6870
}
6971

72+
73+
fun is5GHzBandSupported(): Boolean =
74+
if (minVersionL()) {
75+
wifiManager.is5GHzBandSupported
76+
} else {
77+
false
78+
}
79+
80+
fun is6GHzBandSupported(): Boolean =
81+
if (minVersionR()) {
82+
wifiManager.is6GHzBandSupported
83+
} else {
84+
false
85+
}
86+
87+
fun minVersionL(): Boolean = buildMinVersionL()
88+
89+
fun minVersionR(): Boolean = buildMinVersionR()
90+
7091
}
7192

app/src/main/res/layout/about_content.xml

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
-->
1919

2020
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
21-
android:layout_width="match_parent"
22-
android:layout_height="match_parent"
23-
android:fitsSystemWindows="true"
24-
android:orientation="vertical">
21+
xmlns:tools="http://schemas.android.com/tools"
22+
android:layout_width="match_parent"
23+
android:layout_height="match_parent"
24+
android:fitsSystemWindows="true"
25+
android:orientation="vertical">
2526

2627
<LinearLayout
2728
android:layout_width="match_parent"
@@ -53,28 +54,51 @@
5354
<TextView
5455
android:id="@+id/about_package_name"
5556
android:layout_width="wrap_content"
56-
android:layout_height="wrap_content"/>
57+
android:layout_height="wrap_content"
58+
tools:text="package name" />
5759

5860
<TextView
5961
android:id="@+id/about_version_info"
6062
android:layout_width="wrap_content"
6163
android:layout_height="wrap_content"
62-
android:textStyle="bold"/>
64+
android:textStyle="bold"
65+
tools:text="version information" />
6366

6467
<TextView
6568
android:layout_width="wrap_content"
6669
android:layout_height="wrap_content"
6770
android:text="@string/app_company_name"
68-
android:textStyle="bold"/>
71+
android:textStyle="bold" />
6972

7073
<TextView
7174
android:id="@+id/about_copyright"
7275
android:layout_width="wrap_content"
7376
android:layout_height="wrap_content"
74-
android:textStyle="bold"/>
77+
android:textStyle="bold"
78+
tools:text="copyright" />
7579
</LinearLayout>
7680
</LinearLayout>
7781

82+
<LinearLayout
83+
android:layout_width="match_parent"
84+
android:layout_height="wrap_content"
85+
android:orientation="vertical">
86+
87+
<TextView
88+
android:id="@+id/about_device"
89+
android:layout_width="wrap_content"
90+
android:layout_height="wrap_content"
91+
android:textStyle="bold"
92+
tools:text="device information" />
93+
94+
<TextView
95+
android:id="@+id/about_wi_fi"
96+
android:layout_width="wrap_content"
97+
android:layout_height="wrap_content"
98+
android:textStyle="bold"
99+
tools:text="some other information" />
100+
</LinearLayout>
101+
78102
<ScrollView
79103
android:layout_width="match_parent"
80104
android:layout_height="match_parent">

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@
192192
<string name="wifi_band_title" translatable="false">"2.4/5 GHz"</string>
193193
<string name="wifi_band_2ghz" translatable="false">"2.4 GHz"</string>
194194
<string name="wifi_band_5ghz" translatable="false">"5 GHz"</string>
195+
<string name="wifi_band_6ghz" translatable="false">"6 GHz"</string>
195196
<!-- Wi-Fi band end -->
196197

197198
<!-- Wi-Fi standard start -->

app/src/test/kotlin/com/vrem/wifianalyzer/about/AboutFragmentTest.kt

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,45 @@ class AboutFragmentTest {
9090
@Test
9191
fun testApplicationName() {
9292
// setup
93-
val expectedName = fixture.getString(R.string.app_full_name)
93+
val expected = fixture.getString(R.string.app_full_name)
9494
// execute
9595
val actual = fixture.requireView().findViewById<TextView>(R.id.about_application_name)
9696
// validate
9797
assertNotNull(actual)
98-
assertEquals(expectedName, actual.text)
98+
assertEquals(expected, actual.text)
9999
}
100100

101101
@Test
102102
fun testCopyright() {
103103
// setup
104-
val expectedName = (fixture.getString(R.string.app_copyright) + SimpleDateFormat("yyyy").format(Date()))
104+
val expected = (fixture.getString(R.string.app_copyright) + SimpleDateFormat("yyyy").format(Date()))
105105
// execute
106106
val actual = fixture.requireView().findViewById<TextView>(R.id.about_copyright)
107107
// validate
108108
assertNotNull(actual)
109-
assertEquals(expectedName, actual.text)
109+
assertEquals(expected, actual.text)
110+
}
111+
112+
@Test
113+
fun testDevice() {
114+
// setup
115+
val expected = "unknown - unknown - robolectric"
116+
// execute
117+
val actual = fixture.requireView().findViewById<TextView>(R.id.about_device)
118+
// validate
119+
assertNotNull(actual)
120+
assertEquals(expected, actual.text)
121+
}
122+
123+
@Test
124+
fun testWiFi() {
125+
// setup
126+
val expected = "2.4 GHz"
127+
// execute
128+
val actual = fixture.requireView().findViewById<TextView>(R.id.about_wi_fi)
129+
// validate
130+
assertNotNull(actual)
131+
assertEquals(expected, actual.text)
110132
}
111133

112134
@Test

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

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class WiFiManagerWrapperTest {
2929
private val wifiManager: WifiManager = mock()
3030
private val wiFiSwitch: WiFiSwitch = mock()
3131
private val wifiInfo: WifiInfo = mock()
32-
private val fixture = WiFiManagerWrapper(wifiManager, wiFiSwitch)
32+
private val fixture = spy(WiFiManagerWrapper(wifiManager, wiFiSwitch))
3333

3434
@After
3535
fun tearDown() {
@@ -217,4 +217,55 @@ class WiFiManagerWrapperTest {
217217
assertNull(actual)
218218
verify(wifiManager).connectionInfo
219219
}
220+
221+
@Test
222+
fun testIs5GHzBandSupported() {
223+
// setup
224+
doReturn(false).whenever(fixture).minVersionL()
225+
// execute
226+
val actual = fixture.is5GHzBandSupported()
227+
// validate
228+
assertFalse(actual)
229+
verify(wifiManager, never()).is5GHzBandSupported
230+
verify(fixture).minVersionL()
231+
}
232+
233+
@Test
234+
fun testIs5GHzBandSupportedWithAndroidL() {
235+
// setup
236+
doReturn(true).whenever(fixture).minVersionL()
237+
whenever(wifiManager.is5GHzBandSupported).thenReturn(true)
238+
// execute
239+
val actual = fixture.is5GHzBandSupported()
240+
// validate
241+
assertTrue(actual)
242+
verify(wifiManager).is5GHzBandSupported
243+
verify(fixture).minVersionL()
244+
}
245+
246+
@Test
247+
fun testIs6GHzBandSupported() {
248+
// setup
249+
doReturn(false).whenever(fixture).minVersionR()
250+
// execute
251+
val actual = fixture.is6GHzBandSupported()
252+
// validate
253+
assertFalse(actual)
254+
verify(wifiManager, never()).is6GHzBandSupported
255+
verify(fixture).minVersionR()
256+
}
257+
258+
@Test
259+
fun testIs6GHzBandSupportedWithAndroidR() {
260+
// setup
261+
doReturn(true).whenever(fixture).minVersionR()
262+
whenever(wifiManager.is6GHzBandSupported).thenReturn(true)
263+
// execute
264+
val actual = fixture.is6GHzBandSupported()
265+
// validate
266+
assertTrue(actual)
267+
verify(wifiManager).is6GHzBandSupported
268+
verify(fixture).minVersionR()
269+
}
270+
220271
}

0 commit comments

Comments
 (0)