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

Do not normalize UUIDs on native side #138

Merged
merged 1 commit into from
Feb 16, 2025

Conversation

fotiDim
Copy link
Contributor

@fotiDim fotiDim commented Feb 15, 2025

PR Type

Bug fix, Enhancement


Description

  • Removed UUID normalization logic from both Android and iOS implementations.

  • Simplified UUID handling by directly using provided UUID strings.

  • Updated related methods to remove dependency on validFullUUID.


Changes walkthrough 📝

Relevant files
Enhancement
UniversalBleHelper.kt
Removed UUID normalization logic in Android helper             

android/src/main/kotlin/com/navideck/universal_ble/UniversalBleHelper.kt

  • Removed the validFullUUID function for UUID normalization.
  • Updated toUUIDList to directly use provided UUID strings.
  • +1/-9     
    UniversalBleHelper.swift
    Removed UUID normalization logic in iOS helper                     

    darwin/Classes/UniversalBleHelper.swift

  • Removed the validFullUUID extension for UUID normalization.
  • Simplified UUID handling by eliminating unnecessary logic.
  • +0/-14   
    Bug fix
    UniversalBlePlugin.swift
    Simplified UUID handling in iOS plugin                                     

    darwin/Classes/UniversalBlePlugin.swift

  • Updated UUID handling in onScanResult to directly use UUID strings.
  • Removed usage of validFullUUID in service UUID validation.
  • +2/-2     

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    UUID Validation

    The removal of UUID normalization may cause compatibility issues with devices that send short-form UUIDs. Verify that all connected BLE devices send full UUIDs.

    guard UUID(uuidString: serviceUUID) != nil else {
      throw PigeonError(code: "IllegalArgument", message: "Invalid service UUID:\(serviceUUID)", details: nil)
    Error Handling

    Direct UUID parsing without validation could throw IllegalArgumentException if invalid UUID string is provided. Consider adding error handling.

    return this.map { UUID.fromString(it) }

    @fotiDim fotiDim force-pushed the Do-not-normalize-UUIDs-on-native-side branch from d355c1e to c044706 Compare February 15, 2025 15:39
    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Add error handling for invalid UUIDs

    Add error handling for UUID validation before mapping services. The current code
    could crash if an invalid UUID is encountered.

    darwin/Classes/UniversalBlePlugin.swift [351]

    -services: services?.map { $0.uuidStr }
    +services: services?.compactMap { service in
    +  guard UUID(uuidString: service.uuidStr) != nil else { return nil }
    +  return service.uuidStr
    +}
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    __

    Why: The suggestion adds important error handling for invalid UUIDs that could cause runtime crashes. This is particularly relevant since the PR removes the UUID normalization logic.

    Medium
    Handle invalid UUID parsing errors

    Add try-catch block to handle potential IllegalArgumentException when parsing
    invalid UUIDs.

    android/src/main/kotlin/com/navideck/universal_ble/UniversalBleHelper.kt [77]

    -return this.map { UUID.fromString(it) }
    +return this.mapNotNull { uuid ->
    +  try {
    +    UUID.fromString(uuid)
    +  } catch (e: IllegalArgumentException) {
    +    null
    +  }
    +}
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    __

    Why: The suggestion adds critical error handling for UUID parsing that could throw IllegalArgumentException. This is especially important after removing the UUID validation function.

    Medium

    @fotiDim fotiDim merged commit 1525628 into main Feb 16, 2025
    1 check passed
    @fotiDim fotiDim deleted the Do-not-normalize-UUIDs-on-native-side branch February 16, 2025 11:03
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants