Improve lifecycle of ZenModeFragment & friends

* Don't keep Settings observers longer than start-stop.
* Only call updateState() once on controllers during create->start->resume.
* Remove some duplicate controller update methods from ZenModesFragmentBase (we can directly call DashboardFragment's).
* Don't update controllers if unrelated modes were changed.
* Extract ZenSettingsObserver for use in the link tile later.
* Add tests.

Fixes: 353946788
Test: atest com.android.settings.notification.modes
Flag: android.app.modes_ui
Change-Id: I64b51714d699b5c3a592a76fcb615d2999998829
This commit is contained in:
Matías Hernández
2024-07-29 17:45:27 +02:00
parent cadfc0187d
commit b8b897e552
11 changed files with 577 additions and 231 deletions

View File

@@ -37,7 +37,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settingslib.PrimarySwitchPreference;
@@ -77,13 +76,6 @@ class ZenModeTriggerUpdatePreferenceController extends AbstractZenModePreference
return !zenMode.isCustomManual() && !zenMode.isManualDnd();
}
@Override
public void displayPreference(PreferenceScreen screen, @NonNull ZenMode zenMode) {
// Preload approved components, but only for the package that owns the rule (since it's the
// only package that can have a valid configurationActivity).
mServiceListing.loadApprovedComponents(zenMode.getRule().getPackageName());
}
@Override
void updateState(Preference preference, @NonNull ZenMode zenMode) {
if (!isAvailable(zenMode)) {
@@ -137,6 +129,7 @@ class ZenModeTriggerUpdatePreferenceController extends AbstractZenModePreference
@SuppressLint("SwitchIntDef")
private void setUpForAppTrigger(Preference preference, ZenMode mode) {
// App-owned mode may have triggerDescription, configurationActivity, or both/neither.
mServiceListing.loadApprovedComponents(mode.getRule().getPackageName());
Intent configurationIntent =
mConfigurationActivityHelper.getConfigurationActivityIntentForMode(
mode, mServiceListing::findService);