Keywords: Android 4.0 mobile network Mobile Networks
Platform information:
Kernel: linux2.6/linux3.0
System: Android/android4.0
Platform: s5pv310 (Samsung exynos4210)
Author: xubin341719 (You are welcome to reprint it. Please note the author)
Debug the 3G module a few days ago, and finally find that the bsp I got does not have the 3G option in "Settings"-and the status bar does not display the 3G Status icon, as shown in. This is good, the 3g driver is added, and the process is up, so you don't know how to connect. The most hateful thing is that a buddy encountered the same problem on the Internet. He posted a post for help and finally solved the problem. When the post was closed, he wrote a "solve the problem, close the post ", I asked him how he did it, and he didn't return it either. It's not a good deal. Hey, hey! Find it by yourself ......
1. Mobile Networks string Definition
The data we want is not displayed, and we can find the characters that are never displayed. It's a bit difficult to drive us. "Mobile Networks" is not displayed, so let's start with the code.
4.0.3_r1/packages/apps/Settings/res/values/String.xml <!-- Wireless controls, item title to go into the network settings --> <string name="network_settings_title">Mobile networks</string>
2. network_settings_title reference
4.0.3 _ R1/packages/apps/settings/src/COM/Android/settings/wirelesssettings. Java: "mobile_network_settings" Private Static final string key_mobilenetwork__settings = "mobile_network_settings ";
Assign network_settings_title to key_mobile_network_settings, and then follow up on the key_mobile_network_settings variable.
In the same file, find:
// Remove Mobile Network Settings if it's a wifi-only device. if (Utils.isWifiOnly(getActivity())) { getPreferenceScreen().removePreference(findPreference(KEY_MOBILE_NETWORK_SETTINGS)); }
Getsystemservice (context. connectivity_service); obtain the network connection service, and then determine whether type_mobile is supported. Now it is determined that it is not supported, that is, if: utils. iswifionly (getactivity () = 1
So we removed the "mobile network" option, and now we will focus on analyzing utils. iswifionly (getactivity (), locate the reason for not displaying, that is, the judgment condition in if (), and follow up this code.
3. Let's see where ifwifionly () is holy?
4.0.3 _ R1/packages/apps/settings/src/COM/Android/settings/utils. Java
import android.net.ConnectivityManager; public static boolean isWifiOnly(Context context) {ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);return (cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE) == false);}
Utils. iswifionly (getactivity () = 1 that is
Cm. isnetworksupported (connectivitymanager. type_mobile) = false, but the value we want now is true. Why is false? Let's continue to look at cm. isnetworksupported.
4. Analyze isnetworksupported again
Android.net. connectivitymanager; find
4.0.3 _ R1/frameworks/base/CORE/Java/Android/NET/connectivitymanager. Java
The implementation of isnetworksupported is as follows:
public boolean isNetworkSupported(int networkType) {try {return mService.isNetworkSupported(networkType);} catch (RemoteException e) {}return false;}}
Continue to follow up the implementation of the mservice. isnetworksupported function.
5. Implementation of mservice. isnetworksupported
4.0.3 _ R1/frameworks/base/services/Java/COM/Android/Server/connectivitymanager. Java
@Override public boolean isNetworkSupported(int networkType) { enforceAccessPermission(); loge("xu_bin"+"test typevalid = " + isNetworkTypeValid(networkType) + " trackers = " + (mNetTrackers[networkType] != null)); return (isNetworkTypeValid(networkType) && (mNetTrackers[networkType] != null)); }
There are two parameters: isnetworktypevalid (networktype), (mnettrackers [networktype]! = NULL ))
The value we want is true, and the returned value is false. Check the two values and print them out:
LogE ("xu_bin" + "test typevalid =" + isnetworktypevalid (networktype) + "trackers =" + (mnettrackers [networktype]! = NULL ));
The output is as follows:
The output is as follows:
E/connectivityservice (1426): xu_bin test typevalid = true trackers = false
That is to say: (mnettrackers [networktype]! = NULL) The problem occurs;
That is, mnettrackers [networktype] = NULL
6. Let's take a look at mnettrackers [networktype ].
In fact, I am a little confused about the following code,
4.0.3 _ R1/frameworks/base/services/Java/COM/Android/Server/connectivitymanager. Java
public ConnectivityService(Context context, INetworkManagementService netd, INetworkStatsService statsService, INetworkPolicyManager policyManager){ if (DBG) log("ConnectivityService starting up"); ………… // Load device network attributes from resources String[] raStrings = context.getResources().getStringArray( com.android.internal.R.array.radioAttributes); for (String raString : raStrings) { loge("xu_bin test raStrings" + raStrings); // 1 loge("xu_bin test raString" + raString); RadioAttributes r = new RadioAttributes(raString); if (r.mType > ConnectivityManager.MAX_RADIO_TYPE) { loge("Error in radioAttributes - ignoring attempt to define type " + r.mType); continue; } if (mRadioAttributes[r.mType] != null) { loge("Error in radioAttributes - ignoring attempt to redefine type " + r.mType); continue; } mRadioAttributes[r.mType] = r; } String[] naStrings = context.getResources().getStringArray( com.android.internal.R.array.networkAttributes); for (String naString : naStrings) { loge("xu_bin test naStrings" + naStrings);//2 loge("xu_bin test naString" + naString); try { NetworkConfig n = new NetworkConfig(naString); if (n.type > ConnectivityManager.MAX_NETWORK_TYPE) { loge("Error in networkAttributes - ignoring attempt to define type " + n.type); continue; } if (mNetConfigs[n.type] != null) { loge("Error in networkAttributes - ignoring attempt to redefine type " + n.type); continue; } ………… /* * Create the network state trackers for Wi-Fi and mobile * data. Maybe this could be done with a factory class, * but it's not clear that it's worth it, given that * the number of different network types is not going * to change very often. */ for (int netType : mPriorityList) {loge("xu_bin:" + netType + " " + mNetConfigs[netType].radio + " " + ConnectivityManager.TYPE_MOBILE);loge("xu_bin test mNetConfigs[netType].radio =" + (mNetConfigs[netType].radio));//3 switch (mNetConfigs[netType].radio) { ………… case ConnectivityManager.TYPE_MOBILE: mNetTrackers[netType] = new MobileDataStateTracker(netType, mNetConfigs[netType].name); mNetTrackers[netType].startMonitoring(context, mHandler); break; case ConnectivityManager.TYPE_DUMMY: mNetTrackers[netType] = new DummyDataStateTracker(netType, mNetConfigs[netType].name); mNetTrackers[netType].startMonitoring(context, mHandler); break; ………… case ConnectivityManager.TYPE_ETHERNET: mNetTrackers[netType] = EthernetDataTracker.getInstance(); mNetTrackers[netType].startMonitoring(context, mHandler); break; default: loge("Trying to create a DataStateTracker for an unknown radio type " + mNetConfigs[netType].radio); continue; } mCurrentLinkProperties[netType] = null; if (mNetTrackers[netType] != null && mNetConfigs[netType].isDefault()) { mNetTrackers[netType].reconnect(); } } ………… }
Add print information:
(1 ),
LogE ("xu_bin test rastrings" + rastrings );
LogE ("xu_bin test rastring" + rastring );
(2 ),
LogE ("xu_bin test nastrings" + nastrings );
LogE ("xu_bin test nastring" + nastring );
(3 ),
LogE ("xu_bin:" + nettype + "" + mnetconfigs [nettype]. Radio + "" + connectivitymanager. type_mobile );
LogE ("xu_bin test mnetconfigs [nettype]. Radio =" + (mnetconfigs [nettype]. Radio ));
The printed value is: E/connectivityservice (1426): xu_bin test rastring s [ljava. lang. string; @ 411cf008 E/connectivityservice (1426): xu_bin test rastring 9,1 E/connectivityservice (1426): xu_bin test nastring s [ljava. lang. string; @ 410e30c8 E/connectivityservice (1426): xu_bin test nastring Ethernet, 9, 9, 1,-1, true E/connectivityservice (1426): xu_bin: 9 9 0 E/connectivityservice (1426): xu_bin test mnetconfigs [nettype]. radio = 9 d/networkmanagementservice (1426): Registering observer D/networkmanagementservice (1426): Registering observer D/networkmanagementservice (1426): Registering Observer I/wifiservice (1426 ): wifiservice starting up with Wi-Fi disabled E/connectivityservice (1426): xu_bintest typevalid = true trackers = falsecom. android. internal. r. array. networkattributes value:
We are at: 4.0.3 _ R1/frameworks/base/CORE/RES/values/config. xml
<string-array translatable="false" name="networkAttributes"> <item>"wifi,1,1,1,-1,true"</item> <item>"mobile,0,0,0,-1,true"</item> <item>"mobile_mms,2,0,2,60000,true"</item> <item>"mobile_supl,3,0,2,60000,true"</item> <item>"mobile_hipri,5,0,3,60000,true"</item> <item>"mobile_fota,10,0,2,60000,true"</item> <item>"mobile_ims,11,0,2,60000,true"</item> <item>"mobile_cbs,12,0,2,60000,true"</item> <item>"wifi_p2p,13,1,0,-1,true"</item> </string-array>
There is no Ethernet, 9, 1,-1, true.
So we can search globally:
Grep-r-W Ethernet./* to obtain the following useful information:
./android-samsung-dev.patch:- <item>"ethernet,9,9,2,-1,true"</item> ./android-samsung-dev.patch:+ // Following code will forcefully allow ethernet network as usable required for v310/c210. ./packages/providers/DownloadProvider/src/com/android/providers/downloads/DownloadThread.java: // Following code will forcefully allow ethernet network as usable required for v310/c210. ./device/samsung/smdkv310/overlay/frameworks/base/core/res/res/values/config.xml: <item>"ethernet,9,9,1,-1,true"</item>
Code comparison:
./Packages/providers/downloadprovider/src/COM/Android/providers/downloads/downloadthread. Java Delete
Following code will forcefully allow ethernet network as usable required for v310/c210. if (networkUsable != DownloadInfo.NETWORK_OK) { Log.i(Constants.TAG, " Forcing ethernet connection usable for download to work!!!"); networkUsable = DownloadInfo.NETWORK_OK; }
4.0.3 _ R1/device/Samsung/smdkv310/overlay/frameworks/base/CORE/RES/values/config. xml delete:
<!-- This string array should be overridden by the device to present a list of network attributes. This is used by the connectivity manager to decide which networks can coexist based on the hardware --> <!-- An Array of "[Connection name],[ConnectivityManager connection type], [associated radio-type],[priority],[restoral-timer(ms)],[dependencyMet] --> <!-- the 5th element "resore-time" indicates the number of milliseconds to delay before automatically restore the default connection. Set -1 if the connection does not require auto-restore. --> <!-- the 6th element indicates boot-time dependency-met value. --> <string-array translatable="false" name="networkAttributes"> <item>"ethernet,9,9,1,-1,true"</item> </string-array> <!-- This string array should be overridden by the device to present a list of radio attributes. This is used by the connectivity manager to decide which networks can coexist based on the hardware --> <!-- An Array of "[ConnectivityManager connectionType], [# simultaneous connection types]" --> <string-array translatable="false" name="radioAttributes"> <item>"9,1"</item> </string-array>
Delete the preceding two parts. In fact, the actual value is parsed through the above function in 4.0.3 _ R1/frameworks/base/CORE/RES/values/config. xml.
Normally, the printed values are: WiFi mobile mobile_mms mobile_supl and so on. They are all configured in config. xml.
D/ConnectivityService( 1397): ConnectivityService starting upE/ConnectivityService( 1397): xu_bin test restring s[Ljava.lang.String;@41240e38E/ConnectivityService( 1397): xu_bin test restring 1,1E/ConnectivityService( 1397): xu_bin test restring s[Ljava.lang.String;@41240e38E/ConnectivityService( 1397): xu_bin test restring 0,1E/ConnectivityService( 1397): xu_bin test naString s[Ljava.lang.String;@41241880E/ConnectivityService( 1397): xu_bin test naString wifi,1,1,1,-1,trueE/ConnectivityService( 1397): xu_bin test naString s[Ljava.lang.String;@41241880E/ConnectivityService( 1397): xu_bin test naString mobile,0,0,0,-1,trueE/ConnectivityService( 1397): xu_bin test naString s[Ljava.lang.String;@41241880E/ConnectivityService( 1397): xu_bin test naString mobile_mms,2,0,2,60000,trueE/ConnectivityService( 1397): xu_bin test naString s[Ljava.lang.String;@41241880E/ConnectivityService( 1397): xu_bin test naString mobile_supl,3,0,2,60000,trueE/ConnectivityService( 1397): xu_bin test naString s[Ljava.lang.String;@41241880E/ConnectivityService( 1397): xu_bin test naString mobile_hipri,5,0,3,60000,trueE/ConnectivityService( 1397): xu_bin test naString s[Ljava.lang.String;@41241880E/ConnectivityService( 1397): xu_bin test naString mobile_fota,10,0,2,60000,trueE/ConnectivityService( 1397): xu_bin test naString s[Ljava.lang.String;@41241880E/ConnectivityService( 1397): xu_bin test naString mobile_ims,11,0,2,60000,trueE/ConnectivityService( 1397): xu_bin test naString s[Ljava.lang.String;@41241880E/ConnectivityService( 1397): xu_bin test naString mobile_cbs,12,0,2,60000,trueE/ConnectivityService( 1397): xu_bin test naString s[Ljava.lang.String;@41241880E/ConnectivityService( 1397): xu_bin test naString wifi_p2p,13,1,0,-1,true
Now we can see "mobile network: