一、WelcomeFragment:用戶注冊(cè)選擇登錄服務(wù)器
AssistantActivity(處理用戶注冊(cè)界面)->WelcomeFragment(用于登錄方式,包括:創(chuàng)建用戶、利用LinPhone賬號(hào)、SIP賬號(hào)、獲取遠(yuǎn)程配置)

二、登錄解析
2.3、利用LinPhone賬號(hào)(Use SIP account)


實(shí)際這個(gè)界面所做的業(yè)務(wù),主要通過(guò)AssistantActivity.java 的public void saveCreatedAccount(String username, String userid, String password, String displayname, String ha1, String prefix, String domain, TransportType transport)方法實(shí)現(xiàn)。
三、跟蹤注冊(cè)流程
Java: LoginFragment ----(調(diào)用)---->AssistantActivity(方法:genericLogIn-(調(diào)用)->saveCreatedAccount)-(調(diào)用)->AccountBuilder(方法:saveNewAccount)---(調(diào)用)-->LinphoneCore(Jni方法)
saveNewAccount方法中的添加用戶信息到LinphoneCore
//只是將傳入的cfg追加到lc->sip_conf.proxies列表中存儲(chǔ)起來(lái); 然后通過(guò)linphone_proxy_config_apply(cfg,lc)存儲(chǔ)起來(lái);
lc.addProxyConfig(prxCfg);
//登陸的賬號(hào)信息保存
lc.addAuthInfo(authInfo);
Jni:linphonecore_jni.cc
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addAuthInfo(JNIEnv* env
,jobject thiz
,jlong lc
,jlong pc) {
linphone_core_add_auth_info((LinphoneCore*)lc, (LinphoneAuthInfo*)pc); }
authentucation.c
void linphone_core_add_auth_info(LinphoneCore *lc, const LinphoneAuthInfo *info){
LinphoneAuthInfo *ai;
bctbx_list_t *elem;
bctbx_list_t *l;
int restarted_op_count=0;
bool_t updating=FALSE;
if (info->tls_key == NULL && info->tls_key_path == NULL
&& info->ha1==NULL && info->passwd==NULL){
ms_error("linphone_core_add_auth_info(): info supplied with empty password, ha1 or TLS client/key");
return;
}
/* find if we are attempting to modify an existing auth info */
ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,info->realm,info->username,info->domain);
if (ai!=NULL && ai->domain && info->domain && strcmp(ai->domain, info->domain)==0){
lc->auth_info=bctbx_list_remove(lc->auth_info,ai);
linphone_auth_info_unref(ai);
updating=TRUE;
}
lc->auth_info=bctbx_list_append(lc->auth_info,linphone_auth_info_clone(info));
/* retry pending authentication operations */
for(l=elem=sal_get_pending_auths(lc->sal);elem!=NULL;elem=elem->next){
SalOp *op=(SalOp*)elem->data;
LinphoneAuthInfo *ai;
const SalAuthInfo *req_sai=sal_op_get_auth_requested(op);
ai=(LinphoneAuthInfo*)_linphone_core_find_auth_info(lc,req_sai->realm,req_sai->username,req_sai->domain, FALSE);
if (ai){
SalAuthInfo sai;
bctbx_list_t* proxy;
sai.username=ai->username;
sai.userid=ai->userid;
sai.realm=ai->realm;
sai.password=ai->passwd;
sai.ha1=ai->ha1;
if (ai->tls_cert && ai->tls_key) {
sal_certificates_chain_parse(&sai, ai->tls_cert, SAL_CERTIFICATE_RAW_FORMAT_PEM);
sal_signing_key_parse(&sai, ai->tls_key, "");
} else if (ai->tls_cert_path && ai->tls_key_path) {
sal_certificates_chain_parse_file(&sai, ai->tls_cert_path, SAL_CERTIFICATE_RAW_FORMAT_PEM);
sal_signing_key_parse_file(&sai, ai->tls_key_path, "");
}
/*proxy case*/
for (proxy=(bctbx_list_t*)linphone_core_get_proxy_config_list(lc);proxy!=NULL;proxy=proxy->next) {
if (proxy->data == sal_op_get_user_pointer(op)) {
linphone_proxy_config_set_state((LinphoneProxyConfig*)(proxy->data),LinphoneRegistrationProgress,"Authentication...");
break;
}
}
sal_op_authenticate(op,&sai);
restarted_op_count++;
}
}
if (l){
ms_message("linphone_core_add_auth_info(): restarted [%i] operation(s) after %s auth info for\n"
"\tusername: [%s]\n"
"\trealm [%s]\n"
"\tdomain [%s]\n",
restarted_op_count,
updating ? "updating" : "adding",
info->username ? info->username : "",
info->realm ? info->realm : "",
info->domain ? info->domain : "");
}
bctbx_list_free(l);
write_auth_infos(lc);}
發(fā)送注冊(cè):LinphoneManager(mLc.iterate())
private synchronized void startLibLinphone(Context c) {
try {
copyAssetsFromPackage();
//traces alway start with traces enable to not missed first initialization
mLc = LinphoneCoreFactory.instance().createLinphoneCore(this, mLinphoneConfigFile, mLinphoneFactoryConfigFile, null, c);
TimerTask lTask = new TimerTask() {
@Override
public void run() {
UIThreadDispatcher.dispatch(new Runnable() {
@Override
public void run() {
if (mLc != null) {
mLc.iterate();
}
}
});
}
};
/*use schedule instead of scheduleAtFixedRate to avoid iterate from being call in burst after cpu wake up*/
mTimer = new Timer("Linphone scheduler");
mTimer.schedule(lTask, 0, 20);
} catch (Exception e) {
Log.e(e, "Cannot start linphone");
}
}
開(kāi)啟創(chuàng)建Linphone的核心時(shí)就應(yīng)經(jīng)開(kāi)始了定時(shí)的去處理Linphone的sip指令,那么我們看一下iterate做了一些啥?
跟蹤流程:調(diào)用LinphoneCoreImpl中的private native void iterate(long nativePtr)其中nativePtr是LinphoneCore
Jni:linphonecore_jni.cc
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_iterate(JNIEnv* env
,jobject thiz
,jlong lc) {
linphone_core_iterate((LinphoneCore*)lc);}
實(shí)際上是調(diào)用void linphone_core_iterate(LinphoneCore *lc):
這個(gè)函數(shù)是linphone的核心功能,在這個(gè)循環(huán)內(nèi),主要進(jìn)行的操作有,接收sip消息、處理定時(shí)器、處理proxy的注冊(cè)狀態(tài)變化、認(rèn)證重連;
關(guān)于登錄的處理是通過(guò)proxy_update(lc)實(shí)現(xiàn)的
至此登錄流程不在深究:后續(xù)繼續(xù)補(bǔ)充