Fix NPE when building suggestion identifier.
And refactored the getIdent logic into feature provider. Change-Id: Id6f66a6942cbaf6d26ae4dca62037a6cf01179a5 Fix: 36314240 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -21,7 +21,6 @@ import android.content.pm.PackageManager;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.dashboard.DashboardAdapter;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.SuggestionParser;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
@@ -50,9 +49,10 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
|
||||
|
||||
|
||||
public SuggestionFeatureProviderImpl(Context context) {
|
||||
final Context appContext = context.getApplicationContext();
|
||||
mSuggestionRanker = new SuggestionRanker(
|
||||
new SuggestionFeaturizer(new EventStore(context.getApplicationContext())));
|
||||
mMetricsFeatureProvider = FeatureFactory.getFactory(context)
|
||||
new SuggestionFeaturizer(new EventStore(appContext)));
|
||||
mMetricsFeatureProvider = FeatureFactory.getFactory(appContext)
|
||||
.getMetricsFeatureProvider();
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
|
||||
}
|
||||
mMetricsFeatureProvider.action(
|
||||
context, MetricsProto.MetricsEvent.ACTION_SETTINGS_DISMISS_SUGGESTION,
|
||||
DashboardAdapter.getSuggestionIdentifier(context, suggestion));
|
||||
getSuggestionIdentifier(context, suggestion));
|
||||
|
||||
final boolean isSmartSuggestionEnabled = isSmartSuggestionEnabled(context);
|
||||
if (!parser.dismissSuggestion(suggestion, isSmartSuggestionEnabled)) {
|
||||
@@ -81,4 +81,18 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
|
||||
parser.markCategoryDone(suggestion.category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSuggestionIdentifier(Context context, Tile suggestion) {
|
||||
if (suggestion.intent == null || suggestion.intent.getComponent() == null) {
|
||||
return "unknown_suggestion";
|
||||
}
|
||||
String packageName = suggestion.intent.getComponent().getPackageName();
|
||||
if (packageName.equals(context.getPackageName())) {
|
||||
// Since Settings provides several suggestions, fill in the class instead of the
|
||||
// package for these.
|
||||
packageName = suggestion.intent.getComponent().getClassName();
|
||||
}
|
||||
return packageName;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user