android系统如何管理连接到有界远程服务的客户端列表
Posted
技术标签:
【中文标题】android系统如何管理连接到有界远程服务的客户端列表【英文标题】:How android system manages list of connected clients to a bounded remote service 【发布时间】:2014-08-08 16:01:44 【问题描述】:我正在做一个项目,对安卓手机上的系统进行实时分析。我想知道在给定时间点有多少客户端绑定到任何远程服务。
例如:绑定到 LocationManager 服务的客户端数。
这将帮助我识别对系统服务施加压力的应用程序。它还将帮助我识别是系统服务编写得不好还是系统服务的客户端表现不佳。
例如:我发现当您不断查询/更新/删除联系人内容提供者时,系统显示 com.android.acore 正在消耗更多 cpu,但实际上它是表现不佳的第三方应用程序。
我正在开发自定义 ROM,并且可以访问代码以进行任何修改。
我知道活页夹是引用计数的,并且每个引用活页夹的 BinderProxy 构成对该活页夹的引用。但我不确定它是如何在代码中完成的。
如果有人已经对此进行了一些研究,请分享您的知识。
【问题讨论】:
【参考方案1】:发现有一个 ServiceRecord 类维护与服务相关的所有信息。refer-http://androidxref.com/4.4.4_r1/xref/frameworks/base/services/java/com/android/server/am/ServiceRecord.java
部分字段如下:
// all information about the service.
final ApplicationInfo appInfo;
// information about service's app.
final int userId; // user that this service is running as
final String packageName; // the package implementing intent's component
final String processName; // process where this component wants to run
final String permission;// permission needed to access service
final String baseDir; // where activity source (resources etc) located
final String resDir; // where public activity source (public resources etc) located
final String dataDir; // where activity data should go
final boolean exported; // from ServiceInfo.exported
final Runnable restarter; // used to schedule retries of starting the service
final long createTime; // when this service was created
final ArrayMap<Intent.FilterComparison, IntentBindRecord> bindings
= new ArrayMap<Intent.FilterComparison, IntentBindRecord>();
// All active bindings to the service.
final ArrayMap<IBinder, ArrayList<ConnectionRecord>> connections
= new ArrayMap<IBinder, ArrayList<ConnectionRecord>>();
// IBinder -> ConnectionRecord of all bound clients
ProcessRecord app; // where this service is running or null.
ProcessRecord isolatedProc; // keep track of isolated process, if requested
ProcessStats.ServiceState tracker; // tracking service execution, may be null
ProcessStats.ServiceState restartTracker; // tracking service restart
boolean delayed; // are we waiting to start this service in the background?
boolean isForeground; // is service currently in foreground mode?
int foregroundId; // Notification ID of last foreground req.
Notification foregroundNoti; // Notification record of foreground state.
long lastActivity; // last time there was some activity on the service.
long startingBgTimeout; // time at which we scheduled this for a delayed start.
boolean startRequested; // someone explicitly called start?
boolean delayedStop; // service has been stopped but is in a delayed start?
boolean stopIfKilled; // last onStart() said to stop if service killed?
boolean callStart; // last onStart() has asked to alway be called on restart.
int executeNesting; // number of outstanding operations keeping foreground.
boolean executeFg; // should we be executing in the foreground?
long executingStart; // start time of last execute request.
boolean createdFromFg; // was this service last created due to a foreground process call?
int crashCount; // number of times proc has crashed with service running
int totalRestartCount; // number of times we have had to restart.
int restartCount; // number of restarts performed in a row.
long restartDelay; // delay until next restart attempt.
long restartTime; // time of last restart.
long nextRestartTime; // time when restartDelay will expire.
String stringName; // caching of toString
private int lastStartId; // identifier of most recent start request.
【讨论】:
以上是关于android系统如何管理连接到有界远程服务的客户端列表的主要内容,如果未能解决你的问题,请参考以下文章