Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manually starting 3G connection in Android, and keeping it on

How do you start the 3G data connection in Android at the same time WiFi is on? I tried

IConnectivityManager.setMobileDataEnabled(enabled); // via reflection

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

From the shell (adb shell), ip link provides the details of 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 when WiFi is off. When WiFi is on and I try to turn it on manually, it complains the ppp0 device doesn't exist.

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

When I try to list the device, I can't even find it

bash-3.2# ls /dev/ppp*
ls /dev/ppp*
/dev/ppp
like image 410
Chloe Avatar asked Mar 01 '12 03:03

Chloe


People also ask

How do I make my phone stay on 3G?

Under Wireless and Networks, tap on Mobile Networks. This should bring up the configuration screen for using the Internet through a carrier. Tap on Preferred network type. Here you'll get options for the type of connections your device will always use.

How do I force 3G on Android?

*#*#4636#*#* Select Phone information. From there select your preferred network. For 2G select GSM only. For 3G select WCDMA only.


1 Answers

As I understand it's not possible to get 3g and WiFi simultaneously connected without modifying Android platform source code (at least versions 2.3 and 4). The main problem is hardcoded priorities of 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 is then read by ConnectivityService which is subscribed to connect/disconnect events. And in connect handler it decides what it 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-<--------------------------
like image 55
Dmitry Avatar answered Oct 04 '22 02:10

Dmitry