@regulaforensics/cordova-plugin-document-reader-api 7.4.620 → 7.5.78-rc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitlab/report.yaml +75 -0
- package/.gitlab-ci.yml +49 -0
- package/README.md +1 -1
- package/example/config.xml +14 -12
- package/example/package.json +4 -4
- package/example/www/js/index.js +5 -0
- package/package.json +4 -8
- package/plugin.xml +7 -5
- package/src/android/BluetoothUtil.kt +105 -59
- package/src/android/Config.kt +63 -5
- package/src/android/DocumentReader.kt +66 -47
- package/src/android/JSONConstructor.kt +39 -14
- package/src/android/Utils.kt +7 -2
- package/src/android/build.gradle +2 -4
- package/src/ios/RGLWConfig.h +2 -0
- package/src/ios/RGLWConfig.m +103 -50
- package/src/ios/RGLWDocumentReader.h +4 -1
- package/src/ios/RGLWDocumentReader.m +71 -21
- package/src/ios/RGLWJSONConstructor.h +8 -0
- package/src/ios/RGLWJSONConstructor.m +77 -9
- package/www/DocumentReader.js +82 -6
- package/.github/ISSUE_TEMPLATE/config.yml +0 -5
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
spec:
|
|
2
|
+
inputs:
|
|
3
|
+
stage:
|
|
4
|
+
default: reports
|
|
5
|
+
image:
|
|
6
|
+
default: ubuntu:22.04
|
|
7
|
+
ignore_vulnerabilities:
|
|
8
|
+
default: "false"
|
|
9
|
+
sast_report_file:
|
|
10
|
+
default: gl-sast-report.json
|
|
11
|
+
secret_detection_report_file:
|
|
12
|
+
default: gl-secret-detection-report.json
|
|
13
|
+
dependency_scanning_report_file:
|
|
14
|
+
default: gl-dependency-scanning-report.json
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
view reports:
|
|
18
|
+
image: $[[ inputs.image ]]
|
|
19
|
+
stage: $[[ inputs.stage ]]
|
|
20
|
+
variables:
|
|
21
|
+
IGNORE_VULNERABILITIES: $[[ inputs.ignore_vulnerabilities ]]
|
|
22
|
+
SAST_REPORT_FILE: $[[ inputs.sast_report_file ]]
|
|
23
|
+
SECRET_DETECTION_REPORT_FILE: $[[ inputs.secret_detection_report_file ]]
|
|
24
|
+
DEPENDENCY_SCANNING_REPORT_FILE: $[[ inputs.dependency_scanning_report_file ]]
|
|
25
|
+
RED: \033[0;31m
|
|
26
|
+
YELLOW: \033[1;33m
|
|
27
|
+
GREEN: \033[0;32m
|
|
28
|
+
NC: \033[0m
|
|
29
|
+
needs:
|
|
30
|
+
- job: semgrep-sast
|
|
31
|
+
artifacts: true
|
|
32
|
+
- job: secret_detection
|
|
33
|
+
artifacts: true
|
|
34
|
+
- job: gemnasium-dependency_scanning
|
|
35
|
+
artifacts: true
|
|
36
|
+
rules:
|
|
37
|
+
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
38
|
+
script:
|
|
39
|
+
- ls -la
|
|
40
|
+
- apt update && apt install -y jq
|
|
41
|
+
- |
|
|
42
|
+
for f in SAST_REPORT_FILE SECRET_DETECTION_REPORT_FILE DEPENDENCY_SCANNING_REPORT_FILE
|
|
43
|
+
do
|
|
44
|
+
if [[ -f "${!f}" ]]
|
|
45
|
+
then
|
|
46
|
+
echo -e "${GREEN}File ${!f} exists, adding report${NC}"
|
|
47
|
+
r=${f/%_FILE}
|
|
48
|
+
declare $r="$(cat ${!f} | jq 'select(.vulnerabilities != []).vulnerabilities')"
|
|
49
|
+
if [[ ! -z "${!r}" ]]
|
|
50
|
+
then
|
|
51
|
+
VULNERABILITIES_FOUND=true
|
|
52
|
+
echo -e "${RED}Found $r vulnerabilities${NC}"
|
|
53
|
+
echo "${!r}"
|
|
54
|
+
echo
|
|
55
|
+
fi
|
|
56
|
+
else
|
|
57
|
+
echo -e "${YELLOW}File ${!f} doesn't exist, skipping${NC}"
|
|
58
|
+
fi
|
|
59
|
+
done
|
|
60
|
+
|
|
61
|
+
if [[ "$VULNERABILITIES_FOUND" == true ]]
|
|
62
|
+
then
|
|
63
|
+
if [[ "$IGNORE_VULNERABILITIES" == true ]]
|
|
64
|
+
then
|
|
65
|
+
echo -e "${GREEN}All found vulnerabilities were ignored due to IGNORE_VULNERABILITIES=true${NC}"
|
|
66
|
+
exit 0
|
|
67
|
+
else
|
|
68
|
+
echo -e "${RED}Vulnerabilities found, please see reports above${NC}"
|
|
69
|
+
exit 1
|
|
70
|
+
fi
|
|
71
|
+
fi
|
|
72
|
+
|
|
73
|
+
echo -e "${GREEN}No vulnerabilities found${NC}"
|
|
74
|
+
|
|
75
|
+
exit 0
|
package/.gitlab-ci.yml
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
stages:
|
|
2
|
+
- test
|
|
3
|
+
- reports
|
|
4
|
+
|
|
5
|
+
include:
|
|
6
|
+
- template: Jobs/SAST.gitlab-ci.yml
|
|
7
|
+
- template: Jobs/Secret-Detection.gitlab-ci.yml
|
|
8
|
+
- template: Jobs/Dependency-Scanning.gitlab-ci.yml
|
|
9
|
+
- local: .gitlab/report.yaml
|
|
10
|
+
rules:
|
|
11
|
+
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
12
|
+
inputs:
|
|
13
|
+
stage: reports
|
|
14
|
+
image: ubuntu:22.04
|
|
15
|
+
ignore_vulnerabilities: "false"
|
|
16
|
+
sast_report_file: gl-sast-report.json
|
|
17
|
+
secret_detection_report_file: gl-secret-detection-report.json
|
|
18
|
+
dependency_scanning_report_file: gl-dependency-scanning-report.json
|
|
19
|
+
|
|
20
|
+
trivy scan:
|
|
21
|
+
stage: test
|
|
22
|
+
image: aquasec/trivy
|
|
23
|
+
rules:
|
|
24
|
+
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
25
|
+
script:
|
|
26
|
+
- trivy fs --severity CRITICAL,HIGH,MEDIUM,LOW --ignore-unfixed --db-repository container-registry.regula.local:80/aquasecurity/trivy-db:2 --exit-code 1 .
|
|
27
|
+
|
|
28
|
+
semgrep-sast:
|
|
29
|
+
rules:
|
|
30
|
+
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
31
|
+
artifacts:
|
|
32
|
+
paths:
|
|
33
|
+
- gl-sast-report.json
|
|
34
|
+
|
|
35
|
+
secret_detection:
|
|
36
|
+
rules:
|
|
37
|
+
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
38
|
+
artifacts:
|
|
39
|
+
paths:
|
|
40
|
+
- gl-secret-detection-report.json
|
|
41
|
+
|
|
42
|
+
gemnasium-dependency_scanning:
|
|
43
|
+
variables:
|
|
44
|
+
DS_MAX_DEPTH: -1
|
|
45
|
+
rules:
|
|
46
|
+
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
47
|
+
artifacts:
|
|
48
|
+
paths:
|
|
49
|
+
- gl-dependency-scanning-report.json
|
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ This repository contains the source code of the Document Reader API, and the sam
|
|
|
8
8
|
|
|
9
9
|
## Documentation
|
|
10
10
|
|
|
11
|
-
You can find documentation [here](https://docs.regulaforensics.com/develop/doc-reader-sdk/mobile
|
|
11
|
+
You can find documentation [here](https://docs.regulaforensics.com/develop/doc-reader-sdk/mobile).
|
|
12
12
|
|
|
13
13
|
## License
|
|
14
14
|
|
package/example/config.xml
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
<allow-intent href="mailto:*" />
|
|
17
17
|
<allow-intent href="geo:*" />
|
|
18
18
|
<platform name="android">
|
|
19
|
-
<resource-file src="www/db.dat" target="app/src/main/assets/Regula/db.dat"/>
|
|
19
|
+
<resource-file src="www/db.dat" target="app/src/main/assets/Regula/db.dat" />
|
|
20
20
|
<preference name="android-minSdkVersion" value="23" />
|
|
21
21
|
<preference name="android-targetSdkVersion" value="34" />
|
|
22
22
|
<allow-intent href="market:*" />
|
|
@@ -26,11 +26,13 @@
|
|
|
26
26
|
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
|
27
27
|
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
|
|
28
28
|
</config-file>
|
|
29
|
+
<preference name="orientation" value="portrait" />
|
|
29
30
|
</platform>
|
|
30
31
|
<platform name="ios">
|
|
31
32
|
<resource-file src="www/db.dat" />
|
|
32
33
|
<allow-intent href="itms:*" />
|
|
33
34
|
<allow-intent href="itms-apps:*" />
|
|
35
|
+
<preference name="orientation" value="portrait" />
|
|
34
36
|
<config-file target="*-Info.plist" parent="NSCameraUsageDescription">
|
|
35
37
|
<string>To use camera</string>
|
|
36
38
|
</config-file>
|
|
@@ -42,26 +44,26 @@
|
|
|
42
44
|
</config-file>
|
|
43
45
|
<config-file target="*-Info.plist" parent="com.apple.developer.nfc.readersession.iso7816.select-identifiers">
|
|
44
46
|
<array>
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
<string>A0000002471001</string>
|
|
48
|
+
<string>E80704007F00070302</string>
|
|
49
|
+
<string>A000000167455349474E</string>
|
|
50
|
+
<string>A0000002480100</string>
|
|
51
|
+
<string>A0000002480200</string>
|
|
52
|
+
<string>A0000002480300</string>
|
|
53
|
+
<string>A00000045645444C2D3031</string>
|
|
54
|
+
</array>
|
|
53
55
|
</config-file>
|
|
54
56
|
<config-file target="*-Debug.plist" parent="com.apple.developer.nfc.readersession.formats">
|
|
55
57
|
<array>
|
|
56
58
|
<string>NDEF</string>
|
|
57
|
-
|
|
59
|
+
<string>TAG</string>
|
|
58
60
|
</array>
|
|
59
61
|
</config-file>
|
|
60
62
|
<config-file target="*-Release.plist" parent="com.apple.developer.nfc.readersession.formats">
|
|
61
63
|
<array>
|
|
62
64
|
<string>NDEF</string>
|
|
63
|
-
|
|
65
|
+
<string>TAG</string>
|
|
64
66
|
</array>
|
|
65
67
|
</config-file>
|
|
66
68
|
</platform>
|
|
67
|
-
</widget>
|
|
69
|
+
</widget>
|
package/example/package.json
CHANGED
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"author": "Regula Forensics Inc.",
|
|
14
14
|
"license": "commercial",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@regulaforensics/cordova-plugin-document-reader-api": "7.
|
|
17
|
-
"@regulaforensics/cordova-plugin-document-reader-core-fullauthrfid": "7.
|
|
18
|
-
"cordova-android": "
|
|
19
|
-
"cordova-ios": "7.
|
|
16
|
+
"@regulaforensics/cordova-plugin-document-reader-api": "7.5.78-rc",
|
|
17
|
+
"@regulaforensics/cordova-plugin-document-reader-core-fullauthrfid": "7.7.168-rc",
|
|
18
|
+
"cordova-android": "13.0.0",
|
|
19
|
+
"cordova-ios": "7.1.1",
|
|
20
20
|
"cordova-plugin-add-swift-support": "2.0.2",
|
|
21
21
|
"cordova-plugin-advanced-http": "3.3.1",
|
|
22
22
|
"cordova-plugin-camera": "7.0.0",
|
package/example/www/js/index.js
CHANGED
|
@@ -238,6 +238,11 @@ var app = {
|
|
|
238
238
|
if (value != null)
|
|
239
239
|
document.getElementById("portraitImage").src = "data:image/png;base64," + value
|
|
240
240
|
}, function (error) { console.log(error) })
|
|
241
|
+
|
|
242
|
+
DocumentReader.graphicFieldImageByTypeSource(results, Enum.eGraphicFieldType.GF_PORTRAIT, Enum.eRPRM_ResultType.RFID_RESULT_TYPE_RFID_IMAGE_DATA, function (value) {
|
|
243
|
+
if (value != null)
|
|
244
|
+
document.getElementById("portraitImage").src = "data:image/png;base64," + value
|
|
245
|
+
}, function (error) { console.log(error) })
|
|
241
246
|
}
|
|
242
247
|
|
|
243
248
|
function clearResults() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regulaforensics/cordova-plugin-document-reader-api",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.5.78-rc",
|
|
4
4
|
"description": "Cordova plugin for reading and validation of identification documents (API framework)",
|
|
5
5
|
"cordova": {
|
|
6
6
|
"id": "@regulaforensics/cordova-plugin-document-reader-api",
|
|
@@ -11,17 +11,13 @@
|
|
|
11
11
|
},
|
|
12
12
|
"max_body_size": "1000mb",
|
|
13
13
|
"keywords": [
|
|
14
|
-
"cordova",
|
|
15
|
-
"documentreader",
|
|
16
|
-
"reader",
|
|
17
|
-
"scanner",
|
|
18
|
-
"regula"
|
|
14
|
+
"cordova", "documentreader", "reader", "scanner", "regula"
|
|
19
15
|
],
|
|
20
16
|
"author": "RegulaForensics",
|
|
21
17
|
"license": "commercial",
|
|
22
18
|
"repository": {
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/regulaforensics/DocumentReader-Cordova-Plugin.git"
|
|
25
21
|
},
|
|
26
22
|
"homepage": "https://mobile.regulaforensics.com",
|
|
27
23
|
"publishConfig": {
|
package/plugin.xml
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
<?xml version='1.0' encoding='utf-8'?>
|
|
2
|
-
<plugin id="cordova-plugin-document-reader-api" version="7.
|
|
3
|
-
xmlns="http://apache.org/cordova/ns/plugins/1.0">
|
|
2
|
+
<plugin id="@regulaforensics/cordova-plugin-document-reader-api" version="7.5.78-rc" xmlns="http://apache.org/cordova/ns/plugins/1.0">
|
|
4
3
|
<name>DocumentReaderApi</name>
|
|
5
4
|
<description>Cordova plugin Document reader api</description>
|
|
6
5
|
<license>commercial</license>
|
|
@@ -15,6 +14,7 @@
|
|
|
15
14
|
<feature name="DocumentReader">
|
|
16
15
|
<param name="ios-package" value="RGLWDocumentReader" />
|
|
17
16
|
</feature>
|
|
17
|
+
<preference name="deployment-target" value="13.0" />
|
|
18
18
|
</config-file>
|
|
19
19
|
<header-file src="src/ios/RGLWDocumentReader.h" />
|
|
20
20
|
<source-file src="src/ios/RGLWDocumentReader.m" />
|
|
@@ -23,16 +23,18 @@
|
|
|
23
23
|
<header-file src="src/ios/RGLWConfig.h" />
|
|
24
24
|
<source-file src="src/ios/RGLWConfig.m" />
|
|
25
25
|
<podspec>
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
<config>
|
|
27
|
+
<source url="https://github.com/CocoaPods/Specs.git"/>
|
|
28
|
+
</config>
|
|
28
29
|
<pods>
|
|
29
|
-
<pod name="
|
|
30
|
+
<pod name="DocumentReaderStage" spec="7.7.4492" />
|
|
30
31
|
</pods>
|
|
31
32
|
</podspec>
|
|
32
33
|
</platform>
|
|
33
34
|
|
|
34
35
|
<platform name="android">
|
|
35
36
|
<config-file parent="/*" target="res/xml/config.xml">
|
|
37
|
+
<preference name="GradlePluginKotlinEnabled" value="true" />
|
|
36
38
|
<feature name="DocumentReader">
|
|
37
39
|
<param name="android-package" value="cordova.plugin.documentreader.DocumentReader" />
|
|
38
40
|
</feature>
|
|
@@ -5,10 +5,13 @@
|
|
|
5
5
|
// Created by Pavel Masiuk on 21.09.2023.
|
|
6
6
|
// Copyright © 2023 Regula. All rights reserved.
|
|
7
7
|
//
|
|
8
|
+
@file:SuppressLint("MissingPermission")
|
|
8
9
|
|
|
9
10
|
package cordova.plugin.documentreader
|
|
10
11
|
|
|
11
|
-
import android.Manifest.permission
|
|
12
|
+
import android.Manifest.permission.ACCESS_FINE_LOCATION
|
|
13
|
+
import android.Manifest.permission.BLUETOOTH_CONNECT
|
|
14
|
+
import android.Manifest.permission.BLUETOOTH_SCAN
|
|
12
15
|
import android.annotation.SuppressLint
|
|
13
16
|
import android.app.Activity
|
|
14
17
|
import android.bluetooth.BluetoothAdapter
|
|
@@ -19,94 +22,137 @@ import android.content.pm.PackageManager.PERMISSION_GRANTED
|
|
|
19
22
|
import android.os.Build
|
|
20
23
|
import android.os.IBinder
|
|
21
24
|
import android.provider.Settings
|
|
22
|
-
import androidx.annotation.RequiresPermission
|
|
23
|
-
import androidx.core.app.ActivityCompat.requestPermissions
|
|
24
25
|
import androidx.core.content.ContextCompat.checkSelfPermission
|
|
25
|
-
import com.regula.
|
|
26
|
-
import com.regula.
|
|
27
|
-
import com.regula.
|
|
26
|
+
import com.regula.common.ble.BLEWrapper
|
|
27
|
+
import com.regula.common.ble.BleWrapperCallback
|
|
28
|
+
import com.regula.common.ble.RegulaBleService
|
|
28
29
|
import com.regula.documentreader.api.internal.permission.BluetoothPermissionHelper.BLE_ACCESS_PERMISSION
|
|
29
30
|
import com.regula.documentreader.api.internal.permission.BluetoothSettingsHelper.isBluetoothEnabled
|
|
30
31
|
import com.regula.documentreader.api.internal.permission.BluetoothSettingsHelper.isLocationServiceEnabled
|
|
32
|
+
import java.util.Timer
|
|
33
|
+
import java.util.TimerTask
|
|
31
34
|
|
|
32
|
-
const val
|
|
33
|
-
|
|
35
|
+
const val SEARCHING_TIMEOUT: Long = 7000
|
|
36
|
+
|
|
37
|
+
const val INTENT_REQUEST_ENABLE_LOCATION = 196
|
|
38
|
+
const val INTENT_REQUEST_ENABLE_BLUETOOTH = 197
|
|
34
39
|
|
|
35
40
|
@SuppressLint("StaticFieldLeak")
|
|
36
|
-
var
|
|
41
|
+
lateinit var bluetooth: BLEWrapper
|
|
42
|
+
lateinit var savedCallbackForPermissionResult: Callback
|
|
43
|
+
var deviceConnected = false
|
|
37
44
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
fun connectBluetoothDevice(callback: Callback) {
|
|
46
|
+
// return if already connected
|
|
47
|
+
if (deviceConnected) return
|
|
48
|
+
|
|
49
|
+
// If some of the bluetooth permissions/settings don't match the requirements,
|
|
50
|
+
// save callback for later and request the permissions/settings.
|
|
51
|
+
// Callback will then be used in onRequestPermissionsResult for permission requests
|
|
52
|
+
// and in onActivityResult for settings change requests.
|
|
53
|
+
if (!isBluetoothSettingsReady(activity)) {
|
|
54
|
+
savedCallbackForPermissionResult = callback
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// set searching timeout
|
|
59
|
+
val timer = object : TimerTask() {
|
|
60
|
+
override fun run() {
|
|
61
|
+
callback.success(false)
|
|
62
|
+
bluetooth.stopDeviceScan()
|
|
63
|
+
bluetooth.disconnect()
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
Timer().schedule(timer, SEARCHING_TIMEOUT)
|
|
67
|
+
|
|
68
|
+
// start searching devices
|
|
69
|
+
val bleIntent = Intent(context, RegulaBleService::class.java)
|
|
70
|
+
context.startService(bleIntent)
|
|
71
|
+
context.bindService(bleIntent, object : ServiceConnection {
|
|
72
|
+
override fun onServiceConnected(name: ComponentName, service: IBinder) {
|
|
73
|
+
bluetooth = (service as RegulaBleService.LocalBinder).service.bleManager
|
|
74
|
+
bluetooth.addCallback(object : BleWrapperCallback() {
|
|
75
|
+
override fun onDeviceReady() {
|
|
76
|
+
timer.cancel()
|
|
77
|
+
bluetooth.removeCallback(this)
|
|
78
|
+
deviceConnected = true
|
|
79
|
+
callback.success(true)
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
override fun onServiceDisconnected(name: ComponentName) {}
|
|
85
|
+
}, 0)
|
|
42
86
|
}
|
|
43
87
|
|
|
44
|
-
fun
|
|
45
|
-
|
|
46
|
-
|
|
88
|
+
fun onRequestPermissionsResult(
|
|
89
|
+
requestCode: Int,
|
|
90
|
+
permissions: Array<String>,
|
|
91
|
+
grantResults: IntArray
|
|
92
|
+
): Boolean {
|
|
93
|
+
if (requestCode != BLE_ACCESS_PERMISSION || permissions.isEmpty()) return false
|
|
94
|
+
if (grantResults.isEmpty() || grantResults[0] != PERMISSION_GRANTED) {
|
|
95
|
+
savedCallbackForPermissionResult.success(false)
|
|
96
|
+
return true
|
|
97
|
+
}
|
|
98
|
+
connectBluetoothDevice(savedCallbackForPermissionResult)
|
|
99
|
+
return true
|
|
47
100
|
}
|
|
48
101
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
102
|
+
fun onActivityResult(requestCode: Int, rc: Int, @Suppress("UNUSED_PARAMETER") data: Intent?): Boolean {
|
|
103
|
+
var resultCode = rc
|
|
104
|
+
if (requestCode == INTENT_REQUEST_ENABLE_LOCATION)
|
|
105
|
+
resultCode = if (isLocationServiceEnabled(activity)) Activity.RESULT_OK
|
|
106
|
+
else requestCode
|
|
107
|
+
|
|
108
|
+
if (requestCode == INTENT_REQUEST_ENABLE_BLUETOOTH || requestCode == INTENT_REQUEST_ENABLE_LOCATION) {
|
|
109
|
+
if (resultCode == Activity.RESULT_OK)
|
|
110
|
+
connectBluetoothDevice(savedCallbackForPermissionResult)
|
|
111
|
+
else
|
|
112
|
+
savedCallbackForPermissionResult.success(false)
|
|
113
|
+
return true
|
|
55
114
|
}
|
|
56
|
-
|
|
115
|
+
return false
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
fun isBluetoothSettingsReady(activity: Activity): Boolean {
|
|
119
|
+
deniedBluetoothPermissions()?.let {
|
|
57
120
|
requestPermissions(activity, it, BLE_ACCESS_PERMISSION)
|
|
58
121
|
return false
|
|
59
122
|
}
|
|
60
123
|
if (!isBluetoothEnabled(activity)) {
|
|
61
|
-
|
|
124
|
+
requestEnableBluetooth(activity)
|
|
125
|
+
return false
|
|
126
|
+
}
|
|
127
|
+
if (!isLocationServiceEnabled(activity)) {
|
|
128
|
+
requestEnableLocationService(activity)
|
|
62
129
|
return false
|
|
63
130
|
}
|
|
64
131
|
return true
|
|
65
132
|
}
|
|
66
133
|
|
|
67
|
-
fun deniedBluetoothPermissions(
|
|
134
|
+
fun deniedBluetoothPermissions(): Array<String>? {
|
|
68
135
|
val result = mutableListOf<String>()
|
|
69
136
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
70
|
-
result.addAll(deniedBluetoothPermission(
|
|
71
|
-
result.addAll(deniedBluetoothPermission(
|
|
137
|
+
result.addAll(deniedBluetoothPermission(BLUETOOTH_SCAN))
|
|
138
|
+
result.addAll(deniedBluetoothPermission(BLUETOOTH_CONNECT))
|
|
72
139
|
} else
|
|
73
|
-
result.addAll(deniedBluetoothPermission(
|
|
140
|
+
result.addAll(deniedBluetoothPermission(ACCESS_FINE_LOCATION))
|
|
74
141
|
return result.let { if (it.size > 0) it.toTypedArray() else null }
|
|
75
142
|
}
|
|
76
143
|
|
|
77
|
-
fun deniedBluetoothPermission(
|
|
78
|
-
|
|
79
|
-
permission: String
|
|
80
|
-
): Array<String> {
|
|
81
|
-
if (checkSelfPermission(activity, permission) != PERMISSION_GRANTED)
|
|
144
|
+
fun deniedBluetoothPermission(permission: String): Array<String> {
|
|
145
|
+
if (checkSelfPermission(context, permission) != PERMISSION_GRANTED)
|
|
82
146
|
return arrayOf(permission)
|
|
83
147
|
return arrayOf()
|
|
84
148
|
}
|
|
85
149
|
|
|
86
|
-
fun
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
onReady: () -> Unit
|
|
91
|
-
) {
|
|
92
|
-
val bleIntent = Intent(activity, RegulaBleService::class.java)
|
|
93
|
-
activity.startService(bleIntent)
|
|
94
|
-
|
|
95
|
-
activity.bindService(bleIntent, object : ServiceConnection {
|
|
96
|
-
override fun onServiceConnected(name: ComponentName, service: IBinder) {
|
|
97
|
-
bleManager = (service as RegulaBleService.LocalBinder).service.bleManager
|
|
98
|
-
val isBleManagerConnected = bleManager?.isConnected == true
|
|
99
|
-
onConnected(isBleManagerConnected)
|
|
100
|
-
if (!isBleManagerConnected) {
|
|
101
|
-
bleManager?.addCallback(object : BleWrapperCallback() {
|
|
102
|
-
override fun onDeviceReady() {
|
|
103
|
-
bleManager!!.removeCallback(this)
|
|
104
|
-
onReady()
|
|
105
|
-
}
|
|
106
|
-
})
|
|
107
|
-
}
|
|
108
|
-
}
|
|
150
|
+
fun requestEnableBluetooth(activity: Activity) {
|
|
151
|
+
val enableIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
|
|
152
|
+
startActivityForResult(activity, enableIntent, INTENT_REQUEST_ENABLE_BLUETOOTH)
|
|
153
|
+
}
|
|
109
154
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
155
|
+
fun requestEnableLocationService(activity: Activity) {
|
|
156
|
+
val myIntent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
|
|
157
|
+
startActivityForResult(activity, myIntent, INTENT_REQUEST_ENABLE_LOCATION)
|
|
158
|
+
}
|