From f6cf598d0325c3c96927285b22c84f042e95b6fb Mon Sep 17 00:00:00 2001 From: Matthew Fritze Date: Thu, 9 Nov 2017 09:40:09 -0800 Subject: [PATCH] Prevent crash in Search from Stack overflow NotificationSettingBase's getPreferenceController call is recursive with no base case which crashes search. Root cause here is that NotificationSettingsBase should not be indexed for seacrh but was probably failing the code inspection test. Added NotificationSettingsBase child classes to grandfather list of classes that should be ignored for search. Change-Id: I04ed242db3a394b88e0d0ac420aaaff6f9301cb5 Fixes: 69096424 Test: robotests --- .../ChannelImportanceSettings.java | 11 ----- .../NotificationSettingsBase.java | 40 +++++++------------ .../search/SearchIndexableResources.java | 9 ----- ...randfather_not_implementing_index_provider | 6 ++- .../grandfather_not_implementing_indexable | 2 +- 5 files changed, 20 insertions(+), 48 deletions(-) diff --git a/src/com/android/settings/notification/ChannelImportanceSettings.java b/src/com/android/settings/notification/ChannelImportanceSettings.java index bffed08079c..27b23b8c2cc 100644 --- a/src/com/android/settings/notification/ChannelImportanceSettings.java +++ b/src/com/android/settings/notification/ChannelImportanceSettings.java @@ -163,15 +163,4 @@ public class ChannelImportanceSettings extends NotificationSettingsBase mChannel.lockFields(USER_LOCKED_IMPORTANCE); mBackend.updateChannel(mAppRow.pkg, mAppRow.uid, mChannel); } - - // This page exists per notification channel; should not be included - // in search - public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = - new BaseSearchIndexProvider() { - @Override - public List getXmlResourcesToIndex( - Context context, boolean enabled) { - return null; - } - }; } diff --git a/src/com/android/settings/notification/NotificationSettingsBase.java b/src/com/android/settings/notification/NotificationSettingsBase.java index e9da5d96f32..9afb61845ee 100644 --- a/src/com/android/settings/notification/NotificationSettingsBase.java +++ b/src/com/android/settings/notification/NotificationSettingsBase.java @@ -208,15 +208,19 @@ abstract public class NotificationSettingsBase extends DashboardFragment { intent, 0 //PackageManager.MATCH_DEFAULT_ONLY ); - if (DEBUG) Log.d(TAG, "Found " + resolveInfos.size() + " preference activities" - + (resolveInfos.size() == 0 ? " ;_;" : "")); + if (DEBUG) { + Log.d(TAG, "Found " + resolveInfos.size() + " preference activities" + + (resolveInfos.size() == 0 ? " ;_;" : "")); + } for (ResolveInfo ri : resolveInfos) { final ActivityInfo activityInfo = ri.activityInfo; final ApplicationInfo appInfo = activityInfo.applicationInfo; if (mAppRow.settingsIntent != null) { - if (DEBUG) Log.v(TAG, "Ignoring duplicate notification preference activity (" - + activityInfo.name + ") for package " - + activityInfo.packageName); + if (DEBUG) { + Log.d(TAG, "Ignoring duplicate notification preference activity (" + + activityInfo.name + ") for package " + + activityInfo.packageName); + } continue; } mAppRow.settingsIntent = intent @@ -280,7 +284,7 @@ abstract public class NotificationSettingsBase extends DashboardFragment { public boolean onPreferenceChange(Preference preference, Object o) { boolean value = (Boolean) o; - int importance = value ? IMPORTANCE_LOW : IMPORTANCE_NONE; + int importance = value ? IMPORTANCE_LOW : IMPORTANCE_NONE; channel.setImportance(importance); channel.lockFields( NotificationChannel.USER_LOCKED_IMPORTANCE); @@ -365,8 +369,10 @@ abstract public class NotificationSettingsBase extends DashboardFragment { public void onReceive(Context context, Intent intent) { String packageName = intent.getData().getSchemeSpecificPart(); if (mPkgInfo == null || TextUtils.equals(mPkgInfo.packageName, packageName)) { - if (DEBUG) Log.d(TAG, "Package (" + packageName + ") removed. Removing" - + "NotificationSettingsBase."); + if (DEBUG) { + Log.d(TAG, "Package (" + packageName + ") removed. Removing" + + "NotificationSettingsBase."); + } onPackageRemoved(); } } @@ -380,24 +386,6 @@ abstract public class NotificationSettingsBase extends DashboardFragment { return left.getId().compareTo(right.getId()); }; - /** - * These screens aren't searchable - they only make sense in the context of an app, so - * surfacing a generic version would be impossible. - */ - public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = - new BaseSearchIndexProvider() { - @Override - public List getXmlResourcesToIndex(Context context, - boolean enabled) { - return new ArrayList<>(); - } - - @Override - public List getPreferenceControllers(Context context) { - return getPreferenceControllers(context); - } - }; - protected class ImportanceListener { protected void onImportanceChanged() { final PreferenceScreen screen = getPreferenceScreen(); diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java index 4548342ad57..c5243460eb3 100644 --- a/src/com/android/settings/search/SearchIndexableResources.java +++ b/src/com/android/settings/search/SearchIndexableResources.java @@ -64,10 +64,6 @@ import com.android.settings.location.LocationSettings; import com.android.settings.location.ScanningSettings; import com.android.settings.network.NetworkDashboardFragment; import com.android.settings.nfc.PaymentSettings; -import com.android.settings.notification.AppNotificationSettings; -import com.android.settings.notification.ChannelGroupNotificationSettings; -import com.android.settings.notification.ChannelImportanceSettings; -import com.android.settings.notification.ChannelNotificationSettings; import com.android.settings.notification.ConfigureNotificationSettings; import com.android.settings.notification.SoundSettings; import com.android.settings.notification.ZenModeAutomationSettings; @@ -161,7 +157,6 @@ public final class SearchIndexableResources { addIndex(TtsEnginePreferenceFragment.class); addIndex(MagnificationPreferenceFragment.class); addIndex(AccessibilityShortcutPreferenceFragment.class); - addIndex(ChannelImportanceSettings.class); addIndex(DreamSettings.class); addIndex(SupportDashboardActivity.class); addIndex(AutomaticStorageManagerSettings.class); @@ -171,10 +166,6 @@ public final class SearchIndexableResources { addIndex(LockscreenDashboardFragment.class); addIndex(ZenModeBehaviorSettings.class); addIndex(ZenModeAutomationSettings.class); - addIndex(AppNotificationSettings.class); - addIndex(ChannelNotificationSettings.class); - addIndex(ChannelImportanceSettings.class); - addIndex(ChannelGroupNotificationSettings.class); } private SearchIndexableResources() { diff --git a/tests/robotests/assets/grandfather_not_implementing_index_provider b/tests/robotests/assets/grandfather_not_implementing_index_provider index fda5c8a5c70..6704fc3fb0e 100644 --- a/tests/robotests/assets/grandfather_not_implementing_index_provider +++ b/tests/robotests/assets/grandfather_not_implementing_index_provider @@ -7,6 +7,10 @@ com.android.settings.fuelgauge.AdvancedPowerUsageDetail com.android.settings.development.featureflags.FeatureFlagsDashboard com.android.settings.development.qstile.DevelopmentTileConfigFragment com.android.settings.deviceinfo.StorageProfileFragment +com.android.settings.notification.ChannelNotificationSettings +com.android.settings.notification.ChannelImportanceSettings +com.android.settings.notification.ChannelGroupNotificationSettings +com.android.settings.notification.AppNotificationSettings com.android.settings.wifi.details.WifiNetworkDetailsFragment com.android.settings.wifi.p2p.WifiP2pSettings com.android.settings.enterprise.ApplicationListFragment$AdminGrantedPermissionCamera @@ -15,4 +19,4 @@ com.android.settings.enterprise.ApplicationListFragment$AdminGrantedPermissionMi com.android.settings.enterprise.ApplicationListFragment$EnterpriseInstalledPackages com.android.settings.enterprise.EnterpriseSetDefaultAppsListFragment com.android.settings.wifi.tether.WifiTetherSettings -com.android.settings.wifi.SavedAccessPointsWifiSettings +com.android.settings.wifi.SavedAccessPointsWifiSettings \ No newline at end of file diff --git a/tests/robotests/assets/grandfather_not_implementing_indexable b/tests/robotests/assets/grandfather_not_implementing_indexable index 7c82e78d162..c2a084c5360 100644 --- a/tests/robotests/assets/grandfather_not_implementing_indexable +++ b/tests/robotests/assets/grandfather_not_implementing_indexable @@ -79,4 +79,4 @@ com.android.settings.IccLockSettings com.android.settings.TetherSettings com.android.settings.ApnEditor com.android.settings.UserCredentialsSettings -com.android.settings.TestingSettings +com.android.settings.TestingSettings \ No newline at end of file