一、WelcomeFragment:用户注册选择登录服务器
AssistantActivity(处理用户注册界面)->WelcomeFragment(用于登录方式,包括:创建用户、利用LinPhone账号、SIP账号、获取远程配置)
二、登录解析
2.3、利用LinPhone账号(Use SIP account)
实际这个界面所做的业务,主要通过AssistantActivity.java 的public void saveCreatedAccount(String username, String userid, String password, String displayname, String ha1, String prefix, String domain, TransportType transport)方法实现。
三、跟踪注册流程
Java: LoginFragment ----(调用)---->AssistantActivity(方法:genericLogIn-(调用)->saveCreatedAccount)-(调用)->AccountBuilder(方法:saveNewAccount)---(调用)-->LinphoneCore(Jni方法)
saveNewAccount方法中的添加用户信息到LinphoneCore
//只是将传入的cfg追加到lc->sip_conf.proxies列表中存储起来; 然后通过linphone_proxy_config_apply(cfg,lc)存储起来;
lc.addProxyConfig(prxCfg);
//登陆的账号信息保存
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);}
发送注册: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");
}
}
开启创建Linphone的核心时就应经开始了定时的去处理Linphone的sip指令,那么我们看一下iterate做了一些啥?
跟踪流程:调用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);}
实际上是调用void linphone_core_iterate(LinphoneCore *lc):
这个函数是linphone的核心功能,在这个循环内,主要进行的操作有,接收sip消息、处理定时器、处理proxy的注册状态变化、认证重连;
关于登录的处理是通过proxy_update(lc)实现的
至此登录流程不在深究:后续继续补充