Add menu item to Settings to go to Cell Broadcast settings.

Add menu item to Settings when "config_cellBroadcastAppLinks"
config option is set to true to jump to the Cell Broadcast app
settings activity. This enables the Cell Broadcast launcher
icon to be removed, while still allowing access to the app
(by adding a similar menu item to the MMS app) and its settings
activity (this settings link).

The menu item will not be added if the CellBroadcastReceiver
package is disabled or not installed.

Bug: 6709985
Change-Id: If3a3016ceea70704790964c0b712c31cb38f7b62
diff --git a/src/com/android/settings/WirelessSettings.java b/src/com/android/settings/WirelessSettings.java
index 3b67ec3..347315a 100644
--- a/src/com/android/settings/WirelessSettings.java
+++ b/src/com/android/settings/WirelessSettings.java
@@ -50,6 +50,7 @@
     private static final String KEY_PROXY_SETTINGS = "proxy_settings";
     private static final String KEY_MOBILE_NETWORK_SETTINGS = "mobile_network_settings";
     private static final String KEY_TOGGLE_NSD = "toggle_nsd"; //network service discovery
+    private static final String KEY_CELL_BROADCAST_SETTINGS = "cell_broadcast_settings";
 
     public static final String EXIT_ECM_RESULT = "exit_ecm_result";
     public static final int REQUEST_CODE_EXIT_ECM = 1;
@@ -171,6 +172,26 @@
             Preference p = findPreference(KEY_TETHER_SETTINGS);
             p.setTitle(Utils.getTetheringLabel(cm));
         }
+
+        // Enable link to CMAS app settings depending on the value in config.xml.
+        boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(
+                com.android.internal.R.bool.config_cellBroadcastAppLinks);
+        try {
+            if (isCellBroadcastAppLinkEnabled) {
+                PackageManager pm = getPackageManager();
+                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 (!isCellBroadcastAppLinkEnabled) {
+            PreferenceScreen root = getPreferenceScreen();
+            Preference ps = findPreference(KEY_CELL_BROADCAST_SETTINGS);
+            if (ps != null) root.removePreference(ps);
+        }
     }
 
     @Override