mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 10:25:19 +00:00
Refactor: Sync permission state on check
Replaces manual updatePermissionState calls with a unified checkAndSyncPermission method. This ensures that _permissionState flow always reflects the actual system permission status whenever it is checked (e.g. in requestOneShotLocation), preventing desync issues when permissions are revoked at runtime.
This commit is contained in:
@@ -128,7 +128,7 @@ class LocationChannelManager private constructor(private val context: Context) {
|
|||||||
SystemLocationProvider(context)
|
SystemLocationProvider(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePermissionState()
|
checkAndSyncPermission()
|
||||||
// Initialize DataManager and load persisted settings
|
// Initialize DataManager and load persisted settings
|
||||||
dataManager = com.bitchat.android.ui.DataManager(context)
|
dataManager = com.bitchat.android.ui.DataManager(context)
|
||||||
loadPersistedChannelSelection()
|
loadPersistedChannelSelection()
|
||||||
@@ -293,7 +293,7 @@ class LocationChannelManager private constructor(private val context: Context) {
|
|||||||
// MARK: - Location Operations
|
// MARK: - Location Operations
|
||||||
|
|
||||||
private fun requestOneShotLocation() {
|
private fun requestOneShotLocation() {
|
||||||
if (!hasLocationPermission()) {
|
if (!checkAndSyncPermission()) {
|
||||||
Log.w(TAG, "No location permission for one-shot request")
|
Log.w(TAG, "No location permission for one-shot request")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -334,22 +334,25 @@ class LocationChannelManager private constructor(private val context: Context) {
|
|||||||
// MARK: - Helpers
|
// MARK: - Helpers
|
||||||
|
|
||||||
private fun getCurrentPermissionStatus(): PermissionState {
|
private fun getCurrentPermissionStatus(): PermissionState {
|
||||||
return if (hasLocationPermission()) {
|
return if (checkAndSyncPermission()) {
|
||||||
PermissionState.AUTHORIZED
|
PermissionState.AUTHORIZED
|
||||||
} else {
|
} else {
|
||||||
PermissionState.DENIED
|
PermissionState.DENIED
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updatePermissionState() {
|
private fun checkAndSyncPermission(): Boolean {
|
||||||
val newState = getCurrentPermissionStatus()
|
val hasPermission = ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED ||
|
||||||
Log.d(TAG, "Permission state updated to: $newState")
|
|
||||||
_permissionState.value = newState
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun hasLocationPermission(): Boolean {
|
|
||||||
return ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED ||
|
|
||||||
ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED
|
ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED
|
||||||
|
|
||||||
|
val newState = if (hasPermission) PermissionState.AUTHORIZED else PermissionState.DENIED
|
||||||
|
|
||||||
|
if (_permissionState.value != newState) {
|
||||||
|
Log.d(TAG, "Permission state updated to: $newState")
|
||||||
|
_permissionState.value = newState
|
||||||
|
}
|
||||||
|
|
||||||
|
return hasPermission
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun computeChannels(location: Location) {
|
private fun computeChannels(location: Location) {
|
||||||
|
|||||||
Reference in New Issue
Block a user