Disable suggestion on low memory devices
Change-Id: I9d22170845661fc8b48b116c9b09f758926c096f Fix: 63157777 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -94,9 +94,11 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
|
||||
mConditionManager = ConditionManager.get(activity, false);
|
||||
getLifecycle().addObserver(mConditionManager);
|
||||
mSuggestionParser = new SuggestionParser(activity,
|
||||
mSuggestionFeatureProvider.getSharedPrefs(activity), R.xml.suggestion_ordering);
|
||||
mSuggestionsChecks = new SuggestionsChecks(getContext());
|
||||
if (mSuggestionFeatureProvider.isSuggestionEnabled(activity)) {
|
||||
mSuggestionParser = new SuggestionParser(activity,
|
||||
mSuggestionFeatureProvider.getSharedPrefs(activity), R.xml.suggestion_ordering);
|
||||
mSuggestionsChecks = new SuggestionsChecks(getContext());
|
||||
}
|
||||
if (DEBUG_TIMING) {
|
||||
Log.d(TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
|
||||
+ " ms");
|
||||
@@ -206,11 +208,16 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
|
||||
@VisibleForTesting
|
||||
void rebuildUI() {
|
||||
new SuggestionLoader().execute();
|
||||
// Set categories on their own if loading suggestions takes too long.
|
||||
mHandler.postDelayed(() -> {
|
||||
if (!mSuggestionFeatureProvider.isSuggestionEnabled(getContext())) {
|
||||
Log.d(TAG, "Suggestion feature is disabled, skipping suggestion entirely");
|
||||
updateCategoryAndSuggestion(null /* tiles */);
|
||||
}, MAX_WAIT_MILLIS);
|
||||
} else {
|
||||
new SuggestionLoader().execute();
|
||||
// Set categories on their own if loading suggestions takes too long.
|
||||
mHandler.postDelayed(() -> {
|
||||
updateCategoryAndSuggestion(null /* tiles */);
|
||||
}, MAX_WAIT_MILLIS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -29,6 +29,11 @@ import java.util.List;
|
||||
/** Interface should be implemented if you have added new suggestions */
|
||||
public interface SuggestionFeatureProvider {
|
||||
|
||||
/**
|
||||
* Whether or not the whole suggestion feature is enabled.
|
||||
*/
|
||||
boolean isSuggestionEnabled(Context context);
|
||||
|
||||
/**
|
||||
* Returns true if smart suggestion should be used instead of xml based SuggestionParser.
|
||||
*/
|
||||
|
@@ -16,12 +16,12 @@
|
||||
|
||||
package com.android.settings.dashboard.suggestions;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings.Secure;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
@@ -66,6 +66,13 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private final AmbientDisplayConfiguration mAmbientDisplayConfig;
|
||||
|
||||
@Override
|
||||
public boolean isSuggestionEnabled(Context context) {
|
||||
final ActivityManager am =
|
||||
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
return !am.isLowRamDevice();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSmartSuggestionEnabled(Context context) {
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user