Load suggestions through SettingsIntelligence.
- Add flag to switch between old/new implementation - Add SuggestionLoader to load using Loader (instead of AsyncTask) - Update DashboardAdapater/SuggestionAdapter to take List<Suggestion> - Marked old getter/setters as @Deprecated and added comment - Update tests to cover suggestionV2 adapter changes. TODO: - Handler for dismissing suggestion not set up yet. - Suggestion data structure is incomplete (missing icon, remote view, etc) - Need to extend Suggestion data strcture to support icon and remote view binding Bug: 65065268 Test: robotests Change-Id: I2378ef4c9edee972d5de93c3868068e2cde23f56
This commit is contained in:
@@ -23,6 +23,7 @@ import android.graphics.Color;
|
|||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.drawable.Icon;
|
import android.graphics.drawable.Icon;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.service.settings.suggestions.Suggestion;
|
||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
import android.support.v7.util.DiffUtil;
|
import android.support.v7.util.DiffUtil;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
@@ -62,6 +63,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
implements SummaryLoader.SummaryConsumer {
|
implements SummaryLoader.SummaryConsumer {
|
||||||
public static final String TAG = "DashboardAdapter";
|
public static final String TAG = "DashboardAdapter";
|
||||||
private static final String STATE_SUGGESTION_LIST = "suggestion_list";
|
private static final String STATE_SUGGESTION_LIST = "suggestion_list";
|
||||||
|
private static final String STATE_SUGGESTION_LIST_V2 = "suggestion_list_v2";
|
||||||
private static final String STATE_CATEGORY_LIST = "category_list";
|
private static final String STATE_CATEGORY_LIST = "category_list";
|
||||||
private static final String STATE_SUGGESTIONS_SHOWN_LOGGED = "suggestions_shown_logged";
|
private static final String STATE_SUGGESTIONS_SHOWN_LOGGED = "suggestions_shown_logged";
|
||||||
|
|
||||||
@@ -99,7 +101,10 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
public DashboardAdapter(Context context, Bundle savedInstanceState,
|
public DashboardAdapter(Context context, Bundle savedInstanceState,
|
||||||
List<Condition> conditions, SuggestionParser suggestionParser,
|
List<Condition> conditions, SuggestionParser suggestionParser,
|
||||||
SuggestionDismissController.Callback callback) {
|
SuggestionDismissController.Callback callback) {
|
||||||
|
|
||||||
|
// @deprecated In favor of suggestionsV2 below.
|
||||||
List<Tile> suggestions = null;
|
List<Tile> suggestions = null;
|
||||||
|
List<Suggestion> suggestionsV2 = null;
|
||||||
DashboardCategory category = null;
|
DashboardCategory category = null;
|
||||||
int suggestionConditionMode = DashboardData.HEADER_MODE_DEFAULT;
|
int suggestionConditionMode = DashboardData.HEADER_MODE_DEFAULT;
|
||||||
|
|
||||||
@@ -116,6 +121,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
suggestions = savedInstanceState.getParcelableArrayList(STATE_SUGGESTION_LIST);
|
suggestions = savedInstanceState.getParcelableArrayList(STATE_SUGGESTION_LIST);
|
||||||
|
suggestionsV2 = savedInstanceState.getParcelableArrayList(STATE_SUGGESTION_LIST_V2);
|
||||||
category = savedInstanceState.getParcelable(STATE_CATEGORY_LIST);
|
category = savedInstanceState.getParcelable(STATE_CATEGORY_LIST);
|
||||||
suggestionConditionMode = savedInstanceState.getInt(
|
suggestionConditionMode = savedInstanceState.getInt(
|
||||||
STATE_SUGGESTION_CONDITION_MODE, suggestionConditionMode);
|
STATE_SUGGESTION_CONDITION_MODE, suggestionConditionMode);
|
||||||
@@ -128,6 +134,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
mDashboardData = new DashboardData.Builder()
|
mDashboardData = new DashboardData.Builder()
|
||||||
.setConditions(conditions)
|
.setConditions(conditions)
|
||||||
.setSuggestions(suggestions)
|
.setSuggestions(suggestions)
|
||||||
|
.setSuggestionsV2(suggestionsV2)
|
||||||
.setCategory(category)
|
.setCategory(category)
|
||||||
.setSuggestionConditionMode(suggestionConditionMode)
|
.setSuggestionConditionMode(suggestionConditionMode)
|
||||||
.build();
|
.build();
|
||||||
@@ -137,8 +144,12 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
return mDashboardData.getSuggestions();
|
return mDashboardData.getSuggestions();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCategoriesAndSuggestions(DashboardCategory category,
|
/**
|
||||||
List<Tile> suggestions) {
|
* @deprecated in favor of {@link #setCategory(DashboardCategory)} and
|
||||||
|
* {@link #setSuggestionsV2(List)}.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public void setCategoriesAndSuggestions(DashboardCategory category, List<Tile> suggestions) {
|
||||||
tintIcons(category, suggestions);
|
tintIcons(category, suggestions);
|
||||||
|
|
||||||
final DashboardData prevData = mDashboardData;
|
final DashboardData prevData = mDashboardData;
|
||||||
@@ -168,6 +179,16 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSuggestionsV2(List<Suggestion> data) {
|
||||||
|
// TODO: Tint icon
|
||||||
|
final DashboardData prevData = mDashboardData;
|
||||||
|
mDashboardData = new DashboardData.Builder(prevData)
|
||||||
|
.setSuggestionsV2(data)
|
||||||
|
.build();
|
||||||
|
notifyDashboardDataChanged(prevData);
|
||||||
|
// TODO: Replicate the metrics logging from setCategoriesAndSuggestions()
|
||||||
|
}
|
||||||
|
|
||||||
public void setCategory(DashboardCategory category) {
|
public void setCategory(DashboardCategory category) {
|
||||||
tintIcons(category, null);
|
tintIcons(category, null);
|
||||||
final DashboardData prevData = mDashboardData;
|
final DashboardData prevData = mDashboardData;
|
||||||
@@ -187,6 +208,10 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
notifyDashboardDataChanged(prevData);
|
notifyDashboardDataChanged(prevData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated in favor of {@link #onSuggestionDismissed(Suggestion)}.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public void onSuggestionDismissed(Tile suggestion) {
|
public void onSuggestionDismissed(Tile suggestion) {
|
||||||
final List<Tile> suggestions = mDashboardData.getSuggestions();
|
final List<Tile> suggestions = mDashboardData.getSuggestions();
|
||||||
if (suggestions == null || suggestions.isEmpty()) {
|
if (suggestions == null || suggestions.isEmpty()) {
|
||||||
@@ -205,6 +230,24 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onSuggestionDismissed(Suggestion suggestion) {
|
||||||
|
final List<Suggestion> list = mDashboardData.getSuggestionsV2();
|
||||||
|
if (list == null || list.size() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (list.size() == 1) {
|
||||||
|
// The only suggestion is dismissed, and the the empty suggestion container will
|
||||||
|
// remain as the dashboard item. Need to refresh the dashboard list.
|
||||||
|
final DashboardData prevData = mDashboardData;
|
||||||
|
mDashboardData = new DashboardData.Builder(prevData)
|
||||||
|
.setSuggestionsV2(null)
|
||||||
|
.build();
|
||||||
|
notifyDashboardDataChanged(prevData);
|
||||||
|
} else {
|
||||||
|
mSuggestionAdapter.removeSuggestion(suggestion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void notifySummaryChanged(Tile tile) {
|
public void notifySummaryChanged(Tile tile) {
|
||||||
final int position = mDashboardData.getPositionByTile(tile);
|
final int position = mDashboardData.getPositionByTile(tile);
|
||||||
@@ -303,10 +346,18 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
return mDashboardData.getItemEntityById(itemId);
|
return mDashboardData.getItemEntityById(itemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated in favor of {@link #getSuggestionV2(int)}.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public Tile getSuggestion(int position) {
|
public Tile getSuggestion(int position) {
|
||||||
return mSuggestionAdapter.getSuggestion(position);
|
return mSuggestionAdapter.getSuggestion(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Suggestion getSuggestionV2(int position) {
|
||||||
|
return mSuggestionAdapter.getSuggestionsV2(position);
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void notifyDashboardDataChanged(DashboardData prevData) {
|
void notifyDashboardDataChanged(DashboardData prevData) {
|
||||||
if (mFirstFrameDrawn && prevData != null) {
|
if (mFirstFrameDrawn && prevData != null) {
|
||||||
@@ -426,15 +477,30 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
int position) {
|
int position) {
|
||||||
// If there is suggestions to show, it will be at position 0 as we don't show the suggestion
|
// If there is suggestions to show, it will be at position 0 as we don't show the suggestion
|
||||||
// header anymore.
|
// header anymore.
|
||||||
|
final List<Suggestion> suggestionsV2 = mDashboardData.getSuggestionsV2();
|
||||||
final List<Tile> suggestions = mDashboardData.getSuggestions();
|
final List<Tile> suggestions = mDashboardData.getSuggestions();
|
||||||
if (position == SUGGESTION_CONDITION_HEADER_POSITION
|
|
||||||
&& suggestions != null && suggestions.size() > 0) {
|
boolean conditionOnly = true;
|
||||||
|
if (position == SUGGESTION_CONDITION_HEADER_POSITION) {
|
||||||
|
if (suggestions != null && suggestions.size() > 0) {
|
||||||
|
conditionOnly = false;
|
||||||
mSuggestionAdapter = new SuggestionAdapter(mContext, (List<Tile>)
|
mSuggestionAdapter = new SuggestionAdapter(mContext, (List<Tile>)
|
||||||
mDashboardData.getItemEntityByPosition(position), mSuggestionsShownLogged);
|
mDashboardData.getItemEntityByPosition(position),
|
||||||
|
null, mSuggestionsShownLogged);
|
||||||
mSuggestionDismissHandler = new SuggestionDismissController(mContext,
|
mSuggestionDismissHandler = new SuggestionDismissController(mContext,
|
||||||
holder.data, mSuggestionParser, mCallback);
|
holder.data, mSuggestionParser, mCallback);
|
||||||
holder.data.setAdapter(mSuggestionAdapter);
|
holder.data.setAdapter(mSuggestionAdapter);
|
||||||
} else {
|
} else if (suggestionsV2 != null && suggestionsV2.size() > 0) {
|
||||||
|
conditionOnly = false;
|
||||||
|
mSuggestionAdapter = new SuggestionAdapter(mContext, null,
|
||||||
|
(List<Suggestion>) mDashboardData.getItemEntityByPosition(position),
|
||||||
|
mSuggestionsShownLogged);
|
||||||
|
mSuggestionDismissHandler = new SuggestionDismissController(mContext,
|
||||||
|
holder.data, null /* parser */, mCallback);
|
||||||
|
holder.data.setAdapter(mSuggestionAdapter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (conditionOnly) {
|
||||||
ConditionAdapter adapter = new ConditionAdapter(mContext,
|
ConditionAdapter adapter = new ConditionAdapter(mContext,
|
||||||
(List<Condition>) mDashboardData.getItemEntityByPosition(position),
|
(List<Condition>) mDashboardData.getItemEntityByPosition(position),
|
||||||
mDashboardData.getSuggestionConditionMode());
|
mDashboardData.getSuggestionConditionMode());
|
||||||
@@ -482,11 +548,16 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onSaveInstanceState(Bundle outState) {
|
void onSaveInstanceState(Bundle outState) {
|
||||||
final List<Tile> suggestions = mDashboardData.getSuggestions();
|
|
||||||
final DashboardCategory category = mDashboardData.getCategory();
|
final DashboardCategory category = mDashboardData.getCategory();
|
||||||
|
final List<Tile> suggestions = mDashboardData.getSuggestions();
|
||||||
|
final List<Suggestion> suggestionV2 = mDashboardData.getSuggestionsV2();
|
||||||
if (suggestions != null) {
|
if (suggestions != null) {
|
||||||
outState.putParcelableArrayList(STATE_SUGGESTION_LIST, new ArrayList<>(suggestions));
|
outState.putParcelableArrayList(STATE_SUGGESTION_LIST, new ArrayList<>(suggestions));
|
||||||
}
|
}
|
||||||
|
if (suggestionV2 != null) {
|
||||||
|
outState.putParcelableArrayList(STATE_SUGGESTION_LIST_V2,
|
||||||
|
new ArrayList<>(suggestionV2));
|
||||||
|
}
|
||||||
if (category != null) {
|
if (category != null) {
|
||||||
outState.putParcelable(STATE_CATEGORY_LIST, category);
|
outState.putParcelable(STATE_CATEGORY_LIST, category);
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,7 @@ package com.android.settings.dashboard;
|
|||||||
|
|
||||||
import android.annotation.IntDef;
|
import android.annotation.IntDef;
|
||||||
import android.graphics.drawable.Icon;
|
import android.graphics.drawable.Icon;
|
||||||
|
import android.service.settings.suggestions.Suggestion;
|
||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
import android.support.v7.util.DiffUtil;
|
import android.support.v7.util.DiffUtil;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -69,6 +70,7 @@ public class DashboardData {
|
|||||||
private final DashboardCategory mCategory;
|
private final DashboardCategory mCategory;
|
||||||
private final List<Condition> mConditions;
|
private final List<Condition> mConditions;
|
||||||
private final List<Tile> mSuggestions;
|
private final List<Tile> mSuggestions;
|
||||||
|
private final List<Suggestion> mSuggestionsV2;
|
||||||
@HeaderMode
|
@HeaderMode
|
||||||
private final int mSuggestionConditionMode;
|
private final int mSuggestionConditionMode;
|
||||||
|
|
||||||
@@ -76,6 +78,7 @@ public class DashboardData {
|
|||||||
mCategory = builder.mCategory;
|
mCategory = builder.mCategory;
|
||||||
mConditions = builder.mConditions;
|
mConditions = builder.mConditions;
|
||||||
mSuggestions = builder.mSuggestions;
|
mSuggestions = builder.mSuggestions;
|
||||||
|
mSuggestionsV2 = builder.mSuggestionsV2;
|
||||||
mSuggestionConditionMode = builder.mSuggestionConditionMode;
|
mSuggestionConditionMode = builder.mSuggestionConditionMode;
|
||||||
|
|
||||||
mItems = new ArrayList<>();
|
mItems = new ArrayList<>();
|
||||||
@@ -124,6 +127,10 @@ public class DashboardData {
|
|||||||
return mSuggestions;
|
return mSuggestions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Suggestion> getSuggestionsV2() {
|
||||||
|
return mSuggestionsV2;
|
||||||
|
}
|
||||||
|
|
||||||
public int getSuggestionConditionMode() {
|
public int getSuggestionConditionMode() {
|
||||||
return mSuggestionConditionMode;
|
return mSuggestionConditionMode;
|
||||||
}
|
}
|
||||||
@@ -190,13 +197,22 @@ public class DashboardData {
|
|||||||
* and mIsShowingAll, mSuggestionConditionMode flag.
|
* and mIsShowingAll, mSuggestionConditionMode flag.
|
||||||
*/
|
*/
|
||||||
private void buildItemsData() {
|
private void buildItemsData() {
|
||||||
final boolean hasSuggestions = sizeOf(mSuggestions) > 0;
|
final boolean useSuggestionV2 = mSuggestionsV2 != null;
|
||||||
|
final boolean hasSuggestions = useSuggestionV2
|
||||||
|
? sizeOf(mSuggestionsV2) > 0
|
||||||
|
: sizeOf(mSuggestions) > 0;
|
||||||
final List<Condition> conditions = getConditionsToShow(mConditions);
|
final List<Condition> conditions = getConditionsToShow(mConditions);
|
||||||
final boolean hasConditions = sizeOf(conditions) > 0;
|
final boolean hasConditions = sizeOf(conditions) > 0;
|
||||||
|
|
||||||
final List<Tile> suggestions = getSuggestionsToShow(mSuggestions);
|
final List<Tile> suggestions = getSuggestionsToShow(mSuggestions);
|
||||||
final int hiddenSuggestion =
|
final List<Suggestion> suggestionsV2 = getSuggestionsV2ToShow(mSuggestionsV2);
|
||||||
hasSuggestions ? sizeOf(mSuggestions) - sizeOf(suggestions) : 0;
|
|
||||||
|
final int hiddenSuggestion;
|
||||||
|
if (useSuggestionV2) {
|
||||||
|
hiddenSuggestion = hasSuggestions ? sizeOf(mSuggestionsV2) - sizeOf(suggestionsV2) : 0;
|
||||||
|
} else {
|
||||||
|
hiddenSuggestion = hasSuggestions ? sizeOf(mSuggestions) - sizeOf(suggestions) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
final boolean hasSuggestionAndCollapsed = hasSuggestions
|
final boolean hasSuggestionAndCollapsed = hasSuggestions
|
||||||
&& mSuggestionConditionMode == HEADER_MODE_COLLAPSED;
|
&& mSuggestionConditionMode == HEADER_MODE_COLLAPSED;
|
||||||
@@ -215,10 +231,15 @@ public class DashboardData {
|
|||||||
R.layout.suggestion_condition_header,
|
R.layout.suggestion_condition_header,
|
||||||
STABLE_ID_SUGGESTION_CONDITION_MIDDLE_HEADER, onlyHasConditionAndCollapsed);
|
STABLE_ID_SUGGESTION_CONDITION_MIDDLE_HEADER, onlyHasConditionAndCollapsed);
|
||||||
|
|
||||||
|
if (useSuggestionV2) {
|
||||||
|
addToItemList(suggestionsV2, R.layout.suggestion_condition_container,
|
||||||
|
STABLE_ID_SUGGESTION_CONTAINER, sizeOf(suggestionsV2) > 0);
|
||||||
|
} else {
|
||||||
/* Suggestion container. This is the card view that contains the list of suggestions.
|
/* Suggestion container. This is the card view that contains the list of suggestions.
|
||||||
* This will be added whenever the suggestion list is not empty */
|
* This will be added whenever the suggestion list is not empty */
|
||||||
addToItemList(suggestions, R.layout.suggestion_condition_container,
|
addToItemList(suggestions, R.layout.suggestion_condition_container,
|
||||||
STABLE_ID_SUGGESTION_CONTAINER, sizeOf(suggestions) > 0);
|
STABLE_ID_SUGGESTION_CONTAINER, sizeOf(suggestions) > 0);
|
||||||
|
}
|
||||||
|
|
||||||
/* Second suggestion/condition header. This will be added when there is at least one
|
/* Second suggestion/condition header. This will be added when there is at least one
|
||||||
* suggestion or condition that is not currently displayed, and the user can expand the
|
* suggestion or condition that is not currently displayed, and the user can expand the
|
||||||
@@ -246,7 +267,7 @@ public class DashboardData {
|
|||||||
&& !hasConditions
|
&& !hasConditions
|
||||||
&& hiddenSuggestion == 0);
|
&& hiddenSuggestion == 0);
|
||||||
|
|
||||||
if(mCategory != null) {
|
if (mCategory != null) {
|
||||||
for (int j = 0; j < mCategory.tiles.size(); j++) {
|
for (int j = 0; j < mCategory.tiles.size(); j++) {
|
||||||
final Tile tile = mCategory.tiles.get(j);
|
final Tile tile = mCategory.tiles.get(j);
|
||||||
addToItemList(tile, R.layout.dashboard_tile, Objects.hash(tile.title),
|
addToItemList(tile, R.layout.dashboard_tile, Objects.hash(tile.title),
|
||||||
@@ -274,6 +295,10 @@ public class DashboardData {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated in favor of {@link #getSuggestionsV2ToShow}.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
private List<Tile> getSuggestionsToShow(List<Tile> suggestions) {
|
private List<Tile> getSuggestionsToShow(List<Tile> suggestions) {
|
||||||
if (suggestions == null || mSuggestionConditionMode == HEADER_MODE_COLLAPSED) {
|
if (suggestions == null || mSuggestionConditionMode == HEADER_MODE_COLLAPSED) {
|
||||||
return null;
|
return null;
|
||||||
@@ -285,6 +310,17 @@ public class DashboardData {
|
|||||||
return suggestions.subList(0, DEFAULT_SUGGESTION_COUNT);
|
return suggestions.subList(0, DEFAULT_SUGGESTION_COUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Suggestion> getSuggestionsV2ToShow(List<Suggestion> suggestions) {
|
||||||
|
if (suggestions == null || mSuggestionConditionMode == HEADER_MODE_COLLAPSED) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (mSuggestionConditionMode != HEADER_MODE_DEFAULT
|
||||||
|
|| suggestions.size() <= DEFAULT_SUGGESTION_COUNT) {
|
||||||
|
return suggestions;
|
||||||
|
}
|
||||||
|
return suggestions.subList(0, DEFAULT_SUGGESTION_COUNT);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder used to build the ItemsData
|
* Builder used to build the ItemsData
|
||||||
* <p>
|
* <p>
|
||||||
@@ -296,7 +332,12 @@ public class DashboardData {
|
|||||||
|
|
||||||
private DashboardCategory mCategory;
|
private DashboardCategory mCategory;
|
||||||
private List<Condition> mConditions;
|
private List<Condition> mConditions;
|
||||||
|
/**
|
||||||
|
* @deprecated in favor of SuggestionList
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
private List<Tile> mSuggestions;
|
private List<Tile> mSuggestions;
|
||||||
|
private List<Suggestion> mSuggestionsV2;
|
||||||
|
|
||||||
public Builder() {
|
public Builder() {
|
||||||
}
|
}
|
||||||
@@ -305,6 +346,7 @@ public class DashboardData {
|
|||||||
mCategory = dashboardData.mCategory;
|
mCategory = dashboardData.mCategory;
|
||||||
mConditions = dashboardData.mConditions;
|
mConditions = dashboardData.mConditions;
|
||||||
mSuggestions = dashboardData.mSuggestions;
|
mSuggestions = dashboardData.mSuggestions;
|
||||||
|
mSuggestionsV2 = dashboardData.mSuggestionsV2;
|
||||||
mSuggestionConditionMode = dashboardData.mSuggestionConditionMode;
|
mSuggestionConditionMode = dashboardData.mSuggestionConditionMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,11 +360,20 @@ public class DashboardData {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated in favor of {@link #setSuggestionsV2(List)})}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public Builder setSuggestions(List<Tile> suggestions) {
|
public Builder setSuggestions(List<Tile> suggestions) {
|
||||||
this.mSuggestions = suggestions;
|
this.mSuggestions = suggestions;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder setSuggestionsV2(List<Suggestion> suggestions) {
|
||||||
|
this.mSuggestionsV2 = suggestions;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Builder setSuggestionConditionMode(@HeaderMode int mode) {
|
public Builder setSuggestionConditionMode(@HeaderMode int mode) {
|
||||||
this.mSuggestionConditionMode = mode;
|
this.mSuggestionConditionMode = mode;
|
||||||
return this;
|
return this;
|
||||||
|
@@ -21,6 +21,7 @@ import android.content.Context;
|
|||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.service.settings.suggestions.Suggestion;
|
||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -36,9 +37,9 @@ import com.android.settings.dashboard.conditional.ConditionManager;
|
|||||||
import com.android.settings.dashboard.conditional.ConditionManager.ConditionListener;
|
import com.android.settings.dashboard.conditional.ConditionManager.ConditionListener;
|
||||||
import com.android.settings.dashboard.conditional.FocusRecyclerView;
|
import com.android.settings.dashboard.conditional.FocusRecyclerView;
|
||||||
import com.android.settings.dashboard.conditional.FocusRecyclerView.FocusListener;
|
import com.android.settings.dashboard.conditional.FocusRecyclerView.FocusListener;
|
||||||
|
import com.android.settings.dashboard.suggestions.SuggestionControllerMixin;
|
||||||
import com.android.settings.dashboard.suggestions.SuggestionDismissController;
|
import com.android.settings.dashboard.suggestions.SuggestionDismissController;
|
||||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
||||||
import com.android.settings.dashboard.suggestions.SuggestionControllerMixin;
|
|
||||||
import com.android.settings.dashboard.suggestions.SuggestionsChecks;
|
import com.android.settings.dashboard.suggestions.SuggestionsChecks;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.widget.ActionBarShadowController;
|
import com.android.settings.widget.ActionBarShadowController;
|
||||||
@@ -55,7 +56,8 @@ import java.util.List;
|
|||||||
|
|
||||||
public class DashboardSummary extends InstrumentedFragment
|
public class DashboardSummary extends InstrumentedFragment
|
||||||
implements CategoryListener, ConditionListener,
|
implements CategoryListener, ConditionListener,
|
||||||
FocusListener, SuggestionDismissController.Callback {
|
FocusListener, SuggestionDismissController.Callback,
|
||||||
|
SuggestionControllerMixin.SuggestionControllerHost {
|
||||||
public static final boolean DEBUG = false;
|
public static final boolean DEBUG = false;
|
||||||
private static final boolean DEBUG_TIMING = false;
|
private static final boolean DEBUG_TIMING = false;
|
||||||
private static final int MAX_WAIT_MILLIS = 700;
|
private static final int MAX_WAIT_MILLIS = 700;
|
||||||
@@ -86,7 +88,12 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
mSuggestionControllerMixin = new SuggestionControllerMixin(context, getLifecycle());
|
mSuggestionFeatureProvider = FeatureFactory.getFactory(context)
|
||||||
|
.getSuggestionFeatureProvider(context);
|
||||||
|
if (mSuggestionFeatureProvider.isSuggestionV2Enabled(context)) {
|
||||||
|
mSuggestionControllerMixin = new SuggestionControllerMixin(context, this /* host */,
|
||||||
|
getLifecycle());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -96,8 +103,6 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
mDashboardFeatureProvider = FeatureFactory.getFactory(activity)
|
mDashboardFeatureProvider = FeatureFactory.getFactory(activity)
|
||||||
.getDashboardFeatureProvider(activity);
|
.getDashboardFeatureProvider(activity);
|
||||||
mSuggestionFeatureProvider = FeatureFactory.getFactory(activity)
|
|
||||||
.getSuggestionFeatureProvider(activity);
|
|
||||||
|
|
||||||
mSummaryLoader = new SummaryLoader(activity, CategoryKey.CATEGORY_HOMEPAGE);
|
mSummaryLoader = new SummaryLoader(activity, CategoryKey.CATEGORY_HOMEPAGE);
|
||||||
|
|
||||||
@@ -109,8 +114,7 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
mSuggestionsChecks = new SuggestionsChecks(getContext());
|
mSuggestionsChecks = new SuggestionsChecks(getContext());
|
||||||
}
|
}
|
||||||
if (DEBUG_TIMING) {
|
if (DEBUG_TIMING) {
|
||||||
Log.d(TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
|
Log.d(TAG, "onCreate took " + (System.currentTimeMillis() - startTime) + " ms");
|
||||||
+ " ms");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,12 +225,12 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
void rebuildUI() {
|
void rebuildUI() {
|
||||||
if (!mSuggestionFeatureProvider.isSuggestionEnabled(getContext())) {
|
if (!mSuggestionFeatureProvider.isSuggestionEnabled(getContext())) {
|
||||||
Log.d(TAG, "Suggestion feature is disabled, skipping suggestion entirely");
|
Log.d(TAG, "Suggestion feature is disabled, skipping suggestion entirely");
|
||||||
updateCategoryAndSuggestion(null /* tiles */);
|
updateCategory();
|
||||||
} else {
|
} else {
|
||||||
new SuggestionLoader().execute();
|
new SuggestionLoader().execute();
|
||||||
// Set categories on their own if loading suggestions takes too long.
|
// Set categories on their own if loading suggestions takes too long.
|
||||||
mHandler.postDelayed(() -> {
|
mHandler.postDelayed(() -> {
|
||||||
updateCategoryAndSuggestion(null /* tiles */);
|
updateCategory();
|
||||||
}, MAX_WAIT_MILLIS);
|
}, MAX_WAIT_MILLIS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -263,6 +267,11 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Suggestion getSuggestionAt(int position) {
|
||||||
|
return mAdapter.getSuggestionV2(position);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tile getSuggestionForPosition(int position) {
|
public Tile getSuggestionForPosition(int position) {
|
||||||
return mAdapter.getSuggestion(position);
|
return mAdapter.getSuggestion(position);
|
||||||
@@ -273,6 +282,20 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
mAdapter.onSuggestionDismissed(suggestion);
|
mAdapter.onSuggestionDismissed(suggestion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSuggestionDismissed(Suggestion suggestion) {
|
||||||
|
mAdapter.onSuggestionDismissed(suggestion);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSuggestionReady(List<Suggestion> suggestions) {
|
||||||
|
mAdapter.setSuggestionsV2(suggestions);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated in favor of the real SuggestionLoader.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
private class SuggestionLoader extends AsyncTask<Void, Void, List<Tile>> {
|
private class SuggestionLoader extends AsyncTask<Void, Void, List<Tile>> {
|
||||||
@Override
|
@Override
|
||||||
protected List<Tile> doInBackground(Void... params) {
|
protected List<Tile> doInBackground(Void... params) {
|
||||||
@@ -311,6 +334,17 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateCategory() {
|
||||||
|
final DashboardCategory category = mDashboardFeatureProvider.getTilesForCategory(
|
||||||
|
CategoryKey.CATEGORY_HOMEPAGE);
|
||||||
|
mSummaryLoader.updateSummaryToCache(category);
|
||||||
|
mAdapter.setCategory(category);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated in favor of SuggestionControllerMixin.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void updateCategoryAndSuggestion(List<Tile> suggestions) {
|
void updateCategoryAndSuggestion(List<Tile> suggestions) {
|
||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
|
@@ -15,13 +15,17 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settings.dashboard.suggestions;
|
package com.android.settings.dashboard.suggestions;
|
||||||
|
|
||||||
|
import android.app.PendingIntent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.service.settings.suggestions.Suggestion;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
@@ -41,14 +45,18 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
|||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||||
private final SuggestionFeatureProvider mSuggestionFeatureProvider;
|
private final SuggestionFeatureProvider mSuggestionFeatureProvider;
|
||||||
private List<Tile> mSuggestions;
|
@Deprecated // in favor of mNewSuggestions
|
||||||
|
private final List<Tile> mSuggestions;
|
||||||
|
private final List<Suggestion> mSuggestionsV2;
|
||||||
private final IconCache mCache;
|
private final IconCache mCache;
|
||||||
private final List<String> mSuggestionsShownLogged;
|
private final List<String> mSuggestionsShownLogged;
|
||||||
|
|
||||||
public SuggestionAdapter(Context context, List<Tile> suggestions,
|
public SuggestionAdapter(Context context, List<Tile> suggestions,
|
||||||
|
List<Suggestion> suggestionsV2,
|
||||||
List<String> suggestionsShownLogged) {
|
List<String> suggestionsShownLogged) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mSuggestions = suggestions;
|
mSuggestions = suggestions;
|
||||||
|
mSuggestionsV2 = suggestionsV2;
|
||||||
mSuggestionsShownLogged = suggestionsShownLogged;
|
mSuggestionsShownLogged = suggestionsShownLogged;
|
||||||
mCache = new IconCache(context);
|
mCache = new IconCache(context);
|
||||||
final FeatureFactory factory = FeatureFactory.getFactory(context);
|
final FeatureFactory factory = FeatureFactory.getFactory(context);
|
||||||
@@ -66,6 +74,68 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(DashboardItemHolder holder, int position) {
|
public void onBindViewHolder(DashboardItemHolder holder, int position) {
|
||||||
|
if (mSuggestions != null) {
|
||||||
|
bindSuggestionTile(holder, position);
|
||||||
|
} else {
|
||||||
|
bindSuggestion(holder, position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void bindSuggestion(DashboardItemHolder holder, int position) {
|
||||||
|
final Suggestion suggestion = mSuggestionsV2.get(position);
|
||||||
|
final String id = suggestion.getId();
|
||||||
|
if (!mSuggestionsShownLogged.contains(id)) {
|
||||||
|
mMetricsFeatureProvider.action(
|
||||||
|
mContext, MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION, id);
|
||||||
|
mSuggestionsShownLogged.add(id);
|
||||||
|
}
|
||||||
|
// TODO: Add remote view field in Suggestion, and enable this.
|
||||||
|
// if (suggestion.remoteViews != null) {
|
||||||
|
// final ViewGroup itemView = (ViewGroup) holder.itemView;
|
||||||
|
// itemView.removeAllViews();
|
||||||
|
// itemView.addView(suggestion.remoteViews.apply(itemView.getContext(),
|
||||||
|
// itemView));
|
||||||
|
// } else
|
||||||
|
{
|
||||||
|
// TODO: Add icon field in Suggestion, and enable this.
|
||||||
|
// holder.icon.setImageDrawable(mCache.getIcon(suggestion.icon));
|
||||||
|
holder.title.setText(suggestion.getTitle());
|
||||||
|
final CharSequence summary = suggestion.getSummary();
|
||||||
|
if (!TextUtils.isEmpty(summary)) {
|
||||||
|
holder.summary.setText(summary);
|
||||||
|
holder.summary.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
holder.summary.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final View divider = holder.itemView.findViewById(R.id.divider);
|
||||||
|
if (divider != null) {
|
||||||
|
divider.setVisibility(position < mSuggestionsV2.size() - 1 ? View.VISIBLE : View.GONE);
|
||||||
|
}
|
||||||
|
View clickHandler = holder.itemView;
|
||||||
|
// If a view with @android:id/primary is defined, use that as the click handler
|
||||||
|
// instead.
|
||||||
|
final View primaryAction = holder.itemView.findViewById(android.R.id.primary);
|
||||||
|
if (primaryAction != null) {
|
||||||
|
clickHandler = primaryAction;
|
||||||
|
// set the item view to disabled to remove any touch effects
|
||||||
|
holder.itemView.setEnabled(false);
|
||||||
|
}
|
||||||
|
clickHandler.setOnClickListener(v -> {
|
||||||
|
mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_SETTINGS_SUGGESTION, id);
|
||||||
|
try {
|
||||||
|
suggestion.getPendingIntent().send();
|
||||||
|
} catch (PendingIntent.CanceledException e) {
|
||||||
|
Log.w(TAG, "Failed to start suggestion " + suggestion.getTitle());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated in favor {@link #bindSuggestion(DashboardItemHolder, int)}.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
private void bindSuggestionTile(DashboardItemHolder holder, int position) {
|
||||||
final Tile suggestion = (Tile) mSuggestions.get(position);
|
final Tile suggestion = (Tile) mSuggestions.get(position);
|
||||||
final String suggestionId = mSuggestionFeatureProvider.getSuggestionIdentifier(
|
final String suggestionId = mSuggestionFeatureProvider.getSuggestionIdentifier(
|
||||||
mContext, suggestion);
|
mContext, suggestion);
|
||||||
@@ -115,20 +185,39 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getItemId(int position) {
|
public long getItemId(int position) {
|
||||||
|
if (mSuggestions != null) {
|
||||||
return Objects.hash(mSuggestions.get(position).title);
|
return Objects.hash(mSuggestions.get(position).title);
|
||||||
|
} else {
|
||||||
|
return Objects.hash(mSuggestionsV2.get(position).getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemViewType(int position) {
|
public int getItemViewType(int position) {
|
||||||
|
if (mSuggestions != null) {
|
||||||
Tile suggestion = getSuggestion(position);
|
Tile suggestion = getSuggestion(position);
|
||||||
|
|
||||||
return suggestion.remoteViews != null
|
return suggestion.remoteViews != null
|
||||||
? R.layout.suggestion_tile_remote_container
|
? R.layout.suggestion_tile_remote_container
|
||||||
: R.layout.suggestion_tile;
|
: R.layout.suggestion_tile;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
return R.layout.suggestion_tile;
|
||||||
|
// TODO: Add remote view field in Suggestion, and enable this.
|
||||||
|
// Suggestion suggestion = getSuggestionsV2(position);
|
||||||
|
// return suggestion.remoteViews != null
|
||||||
|
// ? R.layout.suggestion_tile_remote_container
|
||||||
|
// : R.layout.suggestion_tile;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
|
if (mSuggestions != null) {
|
||||||
return mSuggestions.size();
|
return mSuggestions.size();
|
||||||
|
} else {
|
||||||
|
return mSuggestionsV2.size();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tile getSuggestion(int position) {
|
public Tile getSuggestion(int position) {
|
||||||
@@ -141,6 +230,16 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Suggestion getSuggestionsV2(int position) {
|
||||||
|
final long itemId = getItemId(position);
|
||||||
|
for (Suggestion suggestion : mSuggestionsV2) {
|
||||||
|
if (Objects.hash(suggestion.getId()) == itemId) {
|
||||||
|
return suggestion;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public void removeSuggestion(Tile suggestion) {
|
public void removeSuggestion(Tile suggestion) {
|
||||||
mSuggestions.remove(suggestion);
|
mSuggestions.remove(suggestion);
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
@@ -151,4 +250,8 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
|||||||
mSuggestionFeatureProvider.isSmartSuggestionEnabled(mContext));
|
mSuggestionFeatureProvider.isSmartSuggestionEnabled(mContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeSuggestion(Suggestion suggestion) {
|
||||||
|
mSuggestionsV2.remove(suggestion);
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,11 +16,12 @@
|
|||||||
|
|
||||||
package com.android.settings.dashboard.suggestions;
|
package com.android.settings.dashboard.suggestions;
|
||||||
|
|
||||||
|
import android.app.LoaderManager;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Loader;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.service.settings.suggestions.Suggestion;
|
import android.service.settings.suggestions.Suggestion;
|
||||||
import android.support.annotation.VisibleForTesting;
|
|
||||||
import android.util.FeatureFlagUtils;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
@@ -34,23 +35,32 @@ import java.util.List;
|
|||||||
* Manages IPC communication to SettingsIntelligence for suggestion related services.
|
* Manages IPC communication to SettingsIntelligence for suggestion related services.
|
||||||
*/
|
*/
|
||||||
public class SuggestionControllerMixin implements SuggestionController.ServiceConnectionListener,
|
public class SuggestionControllerMixin implements SuggestionController.ServiceConnectionListener,
|
||||||
LifecycleObserver, OnStart, OnStop {
|
LifecycleObserver, OnStart, OnStop, LoaderManager.LoaderCallbacks<List<Suggestion>> {
|
||||||
|
|
||||||
|
public interface SuggestionControllerHost {
|
||||||
|
/**
|
||||||
|
* Called when suggestion data fetching is ready.
|
||||||
|
*/
|
||||||
|
void onSuggestionReady(List<Suggestion> data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@link LoaderManager} associated with the host.
|
||||||
|
*/
|
||||||
|
LoaderManager getLoaderManager();
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
static final String FEATURE_FLAG = "new_settings_suggestion";
|
|
||||||
private static final String TAG = "SuggestionCtrlMixin";
|
private static final String TAG = "SuggestionCtrlMixin";
|
||||||
private static final boolean DEBUG = false;
|
private static final boolean DEBUG = false;
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final SuggestionController mSuggestionController;
|
private final SuggestionController mSuggestionController;
|
||||||
|
private final SuggestionControllerHost mHost;
|
||||||
|
|
||||||
public static boolean isEnabled() {
|
public SuggestionControllerMixin(Context context, SuggestionControllerHost host,
|
||||||
return FeatureFlagUtils.isEnabled(FEATURE_FLAG);
|
Lifecycle lifecycle) {
|
||||||
}
|
|
||||||
|
|
||||||
public SuggestionControllerMixin(Context context, Lifecycle lifecycle) {
|
|
||||||
mContext = context.getApplicationContext();
|
mContext = context.getApplicationContext();
|
||||||
mSuggestionController = new SuggestionController(context,
|
mHost = host;
|
||||||
|
mSuggestionController = new SuggestionController(mContext,
|
||||||
new ComponentName(
|
new ComponentName(
|
||||||
"com.android.settings.intelligence",
|
"com.android.settings.intelligence",
|
||||||
"com.android.settings.intelligence.suggestions.SuggestionService"),
|
"com.android.settings.intelligence.suggestions.SuggestionService"),
|
||||||
@@ -62,10 +72,6 @@ public class SuggestionControllerMixin implements SuggestionController.ServiceCo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
if (!isEnabled()) {
|
|
||||||
Log.w(TAG, "Feature not enabled, skipping");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mSuggestionController.start();
|
mSuggestionController.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,11 +82,8 @@ public class SuggestionControllerMixin implements SuggestionController.ServiceCo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServiceConnected() {
|
public void onServiceConnected() {
|
||||||
// TODO: Call API to get data from a loader instead of in current thread.
|
mHost.getLoaderManager().restartLoader(SuggestionLoader.LOADER_ID_SUGGESTIONS,
|
||||||
final List<Suggestion> data = mSuggestionController.getSuggestions();
|
null /* args */, this /* callback */);
|
||||||
if (DEBUG) {
|
|
||||||
Log.d(TAG, "data size " + (data == null ? 0 : data.size()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -88,5 +91,24 @@ public class SuggestionControllerMixin implements SuggestionController.ServiceCo
|
|||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "SuggestionService disconnected");
|
Log.d(TAG, "SuggestionService disconnected");
|
||||||
}
|
}
|
||||||
|
mHost.getLoaderManager().destroyLoader(SuggestionLoader.LOADER_ID_SUGGESTIONS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Loader<List<Suggestion>> onCreateLoader(int id, Bundle args) {
|
||||||
|
if (id == SuggestionLoader.LOADER_ID_SUGGESTIONS) {
|
||||||
|
return new SuggestionLoader(mContext, mSuggestionController);
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("This loader id is not supported " + id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoadFinished(Loader<List<Suggestion>> loader, List<Suggestion> data) {
|
||||||
|
mHost.onSuggestionReady(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoaderReset(Loader<List<Suggestion>> loader) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
package com.android.settings.dashboard.suggestions;
|
package com.android.settings.dashboard.suggestions;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.service.settings.suggestions.Suggestion;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.support.v7.widget.helper.ItemTouchHelper;
|
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||||
|
|
||||||
@@ -30,18 +31,37 @@ public class SuggestionDismissController extends ItemTouchHelper.SimpleCallback
|
|||||||
public interface Callback {
|
public interface Callback {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @deprecated in favor of {@link #getSuggestionAt(int)}
|
||||||
* Returns suggestion tile data from the callback
|
* Returns suggestion tile data from the callback
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
Tile getSuggestionForPosition(int position);
|
Tile getSuggestionForPosition(int position);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated in favor of {@link #onSuggestionDismissed(Suggestion)}
|
||||||
|
* Called when a suggestion is dismissed.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
void onSuggestionDismissed(Tile suggestion);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns suggestion tile data from the callback
|
||||||
|
*/
|
||||||
|
Suggestion getSuggestionAt(int position);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a suggestion is dismissed.
|
* Called when a suggestion is dismissed.
|
||||||
*/
|
*/
|
||||||
void onSuggestionDismissed(Tile suggestion);
|
void onSuggestionDismissed(Suggestion suggestion);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final SuggestionFeatureProvider mSuggestionFeatureProvider;
|
private final SuggestionFeatureProvider mSuggestionFeatureProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated in favor of the new Suggestion backend.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
private final SuggestionParser mSuggestionParser;
|
private final SuggestionParser mSuggestionParser;
|
||||||
private final Callback mCallback;
|
private final Callback mCallback;
|
||||||
|
|
||||||
@@ -79,8 +99,15 @@ public class SuggestionDismissController extends ItemTouchHelper.SimpleCallback
|
|||||||
if (mCallback == null) {
|
if (mCallback == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Tile suggestion = mCallback.getSuggestionForPosition(viewHolder.getAdapterPosition());
|
final int position = viewHolder.getAdapterPosition();
|
||||||
|
final Suggestion suggestionV2 = mCallback.getSuggestionAt(position);
|
||||||
|
if (suggestionV2 != null) {
|
||||||
|
mSuggestionFeatureProvider.dismissSuggestion(mContext, suggestionV2);
|
||||||
|
mCallback.onSuggestionDismissed(suggestionV2);
|
||||||
|
} else {
|
||||||
|
final Tile suggestion = mCallback.getSuggestionForPosition(position);
|
||||||
mSuggestionFeatureProvider.dismissSuggestion(mContext, mSuggestionParser, suggestion);
|
mSuggestionFeatureProvider.dismissSuggestion(mContext, mSuggestionParser, suggestion);
|
||||||
mCallback.onSuggestionDismissed(suggestion);
|
mCallback.onSuggestionDismissed(suggestion);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,7 @@ package com.android.settings.dashboard.suggestions;
|
|||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.service.settings.suggestions.Suggestion;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import com.android.settingslib.drawer.Tile;
|
import com.android.settingslib.drawer.Tile;
|
||||||
@@ -31,9 +32,16 @@ public interface SuggestionFeatureProvider {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not the whole suggestion feature is enabled.
|
* Whether or not the whole suggestion feature is enabled.
|
||||||
|
* @deprecated in favor of {@link #isSuggestionV2Enabled(Context)}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
boolean isSuggestionEnabled(Context context);
|
boolean isSuggestionEnabled(Context context);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not the suggestion v2 feature is enabled.
|
||||||
|
*/
|
||||||
|
boolean isSuggestionV2Enabled(Context context);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if smart suggestion should be used instead of xml based SuggestionParser.
|
* Returns true if smart suggestion should be used instead of xml based SuggestionParser.
|
||||||
*/
|
*/
|
||||||
@@ -52,7 +60,9 @@ public interface SuggestionFeatureProvider {
|
|||||||
*
|
*
|
||||||
* @param suggestions List of suggestion Tiles
|
* @param suggestions List of suggestion Tiles
|
||||||
* @param suggestionIds List of suggestion ids corresponding to the suggestion tiles.
|
* @param suggestionIds List of suggestion ids corresponding to the suggestion tiles.
|
||||||
|
* @deprecated in favor of SettingsIntelligence
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
void rankSuggestions(final List<Tile> suggestions, List<String> suggestionIds);
|
void rankSuggestions(final List<Tile> suggestions, List<String> suggestionIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,9 +72,17 @@ public interface SuggestionFeatureProvider {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Dismisses a suggestion.
|
* Dismisses a suggestion.
|
||||||
|
*
|
||||||
|
* @deprecated in favor of {@link #dismissSuggestion(Context, Suggestion)}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
void dismissSuggestion(Context context, SuggestionParser parser, Tile suggestion);
|
void dismissSuggestion(Context context, SuggestionParser parser, Tile suggestion);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dismisses a suggestion.
|
||||||
|
*/
|
||||||
|
void dismissSuggestion(Context context, Suggestion suggestion);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an identifier for the suggestion
|
* Returns an identifier for the suggestion
|
||||||
*/
|
*/
|
||||||
|
@@ -23,11 +23,14 @@ import android.content.Context;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.provider.Settings.Secure;
|
import android.provider.Settings.Secure;
|
||||||
|
import android.service.settings.suggestions.Suggestion;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
|
import android.util.FeatureFlagUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
|
import com.android.internal.logging.nano.MetricsProto;
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
import com.android.settings.Settings.AmbientDisplayPickupSuggestionActivity;
|
import com.android.settings.Settings.AmbientDisplayPickupSuggestionActivity;
|
||||||
import com.android.settings.Settings.AmbientDisplaySuggestionActivity;
|
import com.android.settings.Settings.AmbientDisplaySuggestionActivity;
|
||||||
@@ -46,7 +49,6 @@ import com.android.settings.support.NewDeviceIntroSuggestionActivity;
|
|||||||
import com.android.settingslib.drawer.Tile;
|
import com.android.settingslib.drawer.Tile;
|
||||||
import com.android.settingslib.suggestions.SuggestionParser;
|
import com.android.settingslib.suggestions.SuggestionParser;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider {
|
public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider {
|
||||||
@@ -55,6 +57,8 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
|
|||||||
private static final int EXCLUSIVE_SUGGESTION_MAX_COUNT = 3;
|
private static final int EXCLUSIVE_SUGGESTION_MAX_COUNT = 3;
|
||||||
|
|
||||||
private static final String SHARED_PREF_FILENAME = "suggestions";
|
private static final String SHARED_PREF_FILENAME = "suggestions";
|
||||||
|
@VisibleForTesting
|
||||||
|
static final String FEATURE_FLAG_SUGGESTIONS_V2 = "new_settings_suggestion";
|
||||||
|
|
||||||
private final SuggestionRanker mSuggestionRanker;
|
private final SuggestionRanker mSuggestionRanker;
|
||||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||||
@@ -63,7 +67,20 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
|
|||||||
public boolean isSuggestionEnabled(Context context) {
|
public boolean isSuggestionEnabled(Context context) {
|
||||||
final ActivityManager am =
|
final ActivityManager am =
|
||||||
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||||
return !am.isLowRamDevice();
|
boolean isLowRamDevice = am.isLowRamDevice();
|
||||||
|
return !isLowRamDevice && !isV2Enabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSuggestionV2Enabled(Context context) {
|
||||||
|
final ActivityManager am =
|
||||||
|
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||||
|
boolean isLowRamDevice = am.isLowRamDevice();
|
||||||
|
return !isLowRamDevice && isV2Enabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isV2Enabled() {
|
||||||
|
return FeatureFlagUtils.isEnabled(FEATURE_FLAG_SUGGESTIONS_V2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -148,6 +165,17 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
|
|||||||
PackageManager.DONT_KILL_APP);
|
PackageManager.DONT_KILL_APP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dismissSuggestion(Context context, Suggestion suggestion) {
|
||||||
|
if (suggestion == null || context == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mMetricsFeatureProvider.action(
|
||||||
|
context, MetricsProto.MetricsEvent.ACTION_SETTINGS_DISMISS_SUGGESTION,
|
||||||
|
suggestion.getId());
|
||||||
|
// TODO: Call SettingsIntelligence to dismiss suggestion.
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSuggestionIdentifier(Context context, Tile suggestion) {
|
public String getSuggestionIdentifier(Context context, Tile suggestion) {
|
||||||
if (suggestion.intent == null || suggestion.intent.getComponent() == null
|
if (suggestion.intent == null || suggestion.intent.getComponent() == null
|
||||||
|
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.dashboard.suggestions;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.service.settings.suggestions.Suggestion;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.settings.utils.AsyncLoader;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SuggestionLoader extends AsyncLoader<List<Suggestion>> {
|
||||||
|
|
||||||
|
public static final int LOADER_ID_SUGGESTIONS = 42;
|
||||||
|
private static final String TAG = "SuggestionLoader";
|
||||||
|
|
||||||
|
private final SuggestionController mSuggestionController;
|
||||||
|
|
||||||
|
public SuggestionLoader(Context context, SuggestionController controller) {
|
||||||
|
super(context);
|
||||||
|
mSuggestionController = controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDiscardResult(List<Suggestion> result) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Suggestion> loadInBackground() {
|
||||||
|
final List<Suggestion> data = mSuggestionController.getSuggestions();
|
||||||
|
if (data == null) {
|
||||||
|
Log.d(TAG, "data is null");
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "data size " + data.size());
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
@@ -16,5 +16,104 @@
|
|||||||
|
|
||||||
package android.service.settings.suggestions;
|
package android.service.settings.suggestions;
|
||||||
|
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
public class Suggestion {
|
public class Suggestion {
|
||||||
|
private final String mId;
|
||||||
|
private final CharSequence mTitle;
|
||||||
|
private final CharSequence mSummary;
|
||||||
|
private final PendingIntent mPendingIntent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the id for the suggestion object.
|
||||||
|
*/
|
||||||
|
public String getId() {
|
||||||
|
return mId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Title of the suggestion that is shown to the user.
|
||||||
|
*/
|
||||||
|
public CharSequence getTitle() {
|
||||||
|
return mTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional summary describing what this suggestion controls.
|
||||||
|
*/
|
||||||
|
public CharSequence getSummary() {
|
||||||
|
return mSummary;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Intent to launch when the suggestion is activated.
|
||||||
|
*/
|
||||||
|
public PendingIntent getPendingIntent() {
|
||||||
|
return mPendingIntent;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Suggestion(Builder builder) {
|
||||||
|
mTitle = builder.mTitle;
|
||||||
|
mSummary = builder.mSummary;
|
||||||
|
mPendingIntent = builder.mPendingIntent;
|
||||||
|
mId = builder.mId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Suggestion(Parcel in) {
|
||||||
|
mId = in.readString();
|
||||||
|
mTitle = in.readCharSequence();
|
||||||
|
mSummary = in.readCharSequence();
|
||||||
|
mPendingIntent = in.readParcelable(PendingIntent.class.getClassLoader());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder class for {@link Suggestion}.
|
||||||
|
*/
|
||||||
|
public static class Builder {
|
||||||
|
private final String mId;
|
||||||
|
private CharSequence mTitle;
|
||||||
|
private CharSequence mSummary;
|
||||||
|
private PendingIntent mPendingIntent;
|
||||||
|
|
||||||
|
public Builder(String id) {
|
||||||
|
if (TextUtils.isEmpty(id)) {
|
||||||
|
throw new IllegalArgumentException("Suggestion id cannot be empty");
|
||||||
|
}
|
||||||
|
mId = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets suggestion title
|
||||||
|
*/
|
||||||
|
|
||||||
|
public Builder setTitle(CharSequence title) {
|
||||||
|
mTitle = title;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets suggestion summary
|
||||||
|
*/
|
||||||
|
public Builder setSummary(CharSequence summary) {
|
||||||
|
mSummary = summary;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets suggestion intent
|
||||||
|
*/
|
||||||
|
public Builder setPendingIntent(PendingIntent pendingIntent) {
|
||||||
|
mPendingIntent = pendingIntent;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds an immutable {@link Suggestion} object.
|
||||||
|
*/
|
||||||
|
public Suggestion build() {
|
||||||
|
return new Suggestion(this /* builder */);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,6 +28,7 @@ import static org.mockito.Mockito.times;
|
|||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.app.PendingIntent;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -35,6 +36,7 @@ import android.content.res.Resources;
|
|||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.drawable.Icon;
|
import android.graphics.drawable.Icon;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.service.settings.suggestions.Suggestion;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
@@ -557,6 +559,33 @@ public class DashboardAdapterTest {
|
|||||||
// should not crash
|
// should not crash
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBindConditionAndSuggestion_v2_shouldSetSuggestionAdapterAndNoCrash() {
|
||||||
|
mDashboardAdapter = new DashboardAdapter(mContext, null, null, null, null);
|
||||||
|
final List<Suggestion> suggestions = makeSuggestionsV2("pkg1");
|
||||||
|
final DashboardCategory category = mock(DashboardCategory.class);
|
||||||
|
final List<Tile> tiles = new ArrayList<>();
|
||||||
|
tiles.add(mock(Tile.class));
|
||||||
|
category.tiles = tiles;
|
||||||
|
|
||||||
|
mDashboardAdapter.setSuggestionsV2(suggestions);
|
||||||
|
|
||||||
|
final RecyclerView data = mock(RecyclerView.class);
|
||||||
|
when(data.getResources()).thenReturn(mResources);
|
||||||
|
when(data.getContext()).thenReturn(mContext);
|
||||||
|
when(mResources.getDisplayMetrics()).thenReturn(mock(DisplayMetrics.class));
|
||||||
|
final View itemView = mock(View.class);
|
||||||
|
when(itemView.findViewById(R.id.data)).thenReturn(data);
|
||||||
|
final DashboardAdapter.SuggestionAndConditionContainerHolder holder =
|
||||||
|
new DashboardAdapter.SuggestionAndConditionContainerHolder(itemView);
|
||||||
|
|
||||||
|
mDashboardAdapter.onBindConditionAndSuggestion(
|
||||||
|
holder, DashboardAdapter.SUGGESTION_CONDITION_HEADER_POSITION);
|
||||||
|
|
||||||
|
verify(data).setAdapter(any(SuggestionAdapter.class));
|
||||||
|
// should not crash
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBindConditionAndSuggestion_emptySuggestion_shouldSetConditionAdpater() {
|
public void testBindConditionAndSuggestion_emptySuggestion_shouldSetConditionAdpater() {
|
||||||
final Bundle savedInstance = new Bundle();
|
final Bundle savedInstance = new Bundle();
|
||||||
@@ -598,6 +627,17 @@ public class DashboardAdapterTest {
|
|||||||
return suggestions;
|
return suggestions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Suggestion> makeSuggestionsV2(String... pkgNames) {
|
||||||
|
final List<Suggestion> suggestions = new ArrayList<>();
|
||||||
|
for (String pkgName : pkgNames) {
|
||||||
|
final Suggestion suggestion = new Suggestion.Builder(pkgName)
|
||||||
|
.setPendingIntent(mock(PendingIntent.class))
|
||||||
|
.build();
|
||||||
|
suggestions.add(suggestion);
|
||||||
|
}
|
||||||
|
return suggestions;
|
||||||
|
}
|
||||||
|
|
||||||
private void setupSuggestions(List<Tile> suggestions) {
|
private void setupSuggestions(List<Tile> suggestions) {
|
||||||
mDashboardAdapter.setCategoriesAndSuggestions(null /* category */, suggestions);
|
mDashboardAdapter.setCategoriesAndSuggestions(null /* category */, suggestions);
|
||||||
final Context context = RuntimeEnvironment.application;
|
final Context context = RuntimeEnvironment.application;
|
||||||
@@ -605,4 +645,6 @@ public class DashboardAdapterTest {
|
|||||||
LayoutInflater.from(context).inflate(
|
LayoutInflater.from(context).inflate(
|
||||||
R.layout.suggestion_condition_header, new RelativeLayout(context), true));
|
R.layout.suggestion_condition_header, new RelativeLayout(context), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -15,13 +15,23 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settings.dashboard.suggestions;
|
package com.android.settings.dashboard.suggestions;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.Mockito.any;
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
import android.app.PendingIntent;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.Icon;
|
import android.graphics.drawable.Icon;
|
||||||
|
import android.service.settings.suggestions.Suggestion;
|
||||||
|
import android.view.ContextThemeWrapper;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ContextThemeWrapper;
|
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
@@ -31,15 +41,12 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.dashboard.DashboardAdapter;
|
import com.android.settings.dashboard.DashboardAdapter;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settingslib.drawer.Tile;
|
import com.android.settingslib.drawer.Tile;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -50,22 +57,13 @@ import org.robolectric.RuntimeEnvironment;
|
|||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import java.util.ArrayList;
|
||||||
import static org.mockito.Mockito.any;
|
import java.util.List;
|
||||||
import static org.mockito.Mockito.doReturn;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.never;
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
public class SuggestionAdapterTest {
|
public class SuggestionAdapterTest {
|
||||||
@Mock
|
|
||||||
private Tile mSuggestion1;
|
|
||||||
@Mock
|
|
||||||
private Tile mSuggestion2;
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
private SettingsActivity mActivity;
|
private SettingsActivity mActivity;
|
||||||
|
|
||||||
@@ -74,6 +72,8 @@ public class SuggestionAdapterTest {
|
|||||||
private DashboardAdapter.DashboardItemHolder mSuggestionHolder;
|
private DashboardAdapter.DashboardItemHolder mSuggestionHolder;
|
||||||
private List<Tile> mOneSuggestion;
|
private List<Tile> mOneSuggestion;
|
||||||
private List<Tile> mTwoSuggestions;
|
private List<Tile> mTwoSuggestions;
|
||||||
|
private List<Suggestion> mOneSuggestionV2;
|
||||||
|
private List<Suggestion> mTwoSuggestionsV2;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -81,29 +81,64 @@ public class SuggestionAdapterTest {
|
|||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
FakeFeatureFactory.setupForTest(mActivity);
|
FakeFeatureFactory.setupForTest(mActivity);
|
||||||
|
|
||||||
mSuggestion1.title = "Test Suggestion 1";
|
final Tile suggestion1 = new Tile();
|
||||||
mSuggestion1.icon = mock(Icon.class);
|
final Tile suggestion2 = new Tile();
|
||||||
mSuggestion2.title = "Test Suggestion 2";
|
final Suggestion suggestion1V2 = new Suggestion.Builder("id1")
|
||||||
mSuggestion2.icon = mock(Icon.class);
|
.setTitle("Test suggestion 1")
|
||||||
|
.build();
|
||||||
|
final Suggestion suggestion2V2 = new Suggestion.Builder("id2")
|
||||||
|
.setTitle("Test suggestion 2")
|
||||||
|
.build();
|
||||||
|
suggestion1.title = "Test Suggestion 1";
|
||||||
|
suggestion1.icon = mock(Icon.class);
|
||||||
|
suggestion2.title = "Test Suggestion 2";
|
||||||
|
suggestion2.icon = mock(Icon.class);
|
||||||
mOneSuggestion = new ArrayList<>();
|
mOneSuggestion = new ArrayList<>();
|
||||||
mOneSuggestion.add(mSuggestion1);
|
mOneSuggestion.add(suggestion1);
|
||||||
mTwoSuggestions = new ArrayList<>();
|
mTwoSuggestions = new ArrayList<>();
|
||||||
mTwoSuggestions.add(mSuggestion1);
|
mTwoSuggestions.add(suggestion1);
|
||||||
mTwoSuggestions.add(mSuggestion2);
|
mTwoSuggestions.add(suggestion2);
|
||||||
|
mOneSuggestionV2 = new ArrayList<>();
|
||||||
|
mOneSuggestionV2.add(suggestion1V2);
|
||||||
|
mTwoSuggestionsV2 = new ArrayList<>();
|
||||||
|
mTwoSuggestionsV2.add(suggestion1V2);
|
||||||
|
mTwoSuggestionsV2.add(suggestion2V2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getItemCount_shouldReturnListSize() {
|
public void getItemCount_shouldReturnListSize() {
|
||||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mOneSuggestion, new ArrayList<>());
|
mSuggestionAdapter = new SuggestionAdapter(mContext, mOneSuggestion,
|
||||||
|
null /* suggestionV2 */, new ArrayList<>());
|
||||||
assertThat(mSuggestionAdapter.getItemCount()).isEqualTo(1);
|
assertThat(mSuggestionAdapter.getItemCount()).isEqualTo(1);
|
||||||
|
|
||||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mTwoSuggestions, new ArrayList<>());
|
mSuggestionAdapter = new SuggestionAdapter(mContext, mTwoSuggestions,
|
||||||
|
null /* suggestionV2 */, new ArrayList<>());
|
||||||
|
assertThat(mSuggestionAdapter.getItemCount()).isEqualTo(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getItemCount_v2_shouldReturnListSize() {
|
||||||
|
mSuggestionAdapter = new SuggestionAdapter(mContext, null /* suggestions */,
|
||||||
|
mOneSuggestionV2, new ArrayList<>());
|
||||||
|
assertThat(mSuggestionAdapter.getItemCount()).isEqualTo(1);
|
||||||
|
|
||||||
|
mSuggestionAdapter = new SuggestionAdapter(mContext, null /* suggestions */,
|
||||||
|
mTwoSuggestionsV2, new ArrayList<>());
|
||||||
assertThat(mSuggestionAdapter.getItemCount()).isEqualTo(2);
|
assertThat(mSuggestionAdapter.getItemCount()).isEqualTo(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getItemViewType_shouldReturnSuggestionTile() {
|
public void getItemViewType_shouldReturnSuggestionTile() {
|
||||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mOneSuggestion, new ArrayList<>());
|
mSuggestionAdapter = new SuggestionAdapter(mContext, mOneSuggestion,
|
||||||
|
null /* suggestionV2 */, new ArrayList<>());
|
||||||
|
assertThat(mSuggestionAdapter.getItemViewType(0))
|
||||||
|
.isEqualTo(R.layout.suggestion_tile);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getItemViewType_v2_shouldReturnSuggestionTile() {
|
||||||
|
mSuggestionAdapter = new SuggestionAdapter(mContext, null /* suggestions */,
|
||||||
|
mOneSuggestionV2, new ArrayList<>());
|
||||||
assertThat(mSuggestionAdapter.getItemViewType(0))
|
assertThat(mSuggestionAdapter.getItemViewType(0))
|
||||||
.isEqualTo(R.layout.suggestion_tile);
|
.isEqualTo(R.layout.suggestion_tile);
|
||||||
}
|
}
|
||||||
@@ -113,7 +148,8 @@ public class SuggestionAdapterTest {
|
|||||||
final View view = spy(LayoutInflater.from(mContext).inflate(
|
final View view = spy(LayoutInflater.from(mContext).inflate(
|
||||||
R.layout.suggestion_tile, new LinearLayout(mContext), true));
|
R.layout.suggestion_tile, new LinearLayout(mContext), true));
|
||||||
mSuggestionHolder = new DashboardAdapter.DashboardItemHolder(view);
|
mSuggestionHolder = new DashboardAdapter.DashboardItemHolder(view);
|
||||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mOneSuggestion, new ArrayList<>());
|
mSuggestionAdapter = new SuggestionAdapter(mContext, mOneSuggestion,
|
||||||
|
null /* suggestionV2 */, new ArrayList<>());
|
||||||
|
|
||||||
mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
|
mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
|
||||||
|
|
||||||
@@ -127,7 +163,7 @@ public class SuggestionAdapterTest {
|
|||||||
TextView textView = new TextView(RuntimeEnvironment.application);
|
TextView textView = new TextView(RuntimeEnvironment.application);
|
||||||
doReturn(textView).when(remoteViews).apply(any(Context.class), any(ViewGroup.class));
|
doReturn(textView).when(remoteViews).apply(any(Context.class), any(ViewGroup.class));
|
||||||
packages.get(0).remoteViews = remoteViews;
|
packages.get(0).remoteViews = remoteViews;
|
||||||
setupSuggestions(mActivity, packages);
|
setupSuggestions(mActivity, packages, null);
|
||||||
|
|
||||||
mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
|
mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
|
||||||
|
|
||||||
@@ -150,7 +186,7 @@ public class SuggestionAdapterTest {
|
|||||||
layout.addView(primary);
|
layout.addView(primary);
|
||||||
doReturn(layout).when(remoteViews).apply(any(Context.class), any(ViewGroup.class));
|
doReturn(layout).when(remoteViews).apply(any(Context.class), any(ViewGroup.class));
|
||||||
packages.get(0).remoteViews = remoteViews;
|
packages.get(0).remoteViews = remoteViews;
|
||||||
setupSuggestions(mActivity, packages);
|
setupSuggestions(mActivity, packages, null /* suggestionV2 */);
|
||||||
|
|
||||||
mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
|
mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
|
||||||
mSuggestionHolder.itemView.performClick();
|
mSuggestionHolder.itemView.performClick();
|
||||||
@@ -163,6 +199,18 @@ public class SuggestionAdapterTest {
|
|||||||
verify(mActivity).startSuggestion(any(Intent.class));
|
verify(mActivity).startSuggestion(any(Intent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onBindViewHolder_v2_itemViewShouldHandleClick()
|
||||||
|
throws PendingIntent.CanceledException {
|
||||||
|
final List<Suggestion> packages = makeSuggestionsV2("pkg1");
|
||||||
|
setupSuggestions(mActivity, null /* suggestionV1 */ , packages);
|
||||||
|
|
||||||
|
mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
|
||||||
|
mSuggestionHolder.itemView.performClick();
|
||||||
|
|
||||||
|
verify(packages.get(0).getPendingIntent()).send();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onBindViewHolder_viewsShouldClearOnRebind() {
|
public void onBindViewHolder_viewsShouldClearOnRebind() {
|
||||||
Context context =
|
Context context =
|
||||||
@@ -176,7 +224,7 @@ public class SuggestionAdapterTest {
|
|||||||
layout.addView(primary);
|
layout.addView(primary);
|
||||||
doReturn(layout).when(remoteViews).apply(any(Context.class), any(ViewGroup.class));
|
doReturn(layout).when(remoteViews).apply(any(Context.class), any(ViewGroup.class));
|
||||||
packages.get(0).remoteViews = remoteViews;
|
packages.get(0).remoteViews = remoteViews;
|
||||||
setupSuggestions(mActivity, packages);
|
setupSuggestions(mActivity, packages, null /* suggestionV2 */);
|
||||||
|
|
||||||
mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
|
mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
|
||||||
mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
|
mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
|
||||||
@@ -185,8 +233,10 @@ public class SuggestionAdapterTest {
|
|||||||
assertThat(itemView.getChildCount()).isEqualTo(1);
|
assertThat(itemView.getChildCount()).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupSuggestions(Context context, List<Tile> suggestions) {
|
private void setupSuggestions(Context context, List<Tile> suggestions,
|
||||||
mSuggestionAdapter = new SuggestionAdapter(context, suggestions, new ArrayList<>());
|
List<Suggestion> suggestionsV2) {
|
||||||
|
mSuggestionAdapter = new SuggestionAdapter(context, suggestions, suggestionsV2,
|
||||||
|
new ArrayList<>());
|
||||||
mSuggestionHolder = mSuggestionAdapter.onCreateViewHolder(
|
mSuggestionHolder = mSuggestionAdapter.onCreateViewHolder(
|
||||||
new FrameLayout(RuntimeEnvironment.application),
|
new FrameLayout(RuntimeEnvironment.application),
|
||||||
mSuggestionAdapter.getItemViewType(0));
|
mSuggestionAdapter.getItemViewType(0));
|
||||||
@@ -204,4 +254,14 @@ public class SuggestionAdapterTest {
|
|||||||
return suggestions;
|
return suggestions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Suggestion> makeSuggestionsV2(String... pkgNames) {
|
||||||
|
final List<Suggestion> suggestions = new ArrayList<>();
|
||||||
|
for (String pkgName : pkgNames) {
|
||||||
|
final Suggestion suggestion = new Suggestion.Builder(pkgName)
|
||||||
|
.setPendingIntent(mock(PendingIntent.class))
|
||||||
|
.build();
|
||||||
|
suggestions.add(suggestion);
|
||||||
|
}
|
||||||
|
return suggestions;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,14 +17,15 @@
|
|||||||
package com.android.settings.dashboard.suggestions;
|
package com.android.settings.dashboard.suggestions;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.app.LoaderManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.FeatureFlagUtils;
|
|
||||||
|
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
|
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
@@ -38,13 +39,14 @@ import org.robolectric.annotation.Config;
|
|||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||||
shadows = {
|
shadows = {
|
||||||
SettingsShadowSystemProperties.class,
|
|
||||||
ShadowSuggestionController.class
|
ShadowSuggestionController.class
|
||||||
})
|
})
|
||||||
public class SuggestionControllerMixinTest {
|
public class SuggestionControllerMixinTest {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
@Mock
|
||||||
|
private SuggestionControllerMixin.SuggestionControllerHost mHost;
|
||||||
private Lifecycle mLifecycle;
|
private Lifecycle mLifecycle;
|
||||||
private SuggestionControllerMixin mMixin;
|
private SuggestionControllerMixin mMixin;
|
||||||
|
|
||||||
@@ -53,33 +55,16 @@ public class SuggestionControllerMixinTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mLifecycle = new Lifecycle();
|
mLifecycle = new Lifecycle();
|
||||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
when(mContext.getApplicationContext()).thenReturn(mContext);
|
||||||
SettingsShadowSystemProperties.set(
|
|
||||||
FeatureFlagUtils.FFLAG_PREFIX + SuggestionControllerMixin.FEATURE_FLAG, "true");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
ShadowSuggestionController.reset();
|
ShadowSuggestionController.reset();
|
||||||
SettingsShadowSystemProperties.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void systemPropertySet_verifyIsEnabled() {
|
public void goThroughLifecycle_onStartStop_shouldStartStopController() {
|
||||||
SettingsShadowSystemProperties.set(
|
mMixin = new SuggestionControllerMixin(mContext, mHost, mLifecycle);
|
||||||
FeatureFlagUtils.FFLAG_PREFIX + SuggestionControllerMixin.FEATURE_FLAG, "true");
|
|
||||||
assertThat(SuggestionControllerMixin.isEnabled()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void systemPropertyNotSet_verifyIsDisabled() {
|
|
||||||
SettingsShadowSystemProperties.set(
|
|
||||||
FeatureFlagUtils.FFLAG_PREFIX + SuggestionControllerMixin.FEATURE_FLAG, "false");
|
|
||||||
assertThat(SuggestionControllerMixin.isEnabled()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void goThroughLifecycle_onStartStop_shouldStartStopService() {
|
|
||||||
mMixin = new SuggestionControllerMixin(mContext, mLifecycle);
|
|
||||||
|
|
||||||
mLifecycle.onStart();
|
mLifecycle.onStart();
|
||||||
assertThat(ShadowSuggestionController.sStartCalled).isTrue();
|
assertThat(ShadowSuggestionController.sStartCalled).isTrue();
|
||||||
@@ -90,10 +75,13 @@ public class SuggestionControllerMixinTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onServiceConnected_shouldGetSuggestion() {
|
public void onServiceConnected_shouldGetSuggestion() {
|
||||||
mMixin = new SuggestionControllerMixin(mContext, mLifecycle);
|
final LoaderManager loaderManager = mock(LoaderManager.class);
|
||||||
|
when(mHost.getLoaderManager()).thenReturn(loaderManager);
|
||||||
|
|
||||||
|
mMixin = new SuggestionControllerMixin(mContext, mHost, mLifecycle);
|
||||||
mMixin.onServiceConnected();
|
mMixin.onServiceConnected();
|
||||||
|
|
||||||
assertThat(ShadowSuggestionController.sGetSuggestionCalled).isTrue();
|
verify(loaderManager).restartLoader(SuggestionLoader.LOADER_ID_SUGGESTIONS,
|
||||||
|
null /* args */, mMixin /* callback */);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -35,6 +35,7 @@ import android.content.SharedPreferences;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.hardware.fingerprint.FingerprintManager;
|
import android.hardware.fingerprint.FingerprintManager;
|
||||||
import android.provider.Settings.Secure;
|
import android.provider.Settings.Secure;
|
||||||
|
import android.util.FeatureFlagUtils;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
@@ -54,10 +55,12 @@ import com.android.settings.gestures.SwipeToNotificationSettings;
|
|||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||||
|
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
|
||||||
import com.android.settings.testutils.shadow.ShadowSecureSettings;
|
import com.android.settings.testutils.shadow.ShadowSecureSettings;
|
||||||
import com.android.settingslib.drawer.Tile;
|
import com.android.settingslib.drawer.Tile;
|
||||||
import com.android.settingslib.suggestions.SuggestionParser;
|
import com.android.settingslib.suggestions.SuggestionParser;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -76,7 +79,10 @@ import java.util.List;
|
|||||||
@Config(
|
@Config(
|
||||||
manifest = TestConfig.MANIFEST_PATH,
|
manifest = TestConfig.MANIFEST_PATH,
|
||||||
sdk = TestConfig.SDK_VERSION,
|
sdk = TestConfig.SDK_VERSION,
|
||||||
shadows = {ShadowSecureSettings.class, SettingsShadowResources.class}
|
shadows = {ShadowSecureSettings.class,
|
||||||
|
SettingsShadowResources.class,
|
||||||
|
SettingsShadowSystemProperties.class
|
||||||
|
}
|
||||||
)
|
)
|
||||||
public class SuggestionFeatureProviderImplTest {
|
public class SuggestionFeatureProviderImplTest {
|
||||||
|
|
||||||
@@ -122,6 +128,11 @@ public class SuggestionFeatureProviderImplTest {
|
|||||||
mProvider = new SuggestionFeatureProviderImpl(mContext);
|
mProvider = new SuggestionFeatureProviderImpl(mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
SettingsShadowSystemProperties.clear();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isSuggestionCompleted_doubleTapPower_trueWhenNotAvailable() {
|
public void isSuggestionCompleted_doubleTapPower_trueWhenNotAvailable() {
|
||||||
SettingsShadowResources.overrideResource(
|
SettingsShadowResources.overrideResource(
|
||||||
@@ -288,6 +299,23 @@ public class SuggestionFeatureProviderImplTest {
|
|||||||
assertThat(mProvider.isSuggestionEnabled(mContext)).isTrue();
|
assertThat(mProvider.isSuggestionEnabled(mContext)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isSuggestionV2Enabled_isNotLowMemoryDevice_sysPropOn_shouldReturnTrue() {
|
||||||
|
when(mActivityManager.isLowRamDevice()).thenReturn(false);
|
||||||
|
SettingsShadowSystemProperties.set(
|
||||||
|
FeatureFlagUtils.FFLAG_PREFIX + mProvider.FEATURE_FLAG_SUGGESTIONS_V2, "true");
|
||||||
|
assertThat(mProvider.isSuggestionV2Enabled(mContext)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isSuggestionV2Enabled_isNotLowMemoryDevice_sysPropOff_shouldReturnTrue() {
|
||||||
|
when(mActivityManager.isLowRamDevice()).thenReturn(false);
|
||||||
|
SettingsShadowSystemProperties.set(
|
||||||
|
FeatureFlagUtils.FFLAG_PREFIX + mProvider.FEATURE_FLAG_SUGGESTIONS_V2, "false");
|
||||||
|
assertThat(mProvider.isSuggestionV2Enabled(mContext)).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dismissSuggestion_noParserOrSuggestion_noop() {
|
public void dismissSuggestion_noParserOrSuggestion_noop() {
|
||||||
mProvider.dismissSuggestion(mContext, null, null);
|
mProvider.dismissSuggestion(mContext, null, null);
|
||||||
|
Reference in New Issue
Block a user