fix grabbing SSID info

This commit is contained in:
Milos Kozak 2020-07-02 22:45:47 +02:00
parent 3a2790acc3
commit 6e88d127e5
7 changed files with 16 additions and 11 deletions

View file

@ -138,8 +138,8 @@ class MainActivity : NoSplashAppCompatActivity() {
} }
androidPermission.notifyForStoragePermission(this) androidPermission.notifyForStoragePermission(this)
androidPermission.notifyForBatteryOptimizationPermission(this) androidPermission.notifyForBatteryOptimizationPermission(this)
if (config.PUMPDRIVERS) {
androidPermission.notifyForLocationPermissions(this) androidPermission.notifyForLocationPermissions(this)
if (config.PUMPDRIVERS) {
androidPermission.notifyForSMSPermissions(this, smsCommunicatorPlugin) androidPermission.notifyForSMSPermissions(this, smsCommunicatorPlugin)
androidPermission.notifyForSystemWindowPermissions(this) androidPermission.notifyForSystemWindowPermissions(this)
} }

View file

@ -47,7 +47,7 @@ class TriggerWifiSsid(injector: HasAndroidInjector) : Trigger(injector) {
aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription()) aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription())
return true return true
} }
if (eventNetworkChange.wifiConnected && comparator.value.check(eventNetworkChange.connectedSsid(), ssid.value)) { if (eventNetworkChange.wifiConnected && comparator.value.check(eventNetworkChange.ssid, ssid.value)) {
aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription()) aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription())
return true return true
} }

View file

@ -1,5 +1,7 @@
package info.nightscout.androidaps.plugins.general.nsclient; package info.nightscout.androidaps.plugins.general.nsclient;
import java.util.Arrays;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -48,6 +50,7 @@ class NsClientReceiverDelegate {
ev.isChanged(resourceHelper, R.string.key_ns_allowroaming) ev.isChanged(resourceHelper, R.string.key_ns_allowroaming)
) { ) {
receiverStatusStore.updateNetworkStatus(); receiverStatusStore.updateNetworkStatus();
onStatusEvent(receiverStatusStore.getLastNetworkEvent());
} else if (ev.isChanged(resourceHelper, R.string.key_ns_chargingonly)) { } else if (ev.isChanged(resourceHelper, R.string.key_ns_chargingonly)) {
receiverStatusStore.broadcastChargingState(); receiverStatusStore.broadcastChargingState();
} }
@ -92,14 +95,15 @@ class NsClientReceiverDelegate {
boolean calculateStatus(final EventNetworkChange ev) { boolean calculateStatus(final EventNetworkChange ev) {
boolean wifiOnly = sp.getBoolean(R.string.key_ns_wifionly, false); boolean wifiOnly = sp.getBoolean(R.string.key_ns_wifionly, false);
String allowedSSIDs = sp.getString(R.string.key_ns_wifi_ssids, ""); String allowedSSIDstring = sp.getString(R.string.key_ns_wifi_ssids, "");
String[] allowedSSIDs = allowedSSIDstring.split(";");
if (allowedSSIDstring.isEmpty()) allowedSSIDs = new String[0];
boolean allowRoaming = sp.getBoolean(R.string.key_ns_allowroaming, true); boolean allowRoaming = sp.getBoolean(R.string.key_ns_allowroaming, true);
boolean newAllowedState = true; boolean newAllowedState = true;
if (ev.getWifiConnected()) { if (ev.getWifiConnected()) {
if (!allowedSSIDs.trim().isEmpty() && if (allowedSSIDs.length != 0 && !Arrays.asList(allowedSSIDs).contains(ev.getSsid())) {
(!allowedSSIDs.contains(ev.connectedSsid()) && !allowedSSIDs.contains(ev.getSsid()))) {
newAllowedState = false; newAllowedState = false;
} }
} else { } else {

View file

@ -949,7 +949,7 @@
<string name="permission">Permission</string> <string name="permission">Permission</string>
<string name="askforpermission">Ask for permission</string> <string name="askforpermission">Ask for permission</string>
<string name="needsystemwindowpermission">Application needs system window permission for notifications</string> <string name="needsystemwindowpermission">Application needs system window permission for notifications</string>
<string name="needlocationpermission">Application needs location permission for BT scan</string> <string name="needlocationpermission">Application needs location permission for BT scan and WiFi identification</string>
<string name="needstoragepermission">Application needs storage permission to be able store log files</string> <string name="needstoragepermission">Application needs storage permission to be able store log files</string>
<string name="request">Request</string> <string name="request">Request</string>
<string name="insulinsourcesetup">Configure Insulin plugin</string> <string name="insulinsourcesetup">Configure Insulin plugin</string>

View file

@ -1,6 +1,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="info.nightscout.androidaps.core"> package="info.nightscout.androidaps.core">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH" />
<application> <application>

View file

@ -11,8 +11,4 @@ class EventNetworkChange : Event() {
var ssid = "" var ssid = ""
var roaming = false var roaming = false
var metered = false var metered = false
fun connectedSsid(): String {
return StringUtils.removeSurroundingQuotes(ssid)
}
} }

View file

@ -12,6 +12,7 @@ import info.nightscout.androidaps.events.EventNetworkChange
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.utils.StringUtils
import javax.inject.Inject import javax.inject.Inject
class NetworkChangeReceiver : DaggerBroadcastReceiver() { class NetworkChangeReceiver : DaggerBroadcastReceiver() {
@ -39,7 +40,7 @@ class NetworkChangeReceiver : DaggerBroadcastReceiver() {
val wifiManager = context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager val wifiManager = context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
val wifiInfo = wifiManager.connectionInfo val wifiInfo = wifiManager.connectionInfo
if (wifiInfo.supplicantState == SupplicantState.COMPLETED) { if (wifiInfo.supplicantState == SupplicantState.COMPLETED) {
event.ssid = wifiInfo.ssid event.ssid = StringUtils.removeSurroundingQuotes(wifiInfo.ssid)
// aapsLogger.debug(LTag.CORE, "NETCHANGE: Wifi connected. SSID: ${event.connectedSsid()}") // aapsLogger.debug(LTag.CORE, "NETCHANGE: Wifi connected. SSID: ${event.connectedSsid()}")
} }
} }