Merge "Fixes to interstitial activity transitions" into main

This commit is contained in:
Yuri Lin
2024-08-07 21:05:38 +00:00
committed by Android (Google) Code Review
2 changed files with 39 additions and 1 deletions

View File

@@ -115,18 +115,21 @@ public class SetupInterstitialActivity extends FragmentActivity {
if (intent == null) {
Log.w(TAG, "no intent found for modes interstitial");
finish();
return;
}
String modeId = intent.getStringExtra(EXTRA_AUTOMATIC_ZEN_RULE_ID);
if (modeId == null) {
Log.w(TAG, "no mode id included in intent: " + intent);
finish();
return;
}
ZenMode mode = mBackend.getMode(modeId);
if (mode == null) {
Log.w(TAG, "mode not found for mode id: " + modeId);
finish();
return;
}
setTitle(mode.getName());
@@ -237,11 +240,11 @@ public class SetupInterstitialActivity extends FragmentActivity {
// Don't come back to this activity after sending the user to the modes page, if
// they happen to go back. Forward the activity result in case we got here (indirectly)
// from some app that is waiting for the result.
finish();
if (updated) {
ZenSubSettingLauncher.forMode(this, modeId)
.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT).launch();
}
finish();
};
}

View File

@@ -81,6 +81,41 @@ public class SetupInterstitialActivityTest {
when(mImage.getLayoutParams()).thenReturn(new ViewGroup.LayoutParams(0, 0));
}
@Test
public void invalidIntent_doesNotQueryBackend() {
// Mode is set up sensibly
ZenMode mode = new TestModeBuilder().setId(MODE_ID).setEnabled(false).build();
when(mBackend.getMode(MODE_ID)).thenReturn(mode);
// but the intent is lacking the zen mode extra
ActivityScenario<SetupInterstitialActivity> scenario =
ActivityScenario.launch(new Intent(Intent.ACTION_MAIN)
.setClass(RuntimeEnvironment.getApplication(),
SetupInterstitialActivity.class));
// creating the scenario takes it through onResume(), which would query the backend if
// it had mode data.
scenario.onActivity(activity -> {
assertThat(activity.isFinishing()).isTrue();
verify(mBackend, never()).getMode(any());
});
scenario.close();
}
@Test
public void invalidModeId_doesNotCrash() {
when(mBackend.getMode(MODE_ID)).thenReturn(null);
ActivityScenario<SetupInterstitialActivity> scenario =
ActivityScenario.launch(new Intent(Intent.ACTION_MAIN)
.setClass(RuntimeEnvironment.getApplication(),
SetupInterstitialActivity.class)
.putExtra(EXTRA_AUTOMATIC_ZEN_RULE_ID, MODE_ID));
// do nothing, but it would crash if attempting to work with a null mode at any point
scenario.onActivity(activity -> {
assertThat(activity.isFinishing()).isTrue();
});
scenario.close();
}
@Test
public void enableButton_enablesModeAndRedirectsToModePage() {
ZenMode mode = new TestModeBuilder().setId(MODE_ID).setEnabled(false).build();