Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bd74edd1 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

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

parents f2f2da61 0a43ecdf
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import static android.provider.Settings.EXTRA_AUTOMATIC_ZEN_RULE_ID;

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.AutomaticZenRule;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
@@ -184,22 +185,28 @@ public class SetupInterstitialActivity extends FragmentActivity {

    private void setupButton(Button button, @NonNull ZenMode mode) {
        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
    View.OnClickListener enableButtonListener(String modeId) {
    View.OnClickListener enableButtonListener(String modeId, @AutomaticZenRule.Type int modeType) {
        return unused -> {
            // 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.
            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
            // they happen to go back. Forward the activity result in case we got here (indirectly)
            // from some app that is waiting for the result.
            if (updated) {
                ZenSubSettingLauncher.forModeFragment(this, ZenModeFragment.class, modeId,
                                SettingsEnums.ZEN_MODE_INTERSTITIAL)
                                metricsCategory)
                        .addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT).launch();
            }
            finish();
+1 −1
Original line number Diff line number Diff line
@@ -128,7 +128,7 @@ public class SetupInterstitialActivityTest {
                                SetupInterstitialActivity.class)
                        .putExtra(EXTRA_AUTOMATIC_ZEN_RULE_ID, MODE_ID));
        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
            listener.onClick(null);