diff --git a/play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsPreferencesFragment.kt b/play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsPreferencesFragment.kt
index 8ca0e269..d66bce33 100644
--- a/play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsPreferencesFragment.kt
+++ b/play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsPreferencesFragment.kt
@@ -5,24 +5,34 @@
package org.microg.gms.nearby.core.ui
+import android.bluetooth.BluetoothAdapter
+import android.content.Context.LOCATION_SERVICE
+import android.content.Intent
+import android.location.LocationManager
import android.os.Bundle
import android.os.Handler
+import android.provider.Settings
import androidx.core.os.bundleOf
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import androidx.preference.Preference
import androidx.preference.PreferenceCategory
import androidx.preference.PreferenceFragmentCompat
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.withContext
+import org.microg.gms.nearby.exposurenotification.AdvertiserService
import org.microg.gms.nearby.exposurenotification.ExposureDatabase
+import org.microg.gms.nearby.exposurenotification.ScannerService
import org.microg.gms.nearby.exposurenotification.getExposureNotificationsServiceInfo
import org.microg.gms.ui.AppIconPreference
import org.microg.gms.ui.getApplicationInfoIfExists
import org.microg.gms.ui.navigate
+
class ExposureNotificationsPreferencesFragment : PreferenceFragmentCompat() {
private lateinit var exposureEnableInfo: Preference
+ private lateinit var exposureBluetoothOff: Preference
+ private lateinit var exposureLocationOff: Preference
+ private lateinit var exposureBluetoothUnsupported: Preference
+ private lateinit var exposureBluetoothNoAdvertisement: Preference
private lateinit var exposureApps: PreferenceCategory
private lateinit var exposureAppsNone: Preference
private lateinit var collectedRpis: Preference
@@ -37,10 +47,27 @@ class ExposureNotificationsPreferencesFragment : PreferenceFragmentCompat() {
override fun onBindPreferences() {
exposureEnableInfo = preferenceScreen.findPreference("pref_exposure_enable_info") ?: exposureEnableInfo
+ exposureBluetoothOff = preferenceScreen.findPreference("pref_exposure_error_bluetooth_off") ?: exposureBluetoothOff
+ exposureLocationOff = preferenceScreen.findPreference("pref_exposure_error_location_off") ?: exposureLocationOff
+ exposureBluetoothUnsupported = preferenceScreen.findPreference("pref_exposure_error_bluetooth_unsupported") ?: exposureBluetoothUnsupported
+ exposureBluetoothNoAdvertisement = preferenceScreen.findPreference("pref_exposure_error_bluetooth_no_advertise") ?: exposureBluetoothNoAdvertisement
exposureApps = preferenceScreen.findPreference("prefcat_exposure_apps") ?: exposureApps
exposureAppsNone = preferenceScreen.findPreference("pref_exposure_apps_none") ?: exposureAppsNone
collectedRpis = preferenceScreen.findPreference("pref_exposure_collected_rpis") ?: collectedRpis
advertisingId = preferenceScreen.findPreference("pref_exposure_advertising_id") ?: advertisingId
+
+ exposureLocationOff.onPreferenceClickListener = Preference.OnPreferenceClickListener {
+ val intent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
+ startActivity(intent)
+ true
+ }
+
+ exposureBluetoothOff.onPreferenceClickListener = Preference.OnPreferenceClickListener {
+ val intent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
+ startActivity(intent)
+ true
+ }
+
collectedRpis.onPreferenceClickListener = Preference.OnPreferenceClickListener {
findNavController().navigate(requireContext(), R.id.openExposureRpis)
true
@@ -61,12 +88,38 @@ class ExposureNotificationsPreferencesFragment : PreferenceFragmentCompat() {
handler.removeCallbacks(updateContentRunnable)
}
+ private fun isLocationEnabled(): Boolean {
+ val lm = requireContext().getSystemService(LOCATION_SERVICE) as LocationManager
+ var gpsEnabled = false
+ var networkEnabled = false
+
+ try {
+ gpsEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER)
+ } catch (ex: Exception) {
+ }
+
+ try {
+ networkEnabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
+ } catch (ex: Exception) {
+ }
+ return gpsEnabled || networkEnabled
+ }
+
private fun updateStatus() {
lifecycleScope.launchWhenResumed {
handler.postDelayed(updateStatusRunnable, UPDATE_STATUS_INTERVAL)
val enabled = getExposureNotificationsServiceInfo(requireContext()).configuration.enabled
exposureEnableInfo.isVisible = !enabled
- advertisingId.isVisible = enabled
+
+ val bluetoothSupported = ScannerService.isSupported(requireContext())
+ val advertisingSupported = if (bluetoothSupported == true) AdvertiserService.isSupported(requireContext()) else bluetoothSupported
+
+ exposureLocationOff.isVisible = enabled && bluetoothSupported != false && !isLocationEnabled()
+ exposureBluetoothOff.isVisible = enabled && bluetoothSupported == null
+ exposureBluetoothUnsupported.isVisible = enabled && bluetoothSupported == false
+ exposureBluetoothNoAdvertisement.isVisible = enabled && bluetoothSupported == true && advertisingSupported != true
+
+ advertisingId.isVisible = enabled && advertisingSupported == true
}
}
diff --git a/play-services-nearby-core-ui/src/main/res/drawable/ic_alert.xml b/play-services-nearby-core-ui/src/main/res/drawable/ic_alert.xml
new file mode 100644
index 00000000..81bf78b7
--- /dev/null
+++ b/play-services-nearby-core-ui/src/main/res/drawable/ic_alert.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
diff --git a/play-services-nearby-core-ui/src/main/res/drawable/ic_bluetooth_off.xml b/play-services-nearby-core-ui/src/main/res/drawable/ic_bluetooth_off.xml
new file mode 100644
index 00000000..be63ec07
--- /dev/null
+++ b/play-services-nearby-core-ui/src/main/res/drawable/ic_bluetooth_off.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
diff --git a/play-services-nearby-core-ui/src/main/res/drawable/ic_location_off.xml b/play-services-nearby-core-ui/src/main/res/drawable/ic_location_off.xml
new file mode 100644
index 00000000..d45edb51
--- /dev/null
+++ b/play-services-nearby-core-ui/src/main/res/drawable/ic_location_off.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
diff --git a/play-services-nearby-core-ui/src/main/res/values-de/strings.xml b/play-services-nearby-core-ui/src/main/res/values-de/strings.xml
index 0296fdd7..bcd5d252 100644
--- a/play-services-nearby-core-ui/src/main/res/values-de/strings.xml
+++ b/play-services-nearby-core-ui/src/main/res/values-de/strings.xml
@@ -7,6 +7,10 @@
Exposure Notifications
Öffne eine App, die Exposure Notifications unterstützt, um diese zu aktivieren.
+ Aktiviere Bluetooth, um Exposure Notifications zu nutzen.
+ Aktiviere Ortungsdienste, um Exposure Notifications zu nutzen.
+ Leider ist dein Gerät nicht mit Exposure Notifications kompatibel.
+ Leider ist dein Gerät nicht vollständig mit Exposure Notifications kompatibel. Du wirst Warnungen über Risikokontakte erhalten, aber nicht andere Benachrichtigen können.
Apps, die Exposure Notifications nutzen
Gesammelte IDs
%1$d IDs in den letzten 60 Minuten
diff --git a/play-services-nearby-core-ui/src/main/res/values/strings.xml b/play-services-nearby-core-ui/src/main/res/values/strings.xml
index 2b92cb26..9029d772 100644
--- a/play-services-nearby-core-ui/src/main/res/values/strings.xml
+++ b/play-services-nearby-core-ui/src/main/res/values/strings.xml
@@ -17,6 +17,10 @@
Exposure Notifications
To enable Exposure Notifications, open any app supporting it.
+ To use Exposure Notifications, enable Bluetooth in system settings.
+ To use Exposure Notifications, enable Location access in system settings.
+ Unfortunately, your device is not compatible with Exposure Notifications.
+ Unfortunately, your device is only partially compatible with Exposure Notifications. You can be notified for risk contacts but won\'t be able to notify others.
Apps using Exposure Notifications
Collected IDs
%1$d IDs in last hour
diff --git a/play-services-nearby-core-ui/src/main/res/xml/preferences_exposure_notifications.xml b/play-services-nearby-core-ui/src/main/res/xml/preferences_exposure_notifications.xml
index 0c5dc810..2e1ddc25 100644
--- a/play-services-nearby-core-ui/src/main/res/xml/preferences_exposure_notifications.xml
+++ b/play-services-nearby-core-ui/src/main/res/xml/preferences_exposure_notifications.xml
@@ -15,6 +15,36 @@
app:isPreferenceVisible="false"
tools:isPreferenceVisible="true" />
+
+
+
+
+
+
+
+
diff --git a/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/AdvertiserService.kt b/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/AdvertiserService.kt
index 486edd71..2e048b28 100644
--- a/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/AdvertiserService.kt
+++ b/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/AdvertiserService.kt
@@ -236,26 +236,11 @@ class AdvertiserService : LifecycleService() {
fun isSupported(context: Context): Boolean? {
val adapter = BluetoothAdapter.getDefaultAdapter()
return when {
- adapter == null -> {
- Log.d(TAG, "LE advertising not supported via adapter")
- false
- }
- Build.VERSION.SDK_INT >= 26 && (adapter.isLeExtendedAdvertisingSupported || adapter.isLePeriodicAdvertisingSupported) -> {
- Log.d(TAG, "LE advertising supported via feature")
- true
- }
- adapter.state != BluetoothAdapter.STATE_ON -> {
- Log.d(TAG, "LE advertising unknown via state")
- null
- }
- adapter.bluetoothLeAdvertiser != null -> {
- Log.d(TAG, "LE advertising supported via advertiser")
- true
- }
- else -> {
- Log.d(TAG, "LE advertising not supported via advertiser")
- false
- }
+ adapter == null -> false
+ Build.VERSION.SDK_INT >= 26 && (adapter.isLeExtendedAdvertisingSupported || adapter.isLePeriodicAdvertisingSupported) -> true
+ adapter.state != BluetoothAdapter.STATE_ON -> null
+ adapter.bluetoothLeAdvertiser != null -> true
+ else -> false
}
}
}
diff --git a/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ScannerService.kt b/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ScannerService.kt
index 14aabac8..9cfff99c 100644
--- a/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ScannerService.kt
+++ b/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ScannerService.kt
@@ -174,28 +174,12 @@ class ScannerService : LifecycleService() {
}
fun isSupported(context: Context): Boolean? {
- if (AdvertiserService.isSupported(context) == true) {
- Log.d(TAG, "LE scanning supported via advertiser")
- return true
- }
val adapter = BluetoothAdapter.getDefaultAdapter()
return when {
- adapter == null -> {
- Log.d(TAG, "LE scanning not supported via adapter")
- false
- }
- adapter.state != BluetoothAdapter.STATE_ON -> {
- Log.d(TAG, "LE scanning unknown via state")
- null
- }
- adapter.bluetoothLeScanner != null -> {
- Log.d(TAG, "LE scanning supported via scanner")
- true
- }
- else -> {
- Log.d(TAG, "LE scanning not supported via scanner")
- false
- }
+ adapter == null -> false
+ adapter.state != BluetoothAdapter.STATE_ON -> null
+ adapter.bluetoothLeScanner != null -> true
+ else -> false
}
}
}