Fixed multiple Bluetooth Settings crashes.

+ Fixed a crash when selecting On/Off multiple times on an input device.
+ Fixed a crash when visiting different Bluetooth Settings after
disabling an input device.

Bug: 17402421
Change-Id: I23efa3a36ba8cf0df02cf41397586a10dae9e08c
This commit is contained in:
PauloftheWest
2014-09-10 06:45:00 -07:00
parent 1fb5198732
commit 8d6991348b
2 changed files with 21 additions and 8 deletions

View File

@@ -392,7 +392,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
final CachedBluetoothDevice device = (CachedBluetoothDevice) v.getTag();
final Activity activity = getActivity();
DeviceProfilesSettings profileFrag = (DeviceProfilesSettings)activity.
DeviceProfilesSettings profileFragment = (DeviceProfilesSettings)activity.
getFragmentManager().findFragmentById(R.id.bluetooth_fragment_settings);
if (mSettingsDialogView != null){
@@ -402,23 +402,26 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
}
}
if (profileFrag == null) {
if (profileFragment == null) {
LayoutInflater inflater = getActivity().getLayoutInflater();
mSettingsDialogView = inflater.inflate(R.layout.bluetooth_device_settings, null);
profileFrag = (DeviceProfilesSettings)activity.getFragmentManager()
profileFragment = (DeviceProfilesSettings)activity.getFragmentManager()
.findFragmentById(R.id.bluetooth_fragment_settings);
// To enable scrolling we store the name field in a seperate header and add to
// the ListView of the profileFrag.
// the ListView of the profileFragment.
View header = inflater.inflate(R.layout.bluetooth_device_settings_header, null);
profileFrag.getListView().addHeaderView(header);
profileFragment.getListView().addHeaderView(header);
}
final View dialogLayout = mSettingsDialogView;
AlertDialog.Builder settingsDialog = new AlertDialog.Builder(activity);
profileFrag.setDevice(device);
profileFragment.setDevice(device);
final EditText deviceName = (EditText)dialogLayout.findViewById(R.id.name);
deviceName.setText(device.getName(), TextView.BufferType.EDITABLE);
final DeviceProfilesSettings dpsFragment = profileFragment;
final Context context = v.getContext();
settingsDialog.setView(dialogLayout);
settingsDialog.setTitle(R.string.bluetooth_preference_paired_devices);
settingsDialog.setPositiveButton(R.string.okay,
@@ -429,7 +432,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
device.setName(deviceName.getText().toString());
}
});
final Context context = v.getContext();
settingsDialog.setNegativeButton(R.string.forget,
new DialogInterface.OnClickListener() {
@Override
@@ -442,6 +445,16 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
}
});
// We must ensure that the fragment gets destroyed to avoid duplicate fragments.
settingsDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
public void onDismiss(final DialogInterface dialog) {
if (!activity.isDestroyed()) {
activity.getFragmentManager().beginTransaction().remove(dpsFragment)
.commitAllowingStateLoss();
}
}
});
AlertDialog dialog = settingsDialog.create();
dialog.create();
dialog.show();

View File

@@ -232,7 +232,7 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
status == BluetoothProfile.STATE_CONNECTED;
if (isConnected) {
askDisconnect(getActivity(), profile);
askDisconnect(mManager.getForegroundActivity(), profile);
} else {
if (profile.isPreferred(device)) {
// profile is preferred but not connected: disable auto-connect