OSDN Git Service

Fix bug #16896118 SIM cards should ONLY appear in search results for devices with...
authorFabrice Di Meglio <fdimeglio@google.com>
Fri, 8 Aug 2014 19:27:57 +0000 (12:27 -0700)
committerFabrice Di Meglio <fdimeglio@google.com>
Fri, 8 Aug 2014 19:33:21 +0000 (12:33 -0700)
- add the proper SearchIndexProvider to SimSettings
- allow indexing only an only if showSimCardTile() is true
- add Utils.showSimCardTile()

Change-Id: I5df2284d32f91fa454e1edebf1139d00593138a0

src/com/android/settings/SettingsActivity.java
src/com/android/settings/Utils.java
src/com/android/settings/search/SearchIndexableResources.java
src/com/android/settings/sim/SimSettings.java

index f4f34bc..e77ab4f 100644 (file)
@@ -1042,7 +1042,7 @@ public class SettingsActivity extends Activity
                             }
 
                             // Show the SIM Cards setting if there are more than 2 SIMs installed.
-                            if(tile.id != R.id.sim_settings || SimSettings.showSimCardScreen(this)){
+                            if(tile.id != R.id.sim_settings || Utils.showSimCardTile(this)){
                                 category.addTile(tile);
                             }
 
index df05adc..ba5c1e5 100644 (file)
@@ -823,4 +823,16 @@ public final class Utils {
         if (icon == null) return null;
         return CircleFramedDrawable.getInstance(context, icon);
     }
+
+    /**
+     * Return whether or not the user should have a SIM Cards option in Settings.
+     * TODO: Change back to returning true if count is greater than one after testing.
+     * TODO: See bug 16533525.
+     */
+    public static boolean showSimCardTile(Context context) {
+        final TelephonyManager tm =
+                (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+
+        return tm.getSimCount() > 0;
+    }
 }
index a3d2b8d..e0e09a8 100644 (file)
@@ -92,7 +92,7 @@ public final class SearchIndexableResources {
         sResMap.put(SimSettings.class.getName(),
                 new SearchIndexableResource(
                         Ranking.getRankForClassName(SimSettings.class.getName()),
-                        R.xml.sim_settings,
+                        NO_DATA_RES_ID,
                         SimSettings.class.getName(),
                         R.drawable.ic_sim_sd));
 
index 2e1c0f5..24ba4be 100644 (file)
@@ -16,6 +16,7 @@
 
 package com.android.settings.sim;
 
+import android.provider.SearchIndexableResource;
 import com.android.settings.R;
 
 import android.app.AlertDialog;
@@ -55,6 +56,7 @@ import com.android.internal.telephony.PhoneConstants;
 import com.android.internal.telephony.TelephonyIntents;
 import com.android.settings.RestrictedSettingsFragment;
 import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.Utils;
 import com.android.settings.notification.DropDownPreference;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.search.Indexable;
@@ -86,18 +88,6 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
     private SubInfoRecord mCalls = null;
     private SubInfoRecord mSMS = null;
 
-    /**
-     * Return whether or not the user should have a SIM Cards option in Settings.
-     * TODO: Change back to returning true if count is greater than one after testing.
-     * TODO: See bug 16533525.
-     */
-    public static boolean showSimCardScreen(Context context) {
-        final TelephonyManager tm =
-            (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
-
-        return tm.getSimCount() > 0;
-    }
-
     public SimSettings() {
         super(DISALLOW_CONFIG_SIM);
     }
@@ -370,4 +360,26 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
             builder.create().show();
         }
     }
+
+    /**
+     * For search
+     */
+    public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+            new BaseSearchIndexProvider() {
+                @Override
+                public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
+                        boolean enabled) {
+                    ArrayList<SearchIndexableResource> result =
+                            new ArrayList<SearchIndexableResource>();
+
+                    if (Utils.showSimCardTile(context)) {
+                        SearchIndexableResource sir = new SearchIndexableResource(context);
+                        sir.xmlResId = R.xml.sim_settings;
+                        result.add(sir);
+                    }
+
+                    return result;
+                }
+            };
+
 }