Don't observe Modes changes if MODES_UI is disabled

The ZenModesLinkPreferenceController is present in the Notifications and Sound screens, and although isAvailable() is false when MODES_UI is not enabled, it was still registering the listener for Settings changes, and calling updateState().

Thus, Settings would (likely) crash if Zen settings change while the user is in one of those screens, due to not finding the manual rule.

Fixes: 360498255
Test: atest ZenSettingsObserverTest
Flag: android.app.modes_ui
Change-Id: I7741809fd0028aace6ac58992be965701e64a2e3
This commit is contained in:
Matías Hernández
2024-08-22 17:49:30 +02:00
parent db74ac1256
commit d8603124d1
2 changed files with 106 additions and 4 deletions

View File

@@ -16,6 +16,7 @@
package com.android.settings.notification.modes;
import android.app.Flags;
import android.content.Context;
import android.database.ContentObserver;
import android.net.Uri;
@@ -42,13 +43,17 @@ class ZenSettingsObserver extends ContentObserver {
}
void register() {
mContext.getContentResolver().registerContentObserver(ZEN_MODE_URI, false, this);
mContext.getContentResolver().registerContentObserver(ZEN_MODE_CONFIG_ETAG_URI, false,
this);
if (Flags.modesApi() && Flags.modesUi()) {
mContext.getContentResolver().registerContentObserver(ZEN_MODE_URI, false, this);
mContext.getContentResolver().registerContentObserver(ZEN_MODE_CONFIG_ETAG_URI, false,
this);
}
}
void unregister() {
mContext.getContentResolver().unregisterContentObserver(this);
if (Flags.modesApi() && Flags.modesUi()) {
mContext.getContentResolver().unregisterContentObserver(this);
}
}
void setOnChangeListener(@Nullable Runnable callback) {