Loading src/com/android/settings/Utils.java +29 −0 Original line number Diff line number Diff line Loading @@ -504,6 +504,26 @@ public final class Utils extends com.android.settingslib.Utils { metricsCategory); } /** * Start a new instance of the activity, showing only the given fragment. * When launched in this mode, the given preference fragment will be instantiated and fill the * entire activity. * * @param context The context. * @param fragmentName The name of the fragment to display. * @param titleResId resource id for the String to display for the title of this set * of preferences. * @param metricsCategory The current metricsCategory for logging source when fragment starts * @param intentFlags flag that should be added to the intent. */ public static void startWithFragment(Context context, String fragmentName, int titleResId, int metricsCategory, int intentFlags) { startWithFragment(context, fragmentName, null, null, 0, null /* titleResPackageName */, titleResId, null, false /* not a shortcut */, metricsCategory, intentFlags); } /** * Start a new instance of the activity, showing only the given fragment. * When launched in this mode, the given preference fragment will be instantiated and fill the Loading Loading @@ -544,8 +564,17 @@ public final class Utils extends com.android.settingslib.Utils { public static void startWithFragment(Context context, String fragmentName, Bundle args, Fragment resultTo, int resultRequestCode, String titleResPackageName, int titleResId, CharSequence title, boolean isShortcut, int metricsCategory) { startWithFragment(context, fragmentName, args, resultTo, resultRequestCode, titleResPackageName, titleResId, title, isShortcut, metricsCategory, 0); } public static void startWithFragment(Context context, String fragmentName, Bundle args, Fragment resultTo, int resultRequestCode, String titleResPackageName, int titleResId, CharSequence title, boolean isShortcut, int metricsCategory, int flags) { Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, titleResPackageName, titleResId, title, isShortcut, metricsCategory); intent.addFlags(flags); if (resultTo == null) { context.startActivity(intent); } else { Loading src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java +3 −3 Original line number Diff line number Diff line Loading @@ -51,9 +51,9 @@ public class WallpaperSuggestionActivity extends Activity { @VisibleForTesting void startFallbackSuggestion() { // fall back to default wallpaper picker Utils.startWithFragment(this, WallpaperTypeSettings.class.getName(), null, null, 0, R.string.wallpaper_suggestion_title, null, MetricsProto.MetricsEvent.DASHBOARD_SUMMARY); Utils.startWithFragment(this, WallpaperTypeSettings.class.getName(), R.string.wallpaper_suggestion_title, MetricsProto.MetricsEvent.DASHBOARD_SUMMARY, Intent.FLAG_ACTIVITY_FORWARD_RESULT); } @VisibleForTesting Loading src/com/android/settings/wallpaper/WallpaperTypeSettings.java +12 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.settings.wallpaper; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; Loading Loading @@ -67,7 +68,7 @@ public class WallpaperTypeSettings extends SettingsPreferenceFragment implements // Add Preference items for each of the matching activities for (ResolveInfo info : rList) { Preference pref = new Preference(getPrefContext()); Intent prefIntent = new Intent(intent); Intent prefIntent = new Intent(intent).addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT); prefIntent.setComponent(new ComponentName( info.activityInfo.packageName, info.activityInfo.name)); pref.setIntent(prefIntent); Loading @@ -79,6 +80,16 @@ public class WallpaperTypeSettings extends SettingsPreferenceFragment implements } } @Override public boolean onPreferenceTreeClick(Preference preference) { if (preference.getIntent() == null) { return super.onPreferenceTreeClick(preference); } startActivity(preference.getIntent()); finish(); return true; } public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = new BaseSearchIndexProvider() { @Override Loading tests/robotests/src/com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java +3 −1 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ import org.robolectric.annotation.Implements; import org.robolectric.shadows.ShadowActivity; @RunWith(SettingsRobolectricTestRunner.class) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O, shadows = { WallpaperSuggestionActivityTest.ShadowWallpaperManagerWrapper.class }) Loading @@ -67,6 +67,8 @@ public class WallpaperSuggestionActivityTest { final Intent intent = activity.getNextStartedActivity(); assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName()); assertThat(intent.getFlags()).isEqualTo(Intent.FLAG_ACTIVITY_FORWARD_RESULT); assertThat(activity.isFinishing()).isTrue(); } @Test Loading tests/robotests/src/com/android/settings/wallpaper/WallpaperTypeSettingsTest.java 0 → 100644 +67 −0 Original line number Diff line number Diff line package com.android.settings.wallpaper; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.robolectric.RuntimeEnvironment.application; import android.app.Activity; import android.content.Intent; import android.support.v7.preference.Preference; import com.android.settings.TestConfig; import com.android.settings.testutils.SettingsRobolectricTestRunner; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.robolectric.Robolectric; import org.robolectric.annotation.Config; @RunWith(SettingsRobolectricTestRunner.class) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O) public class WallpaperTypeSettingsTest { private Preference mPreference; private Intent mIntent; @Before public void setUp() { mIntent = new Intent(); mPreference = new Preference(application); } @Test public void testOnPreferenceTreeClick_intentNull_shouldDoNothing() { Activity activity = Robolectric.setupActivity(Activity.class); WallpaperTypeSettings fragment = spy(new WallpaperTypeSettings()); doReturn(activity).when(fragment).getActivity(); boolean handled = fragment.onPreferenceTreeClick(mPreference); assertThat(handled).isFalse(); } @Test public void testOnPreferenceTreeClick_shouldLaunchIntentAndFinish() { Activity activity = Robolectric.setupActivity(Activity.class); WallpaperTypeSettings fragment = spy(new WallpaperTypeSettings()); doReturn(activity).when(fragment).getActivity(); mPreference.setIntent(mIntent); doNothing().when(fragment).finish(); ArgumentCaptor<Intent> intent = ArgumentCaptor.forClass(Intent.class); doNothing().when(fragment).startActivity(intent.capture()); boolean handled = fragment.onPreferenceTreeClick(mPreference); assertThat(handled).isTrue(); verify(fragment, times(1)).finish(); assertThat(intent.getValue()).isSameAs(mIntent); } } Loading
src/com/android/settings/Utils.java +29 −0 Original line number Diff line number Diff line Loading @@ -504,6 +504,26 @@ public final class Utils extends com.android.settingslib.Utils { metricsCategory); } /** * Start a new instance of the activity, showing only the given fragment. * When launched in this mode, the given preference fragment will be instantiated and fill the * entire activity. * * @param context The context. * @param fragmentName The name of the fragment to display. * @param titleResId resource id for the String to display for the title of this set * of preferences. * @param metricsCategory The current metricsCategory for logging source when fragment starts * @param intentFlags flag that should be added to the intent. */ public static void startWithFragment(Context context, String fragmentName, int titleResId, int metricsCategory, int intentFlags) { startWithFragment(context, fragmentName, null, null, 0, null /* titleResPackageName */, titleResId, null, false /* not a shortcut */, metricsCategory, intentFlags); } /** * Start a new instance of the activity, showing only the given fragment. * When launched in this mode, the given preference fragment will be instantiated and fill the Loading Loading @@ -544,8 +564,17 @@ public final class Utils extends com.android.settingslib.Utils { public static void startWithFragment(Context context, String fragmentName, Bundle args, Fragment resultTo, int resultRequestCode, String titleResPackageName, int titleResId, CharSequence title, boolean isShortcut, int metricsCategory) { startWithFragment(context, fragmentName, args, resultTo, resultRequestCode, titleResPackageName, titleResId, title, isShortcut, metricsCategory, 0); } public static void startWithFragment(Context context, String fragmentName, Bundle args, Fragment resultTo, int resultRequestCode, String titleResPackageName, int titleResId, CharSequence title, boolean isShortcut, int metricsCategory, int flags) { Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, titleResPackageName, titleResId, title, isShortcut, metricsCategory); intent.addFlags(flags); if (resultTo == null) { context.startActivity(intent); } else { Loading
src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java +3 −3 Original line number Diff line number Diff line Loading @@ -51,9 +51,9 @@ public class WallpaperSuggestionActivity extends Activity { @VisibleForTesting void startFallbackSuggestion() { // fall back to default wallpaper picker Utils.startWithFragment(this, WallpaperTypeSettings.class.getName(), null, null, 0, R.string.wallpaper_suggestion_title, null, MetricsProto.MetricsEvent.DASHBOARD_SUMMARY); Utils.startWithFragment(this, WallpaperTypeSettings.class.getName(), R.string.wallpaper_suggestion_title, MetricsProto.MetricsEvent.DASHBOARD_SUMMARY, Intent.FLAG_ACTIVITY_FORWARD_RESULT); } @VisibleForTesting Loading
src/com/android/settings/wallpaper/WallpaperTypeSettings.java +12 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.settings.wallpaper; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; Loading Loading @@ -67,7 +68,7 @@ public class WallpaperTypeSettings extends SettingsPreferenceFragment implements // Add Preference items for each of the matching activities for (ResolveInfo info : rList) { Preference pref = new Preference(getPrefContext()); Intent prefIntent = new Intent(intent); Intent prefIntent = new Intent(intent).addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT); prefIntent.setComponent(new ComponentName( info.activityInfo.packageName, info.activityInfo.name)); pref.setIntent(prefIntent); Loading @@ -79,6 +80,16 @@ public class WallpaperTypeSettings extends SettingsPreferenceFragment implements } } @Override public boolean onPreferenceTreeClick(Preference preference) { if (preference.getIntent() == null) { return super.onPreferenceTreeClick(preference); } startActivity(preference.getIntent()); finish(); return true; } public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = new BaseSearchIndexProvider() { @Override Loading
tests/robotests/src/com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java +3 −1 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ import org.robolectric.annotation.Implements; import org.robolectric.shadows.ShadowActivity; @RunWith(SettingsRobolectricTestRunner.class) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O, shadows = { WallpaperSuggestionActivityTest.ShadowWallpaperManagerWrapper.class }) Loading @@ -67,6 +67,8 @@ public class WallpaperSuggestionActivityTest { final Intent intent = activity.getNextStartedActivity(); assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName()); assertThat(intent.getFlags()).isEqualTo(Intent.FLAG_ACTIVITY_FORWARD_RESULT); assertThat(activity.isFinishing()).isTrue(); } @Test Loading
tests/robotests/src/com/android/settings/wallpaper/WallpaperTypeSettingsTest.java 0 → 100644 +67 −0 Original line number Diff line number Diff line package com.android.settings.wallpaper; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.robolectric.RuntimeEnvironment.application; import android.app.Activity; import android.content.Intent; import android.support.v7.preference.Preference; import com.android.settings.TestConfig; import com.android.settings.testutils.SettingsRobolectricTestRunner; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.robolectric.Robolectric; import org.robolectric.annotation.Config; @RunWith(SettingsRobolectricTestRunner.class) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O) public class WallpaperTypeSettingsTest { private Preference mPreference; private Intent mIntent; @Before public void setUp() { mIntent = new Intent(); mPreference = new Preference(application); } @Test public void testOnPreferenceTreeClick_intentNull_shouldDoNothing() { Activity activity = Robolectric.setupActivity(Activity.class); WallpaperTypeSettings fragment = spy(new WallpaperTypeSettings()); doReturn(activity).when(fragment).getActivity(); boolean handled = fragment.onPreferenceTreeClick(mPreference); assertThat(handled).isFalse(); } @Test public void testOnPreferenceTreeClick_shouldLaunchIntentAndFinish() { Activity activity = Robolectric.setupActivity(Activity.class); WallpaperTypeSettings fragment = spy(new WallpaperTypeSettings()); doReturn(activity).when(fragment).getActivity(); mPreference.setIntent(mIntent); doNothing().when(fragment).finish(); ArgumentCaptor<Intent> intent = ArgumentCaptor.forClass(Intent.class); doNothing().when(fragment).startActivity(intent.capture()); boolean handled = fragment.onPreferenceTreeClick(mPreference); assertThat(handled).isTrue(); verify(fragment, times(1)).finish(); assertThat(intent.getValue()).isSameAs(mIntent); } }