Skip to content

Commit

Permalink
Merge pull request #23 from ravikp/613-bluetooth-permission
Browse files Browse the repository at this point in the history
fix(#613): [Dhivya] iOS - Allow user to recover when Bluetooth permission is denied
  • Loading branch information
tilak-puli authored Mar 24, 2023
2 parents a9a2dd3 + f664567 commit 6a801eb
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 263 deletions.
14 changes: 8 additions & 6 deletions components/QrScanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Camera } from 'expo-camera';
import { BarCodeEvent, BarCodeScanner } from 'expo-barcode-scanner';
import { Linking, TouchableOpacity, View } from 'react-native';
import { Theme } from './ui/styleUtils';
import { Column, Button, Text } from './ui';
import { Column, Button, Text, Centered } from './ui';
import { GlobalContext } from '../shared/GlobalContext';
import { useSelector } from '@xstate/react';
import { selectIsActive } from '../machines/app';
Expand Down Expand Up @@ -45,11 +45,13 @@ export const QrScanner: React.FC<QrScannerProps> = (props) => {

if (hasPermission === false) {
return (
<Column fill align="space-between">
<Text align="center" margin="0 16" color={Theme.Colors.errorMessage}>
{t('missingPermissionText')}
</Text>
<Button title={t('allowCameraButton')} onPress={openSettings} />
<Column padding="24" fill align="space-between">
<Centered fill>
<Text align="center" color={Theme.Colors.errorMessage}>
{t('missingPermissionText')}
</Text>
</Centered>
<Button title={t('allowCameraButton')} onPress={openSettings}></Button>
</Column>
);
}
Expand Down
6 changes: 4 additions & 2 deletions locales/ara.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,10 @@
"ScanScreen": {
"header": "مسح رمز الاستجابة السريعة",
"noShareableVcs": "لا يمكن مشاركة {{vcLabel}}",
"BluetoothStateIos": "تم إيقاف تشغيل البلوتوث ، يرجى تشغيله من مركز التحكم",
"BluetoothStateAndroid": "تم إيقاف تشغيل البلوتوث ، يرجى تشغيله من قائمة الإعدادات السريعة",
"bluetoothStateAndroid": "يرجى تشغيل البلوتوث من الإعدادات السريعة لدعم المشاركة المحلية",
"bluetoothStateIos": "يرجى تشغيل البلوتوث من مركز التحكم لدعم المشاركة المحلية",
"enableBluetoothMessage": "يرجى تمكين أذونات البلوتوث لدعم المشاركة المحلية",
"enableBluetoothButtonText": "السماح لأذونات البلوتوث",
"sharingVc": "مشاركة {{vcLabel}}",
"errors": {
"locationDisabled": {
Expand Down
6 changes: 4 additions & 2 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,10 @@
"header": "Scan QR Code",
"noShareableVcs": "No shareable {{vcLabel}} are available.",
"sharingVc": "Sharing {{vcLabel}}",
"BluetoothStateIos": "Bluetooth is turned OFF, please turn it ON from Control center",
"BluetoothStateAndroid": "Bluetooth is turned OFF, please turn it ON from Quick settings menu",
"bluetoothStateAndroid": "Please turn on bluetooth from quick settings to support local sharing",
"bluetoothStateIos": "Please turn on bluetooth from control center to support local sharing",
"enableBluetoothMessage":"Please enable bluetooth permissions to support local sharing",
"enableBluetoothButtonText": "Allow Bluetooth Permissions",
"errors": {
"locationDisabled": {
"message": "Location services must be enabled for the scanning functionality",
Expand Down
6 changes: 4 additions & 2 deletions locales/fil.json
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@
"ScanScreen": {
"header": "I-scan ang QR Code",
"noShareableVcs": "Walang magagamit na maibabahaging {{vcLabel}}.",
"BluetoothStateIos": "Naka-OFF ang Bluetooth, paki-ON ito mula sa Control center",
"BluetoothStateAndroid": "Naka-OFF ang Bluetooth, paki-ON ito mula sa menu ng Quick settings",
"bluetoothStateAndroid": "Mangyaring i-on ang bluetooth mula sa mga mabilisang setting upang suportahan ang lokal na pagbabahagi",
"bluetoothStateIos": "Mangyaring i-on ang bluetooth mula sa control center upang suportahan ang lokal na pagbabahagi",
"enableBluetoothMessage": "Mangyaring paganahin ang mga pahintulot ng bluetooth upang suportahan ang lokal na pagbabahagi",
"enableBluetoothButtonText": "Payagan ang Mga Pahintulot sa Bluetooth",
"sharingVc": "Pagbabahagi ng {{vcLabel}}",
"errors": {
"locationDisabled": {
Expand Down
6 changes: 4 additions & 2 deletions locales/hin.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,10 @@
"ScanScreen": {
"header": "क्यूआर कोड स्कैन करे",
"noShareableVcs": "कोई साझा करने योग्य {{vcLabel}} उपलब्ध नहीं है।",
"BluetoothStateIos": "ब्लूटूथ बंद है, कृपया इसे नियंत्रण केंद्र से चालू करें",
"BluetoothStateAndroid": "ब्लूटूथ बंद है, कृपया इसे त्वरित सेटिंग मेनू से चालू करें",
"bluetoothStateAndroid": "स्थानीय साझाकरण का समर्थन करने के लिए कृपया त्वरित सेटिंग से ब्लूटूथ चालू करें",
"bluetoothStateIos": " स्थानीय साझाकरण का समर्थन करने के लिए कृपया नियंत्रण केंद्र से ब्लूटूथ चालू करें",
"enableBluetoothMessage": "स्थानीय साझाकरण का समर्थन करने के लिए कृपया ब्लूटूथ अनुमतियां सक्षम करें",
"enableBluetoothButtonText": "ब्लूटूथ अनुमतियों की अनुमति दें",
"sharingVc": "शेयरिंग {{vcLabel}}",
"errors": {
"locationDisabled": {
Expand Down
6 changes: 4 additions & 2 deletions locales/kan.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,10 @@
"ScanScreen": {
"header": "ಸ್ಕ್ಯಾನ್ ಕ್ಯೂಆರ್ ಕೋಡ್",
"noShareableVcs": "ಯಾವುದೇ ಹಂಚಿಕೊಳ್ಳಬಹುದಾದ {{vcLabel}} ಲಭ್ಯವಿಲ್ಲ.",
"BluetoothStateIos": "ಬ್ಲೂಟೂತ್ ಅನ್ನು ಆಫ್ ಮಾಡಲಾಗಿದೆ, ದಯವಿಟ್ಟು ಅದನ್ನು ನಿಯಂತ್ರಣ ಕೇಂದ್ರದಿಂದ ಆನ್ ಮಾಡಿ",
"BluetoothStateAndroid": "ಬ್ಲೂಟೂತ್ ಆಫ್ ಆಗಿದೆ, ದಯವಿಟ್ಟು ತ್ವರಿತ ಸೆಟ್ಟಿಂಗ್‌ಗಳ ಮೆನುವಿನಿಂದ ಅದನ್ನು ಆನ್ ಮಾಡಿ",
"bluetoothStateAndroid": "ಸ್ಥಳೀಯ ಹಂಚಿಕೆಯನ್ನು ಬೆಂಬಲಿಸಲು ದಯವಿಟ್ಟು ತ್ವರಿತ ಸೆಟ್ಟಿಂಗ್‌ಗಳಿಂದ ಬ್ಲೂಟೂತ್ ಆನ್ ಮಾಡಿ",
"bluetoothStateIos": " ಸ್ಥಳೀಯ ಹಂಚಿಕೆಯನ್ನು ಬೆಂಬಲಿಸಲು ದಯವಿಟ್ಟು ನಿಯಂತ್ರಣ ಕೇಂದ್ರದಿಂದ ಬ್ಲೂಟೂತ್ ಆನ್ ಮಾಡಿ",
"enableBluetoothMessage":"ದಯವಿಟ್ಟು ಸ್ಥಳೀಯ ಹಂಚಿಕೆಯನ್ನು ಬೆಂಬಲಿಸಲು ಬ್ಲೂಟೂತ್ ಅನುಮತಿಗಳನ್ನು ಸಕ್ರಿಯಗೊಳಿಸಿ",
"enableBluetoothButtonText": "ಬ್ಲೂಟೂತ್ ಅನುಮತಿಗಳನ್ನು ಅನುಮತಿಸಿ",
"sharingVc": "ಹಂಚಿಕೆ {{vcLabel}}",
"errors": {
"locationDisabled": {
Expand Down
6 changes: 4 additions & 2 deletions locales/tam.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,10 @@
"ScanScreen": {
"header": "QR குறியீட்டை ஸ்கேன் செய்",
"noShareableVcs": "பகிரக்கூடிய {{vcLabel}} எதுவும் இல்லை.",
"BluetoothStateIos": "புளூடூத் முடக்கப்பட்டுள்ளது, கட்டுப்பாட்டு மையத்திலிருந்து அதை இயக்கவும்",
"BluetoothStateAndroid": "புளூடூத் முடக்கப்பட்டுள்ளது, விரைவு அமைப்புகள் மெனுவிலிருந்து அதை இயக்கவும்",
"bluetoothStateAndroid": "உள்ளூர் பகிர்வை ஆதரிக்க விரைவான அமைப்புகளிலிருந்து புளூடூத்தை இயக்கவும்",
"bluetoothStateIos": "உள்ளூர் பகிர்வை ஆதரிக்க, கட்டுப்பாட்டு மையத்திலிருந்து புளூடூத்தை இயக்கவும்",
"enableBluetoothMessage":"உள்ளூர் பகிர்வை ஆதரிக்க புளூடூத் அனுமதிகளை இயக்கவும்",
"enableBluetoothButtonText": "புளூடூத் அனுமதிகளை அனுமதிக்கவும்",
"sharingVc": "பகிர்தல் {{vcLabel}}",
"errors": {
"locationDisabled": {
Expand Down
58 changes: 33 additions & 25 deletions machines/openIdBle/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ import {
SendVcEvent,
SendVcStatus,
} from '../../shared/openIdBLE/smartshare';
import { check, PERMISSIONS, PermissionStatus } from 'react-native-permissions';
import {
check,
PERMISSIONS,
PermissionStatus,
request,
RESULTS,
} from 'react-native-permissions';
import { checkLocation, requestLocation } from '../../shared/location';
import { CameraCapturedPicture } from 'expo-camera';
import { log } from 'xstate/lib/actions';
Expand Down Expand Up @@ -87,6 +93,8 @@ const model = createModel(
CONNECTION_DESTROYED: () => ({}),
SCREEN_BLUR: () => ({}),
SCREEN_FOCUS: () => ({}),
BLUETOOTH_ALLOWED: () => ({}),
BLUETOOTH_DENIED: () => ({}),
BLUETOOTH_ENABLED: () => ({}),
BLUETOOTH_DISABLED: () => ({}),
GOTO_SETTINGS: () => ({}),
Expand Down Expand Up @@ -150,23 +158,15 @@ export const scanMachine =
states: {
checking: {
invoke: {
src: 'checkBluetoothService',
src: 'checkBluetoothPermission',
},
on: {
BLUETOOTH_ENABLED: {
BLUETOOTH_ALLOWED: {
target: 'enabled',
},
BLUETOOTH_DISABLED: [
{
// In iOS, irrespective of bluetooth permission status provided by the User, we always get BLUETOOTH_DENIED event.
// This issue will be handled separately(#580). Temporarily we are allowing to move forward.
target: '#scan.checkingLocationService',
cond: 'isIOS',
},
{
target: 'requesting',
},
],
BLUETOOTH_DENIED: {
target: '#scan.bluetoothDenied',
},
},
},
requesting: {
Expand All @@ -191,6 +191,7 @@ export const scanMachine =
},
bluetoothDenied: {
on: {
APP_ACTIVE: '#scan.checkingBluetoothService',
GOTO_SETTINGS: {
actions: 'openBluetoothSettings',
},
Expand Down Expand Up @@ -753,22 +754,33 @@ export const scanMachine =
},

services: {
checkBluetoothService: () => (callback) => {
const subscription = BluetoothStateManager.onStateChange((state) => {
if (state === 'PoweredOn') {
callback(model.events.BLUETOOTH_ENABLED());
checkBluetoothPermission: () => async (callback) => {
// wait a bit for animation to finish when app becomes active
await new Promise((resolve) => setTimeout(resolve, 250));
try {
// Passing Granted for android since permission status is always granted even if its denied.
let response: PermissionStatus = RESULTS.GRANTED;

if (Platform.OS === 'ios') {
response = await check(PERMISSIONS.IOS.BLUETOOTH_PERIPHERAL);
}

if (response === RESULTS.GRANTED) {
callback(model.events.BLUETOOTH_ALLOWED());
} else {
callback(model.events.BLUETOOTH_DISABLED());
callback(model.events.BLUETOOTH_DENIED());
}
}, true);
return () => subscription.remove();
} catch (e) {
console.error(e);
}
},

requestBluetooth: () => (callback) => {
BluetoothStateManager.requestToEnable()
.then(() => callback(model.events.BLUETOOTH_ENABLED()))
.catch(() => callback(model.events.BLUETOOTH_DISABLED()));
},

checkLocationPermission: () => async (callback) => {
try {
// wait a bit for animation to finish when app becomes active
Expand Down Expand Up @@ -961,10 +973,6 @@ export const scanMachine =
},

guards: {
isIOS: () => {
return Platform.OS === 'ios';
},

isQrOffline: (_context, event) => {
// don't scan if QR is offline and Google Nearby is enabled
if (Platform.OS === 'ios' && !isBLEEnabled) return false;
Expand Down
Loading

0 comments on commit 6a801eb

Please sign in to comment.