Fix crash in time zone picker due to race condition on view updates
- Can't reproduce the race condition with manual test, probably the view updates are fast enough that only monkey test can reproduce the issue. - Reproduced a similar stacktrace and IndexOutOfBoundsException with Robolectric test by assuming that the race condition happens after text filtering and view updates. Try to fix the bug with this assumption - The fix is to bind the data (data position in adapter) with ViewHolder. Bug: 75322108 Test: m RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.datetime.timezone Change-Id: Ie5d932bce30590b8067e042c3380911c9608872f
This commit is contained in:
@@ -31,7 +31,6 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Render a list of {@class TimeZoneInfo} into the list view in {@class BaseTimeZonePicker}
|
||||
@@ -52,8 +51,8 @@ public abstract class BaseTimeZoneInfoPicker extends BaseTimeZonePicker {
|
||||
return mAdapter;
|
||||
}
|
||||
|
||||
private void onListItemClick(int position) {
|
||||
final TimeZoneInfo timeZoneInfo = mAdapter.getItem(position).mTimeZoneInfo;
|
||||
private void onListItemClick(TimeZoneInfoItem item) {
|
||||
final TimeZoneInfo timeZoneInfo = item.mTimeZoneInfo;
|
||||
getActivity().setResult(Activity.RESULT_OK, prepareResultData(timeZoneInfo));
|
||||
getActivity().finish();
|
||||
}
|
||||
@@ -67,7 +66,7 @@ public abstract class BaseTimeZoneInfoPicker extends BaseTimeZonePicker {
|
||||
protected static class ZoneAdapter extends BaseTimeZoneAdapter<TimeZoneInfoItem> {
|
||||
|
||||
public ZoneAdapter(Context context, List<TimeZoneInfo> timeZones,
|
||||
OnListItemClickListener onListItemClickListener, Locale locale) {
|
||||
OnListItemClickListener<TimeZoneInfoItem> onListItemClickListener, Locale locale) {
|
||||
super(createTimeZoneInfoItems(context, timeZones, locale),
|
||||
onListItemClickListener, locale, true /* showItemSummary */);
|
||||
}
|
||||
|
Reference in New Issue
Block a user