android:title="@string/zen_mode_settings_title"
settings:useAdminDisabledSummary="true"
android:fragment="com.android.settings.notification.ZenModeSettings"
+ settings:controller="com.android.settings.notification.ZenModePreferenceController"
settings:allowDividerAbove="false" />
<!-- Empty category to draw divider -->
android:order="-120"
settings:useAdminDisabledSummary="true"
settings:keywords="@string/keywords_sounds_and_notifications_interruptions"
- settings:allowDividerAbove="true"/>
+ settings:allowDividerAbove="true"
+ settings:controller="com.android.settings.notification.ZenModePreferenceController" />
<Preference
android:key="gesture_prevent_ringing_sound"
import android.os.Bundle;
import android.os.UserHandle;
import android.provider.SearchIndexableResource;
-import androidx.annotation.VisibleForTesting;
-import androidx.preference.Preference;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import java.util.Arrays;
import java.util.List;
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.Preference;
+
@SearchIndexable
public class ConfigureNotificationSettings extends DashboardFragment {
private static final String TAG = "ConfigNotiSettings";
static final String KEY_SWIPE_DOWN = "gesture_swipe_down_fingerprint_notifications";
private static final String KEY_NOTI_DEFAULT_RINGTONE = "notification_default_ringtone";
- private static final String KEY_ZEN_MODE = "zen_mode_notifications";
private RingtonePreference mRequestPreference;
private static final int REQUEST_CODE = 200;
}
});
- controllers.add(new ZenModePreferenceController(context, lifecycle, KEY_ZEN_MODE));
return controllers;
}
keys.add(KEY_LOCKSCREEN);
keys.add(KEY_LOCKSCREEN_WORK_PROFILE);
keys.add(KEY_LOCKSCREEN_WORK_PROFILE_HEADER);
- keys.add(KEY_ZEN_MODE);
return keys;
}
};
import android.provider.SearchIndexableResource;
import android.text.TextUtils;
-import androidx.annotation.VisibleForTesting;
-import androidx.preference.ListPreference;
-import androidx.preference.Preference;
-
import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import java.util.Arrays;
import java.util.List;
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.ListPreference;
+import androidx.preference.Preference;
+
@SearchIndexable
public class SoundSettings extends DashboardFragment {
private static final String TAG = "SoundSettings";
private static final String SELECTED_PREFERENCE_KEY = "selected_preference";
private static final int REQUEST_CODE = 200;
- private static final String KEY_ZEN_MODE = "zen_mode";
private static final int SAMPLE_CUTOFF = 2000; // manually cap sample playback at 2 seconds
@VisibleForTesting
onPreferenceDataChanged(listPreference));
mMediaOutputControllerKey = use(MediaOutputPreferenceController.class).getPreferenceKey();
use(HandsFreeProfileOutputPreferenceController.class).setCallback(listPreference ->
- onPreferenceDataChanged(listPreference));
+ onPreferenceDataChanged(listPreference));
mHfpOutputControllerKey =
use(HandsFreeProfileOutputPreferenceController.class).getPreferenceKey();
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
SoundSettings fragment, Lifecycle lifecycle) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
- controllers.add(new ZenModePreferenceController(context, lifecycle, KEY_ZEN_MODE));
// Volumes are added via xml
return buildPreferenceControllers(context, null /* fragment */,
null /* lifecycle */);
}
-
- @Override
- public List<String> getNonIndexableKeys(Context context) {
- List<String> keys = super.getNonIndexableKeys(context);
- // Duplicate results
- keys.add((new ZenModePreferenceController(context, null, KEY_ZEN_MODE))
- .getPreferenceKey());
- return keys;
- }
};
// === Work Sound Settings ===
import android.os.Handler;
import android.os.UserHandle;
import android.provider.Settings;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-import android.util.Slog;
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnPause;
import com.android.settingslib.core.lifecycle.events.OnResume;
-public class ZenModePreferenceController extends AbstractPreferenceController
- implements LifecycleObserver, OnResume, OnPause, PreferenceControllerMixin {
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
+public class ZenModePreferenceController extends BasePreferenceController
+ implements LifecycleObserver, OnResume, OnPause {
- private final String mKey;
private SettingObserver mSettingObserver;
private ZenModeSettings.SummaryBuilder mSummaryBuilder;
- public ZenModePreferenceController(Context context, Lifecycle lifecycle, String key) {
- super(context);
+ public ZenModePreferenceController(Context context, String key) {
+ super(context, key);
mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
-
- if (lifecycle != null) {
- lifecycle.addObserver(this);
- }
- mKey = key;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
- mSettingObserver = new SettingObserver(screen.findPreference(mKey));
+ mSettingObserver = new SettingObserver(screen.findPreference(getPreferenceKey()));
}
@Override
}
@Override
- public String getPreferenceKey() {
- return mKey;
- }
-
- @Override
- public boolean isAvailable() {
- return true;
+ public int getAvailabilityStatus() {
+ return AVAILABLE_UNSEARCHABLE;
}
@Override
package com.android.settings.notification;
+import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn;
import android.app.NotificationManager;
import android.app.NotificationManager.Policy;
import android.content.Context;
-import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers;
+import androidx.preference.Preference;
+
@RunWith(SettingsRobolectricTestRunner.class)
public class ZenModePreferenceControllerTest {
ShadowApplication shadowApplication = ShadowApplication.getInstance();
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
mContext = shadowApplication.getApplicationContext();
- mController = new ZenModePreferenceController(mContext, null, KEY_ZEN_MODE);
+ mController = new ZenModePreferenceController(mContext, KEY_ZEN_MODE);
when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
mSummaryBuilder = spy(new ZenModeSettings.SummaryBuilder(mContext));
ReflectionHelpers.setField(mController, "mSummaryBuilder", mSummaryBuilder);
}
@Test
- public void isAlwaysAvailable() {
- assertThat(mController.isAvailable()).isTrue();
+ public void isAvailable_unsearchable() {
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
}
@Test