当前位置:网站首页>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);
}
边栏推荐
- flutter报错 -- The argument type ‘Function‘ can‘t be assigned to the parameter type ‘void Function()?‘
- Analyzing the wisdom principle in maker education practice
- 图的连通性基础
- 【模拟】922. Sort Array By Parity II
- Interpreting the scientific and technological literacy contained in maker Education
- 解析融合学科本质的创客教育路径
- User defined annotation implementation verification
- DLS-42/6-4 DC110V双位置继电器
- Why not two or four TCP handshakes
- Pre training / transfer learning of models
猜你喜欢

Use of typora

Pre training / transfer learning of models

One of the basics - overview of sta Basics
![Parity linked list [two general directions of linked list operation]](/img/4e/ce860bc172bb75f456427ba26a7842.png)
Parity linked list [two general directions of linked list operation]

双位置继电器ST2-2L/AC220V

Note d'étude du DC: zéro dans le chapitre officiel - - Aperçu et introduction du processus de base

【qt5-tab标签精讲】Tab标签及内容分层解析

qt5-MVC:数据可视化的层次揭秘

DX-11Q信号继电器

DLS-42/6-4 DC110V双位置继电器
随机推荐
【栈】921. Minimum Add to Make Parentheses Valid
Interpreting the scientific and technological literacy contained in maker Education
Visual studio 2019 shortcut notes
Win11安装redis 数据库以及redis desktop manager的下载
Opencv basic operation 2 realizes label2rgb and converts gray-scale images into color images
User defined annotation implementation verification
使用StrictMode-StrictMode原理(1)
Impact relay zc-23/dc220v
Split the linked list [take next first and then cut the linked list to prevent chain breakage]
闭锁继电器YDB-100、100V
K210门禁毕设
Dls-20 double position relay 220VDC
文件服务设计
sort自定义函数
[leetcode] climb stairs [70]
技术人进阶画业务大图,手把手教学来了
neo4j安装、运行以及项目的构建和功能实现
Training discipline principle of robot programming
1175. Prime Arrangements
The liquor and tourism sector recovers, and Yaduo continues to dream of listing. How far is it from "the first share of the new accommodation economy"?