android4.0网络服务状态或者信号量强度上报过程(RIL Framework Java 部分)
2012-12-12 16:59
429 查看
网络服务状态或者网络信号量是通过Modem 主动上报信息来实现的,相关类有ServiceState,GsmServiceStateTracker,GSMPhone,TelephonyRegistry等。
1.比如现在所处的网络发生变化,RILReciver 收到上报信息,处理 RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED 信息。
case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED:
if (RILJ_LOGD) unsljLog(response);
mVoiceNetworkStateRegistrants
.notifyRegistrants(new AsyncResult(null, null, null));
break;
2.经分析 mVoiceNetworkStateRegistrants,是由 GsmServiceStateTracker 构造的。
public GsmServiceStateTracker(GSMPhone phone) {
...
cm.registerForVoiceNetworkStateChanged(this, EVENT_NETWORK_STATE_CHANGED, null);
...
}
3.消息交给 EVENT_NETWORK_STATE_CHANGED 处理。GsmServiceStateTracker 处理 EVENT_NETWORK_STATE_CHANGED 消息
case EVENT_NETWORK_STATE_CHANGED:
pollState();
break;
4.调用 pollState();
default:
// Issue all poll-related commands at once
// then count down the responses, which
// are allowed to arrive out-of-order
pollingContext[0]++;
cm.getOperator(
obtainMessage(
EVENT_POLL_STATE_OPERATOR, pollingContext));
pollingContext[0]++;
cm.getDataRegistrationState(
obtainMessage(
EVENT_POLL_STATE_GPRS, pollingContext));
pollingContext[0]++;
cm.getVoiceRegistrationState(
obtainMessage(
EVENT_POLL_STATE_REGISTRATION, pollingContext));
pollingContext[0]++;
cm.getNetworkSelectionMode(
obtainMessage(
EVENT_POLL_STATE_NETWORK_SELECTION_MODE, pollingContext));
5.再次向rild 发送消息,等待返回信息 ,信息返回后 GsmServiceStateTracker 处理 EVENT_POLL_STATE_OPERATOR,EVENT_POLL_STATE_GPRS,EVENT_POLL_STATE_REGISTRATION,EVENT_POLL_STATE_NETWORK_SELECTION_MODE
6. GsmServiceStateTracker最后调用 pollStateDone();
7.调用 phone.notifyServiceStateChanged(ss);
8.调用 phoneBase 的 notifyServiceStateChanged
protected void notifyServiceStateChangedP(ServiceState ss) {
AsyncResult ar = new AsyncResult(null, ss, null);
mServiceStateRegistrants.notifyRegistrants(ar);
mNotifier.notifyServiceState(this);
}
9.DefaultPhoneNotifier的 notifyServiceState(this);
10.public void notifyServiceState(Phone sender) {
ServiceState ss = sender.getServiceState();
if (ss == null) {
ss = new ServiceState();
ss.setStateOutOfService();
}
try {
mRegistry.notifyServiceState(ss);
} catch (RemoteException ex) {
// system process is dead
}
}
11. mRegistry 是 TelephonyRegistry.
12.调用 TelephonyRegistry的 notifyServiceState
public void notifyServiceState(ServiceState state) {
if (!checkNotifyPermission("notifyServiceState()")){
return;
}
synchronized (mRecords) {
mServiceState = state;
for (Record r : mRecords) {
if ((r.events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
try {
r.callback.onServiceStateChanged(new ServiceState(state));
} catch (RemoteException ex) {
mRemoveList.add(r.binder);
}
}
}
handleRemoveListLocked();
}
broadcastServiceStateChanged(state);
}
13.回调应用程序的 onServiceStateChanged方法 ,可能会有多个应用程序,现在选择状态栏的处理程序,NetworkController处理网络变化。
public void onServiceStateChanged(ServiceState state) {
if (DEBUG) {
Slog.d(TAG, "onServiceStateChanged state=" + state);
}
mServiceState = state;
if (SystemProperties.getBoolean("ro.config.combined_signal", true)) {
/*
* if combined_signal is set to true only then consider data
* service state for signal display
*/
mDataServiceState = mServiceState.getDataState();
if (DEBUG) {
Slog.d(TAG, "Combining data service state" + mDataServiceState + "for signal");
}
}
updateTelephonySignalStrength();
updateDataNetType();
updateDataIcon();
refreshViews();
}
14. 信号量强度的传递也是类似,都需要状态栏应用(SystemUI)去更新数据。
1.比如现在所处的网络发生变化,RILReciver 收到上报信息,处理 RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED 信息。
case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED:
if (RILJ_LOGD) unsljLog(response);
mVoiceNetworkStateRegistrants
.notifyRegistrants(new AsyncResult(null, null, null));
break;
2.经分析 mVoiceNetworkStateRegistrants,是由 GsmServiceStateTracker 构造的。
public GsmServiceStateTracker(GSMPhone phone) {
...
cm.registerForVoiceNetworkStateChanged(this, EVENT_NETWORK_STATE_CHANGED, null);
...
}
3.消息交给 EVENT_NETWORK_STATE_CHANGED 处理。GsmServiceStateTracker 处理 EVENT_NETWORK_STATE_CHANGED 消息
case EVENT_NETWORK_STATE_CHANGED:
pollState();
break;
4.调用 pollState();
default:
// Issue all poll-related commands at once
// then count down the responses, which
// are allowed to arrive out-of-order
pollingContext[0]++;
cm.getOperator(
obtainMessage(
EVENT_POLL_STATE_OPERATOR, pollingContext));
pollingContext[0]++;
cm.getDataRegistrationState(
obtainMessage(
EVENT_POLL_STATE_GPRS, pollingContext));
pollingContext[0]++;
cm.getVoiceRegistrationState(
obtainMessage(
EVENT_POLL_STATE_REGISTRATION, pollingContext));
pollingContext[0]++;
cm.getNetworkSelectionMode(
obtainMessage(
EVENT_POLL_STATE_NETWORK_SELECTION_MODE, pollingContext));
5.再次向rild 发送消息,等待返回信息 ,信息返回后 GsmServiceStateTracker 处理 EVENT_POLL_STATE_OPERATOR,EVENT_POLL_STATE_GPRS,EVENT_POLL_STATE_REGISTRATION,EVENT_POLL_STATE_NETWORK_SELECTION_MODE
6. GsmServiceStateTracker最后调用 pollStateDone();
7.调用 phone.notifyServiceStateChanged(ss);
8.调用 phoneBase 的 notifyServiceStateChanged
protected void notifyServiceStateChangedP(ServiceState ss) {
AsyncResult ar = new AsyncResult(null, ss, null);
mServiceStateRegistrants.notifyRegistrants(ar);
mNotifier.notifyServiceState(this);
}
9.DefaultPhoneNotifier的 notifyServiceState(this);
10.public void notifyServiceState(Phone sender) {
ServiceState ss = sender.getServiceState();
if (ss == null) {
ss = new ServiceState();
ss.setStateOutOfService();
}
try {
mRegistry.notifyServiceState(ss);
} catch (RemoteException ex) {
// system process is dead
}
}
11. mRegistry 是 TelephonyRegistry.
12.调用 TelephonyRegistry的 notifyServiceState
public void notifyServiceState(ServiceState state) {
if (!checkNotifyPermission("notifyServiceState()")){
return;
}
synchronized (mRecords) {
mServiceState = state;
for (Record r : mRecords) {
if ((r.events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
try {
r.callback.onServiceStateChanged(new ServiceState(state));
} catch (RemoteException ex) {
mRemoveList.add(r.binder);
}
}
}
handleRemoveListLocked();
}
broadcastServiceStateChanged(state);
}
13.回调应用程序的 onServiceStateChanged方法 ,可能会有多个应用程序,现在选择状态栏的处理程序,NetworkController处理网络变化。
public void onServiceStateChanged(ServiceState state) {
if (DEBUG) {
Slog.d(TAG, "onServiceStateChanged state=" + state);
}
mServiceState = state;
if (SystemProperties.getBoolean("ro.config.combined_signal", true)) {
/*
* if combined_signal is set to true only then consider data
* service state for signal display
*/
mDataServiceState = mServiceState.getDataState();
if (DEBUG) {
Slog.d(TAG, "Combining data service state" + mDataServiceState + "for signal");
}
}
updateTelephonySignalStrength();
updateDataNetType();
updateDataIcon();
refreshViews();
}
14. 信号量强度的传递也是类似,都需要状态栏应用(SystemUI)去更新数据。
相关文章推荐
- 【google M】android 网络服务状态运行机制(语音、数据注册状态;运营商信息PLMN,SPN;radio技术;信号强度)
- android4.0来电过程(RIL Framework Java部分)
- android4.0来电过程(RIL Framework Java部分)
- android4.0去电过程(RIL Framework Java 部分)
- android 用eclipse调试framework java层或者应用层代码
- Android深入分析MessageQueue和Looper(FrameWork JAVA部分)
- android froyo framework内RIL.java类分析
- Android的Context && 安卓常用系统服务(当前运行包名/当前网络状态和开关网络/音频服务/马达服务) (转)
- Android 获取 Wifi 信号强度,检测是 Wifi 或者流量,获取手机电池电量及充电状态
- android froyo framework内RIL.java类分析
- Android Java 虚拟机与底层服务通讯过程中字符串的处理
- Android程序:使用系统服务*1.获取网络状态 * 2.打开关闭wifi * 3.获取系统音量 * 4.获取运行程序的包名
- Android网络状态监听,wifi强度监听
- Android RIL 原生代码(c/c++) 和 java代码部分分析
- Android网络服务状态运行机制
- ANDROID 获取Android服务wifi信号状态和移动网络状态
- Android RIL 原生代码(c/c++) 和 java代码部分分析
- Android ril原生代码(C/C++)和java代码部分分析
- 关于android广播包监听网络状态变化收到java.lang.NullPointerException: Error receiving broadcast Intent
- Android中Java服务过程