Add interstitial for modes that are disabled but not by user

This covers both the case of navigating to the mode page through the mode aggregator menu as well as if an app sends an intent to go to the mode.

The interstitial visuals are not done yet; in particular, the image is just a gray box for now.

Manual tests done:
- visually verifying the interstitial page in both portrait and landscape
- accessing the mode page from modes list, confirming interstitial pops up
- accessing enabled and disabled-by-user mode page from modes list (no interstitial)
- getting to the mode page from intent through an app
- accessing enabled and disabled-by-user mode pages from app intent (no interstitial)
- adjusted display and font size (it looks bad with max display & font size, maybe not much to be done)

Bug: 332730534
Test: manual, ZenModeFragmentTest, SetupInterstitialActivityTest
Flag: android.app.modes_ui
Change-Id: I21f13b0842d5b118a341f7d85e8fcac947ca3a06
This commit is contained in:
Yuri Lin
2024-07-18 17:12:41 -04:00
parent bc915e7bdc
commit 65548c0e56
8 changed files with 637 additions and 3 deletions

View File

@@ -16,6 +16,8 @@
package com.android.settings.notification.modes;
import static com.android.settingslib.notification.modes.ZenMode.Status.DISABLED_BY_OTHER;
import android.app.AlertDialog;
import android.app.settings.SettingsEnums;
import android.content.Context;
@@ -25,6 +27,7 @@ import android.view.MenuItem;
import androidx.activity.ComponentActivity;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.MenuProvider;
import com.android.settings.R;
@@ -41,6 +44,7 @@ public class ZenModeFragment extends ZenModeFragmentBase {
private static final int DELETE_MODE = 2;
private ModeMenuProvider mModeMenuProvider;
private boolean mSettingsObserverRegistered = false; // for ManualDurationPreferenceController
@Override
protected int getPreferenceScreenResId() {
@@ -82,9 +86,14 @@ public class ZenModeFragment extends ZenModeFragmentBase {
@Override
public void onStart() {
super.onStart();
ZenMode mode = getMode();
// Consider redirecting to the interstitial if the mode is disabled (but not by the user).
if (maybeRedirectToInterstitial(mode)) {
return;
}
// Set title for the entire screen
ZenMode mode = getMode();
ComponentActivity activity = getActivity();
if (mode != null && activity != null) {
activity.setTitle(mode.getName());
@@ -94,14 +103,27 @@ public class ZenModeFragment extends ZenModeFragmentBase {
// allow duration preference controller to listen for settings changes
use(ManualDurationPreferenceController.class).registerSettingsObserver();
mSettingsObserverRegistered = true;
}
private boolean maybeRedirectToInterstitial(@Nullable ZenMode mode) {
if (mode == null || mode.getStatus() != DISABLED_BY_OTHER) {
return false;
}
// don't come back here from the interstitial
finish();
mContext.startActivity(SetupInterstitialActivity.getIntent(mContext, mode));
return true;
}
@Override
public void onStop() {
if (getActivity() != null) {
if (getActivity() != null && mModeMenuProvider != null) {
getActivity().removeMenuProvider(mModeMenuProvider);
}
use(ManualDurationPreferenceController.class).unregisterSettingsObserver();
if (mSettingsObserverRegistered) {
use(ManualDurationPreferenceController.class).unregisterSettingsObserver();
}
super.onStop();
}