OSDN Git Service

Fix crash from Settings Search
authorMatthew Fritze <mfritze@google.com>
Thu, 19 Oct 2017 17:38:08 +0000 (10:38 -0700)
committerMatthew Fritze <mfritze@google.com>
Thu, 19 Oct 2017 17:58:05 +0000 (10:58 -0700)
Security Settings was returning a search indexable
resource without an xml resource (in this case id = 0).

Settings search did not handle this exception and crashed.
This patch catches the exception, and adds a TODO to fix
the indexing in security settings.

Change-Id: Ic7f05c98d99cc45fbebbdc672c7e346c27daa0f0
Fixes: 67967367
Test: robotests

src/com/android/settings/SecuritySettings.java
src/com/android/settings/search/indexing/IndexDataConverter.java
tests/robotests/src/com/android/settings/search/indexing/IndexDataConverterTest.java

index 822a60d..26a9ecb 100644 (file)
@@ -834,6 +834,8 @@ public class SecuritySettings extends SettingsPreferenceFragment
 
     private static class SecuritySearchIndexProvider extends BaseSearchIndexProvider {
 
+        // TODO (b/68001777) Refactor indexing to include all XML and block other settings.
+
         @Override
         public List<SearchIndexableResource> getXmlResourcesToIndex(
                 Context context, boolean enabled) {
index 487132b..8010db9 100644 (file)
@@ -19,6 +19,7 @@ package com.android.settings.search.indexing;
 
 import android.annotation.Nullable;
 import android.content.Context;
+import android.content.res.Resources;
 import android.content.res.XmlResourceParser;
 import android.provider.SearchIndexableData;
 import android.provider.SearchIndexableResource;
@@ -307,9 +308,11 @@ public class IndexDataConverter {
                 resourceIndexData.add(headerBuilder.build(mContext));
             }
         } catch (XmlPullParserException e) {
-            throw new RuntimeException("Error parsing PreferenceScreen", e);
+            Log.w(LOG_TAG, "XML Error parsing PreferenceScreen: ", e);
         } catch (IOException e) {
-            throw new RuntimeException("Error parsing PreferenceScreen", e);
+            Log.w(LOG_TAG, "IO Error parsing PreferenceScreen: " , e);
+        } catch (Resources.NotFoundException e ) {
+            Log.w(LOG_TAG, "Resoucre not found error parsing PreferenceScreen: ", e);
         } finally {
             if (parser != null) parser.close();
         }
index cac6f3a..1612036 100644 (file)
@@ -334,6 +334,17 @@ public class IndexDataConverterTest {
         assertThat(nonTitlePref.enabled).isTrue();
     }
 
+    @Test
+    public void testResourceWithoutXml_shouldNotCrash() {
+        final SearchIndexableResource resource = getFakeResource(0);
+        final PreIndexData preIndexData = new PreIndexData();
+        preIndexData.dataToUpdate.add(resource);
+
+        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData);
+
+        assertThat(indexData).isEmpty();
+    }
+
     private void assertDisplaySetting(IndexData row, String title, String summaryOn,
             String summaryOff, String key) {
         assertThat(row.normalizedTitle).isEqualTo(title);