Disable SmartSuggestion conditionally
The smart suggestion flag should be treated as false when dismissing first impression type suggestions. Smart suggestion and first impression suggestions have different dismiss rules. Change-Id: Ia99d310ddea7baf58b6eadacee8ccda5bf33f311 Fix: 63094854 Test: robotests
This commit is contained in:
@@ -17,13 +17,14 @@
|
||||
package com.android.settings.dashboard.suggestions;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.content.ContentResolver;
|
||||
import android.provider.Settings.Secure;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
@@ -43,6 +44,12 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
|
||||
|
||||
private static final String SHARED_PREF_FILENAME = "suggestions";
|
||||
|
||||
// Suggestion category name and expiration threshold for first impression type. Needs to keep
|
||||
// in sync with suggestion_ordering.xml
|
||||
private static final String CATEGORY_FIRST_IMPRESSION =
|
||||
"com.android.settings.suggested.category.FIRST_IMPRESSION";
|
||||
private static final long FIRST_IMPRESSION_EXPIRE_DAY_IN_MILLIS = 14 * DateUtils.DAY_IN_MILLIS;
|
||||
|
||||
private final SuggestionRanker mSuggestionRanker;
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
|
||||
@@ -101,7 +108,11 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
|
||||
context, MetricsProto.MetricsEvent.ACTION_SETTINGS_DISMISS_SUGGESTION,
|
||||
getSuggestionIdentifier(context, suggestion));
|
||||
|
||||
final boolean isSmartSuggestionEnabled = isSmartSuggestionEnabled(context);
|
||||
boolean isSmartSuggestionEnabled = isSmartSuggestionEnabled(context);
|
||||
if (isSmartSuggestionEnabled) {
|
||||
// Disable smart suggestion if we are still showing first impression suggestions.
|
||||
isSmartSuggestionEnabled = !isShowingFirstImpressionSuggestion(context);
|
||||
}
|
||||
if (!parser.dismissSuggestion(suggestion, isSmartSuggestionEnabled)) {
|
||||
return;
|
||||
}
|
||||
@@ -111,6 +122,19 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
|
||||
PackageManager.DONT_KILL_APP);
|
||||
}
|
||||
|
||||
private boolean isShowingFirstImpressionSuggestion(Context context) {
|
||||
final String keySetupTime = CATEGORY_FIRST_IMPRESSION + SuggestionParser.SETUP_TIME;
|
||||
final long currentTime = System.currentTimeMillis();
|
||||
final SharedPreferences sharedPrefs = getSharedPrefs(context);
|
||||
if (!sharedPrefs.contains(keySetupTime)) {
|
||||
return true;
|
||||
}
|
||||
final long setupTime = sharedPrefs.getLong(keySetupTime, 0);
|
||||
final long elapsedTime = currentTime - setupTime;
|
||||
Log.d(TAG, "Day " + elapsedTime / DateUtils.DAY_IN_MILLIS + " for first impression");
|
||||
return elapsedTime <= FIRST_IMPRESSION_EXPIRE_DAY_IN_MILLIS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSuggestionIdentifier(Context context, Tile suggestion) {
|
||||
if (suggestion.intent == null || suggestion.intent.getComponent() == null
|
||||
@@ -130,7 +154,7 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
|
||||
boolean hasUsedNightDisplay(Context context) {
|
||||
final ContentResolver cr = context.getContentResolver();
|
||||
final long lastActivatedTimeMillis = Secure.getLong(cr,
|
||||
Secure.NIGHT_DISPLAY_LAST_ACTIVATED_TIME, -1);
|
||||
Secure.NIGHT_DISPLAY_LAST_ACTIVATED_TIME, -1);
|
||||
return lastActivatedTimeMillis > 0;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user