Fixed wifi signal percent + added signal frequency
This commit is contained in:
parent
5eead612ee
commit
8027dbd574
4 changed files with 79 additions and 3 deletions
|
|
@ -30,6 +30,7 @@ import androidx.core.content.ContextCompat
|
|||
import androidx.preference.PreferenceManager
|
||||
import com.gaurav.avnc.R
|
||||
import com.gaurav.avnc.ui.ldc.lib.ApplicationInfo
|
||||
import com.gaurav.avnc.ui.ldc.lib.WifiFrequencies
|
||||
import kotlin.math.max
|
||||
|
||||
|
||||
|
|
@ -194,11 +195,14 @@ class KioskDiagnosticActivity : AppCompatActivity(), View.OnClickListener {
|
|||
toastMessage(activity, "Scan results " + mWifiManager.scanResults.size)
|
||||
|
||||
mWifiManager.scanResults.forEach{
|
||||
val mWifiManager = getSystemService(Context.WIFI_SERVICE) as WifiManager
|
||||
val percent = (100 * mWifiManager.calculateSignalLevel(it.level)) / mWifiManager.maxSignalLevel
|
||||
val row = LayoutInflater.from(this@KioskDiagnosticActivity)
|
||||
.inflate(R.layout.activity_kiosk_diagnostic_wifi_row, null) as TableRow
|
||||
(row.findViewById<View>(R.id.tableCellSSID) as TextView).text = it.SSID
|
||||
(row.findViewById<View>(R.id.tableCellSignal) as TextView).text = it.level.toString()
|
||||
(row.findViewById<View>(R.id.tableCellSignalPercent) as TextView).text = it.level.toString()
|
||||
(row.findViewById<View>(R.id.tableCellSignalPercent) as TextView).text = "$percent %"
|
||||
(row.findViewById<View>(R.id.tableCellSignalFreq) as TextView).text = getWifiType(it.frequency)
|
||||
tableLayoutWifiRows.addView(row)
|
||||
}
|
||||
|
||||
|
|
@ -401,4 +405,27 @@ class KioskDiagnosticActivity : AppCompatActivity(), View.OnClickListener {
|
|||
|
||||
ActivityCompat.requestPermissions(this@KioskDiagnosticActivity, permissionRequest.toTypedArray(), 100)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the wifi network type based on frequency
|
||||
*/
|
||||
private fun getWifiType(frequency: Int): String {
|
||||
|
||||
if (WifiFrequencies.AH_LOW.freq.rangeTo(WifiFrequencies.AH_HIGH.freq).contains(frequency)) {
|
||||
return "860/900 MHz"
|
||||
}
|
||||
if (WifiFrequencies.BGNAX_LOW.freq.rangeTo(WifiFrequencies.BGNAX_HIGH.freq).contains(frequency)) {
|
||||
return "2.4Ghz"
|
||||
}
|
||||
if (WifiFrequencies.Y_LOW.freq.rangeTo(WifiFrequencies.Y_HIGH.freq).contains(frequency)) {
|
||||
return "3.65 GHz (US)"
|
||||
}
|
||||
if (WifiFrequencies.J_LOW.freq.rangeTo(WifiFrequencies.J_HIGH.freq).contains(frequency)) {
|
||||
return "4.9–5.0 GHz (J)"
|
||||
}
|
||||
if (WifiFrequencies.AHNACAX_LOW.freq.rangeTo(WifiFrequencies.AHNACAX_HIGH.freq).contains(frequency)) {
|
||||
return "5Ghz"
|
||||
}
|
||||
return "$frequency N/a"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package com.gaurav.avnc.ui.ldc.lib
|
||||
|
||||
/**
|
||||
* Wifi Channels
|
||||
* https://en.wikipedia.org/wiki/List_of_WLAN_channels
|
||||
*/
|
||||
enum class WifiFrequencies() {
|
||||
/** 802.11ah LOW (860/900 MHz) */
|
||||
AH_LOW(755),
|
||||
/** 802.11ah HIGH (860/900 MHz) */
|
||||
AH_HIGH(755),
|
||||
/** 802.11b/g/n/ax LOW (2.4Ghz) */
|
||||
BGNAX_LOW(2400),
|
||||
/** 802.11b/g/n/ax HIGH (2.4Ghz) */
|
||||
BGNAX_HIGH(2500),
|
||||
/** 802.11y LOW (3.65 GHz) */
|
||||
Y_LOW(3650),
|
||||
/** 802.11y HIGH (3.65 GHz) */
|
||||
Y_HIGH(3700),
|
||||
/** 802.11j LOW (4.9–5.0 GHz) */
|
||||
J_LOW(4900),
|
||||
/** 802.11j HIGH (4.9–5.0 GHz) */
|
||||
J_HIGH(5100),
|
||||
/** 802.11a/h/n/ac/axLOW (5Ghz) */
|
||||
AHNACAX_LOW(5100),
|
||||
/** 802.11a/h/n/ac/ax HIGH (5Ghz) */
|
||||
AHNACAX_HIGH(5900);
|
||||
|
||||
var freq: Int = 0;
|
||||
|
||||
// custom constructors
|
||||
constructor(freq: Int) : this() {
|
||||
this.freq = freq
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,11 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Réseau"/>
|
||||
<TextView
|
||||
android:padding="2.5dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Freq"/>
|
||||
<TextView
|
||||
android:padding="2.5dp"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
|||
|
|
@ -12,16 +12,25 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=""/>
|
||||
<TextView
|
||||
android:id="@+id/tableCellSignalFreq"
|
||||
android:padding="2.5dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=""
|
||||
android:textAlignment="center"/>
|
||||
<TextView
|
||||
android:id="@+id/tableCellSignal"
|
||||
android:padding="2.5dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=""/>
|
||||
android:text=""
|
||||
android:textAlignment="center"/>
|
||||
<TextView
|
||||
android:id="@+id/tableCellSignalPercent"
|
||||
android:padding="2.5dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=""/>
|
||||
android:text=""
|
||||
android:textAlignment="center"/>
|
||||
</TableRow>
|
||||
Loading…
Add table
Reference in a new issue