android 8.0的Volte开关流程。。
Volte按钮:
vendor/qcom/proprietary/telephont-app/NetworkSetting/src/com/qualcomm/qti/networksetting/MoblieNetWorkSettings.java中key为_"enhanced_4g_lte"的SwitchPreference就是设置中的Votle开关。
boolean enhanced4gMode = !enhanced4gModePref.isChecked();
mImsMgr.setEnhanced4gLteModeSettingForSlot(enhanced4gModePref.isChecked());
上两行代码就是按钮相关的设置。
调用ImsManager中的setEnhanced4gLteModeSettingForSlot方法来进行设置。ImsManage路径:android\frameworks\opt\net\ims\src\java\com\android\ims\ImsManager。
~
~
ImsManage.java
public void setEnhanced4gLteModeSettingForSlot(boolean enabled) {
// If false, we must always keep advanced 4G mode set to true (1).
int value = getBooleanCarrierConfigForSlot(
CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL) ? (enabled ? 1: 0) : 1;
int subId = getSubId(mPhoneId);
log("setEnhanced4gLteModeSettingForSlot :: subId=" + subId + " enabled=" + enabled);
try {
int prevSetting = android.provider.Settings.Global.getInt(mContext.getContentResolver(),
android.provider.Settings.Global.ENHANCED_4G_MODE_ENABLED + subId);
if (prevSetting == value) {
// Don't trigger setAdvanced4GMode if the setting hasn't changed.
return;
}
} catch (Settings.SettingNotFoundException e) {
// Setting doesn't exist yet, so set it below.
}
android.provider.Settings.Global.putInt(mContext.getContentResolver(),
android.provider.Settings.Global.ENHANCED_4G_MODE_ENABLED + subId, value);
if (isNonTtyOrTtyOnVolteEnabledForSlot()) { //不支持TTY或者VoLTE支持TTY
try {
setAdvanced4GMode(enabled);//设置Votle
} catch (ImsException ie) {
// do nothing
}
}
}
以上代码是setEnhanced4gLteModeSettingForSlot的具体实现。代码不是很复杂,和android8.0之前版本的区别就在于它多了一个运载配置和getInt中subId的闯入。android8.0之前的版本好像是没有这两个东西的。
~
~
~
private void setAdvanced4GMode(boolean turnOn) throws ImsException {
checkAndThrowExceptionIfServiceUnavailable();
log("setAdvanced4GMode :: turnOn=" + turnOn);
// if turnOn: first set feature values then call turnOnIms()
// if turnOff: only set feature values if IMS turn off is not allowed. If turn off is
// allowed, first call turnOffIms() then set feature values
if (turnOn) {
setLteFeatureValues(turnOn);
log("setAdvanced4GMode: turnOnIms");
turnOnIms();
} else {
if (isImsTurnOffAllowed()) {
log("setAdvanced4GMode: turnOffIms");
turnOffIms();
}
setLteFeatureValues(turnOn);
}
}
private void setLteFeatureValues(boolean turnOn) {
log("setLteFeatureValues: " + turnOn);
try {
ImsConfig config = getConfigInterface();
if (config != null) {
config.setFeatureValue(ImsConfig.FeatureConstants.FEATURE_TYPE_VOICE_OVER_LTE,
TelephonyManager.NETWORK_TYPE_LTE, turnOn ? 1 : 0, mImsConfigListener);
if (isVolteEnabledByPlatformForSlot()) {
boolean ignoreDataEnabledChanged = getBooleanCarrierConfigForSlot(
CarrierConfigManager.KEY_IGNORE_DATA_ENABLED_CHANGED_FOR_VIDEO_CALLS);
boolean enableViLte = turnOn && isVtEnabledByUserForSlot() &&
(ignoreDataEnabledChanged || isDataEnabled());
config.setFeatureValue(ImsConfig.FeatureConstants.FEATURE_TYPE_VIDEO_OVER_LTE,
TelephonyManager.NETWORK_TYPE_LTE,
enableViLte ? 1 : 0,
mImsConfigListener);
}
}
} catch (ImsException e) {
loge("setLteFeatureValues: exception ", e);
}
}
private void turnOffIms() throws ImsException {
checkAndThrowExceptionIfServiceUnavailable();
try {
mImsServiceProxy.turnOffIms();
} catch (RemoteException e) {
throw new ImsException("turnOffIms() ", e, ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
}
}
private void turnOnIms() throws ImsException {
checkAndThrowExceptionIfServiceUnavailable();
try {
mImsServiceProxy.turnOnIms();
} catch (RemoteException e) {
throw new ImsException("turnOnIms() ", e, ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
}
}
上面是setAdvanced4GMode()方法中所调用的具体代码,setLteFeatureValues():下面介绍。而turnOffIms()和turnOnIms()会调用到android\frameworks\base\telephony\java\android\telephony\ims\ImsServiceProxy.java---->ImmService.java--->ImsServiceSub.java。
这里需要说明一下android 8.0和之前的版本不太一样。
代码中定义 private ImsServiceProxyCompat mImsServiceProxy = null;
private void createImsService() {
if (!mConfigDynamicBind) {
// Old method of binding
Rlog.i(TAG, "Creating ImsService using ServiceManager");
mImsServiceProxy = getServiceProxyCompat();
} else {
Rlog.i(TAG, "Creating ImsService using ImsResolver");
mImsServiceProxy = getServiceProxy();
}
// We have created a new ImsService connection, signal for re-registration
synchronized (mHasRegisteredLock) {
mHasRegisteredForProxy = false;
}
}
创建Ims服务的时候会有两种情况,mConfigDynamicBind的值是在framework/core/res/res/values/config.xml中定义的。
所以getServiceProxy()它是指向ImsServiceProxy,ImsServiceProxy继承ImsServiceProxyCompat 。
指向子类,所以调用的是ImsServiceProxy中的turnOnIms()。
~
~
ImsConfig.java中的setFeatureValue()方法:
ImsConfig路径:android\frameworks\base\telephony\java\com\android\ims\ImsConfig.java
调用过程:
ImsConfig.Java中setFeatureValue()--->IImsConfig.aild--->ImsConfigImplBase.java(继承IImsConfig.aild)-->ImsConfigImpl中的setFeatureValue(继承ImsConfigImplBase)。
public void getFeatureValue(int feature, int network,
ImsConfigListener listener) throws ImsException {
if (DBG) {
Rlog.d(TAG, "getFeatureValue: feature = " + feature + ", network =" + network +
", listener =" + listener);
}
try {
miConfig.getFeatureValue(feature, network, listener);
} catch (RemoteException e) {
throw new ImsException("getFeatureValue()", e,
ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
}
}
~
android/vender/qcom/proprietary/telephony-apps/ims/ImsConfigImpl.java
private ImsSenderRxr mCi;
@Override
public void setFeatureValue(int feature, int network, int value, ImsConfigListener listener) {
mContext.enforceCallingOrSelfPermission(MODIFY_PHONE_STATE, "setFeatureValue");
int srvType = ImsQmiIF.CALL_TYPE_VOICE;
if (feature == ImsConfig.FeatureConstants.FEATURE_TYPE_VIDEO_OVER_LTE) {
srvType = ImsQmiIF.CALL_TYPE_VT;
}
int enabled = ImsQmiIF.STATUS_DISABLED;
if (value == ImsConfig.FeatureValueConstants.ON) {
enabled = ImsQmiIF.STATUS_ENABLED;
}
int act = ImsQmiIF.RADIO_TECH_LTE;
if (network == TelephonyManager.NETWORK_TYPE_IWLAN) {
act = ImsQmiIF.RADIO_TECH_IWLAN;
}
if (network == TelephonyManager.NETWORK_TYPE_LTE ||
network == TelephonyManager.NETWORK_TYPE_IWLAN) {
Log.i(this, "SetServiceStatus = " + srvType + " " + network + " " + enabled);
mCi.setServiceStatus(mHandler.obtainMessage(EVENT_SET_FEATURE_VALUE,
new FeatureAccessWrapper(feature, network, value, listener)),
srvType, act, enabled, 0);
}
}
~
android/vender/qcom/proprietary/telephony-apps/ims/ImsSenderRxr.java一直到这,是setFeatureValue的一个流程。
IImsRadio mImsRadio; 到这,我没有再往下深究,文件太多aidl接口实现比较难找。
public void setServiceStatus(Message result, int srvType, int network, int enabled,
int restrictCause) {
final int msgId = ImsQmiIF.REQUEST_SET_SERVICE_STATUS;
final String msgIdString = msgIdToString(msgId);
IFRequest rr = IFRequest.obtain(msgId, result);
if (sendErrorOnImsRadioDown(rr, msgIdString)) {
return;
}
queueRequest(rr);
try {
ServiceStatusInfo serviceStatusInfo = ImsRadioUtils.buildServiceStatusInfo(srvType,
network, enabled, restrictCause);
logSolicitedRequest(rr);
Log.i(this, msgIdString + " to ImsRadio: token -" + rr.mSerial +
" SrvType:" + srvType + " Network:" + network + " enabled:" + enabled +
" RestrictCause:" + restrictCause);
mImsRadio.setServiceStatus(rr.mSerial, serviceStatusInfo);
} catch (Exception ex) {
removeFromQueueAndSendResponse(rr.mSerial, ImsQmiIF.E_GENERIC_FAILURE);
Log.e(this, "SetServiceStatus request to IImsRadio: Exception: " + ex);
}
}
上面是我对Votle开关流程的一个大概理解。
~
~
~
最终会在ImsSenderRxr中发送消息,然后在ImsServiceSub中接收。
ImsServiceSub.java
case EVENT_SRV_STATUS_UPDATE:
Log.i(this, "Received event: EVENT_SRV_STATUS_UPDATE");
AsyncResult arResult = (AsyncResult) msg.obj;
if (arResult.exception == null && arResult.result != null) {
ArrayList responseArray =
(ArrayList) arResult.result;
handleSrvStatusUpdate(responseArray);
} else {
Log.e(this, "IMS Service Status Update failed!");
initServiceStatus();
}
break;
case EVENT_GET_SRV_STATUS:
Log.i(this, "Received event: EVENT_GET_STATUS_UPDATE");
AsyncResult arResultSrv = (AsyncResult) msg.obj;
if (arResultSrv.exception == null && arResultSrv.result != null)
ArrayList responseArray =
(ArrayList) arResultSrv.result;
handleSrvStatusUpdate(responseArray);
} else {
Log.e(this, "IMS Service Status Update failed!");
initServiceStatus();
}
break;
private void handleSrvStatusUpdate(ArrayList updateList) {
、、、、、、、
mImsServiceStateReceiver.updateHDIcon(isVideoSupported(), isVoiceSupported());
、、、、、、、、
}
~
~
调用ImsServiceStateReceiver中的updateHDIcon(),发送通知来设置和更新图标。
public void updateHDIcon(boolean isVideoCapable, boolean isVoiceCapable) {
Log.i(LOG_TAG, "updateHDIcon isVideo : " + isVideoCapable + " isVoice : " +
isVoiceCapable + " phoneId: " + mPhoneId + " show HD Icon: " + mShowHDIcon);
if (ImsCallUtils.isCarrierOneSupported()) {
return;
}
if (mServiceSub.getFeatureState() == ImsFeature.STATE_READY) {
if (shallShowHDIcon()) {
showHDIcon(isVideoCapable || isVoiceCapable);
} else {
// Remove the HD icon during phone process crash/SIM Remove.
showHDIcon(false);
}
} else {
// Remove the HD icon if featureState is not STATE_READY
showHDIcon(false);
}
}
private void showHDIcon(boolean showHDIcon) {
if (mShowHDIcon == showHDIcon) return;
if (mNotificationMgr == null) {
mNotificationMgr = (NotificationManager)mContext.getSystemService(
Context.NOTIFICATION_SERVICE);
}
if (mShowHDIcon) {
NotificationChannel channel = mNotificationMgr.
getNotificationChannel(CHANNEL_ID + mPhoneId);
if (channel == null) {
CharSequence name = mContext.getResources().getString(R.string.ims_channel_name);
int importance = NotificationManager.IMPORTANCE_LOW;
channel = new NotificationChannel(CHANNEL_ID + mPhoneId, name, importance);
mNotificationMgr.createNotificationChannel(channel);
}
Notification.Builder builder = new Notification.Builder(mContext);
builder.setChannel(channel.getId());
if (mShowVOLTEIcon) {
builder.setContentTitle(mContext.getResources().getString(
R.string.device_is_volte_capable,
mPhoneId + 1));
builder.setSmallIcon(R.drawable.volte_icon);
} else {
builder.setContentTitle(mContext.getResources().getString(
R.string.device_is_hd_capable,
mPhoneId + 1));
builder.setSmallIcon(R.drawable.ims_state);
}
builder.setShowWhen(false);
overrideNotificationAppName(mContext, builder);
Notification notification = builder.build();
notification.flags |= Notification.FLAG_NO_CLEAR;
mNotificationMgr.notifyAsUser(null, IMS_HD_ICON + mPhoneId, notification,
UserHandle.ALL);
} else {
mNotificationMgr.cancelAsUser(null, IMS_HD_ICON + mPhoneId, UserHandle.ALL);
}
}