Skip to content

Commit

Permalink
Fix android bluetooth permission error
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Kim committed Mar 21, 2022
1 parent 3ec15b9 commit 5e82e9c
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 11 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ android {
applicationId "money.terra.station"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 10503003
versionName "1.5.3"
versionCode 10504000
versionName "1.5.4"
multiDexEnabled true
setProperty('archivesBaseName', renameArtifact('station-mobile', versionCode))
missingDimensionStrategy 'react-native-camera', 'general'
Expand Down
13 changes: 13 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />

<uses-permission android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"
android:maxSdkVersion="30" />

<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_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>

<application
android:name=".MainApplication"
android:allowBackup="false"
Expand Down
8 changes: 4 additions & 4 deletions ios/TerraStation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@
CODE_SIGN_ENTITLEMENTS = TerraStation/TerraStation.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 10503003;
CURRENT_PROJECT_VERSION = 10504000;
DEVELOPMENT_TEAM = UYTGWV77XZ;
ENABLE_BITCODE = NO;
EXCLUDED_ARCHS = "";
Expand All @@ -801,7 +801,7 @@
INFOPLIST_FILE = TerraStation/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.5.3;
MARKETING_VERSION = 1.5.4;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
Expand All @@ -826,14 +826,14 @@
CODE_SIGN_ENTITLEMENTS = TerraStation/TerraStation.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 10503003;
CURRENT_PROJECT_VERSION = 10504000;
DEVELOPMENT_TEAM = UYTGWV77XZ;
EXCLUDED_ARCHS = "";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
INFOPLIST_FILE = TerraStation/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.5.3;
MARKETING_VERSION = 1.5.4;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
Expand Down
6 changes: 3 additions & 3 deletions ios/TerraStation/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
</dict>
</dict>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Connect with Ledger</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>Connect with Ledger</string>
<string>Allow Bluetooth to connect with Ledger</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>Allow Bluetooth to connect with Ledger</string>
<key>NSCameraUsageDescription</key>
<string>QR Scan</string>
<key>NSFaceIDUsageDescription</key>
Expand Down
6 changes: 5 additions & 1 deletion src/components/Error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ const Error = ({title, content} : { title?: string, content?: string }): ReactEl
lineHeight: 21,
}}
>
{content || 'You have encountered an error'}
{
(typeof content === 'object' || !content) ?
'You have encountered an error' :
content
}
</Text>
</View>
)
Expand Down
13 changes: 12 additions & 1 deletion src/screens/auth/AuthMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { navigationHeaderOptions } from 'components/layout/Header'

import { AuthStackParams } from 'types'
import TopupStore from 'stores/TopupStore'
import { requestPermissionBLE } from 'utils/permission'

const AuthMenu = (): ReactElement => {
const [initPageComplete, setInitPageComplete] = useState(false)
Expand All @@ -32,6 +33,16 @@ const AuthMenu = (): ReactElement => {
setInitPageComplete(true)
}

const grantingBLE = async (): Promise<void> => {
const requestResult = await requestPermissionBLE()
if (requestResult === 'granted') {
navigate('ConnectLedger')
return
} else {
return
}
}

useEffect(() => {
initPage()
}, [])
Expand Down Expand Up @@ -103,7 +114,7 @@ const AuthMenu = (): ReactElement => {
theme={'white'}
title={'Access with Ledger'}
onPress={(): void => {
navigate('ConnectLedger')
grantingBLE()
}}
containerStyle={{ marginBottom: 10 }}
/>
Expand Down
8 changes: 8 additions & 0 deletions src/utils/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ export const requestPermission = async (): Promise<PermissionResult> => {
return request(permissions.CAMERA)
}

export const requestPermissionBLE = async (): Promise<PermissionResult> => {
if (Platform.OS === 'android') {
return request(PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION)
} else {
return 'granted'
}
}

export const openPermissionSettings = (): void => {
openSettings().catch(() => {
// error handling
Expand Down

0 comments on commit 5e82e9c

Please sign in to comment.