Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2a091d7a authored by Robert Greenwalt's avatar Robert Greenwalt
Browse files

Update Tethering.

Adds telephony support, async model, multiple tethered iface suport,
better notifications, device config.

bug:2413855
parent be16be13
Loading
Loading
Loading
Loading
+43 −2
Original line number Original line Diff line number Diff line
@@ -125,13 +125,21 @@ public class ConnectivityManager


    /**
    /**
     * @hide
     * @hide
     * gives a String[]
     */
     */
    public static final String EXTRA_AVAILABLE_TETHER_COUNT = "availableCount";
    public static final String EXTRA_AVAILABLE_TETHER = "availableArray";


    /**
    /**
     * @hide
     * @hide
     * gives a String[]
     */
     */
    public static final String EXTRA_ACTIVE_TETHER_COUNT = "activeCount";
    public static final String EXTRA_ACTIVE_TETHER = "activeArray";

    /**
     * @hide
     * gives a String[]
     */
    public static final String EXTRA_ERRORED_TETHER = "erroredArray";


    /**
    /**
     * The Default Mobile data connection.  When active, all data traffic
     * The Default Mobile data connection.  When active, all data traffic
@@ -400,4 +408,37 @@ public class ConnectivityManager
            return false;
            return false;
        }
        }
    }
    }

    /**
     * {@hide}
     */
    public boolean isTetheringSupported() {
        try {
            return mService.isTetheringSupported();
        } catch (RemoteException e) {
            return false;
        }
    }

    /**
     * {@hide}
     */
    public String[] getTetherableUsbRegexs() {
        try {
            return mService.getTetherableUsbRegexs();
        } catch (RemoteException e) {
            return new String[0];
        }
    }

    /**
     * {@hide}
     */
    public String[] getTetherableWifiRegexs() {
        try {
            return mService.getTetherableWifiRegexs();
        } catch (RemoteException e) {
            return new String[0];
        }
    }
}
}
+6 −0
Original line number Original line Diff line number Diff line
@@ -55,7 +55,13 @@ interface IConnectivityManager


    boolean untether(String iface);
    boolean untether(String iface);


    boolean isTetheringSupported();

    String[] getTetherableIfaces();
    String[] getTetherableIfaces();


    String[] getTetheredIfaces();
    String[] getTetheredIfaces();

    String[] getTetherableUsbRegexs();

    String[] getTetherableWifiRegexs();
}
}
+6 −0
Original line number Original line Diff line number Diff line
@@ -2209,6 +2209,12 @@ public final class Settings {
         */
         */
        public static final String NETWORK_PREFERENCE = "network_preference";
        public static final String NETWORK_PREFERENCE = "network_preference";


        /**
         * Used to disable Tethering on a device - defaults to true
         * @hide
         */
        public static final String TETHER_SUPPORTED = "tether_supported";

        /**
        /**
         * No longer supported.
         * No longer supported.
         */
         */
+44 −18
Original line number Original line Diff line number Diff line
@@ -32,16 +32,19 @@ import android.widget.Toast;
import android.util.Log;
import android.util.Log;


/**
/**
 * This activity is shown to the user for him/her to connect/disconnect a Tether
 * This activity is shown to the user in two cases: when a connection is possible via
 * connection.  It will display notification when a suitable connection is made
 * a usb tether and when any type of tether is connected.  In the connecting case
 * to allow the tether to be setup.  A second notification will be show when a
 * It allows them to start a USB tether.  In the Tethered/disconnecting case it
 * tether is active, allowing the user to manage tethered connections.
 * will disconnect all tethers.
 */
 */
public class TetherActivity extends AlertActivity implements
public class TetherActivity extends AlertActivity implements
        DialogInterface.OnClickListener {
        DialogInterface.OnClickListener {


    private static final int POSITIVE_BUTTON = AlertDialog.BUTTON1;
    private static final int POSITIVE_BUTTON = AlertDialog.BUTTON1;


    // count of the number of tethered connections at activity create time.
    private int mTethered;

    /* Used to detect when the USB cable is unplugged, so we can call finish() */
    /* Used to detect when the USB cable is unplugged, so we can call finish() */
    private BroadcastReceiver mTetherReceiver = new BroadcastReceiver() {
    private BroadcastReceiver mTetherReceiver = new BroadcastReceiver() {
        @Override
        @Override
@@ -52,8 +55,6 @@ public class TetherActivity extends AlertActivity implements
        }
        }
    };
    };


    private boolean mWantTethering;

    @Override
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.onCreate(savedInstanceState);
@@ -61,17 +62,18 @@ public class TetherActivity extends AlertActivity implements
        // determine if we advertise tethering or untethering
        // determine if we advertise tethering or untethering
        ConnectivityManager cm =
        ConnectivityManager cm =
                (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
                (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
        if (cm.getTetheredIfaces().length > 0) {
        mTethered = cm.getTetheredIfaces().length;
            mWantTethering = false;
        int tetherable = cm.getTetherableIfaces().length;
        } else if (cm.getTetherableIfaces().length > 0) {
        if ((mTethered == 0) && (tetherable == 0)) {
            mWantTethering = true;
        } else {
            finish();
            finish();
            return;
            return;
        }
        }


        // Set up the "dialog"
        // Set up the dialog
        if (mWantTethering == true) {
        // if we have a tethered connection we put up a "Do you want to Disconect" dialog
        // otherwise we must have a tetherable interface (else we'd return above)
        // and so we want to put up the "do you want to connect" dialog
        if (mTethered == 0) {
            mAlertParams.mIconId = com.android.internal.R.drawable.ic_dialog_usb;
            mAlertParams.mIconId = com.android.internal.R.drawable.ic_dialog_usb;
            mAlertParams.mTitle = getString(com.android.internal.R.string.tether_title);
            mAlertParams.mTitle = getString(com.android.internal.R.string.tether_title);
            mAlertParams.mMessage = getString(com.android.internal.R.string.tether_message);
            mAlertParams.mMessage = getString(com.android.internal.R.string.tether_message);
@@ -114,17 +116,36 @@ public class TetherActivity extends AlertActivity implements
     * {@inheritDoc}
     * {@inheritDoc}
     */
     */
    public void onClick(DialogInterface dialog, int which) {
    public void onClick(DialogInterface dialog, int which) {
        boolean error =  false;


        if (which == POSITIVE_BUTTON) {
        if (which == POSITIVE_BUTTON) {
            ConnectivityManager connManager =
            ConnectivityManager cm =
                    (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
                    (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
            // start/stop tethering
            // start/stop tethering
            if (mWantTethering) {
            String[] tethered = cm.getTetheredIfaces();
                if (!connManager.tether("ppp0")) {

            if (tethered.length == 0) {
                String[] tetherable = cm.getTetherableIfaces();
                String[] usbRegexs = cm.getTetherableUsbRegexs();
                for (String t : tetherable) {
                    for (String r : usbRegexs) {
                        if (t.matches(r)) {
                            if (!cm.tether(t))
                                error = true;
                            break;
                        }
                    }
                }
                if (error) {
                    showTetheringError();
                    showTetheringError();
                }
                }
            } else {
            } else {
                if (!connManager.untether("ppp0")) {
                for (String t : tethered) {
                    if (!cm.untether("ppp0")) {
                        error = true;
                    }
                }
                if (error) {
                    showUnTetheringError();
                    showUnTetheringError();
                }
                }
            }
            }
@@ -134,8 +155,13 @@ public class TetherActivity extends AlertActivity implements
    }
    }


    private void handleTetherStateChanged(Intent intent) {
    private void handleTetherStateChanged(Intent intent) {
        // determine if we advertise tethering or untethering
        ConnectivityManager cm =
                (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
        if (mTethered != cm.getTetheredIfaces().length) {
            finish();
            finish();
        }
        }
    }


    private void showTetheringError() {
    private void showTetheringError() {
        Toast.makeText(this, com.android.internal.R.string.tether_error_message,
        Toast.makeText(this, com.android.internal.R.string.tether_error_message,
+1 −1
Original line number Original line Diff line number Diff line
@@ -1021,7 +1021,7 @@ public class HierarchicalStateMachine {
     * @param msg that couldn't be handled.
     * @param msg that couldn't be handled.
     */
     */
    protected void unhandledMessage(Message msg) {
    protected void unhandledMessage(Message msg) {
        Log.e(TAG, "unhandledMessage: msg.what=" + msg.what);
        Log.e(TAG, mName + " - unhandledMessage: msg.what=" + msg.what);
    }
    }


    /**
    /**
Loading