diff options
author | Fabrice Di Meglio <fdimeglio@google.com> | 2014-06-07 10:01:14 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-06-07 10:01:14 +0000 |
commit | c6dacf5e560e39d921b263f685919b5b1e57669b (patch) | |
tree | 3dcc966c600976d84bb9509c5e552f8fe7037582 | |
parent | 08a7d554b04bf642fbe869b8ea3d18f9387b1dd1 (diff) | |
parent | c9548c17471ff7d7826a769593250ca3467a2ba5 (diff) | |
download | packages_apps_Settings-c6dacf5e560e39d921b263f685919b5b1e57669b.tar.gz packages_apps_Settings-c6dacf5e560e39d921b263f685919b5b1e57669b.tar.bz2 packages_apps_Settings-c6dacf5e560e39d921b263f685919b5b1e57669b.zip |
am c9548c17: Merge "Fix bug #15460001 "Cell broadcasts" setting search suggested in wifi only device though setting is not present" into lmp-preview-dev
* commit 'c9548c17471ff7d7826a769593250ca3467a2ba5':
Fix bug #15460001 "Cell broadcasts" setting search suggested in wifi only device though setting is not present
-rw-r--r-- | src/com/android/settings/SettingsActivity.java | 2 | ||||
-rw-r--r-- | src/com/android/settings/WirelessSettings.java | 118 | ||||
-rw-r--r-- | src/com/android/settings/search/Index.java | 22 | ||||
-rw-r--r-- | src/com/android/settings/search/SearchIndexableResources.java | 4 |
4 files changed, 131 insertions, 15 deletions
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java index 7dcdfbc7a..ad7d47305 100644 --- a/src/com/android/settings/SettingsActivity.java +++ b/src/com/android/settings/SettingsActivity.java @@ -469,7 +469,7 @@ public class SettingsActivity extends Activity mIsShowingDashboard = (initialFragmentName == null); if (mIsShowingDashboard) { - Index.getInstance(this).update(); + Index.getInstance(getApplicationContext()).update(); } if (savedState != null) { diff --git a/src/com/android/settings/WirelessSettings.java b/src/com/android/settings/WirelessSettings.java index fd2e9456a..7aaa0a6a9 100644 --- a/src/com/android/settings/WirelessSettings.java +++ b/src/com/android/settings/WirelessSettings.java @@ -30,6 +30,7 @@ import android.content.res.Resources; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.nfc.NfcAdapter; +import android.nfc.NfcManager; import android.os.Bundle; import android.os.SystemProperties; import android.os.UserHandle; @@ -37,6 +38,7 @@ import android.preference.CheckBoxPreference; import android.preference.Preference; import android.preference.Preference.OnPreferenceChangeListener; import android.preference.PreferenceScreen; +import android.provider.SearchIndexableResource; import android.provider.Settings; import android.telephony.TelephonyManager; import android.text.TextUtils; @@ -47,11 +49,16 @@ import com.android.internal.telephony.SmsApplication.SmsApplicationData; import com.android.internal.telephony.TelephonyIntents; import com.android.internal.telephony.TelephonyProperties; import com.android.settings.nfc.NfcEnabler; +import com.android.settings.search.BaseSearchIndexProvider; +import com.android.settings.search.Indexable; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; +import java.util.List; public class WirelessSettings extends RestrictedSettingsFragment - implements OnPreferenceChangeListener { + implements OnPreferenceChangeListener, Indexable { private static final String TAG = "WirelessSettings"; private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane"; @@ -270,7 +277,7 @@ public class WirelessSettings extends RestrictedSettingsFragment Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS); //enable/disable wimax depending on the value in config.xml - boolean isWimaxEnabled = !isSecondaryUser && this.getResources().getBoolean( + final boolean isWimaxEnabled = !isSecondaryUser && this.getResources().getBoolean( com.android.internal.R.bool.config_wimaxEnabled); if (!isWimaxEnabled) { PreferenceScreen root = getPreferenceScreen(); @@ -304,7 +311,7 @@ public class WirelessSettings extends RestrictedSettingsFragment findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE); } - // Remove NFC if its not available + // Remove NFC if not available mNfcAdapter = NfcAdapter.getDefaultAdapter(activity); if (mNfcAdapter == null) { getPreferenceScreen().removePreference(nfc); @@ -319,7 +326,7 @@ public class WirelessSettings extends RestrictedSettingsFragment } // Remove Mobile Network Settings and Manage Mobile Plan // if config_show_mobile_plan sets false. - boolean isMobilePlanEnabled = this.getResources().getBoolean( + final boolean isMobilePlanEnabled = this.getResources().getBoolean( R.bool.config_show_mobile_plan); if (!isMobilePlanEnabled) { Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN); @@ -342,14 +349,14 @@ public class WirelessSettings extends RestrictedSettingsFragment // Enable Proxy selector settings if allowed. Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS); - DevicePolicyManager mDPM = (DevicePolicyManager) + final DevicePolicyManager mDPM = (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE); // proxy UI disabled until we have better app support getPreferenceScreen().removePreference(mGlobalProxy); mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null); // Disable Tethering if it's not allowed or if it's a wifi-only device - ConnectivityManager cm = + final ConnectivityManager cm = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE); if (isSecondaryUser || !cm.isTetheringSupported()) { getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS)); @@ -446,4 +453,103 @@ public class WirelessSettings extends RestrictedSettingsFragment } return false; } + + /** + * For Search. + */ + public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = + new BaseSearchIndexProvider() { + @Override + public List<SearchIndexableResource> getXmlResourcesToIndex( + Context context, boolean enabled) { + SearchIndexableResource sir = new SearchIndexableResource(context); + sir.xmlResId = R.xml.wireless_settings; + return Arrays.asList(sir); + } + + @Override + public List<String> getNonIndexableKeys(Context context) { + final ArrayList<String> result = new ArrayList<String>(); + + result.add(KEY_TOGGLE_NSD); + + final boolean isSecondaryUser = UserHandle.myUserId() != UserHandle.USER_OWNER; + final boolean isWimaxEnabled = !isSecondaryUser && context.getResources().getBoolean( + com.android.internal.R.bool.config_wimaxEnabled); + if (!isWimaxEnabled) { + result.add(KEY_WIMAX_SETTINGS); + } + + if (isSecondaryUser) { // Disable VPN + result.add(KEY_VPN_SETTINGS); + } + + // Remove NFC if not available + final NfcManager manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE); + if (manager != null) { + NfcAdapter adapter = manager.getDefaultAdapter(); + if (adapter == null) { + result.add(KEY_TOGGLE_NFC); + result.add(KEY_ANDROID_BEAM_SETTINGS); + } + } + + // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device. + if (isSecondaryUser || Utils.isWifiOnly(context)) { + result.add(KEY_MOBILE_NETWORK_SETTINGS); + result.add(KEY_MANAGE_MOBILE_PLAN); + } + + // Remove Mobile Network Settings and Manage Mobile Plan + // if config_show_mobile_plan sets false. + final boolean isMobilePlanEnabled = context.getResources().getBoolean( + R.bool.config_show_mobile_plan); + if (!isMobilePlanEnabled) { + result.add(KEY_MANAGE_MOBILE_PLAN); + } + + // Remove SMS Application if the device does not support SMS + TelephonyManager tm = + (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); + if (!tm.isSmsCapable()) { + result.add(KEY_SMS_APPLICATION); + } + + final PackageManager pm = context.getPackageManager(); + + // Remove Airplane Mode settings if it's a stationary device such as a TV. + if (pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) { + result.add(KEY_TOGGLE_AIRPLANE); + } + + // proxy UI disabled until we have better app support + result.add(KEY_PROXY_SETTINGS); + + // Disable Tethering if it's not allowed or if it's a wifi-only device + ConnectivityManager cm = + (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + if (isSecondaryUser || !cm.isTetheringSupported()) { + result.add(KEY_TETHER_SETTINGS); + } + + // Enable link to CMAS app settings depending on the value in config.xml. + boolean isCellBroadcastAppLinkEnabled = context.getResources().getBoolean( + com.android.internal.R.bool.config_cellBroadcastAppLinks); + try { + if (isCellBroadcastAppLinkEnabled) { + if (pm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver") + == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) { + isCellBroadcastAppLinkEnabled = false; // CMAS app disabled + } + } + } catch (IllegalArgumentException ignored) { + isCellBroadcastAppLinkEnabled = false; // CMAS app not installed + } + if (isSecondaryUser || !isCellBroadcastAppLinkEnabled) { + result.add(KEY_CELL_BROADCAST_SETTINGS); + } + + return result; + } + }; } diff --git a/src/com/android/settings/search/Index.java b/src/com/android/settings/search/Index.java index 1b1825c4f..9723fbf6a 100644 --- a/src/com/android/settings/search/Index.java +++ b/src/com/android/settings/search/Index.java @@ -139,6 +139,8 @@ public class Index { // Max number of proposed suggestions private static final int MAX_PROPOSED_SUGGESTIONS = 5; + private static final String BASE_AUTHORITY = "com.android.settings"; + private static final String EMPTY = ""; private static final String NON_BREAKING_HYPHEN = "\u2011"; private static final String HYPHEN = "-"; @@ -160,6 +162,7 @@ public class Index { private final AtomicBoolean mIsAvailable = new AtomicBoolean(false); private final UpdateData mDataToProcess = new UpdateData(); private Context mContext; + private final String mBaseAuthority; /** * A private class to describe the update data for the Index database @@ -190,15 +193,16 @@ public class Index { */ public static Index getInstance(Context context) { if (sInstance == null) { - sInstance = new Index(context); + sInstance = new Index(context, BASE_AUTHORITY); } else { sInstance.setContext(context); } return sInstance; } - public Index(Context context) { + public Index(Context context, String baseAuthority) { mContext = context; + mBaseAuthority = baseAuthority; } public void setContext(Context context) { @@ -286,14 +290,15 @@ public class Index { try { final int baseRank = Ranking.getBaseRankForAuthority(authority); - final Context packageContext = mContext.createPackageContext(packageName, 0); + final Context context = mBaseAuthority.equals(authority) ? + mContext : mContext.createPackageContext(packageName, 0); final Uri uriForResources = buildUriForXmlResources(authority); - addIndexablesForXmlResourceUri(packageContext, packageName, uriForResources, + addIndexablesForXmlResourceUri(context, packageName, uriForResources, SearchIndexablesContract.INDEXABLES_XML_RES_COLUMNS, baseRank); final Uri uriForRawData = buildUriForRawData(authority); - addIndexablesForRawDataUri(packageContext, packageName, uriForRawData, + addIndexablesForRawDataUri(context, packageName, uriForRawData, SearchIndexablesContract.INDEXABLES_RAW_COLUMNS, baseRank); return true; } catch (PackageManager.NameNotFoundException e) { @@ -1137,7 +1142,12 @@ public class Index { final int count = dataToUpdate.size(); for (int n = 0; n < count; n++) { final SearchIndexableData data = dataToUpdate.get(n); - indexOneSearchIndexableData(database, localeStr, data, nonIndexableKeys); + try { + indexOneSearchIndexableData(database, localeStr, data, nonIndexableKeys); + } catch (Exception e) { + Log.e(LOG_TAG, + "Cannot index: " + data.className + " for locale: " + localeStr, e); + } } final long now = System.currentTimeMillis(); diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java index 01d3c0738..7c96a4a6e 100644 --- a/src/com/android/settings/search/SearchIndexableResources.java +++ b/src/com/android/settings/search/SearchIndexableResources.java @@ -87,9 +87,9 @@ public final class SearchIndexableResources { sResMap.put(WirelessSettings.class.getName(), new SearchIndexableResource( Ranking.getRankForClassName(WirelessSettings.class.getName()), - R.xml.wireless_settings, + NO_DATA_RES_ID, WirelessSettings.class.getName(), - R.drawable.empty_icon)); + R.drawable.ic_settings_more)); sResMap.put(HomeSettings.class.getName(), new SearchIndexableResource( |