当前位置:网站首页>Strictmode analysis registration strictmode principle (4)
Strictmode analysis registration strictmode principle (4)
2022-07-01 01:28:00 【Strange uncle Lori Kong】
4. Registion Leakage problem of
there Registion There are two main types , Namely Service、BroadCastReceiver:
4.2 Test timing
Here is a pre knowledge point ,stopService The process of :
Context.stopSerivce -> ActivityThread.STOP_SERVICE -> ActivityThread.scheduleContextCleanup() -> LoadApk.removeContextRegistrations
The testing time we need , stay removeContextRegistrations, There are two member variables used :
// according to context, To store the current broadcast and broadcast distributor
private final ArrayMap<Context, ArrayMap<BroadcastReceiver, ReceiverDispatcher>> mReceivers
= new ArrayMap<>();
// according to context, To store service as well as service The dispenser of
private final ArrayMap<Context, ArrayMap<ServiceConnection, LoadedApk.ServiceDispatcher>> mServices
= new ArrayMap<>();
public void removeContextRegistrations(Context context,
String who, String what) {
// Whether the registration leak is enabled
final boolean reportRegistrationLeaks = StrictMode.vmRegistrationLeaksEnabled();
synchronized (mReceivers) {
// Get and current context same map
ArrayMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher> rmap =
mReceivers.remove(context);
if (rmap != null) {
// analysis receiver Leakage of
for (int i = 0; i < rmap.size(); i++) {
LoadedApk.ReceiverDispatcher rd = rmap.valueAt(i);
IntentReceiverLeaked leak = new IntentReceiverLeaked(
what + " " + who + " has leaked IntentReceiver "
+ rd.getIntentReceiver() + " that was " +
"originally registered here. Are you missing a " +
"call to unregisterReceiver()?");
leak.setStackTrace(rd.getLocation().getStackTrace());
Slog.e(ActivityThread.TAG, leak.getMessage(), leak);
if (reportRegistrationLeaks) {
StrictMode.onIntentReceiverLeaked(leak);
}
try {
ActivityManager.getService().unregisterReceiver(
rd.getIIntentReceiver());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
}
mUnregisteredReceivers.remove(context);
}
synchronized (mServices) {
//Slog.i(TAG, "Receiver registrations: " + mReceivers);
// Remove current stop Of service, And return to the current service by key Of map
ArrayMap<ServiceConnection, LoadedApk.ServiceDispatcher> smap =
mServices.remove(context);
if (smap != null) {
// analysis service Leakage of
for (int i = 0; i < smap.size(); i++) {
LoadedApk.ServiceDispatcher sd = smap.valueAt(i);
ServiceConnectionLeaked leak = new ServiceConnectionLeaked(
what + " " + who + " has leaked ServiceConnection "
+ sd.getServiceConnection() + " that was originally bound here");
leak.setStackTrace(sd.getLocation().getStackTrace());
Slog.e(ActivityThread.TAG, leak.getMessage(), leak);
if (reportRegistrationLeaks) {
StrictMode.onServiceConnectionLeaked(leak);
}
try {
ActivityManager.getService().unbindService(
sd.getIServiceConnection());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
sd.doForget();
}
}
mUnboundServices.remove(context);
//Slog.i(TAG, "Service registrations: " + mServices);
}
边栏推荐
- 【网络丢包,网络延迟?这款神器帮你搞定所有!】
- 【office办公-pdf篇】pdf合并与拆分让我们摆脱付费软件的功能限制好不好
- TypeError: Argument ‘angle‘ can not be treated as a double
- 06. on several ways of redis persistence
- 蒹葭苍苍,白露为霜。
- Open3D 点云包围盒
- Green, green the reed. dew and frost gleam.
- WIN11中MathType编辑中“打开数学输入面板”是灰色不可编辑
- "Open math input panel" in MathType editing in win11 is gray and cannot be edited
- Training discipline principle of robot programming
猜你喜欢
随机推荐
【Qt5-基础篇_1】从0开始,德天老师和你一起学习——窗口简介
ESP8266 RC522
流批一体在京东的探索与实践
[learning notes] simple DP
文件服务设计
visual studio 2019 下载
OCR的一些项目
MFC TCP通信服务端客户端Demo备忘vs2019
解析融合学科本质的创客教育路径
MFC TCP communication server client demo notes vs2019
visual studio 2019 快捷键备忘
【学习笔记】简单dp
TypeError: Argument ‘angle‘ can not be treated as a double
Solve idea:class' xxx 'not found in module' xxx‘
【网络丢包,网络延迟?这款神器帮你搞定所有!】
js中把数字转换成汉字输出
Analyze the maker education path integrating the essence of discipline
One of the basics - overview of sta Basics
使用StrictMode-StrictMode原理(1)
蒹葭苍苍,白露为霜。





![奇偶链表[链表操作的两种大方向]](/img/4e/ce860bc172bb75f456427ba26a7842.png)



