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

Commit 351434bd authored by Robert Greenwalt's avatar Robert Greenwalt Committed by Android (Google) Code Review
Browse files

Merge "Add error reporting for Tethering."

parents c1552397 5a73506c
Loading
Loading
Loading
Loading
+55 −5
Original line number Diff line number Diff line
@@ -364,7 +364,7 @@ public class ConnectivityManager
    /**
     * Sets the persisted value for enabling/disabling Mobile data.
     *
     * @param allowMobileData Whether the mobile data connection should be
     * @param enabled Whether the mobile data connection should be
     *            used or not.
     * @hide
     */
@@ -418,22 +418,35 @@ public class ConnectivityManager
    /**
     * {@hide}
     */
    public boolean tether(String iface) {
    public String[] getTetheringErroredIfaces() {
        try {
            return mService.getTetheringErroredIfaces();
        } catch (RemoteException e) {
            return new String[0];
        }
    }

    /**
     * @return error A TETHER_ERROR value indicating success or failure type
     * {@hide}
     */
    public int tether(String iface) {
        try {
            return mService.tether(iface);
        } catch (RemoteException e) {
            return false;
            return TETHER_ERROR_SERVICE_UNAVAIL;
        }
    }

    /**
     * @return error A TETHER_ERROR value indicating success or failure type
     * {@hide}
     */
    public boolean untether(String iface) {
    public int untether(String iface) {
        try {
            return mService.untether(iface);
        } catch (RemoteException e) {
            return false;
            return TETHER_ERROR_SERVICE_UNAVAIL;
        }
    }

@@ -469,4 +482,41 @@ public class ConnectivityManager
            return new String[0];
        }
    }

    /** {@hide} */
    public static final int TETHER_ERROR_NO_ERROR           = 0;
    /** {@hide} */
    public static final int TETHER_ERROR_UNKNOWN_IFACE      = 1;
    /** {@hide} */
    public static final int TETHER_ERROR_SERVICE_UNAVAIL    = 2;
    /** {@hide} */
    public static final int TETHER_ERROR_UNSUPPORTED        = 3;
    /** {@hide} */
    public static final int TETHER_ERROR_UNAVAIL_IFACE      = 4;
    /** {@hide} */
    public static final int TETHER_ERROR_MASTER_ERROR       = 5;
    /** {@hide} */
    public static final int TETHER_ERROR_TETHER_IFACE_ERROR = 6;
    /** {@hide} */
    public static final int TETHER_ERROR_UNTETHER_IFACE_ERROR = 7;
    /** {@hide} */
    public static final int TETHER_ERROR_ENABLE_NAT_ERROR     = 8;
    /** {@hide} */
    public static final int TETHER_ERROR_DISABLE_NAT_ERROR    = 9;
    /** {@hide} */
    public static final int TETHER_ERROR_IFACE_CFG_ERROR      = 10;

    /**
     * @param iface The name of the interface we're interested in
     * @return error The error code of the last error tethering or untethering the named
     *               interface
     * {@hide}
     */
    public int getLastTetherError(String iface) {
        try {
            return mService.getLastTetherError(iface);
        } catch (RemoteException e) {
            return TETHER_ERROR_SERVICE_UNAVAIL;
        }
   }
}
+6 −2
Original line number Diff line number Diff line
@@ -55,9 +55,11 @@ interface IConnectivityManager

    void setMobileDataEnabled(boolean enabled);

    boolean tether(String iface);
    int tether(String iface);

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

    int getLastTetherError(String iface);

    boolean isTetheringSupported();

@@ -65,6 +67,8 @@ interface IConnectivityManager

    String[] getTetheredIfaces();

    String[] getTetheringErroredIfaces();

    String[] getTetherableUsbRegexs();

    String[] getTetherableWifiRegexs();
+22 −19
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ public class TetherActivity extends AlertActivity implements
        // determine if we advertise tethering or untethering
        ConnectivityManager cm =
                (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);

        mTethered = cm.getTetheredIfaces().length;
        int tetherable = cm.getTetherableIfaces().length;
        if ((mTethered == 0) && (tetherable == 0)) {
@@ -116,7 +117,7 @@ public class TetherActivity extends AlertActivity implements
     * {@inheritDoc}
     */
    public void onClick(DialogInterface dialog, int which) {
        boolean error =  false;
        int error = ConnectivityManager.TETHER_ERROR_NO_ERROR;

        if (which == POSITIVE_BUTTON) {
            ConnectivityManager cm =
@@ -130,24 +131,17 @@ public class TetherActivity extends AlertActivity implements
                for (String t : tetherable) {
                    for (String r : usbRegexs) {
                        if (t.matches(r)) {
                            if (!cm.tether(t))
                                error = true;
                            error = cm.tether(t);
                            break;
                        }
                    }
                }
                if (error) {
                    showTetheringError();
                }
                showTetheringError(error);
            } else {
                for (String t : tethered) {
                    if (!cm.untether(t)) {
                        error = true;
                    }
                }
                if (error) {
                    showUnTetheringError();
                    error = cm.untether(t);
                }
                showUnTetheringError(error);
            }
        }
        // No matter what, finish the activity
@@ -163,14 +157,23 @@ public class TetherActivity extends AlertActivity implements
        }
    }

    private void showTetheringError() {
    private void showTetheringError(int error) {
        switch(error) {
        case ConnectivityManager.TETHER_ERROR_NO_ERROR:
            return;
        default:
            Toast.makeText(this, com.android.internal.R.string.tether_error_message,
                    Toast.LENGTH_LONG).show();
        }
    }

    private void showUnTetheringError() {
    private void showUnTetheringError(int error) {
        switch(error) {
        case ConnectivityManager.TETHER_ERROR_NO_ERROR:
            return;
        default:
            Toast.makeText(this, com.android.internal.R.string.tether_stop_error_message,
                    Toast.LENGTH_LONG).show();
        }

    }
}
+6 −3
Original line number Diff line number Diff line
@@ -2249,8 +2249,10 @@
    <string name="tether_button">Tether</string>
    <!-- See TETHER.   This is the button text to ignore the plugging in of the phone.. -->
    <string name="tether_button_cancel">Cancel</string>
    <!-- See TETHER.  If there was an error mounting, this is the text. -->
    <string name="tether_error_message">There is a problem tethering.</string>

    <!-- See TETHER.  If there was a recoverable error, this is the text. -->
    <string name="tether_error_message">We\'ve encountered a problem turning on Tethering.  Please try again.</string>

    <!-- TETHER: When the user connects the phone to a computer, we show a notification asking if he wants to share his cellular network connection.  This is the title -->
    <string name="tether_available_notification_title">USB tethering available</string>
    <!-- See USB_STORAGE. This is the message. -->
@@ -2270,7 +2272,8 @@
    <string name="tether_stop_button">Disconnect</string>
    <!-- See TETHER_STOP.   This is the button text to cancel disconnecting the tether. -->
    <string name="tether_stop_button_cancel">Cancel</string>
    <!-- See TETHER_STOP_DIALOG.  If there was an error disconnect, this is the text. -->

    <!-- See TETHER_STOP.  If there was an error disconnect, this is the text. -->
    <string name="tether_stop_error_message">We\'ve encountered a problem turning off Tethering. Please try again.</string>

    <!-- Strings for car mode notification -->
+30 −4
Original line number Diff line number Diff line
@@ -1457,15 +1457,36 @@ public class ConnectivityService extends IConnectivityManager.Stub {
    }

    // javadoc from interface
    public boolean tether(String iface) {
    public int tether(String iface) {
        enforceTetherChangePermission();
        return isTetheringSupported() && mTethering.tether(iface);

        if (isTetheringSupported()) {
            return mTethering.tether(iface);
        } else {
            return ConnectivityManager.TETHER_ERROR_UNSUPPORTED;
        }
    }

    // javadoc from interface
    public boolean untether(String iface) {
    public int untether(String iface) {
        enforceTetherChangePermission();
        return isTetheringSupported() && mTethering.untether(iface);

        if (isTetheringSupported()) {
            return mTethering.untether(iface);
        } else {
            return ConnectivityManager.TETHER_ERROR_UNSUPPORTED;
        }
    }

    // javadoc from interface
    public int getLastTetherError(String iface) {
        enforceTetherAccessPermission();

        if (isTetheringSupported()) {
            return mTethering.getLastTetherError(iface);
        } else {
            return ConnectivityManager.TETHER_ERROR_UNSUPPORTED;
        }
    }

    // TODO - proper iface API for selection by property, inspection, etc
@@ -1499,6 +1520,11 @@ public class ConnectivityService extends IConnectivityManager.Stub {
        return mTethering.getTetheredIfaces();
    }

    public String[] getTetheringErroredIfaces() {
        enforceTetherAccessPermission();
        return mTethering.getErroredIfaces();
    }

    // if ro.tether.denied = true we default to no tethering
    // gservices could set the secure setting to 1 though to enable it on a build where it
    // had previously been turned off.
Loading