android adb杀死服务,Android app是如何杀掉的

1. adb shell kill -9 pid_of_app

AMS定义了AppDeathRecipient

APP 在 attachApplication -> attachApplicationLocked

AMS里会注册 App 进程的 BinderDeath通知

AppDeathRecipient adr = new AppDeathRecipient(app, pid, thread);

thread.asBinder().linkToDeath(adr, 0);

当App进程被杀了后

binder里的 binder_fops就会调用

binder_release -> binder_deferred_func -> binder_deferred_release

-> BINDER_WORK_DEAD_BINDER(binder_thread_read) -> BR_DEAD_BINDER(binder_thread_read) -> BR_DEAD_BINDER(IPCThreadState::executeCommand)

-> (BpBinder->sendObituary) -> (BpBinder->reportOneDeath) -> (JavaDeathRecipient->binderDied)

-> BinderProxy.sendDeathNotice

-> ActivityManagerService.binderDied -> appDiedLocked -> handleAppDiedLocked 清理相关资源 resumeFocusedStackTopActivityLocked

注意,这种方式kill掉的进程不会调用 onDestroy

1180886b3ff3

link to death

2. 通过Recents里removeTasks杀掉进程

AMS.removeTask -> ASS.removeTaskByIdLocked ->

TaskRecord.removeTaskActivitiesLocked -> 这里面会去finish掉当前Activity, 也就是会调用onDestroy

ASS.cleanUpRemovedTaskLocked -> ProcessRecord.kill ->

Process.killProcessQuiet -> sendSignalQuiet -> kill -9 pid (类似于kill -9)

Process.killProcessGroup -> killProcessGroup

后面的过程的1一样,通过binder death去通知AMS

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值