Fix the overlapping problem of the burst of slice updates

Implement a throttle in SliceBackgroundWorker to control slice updates.

Test: robotest
Fixes: 152366832
Change-Id: I8b65d1b57973e036b932172627aca506f4fae3a4
This commit is contained in:
Jason Chiu
2020-06-12 11:59:45 +08:00
parent 5bd41e573b
commit 0625bb4815
7 changed files with 124 additions and 11 deletions

View File

@@ -243,7 +243,7 @@ public class SettingsSliceProvider extends SliceProvider {
.createWifiCallingPreferenceSlice(sliceUri);
}
SliceData cachedSliceData = mSliceWeakDataCache.get(sliceUri);
final SliceData cachedSliceData = mSliceWeakDataCache.get(sliceUri);
if (cachedSliceData == null) {
loadSliceInBackground(sliceUri);
return getSliceStub(sliceUri);
@@ -466,14 +466,14 @@ public class SettingsSliceProvider extends SliceProvider {
final SliceBackgroundWorker worker = SliceBackgroundWorker.getInstance(
getContext(), sliceable, uri);
mPinnedWorkers.put(uri, worker);
worker.onSlicePinned();
worker.pin();
}
private void stopBackgroundWorker(Uri uri) {
final SliceBackgroundWorker worker = mPinnedWorkers.get(uri);
if (worker != null) {
Log.d(TAG, "Stopping background worker for: " + uri);
worker.onSliceUnpinned();
worker.unpin();
mPinnedWorkers.remove(uri);
}
}