当前位置:网站首页>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);
}
边栏推荐
- Impact relay zc-23/dc220v
- 日志 logrus第三方库的使用
- 用Steam教育启发学生多元化思维
- Pre training / transfer learning of models
- Technical personnel advanced to draw a big picture of business, hand-in-hand teaching is coming
- 06. on several ways of redis persistence
- 解析融合学科本质的创客教育路径
- StrictMode分析Activity泄漏-StrictMode原理(3)
- C语言一点点(未来可会增加)
- 孔乙己第一问之服务通信知多少?
猜你喜欢
K210工地安全帽
K210 site helmet
Analyze the maker education path integrating the essence of discipline
解析融合学科本质的创客教育路径
Pre training / transfer learning of models
分割链表[先取next再斩断链表防止断链]
Koa koa combine routes sub route management
"Open math input panel" in MathType editing in win11 is gray and cannot be edited
日志 logrus第三方库的使用
gin 配置文件
随机推荐
探索互联网时代STEAM教育创新之路
解读创客教育所蕴含的科技素养
Chromatic judgement bipartite graph
软硬件基础知识学习--小日记(1)
冲击继电器ZC-23/DC220V
闭锁继电器YDB-100、100V
【模拟】922. Sort Array By Parity II
[go] go implements row column conversion of sets
Open3D 点云颜色渲染
gin 配置文件
Call the classic architecture and build the model based on the classic
DX-11Q信号继电器
生意和投资的思考
[leetcode] sum of two numbers [1]
蒹葭苍苍,白露为霜。
孙宇晨接受瑞士媒体Bilan采访:熊市不会持续太久
[network packet loss and network delay? This artifact can help you deal with everything!]
StrictMode带来的思考-StrictMode原理(5)
(learning power + thinking power) x action power, summary of flywheel effect on the growth of technicians
For the first time in more than 20 years! CVPR best student thesis awarded to Chinese college students!