Merge "Restart or finish HomepageActivity when it's launched unexpectedly" into main
This commit is contained in:
@@ -194,8 +194,12 @@ public class SettingsHomepageActivity extends FragmentActivity implements
|
|||||||
if (unprovisioned) {
|
if (unprovisioned) {
|
||||||
Log.e(TAG, "Device is not provisioned, exiting Settings");
|
Log.e(TAG, "Device is not provisioned, exiting Settings");
|
||||||
finish();
|
finish();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Settings homepage should be the task root, otherwise there will be UI issues.
|
||||||
|
boolean isTaskRoot = isTaskRoot();
|
||||||
|
|
||||||
mIsEmbeddingActivityEnabled = ActivityEmbeddingUtils.isEmbeddingActivityEnabled(this);
|
mIsEmbeddingActivityEnabled = ActivityEmbeddingUtils.isEmbeddingActivityEnabled(this);
|
||||||
if (mIsEmbeddingActivityEnabled) {
|
if (mIsEmbeddingActivityEnabled) {
|
||||||
final UserManager um = getSystemService(UserManager.class);
|
final UserManager um = getSystemService(UserManager.class);
|
||||||
@@ -211,13 +215,34 @@ public class SettingsHomepageActivity extends FragmentActivity implements
|
|||||||
} else {
|
} else {
|
||||||
intent.setPackage(getPackageName());
|
intent.setPackage(getPackageName());
|
||||||
}
|
}
|
||||||
intent.removeFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
if (!isTaskRoot) {
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
} else {
|
||||||
|
intent.removeFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
}
|
||||||
startActivityAsUser(intent, um.getProfileParent(userInfo.id).getUserHandle());
|
startActivityAsUser(intent, um.getProfileParent(userInfo.id).getUserHandle());
|
||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isTaskRoot) {
|
||||||
|
if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
|
||||||
|
Log.i(TAG, "Activity has been started, finishing");
|
||||||
|
} else {
|
||||||
|
Log.i(TAG, "Homepage should be started with FLAG_ACTIVITY_NEW_TASK, restarting");
|
||||||
|
Intent intent = new Intent(getIntent())
|
||||||
|
.setPackage(getPackageName())
|
||||||
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
| Intent.FLAG_ACTIVITY_FORWARD_RESULT)
|
||||||
|
.putExtra(EXTRA_USER_HANDLE, getUser())
|
||||||
|
.putExtra(EXTRA_INITIAL_REFERRER, getCurrentReferrer());
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setupEdgeToEdge();
|
setupEdgeToEdge();
|
||||||
setContentView(R.layout.settings_homepage_container);
|
setContentView(R.layout.settings_homepage_container);
|
||||||
|
|
||||||
|
@@ -24,11 +24,13 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.Assert.assertNotEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -241,6 +243,42 @@ public class SettingsHomepageActivityTest {
|
|||||||
& SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS).isEqualTo(0);
|
& SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onCreate_TaskRoot_shouldNotFinish() {
|
||||||
|
SettingsHomepageActivity activity =
|
||||||
|
spy(Robolectric.buildActivity(SettingsHomepageActivity.class).get());
|
||||||
|
doReturn(true).when(activity).isTaskRoot();
|
||||||
|
|
||||||
|
activity.onCreate(/* savedInstanceState */ null);
|
||||||
|
|
||||||
|
verify(activity, never()).finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onCreate_notTaskRoot_shouldRestartActivity() {
|
||||||
|
SettingsHomepageActivity activity =
|
||||||
|
spy(Robolectric.buildActivity(SettingsHomepageActivity.class).get());
|
||||||
|
doReturn(false).when(activity).isTaskRoot();
|
||||||
|
|
||||||
|
activity.onCreate(/* savedInstanceState */ null);
|
||||||
|
|
||||||
|
verify(activity).finish();
|
||||||
|
verify(activity).startActivity(any(Intent.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onCreate_notTaskRoot_flagNewTask_shouldOnlyFinish() {
|
||||||
|
SettingsHomepageActivity activity =
|
||||||
|
spy(Robolectric.buildActivity(SettingsHomepageActivity.class).get());
|
||||||
|
doReturn(false).when(activity).isTaskRoot();
|
||||||
|
activity.setIntent(new Intent().addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||||
|
|
||||||
|
activity.onCreate(/* savedInstanceState */ null);
|
||||||
|
|
||||||
|
verify(activity).finish();
|
||||||
|
verify(activity, never()).startActivity(any(Intent.class));
|
||||||
|
}
|
||||||
|
|
||||||
/** This test is for large screen devices Activity embedding. */
|
/** This test is for large screen devices Activity embedding. */
|
||||||
@Test
|
@Test
|
||||||
@Config(shadows = ShadowActivityEmbeddingUtils.class)
|
@Config(shadows = ShadowActivityEmbeddingUtils.class)
|
||||||
|
Reference in New Issue
Block a user