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

完成作业 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

simplezhli
Copy link

@simplezhli simplezhli commented Feb 8, 2019

极客时间账号:13571883375

实现原理:

根据老师提供的提示信息,动态代理对应的Service实现,核心代码:

Object oldObj = mHostContext.getSystemService(Context.XXX_SERVICE);
Class<?> clazz = oldObj.getClass();
Field field = clazz.getDeclaredField("mService");
 field.setAccessible(true);

final Object mService = field.get(oldObj);
setProxyObj(mService);

Object newObj = Proxy.newProxyInstance(this.getClass().getClassLoader(), mService.getClass().getInterfaces(), this);
field.set(oldObj, newObj);

写了几个调用方法去触发,通过判断对应的方法名来做堆栈信息的输出。

不足之处:

1.可能兼容性上不是特别完善(期待老师的标准答案)。

2.没有按照耗电监控的规则去做一些业务处理。

心得体会:

1.本身并不复杂,只是为了找到hook点,看了对应的Service源码耗费了一定时间,对于它们的工作流程有了更深的认识。

2.平时也很少使用动态代理,这回查漏补缺,一次用了个爽。

@yueshao6800
Copy link

学习了

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.

2 participants