Resolve intent before launching from DashboardFragment.
Once dashboard tile is displayed, the underlying intent can be disabled. We will eventually hide the item from UI, but there can be a brief moment before we are able to hide it. So to prevent user click and launch a non-exist intent, we will try to resolve it first before launching anything. Change-Id: Ic8d790bf3c5d4d269eadb757f789a1641928a7b7 Fix: 36036097 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -50,6 +50,7 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowActivity;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -293,9 +294,35 @@ public class DashboardFeatureProviderImplTest {
|
||||
.isEqualTo(MetricsProto.MetricsEvent.SETTINGS_GESTURES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clickPreference_withUnresolvableIntent_shouldNotLaunchAnything() {
|
||||
ReflectionHelpers.setField(
|
||||
mImpl, "mPackageManager", RuntimeEnvironment.getPackageManager());
|
||||
Activity activity = Robolectric.buildActivity(Activity.class).get();
|
||||
final ShadowApplication application = ShadowApplication.getInstance();
|
||||
final Preference preference = new Preference(application.getApplicationContext());
|
||||
final Tile tile = new Tile();
|
||||
tile.key = "key";
|
||||
tile.intent = new Intent();
|
||||
tile.intent.setComponent(new ComponentName("pkg", "class"));
|
||||
tile.metaData = new Bundle();
|
||||
tile.metaData.putString("com.android.settings.intent.action", "TestAction");
|
||||
tile.userHandle = null;
|
||||
|
||||
mImpl.bindPreferenceToTile(activity, MetricsProto.MetricsEvent.SETTINGS_GESTURES,
|
||||
preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
preference.performClick();
|
||||
|
||||
final ShadowActivity.IntentForResult launchIntent =
|
||||
shadowOf(activity).getNextStartedActivityForResult();
|
||||
|
||||
assertThat(launchIntent).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPreferences_noCategory_shouldReturnNull() {
|
||||
mImpl = new DashboardFeatureProviderImpl(mActivity, mCategoryManager);
|
||||
mImpl = new DashboardFeatureProviderImpl(mActivity);
|
||||
ReflectionHelpers.setField(mImpl, "mCategoryManager", mCategoryManager);
|
||||
when(mCategoryManager.getTilesByCategory(mActivity, CategoryKey.CATEGORY_HOMEPAGE))
|
||||
.thenReturn(null);
|
||||
|
||||
@@ -306,7 +333,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
|
||||
@Test
|
||||
public void getPreferences_noTileForCategory_shouldReturnNull() {
|
||||
mImpl = new DashboardFeatureProviderImpl(mActivity, mCategoryManager);
|
||||
mImpl = new DashboardFeatureProviderImpl(mActivity);
|
||||
ReflectionHelpers.setField(mImpl, "mCategoryManager", mCategoryManager);
|
||||
when(mCategoryManager.getTilesByCategory(mActivity, CategoryKey.CATEGORY_HOMEPAGE))
|
||||
.thenReturn(new DashboardCategory());
|
||||
|
||||
@@ -317,7 +345,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
|
||||
@Test
|
||||
public void getPreferences_hasTileForCategory_shouldReturnPrefList() {
|
||||
mImpl = new DashboardFeatureProviderImpl(mActivity, mCategoryManager);
|
||||
mImpl = new DashboardFeatureProviderImpl(mActivity);
|
||||
ReflectionHelpers.setField(mImpl, "mCategoryManager", mCategoryManager);
|
||||
final DashboardCategory category = new DashboardCategory();
|
||||
category.tiles.add(new Tile());
|
||||
when(mCategoryManager
|
||||
|
Reference in New Issue
Block a user