Android中的信号强度上报与显示完整流程()

更新时间:2023-07-01 19:34:55 阅读: 评论:0

Android中的信号强度上报与显⽰完整流程()分析:
在RILConstants.java中找到:
int RIL_UNSOL_SIGNAL_STRENGTH = 1009;
张家界风景图片
在RIL.java中找到与其相关的代码:
private void
processUnsolicited (Parcel p) {
…….
ca RIL_UNSOL_SIGNAL_STRENGTH: ret = responSignalStrength(p); break;
…..
ca RIL_UNSOL_SIGNAL_STRENGTH:
// Note this is t to “verbo” becau it happens
/
/ frequently
if (RILJ_LOGV) unsljLogvRet(respon, ret);
if (mSignalStrengthRegistrant != null) {
new AsyncResult (null, ret, null));
}
在RIL的⽗类BaCommands.java中找到:
public void tOnSignalStrengthUpdate(Handler h, int what, Object obj) {
mSignalStrengthRegistrant = new Registrant (h, what, obj);
}
再找其调⽤者(GsmServiceStateTracker.java):
public GsmServiceStateTracker(GSMPhone phone) {
super();
……
cm.tOnSignalStrengthUpdate(this, EVENT_SIGNAL_STRENGTH_UPDATE, null);
……
GsmServiceStateTracker⾃⼰处理上报上来的信号强度信息:
ca EVENT_SIGNAL_STRENGTH_UPDATE:
// This is a notification from
// CommandsInterface.tOnSignalStrengthUpdate
ar = (AsyncResult) msg.obj;
// The radio is telling us about signal strength changes
/
/ we don’t have to ask it
dontPollSignalStrength = true;
onSignalStrengthResult(ar);
break;
函数onSignalStrengthResult负责处理:
private void onSignalStrengthResult(AsyncResult ar) {
SignalStrength oldSignalStrength = mSignalStrength;
int rssi = 99;
if (ar.exception != null) {
// -1 = unknown
胖人装悬针纹// most likely radio is retting/disconnected
tSignalStrengthDefaultValues();
} el {
int[] ints = (int[])ar.result;
// bug 658816 ems to be a ca where the result is 0-length
if (ints.length != 0) {
rssi = ints[0];
} el {
Log.e(LOG_TAG, “Bogus signal strength respon”);
rssi = 99;
}
}
mSignalStrength = new SignalStrength(rssi, -1, -1, -1,
-1, -1, -1, true);
if (!mSignalStrength.equals(oldSignalStrength)) {
try { // This takes care of delayed EVENT_POLL_SIGNAL_STRENGTH (scheduled after
// POLL_PERIOD_MILLIS) during Radio Technology Change)
} catch (NullPointerException ex) {
log(“onSignalStrengthResult() Phone already destroyed: ” + ex
+ “SignalStrength not notified”);
}
}
}
若没发⽣异常,且值产⽣变化,则调⽤ ifySignalStrength通知(见GSMPhone.java):notifySignalStrength() {
}
DefaultPhoneNotifier(DefaultPhoneNotifier.java)通知注册者:
public void notifySignalStrength(Phone nder) {
try {
} catch (RemoteException ex) {
// system process is dead
}
}
这个注册者来⾃:
DefaultPhoneNotifier() {
mRegistry = ITelephonyRegistry.Stub.Service(“istry”));
}
TelephonyRegistry.java,TelephonyRegistry是ITelephonyRegistry.Stub的⼦类,作为rvice运⾏在system_rver进程中,它会通知注册者。上⾯的DefaultPhoneNotifier运⾏在com.android.phone进程中,当信号强度值变化时,通过Service进⾏通知(rvice被感兴趣的注册者调⽤了listen,添加了回调函数。
public void notifySignalStrength(SignalStrength signalStrength) {
if (!checkNotifyPermission(“notifySignalStrength()”)) {
return;
写雪的诗句
}
synchronized (mRecords) {
mSignalStrength = signalStrength;
for (int i = mRecords.size() – 1; i >= 0; i–) {
Record r = (i);
if ((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
ndSignalStrength(r, signalStrength);
}
if ((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
try {
int gsmSignalStrength = GsmSignalStrength();
SignalStrengthChanged((gsmSignalStrength == 99 ? -1
: gsmSignalStrength));
} catch (RemoteException ex) {
remove(r.binder);
}
}
}
雾霾有什么危害
}
broadcastSignalStrengthChanged(signalStrength);    //此处作⽤⼀,就是通知
PhoneSignalStrength(signalStrength);信号变化,开始计时,从⽽⽤来统计信号处于这⼀状态的时长。
}
在TelephonyManager.java中提供了API,应⽤程序可以监听各种事件,实际上它将感兴趣的监听者作为⼀条记录添加到rvice⼀侧的列表(跨进程)中,当有变化时,调⽤它们提供的回调函数,通知(跨进程)这些注册者。
TelephonyManager.java中的listen函数如下:
public void listen(PhoneStateListener listener, int events) {
String pkgForDebug = mContext != null ? PackageName() : “<unknown>”;
try {
Boolean notifyNow = (getITelephony() != null);
mRegistry.listen(pkgForDebug, listener.callback, events, notifyNow);
} catch (RemoteException ex) {
// system process dead
} catch (NullPointerException ex) {
// system process dead
}
}
其中回调对象实例listener.callback来⾃于PhoneStateListener.java嵌套定义及其实例,这样,当TelephonyRegistry.java调⽤回调函数时,就调⽤到listener.callback,进⽽发送消息给PhoneStateListener.java中的mHandler,由其处理,进⽽由其⼦类去处理。
在StatusBarPolicy.java中,注册了下⾯要监听处理的事件。第⼆个为信号强度:
((SystemService(Context.TELEPHONY_SERVICE))
.listen(mPhoneStateListener,琦珂银饰
PhoneStateListener.LISTEN_SERVICE_STATE
| PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
| PhoneStateListener.LISTEN_CALL_STATE
| PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
| PhoneStateListener.LISTEN_DATA_ACTIVITY);
处理者为:
private PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
mSignalStrength = signalStrength;
updateSignalStrength();
}
在StatusBarPolicy的updateSignalStrength函数中,将根据得到的信息,设置适当的图标id,显⽰合适的图标。
主动请求:
GsmServiceStateTracker.java
ca EVENT_POLL_SIGNAL_STRENGTH:
// Just poll signal strength…not part of pollState()感动到哭的句子
break;
在RIL.java中,发送请求:
public void
getSignalStrength (Message result) {
RILRequest rr
= RILRequest.obtain(RIL_REQUEST_SIGNAL_STRENGTH, result);
/*if (RILJ_LOGD)*/ riljLog(rr.rialString() + “> ” + requestToString(rr.mRequest));
nd(rr);
}
请求号在RIL.java中,定义了请求号:
RIL_REQUEST_SIGNAL_STRENGTH
返回结果: processSolicited中得到结果后ndToTarget
private void
processSolicited (Parcel p) {
…..
ca RIL_REQUEST_SIGNAL_STRENGTH: ret = responSignalStrength(p); break;
在GsmServiceStateTracker.java中,msg的handler指定为this,所以GsmServiceStateTracker负责回送的消息的处理:ca EVENT_GET_SIGNAL_STRENGTH:
// This callback is called when signal strength is polled
// all by itlf
if (!(cm.getRadioState().isOn()) || (cm.getRadioState().isCdma())) {
// Polling will continue when radio turns back on and not CDMA
桂花山药的做法
return;
}
ar = (AsyncResult) msg.obj;
onSignalStrengthResult(ar);
queueNextSignalStrengthPoll();
break;
private void onSignalStrengthResult(AsyncResult ar) {
SignalStrength oldSignalStrength = mSignalStrength;
int rssi = 99;
Log.d(“YCG”, “query done! onSignalStrengthResult”);
if (ar.exception != null) {
// -1 = unknown
// most likely radio is retting/disconnected
tSignalStrengthDefaultValues();
} el {
int[] ints = (int[])ar.result;
// bug 658816 ems to be a ca where the result is 0-length
if (ints.length != 0) {
rssi = ints[0];
Log.d(“YCG”, “query done! rssi=”+rssi);
} el {
Log.e(LOG_TAG, “Bogus signal strength respon”);
rssi = 99;
}
}
mSignalStrength = new SignalStrength(rssi, -1, -1, -1,
-1, -1, -1, true);
if (!mSignalStrength.equals(oldSignalStrength)) {
try { // This takes care of delayed EVENT_POLL_SIGNAL_STRENGTH (scheduled after // POLL_PERIOD_MILLIS) during Radio Technology Change)
} catch (NullPointerException ex) {
log(“onSignalStrengthResult() Phone already destroyed: ” + ex
+ “SignalStrength not notified”);
}
}
}

本文发布于:2023-07-01 19:34:55,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/1072723.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:处理   回调   信号
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图