Fix a race condition where the extra view may not update timely.
Previously, we queried for the extra view's stats during the rebuild. The full rebuild can take an arduous amount of time. By moving the background calculation outside of the rebuild code path, we can load the stats in the background and update the view outside of the app loading cycle. Bug: 35144044 Test: Manual -- this was race condition-y, so I just tested several times. Change-Id: Id2f92e32c3b3f9c5d5cf4a7308cca38c2e52789c
This commit is contained in:
@@ -331,7 +331,8 @@ public class ManageApplications extends InstrumentedPreferenceFragment
|
||||
mApplications.setExtraViewController(new MusicViewHolderController(
|
||||
context,
|
||||
new StorageStatsSource(context),
|
||||
mVolumeUuid));
|
||||
mVolumeUuid,
|
||||
UserHandle.of(UserHandle.getUserId(mCurrentUid))));
|
||||
}
|
||||
mListView.setAdapter(mApplications);
|
||||
mListView.setRecyclerListener(mApplications);
|
||||
@@ -870,6 +871,12 @@ public class ManageApplications extends InstrumentedPreferenceFragment
|
||||
|
||||
public void setExtraViewController(FileViewHolderController extraViewController) {
|
||||
mExtraViewController = extraViewController;
|
||||
mBgHandler.post(() -> {
|
||||
mExtraViewController.queryStats();
|
||||
mFgHandler.post(() -> {
|
||||
onExtraViewCompleted();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public void resume(int sort) {
|
||||
@@ -957,10 +964,6 @@ public class ManageApplications extends InstrumentedPreferenceFragment
|
||||
break;
|
||||
}
|
||||
|
||||
if (mExtraViewController != null) {
|
||||
mExtraViewController.queryStats();
|
||||
}
|
||||
|
||||
filterObj = new CompoundFilter(filterObj, ApplicationsState.FILTER_NOT_HIDE);
|
||||
AppFilter finalFilterObj = filterObj;
|
||||
mBgHandler.post(() -> {
|
||||
@@ -1178,6 +1181,23 @@ public class ManageApplications extends InstrumentedPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
public void onExtraViewCompleted() {
|
||||
int size = mActive.size();
|
||||
// If we have no elements, don't do anything.
|
||||
if (size < 1) {
|
||||
return;
|
||||
}
|
||||
AppViewHolder holder = (AppViewHolder) mActive.get(size - 1).getTag();
|
||||
|
||||
// HACK: The extra view has no AppEntry -- and should be the only element without one.
|
||||
// Thus, if the last active element has no AppEntry, it is the extra view.
|
||||
if (holder == null || holder.entry != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
mExtraViewController.setupView(holder);
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
if (mEntries == null) {
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user