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:
Daniel Nishi
2017-02-08 12:29:24 -08:00
parent bbd80517f0
commit a412c30d90
3 changed files with 32 additions and 9 deletions

View File

@@ -38,18 +38,20 @@ public class MusicViewHolderController implements FileViewHolderController {
private StorageStatsSource mSource;
private String mVolumeUuid;
private long mMusicSize;
private UserHandle mUser;
public MusicViewHolderController(
Context context, StorageStatsSource source, String volumeUuid) {
Context context, StorageStatsSource source, String volumeUuid, UserHandle user) {
mContext = context;
mSource = source;
mVolumeUuid = volumeUuid;
mUser = user;
}
@Override
@WorkerThread
public void queryStats() {
mMusicSize = mSource.getExternalStorageStats(mVolumeUuid, UserHandle.CURRENT).audioBytes;
mMusicSize = mSource.getExternalStorageStats(mVolumeUuid, mUser).audioBytes;
}
@Override
@@ -69,7 +71,7 @@ public class MusicViewHolderController implements FileViewHolderController {
Intent intent = new Intent(DocumentsContract.ACTION_BROWSE);
intent.setData(DocumentsContract.buildRootUri(AUTHORITY_MEDIA, "audio_root"));
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.putExtra(Intent.EXTRA_USER_ID, UserHandle.CURRENT);
intent.putExtra(Intent.EXTRA_USER_ID, mUser);
Utils.launchIntent(fragment, intent);
}
}