-
Notifications
You must be signed in to change notification settings - Fork 145
[WOOMOB-3851] Request the Android 17 local network permission for POS phone-as-reader #16418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: issue/increment-target-sdk-37
Are you sure you want to change the base?
Changes from 5 commits
db57773
462fd6b
2a2e2b6
917bbe3
3e24f78
680fa9a
78c069a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,6 +87,7 @@ class WooPosCardReaderConnectionController( | |
| private var isRequiredUpdate = true | ||
| private var isBluetoothPermissionPermanentlyDenied = false | ||
| private var isLocationPermissionPermanentlyDenied = false | ||
| private var isLocalNetworkPermissionPermanentlyDenied = false | ||
|
|
||
| fun showRemoteTapToPayExplainer() { | ||
| if (_state.value !is WooPosCardReaderConnectionState.Scanning) return | ||
|
|
@@ -185,6 +186,14 @@ class WooPosCardReaderConnectionController( | |
| checkRequirementsAndStartDiscovery() | ||
| } | ||
|
|
||
| fun onLocalNetworkPermissionResult(granted: Boolean, shouldShowRationale: Boolean) { | ||
| isLocalNetworkPermissionPermanentlyDenied = !granted && !shouldShowRationale | ||
| val currentState = _state.value | ||
| if (granted && currentState is WooPosCardReaderConnectionState.MissingLocalNetworkPermission) { | ||
| onPhoneConnectClicked(currentState.phone) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AI Code Review [follow-up] Issue: When local-network permission is granted (here and in Suggestion: Refresh the address before reconnecting, mirroring |
||
| } | ||
| } | ||
|
|
||
| fun onBluetoothEnabled() { | ||
| checkRequirementsAndStartDiscovery() | ||
| } | ||
|
|
@@ -195,10 +204,14 @@ class WooPosCardReaderConnectionController( | |
|
|
||
| fun recheckPermissions() { | ||
| val currentState = _state.value | ||
| if (currentState is WooPosCardReaderConnectionState.MissingBluetoothPermission || | ||
| currentState is WooPosCardReaderConnectionState.MissingLocationPermission | ||
| ) { | ||
| checkRequirementsAndStartDiscovery() | ||
| when { | ||
| currentState is WooPosCardReaderConnectionState.MissingBluetoothPermission || | ||
| currentState is WooPosCardReaderConnectionState.MissingLocationPermission -> | ||
| checkRequirementsAndStartDiscovery() | ||
|
|
||
| currentState is WooPosCardReaderConnectionState.MissingLocalNetworkPermission && | ||
| WooPermissionUtils.hasLocalNetworkPermission(context) -> | ||
| onPhoneConnectClicked(currentState.phone) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -267,6 +280,7 @@ class WooPosCardReaderConnectionController( | |
| data object RequestBluetoothPermission : ControllerEvent | ||
| data object RequestEnableBluetooth : ControllerEvent | ||
| data object RequestLocationPermission : ControllerEvent | ||
| data object RequestLocalNetworkPermission : ControllerEvent | ||
| data object RequestEnableLocation : ControllerEvent | ||
| data object OpenAppSettings : ControllerEvent | ||
| data object Cancelled : ControllerEvent | ||
|
|
@@ -349,7 +363,7 @@ class WooPosCardReaderConnectionController( | |
| if (event is WooPosUnifiedDiscoveryEvent.ReadersFound) { | ||
| latestDiscoveredPhones = event.readers.filterIsInstance<WooPosDiscoveredReader.Phone>() | ||
| } | ||
| if (isShowingConnectionOutcome()) return | ||
| if (shouldIgnoreDiscoveryUpdates()) return | ||
|
|
||
| when (event) { | ||
| is WooPosUnifiedDiscoveryEvent.Started -> { | ||
|
|
@@ -379,9 +393,10 @@ class WooPosCardReaderConnectionController( | |
| } | ||
| } | ||
|
|
||
| private fun isShowingConnectionOutcome(): Boolean = | ||
| private fun shouldIgnoreDiscoveryUpdates(): Boolean = | ||
| _state.value is WooPosCardReaderConnectionState.Connecting || | ||
| _state.value is WooPosCardReaderConnectionState.ConnectingFailed || | ||
| _state.value is WooPosCardReaderConnectionState.MissingLocalNetworkPermission || | ||
| _state.value is Connected | ||
|
|
||
| private fun handleReadersFound( | ||
|
|
@@ -473,6 +488,21 @@ class WooPosCardReaderConnectionController( | |
|
|
||
| private fun onPhoneConnectClicked(phone: WooPosDiscoveredReader.Phone) { | ||
| if (_state.value is WooPosCardReaderConnectionState.Connecting) return | ||
| if (!WooPermissionUtils.hasLocalNetworkPermission(context)) { | ||
| logger.d("Local network permission not granted") | ||
| _state.value = WooPosCardReaderConnectionState.MissingLocalNetworkPermission( | ||
| phone = phone, | ||
| onRequestPermissionClicked = { | ||
| if (isLocalNetworkPermissionPermanentlyDenied) { | ||
| emitEvent(ControllerEvent.OpenAppSettings) | ||
| } else { | ||
| emitEvent(ControllerEvent.RequestLocalNetworkPermission) | ||
| } | ||
| }, | ||
| onCancelClicked = { cancel() }, | ||
| ) | ||
| return | ||
| } | ||
| markPhoneReaderSelected() | ||
| tracker.trackOnConnectTapped() | ||
| selectedReader = null | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.