Android U 匹配不到APN,无法发起数据建立的问题分析

2023-11-22 19:04

本文主要是介绍Android U 匹配不到APN,无法发起数据建立的问题分析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

问题

打开数据开关后,没有data PDN请求发起,因此无法上网。

根据日志确定是没有找到合适的data profile,原因一般有:

1、APN 没有配置

2、APN 类型/网络能力不满足——APN type或bearer

3、APN 配置了但被disable了——APN proofile的carrierEnable值

日志分析

fail log:

APN 被disable了,所以无法匹配。

//preferred=true说明当前选中的是此条APN

11-20 15:01:51.409140  2316  3480 D DPM-0   : getApnSettingForNetworkRequest: networkType=13 isMtkImsDataSupport=true hasEimsCapability=false mPreferredDataProfile=[DataProfile=[ApnSetting]....] dataProfilesCount=0 dataProfiles=[] mAllDataProfiles=[[DataProfile=[ApnSetting] INTERNET, 3080, xxxxxx, internet, , null, , null, null, 0, supl | hipri | default, IPV4V6, IP, false, 0, true, 0, 0, 0, 0, 0, gid, xxxxx000000000000, false, UNKNOWN, UNKNOWN, 0, -1, -1, false, 961, TrafficDescriptor={mDnn=internet, null}, preferred=true]...]
11-20 15:01:51.410224  2316  3480 D DPM-0   : Can't find any data profile that can satisfy [NetworkRequest [ NONE id=0, [ Capabilities: DUN&TRUSTED&NOT_VPN&NOT_VCN_MANAGED Uid: 1001 UnderlyingNetworks: Null] ], mPriority=30, state=UNSATISFIED, mAttachedDataNetwork=null, isMetered=true, created time=15:01:51.407, evaluation result=null]
11-20 15:01:51.411224  1366  1366 D ImsManager: [1] Registration callback removed.
11-20 15:01:51.413463  2316  3480 D DPM-0   : Unable to find a data profile for [NetworkRequest [ NONE id=0, [ Capabilities: DUN&TRUSTED&NOT_VPN&NOT_VCN_MANAGED Uid: 1001 UnderlyingNetworks: Null] ], mPriority=30, state=UNSATISFIED, mAttachedDataNetwork=null, isMetered=true, created time=15:01:51.408, evaluation result=null]

正常日志:

dataProfilesCount 指明网络能力匹配的APN数

11-20 15:19:20.723854  2316  2316 D DPM-0   : getApnSettingForNetworkRequest: networkType=13 isMtkImsDataSupport=true hasEimsCapability=false mPreferredDataProfile=[DataProfile=[ApnSetting] ....] dataProfilesCount=1 dataProfiles=[[DataProfile=[ApnSetting] 

11-20 15:19:20.725075  2316  2316 V DPM-0   : Satisfied profile: [DataProfile=[ApnSetting]

11-20 15:19:20.725871  2316  2316 D DPM-0   : The final available profile: [DataProfile=[ApnSetting] 

11-20 15:19:20.729504  2316  2316 D DNC-0   : Data evaluation: evaluation reason:NEW_REQUEST, Data allowed reason: NORMAL, candidate profile=[DataProfile=[ApnSetting] 

11-20 15:19:20.730116  2316  2316 D DNC-0   : onSetupDataNetwork: dataProfile=[DataProfile=[ApnSetting] 

11-20 15:19:20.731688  2316  2316 D DNC-0   : Creating data network on WWAN with [DataProfile=[ApnSetting] 

11-20 15:19:20.768286  2316  2316 D DSM-C-0 : setupDataCall

11-20 15:19:20.769505  2316  2316 D DN-114-C: ConnectingState: setupData: accessNetwork=EUTRAN, [DataProfile=[ApnSetting] ...], isModemRoaming=false, allowRoaming=true, PDU session id=0, matchAllRuleAllowed=true
11-20 15:19:20.776007  2316  2682 D RILJ    :

 [0868]> SETUP_DATA_CALL,reason=NORMAL,accessNetworkType=EUTRAN,dataProfile=[DataProfile=[ApnSetting] ..],isRoaming=false,allowRoaming=true,linkProperties=null,pduSessionId=0,sliceInfo=null,trafficDescriptor=TrafficDescriptor={mDnn=VZWADMIN, null},matchAllRuleAllowed=true [PHONE0]

11-20 15:19:21.063568  2316  2674 D RILJ    : [0868]< SETUP_DATA_CALL DataCallResponse: { cause=NONE(0x0) retry=-1 cid=1803 linkStatus=2 protocolType=2 ifname=ccmni3 addresses=[10.128.159.113/32, 2600:100f:f00c:330f:0:56:6fe2:e801/64] dnses=[/2001:4888:53:ff00:524:d::, /2001:4888:52:ff00:528:d::, /198.224.166.135, /198.224.167.135] gateways=[/10.128.159.113, /::] pcscf=[] mtu=1428 mtuV4=1428 mtuV6=1428 handoverFailureMode=unknown pduSessionId=0 defaultQos=EpsQos { qosClassId=8 downlink=Bandwidth { maxBitrateKbps=0 guaranteedBitrateKbps=0} uplink=Bandwidth { maxBitrateKbps=0 guaranteedBitrateKbps=0}} qosBearerSessions=[] sliceInfo=null trafficDescriptors=[]} [PHONE0]

 代码分析

DataProfileManager.java - 【frameworks/opt/telephony】

/*** Get the APN setting for the network request.** @param networkRequest The network request.* @param networkType The current data network type.* @param ignorePermanentFailure {@code true} to ignore {@link ApnSetting#getPermanentFailed()}.* This should be set to true for condition-based retry/setup.* @return The APN setting. {@code null} if can't find any satisfiable data profile.*/
private @Nullable ApnSetting getApnSettingForNetworkRequest(@NonNull TelephonyNetworkRequest networkRequest, @NetworkType int networkType,boolean ignorePermanentFailure) {if (!networkRequest.hasAttribute(TelephonyNetworkRequest.CAPABILITY_ATTRIBUTE_APN_SETTING)) {loge("Network request does not have APN setting attribute.");return null;}//1、优先选择preferred APN,如果满足并且不处于PermanentFailure状态则直接请求// If the preferred data profile can be used, always use it if it can satisfy the network// request with current network type (even though it's been marked as permanent failed.)if (mPreferredDataProfile != null&& networkRequest.canBeSatisfiedBy(mPreferredDataProfile)&& mPreferredDataProfile.getApnSetting() != null&& mPreferredDataProfile.getApnSetting().canSupportNetworkType(networkType)) {if (ignorePermanentFailure || !mPreferredDataProfile.getApnSetting().getPermanentFailed()) {return mPreferredDataProfile.getApnSetting();}log("The preferred data profile is permanently failed. Only condition based retry "+ "can happen.");return null;}//2、如果没有首选数据配置文件,则过滤掉不能满足网络请求的数据配置文件//Note:找不到profile 一般就是这里匹配不到了// Filter out the data profile that can't satisfy the request.// Preferred data profile should be returned in the top of the list.List<DataProfile> dataProfiles = mAllDataProfiles.stream().filter(networkRequest::canBeSatisfiedBy)// The longest time hasn't used data profile will be in the front so all the data// profiles can be tried..sorted(Comparator.comparing(DataProfile::getLastSetupTimestamp))    //并按照它们的最后设置时间进行排序,将最长时间未使用的数据配置文件放在列表的前面.collect(Collectors.toList());for (DataProfile dataProfile : dataProfiles) {    //然后尝试筛选并使用它们来满足网络请求。logv("Satisfied profile: " + dataProfile + ", last setup="+ DataUtils.elapsedTimeToString(dataProfile.getLastSetupTimestamp()));}if (dataProfiles.size() == 0) {log("Can't find any data profile that can satisfy " + networkRequest);return null;}// Check if the remaining data profiles can used in current data network type.dataProfiles = dataProfiles.stream().filter(dp -> dp.getApnSetting() != null&& dp.getApnSetting().canSupportNetworkType(networkType)).collect(Collectors.toList());if (dataProfiles.size() == 0) {log("Can't find any data profile for network type "+ TelephonyManager.getNetworkTypeName(networkType));return null;}// Check if preferred data profile set id matches.dataProfiles = dataProfiles.stream().filter(dp -> dp.getApnSetting() != null&& (dp.getApnSetting().getApnSetId()== Telephony.Carriers.MATCH_ALL_APN_SET_ID|| dp.getApnSetting().getApnSetId() == mPreferredDataProfileSetId)).collect(Collectors.toList());if (dataProfiles.size() == 0) {log("Can't find any data profile has APN set id matched. mPreferredDataProfileSetId="+ mPreferredDataProfileSetId);return null;}// Check if data profiles are permanently failed.dataProfiles = dataProfiles.stream().filter(dp -> ignorePermanentFailure || !dp.getApnSetting().getPermanentFailed()).collect(Collectors.toList());if (dataProfiles.size() == 0) {log("The suitable data profiles are all in permanent failed state.");return null;}return dataProfiles.get(0).getApnSetting();
}
排查接口

canBeSatisfiedBy in TelephonyNetworkRequest.java -【frameworks/opt/telephony】

canHandleType in ApnSetting.java【frameworks/base/telephony】


匹配不到关键就是在网络能力评估的过程,canBeSatisfiedBy会根据APN类型筛选能力匹配的项,在canHandleType检查完APN可用性之后,返回enable且符合网络的APN。

/**
* Check if this network request can be satisfied by a data profile.
*
* @param dataProfile The data profile to check.
* @return {@code true} if this network request can be satisfied by the data profile.
*/
public boolean canBeSatisfiedBy(@NonNull DataProfile dataProfile) {// If the network request can be translated to OS/App id, then check if the data profile's// OS/App id can satisfy it.if (hasAttribute(CAPABILITY_ATTRIBUTE_TRAFFIC_DESCRIPTOR_OS_APP_ID)&& getOsAppId() != null) {// The network request has traffic descriptor type capabilities. Match the traffic// descriptor.if (dataProfile.getTrafficDescriptor() != null && Arrays.equals(getOsAppId().getBytes(),dataProfile.getTrafficDescriptor().getOsAppId())) {return true;}}// If the network request can be translated to APN setting or DNN in traffic descriptor,// then check if the data profile's APN setting can satisfy it.if ((hasAttribute(CAPABILITY_ATTRIBUTE_APN_SETTING)|| hasAttribute(CAPABILITY_ATTRIBUTE_TRAFFIC_DESCRIPTOR_DNN))&& dataProfile.getApnSetting() != null) {// Fallback to the legacy APN type matching.List<Integer> apnTypes = Arrays.stream(getCapabilities()).boxed().map(DataUtils::networkCapabilityToApnType).filter(apnType -> apnType != ApnSetting.TYPE_NONE).collect(Collectors.toList());// In case of enterprise network request, the network request will have internet,// but APN type will not have default type as the enterprise apn should not be used// as default network. Ignore default type of the network request if it// has enterprise type as well. This will make sure the network request with// internet and enterprise will be satisfied with data profile with enterprise at the// same time default network request will not get satisfied with enterprise data// profile.// TODO b/232264746if (apnTypes.contains(ApnSetting.TYPE_ENTERPRISE)) {apnTypes.remove((Integer) ApnSetting.TYPE_DEFAULT);}return apnTypes.stream().allMatch(dataProfile.getApnSetting()::canHandleType);}return false;
}/** @hide */
public boolean canHandleType(@ApnType int type) {if (!mCarrierEnabled) {return false;}// DEFAULT can handle HIPRI.return hasApnType(type);
}

定位原因的方法

查看APNSettings配置是否正确,以上问题就是APN配置了但被disable了。

[DataProfile=[ApnSetting] INTERNET, 3080, xxxxxx, internet, , null, , null, null, 0, supl | hipri | default, IPV4V6, IP, false, 0, true, 0, 0, 0, 0, 0, gid, xxxxx000000000000, false, UNKNOWN, UNKNOWN, 0, -1, -1, false, 961, TrafficDescriptor={mDnn=internet, null}, preferred=true]

根据ApnSettings实体节后打印信息,mCarrierEnabled就是上述日志false的位置。

/*** Returns the string representation of ApnSetting.** This method prints null for unset elements. The output doesn't contain password or user.* @hide*/
public String toString() {StringBuilder sb = new StringBuilder();sb.append("[ApnSetting] ").append(mEntryName).append(", ").append(mId).append(", ").append(mOperatorNumeric).append(", ").append(mApnName).append(", ").append(mProxyAddress).append(", ").append(UriToString(mMmsc)).append(", ").append(mMmsProxyAddress).append(", ").append(portToString(mMmsProxyPort)).append(", ").append(portToString(mProxyPort)).append(", ").append(mAuthType).append(", ");final String[] types = getApnTypesStringFromBitmask(mApnTypeBitmask).split(",");sb.append(TextUtils.join(" | ", types));sb.append(", ").append(PROTOCOL_INT_MAP.get(mProtocol));sb.append(", ").append(PROTOCOL_INT_MAP.get(mRoamingProtocol));sb.append(", ").append(mCarrierEnabled);    //APN启用情况sb.append(", ").append(mProfileId);sb.append(", ").append(mPersistent);sb.append(", ").append(mMaxConns);sb.append(", ").append(mWaitTime);sb.append(", ").append(mMaxConnsTime);sb.append(", ").append(mMtuV4);sb.append(", ").append(mMtuV6);sb.append(", ").append(MVNO_TYPE_INT_MAP.get(mMvnoType));sb.append(", ").append(mMvnoMatchData);sb.append(", ").append(mPermanentFailed);sb.append(", ").append(TelephonyManager.convertNetworkTypeBitmaskToString(mNetworkTypeBitmask));sb.append(", ").append(TelephonyManager.convertNetworkTypeBitmaskToString(mLingeringNetworkTypeBitmask));sb.append(", ").append(mApnSetId);sb.append(", ").append(mCarrierId);sb.append(", ").append(mSkip464Xlat);sb.append(", ").append(mAlwaysOn);sb.append(", ").append(Objects.hash(mUser, mPassword));return sb.toString();
}

这篇关于Android U 匹配不到APN,无法发起数据建立的问题分析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/412266

相关文章

kali linux 无法登录root的问题及解决方法

《kalilinux无法登录root的问题及解决方法》:本文主要介绍kalilinux无法登录root的问题及解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,... 目录kali linux 无法登录root1、问题描述1.1、本地登录root1.2、ssh远程登录root2、

SQL server配置管理器找不到如何打开它

《SQLserver配置管理器找不到如何打开它》最近遇到了SQLserver配置管理器打不开的问题,尝试在开始菜单栏搜SQLServerManager无果,于是将自己找到的方法总结分享给大家,对SQ... 目录方法一:桌面图标进入方法二:运行窗口进入方法三:查找文件路径方法四:检查 SQL Server 安

SpringBoot应用中出现的Full GC问题的场景与解决

《SpringBoot应用中出现的FullGC问题的场景与解决》这篇文章主要为大家详细介绍了SpringBoot应用中出现的FullGC问题的场景与解决方法,文中的示例代码讲解详细,感兴趣的小伙伴可... 目录Full GC的原理与触发条件原理触发条件对Spring Boot应用的影响示例代码优化建议结论F

SpringValidation数据校验之约束注解与分组校验方式

《SpringValidation数据校验之约束注解与分组校验方式》本文将深入探讨SpringValidation的核心功能,帮助开发者掌握约束注解的使用技巧和分组校验的高级应用,从而构建更加健壮和可... 目录引言一、Spring Validation基础架构1.1 jsR-380标准与Spring整合1

Python中使用正则表达式精准匹配IP地址的案例

《Python中使用正则表达式精准匹配IP地址的案例》Python的正则表达式(re模块)是完成这个任务的利器,但你知道怎么写才能准确匹配各种合法的IP地址吗,今天我们就来详细探讨这个问题,感兴趣的朋... 目录为什么需要IP正则表达式?IP地址的基本结构基础正则表达式写法精确匹配0-255的数字验证IP地

Android实现打开本地pdf文件的两种方式

《Android实现打开本地pdf文件的两种方式》在现代应用中,PDF格式因其跨平台、稳定性好、展示内容一致等特点,在Android平台上,如何高效地打开本地PDF文件,不仅关系到用户体验,也直接影响... 目录一、项目概述二、相关知识2.1 PDF文件基本概述2.2 android 文件访问与存储权限2.

MySQL 中查询 VARCHAR 类型 JSON 数据的问题记录

《MySQL中查询VARCHAR类型JSON数据的问题记录》在数据库设计中,有时我们会将JSON数据存储在VARCHAR或TEXT类型字段中,本文将详细介绍如何在MySQL中有效查询存储为V... 目录一、问题背景二、mysql jsON 函数2.1 常用 JSON 函数三、查询示例3.1 基本查询3.2

SpringBatch数据写入实现

《SpringBatch数据写入实现》SpringBatch通过ItemWriter接口及其丰富的实现,提供了强大的数据写入能力,本文主要介绍了SpringBatch数据写入实现,具有一定的参考价值,... 目录python引言一、ItemWriter核心概念二、数据库写入实现三、文件写入实现四、多目标写入

Android Studio 配置国内镜像源的实现步骤

《AndroidStudio配置国内镜像源的实现步骤》本文主要介绍了AndroidStudio配置国内镜像源的实现步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,... 目录一、修改 hosts,解决 SDK 下载失败的问题二、修改 gradle 地址,解决 gradle

Python 迭代器和生成器概念及场景分析

《Python迭代器和生成器概念及场景分析》yield是Python中实现惰性计算和协程的核心工具,结合send()、throw()、close()等方法,能够构建高效、灵活的数据流和控制流模型,这... 目录迭代器的介绍自定义迭代器省略的迭代器生产器的介绍yield的普通用法yield的高级用法yidle