绕过华为register too many Broadcast Receivers限制

前言

一个普通的app撑死也不会注册500个广播接收,但是开发android沙盒就不一样了,在沙盒上要跑很多app,非常容易超过这个限制。因此我公开这个技术是很有必要的。

register too many Broadcast Receivers

如何解决

框架抛出的异常当然是逆向框架层然后patch啰,至于如何逆向第三方厂商rom的框架层,请参见我的文章:Android逆向之逆向框架层

我已经逆向完了,不喜欢啰嗦,直接上代码:

public static void patchHWLoadedApk(Context context) {

if(HWLoadedApk.Class!=null&& (context.getApplicationContext()instanceofApplication)) {

Object packageInfo = ContextImpl.mPackageInfo.get(((Application) context.getApplicationContext()).getBaseContext());

if(packageInfo !=null) {

Object receiverResource = HWLoadedApk.mReceiverResource.get(packageInfo);

if(receiverResource ==null) {

return;

}

if(ReceiverResourceM.Class!=null) {

if(ReceiverResourceM.Class.isAssignableFrom(receiverResource.getClass())) {

String[] whiteList =  ReceiverResourceM.mWhiteList.get(receiverResource);

List arrayList =newArrayList();

arrayList.add(context.getPackageName());

if(whiteList !=null) {

for(inti =0;i < whiteList.length;i ++) {

arrayList.add(whiteList[i]);

}

}

ReceiverResourceM.mWhiteList.set(receiverResource,(String[]) arrayList.toArray(newString[arrayList.size()]));

}

}else if(ReceiverResourceLP.Class!=null) {

ReceiverResourceLP.mResourceConfig.set(receiverResource, null);

}

}

}

}

你可能感兴趣的:(绕过华为register too many Broadcast Receivers限制)