Add intent extra when launching WallpaperPicker from SUW and Settings
- Add extra to these intents to help WallpaperPicker log the launch source Bug: 154781896 Test: make SettingsRoboTests Change-Id: Ifb0ed22ab8ebfbb3c2ad24e9b7bad80007162b6e
This commit is contained in:
committed by
Wesley Wang
parent
a6575f9bb8
commit
ff0e65c7f7
@@ -49,6 +49,8 @@
|
||||
<string name="config_wallpaper_picker_class" translatable="false">com.android.settings.Settings$WallpaperSettingsActivity</string>
|
||||
<!-- Fully-qualified class name for the styles & wallpaper picker activity. -->
|
||||
<string name="config_styles_and_wallpaper_picker_class" translatable="false"></string>
|
||||
<!-- Intent extra for wallpaper picker activity. -->
|
||||
<string name="config_wallpaper_picker_launch_extra" translatable="false">com.android.wallpaper.LAUNCH_SOURCE</string>
|
||||
|
||||
<!-- Manufacturer backup settings to launch -->
|
||||
<string name="config_backup_settings_intent" translatable="false"></string>
|
||||
|
@@ -36,10 +36,12 @@ import java.util.List;
|
||||
|
||||
public class WallpaperPreferenceController extends BasePreferenceController {
|
||||
private static final String TAG = "WallpaperPrefController";
|
||||
private static final String LAUNCHED_SETTINGS = "app_launched_settings";
|
||||
|
||||
private final String mWallpaperPackage;
|
||||
private final String mWallpaperClass;
|
||||
private final String mStylesAndWallpaperClass;
|
||||
private final String mWallpaperLaunchExtra;
|
||||
|
||||
public WallpaperPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
@@ -47,6 +49,7 @@ public class WallpaperPreferenceController extends BasePreferenceController {
|
||||
mWallpaperClass = mContext.getString(R.string.config_wallpaper_picker_class);
|
||||
mStylesAndWallpaperClass =
|
||||
mContext.getString(R.string.config_styles_and_wallpaper_picker_class);
|
||||
mWallpaperLaunchExtra = mContext.getString(R.string.config_wallpaper_picker_launch_extra);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -96,7 +99,8 @@ public class WallpaperPreferenceController extends BasePreferenceController {
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (getPreferenceKey().equals(preference.getKey())) {
|
||||
final Intent intent = new Intent().setComponent(getComponentName());
|
||||
final Intent intent = new Intent().setComponent(
|
||||
getComponentName()).putExtra(mWallpaperLaunchExtra, LAUNCHED_SETTINGS);
|
||||
if (areStylesAvailable()) {
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@ import android.content.Intent;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.display.WallpaperPreferenceController;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.Indexable;
|
||||
@@ -40,11 +41,18 @@ public class WallpaperSuggestionActivity extends StyleSuggestionActivityBase imp
|
||||
private static final String WALLPAPER_FLAVOR_EXTRA = "com.android.launcher3.WALLPAPER_FLAVOR";
|
||||
private static final String WALLPAPER_FOCUS = "focus_wallpaper";
|
||||
private static final String WALLPAPER_ONLY = "wallpaper_only";
|
||||
private static final String LAUNCHED_SUW = "app_launched_suw";
|
||||
|
||||
private String mWallpaperLaunchExtra;
|
||||
|
||||
@Override
|
||||
protected void addExtras(Intent intent) {
|
||||
if (WizardManagerHelper.isAnySetupWizard(intent)) {
|
||||
intent.putExtra(WALLPAPER_FLAVOR_EXTRA, WALLPAPER_ONLY);
|
||||
|
||||
mWallpaperLaunchExtra =
|
||||
getResources().getString(R.string.config_wallpaper_picker_launch_extra);
|
||||
intent.putExtra(mWallpaperLaunchExtra, LAUNCHED_SUW);
|
||||
} else {
|
||||
intent.putExtra(WALLPAPER_FLAVOR_EXTRA, WALLPAPER_FOCUS);
|
||||
}
|
||||
|
@@ -211,4 +211,19 @@ public class WallpaperPreferenceControllerTest {
|
||||
.getNextStartedActivityForResult().intent.getComponent().getClassName())
|
||||
.isEqualTo(mContext.getString(R.string.config_styles_and_wallpaper_picker_class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_launchSourceExtra() {
|
||||
mShadowPackageManager.setResolveInfosForIntent(
|
||||
mWallpaperIntent, Lists.newArrayList());
|
||||
mShadowPackageManager.setResolveInfosForIntent(
|
||||
mStylesAndWallpaperIntent, Lists.newArrayList());
|
||||
Preference preference = new Preference(mContext);
|
||||
preference.setKey(TEST_KEY);
|
||||
|
||||
mController.handlePreferenceTreeClick(preference);
|
||||
|
||||
assertThat(Shadows.shadowOf(mContext).getNextStartedActivityForResult()
|
||||
.intent.hasExtra("com.android.wallpaper.LAUNCH_SOURCE")).isTrue();
|
||||
}
|
||||
}
|
||||
|
@@ -56,6 +56,7 @@ public class WallpaperSuggestionActivityTest {
|
||||
private static final String PACKAGE_WALLPAPER_ACTIVITY =
|
||||
"com.android.settings.wallpaper.WallpaperSuggestionActivity";
|
||||
private static final String WALLPAPER_FLAVOR = "com.android.launcher3.WALLPAPER_FLAVOR";
|
||||
private static final String WALLPAPER_LAUNCH_SOURCE = "com.android.wallpaper.LAUNCH_SOURCE";
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -100,7 +101,7 @@ public class WallpaperSuggestionActivityTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addExtras_intentFromSetupWizard_extrasHasWallpaperOnly() {
|
||||
public void addExtras_intentFromSetupWizard_extrasHasWallpaperOnlyAndLaunchedSuw() {
|
||||
WallpaperSuggestionActivity activity =
|
||||
Robolectric.buildActivity(WallpaperSuggestionActivity.class, new Intent(
|
||||
Intent.ACTION_MAIN).setComponent(
|
||||
@@ -112,6 +113,8 @@ public class WallpaperSuggestionActivityTest {
|
||||
|
||||
assertThat(intent).isNotNull();
|
||||
assertThat(intent.getStringExtra(WALLPAPER_FLAVOR)).isEqualTo("wallpaper_only");
|
||||
assertThat(intent.getStringExtra(WALLPAPER_LAUNCH_SOURCE))
|
||||
.isEqualTo("app_launched_suw");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user