Merge "Add metrics for driving and bedtime interstitials" into main

This commit is contained in:
Treehugger Robot
2024-08-23 02:59:26 +00:00
committed by Android (Google) Code Review
2 changed files with 11 additions and 4 deletions

View File

@@ -29,6 +29,7 @@ import static android.provider.Settings.EXTRA_AUTOMATIC_ZEN_RULE_ID;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.ActionBar; import android.app.ActionBar;
import android.app.AutomaticZenRule;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@@ -184,22 +185,28 @@ public class SetupInterstitialActivity extends FragmentActivity {
private void setupButton(Button button, @NonNull ZenMode mode) { private void setupButton(Button button, @NonNull ZenMode mode) {
button.setText(getString(R.string.zen_mode_setup_button_label, mode.getName())); button.setText(getString(R.string.zen_mode_setup_button_label, mode.getName()));
button.setOnClickListener(enableButtonListener(mode.getId())); button.setOnClickListener(enableButtonListener(mode.getId(), mode.getType()));
} }
@VisibleForTesting @VisibleForTesting
View.OnClickListener enableButtonListener(String modeId) { View.OnClickListener enableButtonListener(String modeId, @AutomaticZenRule.Type int modeType) {
return unused -> { return unused -> {
// When clicked, we first reload mode info in case it has changed in the interim, // When clicked, we first reload mode info in case it has changed in the interim,
// then enable the mode and then send the user to the mode's configuration page. // then enable the mode and then send the user to the mode's configuration page.
boolean updated = enableMode(modeId); boolean updated = enableMode(modeId);
int metricsCategory = switch (modeType) {
case TYPE_BEDTIME -> SettingsEnums.ZEN_MODE_INTERSTITIAL_BEDTIME;
case TYPE_DRIVING -> SettingsEnums.ZEN_MODE_INTERSTITIAL_DRIVING;
default -> SettingsEnums.ZEN_MODE_INTERSTITIAL;
};
// Don't come back to this activity after sending the user to the modes page, if // 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) // they happen to go back. Forward the activity result in case we got here (indirectly)
// from some app that is waiting for the result. // from some app that is waiting for the result.
if (updated) { if (updated) {
ZenSubSettingLauncher.forModeFragment(this, ZenModeFragment.class, modeId, ZenSubSettingLauncher.forModeFragment(this, ZenModeFragment.class, modeId,
SettingsEnums.ZEN_MODE_INTERSTITIAL) metricsCategory)
.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT).launch(); .addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT).launch();
} }
finish(); finish();

View File

@@ -128,7 +128,7 @@ public class SetupInterstitialActivityTest {
SetupInterstitialActivity.class) SetupInterstitialActivity.class)
.putExtra(EXTRA_AUTOMATIC_ZEN_RULE_ID, MODE_ID)); .putExtra(EXTRA_AUTOMATIC_ZEN_RULE_ID, MODE_ID));
scenario.onActivity(activity -> { scenario.onActivity(activity -> {
View.OnClickListener listener = activity.enableButtonListener(MODE_ID); View.OnClickListener listener = activity.enableButtonListener(MODE_ID, mode.getType());
// simulate button press even though we don't actually have a button // simulate button press even though we don't actually have a button
listener.onClick(null); listener.onClick(null);