Enable reverse tethering in BT settings screen.

- Enable support for reverse tethering in BT settings.
- Add string resource for "Auto connect" preference.
- Remove unused imports and other minor cleanups.
- Add isConnectable() and isAutoConnectable() methods to Profile
  enum type and remove isConnectableProfile() method.

Change-Id: Ie606db04028a8278e98231f0671a388671f2f067
This commit is contained in:
Jake Hamby
2010-12-16 18:33:28 -08:00
parent 9757e30dfa
commit 39ef225e7c
16 changed files with 100 additions and 126 deletions

View File

@@ -254,6 +254,9 @@
<!-- Strings for msg to display to user while bluetooth is turning on --> <!-- Strings for msg to display to user while bluetooth is turning on -->
<string name="bluetooth_turning_on">"Turning on Bluetooth\u2026"</string> <string name="bluetooth_turning_on">"Turning on Bluetooth\u2026"</string>
<!-- Strings for device profile auto connect setting -->
<string name="bluetooth_auto_connect">Auto connect</string>
<!-- Date & time settings screen title --> <!-- Date & time settings screen title -->
<string name="date_and_time">Date &amp; time settings</string> <string name="date_and_time">Date &amp; time settings</string>
<!-- Date/time settings. Summary of the checkbox for choosing between 12 hour time or 24 hour time. Sample of 12-hour time --> <!-- Date/time settings. Summary of the checkbox for choosing between 12 hour time or 24 hour time. Sample of 12-hour time -->
@@ -809,19 +812,6 @@
<!-- Bluetooth settings. The user-visible string that is used whenever referring to the PAN profile. [CHAR LIMIT=25]--> <!-- Bluetooth settings. The user-visible string that is used whenever referring to the PAN profile. [CHAR LIMIT=25]-->
<string name="bluetooth_profile_pan">Tethering</string> <string name="bluetooth_profile_pan">Tethering</string>
<!-- Bluetooth settings. The summary string when a device is connected to the A2DP profile. -->
<string name="bluetooth_summary_connected_to_a2dp">Connected to media audio</string>
<!-- Bluetooth settings. The summary string when a device is connected to the headset profile. -->
<string name="bluetooth_summary_connected_to_headset" product="tablet">Connected to tablet audio</string>
<!-- Bluetooth settings. The summary string when a device is connected to the headset profile. -->
<string name="bluetooth_summary_connected_to_headset" product="default">Connected to phone audio</string>
<!-- Bluetooth settings. The summary string when a device is connected to the A2DP and headset profiles. -->
<string name="bluetooth_summary_connected_to_a2dp_headset">Connected to phone and media audio</string>
<!-- Bluetooth settings. The summary string when a device is connected to the HID profile. -->
<string name="bluetooth_summary_connected_to_hid">Connected to input device</string>
<!-- Bluetooth settings. The summary string when a device is connected to the PAN profile. [CHAR LIMIT=35]-->
<string name="bluetooth_summary_connected_to_pan">Tethered</string>
<!-- Bluetooth settings. Message for disconnecting from the A2DP profile. --> <!-- Bluetooth settings. Message for disconnecting from the A2DP profile. -->
<string name="bluetooth_disconnect_a2dp_profile"><xliff:g id="device_name">%1$s</xliff:g> will be disconnected from media audio.</string> <string name="bluetooth_disconnect_a2dp_profile"><xliff:g id="device_name">%1$s</xliff:g> will be disconnected from media audio.</string>
<!-- Bluetooth settings. Message for disconnecting from the headset profile. --> <!-- Bluetooth settings. Message for disconnecting from the headset profile. -->
@@ -868,6 +858,10 @@
for the HID checkbox preference that describes how checking it for the HID checkbox preference that describes how checking it
will set the HID profile as preferred. --> will set the HID profile as preferred. -->
<string name="bluetooth_hid_profile_summary_use_for">Use for input</string> <string name="bluetooth_hid_profile_summary_use_for">Use for input</string>
<!-- Bluetooth settings. Connection options screen. The summary
for the PAN checkbox preference that describes how checking it
will set the PAN profile as preferred. -->
<string name="bluetooth_pan_profile_summary_use_for">Use for Internet access</string>
<!-- Bluetooth settings. Dock Setting Title --> <!-- Bluetooth settings. Dock Setting Title -->
<string name="bluetooth_dock_settings">Dock Settings</string> <string name="bluetooth_dock_settings">Dock Settings</string>

View File

@@ -53,7 +53,6 @@ public class DockSettings extends SettingsPreferenceFragment {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
ContentResolver resolver = getContentResolver();
addPreferencesFromResource(R.xml.dock_settings); addPreferencesFromResource(R.xml.dock_settings);
initDockSettings(); initDockSettings();

View File

@@ -42,8 +42,7 @@ public class BluetoothDevicePreference extends Preference implements
private static int sDimAlpha = Integer.MIN_VALUE; private static int sDimAlpha = Integer.MIN_VALUE;
private CachedBluetoothDevice mCachedDevice; private final CachedBluetoothDevice mCachedDevice;
private int mAccessibleProfile;
private ImageView mDeviceSettings; private ImageView mDeviceSettings;
@@ -55,8 +54,7 @@ public class BluetoothDevicePreference extends Preference implements
*/ */
private boolean mIsBusy; private boolean mIsBusy;
public BluetoothDevicePreference(Context context, CachedBluetoothDevice cachedDevice, public BluetoothDevicePreference(Context context, CachedBluetoothDevice cachedDevice) {
int accessibleProfile) {
super(context); super(context);
if (sDimAlpha == Integer.MIN_VALUE) { if (sDimAlpha == Integer.MIN_VALUE) {
@@ -66,7 +64,6 @@ public class BluetoothDevicePreference extends Preference implements
} }
mCachedDevice = cachedDevice; mCachedDevice = cachedDevice;
mAccessibleProfile = accessibleProfile;
setWidgetLayoutResource(R.layout.preference_bluetooth); setWidgetLayoutResource(R.layout.preference_bluetooth);

View File

@@ -27,7 +27,6 @@ import android.content.IntentFilter;
import android.preference.Preference; import android.preference.Preference;
import android.preference.CheckBoxPreference; import android.preference.CheckBoxPreference;
import android.provider.Settings; import android.provider.Settings;
import android.text.TextUtils;
import android.widget.Toast; import android.widget.Toast;
/** /**

View File

@@ -44,7 +44,7 @@ import java.util.concurrent.TimeUnit;
* API and dispatches the event on the UI thread to the right class in the * API and dispatches the event on the UI thread to the right class in the
* Settings. * Settings.
*/ */
public class BluetoothEventRedirector { class BluetoothEventRedirector {
private static final String TAG = "BluetoothEventRedirector"; private static final String TAG = "BluetoothEventRedirector";
/* package */ final LocalBluetoothManager mManager; /* package */ final LocalBluetoothManager mManager;
@@ -142,8 +142,9 @@ public class BluetoothEventRedirector {
Profile.HID, newState); Profile.HID, newState);
} else if (action.equals(BluetoothPan.ACTION_PAN_STATE_CHANGED)) { } else if (action.equals(BluetoothPan.ACTION_PAN_STATE_CHANGED)) {
// TODO: uncomment and execute for reverse tethering only final int role = intent.getIntExtra(
/* BluetoothPan.EXTRA_LOCAL_ROLE, 0);
if (role == BluetoothPan.LOCAL_PANU_ROLE) {
final int newState = intent.getIntExtra( final int newState = intent.getIntExtra(
BluetoothPan.EXTRA_PAN_STATE, 0); BluetoothPan.EXTRA_PAN_STATE, 0);
final int oldState = intent.getIntExtra( final int oldState = intent.getIntExtra(
@@ -154,8 +155,7 @@ public class BluetoothEventRedirector {
} }
mManager.getCachedDeviceManager().onProfileStateChanged(device, mManager.getCachedDeviceManager().onProfileStateChanged(device,
Profile.PAN, newState); Profile.PAN, newState);
*/ }
} else if (action.equals(BluetoothDevice.ACTION_CLASS_CHANGED)) { } else if (action.equals(BluetoothDevice.ACTION_CLASS_CHANGED)) {
mManager.getCachedDeviceManager().onBtClassChanged(device); mManager.getCachedDeviceManager().onBtClassChanged(device);
@@ -164,7 +164,7 @@ public class BluetoothEventRedirector {
} else if (action.equals(BluetoothDevice.ACTION_PAIRING_CANCEL)) { } else if (action.equals(BluetoothDevice.ACTION_PAIRING_CANCEL)) {
int errorMsg = R.string.bluetooth_pairing_error_message; int errorMsg = R.string.bluetooth_pairing_error_message;
mManager.showError(device, R.string.bluetooth_error_title, errorMsg); mManager.showError(device, errorMsg);
} else if (action.equals(Intent.ACTION_DOCK_EVENT)) { } else if (action.equals(Intent.ACTION_DOCK_EVENT)) {
// Remove if unpair device upon undocking // Remove if unpair device upon undocking
@@ -183,7 +183,7 @@ public class BluetoothEventRedirector {
mManager = localBluetoothManager; mManager = localBluetoothManager;
} }
public void start() { public void registerReceiver() {
IntentFilter filter = new IntentFilter(); IntentFilter filter = new IntentFilter();
// Bluetooth on/off broadcasts // Bluetooth on/off broadcasts

View File

@@ -22,9 +22,7 @@ import com.android.settings.R;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.preference.Preference; import android.preference.Preference;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.ImageView; import android.widget.ImageView;
@@ -39,7 +37,7 @@ public class BluetoothProfilePreference extends Preference implements OnClickLis
private Drawable mProfileDrawable; private Drawable mProfileDrawable;
private boolean mExpanded; private boolean mExpanded;
private ImageView mProfileExpandView; private ImageView mProfileExpandView;
private Profile mProfile; private final Profile mProfile;
private OnClickListener mOnExpandClickListener; private OnClickListener mOnExpandClickListener;
@@ -77,12 +75,16 @@ public class BluetoothProfilePreference extends Preference implements OnClickLis
btProfile.setImageDrawable(mProfileDrawable); btProfile.setImageDrawable(mProfileDrawable);
mProfileExpandView = (ImageView) view.findViewById(R.id.profileExpand); mProfileExpandView = (ImageView) view.findViewById(R.id.profileExpand);
if (mProfile == Profile.PAN) {
mProfileExpandView.setVisibility(View.GONE);
} else {
mProfileExpandView.setOnClickListener(this); mProfileExpandView.setOnClickListener(this);
mProfileExpandView.setTag(mProfile); mProfileExpandView.setTag(mProfile);
mProfileExpandView.setImageResource(mExpanded ? R.drawable.ic_preferences_expanded mProfileExpandView.setImageResource(mExpanded ? R.drawable.ic_preferences_expanded
: R.drawable.ic_preferences_collapsed); : R.drawable.ic_preferences_collapsed);
} }
}
public void onClick(View v) { public void onClick(View v) {
if (v == mProfileExpandView) { if (v == mProfileExpandView) {

View File

@@ -16,23 +16,19 @@
package com.android.settings.bluetooth; package com.android.settings.bluetooth;
import com.android.settings.bluetooth.LocalBluetoothProfileManager.Profile;
import com.android.settings.ProgressCategory; import com.android.settings.ProgressCategory;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment; import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.UserLeaveHintListener; import com.android.settings.UserLeaveHintListener;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevicePicker; import android.bluetooth.BluetoothDevicePicker;
import android.bluetooth.BluetoothPan;
import android.bluetooth.BluetoothUuid; import android.bluetooth.BluetoothUuid;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.os.Bundle; import android.os.Bundle;
@@ -62,7 +58,6 @@ public class BluetoothSettings extends SettingsPreferenceFragment
private static final String KEY_BT_DEVICE_LIST = "bt_device_list"; private static final String KEY_BT_DEVICE_LIST = "bt_device_list";
private static final String KEY_BT_NAME = "bt_name"; private static final String KEY_BT_NAME = "bt_name";
private static final String KEY_BT_SCAN = "bt_scan"; private static final String KEY_BT_SCAN = "bt_scan";
private static final String KEY_BT_FIND_NEARBY = "bt_find_nearby";
private static final int SCREEN_TYPE_SETTINGS = 0; private static final int SCREEN_TYPE_SETTINGS = 0;
private static final int SCREEN_TYPE_DEVICEPICKER = 1; private static final int SCREEN_TYPE_DEVICEPICKER = 1;
@@ -118,11 +113,6 @@ public class BluetoothSettings extends SettingsPreferenceFragment
} }
}; };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
// We delay calling super.onActivityCreated(). See WifiSettings.java for more info. // We delay calling super.onActivityCreated(). See WifiSettings.java for more info.
@@ -376,8 +366,7 @@ public class BluetoothSettings extends SettingsPreferenceFragment
private void createDevicePreference(CachedBluetoothDevice cachedDevice) { private void createDevicePreference(CachedBluetoothDevice cachedDevice) {
BluetoothDevicePreference preference = new BluetoothDevicePreference( BluetoothDevicePreference preference = new BluetoothDevicePreference(
getActivity(), cachedDevice, getActivity(), cachedDevice);
CachedBluetoothDevice.OTHER_PROFILES);
if (mScreenType == SCREEN_TYPE_SETTINGS) { if (mScreenType == SCREEN_TYPE_SETTINGS) {
preference.setOnSettingsClickListener(this); preference.setOnSettingsClickListener(this);

View File

@@ -25,7 +25,6 @@ import android.app.AlertDialog;
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothUuid;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.res.Resources; import android.content.res.Resources;
@@ -36,8 +35,6 @@ import android.preference.Preference;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@@ -50,15 +47,12 @@ import java.util.Map;
* functionality that can be performed on the device (connect, pair, disconnect, * functionality that can be performed on the device (connect, pair, disconnect,
* etc.). * etc.).
*/ */
public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> { class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
private static final String TAG = "CachedBluetoothDevice"; private static final String TAG = "CachedBluetoothDevice";
private static final boolean D = LocalBluetoothManager.D; private static final boolean D = LocalBluetoothManager.D;
private static final boolean V = LocalBluetoothManager.V; private static final boolean V = LocalBluetoothManager.V;
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
public static final int PAN_PROFILE = 1;
public static final int OTHER_PROFILES = 2;
private final BluetoothDevice mDevice; private final BluetoothDevice mDevice;
private String mName; private String mName;
private short mRssi; private short mRssi;
@@ -275,7 +269,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
mConnectAttempted = SystemClock.elapsedRealtime(); mConnectAttempted = SystemClock.elapsedRealtime();
connectWithoutResettingTimer(); connectWithoutResettingTimer(true);
} }
/*package*/ void onBondingDockConnect() { /*package*/ void onBondingDockConnect() {
@@ -284,7 +278,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
connect(); connect();
} }
private void connectWithoutResettingTimer() { private void connectWithoutResettingTimer(boolean connectAllProfiles) {
// Try to initialize the profiles if there were not. // Try to initialize the profiles if there were not.
if (mProfiles.size() == 0) { if (mProfiles.size() == 0) {
if (!updateProfiles()) { if (!updateProfiles()) {
@@ -300,7 +294,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
int preferredProfiles = 0; int preferredProfiles = 0;
for (Profile profile : mProfiles) { for (Profile profile : mProfiles) {
if (isConnectableProfile(profile)) { if (connectAllProfiles ? profile.isConnectable() : profile.isAutoConnectable()) {
LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager
.getProfileManager(mLocalManager, profile); .getProfileManager(mLocalManager, profile);
if (profileManager.isPreferred(mDevice)) { if (profileManager.isPreferred(mDevice)) {
@@ -313,18 +307,18 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
if (DEBUG) Log.d(TAG, "Preferred profiles = " + preferredProfiles); if (DEBUG) Log.d(TAG, "Preferred profiles = " + preferredProfiles);
if (preferredProfiles == 0) { if (preferredProfiles == 0) {
connectAllProfiles(); connectAllAutoConnectableProfiles();
} }
} }
private void connectAllProfiles() { private void connectAllAutoConnectableProfiles() {
if (!ensurePaired()) return; if (!ensurePaired()) return;
// Reset the only-show-one-error-dialog tracking variable // Reset the only-show-one-error-dialog tracking variable
mIsConnectingErrorPossible = true; mIsConnectingErrorPossible = true;
for (Profile profile : mProfiles) { for (Profile profile : mProfiles) {
if (isConnectableProfile(profile)) { if (profile.isAutoConnectable()) {
LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager
.getProfileManager(mLocalManager, profile); .getProfileManager(mLocalManager, profile);
profileManager.setPreferred(mDevice, true); profileManager.setPreferred(mDevice, true);
@@ -378,7 +372,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
if (!mIsConnectingErrorPossible) return; if (!mIsConnectingErrorPossible) return;
mIsConnectingErrorPossible = false; mIsConnectingErrorPossible = false;
mLocalManager.showError(mDevice, R.string.bluetooth_error_title, mLocalManager.showError(mDevice,
R.string.bluetooth_connecting_error_message); R.string.bluetooth_connecting_error_message);
} }
@@ -400,7 +394,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
} }
if (!mDevice.createBond()) { if (!mDevice.createBond()) {
mLocalManager.showError(mDevice, R.string.bluetooth_error_title, mLocalManager.showError(mDevice,
R.string.bluetooth_pairing_error_message); R.string.bluetooth_pairing_error_message);
return; return;
} }
@@ -635,7 +629,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
if (mProfiles.size() > 0 if (mProfiles.size() > 0
&& (mConnectAttempted + MAX_UUID_DELAY_FOR_AUTO_CONNECT) > SystemClock && (mConnectAttempted + MAX_UUID_DELAY_FOR_AUTO_CONNECT) > SystemClock
.elapsedRealtime()) { .elapsedRealtime()) {
connectWithoutResettingTimer(); connectWithoutResettingTimer(false);
} }
dispatchAttributesChanged(); dispatchAttributesChanged();
} }
@@ -699,18 +693,13 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
public List<Profile> getConnectableProfiles() { public List<Profile> getConnectableProfiles() {
ArrayList<Profile> connectableProfiles = new ArrayList<Profile>(); ArrayList<Profile> connectableProfiles = new ArrayList<Profile>();
for (Profile profile : mProfiles) { for (Profile profile : mProfiles) {
if (isConnectableProfile(profile)) { if (profile.isConnectable()) {
connectableProfiles.add(profile); connectableProfiles.add(profile);
} }
} }
return connectableProfiles; return connectableProfiles;
} }
private boolean isConnectableProfile(Profile profile) {
return profile.equals(Profile.HEADSET) || profile.equals(Profile.A2DP) ||
profile.equals(Profile.HID);
}
public void onClickedAdvancedOptions(SettingsPreferenceFragment fragment) { public void onClickedAdvancedOptions(SettingsPreferenceFragment fragment) {
// TODO: Verify if there really is a case when there's no foreground // TODO: Verify if there really is a case when there's no foreground
// activity // activity

View File

@@ -32,7 +32,7 @@ import java.util.Set;
/** /**
* CachedBluetoothDeviceManager manages the set of remote Bluetooth devices. * CachedBluetoothDeviceManager manages the set of remote Bluetooth devices.
*/ */
public class CachedBluetoothDeviceManager { class CachedBluetoothDeviceManager {
private static final String TAG = "CachedBluetoothDeviceManager"; private static final String TAG = "CachedBluetoothDeviceManager";
final LocalBluetoothManager mLocalManager; final LocalBluetoothManager mLocalManager;
@@ -207,22 +207,22 @@ public class CachedBluetoothDeviceManager {
switch(reason) { switch(reason) {
case BluetoothDevice.UNBOND_REASON_AUTH_FAILED: case BluetoothDevice.UNBOND_REASON_AUTH_FAILED:
errorMsg = R.string.bluetooth_pairing_pin_error_message; errorMsg = R.string.bluetooth_pairing_pin_error_message;
mLocalManager.showError(device, R.string.bluetooth_error_title, errorMsg); mLocalManager.showError(device, errorMsg);
break; break;
case BluetoothDevice.UNBOND_REASON_AUTH_REJECTED: case BluetoothDevice.UNBOND_REASON_AUTH_REJECTED:
errorMsg = R.string.bluetooth_pairing_rejected_error_message; errorMsg = R.string.bluetooth_pairing_rejected_error_message;
mLocalManager.showError(device, R.string.bluetooth_error_title, errorMsg); mLocalManager.showError(device, errorMsg);
break; break;
case BluetoothDevice.UNBOND_REASON_REMOTE_DEVICE_DOWN: case BluetoothDevice.UNBOND_REASON_REMOTE_DEVICE_DOWN:
errorMsg = R.string.bluetooth_pairing_device_down_error_message; errorMsg = R.string.bluetooth_pairing_device_down_error_message;
mLocalManager.showError(device, R.string.bluetooth_error_title, errorMsg); mLocalManager.showError(device, errorMsg);
break; break;
case BluetoothDevice.UNBOND_REASON_DISCOVERY_IN_PROGRESS: case BluetoothDevice.UNBOND_REASON_DISCOVERY_IN_PROGRESS:
case BluetoothDevice.UNBOND_REASON_AUTH_TIMEOUT: case BluetoothDevice.UNBOND_REASON_AUTH_TIMEOUT:
case BluetoothDevice.UNBOND_REASON_REPEATED_ATTEMPTS: case BluetoothDevice.UNBOND_REASON_REPEATED_ATTEMPTS:
case BluetoothDevice.UNBOND_REASON_REMOTE_AUTH_CANCELED: case BluetoothDevice.UNBOND_REASON_REMOTE_AUTH_CANCELED:
errorMsg = R.string.bluetooth_pairing_error_message; errorMsg = R.string.bluetooth_pairing_error_message;
mLocalManager.showError(device, R.string.bluetooth_error_title, errorMsg); mLocalManager.showError(device, errorMsg);
break; break;
default: default:
Log.w(TAG, "showUnbondMessage: Not displaying any message for reason:" + reason); Log.w(TAG, "showUnbondMessage: Not displaying any message for reason:" + reason);

View File

@@ -20,9 +20,7 @@ import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment; import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.bluetooth.LocalBluetoothProfileManager.Profile; import com.android.settings.bluetooth.LocalBluetoothProfileManager.Profile;
import android.app.FragmentTransaction;
import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.os.Bundle; import android.os.Bundle;
import android.preference.CheckBoxPreference; import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference; import android.preference.EditTextPreference;
@@ -59,7 +57,7 @@ public class DeviceProfilesSettings extends SettingsPreferenceFragment
private PreferenceGroup mProfileContainer; private PreferenceGroup mProfileContainer;
private CheckBoxPreference mAllowIncomingPref; private CheckBoxPreference mAllowIncomingPref;
private EditTextPreference mDeviceNamePref; private EditTextPreference mDeviceNamePref;
private HashMap<String,CheckBoxPreference> mAutoConnectPrefs private final HashMap<String,CheckBoxPreference> mAutoConnectPrefs
= new HashMap<String,CheckBoxPreference>(); = new HashMap<String,CheckBoxPreference>();
@Override @Override
@@ -156,6 +154,14 @@ public class DeviceProfilesSettings extends SettingsPreferenceFragment
pref.setOrder(getProfilePreferenceIndex(profile)); pref.setOrder(getProfilePreferenceIndex(profile));
pref.setOnExpandClickListener(this); pref.setOnExpandClickListener(this);
LocalBluetoothProfileManager profileManager =
LocalBluetoothProfileManager.getProfileManager(mManager, profile);
int iconResource = profileManager.getDrawableResource();
if (iconResource != 0) {
pref.setProfileDrawable(mManager.getContext()
.getResources().getDrawable(iconResource));
}
/** /**
* Gray out profile while connecting and disconnecting * Gray out profile while connecting and disconnecting
*/ */
@@ -302,6 +308,8 @@ public class DeviceProfilesSettings extends SettingsPreferenceFragment
return R.string.bluetooth_headset_profile_summary_use_for; return R.string.bluetooth_headset_profile_summary_use_for;
case HID: case HID:
return R.string.bluetooth_hid_profile_summary_use_for; return R.string.bluetooth_hid_profile_summary_use_for;
case PAN:
return R.string.bluetooth_pan_profile_summary_use_for;
default: default:
return 0; return 0;
} }
@@ -315,7 +323,7 @@ public class DeviceProfilesSettings extends SettingsPreferenceFragment
autoConnectPref = new CheckBoxPreference(getActivity()); autoConnectPref = new CheckBoxPreference(getActivity());
autoConnectPref.setLayoutResource(com.android.internal.R.layout.preference_child); autoConnectPref.setLayoutResource(com.android.internal.R.layout.preference_child);
autoConnectPref.setKey(prof.toString()); autoConnectPref.setKey(prof.toString());
autoConnectPref.setTitle(getCheckBoxTitle(prof)); autoConnectPref.setTitle(R.string.bluetooth_auto_connect);
autoConnectPref.setOrder(getProfilePreferenceIndex(prof) + 1); autoConnectPref.setOrder(getProfilePreferenceIndex(prof) + 1);
autoConnectPref.setChecked(getAutoConnect(prof)); autoConnectPref.setChecked(getAutoConnect(prof));
autoConnectPref.setOnPreferenceChangeListener(this); autoConnectPref.setOnPreferenceChangeListener(this);
@@ -356,11 +364,6 @@ public class DeviceProfilesSettings extends SettingsPreferenceFragment
return true; return true;
} }
private String getCheckBoxTitle(Profile prof) {
// TODO: Use resources and base it on profile if necessary
return "Auto connect";
}
private boolean getAutoConnect(Profile prof) { private boolean getAutoConnect(Profile prof) {
return LocalBluetoothProfileManager.getProfileManager(mManager, prof) return LocalBluetoothProfileManager.getProfileManager(mManager, prof)
.isPreferred(mCachedDevice.getDevice()); .isPreferred(mCachedDevice.getDevice());

View File

@@ -16,8 +16,6 @@
package com.android.settings.bluetooth; package com.android.settings.bluetooth;
import com.android.settings.bluetooth.LocalBluetoothProfileManager.Profile;
import android.app.Service; import android.app.Service;
import android.bluetooth.BluetoothA2dp; import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter;
@@ -27,7 +25,6 @@ import android.bluetooth.BluetoothProfile;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.os.PowerManager; import android.os.PowerManager;
import android.util.Log; import android.util.Log;

View File

@@ -27,7 +27,6 @@ import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset; import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothProfile;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;

View File

@@ -57,12 +57,11 @@ public class LocalBluetoothManager {
private BluetoothAdapter mAdapter; private BluetoothAdapter mAdapter;
private CachedBluetoothDeviceManager mCachedDeviceManager; private CachedBluetoothDeviceManager mCachedDeviceManager;
private BluetoothEventRedirector mEventRedirector;
private BluetoothA2dp mBluetoothA2dp; private BluetoothA2dp mBluetoothA2dp;
private int mState = BluetoothAdapter.ERROR; private int mState = BluetoothAdapter.ERROR;
private List<Callback> mCallbacks = new ArrayList<Callback>(); private final List<Callback> mCallbacks = new ArrayList<Callback>();
private static final int SCAN_EXPIRATION_MS = 5 * 60 * 1000; // 5 mins private static final int SCAN_EXPIRATION_MS = 5 * 60 * 1000; // 5 mins
@@ -111,15 +110,14 @@ public class LocalBluetoothManager {
mCachedDeviceManager = new CachedBluetoothDeviceManager(this); mCachedDeviceManager = new CachedBluetoothDeviceManager(this);
mEventRedirector = new BluetoothEventRedirector(this); new BluetoothEventRedirector(this).registerReceiver();
mEventRedirector.start();
mAdapter.getProfileProxy(mContext, mProfileListener, BluetoothProfile.A2DP); mAdapter.getProfileProxy(mContext, mProfileListener, BluetoothProfile.A2DP);
return true; return true;
} }
private BluetoothProfile.ServiceListener mProfileListener = private final BluetoothProfile.ServiceListener mProfileListener =
new BluetoothProfile.ServiceListener() { new BluetoothProfile.ServiceListener() {
public void onServiceConnected(int profile, BluetoothProfile proxy) { public void onServiceConnected(int profile, BluetoothProfile proxy) {
mBluetoothA2dp = (BluetoothA2dp) proxy; mBluetoothA2dp = (BluetoothA2dp) proxy;
@@ -286,7 +284,7 @@ public class LocalBluetoothManager {
} }
} }
public void showError(BluetoothDevice device, int titleResId, int messageResId) { public void showError(BluetoothDevice device, int messageResId) {
CachedBluetoothDevice cachedDevice = mCachedDeviceManager.findDevice(device); CachedBluetoothDevice cachedDevice = mCachedDeviceManager.findDevice(device);
String name = null; String name = null;
if (cachedDevice == null) { if (cachedDevice == null) {
@@ -304,7 +302,7 @@ public class LocalBluetoothManager {
// Need an activity context to show a dialog // Need an activity context to show a dialog
mErrorDialog = new AlertDialog.Builder(mForegroundActivity) mErrorDialog = new AlertDialog.Builder(mForegroundActivity)
.setIcon(android.R.drawable.ic_dialog_alert) .setIcon(android.R.drawable.ic_dialog_alert)
.setTitle(titleResId) .setTitle(R.string.bluetooth_error_title)
.setMessage(message) .setMessage(message)
.setPositiveButton(android.R.string.ok, null) .setPositiveButton(android.R.string.ok, null)
.show(); .show();

View File

@@ -40,7 +40,7 @@ import java.util.Map;
* LocalBluetoothProfileManager is an abstract class defining the basic * LocalBluetoothProfileManager is an abstract class defining the basic
* functionality related to a profile. * functionality related to a profile.
*/ */
public abstract class LocalBluetoothProfileManager { abstract class LocalBluetoothProfileManager {
private static final String TAG = "LocalBluetoothProfileManager"; private static final String TAG = "LocalBluetoothProfileManager";
/* package */ static final ParcelUuid[] HEADSET_PROFILE_UUIDS = new ParcelUuid[] { /* package */ static final ParcelUuid[] HEADSET_PROFILE_UUIDS = new ParcelUuid[] {
@@ -97,10 +97,10 @@ public abstract class LocalBluetoothProfileManager {
} }
// TODO: close profiles when we're shutting down // TODO: close profiles when we're shutting down
private static Map<Profile, LocalBluetoothProfileManager> sProfileMap = private static final Map<Profile, LocalBluetoothProfileManager> sProfileMap =
new HashMap<Profile, LocalBluetoothProfileManager>(); new HashMap<Profile, LocalBluetoothProfileManager>();
protected LocalBluetoothManager mLocalManager; protected final LocalBluetoothManager mLocalManager;
public static void init(LocalBluetoothManager localManager) { public static void init(LocalBluetoothManager localManager) {
synchronized (sProfileMap) { synchronized (sProfileMap) {
@@ -141,14 +141,10 @@ public abstract class LocalBluetoothProfileManager {
sProfileMap.remove(Profile.OPP); sProfileMap.remove(Profile.OPP);
} }
if (!BluetoothUuid.containsAnyUuid(uuids, PANU_PROFILE_UUIDS)) {
sProfileMap.remove(Profile.PAN);
}
// There is no local SDP record for HID and Settings app doesn't control PBAP // There is no local SDP record for HID and Settings app doesn't control PBAP
} }
private static LinkedList<ServiceListener> mServiceListeners = private static final LinkedList<ServiceListener> mServiceListeners =
new LinkedList<ServiceListener>(); new LinkedList<ServiceListener>();
public static void addServiceListener(ServiceListener l) { public static void addServiceListener(ServiceListener l) {
@@ -225,7 +221,7 @@ public abstract class LocalBluetoothProfileManager {
profiles.add(Profile.HID); profiles.add(Profile.HID);
} }
if (BluetoothUuid.containsAnyUuid(uuids, PANU_PROFILE_UUIDS) && if (BluetoothUuid.containsAnyUuid(uuids, NAP_PROFILE_UUIDS) &&
sProfileMap.containsKey(Profile.PAN)) { sProfileMap.containsKey(Profile.PAN)) {
profiles.add(Profile.PAN); profiles.add(Profile.PAN);
} }
@@ -259,21 +255,32 @@ public abstract class LocalBluetoothProfileManager {
public abstract boolean isProfileReady(); public abstract boolean isProfileReady();
public int getDrawableResource() { public abstract int getDrawableResource();
return R.drawable.ic_bt_headphones_a2dp;
}
public static enum Profile { public static enum Profile {
HEADSET(R.string.bluetooth_profile_headset), HEADSET(R.string.bluetooth_profile_headset, true, true),
A2DP(R.string.bluetooth_profile_a2dp), A2DP(R.string.bluetooth_profile_a2dp, true, true),
OPP(R.string.bluetooth_profile_opp), OPP(R.string.bluetooth_profile_opp, false, false),
HID(R.string.bluetooth_profile_hid), HID(R.string.bluetooth_profile_hid, true, true),
PAN(R.string.bluetooth_profile_pan); PAN(R.string.bluetooth_profile_pan, true, false);
public final int localizedString; public final int localizedString;
private final boolean mConnectable;
private final boolean mAutoConnectable;
private Profile(int localizedString) { private Profile(int localizedString, boolean connectable,
boolean autoConnectable) {
this.localizedString = localizedString; this.localizedString = localizedString;
this.mConnectable = connectable;
this.mAutoConnectable = autoConnectable;
}
public boolean isConnectable() {
return mConnectable;
}
public boolean isAutoConnectable() {
return mAutoConnectable;
} }
} }
@@ -401,7 +408,7 @@ public abstract class LocalBluetoothProfileManager {
private static class HeadsetProfileManager extends LocalBluetoothProfileManager private static class HeadsetProfileManager extends LocalBluetoothProfileManager
implements BluetoothProfile.ServiceListener { implements BluetoothProfile.ServiceListener {
private BluetoothHeadset mService; private BluetoothHeadset mService;
private Handler mUiHandler = new Handler(); private final Handler mUiHandler = new Handler();
private boolean profileReady = false; private boolean profileReady = false;
// TODO(): The calls must get queued if mService becomes null. // TODO(): The calls must get queued if mService becomes null.
@@ -623,7 +630,7 @@ public abstract class LocalBluetoothProfileManager {
} }
private static class HidProfileManager extends LocalBluetoothProfileManager { private static class HidProfileManager extends LocalBluetoothProfileManager {
private BluetoothInputDevice mService; private final BluetoothInputDevice mService;
public HidProfileManager(LocalBluetoothManager localManager) { public HidProfileManager(LocalBluetoothManager localManager) {
super(localManager); super(localManager);
@@ -711,7 +718,7 @@ public abstract class LocalBluetoothProfileManager {
} }
private static class PanProfileManager extends LocalBluetoothProfileManager { private static class PanProfileManager extends LocalBluetoothProfileManager {
private BluetoothPan mService; private final BluetoothPan mService;
public PanProfileManager(LocalBluetoothManager localManager) { public PanProfileManager(LocalBluetoothManager localManager) {
super(localManager); super(localManager);
@@ -777,17 +784,18 @@ public abstract class LocalBluetoothProfileManager {
@Override @Override
public boolean isPreferred(BluetoothDevice device) { public boolean isPreferred(BluetoothDevice device) {
return false; return true;
} }
@Override @Override
public void setPreferred(BluetoothDevice device, boolean preferred) { public void setPreferred(BluetoothDevice device, boolean preferred) {
// ignore: isPreferred is always true for PAN
return; return;
} }
@Override @Override
public int getDrawableResource() { public int getDrawableResource() {
// TODO: // TODO: return PAN icon resource ID
return 0; return 0;
} }
} }

View File

@@ -72,7 +72,7 @@ public class RequestPermissionActivity extends Activity implements
private AlertDialog mDialog = null; private AlertDialog mDialog = null;
private BroadcastReceiver mReceiver = new BroadcastReceiver() { private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {

View File

@@ -24,7 +24,7 @@ import com.android.settings.R;
* SettingsBtStatus is a helper class that contains constants for various status * SettingsBtStatus is a helper class that contains constants for various status
* codes. * codes.
*/ */
public class SettingsBtStatus { class SettingsBtStatus {
private static final String TAG = "SettingsBtStatus"; private static final String TAG = "SettingsBtStatus";
// Connection status // Connection status