Skip to content

Conversation

@pengfeixx
Copy link
Contributor

@pengfeixx pengfeixx commented Sep 25, 2025

Fix the issue of the storage message click having no effect

Log: Fix the issue of the storage message click having no effect
pms: BUG-333027

Summary by Sourcery

Improve notification interaction in the OBEX agent by converting the requestNotifyCh channel from bool to string, mapping notification action clicks to explicit "receive", "decline", and "obex_cancel" reasons, and adjusting the handler to properly respond to each case. Also increase the file receive notification timeout to 40 seconds.

Bug Fixes:

  • Trigger file receive or decline logic based on notification clicks by sending distinct string reasons instead of a boolean flag.
  • Treat OBEX-induced cancel events as timeouts to restore transportability and send a timeout notification.

Enhancements:

  • Increase the user notification click timeout for incoming file transfers from 15s to 40s.

@sourcery-ai
Copy link

sourcery-ai bot commented Sep 25, 2025

Reviewer's Guide

This PR refactors the OBEX agent’s notification handling by replacing the boolean channel with a string-based one to distinguish user actions and cancel events, extends the notification timeout, and updates the requestReceive logic to handle clicks and cancels correctly.

Sequence diagram for updated requestReceive notification handling

sequenceDiagram
participant "User"
participant "obexAgent"
participant "notify"

User->>notify: Clicks notification ("receive" or "decline")
notify->>obexAgent: ConnectActionInvoked(actionKey)
obexAgent->>obexAgent: requestNotifyCh <- "receive" or "decline"
obexAgent->>obexAgent: select on requestNotifyCh
alt actionKey == "receive"
  obexAgent->>obexAgent: result = true
else actionKey == "decline"
  obexAgent->>obexAgent: result = false
end
Loading

File-Level Changes

Change Details Files
Extended the file receive notification timeout
  • Increased receiveFileNotifyTimeout from 151000 to 401000
bluetooth1/obex_agent.go
Replaced boolean channel with string channel for request notifications
  • Changed requestNotifyCh type from chan bool to chan string
  • Reinitialized requestNotifyCh as chan string in requestReceive
bluetooth1/obex_agent.go
Mark cancel events explicitly
  • Updated Cancel() to send “obex_cancel” instead of false
bluetooth1/obex_agent.go
Differentiate receive and decline actions
  • Notify channel with “receive” or “decline” based on actionKey
  • Ensure decline does not trigger timeout notification
bluetooth1/obex_agent.go
Handle string-based reasons in requestReceive select
  • Treat “obex_cancel” as timeout and send timeout notify
  • Handle “decline” by resetting transportable without timeout notify
  • Return true only for “receive” events
bluetooth1/obex_agent.go

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. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the 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 exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

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

@deepin-ci-robot
Copy link

deepin pr auto review

我对这段代码进行了仔细审查,以下是我的分析和改进建议:

1. 语法逻辑

  • 代码逻辑基本正确,但有几个地方可以改进:
    • requestReceive函数中,将chan bool改为chan string是一个好的改进,因为它提供了更明确的语义。
    • 对不同情况的处理(取消、拒绝、接收)使用明确的字符串标识符,提高了代码可读性。

2. 代码质量

  • 优点:

    • 使用了互斥锁(requestNotifyChMu)来保护共享通道,避免了竞态条件。
    • 使用了有缓冲的通道(容量为10),提高了并发性能。
  • 改进建议:

    • 可以考虑将字符串常量("obex_cancel", "decline", "receive")定义为常量或枚举,以提高代码可维护性。
    • Cancel函数中,添加了对requestNotifyCh是否为nil的检查,避免可能的panic。

3. 代码性能

  • 优点:

    • 使用通道进行通知是高效的并发通信方式。
    • 设置了合理的超时时间(40秒),避免了无限等待。
  • 改进建议:

    • 可以考虑使用context.Context替代通道和超时机制,这样可以更灵活地控制取消和超时。
    • 在高频操作场景下,可以考虑使用对象池来重用通道,减少内存分配开销。

4. 代码安全

  • 优点:

    • 正确使用了互斥锁保护共享资源。
    • 对DBus错误进行了适当的处理和转换。
  • 改进建议:

    • 在通道操作中添加超时保护,防止在某些异常情况下导致goroutine永久阻塞。
    • 考虑添加通道关闭后的处理逻辑,避免向已关闭的通道发送数据导致panic。
    • 可以添加更多的错误检查和日志记录,便于问题排查。

具体改进建议代码:

// 定义常量提高可维护性
const (
    ActionObexCancel = "obex_cancel"
    ActionDecline    = "decline"
    ActionReceive    = "receive"
)

func (a *obexAgent) Cancel() *dbus.Error {
    a.requestNotifyChMu.Lock()
    defer a.requestNotifyChMu.Unlock()
    
    if a.requestNotifyCh == nil {
        return nil
    }
    
    // 添加超时保护
    select {
    case a.requestNotifyCh <- ActionObexCancel:
    case <-time.After(100 * time.Millisecond):
        logger.Warning("Failed to send cancel notification, channel might be blocked")
    }
    return nil
}

func (a *obexAgent) requestReceive(deviceName, filename string) (bool, error) {
    // ... 其他代码 ...

    a.requestNotifyChMu.Lock()
    // 使用对象池或重用通道
    if a.requestNotifyCh == nil {
        a.requestNotifyCh = make(chan string, 10)
    } else {
        // 清空通道中的旧数据
        for len(a.requestNotifyCh) > 0 {
            <-a.requestNotifyCh
        }
    }
    a.requestNotifyChMu.Unlock()

    // ... 其他代码 ...

    var result bool
    select {
    case reason := <-a.requestNotifyCh:
        switch reason {
        case ActionObexCancel:
            // cancel from obexd, treat as timeout notify
            a.b.setPropTransportable(true)
            a.notifyReceiveFileTimeout(notify, notifyID, filename)
            result = false
        case ActionDecline:
            // user declined, do not send timeout notify
            a.b.setPropTransportable(true)
            result = false
        case ActionReceive:
            result = true
        default:
            logger.Warningf("Unknown action received: %s", reason)
            result = false
        }
    case <-time.After(receiveFileTimeout):
        a.b.setPropTransportable(true)
        // ... 超时处理 ...
    }
    
    // 清理资源
    a.requestNotifyChMu.Lock()
    close(a.requestNotifyCh)
    a.requestNotifyCh = nil
    a.requestNotifyChMu.Unlock()
    
    return result, nil
}

这些改进提高了代码的可维护性、安全性和性能,同时保持了原有的功能完整性。

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 there - I've reviewed your changes and they look great!


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.

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Sep 25, 2025

TAG Bot

New tag: 6.1.57
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #920

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Oct 10, 2025

TAG Bot

New tag: 6.1.58
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #924

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Oct 16, 2025

TAG Bot

New tag: 6.1.59
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #934

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fly602, pengfeixx

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants