CarrierConfigManager.java revision 97f5ccd1cc9f06c27c5e38bfb4a8a05238e1df2f
1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.telephony;
18
19import com.android.internal.telephony.ICarrierConfigLoader;
20
21import android.annotation.NonNull;
22import android.annotation.Nullable;
23import android.annotation.SystemApi;
24import android.content.Context;
25import android.os.PersistableBundle;
26import android.os.RemoteException;
27import android.os.ServiceManager;
28
29/**
30 * Provides access to telephony configuration values that are carrier-specific.
31 * <p>
32 * Users should obtain an instance of this class by calling
33 * {@code mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);}
34 * </p>
35 *
36 * @see Context#getSystemService
37 * @see Context#CARRIER_CONFIG_SERVICE
38 */
39public class CarrierConfigManager {
40    private final static String TAG = "CarrierConfigManager";
41
42    /**
43     * @hide
44     */
45    public CarrierConfigManager() {
46    }
47
48    /**
49     * This intent is broadcast by the system when carrier config changes.
50     */
51    public static final String
52            ACTION_CARRIER_CONFIG_CHANGED = "android.telephony.action.CARRIER_CONFIG_CHANGED";
53
54    // Below are the keys used in carrier config bundles. To add a new variable, define the key and
55    // give it a default value in sDefaults. If you need to ship a per-network override in the
56    // system image, that can be added in packages/apps/CarrierConfig.
57
58    /**
59     * Flag indicating whether the Phone app should ignore EVENT_SIM_NETWORK_LOCKED
60     * events from the Sim.
61     * If true, this will prevent the IccNetworkDepersonalizationPanel from being shown, and
62     * effectively disable the "Sim network lock" feature.
63     */
64    public static final String
65            BOOL_IGNORE_SIM_NETWORK_LOCKED_EVENTS = "bool_ignore_sim_network_locked_events";
66
67    /**
68     * Flag indicating whether the Phone app should provide a "Dismiss" button on the SIM network
69     * unlock screen. The default value is true. If set to false, there will be *no way* to dismiss
70     * the SIM network unlock screen if you don't enter the correct unlock code. (One important
71     * consequence: there will be no way to make an Emergency Call if your SIM is network-locked and
72     * you don't know the PIN.)
73     */
74    public static final String
75            BOOL_SIM_NETWORK_UNLOCK_ALLOW_DISMISS = "bool_sim_network_unlock_allow_dismiss";
76
77    /** Flag indicating if the phone is a world phone */
78    public static final String BOOL_WORLD_PHONE = "bool_world_phone";
79
80    /**
81     * If true, enable vibration (haptic feedback) for key presses in the EmergencyDialer activity.
82     * The pattern is set on a per-platform basis using config_virtualKeyVibePattern. To be
83     * consistent with the regular Dialer, this value should agree with the corresponding values
84     * from config.xml under apps/Contacts.
85     */
86    public static final String
87            BOOL_ENABLE_DIALER_KEY_VIBRATION = "bool_enable_dialer_key_vibration";
88
89    /** Flag indicating if dtmf tone type is enabled */
90    public static final String BOOL_DTMF_TYPE_ENABLED = "bool_dtmf_type_enabled";
91
92    /** Flag indicating if auto retry is enabled */
93    public static final String BOOL_AUTO_RETRY_ENABLED = "bool_auto_retry_enabled";
94
95    /**
96     * Determine whether we want to play local DTMF tones in a call, or just let the radio/BP handle
97     * playing of the tones.
98     */
99    public static final String BOOL_ALLOW_LOCAL_DTMF_TONES = "bool_allow_local_dtmf_tones";
100
101    /**
102     * If true, show an onscreen "Dial" button in the dialer. In practice this is used on all
103     * platforms, even the ones with hard SEND/END keys, but for maximum flexibility it's controlled
104     * by a flag here (which can be overridden on a per-product basis.)
105     */
106    public static final String BOOL_SHOW_ONSCREEN_DIAL_BUTTON = "bool_show_onscreen_dial_button";
107
108    /** Determines if device implements a noise suppression device for in call audio. */
109    public static final String
110            BOOL_HAS_IN_CALL_NOISE_SUPPRESSION = "bool_has_in_call_noise_suppression";
111
112    /**
113     * Determines if the current device should allow emergency numbers to be logged in the Call Log.
114     * (Some carriers require that emergency calls *not* be logged, presumably to avoid the risk of
115     * accidental redialing from the call log UI. This is a good idea, so the default here is
116     * false.)
117     * <p>
118     * TODO: on the other hand, it might still be useful to have some record of the emergency calls
119     * you've made, or to be able to look up the exact date/time of an emergency call. So perhaps we
120     * <b>should</b> log those calls, but instead fix the call log to disable the "call" button for
121     * emergency numbers.
122     */
123    public static final String
124            BOOL_ALLOW_EMERGENCY_NUMBERS_IN_CALL_LOG = "bool_allow_emergency_numbers_in_call_log";
125
126    /** If true, removes the Voice Privacy option from Call Settings */
127    public static final String BOOL_VOICE_PRIVACY_DISABLE = "bool_voice_privacy_disable";
128
129    /** Control whether users can reach the carrier portions of Cellular Network Settings. */
130    public static final String
131            BOOL_HIDE_CARRIER_NETWORK_SETTINGS = "bool_hide_carrier_network_settings";
132
133    /** Control whether users can edit APNs in Settings. */
134    public static final String BOOL_APN_EXPAND = "bool_apn_expand";
135
136    /** Control whether users can choose a network operator. */
137    public static final String BOOL_OPERATOR_SELECTION_EXPAND = "bool_operator_selection_expand";
138
139    /** Used in Cellular Network Settings for preferred network type. */
140    public static final String BOOL_PREFER_2G = "bool_prefer_2g";
141
142    /** Show cdma network mode choices 1x, 3G, global etc. */
143    public static final String BOOL_SHOW_CDMA_CHOICES = "bool_show_cdma_choices";
144
145    /** CDMA activation goes through HFA */
146    public static final String BOOL_USE_HFA_FOR_PROVISIONING = "bool_use_hfa_for_provisioning";
147
148    /**
149     * CDMA activation goes through OTASP.
150     * <p>
151     * TODO: This should be combined with config_use_hfa_for_provisioning and implemented as an enum
152     * (NONE, HFA, OTASP).
153     */
154    public static final String BOOL_USE_OTASP_FOR_PROVISIONING = "bool_use_otasp_for_provisioning";
155
156    /** Display carrier settings menu if true */
157    public static final String BOOL_CARRIER_SETTINGS_ENABLE = "bool_carrier_settings_enable";
158
159    /** Does not display additional call seting for IMS phone based on GSM Phone */
160    public static final String BOOL_ADDITIONAL_CALL_SETTING = "bool_additional_call_setting";
161
162    /** Show APN Settings for some CDMA carriers */
163    public static final String BOOL_SHOW_APN_SETTING_CDMA = "bool_show_apn_setting_cdma";
164
165    /** After a CDMA conference call is merged, the swap button should be displayed. */
166    public static final String BOOL_SUPPORT_SWAP_AFTER_MERGE = "bool_support_swap_after_merge";
167
168    /**
169     * Determine whether the voicemail notification is persistent in the notification bar. If true,
170     * the voicemail notifications cannot be dismissed from the notification bar.
171     */
172    public static final String
173            BOOL_VOICEMAIL_NOTIFICATION_PERSISTENT = "bool_voicemail_notification_persistent";
174
175    /** For IMS video over LTE calls, determines whether video pause signalling is supported. */
176    public static final String
177            BOOL_SUPPORT_PAUSE_IMS_VIDEO_CALLS = "bool_support_pause_ims_video_calls";
178
179    /**
180     * Disables dialing "*228" (OTASP provisioning) on CDMA carriers where it is not supported or is
181     * potentially harmful by locking the SIM to 3G.
182     */
183    public static final String
184            BOOL_DISABLE_CDMA_ACTIVATION_CODE = "bool_disable_cdma_activation_code";
185
186    /**
187     * Flag specifying whether VoLTE should be available for carrier, independent of carrier
188     * provisioning. If false: hard disabled. If true: then depends on carrier provisioning,
189     * availability, etc.
190     */
191    public static final String BOOL_CARRIER_VOLTE_AVAILABLE = "bool_carrier_volte_available";
192
193    /** Flag specifying whether VoLTE availability is based on provisioning. */
194    public static final String BOOL_CARRIER_VOLTE_PROVISIONED = "bool_carrier_volte_provisioned";
195
196    /** Flag specifying whether VoLTE TTY is supported. */
197    public static final String BOOL_CARRIER_VOLTE_TTY_SUPPORTED
198            = "bool_carrier_volte_tty_supported";
199
200    /**
201     * If Voice Radio Technology is RIL_RADIO_TECHNOLOGY_LTE:14 or RIL_RADIO_TECHNOLOGY_UNKNOWN:0
202     * this is the value that should be used instead. A configuration value of
203     * RIL_RADIO_TECHNOLOGY_UNKNOWN:0 means there is no replacement value and that the default
204     * assumption for phone type (GSM) should be used.
205     */
206    public static final String INT_VOLTE_REPLACEMENT_RAT = "int_volte_replacement_rat";
207
208    /* The following 3 fields are related to carrier visual voicemail. */
209
210    /**
211     * The carrier number MO sms messages are sent to.
212     *
213     * @hide
214     */
215    public static final String STRING_VVM_DESTINATION_NUMBER = "string_vvm_destination_number";
216
217    /**
218     * The port through which the MO sms messages are sent through.
219     *
220     * @hide
221     */
222    public static final String INT_VVM_PORT_NUMBER = "int_vvm_port_number";
223
224    /**
225     * The type of visual voicemail protocol the carrier adheres to. See {@link TelephonyManager}
226     * for possible values. For example {@link TelephonyManager#VVM_TYPE_OMTP}.
227     *
228     * @hide
229     */
230    public static final String STRING_VVM_TYPE = "string_vvm_type";
231
232    /**
233     * The package name of the carrier's visual voicemail app to ensure that dialer visual voicemail
234     * and carrier visual voicemail are not active at the same time.
235     *
236     * @hide
237     */
238    public static final String STRING_CARRIER_VVM_PACKAGE_NAME = "string_carrier_vvm_package_name";
239
240    // These variables are used by the MMS service and exposed through another API, {@link
241    // SmsManager}. The variable names and string values are copied from there.
242    public static final String BOOL_MMS_ALIAS_ENABLED = "aliasEnabled";
243    public static final String BOOL_MMS_ALLOW_ATTACH_AUDIO = "allowAttachAudio";
244    public static final String BOOL_MMS_APPEND_TRANSACTION_ID = "enabledTransID";
245    public static final String BOOL_MMS_GROUP_MMS_ENABLED = "enableGroupMms";
246    public static final String BOOL_MMS_MMS_DELIVERY_REPORT_ENABLED = "enableMMSDeliveryReports";
247    public static final String BOOL_MMS_MMS_ENABLED = "enabledMMS";
248    public static final String BOOL_MMS_MMS_READ_REPORT_ENABLED = "enableMMSReadReports";
249    public static final String BOOL_MMS_MULTIPART_SMS_ENABLED = "enableMultipartSMS";
250    public static final String BOOL_MMS_NOTIFY_WAP_MMSC_ENABLED = "enabledNotifyWapMMSC";
251    public static final String BOOL_MMS_SEND_MULTIPART_SMS_AS_SEPARATE_MESSAGES = "sendMultipartSmsAsSeparateMessages";
252    public static final String BOOL_MMS_SHOW_CELL_BROADCAST_APP_LINKS = "config_cellBroadcastAppLinks";
253    public static final String BOOL_MMS_SMS_DELIVERY_REPORT_ENABLED = "enableSMSDeliveryReports";
254    public static final String BOOL_MMS_SUPPORT_HTTP_CHARSET_HEADER = "supportHttpCharsetHeader";
255    public static final String BOOL_MMS_SUPPORT_MMS_CONTENT_DISPOSITION = "supportMmsContentDisposition";
256    public static final String INT_MMS_ALIAS_MAX_CHARS = "aliasMaxChars";
257    public static final String INT_MMS_ALIAS_MIN_CHARS = "aliasMinChars";
258    public static final String INT_MMS_HTTP_SOCKET_TIMEOUT = "httpSocketTimeout";
259    public static final String INT_MMS_MAX_IMAGE_HEIGHT = "maxImageHeight";
260    public static final String INT_MMS_MAX_IMAGE_WIDTH = "maxImageWidth";
261    public static final String INT_MMS_MAX_MESSAGE_SIZE = "maxMessageSize";
262    public static final String INT_MMS_MESSAGE_TEXT_MAX_SIZE = "maxMessageTextSize";
263    public static final String INT_MMS_RECIPIENT_LIMIT = "recipientLimit";
264    public static final String INT_MMS_SMS_TO_MMS_TEXT_LENGTH_THRESHOLD = "smsToMmsTextLengthThreshold";
265    public static final String INT_MMS_SMS_TO_MMS_TEXT_THRESHOLD = "smsToMmsTextThreshold";
266    public static final String INT_MMS_SUBJECT_MAX_LENGTH = "maxSubjectLength";
267    public static final String STRING_MMS_EMAIL_GATEWAY_NUMBER = "emailGatewayNumber";
268    public static final String STRING_MMS_HTTP_PARAMS = "httpParams";
269    public static final String STRING_MMS_NAI_SUFFIX = "naiSuffix";
270    public static final String STRING_MMS_UA_PROF_TAG_NAME = "uaProfTagName";
271    public static final String STRING_MMS_UA_PROF_URL = "uaProfUrl";
272    public static final String STRING_MMS_USER_AGENT = "userAgent";
273
274    /** The default value for every variable. */
275    private final static PersistableBundle sDefaults;
276
277    static {
278        sDefaults = new PersistableBundle();
279        sDefaults.putBoolean(BOOL_ADDITIONAL_CALL_SETTING, true);
280        sDefaults.putBoolean(BOOL_ALLOW_EMERGENCY_NUMBERS_IN_CALL_LOG, false);
281        sDefaults.putBoolean(BOOL_ALLOW_LOCAL_DTMF_TONES, true);
282        sDefaults.putBoolean(BOOL_APN_EXPAND, true);
283        sDefaults.putBoolean(BOOL_AUTO_RETRY_ENABLED, false);
284        sDefaults.putBoolean(BOOL_CARRIER_SETTINGS_ENABLE, false);
285        sDefaults.putBoolean(BOOL_CARRIER_VOLTE_AVAILABLE, false);
286        sDefaults.putBoolean(BOOL_CARRIER_VOLTE_PROVISIONED, false);
287        sDefaults.putBoolean(BOOL_CARRIER_VOLTE_TTY_SUPPORTED, true);
288        sDefaults.putBoolean(BOOL_DISABLE_CDMA_ACTIVATION_CODE, false);
289        sDefaults.putBoolean(BOOL_DTMF_TYPE_ENABLED, false);
290        sDefaults.putBoolean(BOOL_ENABLE_DIALER_KEY_VIBRATION, true);
291        sDefaults.putBoolean(BOOL_HAS_IN_CALL_NOISE_SUPPRESSION, false);
292        sDefaults.putBoolean(BOOL_HIDE_CARRIER_NETWORK_SETTINGS, false);
293        sDefaults.putBoolean(BOOL_IGNORE_SIM_NETWORK_LOCKED_EVENTS, false);
294        sDefaults.putBoolean(BOOL_OPERATOR_SELECTION_EXPAND, true);
295        sDefaults.putBoolean(BOOL_PREFER_2G, true);
296        sDefaults.putBoolean(BOOL_SHOW_APN_SETTING_CDMA, false);
297        sDefaults.putBoolean(BOOL_SHOW_CDMA_CHOICES, false);
298        sDefaults.putBoolean(BOOL_SHOW_ONSCREEN_DIAL_BUTTON, true);
299        sDefaults.putBoolean(BOOL_SIM_NETWORK_UNLOCK_ALLOW_DISMISS, true);
300        sDefaults.putBoolean(BOOL_SUPPORT_PAUSE_IMS_VIDEO_CALLS, true);
301        sDefaults.putBoolean(BOOL_SUPPORT_SWAP_AFTER_MERGE, true);
302        sDefaults.putBoolean(BOOL_USE_HFA_FOR_PROVISIONING, false);
303        sDefaults.putBoolean(BOOL_USE_OTASP_FOR_PROVISIONING, false);
304        sDefaults.putBoolean(BOOL_VOICEMAIL_NOTIFICATION_PERSISTENT, false);
305        sDefaults.putBoolean(BOOL_VOICE_PRIVACY_DISABLE, false);
306        sDefaults.putBoolean(BOOL_WORLD_PHONE, false);
307        sDefaults.putInt(INT_VOLTE_REPLACEMENT_RAT, 0);
308        sDefaults.putInt(INT_VVM_PORT_NUMBER, 0);
309        sDefaults.putString(STRING_VVM_DESTINATION_NUMBER, "");
310        sDefaults.putString(STRING_VVM_TYPE, "");
311
312        // MMS defaults
313        sDefaults.putBoolean(BOOL_MMS_ALIAS_ENABLED, false);
314        sDefaults.putBoolean(BOOL_MMS_ALLOW_ATTACH_AUDIO, true);
315        sDefaults.putBoolean(BOOL_MMS_APPEND_TRANSACTION_ID, false);
316        sDefaults.putBoolean(BOOL_MMS_GROUP_MMS_ENABLED, true);
317        sDefaults.putBoolean(BOOL_MMS_MMS_DELIVERY_REPORT_ENABLED, false);
318        sDefaults.putBoolean(BOOL_MMS_MMS_ENABLED, true);
319        sDefaults.putBoolean(BOOL_MMS_MMS_READ_REPORT_ENABLED, false);
320        sDefaults.putBoolean(BOOL_MMS_MULTIPART_SMS_ENABLED, true);
321        sDefaults.putBoolean(BOOL_MMS_NOTIFY_WAP_MMSC_ENABLED, false);
322        sDefaults.putBoolean(BOOL_MMS_SEND_MULTIPART_SMS_AS_SEPARATE_MESSAGES, false);
323        sDefaults.putBoolean(BOOL_MMS_SHOW_CELL_BROADCAST_APP_LINKS, true);
324        sDefaults.putBoolean(BOOL_MMS_SMS_DELIVERY_REPORT_ENABLED, true);
325        sDefaults.putBoolean(BOOL_MMS_SUPPORT_HTTP_CHARSET_HEADER, false);
326        sDefaults.putBoolean(BOOL_MMS_SUPPORT_MMS_CONTENT_DISPOSITION, true);
327        sDefaults.putInt(INT_MMS_ALIAS_MAX_CHARS, 48);
328        sDefaults.putInt(INT_MMS_ALIAS_MIN_CHARS, 2);
329        sDefaults.putInt(INT_MMS_HTTP_SOCKET_TIMEOUT, 60 * 1000);
330        sDefaults.putInt(INT_MMS_MAX_IMAGE_HEIGHT, 480);
331        sDefaults.putInt(INT_MMS_MAX_IMAGE_WIDTH, 640);
332        sDefaults.putInt(INT_MMS_MAX_MESSAGE_SIZE, 300 * 1024);
333        sDefaults.putInt(INT_MMS_MESSAGE_TEXT_MAX_SIZE, -1);
334        sDefaults.putInt(INT_MMS_RECIPIENT_LIMIT, Integer.MAX_VALUE);
335        sDefaults.putInt(INT_MMS_SMS_TO_MMS_TEXT_LENGTH_THRESHOLD, -1);
336        sDefaults.putInt(INT_MMS_SMS_TO_MMS_TEXT_THRESHOLD, -1);
337        sDefaults.putInt(INT_MMS_SUBJECT_MAX_LENGTH, 40);
338        sDefaults.putString(STRING_MMS_EMAIL_GATEWAY_NUMBER, "");
339        sDefaults.putString(STRING_MMS_HTTP_PARAMS, "");
340        sDefaults.putString(STRING_MMS_NAI_SUFFIX, "");
341        sDefaults.putString(STRING_MMS_UA_PROF_TAG_NAME, "x-wap-profile");
342        sDefaults.putString(STRING_MMS_UA_PROF_URL, "");
343        sDefaults.putString(STRING_MMS_USER_AGENT, "");
344    }
345
346    /**
347     * Gets the configuration values for a particular subscription, which is associated with a
348     * specific SIM card. If an invalid subId is used, the returned config will contain default
349     * values.
350     *
351     * @param subId the subscription ID, normally obtained from {@link SubscriptionManager}.
352     * @return A {@link PersistableBundle} containing the config for the given subId, or default
353     *         values for an invalid subId.
354     */
355    @Nullable
356    public PersistableBundle getConfigForSubId(int subId) {
357        try {
358            return getICarrierConfigLoader().getConfigForSubId(subId);
359        } catch (RemoteException ex) {
360            Rlog.e(TAG, "Error getting config for subId " + Integer.toString(subId) + ": "
361                    + ex.toString());
362        } catch (NullPointerException ex) {
363            Rlog.e(TAG, "Error getting config for subId " + Integer.toString(subId) + ": "
364                    + ex.toString());
365        }
366        return null;
367    }
368
369    /**
370     * Gets the configuration values for the default subscription.
371     *
372     * @see #getConfigForSubId
373     */
374    @Nullable
375    public PersistableBundle getConfig() {
376        return getConfigForSubId(SubscriptionManager.getDefaultSubId());
377    }
378
379    /**
380     * Calling this method triggers telephony services to fetch the current carrier configuration.
381     * <p>
382     * Normally this does not need to be called because the platform reloads config on its own. Call
383     * this method if your app wants to update config at an arbitrary moment.
384     * </p>
385     * <p>
386     * This method returns before the reload has completed, and
387     * {@link android.service.carrier.CarrierService#onLoadConfig} will be called from an
388     * arbitrary thread.
389     * </p>
390     */
391    public void reloadCarrierConfigForSubId(int subId) {
392        try {
393            getICarrierConfigLoader().reloadCarrierConfigForSubId(subId);
394        } catch (RemoteException ex) {
395            Rlog.e(TAG, "Error reloading config for subId=" + subId + ": " + ex.toString());
396        } catch (NullPointerException ex) {
397            Rlog.e(TAG, "Error reloading config for subId=" + subId + ": " + ex.toString());
398        }
399    }
400
401    /**
402     * Request the carrier config loader to update the cofig for phoneId.
403     * <p>
404     * Depending on simState, the config may be cleared or loaded from config app. This is only used
405     * by SubscriptionInfoUpdater.
406     * </p>
407     *
408     * @hide
409     */
410    @SystemApi
411    public void updateConfigForPhoneId(int phoneId, String simState) {
412        try {
413            getICarrierConfigLoader().updateConfigForPhoneId(phoneId, simState);
414        } catch (RemoteException ex) {
415            Rlog.e(TAG, "Error updating config for phoneId=" + phoneId + ": " + ex.toString());
416        } catch (NullPointerException ex) {
417            Rlog.e(TAG, "Error updating config for phoneId=" + phoneId + ": " + ex.toString());
418        }
419    }
420
421    /**
422     * Returns a new bundle with the default value for every supported configuration variable.
423     *
424     * @hide
425     */
426    @NonNull
427    @SystemApi
428    public static PersistableBundle getDefaultConfig() {
429        return new PersistableBundle(sDefaults);
430    }
431
432    /** @hide */
433    private ICarrierConfigLoader getICarrierConfigLoader() {
434        return ICarrierConfigLoader.Stub
435                .asInterface(ServiceManager.getService(Context.CARRIER_CONFIG_SERVICE));
436    }
437}
438