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

Feature Request: Add restart_adb_server() Function to Simplify ADB Server Restart #102

Closed
songyuc opened this issue Jan 15, 2024 · 10 comments

Comments

@songyuc
Copy link

songyuc commented Jan 15, 2024

Feature Description

I would like to propose the addition of a new function, restart_adb_server(), to the adbutils library. This function would encapsulate the functionality to restart the Android Debug Bridge (ADB) server, making it more convenient for developers to perform this common task.

Rationale

Currently, restarting the ADB server requires calling two separate functions: kill_server() and start_server(). While this is effective, it can be more streamlined. Implementing a restart_adb_server() function would simplify the code needed to restart the ADB server, making the process more efficient and user-friendly.

Proposed Implementation

The restart_adb_server() function could internally call the existing kill_server() and start_server() functions. This would encapsulate the restart logic within a single, easy-to-use function. Here's a rough implementation idea:

def restart_adb_server():
    kill_server()
    start_server()

Potential Benefits

  • Simplicity: Provides a straightforward way to restart the ADB server.
  • Convenience: Saves time for developers who frequently restart the ADB server during development.
  • Code Cleanliness: Reduces the need for repetitive code in projects that use adbutils.

Conclusion

I believe that adding this function would be a valuable enhancement to the adbutils library, making it more convenient for developers working with Android devices. I look forward to hearing your thoughts on this suggestion. Thank you for considering this feature request.

Best regards,
Yucheng Song

@codeskyblue
Copy link
Member

可以啊,提个pr呗

@songyuc
Copy link
Author

songyuc commented Jan 17, 2024

尊敬的@codeskyblue,

我考虑将这个函数放在代码库中adb.device()函数之前,具体的位置是 adbutils/init.py#L66
您认为这样的安排是否符合库的结构和设计理念?
对于在adbutils库中放置这个函数的最佳位置,非常欢迎任何反馈或建议。

感谢您的时间和支持。

@codeskyblue
Copy link
Member

Lgtm

@songyuc
Copy link
Author

songyuc commented Jan 18, 2024

您好,
函数的实现如下:

def restart_adb_server():
    try:
        # 停止ADB服务
        subprocess.run(["adb", "kill-server"], check=True)
        # 启动ADB服务
        subprocess.run(["adb", "start-server"], check=True)

    except subprocess.CalledProcessError as e:
        print(f"执行ADB命令时出错:{e}")

您看,这样的实现可以吗

@codeskyblue
Copy link
Member

不要用subprocess

@songyuc
Copy link
Author

songyuc commented Jan 19, 2024

您好@codeskyblue

关于 restart_adb_server() 函数的实现,我希望能遵循您提出的不使用 subprocess 的建议。我想请教您是否推荐使用其他Python标准库,如 ossignal,通过发送信号的方式来控制ADB进程,以实现其重启?或者,您是否有其他更好的实现建议?由于我是Android测试的初学者,任何建议都将对我帮助巨大。

期待您的回复,非常感谢您在这个项目中的帮助!

诚挚地,
songyuc

@codeskyblue
Copy link
Member

这尼玛,GPT机器人吗?

@songyuc
Copy link
Author

songyuc commented Jan 22, 2024

老师,您好,我不是机器人,我是华科的一名学生哈

@LiJiaHeer
Copy link

哈哈哈哈哈哈笑死了 谢谢Yucheng Song

@codeskyblue
Copy link
Member

直接提pr好了,不要一直留言了

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

No branches or pull requests

3 participants