Fix Bluetooth device details crash on screen rotation
We were getting the following exception when you rotated the Bluetooth device details screen: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.settings/com.android.settings.SubSettings}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set android:windowActionBar to false in your theme to use a Toolbar instead. It turns out that allowing EntityHeaderController to inflate the settings_entity_header.xml view seems to cause this - if you instead manually include a LayoutPreference and hand that to EntityHeaderController, you don't have the problem. The rotation failure couldn't be tested with Robolectric because our version doesn't support using FragmentTestUtil.startFragment for fragments which use PreferenceScreen's ("sorry, not yet implemented"). So instead this includes an app test. Bug: 62447414 Test: runtest --path=BluetoothDeviceDetailsRotationTest.java Change-Id: I8d052d1f4ab6e2b0ca5c0e513ec366bdcc382d99
This commit is contained in:
@@ -22,6 +22,7 @@ import android.support.v14.preference.PreferenceFragment;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.applications.LayoutPreference;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
@@ -31,6 +32,7 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
* This class adds a header with device name and status (connected/disconnected, etc.).
|
||||
*/
|
||||
public class BluetoothDetailsHeaderController extends BluetoothDetailsController {
|
||||
private static final String KEY_DEVICE_HEADER = "bluetooth_device_header";
|
||||
|
||||
private EntityHeaderController mHeaderController;
|
||||
|
||||
@@ -41,10 +43,11 @@ public class BluetoothDetailsHeaderController extends BluetoothDetailsController
|
||||
|
||||
@Override
|
||||
protected void init(PreferenceScreen screen) {
|
||||
final LayoutPreference headerPreference =
|
||||
(LayoutPreference) screen.findPreference(KEY_DEVICE_HEADER);
|
||||
mHeaderController = EntityHeaderController.newInstance(mFragment.getActivity(), mFragment,
|
||||
null);
|
||||
LayoutPreference pref = mHeaderController.done(mFragment.getActivity(), mContext);
|
||||
screen.addPreference(pref);
|
||||
headerPreference.findViewById(R.id.entity_header));
|
||||
screen.addPreference(headerPreference);
|
||||
}
|
||||
|
||||
protected void setHeaderProperties() {
|
||||
@@ -66,6 +69,6 @@ public class BluetoothDetailsHeaderController extends BluetoothDetailsController
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return EntityHeaderController.PREF_KEY_APP_HEADER;
|
||||
return KEY_DEVICE_HEADER;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user