Fix back stack didn't perserved when Files Activity launched by Setting storage then back case.

Due to FilesActivity set "android:documentLaunchMode="intoExisting", it will create
new task when launched from Storage Setting page.

When select FilesActivity task from recents & press back key, it will not back
to settings page.

Using startActivityForResult to set task as source task can fix task separated case.

Change-Id: I26362928261a1a9c0e485a486be493423d1fcf61
Fixes: 33117269
Test: Manual
Test: atest StorageItemPreferenceControllerTest
This commit is contained in:
lumark
2018-06-11 15:20:39 +08:00
parent ddd9283ee0
commit 9e25726593
2 changed files with 21 additions and 15 deletions

View File

@@ -19,6 +19,7 @@ import static com.android.settings.applications.manageapplications.ManageApplica
import static com.android.settings.applications.manageapplications.ManageApplications.EXTRA_WORK_ONLY;
import static com.android.settings.utils.FileSizeFormatter.MEGABYTE_IN_BYTES;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
@@ -123,7 +124,8 @@ public class StorageItemPreferenceControllerTest {
mController.handlePreferenceTreeClick(mPreference);
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(mActivity).startActivityAsUser(argumentCaptor.capture(), nullable(UserHandle.class));
verify(mActivity).startActivityForResultAsUser(argumentCaptor.capture(), anyInt(),
nullable(UserHandle.class));
final Intent intent = argumentCaptor.getValue();
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
@@ -140,8 +142,8 @@ public class StorageItemPreferenceControllerTest {
mController.handlePreferenceTreeClick(mPreference);
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(mFragment.getActivity())
.startActivityAsUser(argumentCaptor.capture(), nullable(UserHandle.class));
verify(mFragment.getActivity()).startActivityForResultAsUser(argumentCaptor.capture(),
anyInt(), nullable(UserHandle.class));
final Intent intent = argumentCaptor.getValue();
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
@@ -167,8 +169,8 @@ public class StorageItemPreferenceControllerTest {
mController.handlePreferenceTreeClick(mPreference);
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
nullable(UserHandle.class));
verify(mFragment.getActivity()).startActivityForResultAsUser(argumentCaptor.capture(),
anyInt(), nullable(UserHandle.class));
final Intent intent = argumentCaptor.getValue();
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
@@ -186,8 +188,8 @@ public class StorageItemPreferenceControllerTest {
mController.handlePreferenceTreeClick(mPreference);
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(mFragment.getActivity())
.startActivityAsUser(argumentCaptor.capture(), nullable(UserHandle.class));
verify(mFragment.getActivity()).startActivityForResultAsUser(argumentCaptor.capture(),
anyInt(), nullable(UserHandle.class));
Intent intent = argumentCaptor.getValue();
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
@@ -223,8 +225,8 @@ public class StorageItemPreferenceControllerTest {
.isTrue();
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
nullable(UserHandle.class));
verify(mFragment.getActivity()).startActivityForResultAsUser(argumentCaptor.capture(),
anyInt(), nullable(UserHandle.class));
Intent intent = argumentCaptor.getValue();
Intent browseIntent = mVolume.buildBrowseIntent();
@@ -240,8 +242,8 @@ public class StorageItemPreferenceControllerTest {
mController.handlePreferenceTreeClick(mPreference);
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
nullable(UserHandle.class));
verify(mFragment.getActivity()).startActivityForResultAsUser(argumentCaptor.capture(),
anyInt(), nullable(UserHandle.class));
Intent intent = argumentCaptor.getValue();
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
@@ -258,8 +260,8 @@ public class StorageItemPreferenceControllerTest {
mController.handlePreferenceTreeClick(mPreference);
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
nullable(UserHandle.class));
verify(mFragment.getActivity()).startActivityForResultAsUser(argumentCaptor.capture(),
anyInt(), nullable(UserHandle.class));
Intent intent = argumentCaptor.getValue();
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);