Skip to content
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

CI and improvements on Bluetooth errors #10

Merged
merged 17 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Build lint checker report and unit tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Java JDK
uses: actions/setup-java@v3
with:
java-version: "18"
distribution: "temurin"

- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1

- name: lint
uses: gradle/gradle-build-action@v2
with:
arguments: lintDebug
build-root-directory: ./

test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Java JDK
uses: actions/setup-java@v3
with:
java-version: "18"
distribution: "temurin"

- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1

- name: test
uses: gradle/gradle-build-action@v2
with:
arguments: test
build-root-directory: ./
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions WalletSdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ android {

dependencies {
api("com.spruceid.wallet.sdk.rs:walletsdkrs:0.0.25")
//noinspection GradleCompatible
implementation("com.android.support:appcompat-v7:28.0.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("com.android.support.test:runner:1.0.2")
Expand Down
11 changes: 11 additions & 0 deletions WalletSdk/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission
android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30" />
<uses-permission
android:name="android.permission.BLUETOOTH_ADMIN"
android:maxSdkVersion="30" />
<!-- Needed only if your app looks for Bluetooth devices. -->
<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-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />

</manifest>
30 changes: 18 additions & 12 deletions WalletSdk/src/main/java/com/spruceid/wallet/sdk/BleCentral.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ import android.content.Context
import android.content.Context.*
import android.content.pm.PackageManager
import android.os.Build
import android.os.Looper
import android.util.Log

class BleCentral(private var callback: BleCentralCallback,
private var serviceUUID: UUID,
bluetoothAdapter: BluetoothAdapter) {
class BleCentral(
private var callback: BleCentralCallback,
private var serviceUUID: UUID,
bluetoothAdapter: BluetoothAdapter
) {

private val bluetoothLeScanner = bluetoothAdapter.bluetoothLeScanner
private var scanning = false
private val handler = Handler()
private val handler = Handler(Looper.myLooper()!!)

// Limits scanning to 3 min - preserves battery life - ideally should be lower.
private val scanPeriod: Long = 180000
Expand Down Expand Up @@ -113,22 +117,24 @@ class BleCentral(private var callback: BleCentralCallback,
}
}
}
fun getPermissions(): List<String> {
var permissions = listOf(Manifest.permission.ACCESS_FINE_LOCATION)

fun getPermissions(): List<String> {
val permissions =
arrayListOf(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION)

/**
* The OS seems to omit certain permission requests like "BLUETOOTH" to the user depending
* on the OS version. Although, this does not cause an error it will create a dependency on
* a permission that can never be accepted.
*/
if (Build.VERSION.SDK_INT >= 31) {
permissions.plus(Manifest.permission.BLUETOOTH_SCAN)
permissions.plus(Manifest.permission.BLUETOOTH_ADVERTISE)
permissions.plus(Manifest.permission.BLUETOOTH_CONNECT)
permissions.add(Manifest.permission.BLUETOOTH_SCAN)
permissions.add(Manifest.permission.BLUETOOTH_ADVERTISE)
permissions.add(Manifest.permission.BLUETOOTH_CONNECT)
} else {
Manifest.permission.BLUETOOTH
Manifest.permission.BLUETOOTH_ADMIN
Manifest.permission.BLUETOOTH_PRIVILEGED
permissions.add(Manifest.permission.BLUETOOTH)
permissions.add(Manifest.permission.BLUETOOTH_ADMIN)
permissions.add(Manifest.permission.BLUETOOTH_PRIVILEGED)
}

return permissions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import java.util.UUID

class CredentialsViewModel : ViewModel() {

private val _credentials = MutableStateFlow<List<BaseCredential>>(listOf())
private val _credentials = MutableStateFlow<ArrayList<BaseCredential>>(arrayListOf())
val credentials = _credentials.asStateFlow()

private val _currState = MutableStateFlow(PresentmentState.UNINITIALIZED)
Expand All @@ -37,8 +37,8 @@ class CredentialsViewModel : ViewModel() {

private val _transport = MutableStateFlow<Transport?>(null)

fun storeCredental(credential: BaseCredential) {
_credentials.value = _credentials.value.plus(credential)
fun storeCredential(credential: BaseCredential) {
_credentials.value.add(credential)
}

fun toggleAllowedNamespace(docType: String, specName: String, fieldName: String) {
Expand Down
Loading
Loading