UiccCardApplication所担任的任务主要包括创建并向外提供IccFileHandler、IccRecords对象、提供对SIM卡状态的监听等。
一、UiccCardApplication的主要功能
public void registerForReady(Handler h, int what, Object obj) {}
public void registerForLocked(Handler h, int what, Object obj) {}
public void registerForNetworkLocked(Handler h, int what, Object obj) {}
public AppState getState() {}
public AppType getType() {}
public PersoSubState getPersoSubState() {}
public String getAid() {}
public PinState getPin1State() {}
public IccFileHandler getIccFileHandler() {}
public IccRecords getIccRecords() {}
public void supplyPin (String pin, Message onComplete) {}
public void supplyPuk (String puk, String newPin, Message onComplete) {}
public void supplyPin2 (String pin2, Message onComplete) {}
public void supplyPuk2 (String puk2, String newPin2, Message onComplete) {}
public void supplyNetworkDepersonalization (String pin, Message onComplete) {}
public boolean getIccLockEnabled() {}
public boolean getIccFdnEnabled() {}
public void setIccLockEnabled (boolean enabled, String password, Message onComplete) {}
public void setIccFdnEnabled (boolean enabled, String password, Message onComplete) {}
public void changeIccLockPassword(String oldPassword, String newPassword, Message onComplete) {}
public void changeIccFdnPassword(String oldPassword, String newPassword, Message onComplete) {}
由此可以看到UiccCardApplication的主要功能:
1、创建并向外提供IccFileHandler、IccRecords对象
2、查询当前UiccCardApplication状态信息,主要包括mAppState、mAppType
3、查询、设置Fdn的状态
4、查询、设置Pin、Puk状态和密码
5、提供网络锁、Pin锁、状态OK的监听器
二、UiccCardApplication的初始化过程
我们先来看UiccCardApplication的属性:
public class UiccCardApplication {}
与UiccCard类似,其没有父类,然后看构造函数:
UiccCardApplication(UiccCard uiccCard, IccCardApplicationStatus as, Context c, CommandsInterface ci) {
mUiccCard = uiccCard;
mAppState = as.app_state;
mAppType = as.app_type;
mPersoSubState = as.perso_substate;
mAid = as.aid;
mAppLabel = as.app_label;
mPin1Replaced = (as.pin1_replaced != 0);
mPin1State = as.pin1;
mPin2State = as.pin2;
mContext = c;
mCi = ci;
//创建IccFileHandler对象
mIccFh = createIccFileHandler(as.app_type);
//创建IccRecords对象
mIccRecords = createIccRecords(as.app_type, mContext, mCi);
if (mAppState == AppState.APPSTATE_READY) {
//查询fdn号码
queryFdn();
//查询Pin码状态
queryPin1State();
}
}
在构造函数中主要完成了四个任务:
1、创建SIM卡的文件系统管理者IccFileHandler的子类对象:SIMFileHandler/RuimFileHandler/UsimFileHandler/CsimFileHandler/IsimFileHandler
2、创建SIM卡信息IccRecords的子类对象:SIMRecords/RuimRecords/IsimUiccRecords
3、查询Fdn号码
4、查询Pin码状态
三、UiccCardApplication的更新过程
void update (IccCardApplicationStatus as, Context c, CommandsInterface ci) {
synchronized (mLock) {
//状态更新
mContext = c;
mCi = ci;
AppType oldAppType = mAppType;
AppState oldAppState = mAppState;
PersoSubState oldPersoSubState = mPersoSubState;
mAppType = as.app_type;
mAppState = as.app_state;
mPersoSubState = as.perso_substate;
mAid = as.aid;
mAppLabel = as.app_label;
mPin1Replaced = (as.pin1_replaced != 0);
mPin1State = as.pin1;
mPin2State = as.pin2;
if (mAppType != oldAppType) {
if (mIccFh != null) { mIccFh.dispose();}
if (mIccRecords != null) { mIccRecords.dispose();}
//重新创建IccFileHandler和IccRecords
mIccFh = createIccFileHandler(as.app_type);
mIccRecords = createIccRecords(as.app_type, c, ci);
}
if (mPersoSubState != oldPersoSubState && mPersoSubState == PersoSubState.PERSOSUBSTATE_SIM_NETWORK) {
//通知网络锁的监听器
notifyNetworkLockedRegistrantsIfNeeded(null);
}
if (mAppState != oldAppState) {
if (mAppState == AppState.APPSTATE_READY) {
//重新查询Fdn和Pin
queryFdn();
queryPin1State();
}
//通知网络锁和网络注册的监听器
notifyPinLockedRegistrantsIfNeeded(null);
notifyReadyRegistrantsIfNeeded(null);
}
}
}
我们看到,在UiccCardApplication的更新过程中,完成了3个任务:
1、更新当前状态相关的成员变量
2、需要时重新构建IccFileHandler、IccRecords,以及重新查询Fdn和Pin
3、通知监听器
接下来的章节我们分析由UiccCardApplication创建的 IccFileHandler和IccRecords对象