Not use NEW_TASKS for Wallpaper & style's 2-pane UX
Refine launch mode to support 2-pane UX for Settings. Bug: 197609643 Test: make RunSettingsRoboTests Change-Id: I5212bbcf8c512fac571284379a29cf487f387c5a
This commit is contained in:
@@ -31,6 +31,7 @@ import androidx.preference.Preference;
|
|||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.activityembedding.ActivityEmbeddingUtils;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||||
import com.android.settingslib.RestrictedTopLevelPreference;
|
import com.android.settingslib.RestrictedTopLevelPreference;
|
||||||
@@ -97,7 +98,8 @@ public class TopLevelWallpaperPreferenceController extends BasePreferenceControl
|
|||||||
if (getPreferenceKey().equals(preference.getKey())) {
|
if (getPreferenceKey().equals(preference.getKey())) {
|
||||||
final Intent intent = new Intent().setComponent(
|
final Intent intent = new Intent().setComponent(
|
||||||
getComponentName()).putExtra(mWallpaperLaunchExtra, LAUNCHED_SETTINGS);
|
getComponentName()).putExtra(mWallpaperLaunchExtra, LAUNCHED_SETTINGS);
|
||||||
if (areStylesAvailable()) {
|
if (areStylesAvailable() && !ActivityEmbeddingUtils.isEmbeddingActivityEnabled(
|
||||||
|
mContext)) {
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||||
}
|
}
|
||||||
preference.getContext().startActivity(intent);
|
preference.getContext().startActivity(intent);
|
||||||
|
@@ -29,6 +29,7 @@ import androidx.preference.Preference;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||||
|
import com.android.settings.testutils.shadow.ShadowActivityEmbeddingUtils;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
@@ -43,7 +44,7 @@ import org.robolectric.annotation.Config;
|
|||||||
import org.robolectric.shadows.ShadowPackageManager;
|
import org.robolectric.shadows.ShadowPackageManager;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@Config(shadows = {SettingsShadowResources.class})
|
@Config(shadows = {SettingsShadowResources.class, ShadowActivityEmbeddingUtils.class})
|
||||||
public class TopLevelWallpaperPreferenceControllerTest {
|
public class TopLevelWallpaperPreferenceControllerTest {
|
||||||
private static final String TEST_KEY = "test_key";
|
private static final String TEST_KEY = "test_key";
|
||||||
|
|
||||||
@@ -204,18 +205,32 @@ public class TopLevelWallpaperPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handlePreferenceTreeClick_launchClearTask() {
|
public void handlePreferenceTreeClick_embeddingActivityDisabled_launchWithTaskFlag() {
|
||||||
mShadowPackageManager.setResolveInfosForIntent(
|
ShadowActivityEmbeddingUtils.setIsEmbeddingActivityEnabled(false);
|
||||||
mWallpaperIntent, Lists.newArrayList());
|
|
||||||
mShadowPackageManager.setResolveInfosForIntent(
|
mShadowPackageManager.setResolveInfosForIntent(
|
||||||
mStylesAndWallpaperIntent, Lists.newArrayList(mock(ResolveInfo.class)));
|
mStylesAndWallpaperIntent, Lists.newArrayList(mock(ResolveInfo.class)));
|
||||||
|
|
||||||
Preference preference = new Preference(mContext);
|
Preference preference = new Preference(mContext);
|
||||||
preference.setKey(TEST_KEY);
|
preference.setKey(TEST_KEY);
|
||||||
|
|
||||||
mController.handlePreferenceTreeClick(preference);
|
mController.handlePreferenceTreeClick(preference);
|
||||||
|
|
||||||
assertThat((Shadows.shadowOf(mContext).getNextStartedActivityForResult()
|
int flags = Shadows.shadowOf(mContext).getNextStartedActivityForResult().intent.getFlags();
|
||||||
.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_TASK) != 0).isTrue();
|
assertThat((flags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0).isTrue();
|
||||||
|
assertThat((flags & Intent.FLAG_ACTIVITY_CLEAR_TASK) != 0).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void handlePreferenceTreeClick_embeddingActivityEnabled_launchWithoutTaskFlag() {
|
||||||
|
ShadowActivityEmbeddingUtils.setIsEmbeddingActivityEnabled(true);
|
||||||
|
mShadowPackageManager.setResolveInfosForIntent(
|
||||||
|
mStylesAndWallpaperIntent, Lists.newArrayList(mock(ResolveInfo.class)));
|
||||||
|
Preference preference = new Preference(mContext);
|
||||||
|
preference.setKey(TEST_KEY);
|
||||||
|
|
||||||
|
mController.handlePreferenceTreeClick(preference);
|
||||||
|
|
||||||
|
int flags = Shadows.shadowOf(mContext).getNextStartedActivityForResult().intent.getFlags();
|
||||||
|
assertThat((flags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0).isFalse();
|
||||||
|
assertThat((flags & Intent.FLAG_ACTIVITY_CLEAR_TASK) != 0).isFalse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 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.testutils.shadow;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.android.settings.activityembedding.ActivityEmbeddingUtils;
|
||||||
|
|
||||||
|
import org.robolectric.annotation.Implementation;
|
||||||
|
import org.robolectric.annotation.Implements;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shadow class for {@link ActivityEmbeddingUtils} to test embedding activity features.
|
||||||
|
*/
|
||||||
|
@Implements(ActivityEmbeddingUtils.class)
|
||||||
|
public class ShadowActivityEmbeddingUtils {
|
||||||
|
private static boolean sIsEmbeddingActivityEnabled;
|
||||||
|
|
||||||
|
@Implementation
|
||||||
|
public static boolean isEmbeddingActivityEnabled(Context context) {
|
||||||
|
return sIsEmbeddingActivityEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setIsEmbeddingActivityEnabled(boolean isEmbeddingActivityEnabled) {
|
||||||
|
sIsEmbeddingActivityEnabled = isEmbeddingActivityEnabled;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user