Snap for 6497471 from 1af21492fe to mainline-release

Change-Id: Ibbf29df92e60c75ac407e8181caa035559a46c0f
This commit is contained in:
android-build-team Robot
2020-05-15 07:08:06 +00:00
15 changed files with 111 additions and 63 deletions

View File

@@ -20,7 +20,7 @@
android:title="@string/storage_settings" android:title="@string/storage_settings"
android:orderingFromXml="false"> android:orderingFromXml="false">
<com.android.settings.deviceinfo.storage.StorageSummaryDonutPreference <com.android.settings.deviceinfo.storage.StorageSummaryDonutPreference
android:key="pref_summary" android:key="storage_summary"
android:order="0" android:order="0"
settings:searchable="false" settings:searchable="false"
settings:controller="com.android.settings.deviceinfo.storage.StorageSummaryDonutPreferenceController"/> settings:controller="com.android.settings.deviceinfo.storage.StorageSummaryDonutPreferenceController"/>

View File

@@ -23,6 +23,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import android.text.TextUtils;
import androidx.preference.Preference; import androidx.preference.Preference;
@@ -100,29 +101,31 @@ public abstract class BiometricStatusPreferenceController extends BasePreference
} else { } else {
preference.setVisible(true); preference.setVisible(true);
} }
final int userId = getUserId(); preference.setSummary(hasEnrolledBiometrics() ? getSummaryTextEnrolled()
final String clazz; : getSummaryTextNoneEnrolled());
if (hasEnrolledBiometrics()) { }
preference.setSummary(getSummaryTextEnrolled());
clazz = getSettingsClassName(); @Override
} else { public boolean handlePreferenceTreeClick(Preference preference) {
preference.setSummary(getSummaryTextNoneEnrolled()); if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
clazz = getEnrollClassName(); return super.handlePreferenceTreeClick(preference);
} }
preference.setOnPreferenceClickListener(target -> {
final Context context = target.getContext(); final Context context = preference.getContext();
final UserManager userManager = UserManager.get(context); final UserManager userManager = UserManager.get(context);
if (Utils.startQuietModeDialogIfNecessary(context, userManager, final int userId = getUserId();
userId)) { if (Utils.startQuietModeDialogIfNecessary(context, userManager, userId)) {
return false; return false;
} }
Intent intent = new Intent();
intent.setClassName(SETTINGS_PACKAGE_NAME, clazz); final Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_USER_ID, userId); final String clazz = hasEnrolledBiometrics() ? getSettingsClassName()
intent.putExtra(EXTRA_FROM_SETTINGS_SUMMARY, true); : getEnrollClassName();
context.startActivity(intent); intent.setClassName(SETTINGS_PACKAGE_NAME, clazz);
return true; intent.putExtra(Intent.EXTRA_USER_ID, userId);
}); intent.putExtra(EXTRA_FROM_SETTINGS_SUMMARY, true);
context.startActivity(intent);
return true;
} }
protected int getUserId() { protected int getUserId() {

View File

@@ -35,6 +35,8 @@ import com.android.settings.R;
import com.android.settings.SettingsActivity; import com.android.settings.SettingsActivity;
import com.android.settings.core.BasePreferenceController; import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment; import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.widget.LayoutPreference; import com.android.settingslib.widget.LayoutPreference;
import java.util.List; import java.util.List;
@@ -80,12 +82,14 @@ public class FaceSettingsRemoveButtonPreferenceController extends BasePreference
void onRemoved(); void onRemoved();
} }
private Preference mPreference;
private Button mButton; private Button mButton;
private Listener mListener; private Listener mListener;
private SettingsActivity mActivity; private SettingsActivity mActivity;
private int mUserId; private int mUserId;
private boolean mRemoving; private boolean mRemoving;
private final MetricsFeatureProvider mMetricsFeatureProvider;
private final Context mContext; private final Context mContext;
private final FaceManager mFaceManager; private final FaceManager mFaceManager;
private final FaceManager.RemovalCallback mRemovalCallback = new FaceManager.RemovalCallback() { private final FaceManager.RemovalCallback mRemovalCallback = new FaceManager.RemovalCallback() {
@@ -141,6 +145,7 @@ public class FaceSettingsRemoveButtonPreferenceController extends BasePreference
super(context, preferenceKey); super(context, preferenceKey);
mContext = context; mContext = context;
mFaceManager = context.getSystemService(FaceManager.class); mFaceManager = context.getSystemService(FaceManager.class);
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
} }
public FaceSettingsRemoveButtonPreferenceController(Context context) { public FaceSettingsRemoveButtonPreferenceController(Context context) {
@@ -155,6 +160,7 @@ public class FaceSettingsRemoveButtonPreferenceController extends BasePreference
public void updateState(Preference preference) { public void updateState(Preference preference) {
super.updateState(preference); super.updateState(preference);
mPreference = preference;
mButton = ((LayoutPreference) preference) mButton = ((LayoutPreference) preference)
.findViewById(R.id.security_settings_face_settings_remove_button); .findViewById(R.id.security_settings_face_settings_remove_button);
mButton.setOnClickListener(this); mButton.setOnClickListener(this);
@@ -179,6 +185,7 @@ public class FaceSettingsRemoveButtonPreferenceController extends BasePreference
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (v == mButton) { if (v == mButton) {
mMetricsFeatureProvider.logClickedPreference(mPreference, getMetricsCategory());
mRemoving = true; mRemoving = true;
ConfirmRemoveDialog dialog = new ConfirmRemoveDialog(); ConfirmRemoveDialog dialog = new ConfirmRemoveDialog();
dialog.setOnClickListener(mOnClickListener); dialog.setOnClickListener(mOnClickListener);

View File

@@ -63,7 +63,7 @@ public class StorageDashboardFragment extends DashboardFragment
implements implements
LoaderManager.LoaderCallbacks<SparseArray<StorageAsyncLoader.AppsStorageResult>> { LoaderManager.LoaderCallbacks<SparseArray<StorageAsyncLoader.AppsStorageResult>> {
private static final String TAG = "StorageDashboardFrag"; private static final String TAG = "StorageDashboardFrag";
private static final String SUMMARY_PREF_KEY = "pref_summary"; private static final String SUMMARY_PREF_KEY = "storage_summary";
private static final int STORAGE_JOB_ID = 0; private static final int STORAGE_JOB_ID = 0;
private static final int ICON_JOB_ID = 1; private static final int ICON_JOB_ID = 1;
private static final int VOLUME_SIZE_JOB_ID = 2; private static final int VOLUME_SIZE_JOB_ID = 2;

View File

@@ -19,10 +19,7 @@ package com.android.settings.deviceinfo.storage;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Typeface;
import android.os.storage.StorageManager; import android.os.storage.StorageManager;
import android.text.TextPaint;
import android.text.style.StyleSpan;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
@@ -31,8 +28,10 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder; import androidx.preference.PreferenceViewHolder;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.overlay.FeatureFactory; import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.DonutView; import com.android.settings.widget.DonutView;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
/** /**
* StorageSummaryDonutPreference is a preference which summarizes the used and remaining storage left * StorageSummaryDonutPreference is a preference which summarizes the used and remaining storage left
@@ -79,23 +78,14 @@ public class StorageSummaryDonutPreference extends Preference implements View.On
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (v != null && R.id.deletion_helper_button == v.getId()) { if (v != null && R.id.deletion_helper_button == v.getId()) {
Context context = getContext(); final Context context = getContext();
FeatureFactory.getFactory(context).getMetricsFeatureProvider().action( final MetricsFeatureProvider metricsFeatureProvider =
context, SettingsEnums.STORAGE_FREE_UP_SPACE_NOW); FeatureFactory.getFactory(context).getMetricsFeatureProvider();
Intent intent = new Intent(StorageManager.ACTION_MANAGE_STORAGE); metricsFeatureProvider.logClickedPreference(this,
getContext().startActivity(intent); getExtras().getInt(DashboardFragment.CATEGORY));
} metricsFeatureProvider.action(context, SettingsEnums.STORAGE_FREE_UP_SPACE_NOW);
} final Intent intent = new Intent(StorageManager.ACTION_MANAGE_STORAGE);
context.startActivity(intent);
private static class BoldLinkSpan extends StyleSpan {
public BoldLinkSpan() {
super(Typeface.BOLD);
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setColor(ds.linkColor);
} }
} }
} }

View File

@@ -74,7 +74,7 @@ public class NightDisplayAutoModePreferenceController extends BasePreferenceCont
if (String.valueOf(ColorDisplayManager.AUTO_MODE_TWILIGHT).equals(newValue) if (String.valueOf(ColorDisplayManager.AUTO_MODE_TWILIGHT).equals(newValue)
&& !mLocationManager.isLocationEnabled()) { && !mLocationManager.isLocationEnabled()) {
TwilightLocationDialog.show(mContext); TwilightLocationDialog.show(mContext);
return false; return true;
} }
return mColorDisplayManager.setNightDisplayAutoMode(Integer.parseInt((String) newValue)); return mColorDisplayManager.setNightDisplayAutoMode(Integer.parseInt((String) newValue));
} }

View File

@@ -33,7 +33,7 @@ import com.android.settings.display.TwilightLocationDialog;
*/ */
public class DarkModeScheduleSelectorController extends BasePreferenceController public class DarkModeScheduleSelectorController extends BasePreferenceController
implements Preference.OnPreferenceChangeListener { implements Preference.OnPreferenceChangeListener {
private static final String TAG = DarkModeScheduleSelectorController.class.getSimpleName();
private final UiModeManager mUiModeManager; private final UiModeManager mUiModeManager;
private PowerManager mPowerManager; private PowerManager mPowerManager;
private DropDownPreference mPreference; private DropDownPreference mPreference;
@@ -51,7 +51,6 @@ public class DarkModeScheduleSelectorController extends BasePreferenceController
public void displayPreference(PreferenceScreen screen) { public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen); super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey()); mPreference = screen.findPreference(getPreferenceKey());
init();
} }
@Override @Override
@@ -59,7 +58,8 @@ public class DarkModeScheduleSelectorController extends BasePreferenceController
return BasePreferenceController.AVAILABLE; return BasePreferenceController.AVAILABLE;
} }
private void init() { @Override
public final void updateState(Preference preference) {
final boolean batterySaver = mPowerManager.isPowerSaveMode(); final boolean batterySaver = mPowerManager.isPowerSaveMode();
mPreference.setEnabled(!batterySaver); mPreference.setEnabled(!batterySaver);
mCurrentMode = getCurrentMode(); mCurrentMode = getCurrentMode();
@@ -87,25 +87,25 @@ public class DarkModeScheduleSelectorController extends BasePreferenceController
if (newMode == mCurrentMode) { if (newMode == mCurrentMode) {
return false; return false;
} }
mCurrentMode = newMode; if (newMode == mPreference.findIndexOfValue(
if (mCurrentMode == mPreference.findIndexOfValue(
mContext.getString(R.string.dark_ui_auto_mode_never))) { mContext.getString(R.string.dark_ui_auto_mode_never))) {
boolean active = (mContext.getResources().getConfiguration().uiMode boolean active = (mContext.getResources().getConfiguration().uiMode
& Configuration.UI_MODE_NIGHT_YES) != 0; & Configuration.UI_MODE_NIGHT_YES) != 0;
int mode = active ? UiModeManager.MODE_NIGHT_YES int mode = active ? UiModeManager.MODE_NIGHT_YES
: UiModeManager.MODE_NIGHT_NO; : UiModeManager.MODE_NIGHT_NO;
mUiModeManager.setNightMode(mode); mUiModeManager.setNightMode(mode);
} else if (mCurrentMode == mPreference.findIndexOfValue( } else if (newMode == mPreference.findIndexOfValue(
mContext.getString(R.string.dark_ui_auto_mode_auto))) { mContext.getString(R.string.dark_ui_auto_mode_auto))) {
if (!mLocationManager.isLocationEnabled()) { if (!mLocationManager.isLocationEnabled()) {
TwilightLocationDialog.show(mContext); TwilightLocationDialog.show(mContext);
return false; return true;
} }
mUiModeManager.setNightMode(UiModeManager.MODE_NIGHT_AUTO); mUiModeManager.setNightMode(UiModeManager.MODE_NIGHT_AUTO);
} else if (mCurrentMode == mPreference.findIndexOfValue( } else if (newMode == mPreference.findIndexOfValue(
mContext.getString(R.string.dark_ui_auto_mode_custom))) { mContext.getString(R.string.dark_ui_auto_mode_custom))) {
mUiModeManager.setNightMode(UiModeManager.MODE_NIGHT_CUSTOM); mUiModeManager.setNightMode(UiModeManager.MODE_NIGHT_CUSTOM);
} }
mCurrentMode = newMode;
return true; return true;
} }
} }

View File

@@ -18,6 +18,8 @@ package com.android.settings.homepage.contextualcards;
import static android.app.slice.Slice.HINT_ERROR; import static android.app.slice.Slice.HINT_ERROR;
import static com.android.settings.intelligence.ContextualCardProto.ContextualCard.Category.STICKY_VALUE;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
@@ -94,6 +96,11 @@ public class EligibleCardChecker implements Callable<ContextualCard> {
return false; return false;
} }
if (card.getCategory() == STICKY_VALUE) {
Log.d(TAG, "Sticky card, skip checking. Uri = " + card.getSliceUri());
return true;
}
final Slice slice = bindSlice(uri); final Slice slice = bindSlice(uri);
if (isSliceToggleable(slice)) { if (isSliceToggleable(slice)) {

View File

@@ -16,6 +16,8 @@
package com.android.settings.media; package com.android.settings.media;
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_INDICATOR_SLICE_URI; import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_INDICATOR_SLICE_URI;
import android.annotation.ColorInt; import android.annotation.ColorInt;
@@ -61,7 +63,7 @@ public class MediaOutputIndicatorSlice implements CustomSliceable {
final CharSequence title = mContext.getString(R.string.media_output_label_title, final CharSequence title = mContext.getString(R.string.media_output_label_title,
Utils.getApplicationLabel(mContext, getWorker().getPackageName())); Utils.getApplicationLabel(mContext, getWorker().getPackageName()));
final PendingIntent primaryActionIntent = PendingIntent.getActivity(mContext, final PendingIntent primaryActionIntent = PendingIntent.getActivity(mContext,
0 /* requestCode */, getMediaOutputSliceIntent(), 0 /* flags */); 0 /* requestCode */, getMediaOutputSliceIntent(), FLAG_UPDATE_CURRENT);
final SliceAction primarySliceAction = SliceAction.createDeeplink( final SliceAction primarySliceAction = SliceAction.createDeeplink(
primaryActionIntent, icon, ListBuilder.ICON_IMAGE, title); primaryActionIntent, icon, ListBuilder.ICON_IMAGE, title);
@ColorInt final int color = Utils.getColorAccentDefaultColor(mContext); @ColorInt final int color = Utils.getColorAccentDefaultColor(mContext);

View File

@@ -140,11 +140,10 @@ public class PanelSlicesAdapter
final Slice slice = sliceLiveData.getValue(); final Slice slice = sliceLiveData.getValue();
if (slice == null || slice.getUri().equals(MEDIA_OUTPUT_INDICATOR_SLICE_URI)) { if (slice == null || slice.getUri().equals(MEDIA_OUTPUT_INDICATOR_SLICE_URI)) {
mDividerAllowedAbove = false; mDividerAllowedAbove = false;
} } else if (position == 0 && (slice.getUri().equals(MEDIA_OUTPUT_SLICE_URI)
// Customize output switcher slice top padding
if (position == 0 && (slice.getUri().equals(MEDIA_OUTPUT_SLICE_URI)
|| slice.getUri().equals(MEDIA_OUTPUT_GROUP_SLICE_URI))) { || slice.getUri().equals(MEDIA_OUTPUT_GROUP_SLICE_URI))) {
sliceView.setClickable(false);
// Customize output switcher slice top padding
final int paddingTop = mPanelFragment.getResources().getDimensionPixelSize( final int paddingTop = mPanelFragment.getResources().getDimensionPixelSize(
R.dimen.output_switcher_slice_padding_top); R.dimen.output_switcher_slice_padding_top);
mSliceSliderLayout.setPadding(mSliceSliderLayout.getPaddingLeft(), paddingTop, mSliceSliderLayout.setPadding(mSliceSliderLayout.getPaddingLeft(), paddingTop,

View File

@@ -18,7 +18,10 @@ package com.android.settings.widget;
import androidx.preference.Preference; import androidx.preference.Preference;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
/* /*
* The switch controller that is used to update the switch widget in the MasterSwitchPreference * The switch controller that is used to update the switch widget in the MasterSwitchPreference
@@ -28,9 +31,12 @@ public class MasterSwitchController extends SwitchWidgetController implements
Preference.OnPreferenceChangeListener { Preference.OnPreferenceChangeListener {
private final MasterSwitchPreference mPreference; private final MasterSwitchPreference mPreference;
private final MetricsFeatureProvider mMetricsFeatureProvider;
public MasterSwitchController(MasterSwitchPreference preference) { public MasterSwitchController(MasterSwitchPreference preference) {
mPreference = preference; mPreference = preference;
mMetricsFeatureProvider = FeatureFactory.getFactory(preference.getContext())
.getMetricsFeatureProvider();
} }
@Override @Override
@@ -65,7 +71,12 @@ public class MasterSwitchController extends SwitchWidgetController implements
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
if (mListener != null) { if (mListener != null) {
return mListener.onSwitchToggled((Boolean) newValue); final boolean result = mListener.onSwitchToggled((Boolean) newValue);
if (result) {
mMetricsFeatureProvider.logClickedPreference(preference,
preference.getExtras().getInt(DashboardFragment.CATEGORY));
}
return result;
} }
return false; return false;
} }

View File

@@ -113,7 +113,6 @@ public class FaceStatusPreferenceControllerTest {
assertThat(mPreference.getSummary()).isEqualTo( assertThat(mPreference.getSummary()).isEqualTo(
mContext.getString(R.string.security_settings_face_preference_summary_none)); mContext.getString(R.string.security_settings_face_preference_summary_none));
assertThat(mPreference.isVisible()).isTrue(); assertThat(mPreference.isVisible()).isTrue();
assertThat(mPreference.getOnPreferenceClickListener()).isNotNull();
} }
@Test @Test
@@ -129,6 +128,5 @@ public class FaceStatusPreferenceControllerTest {
assertThat(mPreference.getSummary()).isEqualTo(mContext.getResources() assertThat(mPreference.getSummary()).isEqualTo(mContext.getResources()
.getString(R.string.security_settings_face_preference_summary)); .getString(R.string.security_settings_face_preference_summary));
assertThat(mPreference.isVisible()).isTrue(); assertThat(mPreference.isVisible()).isTrue();
assertThat(mPreference.getOnPreferenceClickListener()).isNotNull();
} }
} }

View File

@@ -115,7 +115,6 @@ public class FingerprintStatusPreferenceControllerTest {
assertThat(mPreference.getSummary()).isEqualTo( assertThat(mPreference.getSummary()).isEqualTo(
mContext.getString(R.string.security_settings_fingerprint_preference_summary_none)); mContext.getString(R.string.security_settings_fingerprint_preference_summary_none));
assertThat(mPreference.isVisible()).isTrue(); assertThat(mPreference.isVisible()).isTrue();
assertThat(mPreference.getOnPreferenceClickListener()).isNotNull();
} }
@Test @Test
@@ -130,6 +129,5 @@ public class FingerprintStatusPreferenceControllerTest {
assertThat(mPreference.getSummary()).isEqualTo(mContext.getResources().getQuantityString( assertThat(mPreference.getSummary()).isEqualTo(mContext.getResources().getQuantityString(
R.plurals.security_settings_fingerprint_preference_summary, 1, 1)); R.plurals.security_settings_fingerprint_preference_summary, 1, 1));
assertThat(mPreference.isVisible()).isTrue(); assertThat(mPreference.isVisible()).isTrue();
assertThat(mPreference.getOnPreferenceClickListener()).isNotNull();
} }
} }

View File

@@ -98,6 +98,7 @@ public class DarkModeScheduleSelectorControllerTest {
public void nightMode_updateStateNone_dropDownValueChangedToNone() { public void nightMode_updateStateNone_dropDownValueChangedToNone() {
when(mUiService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_YES); when(mUiService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_YES);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
mController.updateState(mScreen);
verify(mPreference).setValueIndex(0); verify(mPreference).setValueIndex(0);
} }
@@ -105,6 +106,7 @@ public class DarkModeScheduleSelectorControllerTest {
public void nightMode_updateStateNone_dropDownValueChangedToAuto() { public void nightMode_updateStateNone_dropDownValueChangedToAuto() {
when(mUiService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_AUTO); when(mUiService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_AUTO);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
mController.updateState(mScreen);
verify(mPreference).setValueIndex(1); verify(mPreference).setValueIndex(1);
} }
@@ -112,6 +114,7 @@ public class DarkModeScheduleSelectorControllerTest {
public void batterySaver_dropDown_disabledSelector() { public void batterySaver_dropDown_disabledSelector() {
when(mPM.isPowerSaveMode()).thenReturn(true); when(mPM.isPowerSaveMode()).thenReturn(true);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
mController.updateState(mScreen);
verify(mPreference).setEnabled(eq(false)); verify(mPreference).setEnabled(eq(false));
} }
} }

View File

@@ -18,11 +18,15 @@ package com.android.settings.homepage.contextualcards;
import static android.app.slice.Slice.HINT_ERROR; import static android.app.slice.Slice.HINT_ERROR;
import static com.android.settings.intelligence.ContextualCardProto.ContextualCard.Category.STICKY_VALUE;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.content.Context; import android.content.Context;
import android.net.Uri; import android.net.Uri;
@@ -64,6 +68,32 @@ public class EligibleCardCheckerTest {
assertThat(mEligibleCardChecker.isSliceToggleable(slice)).isTrue(); assertThat(mEligibleCardChecker.isSliceToggleable(slice)).isTrue();
} }
@Test
public void isCardEligibleToDisplay_stickyCard_returnTrue() {
final ContextualCard card = new ContextualCard.Builder()
.setName("test_card")
.setCardType(ContextualCard.CardType.SLICE)
.setCategory(STICKY_VALUE)
.setSliceUri(CustomSliceRegistry.FLASHLIGHT_SLICE_URI)
.build();
assertThat(mEligibleCardChecker.isCardEligibleToDisplay(card)).isTrue();
}
@Test
public void isCardEligibleToDisplay_stickyCard_shouldNotPrebind() {
final ContextualCard card = new ContextualCard.Builder()
.setName("test_card")
.setCardType(ContextualCard.CardType.SLICE)
.setCategory(STICKY_VALUE)
.setSliceUri(CustomSliceRegistry.FLASHLIGHT_SLICE_URI)
.build();
mEligibleCardChecker.isCardEligibleToDisplay(card);
verify(mEligibleCardChecker, never()).bindSlice(CustomSliceRegistry.FLASHLIGHT_SLICE_URI);
}
@Test @Test
public void isCardEligibleToDisplay_toggleSlice_hasInlineActionShouldBeTrue() { public void isCardEligibleToDisplay_toggleSlice_hasInlineActionShouldBeTrue() {
final ContextualWifiSlice wifiSlice = new ContextualWifiSlice(mContext); final ContextualWifiSlice wifiSlice = new ContextualWifiSlice(mContext);