b/2154978 Show only connectable profiles (Headset and& A2DP but not OPP) in Bluetooth Device Advance Options aka "Connect to..."
Change-Id: I34249a4828707bde491da4a82dca94ecf37cf490
This commit is contained in:
@@ -20,11 +20,11 @@ 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.os.ParcelUuid;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.os.ParcelUuid;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -794,8 +794,18 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Profile> getProfiles() {
|
public List<Profile> getConnectableProfiles() {
|
||||||
return new ArrayList<Profile>(mProfiles);
|
ArrayList<Profile> connectableProfiles = new ArrayList<Profile>();
|
||||||
|
for (Profile profile : mProfiles) {
|
||||||
|
if (isConnectableProfile(profile)) {
|
||||||
|
connectableProfiles.add(profile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return connectableProfiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isConnectableProfile(Profile profile) {
|
||||||
|
return profile.equals(Profile.HEADSET) || profile.equals(Profile.A2DP);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onCreateContextMenu(ContextMenu menu) {
|
public void onCreateContextMenu(ContextMenu menu) {
|
||||||
@@ -806,7 +816,14 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
|
|
||||||
int bondState = getBondState();
|
int bondState = getBondState();
|
||||||
boolean isConnected = isConnected();
|
boolean isConnected = isConnected();
|
||||||
boolean hasProfiles = mProfiles.size() > 0;
|
boolean hasConnectableProfiles = false;
|
||||||
|
|
||||||
|
for (Profile profile : mProfiles) {
|
||||||
|
if (isConnectableProfile(profile)) {
|
||||||
|
hasConnectableProfiles = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
menu.setHeaderTitle(getName());
|
menu.setHeaderTitle(getName());
|
||||||
|
|
||||||
@@ -819,14 +836,14 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
menu.add(0, CONTEXT_ITEM_UNPAIR, 0,
|
menu.add(0, CONTEXT_ITEM_UNPAIR, 0,
|
||||||
R.string.bluetooth_device_context_disconnect_unpair);
|
R.string.bluetooth_device_context_disconnect_unpair);
|
||||||
} else { // Paired but not connected
|
} else { // Paired but not connected
|
||||||
if (hasProfiles) {
|
if (hasConnectableProfiles) {
|
||||||
menu.add(0, CONTEXT_ITEM_CONNECT, 0, R.string.bluetooth_device_context_connect);
|
menu.add(0, CONTEXT_ITEM_CONNECT, 0, R.string.bluetooth_device_context_connect);
|
||||||
}
|
}
|
||||||
menu.add(0, CONTEXT_ITEM_UNPAIR, 0, R.string.bluetooth_device_context_unpair);
|
menu.add(0, CONTEXT_ITEM_UNPAIR, 0, R.string.bluetooth_device_context_unpair);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show the connection options item
|
// Show the connection options item
|
||||||
if (hasProfiles) {
|
if (hasConnectableProfiles) {
|
||||||
menu.add(0, CONTEXT_ITEM_CONNECT_ADVANCED, 0,
|
menu.add(0, CONTEXT_ITEM_CONNECT_ADVANCED, 0,
|
||||||
R.string.bluetooth_device_context_connect_advanced);
|
R.string.bluetooth_device_context_connect_advanced);
|
||||||
}
|
}
|
||||||
|
@@ -16,9 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.bluetooth;
|
package com.android.settings.bluetooth;
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.bluetooth.LocalBluetoothProfileManager.Profile;
|
|
||||||
|
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -29,7 +26,8 @@ import android.preference.PreferenceGroup;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.List;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.bluetooth.LocalBluetoothProfileManager.Profile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ConnectSpecificProfilesActivity presents the user with all of the profiles
|
* ConnectSpecificProfilesActivity presents the user with all of the profiles
|
||||||
@@ -46,9 +44,6 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
|
|
||||||
public static final String EXTRA_DEVICE = "device";
|
public static final String EXTRA_DEVICE = "device";
|
||||||
|
|
||||||
public static final String CLASS_NAME_OPP_PROFILE_MANAGER =
|
|
||||||
"com.android.settings.bluetooth.LocalBluetoothProfileManager$OppProfileManager";
|
|
||||||
|
|
||||||
private LocalBluetoothManager mManager;
|
private LocalBluetoothManager mManager;
|
||||||
private CachedBluetoothDevice mCachedDevice;
|
private CachedBluetoothDevice mCachedDevice;
|
||||||
|
|
||||||
@@ -129,7 +124,7 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addPreferencesForProfiles() {
|
private void addPreferencesForProfiles() {
|
||||||
for (Profile profile : mCachedDevice.getProfiles()) {
|
for (Profile profile : mCachedDevice.getConnectableProfiles()) {
|
||||||
Preference pref = createProfilePreference(profile);
|
Preference pref = createProfilePreference(profile);
|
||||||
mProfileContainer.addPreference(pref);
|
mProfileContainer.addPreference(pref);
|
||||||
}
|
}
|
||||||
@@ -154,14 +149,9 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
.getProfileManager(mManager, profile);
|
.getProfileManager(mManager, profile);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gray out checkbox while connecting and disconnecting or this is OPP
|
* Gray out checkbox while connecting and disconnecting
|
||||||
* profile
|
|
||||||
*/
|
*/
|
||||||
if (profileManager.getClass().getName().equals(CLASS_NAME_OPP_PROFILE_MANAGER)) {
|
|
||||||
pref.setEnabled(false);
|
|
||||||
} else {
|
|
||||||
pref.setEnabled(!mCachedDevice.isBusy());
|
pref.setEnabled(!mCachedDevice.isBusy());
|
||||||
}
|
|
||||||
|
|
||||||
refreshProfilePreference(pref, profile);
|
refreshProfilePreference(pref, profile);
|
||||||
|
|
||||||
@@ -239,12 +229,6 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
/* Gray out checkbox while connecting and disconnecting */
|
/* Gray out checkbox while connecting and disconnecting */
|
||||||
mOnlineModePreference.setEnabled(!mCachedDevice.isBusy());
|
mOnlineModePreference.setEnabled(!mCachedDevice.isBusy());
|
||||||
|
|
||||||
List<Profile> profiles = mCachedDevice.getProfiles();
|
|
||||||
if ((profiles.size() == 1) && (profiles.get(0).name().equals("OPP"))) {
|
|
||||||
Log.w(TAG, "there is only one profile: Opp, disable the connect button.");
|
|
||||||
mOnlineModePreference.setEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the device is online, show status. Otherwise, show a summary that
|
* If the device is online, show status. Otherwise, show a summary that
|
||||||
* describes what the checkbox does.
|
* describes what the checkbox does.
|
||||||
@@ -254,7 +238,7 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void refreshProfiles() {
|
private void refreshProfiles() {
|
||||||
for (Profile profile : mCachedDevice.getProfiles()) {
|
for (Profile profile : mCachedDevice.getConnectableProfiles()) {
|
||||||
CheckBoxPreference profilePref =
|
CheckBoxPreference profilePref =
|
||||||
(CheckBoxPreference) findPreference(profile.toString());
|
(CheckBoxPreference) findPreference(profile.toString());
|
||||||
if (profilePref == null) {
|
if (profilePref == null) {
|
||||||
@@ -274,15 +258,9 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
int connectionStatus = profileManager.getConnectionStatus(device);
|
int connectionStatus = profileManager.getConnectionStatus(device);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Gray out checkbox while connecting and disconnecting or this is OPP
|
* Gray out checkbox while connecting and disconnecting
|
||||||
* profile
|
|
||||||
*/
|
*/
|
||||||
if (profileManager.getClass().getName().equals(CLASS_NAME_OPP_PROFILE_MANAGER)) {
|
|
||||||
Log.w(TAG, "this is Opp profile");
|
|
||||||
profilePref.setEnabled(false);
|
|
||||||
} else {
|
|
||||||
profilePref.setEnabled(!mCachedDevice.isBusy());
|
profilePref.setEnabled(!mCachedDevice.isBusy());
|
||||||
}
|
|
||||||
profilePref.setSummary(getProfileSummary(profileManager, profile, device,
|
profilePref.setSummary(getProfileSummary(profileManager, profile, device,
|
||||||
connectionStatus, mOnlineMode));
|
connectionStatus, mOnlineMode));
|
||||||
|
|
||||||
@@ -322,8 +300,6 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
return R.string.bluetooth_a2dp_profile_summary_use_for;
|
return R.string.bluetooth_a2dp_profile_summary_use_for;
|
||||||
case HEADSET:
|
case HEADSET:
|
||||||
return R.string.bluetooth_headset_profile_summary_use_for;
|
return R.string.bluetooth_headset_profile_summary_use_for;
|
||||||
case OPP:
|
|
||||||
return R.string.bluetooth_opp_profile_summary_use_for;
|
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user