Android 7.0 UICC 分析(二)
本文讲解UiccCard类
/frameworks/opt/telephony/src/java/com/android/internal/telephony/uicc/UiccCard.java
UICCController 类的onGetIccCardStatusDone() 方法,根据获取的SIM状态信息IccCardStatus 创建或更新UiccCard 对象;
private synchronized void onGetIccCardStatusDone(AsyncResult ar, Integer index) {
.......
IccCardStatus status = (IccCardStatus)ar.result; if (mUiccCards[index] == null) {
//Create new card
mUiccCards[index] = new UiccCard(mContext, mCis[index], status, index);
} else {
//Update already existing card
mUiccCards[index].update(mContext, mCis[index] , status);
}
.......
}
UiccCard 类的构造方法,同样会调用update() 方法更新SIM 卡状态信息;
public UiccCard(Context c, CommandsInterface ci, IccCardStatus ics, int phoneId) {
mCardState = ics.mCardState;
mPhoneId = phoneId;
update(c, ci, ics);
}
UiccCard 类的 update() 方法:
1、根据IccCardStatus 参数在mUiccApplication 列表中匹配UiccCardApplication 对象,通过UiccCardApplication 类的update() 方法更新,否则创建一个UiccCardApplication 对象;
2、调用createAndUpdateCatService() 方法创建或更新CatService 对象;
3、获取RadioState状态,更新CardState,发出SIM卡插拔消息;
public void update(Context c, CommandsInterface ci, IccCardStatus ics) {
........
//update applications
if (DBG) log(ics.mApplications.length + " applications");
for ( int i = 0; i < mUiccApplications.length; i++) {
if (mUiccApplications[i] == null) {
//Create newly added Applications
if (i < ics.mApplications.length) {
mUiccApplications[i] = new UiccCardApplication(this,
ics.mApplications[i], mContext, mCi);
}
} else if (i >= ics.mApplications.length) {
//Delete removed applications
mUiccApplications[i].dispose();
mUiccApplications[i] = null;
} else {
//Update the rest
mUiccApplications[i].update(ics.mApplications[i], mContext, mCi); //调用UiccCardApplication.java
}
} createAndUpdateCatService(); //CatService
..........
RadioState radioState = mCi.getRadioState();
if (DBG) log("update: radioState=" + radioState + " mLastRadioState="
+ mLastRadioState);
// No notifications while radio is off or we just powering up
if (radioState == RadioState.RADIO_ON && mLastRadioState == RadioState.RADIO_ON) {
if (oldState != CardState.CARDSTATE_ABSENT &&
mCardState == CardState.CARDSTATE_ABSENT) {
if (DBG) log("update: notify card removed");
mAbsentRegistrants.notifyRegistrants();
mHandler.sendMessage(mHandler.obtainMessage(EVENT_CARD_REMOVED, null));
} else if (oldState == CardState.CARDSTATE_ABSENT &&
mCardState != CardState.CARDSTATE_ABSENT) {
if (DBG) log("update: notify card added");
mHandler.sendMessage(mHandler.obtainMessage(EVENT_CARD_ADDED, null));
}
}
mLastRadioState = radioState;
}
}
createAndUpdateCatService() 方法,创建或更新CatService:
protected void createAndUpdateCatService() {
if (mUiccApplications.length > 0 && mUiccApplications[0] != null) {
// Initialize or Reinitialize CatService
if (mCatService == null) {
mCatService = CatService.getInstance(mCi, mContext, this, mPhoneId);
} else {
((CatService)mCatService).update(mCi, mContext, this);
}
} else {
if (mCatService != null) {
mCatService.dispose();
}
mCatService = null;
}
}
消息EVENT_CARD_REMOVED、 EVENT_CARD_ADDED 在UiccCard 类的handleMessage()方法中处理:
protected Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg){
switch (msg.what) {
case EVENT_CARD_REMOVED:
onIccSwap(false);
break;
case EVENT_CARD_ADDED:
onIccSwap(true);
break;
.........
}
}
};
onIccSwap() 方法,判断是否共卡座,如果是直接返回,否则调用promptForRestart():
private void onIccSwap(boolean isAdded) { boolean isHotSwapSupported = mContext.getResources().getBoolean(
R.bool.config_hotswapCapable); if (isHotSwapSupported) { //给国内双卡共卡座设计留下接口
log("onIccSwap: isHotSwapSupported is true, don't prompt for rebooting");
return;
}
log("onIccSwap: isHotSwapSupported is false, prompt for rebooting"); promptForRestart(isAdded);
}
promptForRestart() 方法,切换sim卡,弹出提示框:
private void promptForRestart(boolean isAdded) {
synchronized (mLock) {
final Resources res = mContext.getResources();
final String dialogComponent = res.getString(
R.string.config_iccHotswapPromptForRestartDialogComponent);
if (dialogComponent != null) {
Intent intent = new Intent().setComponent(ComponentName.unflattenFromString(
dialogComponent)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(EXTRA_ICC_CARD_ADDED, isAdded);
try {
mContext.startActivity(intent);
return;
} catch (ActivityNotFoundException e) {
loge("Unable to find ICC hotswap prompt for restart activity: " + e);
}
} // TODO: Here we assume the device can't handle SIM hot-swap
// and has to reboot. We may want to add a property,
// e.g. REBOOT_ON_SIM_SWAP, to indicate if modem support
// hot-swap.
DialogInterface.OnClickListener listener = null; // TODO: SimRecords is not reset while SIM ABSENT (only reset while
// Radio_off_or_not_available). Have to reset in both both
// added or removed situation.
listener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
synchronized (mLock) {
if (which == DialogInterface.BUTTON_POSITIVE) {
if (DBG) log("Reboot due to SIM swap");
PowerManager pm = (PowerManager) mContext
.getSystemService(Context.POWER_SERVICE);
pm.reboot("SIM is added."); //SIM卡上电重启
}
}
} }; Resources r = Resources.getSystem(); String title = (isAdded) ? r.getString(R.string.sim_added_title) :
r.getString(R.string.sim_removed_title);
String message = (isAdded) ? r.getString(R.string.sim_added_message) :
r.getString(R.string.sim_removed_message);
String buttonTxt = r.getString(R.string.sim_restart_button); AlertDialog dialog = new AlertDialog.Builder(mContext)
.setTitle(title)
.setMessage(message)
.setPositiveButton(buttonTxt, listener)
.create();
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
dialog.show(); //SIM卡弹出提示框
}
}
Android 7.0 UICC 分析(二)的更多相关文章
- Android 7.0 UICC 分析(四)
本文讲解SIMRecords /frameworks/opt/telephony/src/java/com/android/internal/telephony/uicc/SIMRecords.jav ...
- Android 7.0 UICC 分析(三)
本文讲解UICCCardApplication /frameworks/opt/telephony/src/java/com/android/internal/telephony/uicc/UiccC ...
- Android 7.0 UICC 分析(一)
UICC(Universal Intergrated Circuit Card) 框架 * Following is class diagram for uicc classes: * * UiccC ...
- Android 5.0 Uicc框架分析
已同步更新至个人blog: dxjia.cn Uicc框架 UICC框架是Android在4.1引入的,使的对卡的管理控制更加清晰.要了解这个UICC框架,需要从UiccController开始, ...
- android 休眠唤醒机制分析(二) — early_suspend
本文转自:http://blog.csdn.net/g_salamander/article/details/7982170 early_suspend是Android休眠流程的第一阶段即浅度休眠,不 ...
- Android 5.0 怎样正确启用isLoggable(二)__原理分析
前置文章 <Android 5.0 怎样正确启用isLoggable(一)__使用具体解释> 概要 在上文<Android 5.0 怎样正确启用isLoggable(一)__使用具体 ...
- Android 8.1 源码_启动篇(二) -- 深入研究 zygote(转 Android 9.0 分析)
前言 在Android中,zygote是整个系统创建新进程的核心进程.zygote进程在内部会先启动Dalvik虚拟机,继而加载一些必要的系统资源和系统类,最后进入一种监听状态.在之后的运作中,当其他 ...
- Android 7.0 启动篇 — init原理(二)(转 Android 9.0 分析)
======================================================== ================================== ...
- Android4.0图库Gallery2代码分析(二) 数据管理和数据加载
Android4.0图库Gallery2代码分析(二) 数据管理和数据加载 2012-09-07 11:19 8152人阅读 评论(12) 收藏 举报 代码分析android相册优化工作 Androi ...
随机推荐
- C++设计模式-Memento备忘录模式
Memento模式作用:在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象之外保存这个状态,这样以后就可将该对象恢复到原先保存的状态. UML图: Originator:负责创建一个备忘录Me ...
- 去除angularjs路由的显眼的#号
在接触到angularj并完成第一个demo后,惊奇地发现居然还可以这样开发前端界面.个人喜欢的一个功能点就是ng的路由功能,可以很好地将视图放入多个文件中.但最基础的使用会给url添加一个显眼的#, ...
- VI 命令 gg 跳到第一行,dG 删除后面的所有内容
VI 命令 gg 跳到第一行,dG 删除后面的所有内容
- 哆啦A梦 canvas
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Hibernate配置文档详解
Hibernate配置文档有框架总部署文档hibernate.cfg.xml 和映射类的配置文档 ***.hbm.xml hibernate.cfg.xml(文件位置直接放在src源文件夹即可) (在 ...
- Android test---robotium----简单例子
1.首先新建一个要被测试的工程,命名为”robotium“:一个很简单的Android 应用程序:主页面只有个 TextView 控件: 2. 在建一个用于测试的工程 ,命名为”robotiumTes ...
- 第一天 :学习node.js
① node.js环境配置 我学过的语言最简单的一门 直接百度就可以配置 ② 每个入门 的程序都是从helloworld开始 代码如下 : var http=require('http'); http ...
- NHibernate系列文章二十七:NHibernate Mapping之Fluent Mapping基础(附程序下载)
摘要 从这一节起,介绍NHibernate Mapping的内容.前面文章都是使用的NHibernate XML Mapping.NHibernate XML Mapping是NHibernate最早 ...
- Debian7下lnmp+gunicorn部署Django运行环境
首先安装lnmp,安装方法见lnmp.org wget -c http://soft.vpser.net/lnmp/lnmp1.3-full.tar.gz && tar zxf lnm ...
- Orcle学习(一)
exists"和"in"的效率问题 1) select * from T1 where exists(select 1 from T2 where T1.a=T2.a) ...