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:
Victor Chang
2018-03-24 18:07:50 +00:00
parent d7ea524e81
commit 201c629fcc
5 changed files with 138 additions and 43 deletions

View File

@@ -17,6 +17,7 @@
package com.android.settings.datetime.timezone;
import android.os.Bundle;
import android.support.annotation.VisibleForTesting;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
@@ -161,8 +162,8 @@ public abstract class BaseTimeZonePicker extends InstrumentedFragment
return false;
}
public interface OnListItemClickListener {
void onListItemClick(int position);
public interface OnListItemClickListener<T extends BaseTimeZoneAdapter.AdapterItem> {
void onListItemClick(T item);
}
}