From a25bc6983e14d9bd1175791b28e1086b539b11b7 Mon Sep 17 00:00:00 2001 From: Fan Zhang Date: Tue, 25 Apr 2017 12:45:35 -0700 Subject: [PATCH] Add search index provider for ConfigureNotificationSettings Change-Id: I1da8e318a8823ffe54b2edd7a83a8c7e31ee34e6 Fix: 37593839 Test: make RunSettingsRoboTests --- .../ConfigureNotificationSettings.java | 44 ++++++++++++++++--- .../search/BaseSearchIndexProvider.java | 2 + ...randfather_not_implementing_index_provider | 2 - 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/com/android/settings/notification/ConfigureNotificationSettings.java b/src/com/android/settings/notification/ConfigureNotificationSettings.java index aee9dc2622a..b591d8563d4 100644 --- a/src/com/android/settings/notification/ConfigureNotificationSettings.java +++ b/src/com/android/settings/notification/ConfigureNotificationSettings.java @@ -17,21 +17,24 @@ package com.android.settings.notification; import android.content.Context; +import android.provider.SearchIndexableResource; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.settings.R; import com.android.settings.core.PreferenceController; +import com.android.settings.core.lifecycle.Lifecycle; import com.android.settings.dashboard.DashboardFragment; import com.android.settings.gestures.SwipeToNotificationPreferenceController; +import com.android.settings.search.BaseSearchIndexProvider; +import com.android.settings.search.Indexable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class ConfigureNotificationSettings extends DashboardFragment { private static final String TAG = "ConfigNotiSettings"; - private LockScreenNotificationPreferenceController mLockScreenNotificationController; - @Override public int getMetricsCategory() { return MetricsEvent.CONFIGURE_NOTIFICATION; @@ -49,15 +52,42 @@ public class ConfigureNotificationSettings extends DashboardFragment { @Override protected List getPreferenceControllers(Context context) { + return buildPreferenceControllers(context, getLifecycle()); + } + + private static List buildPreferenceControllers(Context context, + Lifecycle lifecycle) { final List controllers = new ArrayList<>(); final PulseNotificationPreferenceController pulseController = new PulseNotificationPreferenceController(context); - mLockScreenNotificationController = new LockScreenNotificationPreferenceController(context); - getLifecycle().addObserver(pulseController); - getLifecycle().addObserver(mLockScreenNotificationController); - controllers.add(new SwipeToNotificationPreferenceController(context, getLifecycle())); + final LockScreenNotificationPreferenceController lockScreenNotificationController = + new LockScreenNotificationPreferenceController(context); + if (lifecycle != null) { + lifecycle.addObserver(pulseController); + lifecycle.addObserver(lockScreenNotificationController); + } + controllers.add(new SwipeToNotificationPreferenceController(context, lifecycle)); controllers.add(pulseController); - controllers.add(mLockScreenNotificationController); + controllers.add(lockScreenNotificationController); return controllers; } + + /** + * For Search. + */ + public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = + new BaseSearchIndexProvider() { + @Override + public List getXmlResourcesToIndex( + Context context, boolean enabled) { + final SearchIndexableResource sir = new SearchIndexableResource(context); + sir.xmlResId = R.xml.configure_notification_settings; + return Arrays.asList(sir); + } + + @Override + public List getPreferenceControllers(Context context) { + return buildPreferenceControllers(context, null); + } + }; } diff --git a/src/com/android/settings/search/BaseSearchIndexProvider.java b/src/com/android/settings/search/BaseSearchIndexProvider.java index 54f66ead941..bda93198cab 100644 --- a/src/com/android/settings/search/BaseSearchIndexProvider.java +++ b/src/com/android/settings/search/BaseSearchIndexProvider.java @@ -19,6 +19,7 @@ package com.android.settings.search; import android.content.Context; import android.content.res.XmlResourceParser; import android.provider.SearchIndexableResource; +import android.support.annotation.CallSuper; import android.text.TextUtils; import android.util.AttributeSet; import android.util.Log; @@ -57,6 +58,7 @@ public class BaseSearchIndexProvider implements Indexable.SearchIndexProvider { } @Override + @CallSuper public List getNonIndexableKeys(Context context) { if (!isPageSearchEnabled(context)) { // Entire page should be suppressed, mark all keys from this page as non-indexable. diff --git a/tests/robotests/assets/grandfather_not_implementing_index_provider b/tests/robotests/assets/grandfather_not_implementing_index_provider index 240b8eb18fb..f5462b04dbc 100644 --- a/tests/robotests/assets/grandfather_not_implementing_index_provider +++ b/tests/robotests/assets/grandfather_not_implementing_index_provider @@ -1,7 +1,5 @@ -com.android.settings.notification.ConfigureNotificationSettings com.android.settings.language.LanguageAndRegionSettings com.android.settings.notification.ZenModePrioritySettings -com.android.settings.inputmethod.InputAndGestureSettings com.android.settings.accounts.AccountDetailDashboardFragment com.android.settings.fuelgauge.PowerUsageDetail com.android.settings.fuelgauge.AdvancedPowerUsageDetail