Manually launch a 3G connection in Android and save it

How to start a 3G data connection in Android simultaneously with WiFi? I tried

IConnectivityManager.setMobileDataEnabled(enabled); // via reflection 

and it works in the emulator, but in my real phone (Droid 2) it turns on briefly and then turns off again.

The shell (adb shell) ip link contains information about the 3G connection:

15: ppp0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 3 link/ppp

However, it is only available if WiFi is turned off. When WiFi is turned on and I try to turn it on manually, it complains that the ppp0 device does not exist.

 bash-3.2# ip link set ppp0 up ip link set ppp0 up Cannot find device "ppp0" 

When I try to list a device, I can’t even find it

 bash-3.2# ls /dev/ppp* ls /dev/ppp* /dev/ppp 
+6
source share
3 answers

As I understand it, it is impossible to connect 3g and WiFi simultaneously without changing the source code of the Android platform (at least versions 2.3 and 4). The main problem is the hard-set priorities of the connections defined in frameworks / base / core / res / res / values ​​/config.xml :

 <!-- 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] --> <!-- ^^^^^^^^^^---------- Connection priority --> <string-array translatable="false" name="networkAttributes"> <item>"wifi,1,1,1"</item> <item>"mobile,0,0,0"</item> <item>"mobile_mms,2,0,2"</item> <item>"mobile_supl,3,0,2"</item> <item>"mobile_hipri,5,0,3"</item> </string-array> 

This config.xml file is then read by ConnectivityService , which is signed to enable / disable events. And in the connection handler, he decides what he should do with other connections:

 private void handleConnect(NetworkInfo info) { //------------8-<-------------------------- // if this is a default net and other default is running // kill the one not preferred if (mNetAttributes[type].isDefault()) { if (mActiveDefaultNetwork != -1 && mActiveDefaultNetwork != type) { if ((type != mNetworkPreference && mNetAttributes[mActiveDefaultNetwork].mPriority > // ^^^^^^^^^ --- From config.xml mNetAttributes[type].mPriority) || // ^^^^^^^^^-------- From config.xml mNetworkPreference == mActiveDefaultNetwork) { // don't accept this one if (DBG) Slog.v(TAG, "Not broadcasting CONNECT_ACTION " + "to torn down network " + info.getTypeName()); teardown(thisNet); return; //------------8-<-------------------------- 
+2
source

You can try to keep both active assets at the same time by changing your connectivityservice services, but I would advise him, as this will most likely destroy your battery life.

See here if you want to try it anyway (and make sure you have a backup, obviously)

0
source

If you are trying to connect to a specific computer, you can try ConnectivityManager.requestRouteToHost .

0
source

Source: https://habr.com/ru/post/909708/


All Articles