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

fix: Bluetooth Scan #2613

Merged
merged 2 commits into from
Jan 18, 2025
Merged

fix: Bluetooth Scan #2613

merged 2 commits into from
Jan 18, 2025

Conversation

AsCress
Copy link
Collaborator

@AsCress AsCress commented Jan 17, 2025

Fixes #2611

Changes

  • Adds the required permissions and permission checks for Bluetooth scan and connections.

Screenshots / Recordings

Screen_recording_20250117_222604.webm

Checklist:

  • No hard coding: I have used resources from strings.xml, dimens.xml and colors.xml without hard coding any value.
  • No end of file edits: No modifications done at end of resource files strings.xml, dimens.xml or colors.xml.
  • Code reformatting: I have reformatted code and fixed indentation in every file included in this pull request.
  • No extra space: My code does not contain any extra lines or extra spaces than the ones that are necessary.

Summary by Sourcery

Add Bluetooth permissions and checks for scanning and connections.

Bug Fixes:

  • Fix Bluetooth scanning issues.

Enhancements:

  • Improve Bluetooth device connection handling.

@AsCress AsCress added the Fix Solution to an existing issue in app label Jan 17, 2025
@AsCress AsCress self-assigned this Jan 17, 2025
Copy link

sourcery-ai bot commented Jan 17, 2025

Reviewer's Guide by Sourcery

This pull request adds the necessary permissions and permission checks for Bluetooth scanning and connections. It ensures that the app requests and verifies the required Bluetooth permissions before performing any Bluetooth-related operations, enhancing the app's stability and user experience.

Sequence diagram for Bluetooth scan and permission flow

sequenceDiagram
    participant User as User
    participant App as BluetoothScanFragment
    participant Permission as PSLabPermission
    participant System as Android System

    User->>App: Initiate Bluetooth scan
    App->>Permission: checkPermissions(BLUETOOTH_PERMISSION)
    Permission->>System: Check BLUETOOTH permissions
    alt Permissions not granted
        System-->>Permission: Permission denied
        Permission->>System: Request permissions
        System->>User: Show permission dialog
        User->>System: Grant permissions
        System-->>App: Permissions granted
    else Permissions already granted
        System-->>Permission: Permissions granted
        Permission-->>App: Permissions OK
    end
    App->>System: Start Bluetooth discovery
    System-->>App: Return discovered devices
    App->>App: Update device list
Loading

Class diagram for PSLabPermission changes

classDiagram
    class PSLabPermission {
        -String[] allPermissions
        -String[] csvPermissions
        -String[] logPermissions
        -String[] mapPermissions
        +String[] bluetoothPermission
        +List~String~ listPermissionsNeeded
        +static final int BLUETOOTH_PERMISSION
        +static PSLabPermission getInstance()
        +boolean checkPermissions(Activity, int)
    }
    note for PSLabPermission "Added new bluetoothPermission array and BLUETOOTH_PERMISSION constant"
Loading

State diagram for Bluetooth scan process

stateDiagram-v2
    [*] --> CheckPermissions
    CheckPermissions --> RequestPermissions: Permissions not granted
    CheckPermissions --> StartScan: Permissions granted
    RequestPermissions --> StartScan: User grants permissions
    RequestPermissions --> [*]: User denies permissions
    StartScan --> Scanning
    Scanning --> DeviceFound: Device discovered
    Scanning --> StopScan: User stops scan
    DeviceFound --> ConnectDevice: User selects device
    StopScan --> [*]
    ConnectDevice --> [*]
Loading

File-Level Changes

Change Details Files
Added Bluetooth permissions to the manifest.
  • Added BLUETOOTH permission.
  • Added BLUETOOTH_ADMIN permission.
  • Added BLUETOOTH_CONNECT permission.
  • Added BLUETOOTH_SCAN permission.
app/src/main/AndroidManifest.xml
Implemented permission checks before initiating Bluetooth scan.
  • Added permission check before starting Bluetooth discovery.
  • Added permission check before canceling Bluetooth discovery.
  • Added permission check before creating a socket.
app/src/main/java/io/pslab/fragment/BluetoothScanFragment.java
Added Bluetooth permissions to the permission check class.
  • Added BLUETOOTH, BLUETOOTH_ADMIN, BLUETOOTH_SCAN, and BLUETOOTH_CONNECT permissions to the bluetooth permission array.
  • Added BLUETOOTH_PERMISSION to the permission request codes.
  • Added a permission request for BLUETOOTH_SCAN.
app/src/main/java/io/pslab/others/PSLabPermission.java
Request Bluetooth permissions on HomeFragment.
  • Added a call to check for bluetooth permissions.
app/src/main/java/io/pslab/fragment/HomeFragment.java

Assessment against linked issues

Issue Objective Addressed Explanation
#2611 Fix the app crash when Bluetooth scan is started on Android 13
#2611 Add necessary Bluetooth permissions for Android 13 compatibility
#2611 Implement proper permission checks before Bluetooth operations

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @AsCress - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • The permission check logic appears to be inverted - devices are only added when permission is NOT granted (link)

Overall Comments:

  • The Bluetooth permission check logic in BluetoothScanFragment.java is inverted - devices are only added when permission is NOT granted. This condition needs to be fixed.
  • Empty else blocks with /**/ comments should properly handle permission denied cases and provide user feedback, rather than silently failing.
Here's what I looked at during the review
  • 🔴 General issues: 1 blocking issue, 1 other issue
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

github-actions bot commented Jan 17, 2025

@marcnause marcnause merged commit 0acdb1b into fossasia:development Jan 18, 2025
4 checks passed
@AsCress AsCress deleted the issue2611 branch February 11, 2025 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Solution to an existing issue in app
Projects
None yet
Development

Successfully merging this pull request may close these issues.

App crashes when Bluetooth scan is started
3 participants