First pass at USB Tethering.
bug:2281900
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java
index 30799ec..d435df5 100644
--- a/core/java/android/net/ConnectivityManager.java
+++ b/core/java/android/net/ConnectivityManager.java
@@ -116,6 +116,24 @@
"android.net.conn.BACKGROUND_DATA_SETTING_CHANGED";
/**
+ * Broadcast Action: A tetherable connection has come or gone
+ * TODO - finish the doc
+ * @hide
+ */
+ public static final String ACTION_TETHER_STATE_CHANGED =
+ "android.net.conn.TETHER_STATE_CHANGED";
+
+ /**
+ * @hide
+ */
+ public static final String EXTRA_AVAILABLE_TETHER_COUNT = "availableCount";
+
+ /**
+ * @hide
+ */
+ public static final String EXTRA_ACTIVE_TETHER_COUNT = "activeCount";
+
+ /**
* The Default Mobile data connection. When active, all data traffic
* will use this connection by default. Should not coexist with other
* default connections.
@@ -338,4 +356,48 @@
}
mService = service;
}
+
+ /**
+ * {@hide}
+ */
+ public String[] getTetherableIfaces() {
+ try {
+ return mService.getTetherableIfaces();
+ } catch (RemoteException e) {
+ return new String[0];
+ }
+ }
+
+ /**
+ * {@hide}
+ */
+ public String[] getTetheredIfaces() {
+ try {
+ return mService.getTetheredIfaces();
+ } catch (RemoteException e) {
+ return new String[0];
+ }
+ }
+
+ /**
+ * {@hide}
+ */
+ public boolean tether(String iface) {
+ try {
+ return mService.tether(iface);
+ } catch (RemoteException e) {
+ return false;
+ }
+ }
+
+ /**
+ * {@hide}
+ */
+ public boolean untether(String iface) {
+ try {
+ return mService.untether(iface);
+ } catch (RemoteException e) {
+ return false;
+ }
+ }
}
diff --git a/core/java/android/net/IConnectivityManager.aidl b/core/java/android/net/IConnectivityManager.aidl
index 9f59cce..caa3f2b 100644
--- a/core/java/android/net/IConnectivityManager.aidl
+++ b/core/java/android/net/IConnectivityManager.aidl
@@ -50,4 +50,12 @@
boolean getBackgroundDataSetting();
void setBackgroundDataSetting(boolean allowBackgroundData);
+
+ boolean tether(String iface);
+
+ boolean untether(String iface);
+
+ String[] getTetherableIfaces();
+
+ String[] getTetheredIfaces();
}
diff --git a/core/java/android/os/INetworkManagementService.aidl b/core/java/android/os/INetworkManagementService.aidl
index e4ec098..f48f45f 100644
--- a/core/java/android/os/INetworkManagementService.aidl
+++ b/core/java/android/os/INetworkManagementService.aidl
@@ -140,7 +140,8 @@
* Attaches a PPP server daemon to the specified TTY with the specified
* local/remote addresses.
*/
- void attachPppd(String tty, String localAddr, String remoteAddr);
+ void attachPppd(String tty, String localAddr, String remoteAddr, String dns1Addr,
+ String dns2Addr);
/**
* Detaches a PPP server daemon from the specified TTY.
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 7128005..bacaf43 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -2944,6 +2944,13 @@
public static final String MOUNT_UMS_NOTIFY_ENABLED = "mount_ums_notify_enabled";
/**
+ * Whether or not a notification is displayed when a Tetherable interface is detected.
+ * (0 = false, 1 = true)
+ * @hide
+ */
+ public static final String TETHER_NOTIFY = "tether_notify";
+
+ /**
* If nonzero, ANRs in invisible background processes bring up a dialog.
* Otherwise, the process will be silently killed.
* @hide
diff --git a/core/java/com/android/internal/app/TetherActivity.java b/core/java/com/android/internal/app/TetherActivity.java
new file mode 100644
index 0000000..2b93dbc
--- /dev/null
+++ b/core/java/com/android/internal/app/TetherActivity.java
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2007 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.app;
+
+import android.app.AlertDialog;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.net.ConnectivityManager;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.IMountService;
+import android.os.Message;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.widget.Toast;
+import android.util.Log;
+
+/**
+ * This activity is shown to the user for him/her to connect/disconnect a Tether
+ * connection. It will display notification when a suitable connection is made
+ * to allow the tether to be setup. A second notification will be show when a
+ * tether is active, allowing the user to manage tethered connections.
+ */
+public class TetherActivity extends AlertActivity implements
+ DialogInterface.OnClickListener {
+
+ private static final int POSITIVE_BUTTON = AlertDialog.BUTTON1;
+
+ /* Used to detect when the USB cable is unplugged, so we can call finish() */
+ private BroadcastReceiver mTetherReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent.getAction() == ConnectivityManager.ACTION_TETHER_STATE_CHANGED) {
+ handleTetherStateChanged(intent);
+ }
+ }
+ };
+
+ private boolean mWantTethering;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ // determine if we advertise tethering or untethering
+ ConnectivityManager cm =
+ (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
+ if (cm.getTetheredIfaces().length > 0) {
+ mWantTethering = false;
+ } else if (cm.getTetherableIfaces().length > 0) {
+ mWantTethering = true;
+ } else {
+ finish();
+ return;
+ }
+
+ // Set up the "dialog"
+ if (mWantTethering == true) {
+ mAlertParams.mIconId = com.android.internal.R.drawable.ic_dialog_usb;
+ mAlertParams.mTitle = getString(com.android.internal.R.string.tether_title);
+ mAlertParams.mMessage = getString(com.android.internal.R.string.tether_message);
+ mAlertParams.mPositiveButtonText =
+ getString(com.android.internal.R.string.tether_button);
+ mAlertParams.mPositiveButtonListener = this;
+ mAlertParams.mNegativeButtonText =
+ getString(com.android.internal.R.string.tether_button_cancel);
+ mAlertParams.mNegativeButtonListener = this;
+ } else {
+ mAlertParams.mIconId = com.android.internal.R.drawable.ic_dialog_usb;
+ mAlertParams.mTitle = getString(com.android.internal.R.string.tether_stop_title);
+ mAlertParams.mMessage = getString(com.android.internal.R.string.tether_stop_message);
+ mAlertParams.mPositiveButtonText =
+ getString(com.android.internal.R.string.tether_stop_button);
+ mAlertParams.mPositiveButtonListener = this;
+ mAlertParams.mNegativeButtonText =
+ getString(com.android.internal.R.string.tether_stop_button_cancel);
+ mAlertParams.mNegativeButtonListener = this;
+ }
+ setupAlert();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+
+ registerReceiver(mTetherReceiver, new IntentFilter(
+ ConnectivityManager.ACTION_TETHER_STATE_CHANGED));
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+
+ unregisterReceiver(mTetherReceiver);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void onClick(DialogInterface dialog, int which) {
+
+ if (which == POSITIVE_BUTTON) {
+ ConnectivityManager connManager =
+ (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
+ // start/stop tethering
+ if (mWantTethering) {
+ if (!connManager.tether("ppp0")) {
+ showTetheringError();
+ }
+ } else {
+ if (!connManager.untether("ppp0")) {
+ showUnTetheringError();
+ }
+ }
+ }
+ // No matter what, finish the activity
+ finish();
+ }
+
+ private void handleTetherStateChanged(Intent intent) {
+ finish();
+ }
+
+ private void showTetheringError() {
+ Toast.makeText(this, com.android.internal.R.string.tether_error_message,
+ Toast.LENGTH_LONG).show();
+ }
+
+ private void showUnTetheringError() {
+ Toast.makeText(this, com.android.internal.R.string.tether_stop_error_message,
+ Toast.LENGTH_LONG).show();
+ }
+
+}
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 665088a..1406b66 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -1239,6 +1239,10 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
+ <activity android:name="com.android.internal.app.TetherActivity"
+ android:theme="@style/Theme.Dialog.Alert"
+ android:excludeFromRecents="true">
+ </activity>
<activity android:name="com.android.internal.app.UsbStorageActivity"
android:excludeFromRecents="true">
</activity>
diff --git a/core/res/res/drawable-hdpi/stat_sys_tether_active.png b/core/res/res/drawable-hdpi/stat_sys_tether_active.png
new file mode 100755
index 0000000..4c14c07
--- /dev/null
+++ b/core/res/res/drawable-hdpi/stat_sys_tether_active.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/stat_sys_tether_usb.png b/core/res/res/drawable-hdpi/stat_sys_tether_usb.png
new file mode 100755
index 0000000..4c14c07
--- /dev/null
+++ b/core/res/res/drawable-hdpi/stat_sys_tether_usb.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/stat_sys_tether_active.png b/core/res/res/drawable-mdpi/stat_sys_tether_active.png
new file mode 100644
index 0000000..2d0da4c
--- /dev/null
+++ b/core/res/res/drawable-mdpi/stat_sys_tether_active.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/stat_sys_tether_usb.png b/core/res/res/drawable-mdpi/stat_sys_tether_usb.png
new file mode 100644
index 0000000..2d0da4c
--- /dev/null
+++ b/core/res/res/drawable-mdpi/stat_sys_tether_usb.png
Binary files differ
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 30d0da7..d1bfc68 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -1078,7 +1078,13 @@
<string name="permlab_changeNetworkState">change network connectivity</string>
<!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
<string name="permdesc_changeNetworkState">Allows an application to change
- the state network connectivity.</string>
+ the state of network connectivity.</string>
+
+ <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+ <string name="permlab_changeTetherState">change tethered connectivity</string>
+ <!-- Description of an application permission, listed so the user can choose whether they want to allow the applicaiton to do this. -->
+ <string name="permdesc_changeTetherState">Allows an application to change
+ the state of tethered network connectivity.</string>
<!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
<string name="permlab_changeBackgroundDataSetting">change background data usage setting</string>
@@ -2200,4 +2206,40 @@
Used by AccessibilityService to announce the purpose of the view.
-->
<string name="description_star">favorite</string>
+
+
+ <!-- Strings for Tethering dialogs -->
+ <!-- This is the label for the activity, and should never be visible to the user. -->
+ <!-- See TETHERING. TETHERING_DIALOG: After the user selects the notification, a dialog is shown asking if he wants to Tether. This is the title. -->
+ <string name="tether_title">USB tethering available</string>
+ <!-- See TETHER. This is the message. -->
+ <string name="tether_message">Select \"Tether\" if you want to share your phone\'s data connection with your computer.</string>
+ <!-- See TETHER. This is the button text to Tether the computer with the phone. -->
+ <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>
+ <!-- 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. -->
+ <string name="tether_available_notification_message">Select to tether your computer to your phone.</string>
+ <!-- TETHER_STOP: While TETHER is enabled, we show a notification dialog asking if he wants to stop. This is the title -->
+ <string name="tether_stop_notification_title">Untether</string>
+ <!-- See TETHER. This is the message. -->
+ <string name="tether_stop_notification_message">Select to untether your computer.</string>
+
+ <!-- TETHER stop dialog strings -->
+ <!-- This is the label for the activity, and should never be visible to the user. -->
+ <!-- See TETHER_STOP. TETHER_STOP_DIALOG: After the user selects the notification, a dialog is shown asking if he wants to stop tethering. This is the title. -->
+ <string name="tether_stop_title">Disconnect tethering</string>
+ <!-- See TETHER_STOP. This is the message. -->
+ <string name="tether_stop_message">You have been sharing your phone\'s cellular data connection with your computer. Select \"Disconnect\" to disconnect USB tethering.</string>
+ <!-- See TETHER_STOP. This is the button text to disconnect tethering. -->
+ <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. -->
+ <string name="tether_stop_error_message">We\'ve encountered a problem turning off Tethering. Please try again.</string>
+
</resources>