杀死其他APP后台服务

1. 一开始是这样的,在反编译完美团外卖商家Android版后,我发现其中有一个杀死后台运行进程的权限

<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>

Android开发者官方文档描述如下:

Have the system immediately kill all background processes associated with the given package. This is the same as the kernel killing those processes to reclaim memory; the system will take care of restarting these processes in the future as needed.You must hold the permission KILL_BACKGROUND_PROCESSES to be able to call this method.


2. 看到这个权限后,第一感觉应该是美团为了保证自己App可以流畅运行而杀死后台长时间不运行的App,凭借着职业的敏感继续跟进,终于找到killBackgroundProcesses(String packageName)的调用处:
杀死其他APP后台服务_第1张图片
3. 从调用处看,美团并未使用很高深的技术来判断后台运行进程来选择杀死长期不运行的App,而是直接用Hardcode写死了四款App的包名,细心读了读包名,结果让我震惊
杀死其他APP后台服务_第2张图片这些熟悉的名字,每个都是美团的竞对。原来美团并不是为了让自己App运行更流畅而杀死别的App,而是直接封杀竞对的App。

4. 从上图看,调用killBackgroundProcesses(String packageName)方法的类名是FriendUtil,也就是美团字面上称竞对是朋友,然后背后捅一刀子。

看到这里,我点了根烟,陷入了深深的沉思(严肃脸)。这样大胆地用Hardcode封杀,给人的感觉怎么都像是小偷作完案还要在别人家里留张名片,不知道各位怎样看?


你可能感兴趣的:(杀死其他APP后台服务)