Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
6
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
DAVx⁵
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
2
Merge Requests
2
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
bitfire web engineering
DAVx⁵
Commits
96aa2fe3
Commit
96aa2fe3
authored
Oct 24, 2020
by
Ricki Hirner
🐑
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't ask for active location services on Android <9 / location permissions on Android 8.0
parent
ca9044cf
Pipeline
#207302043
passed with stage
in 7 minutes and 31 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
16 deletions
+25
-16
app/src/main/java/at/bitfire/davdroid/PermissionUtils.kt
app/src/main/java/at/bitfire/davdroid/PermissionUtils.kt
+13
-9
app/src/main/java/at/bitfire/davdroid/ui/account/WifiPermissionsActivity.kt
...at/bitfire/davdroid/ui/account/WifiPermissionsActivity.kt
+12
-7
No files found.
app/src/main/java/at/bitfire/davdroid/PermissionUtils.kt
View file @
96aa2fe3
...
...
@@ -30,7 +30,7 @@ object PermissionUtils {
val
WIFI_SSID_PERMISSIONS
=
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
Q
)
arrayOf
(
Manifest
.
permission
.
ACCESS_FINE_LOCATION
,
Manifest
.
permission
.
ACCESS_BACKGROUND_LOCATION
)
else
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
else
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
_MR1
)
arrayOf
(
Manifest
.
permission
.
ACCESS_COARSE_LOCATION
)
else
arrayOf
()
...
...
@@ -38,22 +38,26 @@ object PermissionUtils {
/**
* Checks whether all conditions to access the current WiFi's SSID are met:
*
* 1. location permissions ([WIFI_SSID_PERMISSIONS]) granted
* 2. location enabled
* 1. location permissions ([WIFI_SSID_PERMISSIONS]) granted
(Android 8.1+)
* 2. location enabled
(Android 9+)
*
* @return *true* if SSID can be obtained; *false* if the SSID will be <unknown> or something like that
*/
fun
canAccessWifiSsid
(
context
:
Context
):
Boolean
{
// before Android 8, SSIDs are always readable
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
O
)
// before Android 8
.1
, SSIDs are always readable
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
O
_MR1
)
return
true
val
locationEnabled
=
ContextCompat
.
getSystemService
(
context
,
LocationManager
::
class
.
java
)
?.
let
{
locationManager
->
LocationManagerCompat
.
isLocationEnabled
(
locationManager
)
}
?:
/* location feature not available on this device */
false
val
locationAvailable
=
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
P
)
true
// Android <9 doesn't require active location services
else
ContextCompat
.
getSystemService
(
context
,
LocationManager
::
class
.
java
)
?.
let
{
locationManager
->
LocationManagerCompat
.
isLocationEnabled
(
locationManager
)
}
?:
/* location feature not available on this device */
false
return
havePermissions
(
context
,
WIFI_SSID_PERMISSIONS
)
&&
location
Enabled
location
Available
}
/**
...
...
app/src/main/java/at/bitfire/davdroid/ui/account/WifiPermissionsActivity.kt
View file @
96aa2fe3
...
...
@@ -129,23 +129,28 @@ class WifiPermissionsActivity: AppCompatActivity() {
}
fun
checkPermissions
()
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
// Android 8.1+: location permission
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O_MR1
)
{
val
location
=
ContextCompat
.
checkSelfPermission
(
getApplication
(),
PERMISSION_LOCATION
)
==
PackageManager
.
PERMISSION_GRANTED
haveLocation
.
value
=
location
needLocation
.
value
=
location
}
// Android 9+: location service
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
P
)
{
getSystemService
(
getApplication
(),
LocationManager
::
class
.
java
)
?.
let
{
locationManager
->
val
locationEnabled
=
LocationManagerCompat
.
isLocationEnabled
(
locationManager
)
isLocationEnabled
.
value
=
locationEnabled
needLocationEnabled
.
value
=
locationEnabled
}
}
// Android 10+: background location permission
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
Q
)
{
val
backgroundLocation
=
ContextCompat
.
checkSelfPermission
(
getApplication
(),
Manifest
.
permission
.
ACCESS_BACKGROUND_LOCATION
)
==
PackageManager
.
PERMISSION_GRANTED
haveBackgroundLocation
.
value
=
backgroundLocation
needBackgroundLocation
.
value
=
backgroundLocation
}
getSystemService
(
getApplication
(),
LocationManager
::
class
.
java
)
?.
let
{
locationManager
->
val
locationEnabled
=
LocationManagerCompat
.
isLocationEnabled
(
locationManager
)
isLocationEnabled
.
value
=
locationEnabled
needLocationEnabled
.
value
=
locationEnabled
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment