Adjust timeout limit of contextual card loading
Add a way to get the timeout limit of contextual card loading from Settings.Global. If Settings.Global doesn't have the timeout limit, will use the default timeout limit. Bug: 124460999 Test: robotests Change-Id: I2a25570f51013b566914e485d61405f14290d338
This commit is contained in:
@@ -24,6 +24,8 @@ import static java.util.stream.Collectors.groupingBy;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Log;
|
||||
import android.widget.BaseAdapter;
|
||||
@@ -62,8 +64,12 @@ import java.util.stream.Collectors;
|
||||
public class ContextualCardManager implements ContextualCardLoader.CardContentLoaderListener,
|
||||
ContextualCardUpdateListener, LifecycleObserver, OnSaveInstanceState {
|
||||
|
||||
private static final String KEY_CONTEXTUAL_CARDS = "key_contextual_cards";
|
||||
@VisibleForTesting
|
||||
static final long CARD_CONTENT_LOADER_TIMEOUT_MS = DateUtils.SECOND_IN_MILLIS;
|
||||
@VisibleForTesting
|
||||
static final String KEY_GLOBAL_CARD_LOADER_TIMEOUT = "global_card_loader_timeout_key";
|
||||
|
||||
private static final String KEY_CONTEXTUAL_CARDS = "key_contextual_cards";
|
||||
private static final String TAG = "ContextualCardManager";
|
||||
|
||||
//The list for Settings Custom Card
|
||||
@@ -201,7 +207,8 @@ public class ContextualCardManager implements ContextualCardLoader.CardContentLo
|
||||
}
|
||||
|
||||
//only log homepage display upon a fresh launch
|
||||
if (loadTime <= ContextualCardLoader.CARD_CONTENT_LOADER_TIMEOUT_MS) {
|
||||
final long timeoutLimit = getCardLoaderTimeout(mContext);
|
||||
if (loadTime <= timeoutLimit) {
|
||||
onContextualCardUpdated(cards.stream()
|
||||
.collect(groupingBy(ContextualCard::getCardType)));
|
||||
}
|
||||
@@ -239,6 +246,14 @@ public class ContextualCardManager implements ContextualCardLoader.CardContentLo
|
||||
return getCardsWithSuggestionViewType(result);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
long getCardLoaderTimeout(Context context) {
|
||||
// Return the timeout limit if Settings.Global has the KEY_GLOBAL_CARD_LOADER_TIMEOUT key,
|
||||
// else return default timeout.
|
||||
return Settings.Global.getLong(mContext.getContentResolver(),
|
||||
KEY_GLOBAL_CARD_LOADER_TIMEOUT, CARD_CONTENT_LOADER_TIMEOUT_MS);
|
||||
}
|
||||
|
||||
private List<ContextualCard> getCardsWithSuggestionViewType(List<ContextualCard> cards) {
|
||||
// Shows as half cards if 2 suggestion type of cards are next to each other.
|
||||
// Shows as full card if 1 suggestion type of card lives alone.
|
||||
|
Reference in New Issue
Block a user