Remove Bluetooth tethering settings screen.

Remove obsolete Bluetooth tethering settings screen. BT tethering can
be turned on and off, but the connection must be initiated by the
remote device. For reverse tethering, there will be a checkbox for
that profile in the regular Bluetooth device settings screen.

Bug: 3283928
Change-Id: Ic25139f8862b305feb0381e61c24b7783fad2366
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 8bc4139..e18fdc3 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1728,9 +1728,6 @@
     <!-- Bluetooth Tethering settings.  Message for untethering from a bluetooth device [CHAR LIMIT=50]-->
     <string name="bluetooth_untether_blank"><xliff:g id="device_name">%1$s</xliff:g> will be untethered.</string>
 
-    <string name="bluetooth_tether_settings_text">Bluetooth tethering settings</string>
-    <string name="bluetooth_tether_settings_subtext">Select Bluetooth devices to tether</string>
-
     <!-- Tethering help button - calls up a web view with general tethering info -->
     <string name="tethering_help_button_text">Help</string>
 
diff --git a/res/xml/tether_prefs.xml b/res/xml/tether_prefs.xml
index d475a14..f16200d 100644
--- a/res/xml/tether_prefs.xml
+++ b/res/xml/tether_prefs.xml
@@ -38,15 +38,6 @@
         android:title="@string/bluetooth_tether_checkbox_text"
         android:persistent="false" />
 
-    <!-- BluetoothSettings will have extra argument to know this request is
-         for tethering, not for BT setting in general. -->
-    <PreferenceScreen
-        android:fragment="com.android.settings.bluetooth.BluetoothSettings"
-        android:key="bluetooth_tether_settings"
-        android:title="@string/bluetooth_tether_settings_text"
-        android:summary="@string/bluetooth_tether_settings_subtext" >
-    </PreferenceScreen>
-
     <PreferenceScreen
         android:key="tethering_help"
         android:title="@string/tethering_help_button_text" >
diff --git a/src/com/android/settings/TetherSettings.java b/src/com/android/settings/TetherSettings.java
index bc27dc0..81d23ab 100644
--- a/src/com/android/settings/TetherSettings.java
+++ b/src/com/android/settings/TetherSettings.java
@@ -51,7 +51,6 @@
     private static final String ENABLE_WIFI_AP = "enable_wifi_ap";
     private static final String WIFI_AP_SETTINGS = "wifi_ap_settings";
     private static final String ENABLE_BLUETOOTH_TETHERING = "enable_bluetooth_tethering";
-    private static final String BLUETOOTH_TETHER_SETTINGS = "bluetooth_tether_settings";
     private static final String TETHERING_HELP = "tethering_help";
     private static final String USB_HELP_MODIFIER = "usb_";
     private static final String WIFI_HELP_MODIFIER = "wifi_";
@@ -68,7 +67,6 @@
     private WifiApEnabler mWifiApEnabler;
 
     private CheckBoxPreference mBluetoothTether;
-    private PreferenceScreen mBluetoothSettings;
 
     private PreferenceScreen mTetherHelp;
 
@@ -97,7 +95,6 @@
         mWifiApSettings = (PreferenceScreen) findPreference(WIFI_AP_SETTINGS);
         mUsbTether = (CheckBoxPreference) findPreference(USB_TETHER_SETTINGS);
         mBluetoothTether = (CheckBoxPreference) findPreference(ENABLE_BLUETOOTH_TETHERING);
-        mBluetoothSettings = (PreferenceScreen) findPreference(BLUETOOTH_TETHER_SETTINGS);
         mTetherHelp = (PreferenceScreen) findPreference(TETHERING_HELP);
 
         ConnectivityManager cm =
@@ -121,14 +118,11 @@
         }
         if (!bluetoothAvailable) {
             getPreferenceScreen().removePreference(mBluetoothTether);
-            getPreferenceScreen().removePreference(mBluetoothSettings);
         } else {
             if (mBluetoothPan.isTetheringOn()) {
                 mBluetoothTether.setChecked(true);
-                mBluetoothSettings.setEnabled(true);
             } else {
                 mBluetoothTether.setChecked(false);
-                mBluetoothSettings.setEnabled(false);
             }
         }
         /* Don't change the title for two-pane settings
@@ -360,17 +354,14 @@
         int btState = adapter.getState();
         if (btState == BluetoothAdapter.STATE_TURNING_OFF) {
             mBluetoothTether.setEnabled(false);
-            mBluetoothSettings.setEnabled(false);
             mBluetoothTether.setSummary(R.string.wifi_stopping);
         } else if (btState == BluetoothAdapter.STATE_TURNING_ON) {
             mBluetoothTether.setEnabled(false);
-            mBluetoothSettings.setEnabled(false);
             mBluetoothTether.setSummary(R.string.bluetooth_turning_on);
         } else if (mBluetoothPan.isTetheringOn()) {
             mBluetoothTether.setChecked(true);
             if (btState == BluetoothAdapter.STATE_ON) {
                 mBluetoothTether.setEnabled(true);
-                mBluetoothSettings.setEnabled(true);
                 if (bluetoothTethered) {
                     mBluetoothTether.setSummary(R.string.bluetooth_tethering_connected_subtext);
                 } else if (bluetoothErrored) {
@@ -382,7 +373,6 @@
         } else {
             mBluetoothTether.setEnabled(true);
             mBluetoothTether.setChecked(false);
-            mBluetoothSettings.setEnabled(false);
             mBluetoothTether.setSummary(R.string.bluetooth_tethering_off_subtext);
         }
     }
@@ -433,9 +423,6 @@
                     adapter.enable();
                     mBluetoothTether.setSummary(R.string.bluetooth_turning_on);
                     mBluetoothTether.setEnabled(false);
-                    mBluetoothSettings.setEnabled(false);
-                } else {
-                    mBluetoothSettings.setEnabled(true);
                 }
 
                 mBluetoothPan.setBluetoothTethering(true);
@@ -453,16 +440,12 @@
                 }
 
                 mBluetoothPan.setBluetoothTethering(false);
-                mBluetoothSettings.setEnabled(false);
                 if (errored) {
                     mBluetoothTether.setSummary(R.string.bluetooth_tethering_errored_subtext);
                 } else {
                     mBluetoothTether.setSummary(R.string.bluetooth_tethering_off_subtext);
                 }
             }
-        } else if (preference == mBluetoothSettings) {
-            preference.getExtras().putString(BluetoothSettings.ACTION,
-                    BluetoothSettings.ACTION_LAUNCH_TETHER_PICKER);
         } else if (preference == mTetherHelp) {
             showDialog(DIALOG_TETHER_HELP);
             return true;
diff --git a/src/com/android/settings/bluetooth/BluetoothEventRedirector.java b/src/com/android/settings/bluetooth/BluetoothEventRedirector.java
index 3042e3d..57e359d 100644
--- a/src/com/android/settings/bluetooth/BluetoothEventRedirector.java
+++ b/src/com/android/settings/bluetooth/BluetoothEventRedirector.java
@@ -142,6 +142,8 @@
                         Profile.HID, newState);
 
             } else if (action.equals(BluetoothPan.ACTION_PAN_STATE_CHANGED)) {
+                // TODO: uncomment and execute for reverse tethering only
+/*
                 final int newState = intent.getIntExtra(
                         BluetoothPan.EXTRA_PAN_STATE, 0);
                 final int oldState = intent.getIntExtra(
@@ -152,6 +154,7 @@
                 }
                 mManager.getCachedDeviceManager().onProfileStateChanged(device,
                         Profile.PAN, newState);
+*/
 
             } else if (action.equals(BluetoothDevice.ACTION_CLASS_CHANGED)) {
                 mManager.getCachedDeviceManager().onBtClassChanged(device);
diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java
index aae1311..89efd72 100644
--- a/src/com/android/settings/bluetooth/BluetoothSettings.java
+++ b/src/com/android/settings/bluetooth/BluetoothSettings.java
@@ -42,6 +42,7 @@
 import android.preference.PreferenceCategory;
 import android.preference.PreferenceScreen;
 import android.text.TextUtils;
+import android.util.Log;
 import android.view.View;
 
 import java.util.List;
@@ -65,24 +66,21 @@
 
     private static final int SCREEN_TYPE_SETTINGS = 0;
     private static final int SCREEN_TYPE_DEVICEPICKER = 1;
-    private static final int SCREEN_TYPE_TETHERING = 2;
-    private static final int SCREEN_TYPE_SCAN = 3;
+    private static final int SCREEN_TYPE_SCAN = 2;
 
     public static final String ACTION = "bluetooth_action";
-    public static final String ACTION_LAUNCH_TETHER_PICKER =
-            "com.android.settings.bluetooth.action.LAUNCH_TETHER_PICKER";
     public static final String ACTION_LAUNCH_SCAN_MODE =
             "com.android.settings.bluetooth.action.LAUNCH_SCAN_MODE";
 
-    private int mScreenType;
+    /*package*/ int mScreenType;
     private int mFilterType;
     private boolean mNeedAuth;
     private String mLaunchPackage;
     private String mLaunchClass;
 
-    private BluetoothDevice mSelectedDevice= null;
+    /*package*/ BluetoothDevice mSelectedDevice= null;
 
-    private LocalBluetoothManager mLocalManager;
+    /*package*/ LocalBluetoothManager mLocalManager;
 
     private BluetoothEnabler mEnabler;
     private BluetoothDiscoverableEnabler mDiscoverableEnabler;
@@ -111,8 +109,6 @@
                         if (mScreenType == SCREEN_TYPE_DEVICEPICKER) {
                             sendDevicePickedIntent(device);
                             finish();
-                        } else if (mScreenType == SCREEN_TYPE_TETHERING) {
-                            onPanDevicePicked();
                         } else if (mScreenType == SCREEN_TYPE_SCAN) {
                             finish();
                         }
@@ -168,12 +164,6 @@
 
             activity.setTitle(activity.getString(R.string.device_picker));
             addPreferencesFromResource(R.xml.device_picker);
-        } else if (action.equals(ACTION_LAUNCH_TETHER_PICKER)) {
-            mScreenType = SCREEN_TYPE_TETHERING;
-            mFilterType = BluetoothDevicePicker.FILTER_TYPE_PANU;
-
-            activity.setTitle(activity.getString(R.string.device_picker));
-            addPreferencesFromResource(R.xml.device_picker);
         } else if (action.equals(ACTION_LAUNCH_SCAN_MODE)) {
             mScreenType = SCREEN_TYPE_SCAN;
 
@@ -293,15 +283,9 @@
                 } else {
                     btPreference.getCachedDevice().onClicked();
                 }
-            } else if (mScreenType == SCREEN_TYPE_TETHERING) {
-                mLocalManager.stopScanning();
-                mLocalManager.persistSelectedDeviceInPicker(mSelectedDevice.getAddress());
-                if ((device.getBondState() == BluetoothDevice.BOND_BONDED)) {
-                    onPanDevicePicked();
-                    // don't call finish so that users can see it connecting
-                } else {
-                    btPreference.getCachedDevice().onClicked();
-                }
+            } else {
+                Log.e(TAG, "onPreferenceTreeClick has invalid mScreenType: "
+                        + mScreenType);
             }
             return true;
         }
@@ -391,14 +375,10 @@
     }
 
     private void createDevicePreference(CachedBluetoothDevice cachedDevice) {
-        BluetoothDevicePreference preference;
-        if (mScreenType == SCREEN_TYPE_TETHERING) {
-            preference = new BluetoothDevicePreference(
-                    getActivity(), cachedDevice, CachedBluetoothDevice.PAN_PROFILE);
-        } else {
-            preference = new BluetoothDevicePreference(
-                    getActivity(), cachedDevice, CachedBluetoothDevice.OTHER_PROFILES);
-        }
+        BluetoothDevicePreference preference = new BluetoothDevicePreference(
+                getActivity(), cachedDevice,
+                CachedBluetoothDevice.OTHER_PROFILES);
+
         if (mScreenType == SCREEN_TYPE_SETTINGS) {
             preference.setOnSettingsClickListener(this);
         }
@@ -422,7 +402,8 @@
             ((ProgressCategory) mDeviceList).setProgress(start);
         }
     }
-    private void onBluetoothStateChanged(int bluetoothState) {
+
+    /*package*/ void onBluetoothStateChanged(int bluetoothState) {
         // When bluetooth is enabled (and we are in the activity, which we are),
         // we should start a scan
         if (bluetoothState == BluetoothAdapter.STATE_ON) {
@@ -434,47 +415,7 @@
         }
     }
 
-    private void onPanDevicePicked() {
-        final Activity activity = getActivity();
-        final LocalBluetoothProfileManager profileManager =
-            LocalBluetoothProfileManager.getProfileManager(mLocalManager, Profile.PAN);
-        int status = profileManager.getConnectionStatus(mSelectedDevice);
-        if (SettingsBtStatus.isConnectionStatusConnected(status)) {
-            String name = mSelectedDevice.getName();
-            if (TextUtils.isEmpty(name)) {
-                name = activity.getString(R.string.bluetooth_device);
-            }
-            String message = activity.getString(R.string.bluetooth_untether_blank, name);
-            DialogInterface.OnClickListener disconnectListener =
-                new DialogInterface.OnClickListener() {
-                public void onClick(DialogInterface dialog, int which) {
-                    profileManager.disconnect(mSelectedDevice);
-                }
-            };
-            new AlertDialog.Builder(activity)
-                .setTitle(name)
-                .setMessage(message)
-                .setPositiveButton(android.R.string.ok, disconnectListener)
-                .setNegativeButton(android.R.string.cancel, null)
-                .create()
-                .show();
-        } else if (status == SettingsBtStatus.CONNECTION_STATUS_DISCONNECTED) {
-            if (profileManager.getConnectedDevices().size() >= BluetoothPan.MAX_CONNECTIONS) {
-                new AlertDialog.Builder(activity)
-                    .setIcon(android.R.drawable.ic_dialog_alert)
-                    .setTitle(R.string.bluetooth_error_title)
-                    .setMessage(activity.getString(R.string.bluetooth_tethering_overflow_error,
-                            BluetoothPan.MAX_CONNECTIONS))
-                    .setNegativeButton(android.R.string.ok, null)
-                    .create()
-                    .show();
-                return;
-            }
-            profileManager.connect(mSelectedDevice);
-        }
-    }
-
-    private void sendDevicePickedIntent(BluetoothDevice device) {
+    /*package*/ void sendDevicePickedIntent(BluetoothDevice device) {
         Intent intent = new Intent(BluetoothDevicePicker.ACTION_DEVICE_SELECTED);
         intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
         if (mScreenType == SCREEN_TYPE_DEVICEPICKER &&