Loading play-services-core/src/withNearby/AndroidManifest.xml +9 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,15 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" /> <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> <uses-permission android:name="android.permission.BLUETOOTH_SCAN" /> <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <permission android:name="com.google.android.gms.nearby.exposurenotification.EXPOSURE_CALLBACK" android:protectionLevel="normal" /> Loading play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsConfirmActivity.kt +34 −29 Original line number Diff line number Diff line Loading @@ -5,11 +5,14 @@ package org.microg.gms.nearby.core.ui import android.Manifest.permission.* import android.annotation.SuppressLint import android.bluetooth.BluetoothAdapter import android.content.Context import android.content.Intent import android.content.pm.PackageInfo.REQUESTED_PERMISSION_NEVER_FOR_LOCATION import android.content.pm.PackageManager import android.content.pm.PackageManager.PERMISSION_GRANTED import android.location.LocationManager import android.os.Build import android.os.Bundle Loading @@ -19,7 +22,7 @@ import android.view.View import android.widget.Button import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat.checkSelfPermission import androidx.core.location.LocationManagerCompat import androidx.lifecycle.lifecycleScope import org.microg.gms.nearby.exposurenotification.* Loading Loading @@ -110,17 +113,26 @@ class ExposureNotificationsConfirmActivity : AppCompatActivity() { private var permissionNeedsHandling: Boolean = false private var backgroundLocationNeedsHandling: Boolean = false private var permissionRequestCode = 33 private val permissions by lazy { when { private fun getRequiredPermissions(): Array<String> { return when { Build.VERSION.SDK_INT >= 31 -> { // We shouldn't be needing the LOCATION permissions on 31+ anymore, at least when // apps making use of this target 31+ as well, but this needs more testing. See // We only need bluetooth permission on 31+ if it's "strongly asserted" that we won't use bluetooth for // location. Otherwise, we also need LOCATION permissions. See // https://developer.android.com/guide/topics/connectivity/bluetooth/permissions#assert-never-for-location try { val packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS) val bluetoothScanIndex = packageInfo.requestedPermissions.indexOf(BLUETOOTH_SCAN) if (packageInfo.requestedPermissionsFlags[bluetoothScanIndex] and REQUESTED_PERMISSION_NEVER_FOR_LOCATION > 0) { return arrayOf(BLUETOOTH_ADVERTISE, BLUETOOTH_SCAN) } } catch (e: Exception) { // Ignore } arrayOf( "android.permission.BLUETOOTH_ADVERTISE", "android.permission.BLUETOOTH_SCAN", "android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION" BLUETOOTH_ADVERTISE, BLUETOOTH_SCAN, ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION ) } Build.VERSION.SDK_INT == 29 -> { Loading @@ -128,38 +140,31 @@ class ExposureNotificationsConfirmActivity : AppCompatActivity() { // We need it on 30 (and possibly later) as well, but it has to be requested in a two // step process, see https://fosstodon.org/@utf8equalsX/104359649537615235 arrayOf( "android.permission.ACCESS_BACKGROUND_LOCATION", "android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION" ACCESS_BACKGROUND_LOCATION, ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION ) } else -> { // Below 29 or equals 30 arrayOf( "android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION" ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION ) } } } private fun checkPermissions() { val permissions = getRequiredPermissions() permissionNeedsHandling = Build.VERSION.SDK_INT >= 23 && permissions.any { ContextCompat.checkSelfPermission( this, it ) != PackageManager.PERMISSION_GRANTED checkSelfPermission(this, it) != PERMISSION_GRANTED } backgroundLocationNeedsHandling = Build.VERSION.SDK_INT >= 30 && ContextCompat.checkSelfPermission( this, "android.permission.ACCESS_FINE_LOCATION" ) == PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission( this, "android.permission.ACCESS_BACKGROUND_LOCATION" ) != PackageManager.PERMISSION_GRANTED && ACCESS_FINE_LOCATION in permissions && checkSelfPermission(this, ACCESS_FINE_LOCATION) == PERMISSION_GRANTED && checkSelfPermission(this, ACCESS_BACKGROUND_LOCATION) != PERMISSION_GRANTED findViewById<View>(R.id.grant_permission_view).visibility = if (permissionNeedsHandling) View.VISIBLE else View.GONE Loading @@ -170,13 +175,13 @@ class ExposureNotificationsConfirmActivity : AppCompatActivity() { private fun requestPermissions() { if (Build.VERSION.SDK_INT >= 23) { requestPermissions(permissions, ++permissionRequestCode) requestPermissions(getRequiredPermissions(), ++permissionRequestCode) } } private fun requestBackgroundLocation() { if (Build.VERSION.SDK_INT >= 23) { requestPermissions(arrayOf("android.permission.ACCESS_BACKGROUND_LOCATION"), ++permissionRequestCode) if (Build.VERSION.SDK_INT >= 29) { requestPermissions(arrayOf(ACCESS_BACKGROUND_LOCATION), ++permissionRequestCode) } } Loading play-services-nearby-core/src/main/AndroidManifest.xml +0 −9 Original line number Diff line number Diff line Loading @@ -6,16 +6,7 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.microg.gms.nearby.core"> <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" /> <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> <uses-permission android:name="android.permission.BLUETOOTH_SCAN" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="com.google.android.gms.nearby.exposurenotification.EXPOSURE_CALLBACK" /> <application> Loading play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/AdvertiserService.kt +3 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ package org.microg.gms.nearby.exposurenotification import android.annotation.SuppressLint import android.annotation.TargetApi import android.app.AlarmManager import android.app.PendingIntent Loading Loading @@ -110,6 +111,7 @@ class AdvertiserService : LifecycleService() { private var sendingBytes = ByteArray(0) private var starting = false @SuppressLint("MissingPermission") private suspend fun startAdvertising() { val advertiser = synchronized(this) { if (advertising || starting) return Loading Loading @@ -207,6 +209,7 @@ class AdvertiserService : LifecycleService() { } @Synchronized @SuppressLint("MissingPermission") private fun stopOrRestartAdvertising() { if (!advertising) return Log.i(TAG, "Stopping advertiser") Loading play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ScannerService.kt +1 −1 Original line number Diff line number Diff line Loading @@ -116,7 +116,7 @@ class ScannerService : LifecycleService() { stopScan() } @SuppressLint("WakelockTimeout") @SuppressLint("WakelockTimeout", "MissingPermission") @Synchronized private fun startScan() { if (scanning) return Loading Loading
play-services-core/src/withNearby/AndroidManifest.xml +9 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,15 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" /> <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> <uses-permission android:name="android.permission.BLUETOOTH_SCAN" /> <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <permission android:name="com.google.android.gms.nearby.exposurenotification.EXPOSURE_CALLBACK" android:protectionLevel="normal" /> Loading
play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsConfirmActivity.kt +34 −29 Original line number Diff line number Diff line Loading @@ -5,11 +5,14 @@ package org.microg.gms.nearby.core.ui import android.Manifest.permission.* import android.annotation.SuppressLint import android.bluetooth.BluetoothAdapter import android.content.Context import android.content.Intent import android.content.pm.PackageInfo.REQUESTED_PERMISSION_NEVER_FOR_LOCATION import android.content.pm.PackageManager import android.content.pm.PackageManager.PERMISSION_GRANTED import android.location.LocationManager import android.os.Build import android.os.Bundle Loading @@ -19,7 +22,7 @@ import android.view.View import android.widget.Button import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat.checkSelfPermission import androidx.core.location.LocationManagerCompat import androidx.lifecycle.lifecycleScope import org.microg.gms.nearby.exposurenotification.* Loading Loading @@ -110,17 +113,26 @@ class ExposureNotificationsConfirmActivity : AppCompatActivity() { private var permissionNeedsHandling: Boolean = false private var backgroundLocationNeedsHandling: Boolean = false private var permissionRequestCode = 33 private val permissions by lazy { when { private fun getRequiredPermissions(): Array<String> { return when { Build.VERSION.SDK_INT >= 31 -> { // We shouldn't be needing the LOCATION permissions on 31+ anymore, at least when // apps making use of this target 31+ as well, but this needs more testing. See // We only need bluetooth permission on 31+ if it's "strongly asserted" that we won't use bluetooth for // location. Otherwise, we also need LOCATION permissions. See // https://developer.android.com/guide/topics/connectivity/bluetooth/permissions#assert-never-for-location try { val packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS) val bluetoothScanIndex = packageInfo.requestedPermissions.indexOf(BLUETOOTH_SCAN) if (packageInfo.requestedPermissionsFlags[bluetoothScanIndex] and REQUESTED_PERMISSION_NEVER_FOR_LOCATION > 0) { return arrayOf(BLUETOOTH_ADVERTISE, BLUETOOTH_SCAN) } } catch (e: Exception) { // Ignore } arrayOf( "android.permission.BLUETOOTH_ADVERTISE", "android.permission.BLUETOOTH_SCAN", "android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION" BLUETOOTH_ADVERTISE, BLUETOOTH_SCAN, ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION ) } Build.VERSION.SDK_INT == 29 -> { Loading @@ -128,38 +140,31 @@ class ExposureNotificationsConfirmActivity : AppCompatActivity() { // We need it on 30 (and possibly later) as well, but it has to be requested in a two // step process, see https://fosstodon.org/@utf8equalsX/104359649537615235 arrayOf( "android.permission.ACCESS_BACKGROUND_LOCATION", "android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION" ACCESS_BACKGROUND_LOCATION, ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION ) } else -> { // Below 29 or equals 30 arrayOf( "android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION" ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION ) } } } private fun checkPermissions() { val permissions = getRequiredPermissions() permissionNeedsHandling = Build.VERSION.SDK_INT >= 23 && permissions.any { ContextCompat.checkSelfPermission( this, it ) != PackageManager.PERMISSION_GRANTED checkSelfPermission(this, it) != PERMISSION_GRANTED } backgroundLocationNeedsHandling = Build.VERSION.SDK_INT >= 30 && ContextCompat.checkSelfPermission( this, "android.permission.ACCESS_FINE_LOCATION" ) == PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission( this, "android.permission.ACCESS_BACKGROUND_LOCATION" ) != PackageManager.PERMISSION_GRANTED && ACCESS_FINE_LOCATION in permissions && checkSelfPermission(this, ACCESS_FINE_LOCATION) == PERMISSION_GRANTED && checkSelfPermission(this, ACCESS_BACKGROUND_LOCATION) != PERMISSION_GRANTED findViewById<View>(R.id.grant_permission_view).visibility = if (permissionNeedsHandling) View.VISIBLE else View.GONE Loading @@ -170,13 +175,13 @@ class ExposureNotificationsConfirmActivity : AppCompatActivity() { private fun requestPermissions() { if (Build.VERSION.SDK_INT >= 23) { requestPermissions(permissions, ++permissionRequestCode) requestPermissions(getRequiredPermissions(), ++permissionRequestCode) } } private fun requestBackgroundLocation() { if (Build.VERSION.SDK_INT >= 23) { requestPermissions(arrayOf("android.permission.ACCESS_BACKGROUND_LOCATION"), ++permissionRequestCode) if (Build.VERSION.SDK_INT >= 29) { requestPermissions(arrayOf(ACCESS_BACKGROUND_LOCATION), ++permissionRequestCode) } } Loading
play-services-nearby-core/src/main/AndroidManifest.xml +0 −9 Original line number Diff line number Diff line Loading @@ -6,16 +6,7 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.microg.gms.nearby.core"> <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" /> <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> <uses-permission android:name="android.permission.BLUETOOTH_SCAN" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="com.google.android.gms.nearby.exposurenotification.EXPOSURE_CALLBACK" /> <application> Loading
play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/AdvertiserService.kt +3 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ package org.microg.gms.nearby.exposurenotification import android.annotation.SuppressLint import android.annotation.TargetApi import android.app.AlarmManager import android.app.PendingIntent Loading Loading @@ -110,6 +111,7 @@ class AdvertiserService : LifecycleService() { private var sendingBytes = ByteArray(0) private var starting = false @SuppressLint("MissingPermission") private suspend fun startAdvertising() { val advertiser = synchronized(this) { if (advertising || starting) return Loading Loading @@ -207,6 +209,7 @@ class AdvertiserService : LifecycleService() { } @Synchronized @SuppressLint("MissingPermission") private fun stopOrRestartAdvertising() { if (!advertising) return Log.i(TAG, "Stopping advertiser") Loading
play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ScannerService.kt +1 −1 Original line number Diff line number Diff line Loading @@ -116,7 +116,7 @@ class ScannerService : LifecycleService() { stopScan() } @SuppressLint("WakelockTimeout") @SuppressLint("WakelockTimeout", "MissingPermission") @Synchronized private fun startScan() { if (scanning) return Loading