CarrierConfigManager.java revision 9892718663be17e00cc20e82d75a532161bcd613
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.SystemApi;
22import android.content.Context;
23import android.os.Bundle;
24import android.os.RemoteException;
25import android.os.ServiceManager;
26
27/**
28 * Provides access to telephony configuration values that are carrier-specific.
29 * <p>
30 * Users should obtain an instance of this class by calling
31 * {@code mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);}
32 * </p>
33 *
34 * @see Context#getSystemService
35 * @see Context#CARRIER_CONFIG_SERVICE
36 */
37public class CarrierConfigManager {
38    /**
39     * @hide
40     */
41    public CarrierConfigManager() {
42    }
43
44    /**
45     * This intent is broadcast by the system when carrier config changes.
46     */
47    public static final String
48            ACTION_CARRIER_CONFIG_CHANGED = "android.telephony.action.CARRIER_CONFIG_CHANGED";
49
50    /**
51     * Flag specifying whether VoLTE should be available for carrier, independent of carrier
52     * provisioning. If false: hard disabled. If true: then depends on carrier provisioning,
53     * availability, etc.
54     */
55    public static final String BOOL_CARRIER_VOLTE_AVAILABLE = "bool_carrier_volte_available";
56
57    /**
58     * Flag specifying whether VoLTE availability is based on provisioning.
59     */
60    public static final String BOOL_CARRIER_VOLTE_PROVISIONED = "bool_carrier_volte_provisioned";
61
62    /**
63     * Flag specifying whether VoLTE TTY is supported.
64     */
65    public static final String BOOL_CARRIER_VOLTE_TTY_SUPPORTED
66            = "bool_carrier_volte_tty_supported";
67
68    /**
69     * Show APN Settings for some CDMA carriers.
70     */
71    public static final String BOOL_SHOW_APN_SETTING_CDMA = "bool_show_apn_setting_cdma";
72
73    /**
74     * Control whether users can edit APNs in Settings.
75     */
76    public static final String BOOL_APN_EXPAND = "bool_apn_expand";
77
78    /**
79     * If Voice Radio Technology is RIL_RADIO_TECHNOLOGY_LTE:14 or RIL_RADIO_TECHNOLOGY_UNKNOWN:0
80     * this is the value that should be used instead. A configuration value of
81     * RIL_RADIO_TECHNOLOGY_UNKNOWN:0 means there is no replacement value and that the default
82     * assumption for phone type (GSM) should be used.
83     */
84    public static final String INT_VOLTE_REPLACEMENT_RAT = "int_volte_replacement_rat";
85
86    /* The following 3 fields are related to carrier visual voicemail. */
87
88    /**
89     *  The carrier number MO sms messages are sent to.
90     *
91     *  @hide
92     */
93    public static final String STRING_VVM_DESTINATION_NUMBER = "string_vvm_destination_number";
94
95    /**
96     * The port through which the MO sms messages are sent through.
97     *
98     * @hide
99     */
100    public static final String INT_VVM_PORT_NUMBER = "int_vvm_port_number";
101
102    /**
103     * The type of visual voicemail protocol the carrier adheres to (see below).
104     *
105     * @hide
106     */
107    public static final String STRING_VVM_TYPE = "string_vvm_type";
108
109    /* Visual voicemail protocols */
110
111    /**
112     * The OMTP protocol.
113     *
114     * @hide
115     */
116    public static final String VVM_TYPE_OMTP = "vvm_type_omtp";
117
118    private final static String TAG = "CarrierConfigManager";
119
120    /** The default value for every variable. */
121    private final static Bundle sDefaults;
122
123    static {
124        sDefaults = new Bundle();
125        sDefaults.putBoolean(BOOL_CARRIER_VOLTE_AVAILABLE, false);
126        sDefaults.putBoolean(BOOL_CARRIER_VOLTE_PROVISIONED, false);
127        sDefaults.putBoolean(BOOL_CARRIER_VOLTE_TTY_SUPPORTED, true);
128        sDefaults.putBoolean(BOOL_SHOW_APN_SETTING_CDMA, false);
129        sDefaults.putBoolean(BOOL_APN_EXPAND, true);
130
131        sDefaults.putInt(INT_VOLTE_REPLACEMENT_RAT, 0);
132
133        sDefaults.putString(STRING_VVM_DESTINATION_NUMBER, "");
134        sDefaults.putString(STRING_VVM_TYPE, "");
135        sDefaults.putInt(INT_VVM_PORT_NUMBER, 0);
136    }
137
138    /**
139     * Gets the configuration values for a particular subscription, which is associated with a
140     * specific SIM card. If an invalid subId is used, the returned config will contain default
141     * values.
142     *
143     * @param subId the subscription ID, normally obtained from {@link SubscriptionManager}.
144     * @return A {@link Bundle} containing the config for the given subId, or default values for an
145     *         invalid subId.
146     */
147    public Bundle getConfigForSubId(int subId) {
148        try {
149            return getICarrierConfigLoader().getConfigForSubId(subId);
150        } catch (RemoteException ex) {
151            Rlog.e(TAG, "Error getting config for subId " + Integer.toString(subId) + ": "
152                    + ex.toString());
153        } catch (NullPointerException ex) {
154            Rlog.e(TAG, "Error getting config for subId " + Integer.toString(subId) + ": "
155                    + ex.toString());
156        }
157        return null;
158    }
159
160    /**
161     * Gets the configuration values for the default subscription.
162     *
163     * @see #getConfigForSubId
164     */
165    public Bundle getConfig() {
166        return getConfigForSubId(SubscriptionManager.getDefaultSubId());
167    }
168
169    /**
170     * Calling this method triggers telephony services to fetch the current carrier configuration.
171     * <p>
172     * Normally this does not need to be called because the platform reloads config on its own. Call
173     * this method if your app wants to update config at an arbitrary moment.
174     * </p>
175     * <p>
176     * This method returns before the reload has completed, and
177     * {@link android.service.carrier.CarrierConfigService#onLoadConfig} will be called from an
178     * arbitrary thread.
179     * </p>
180     */
181    public void reloadCarrierConfigForSubId(int subId) {
182        try {
183            getICarrierConfigLoader().reloadCarrierConfigForSubId(subId);
184        } catch (RemoteException ex) {
185            Rlog.e(TAG, "Error reloading config for subId=" + subId + ": " + ex.toString());
186        } catch (NullPointerException ex) {
187            Rlog.e(TAG, "Error reloading config for subId=" + subId + ": " + ex.toString());
188        }
189    }
190
191    /**
192     * Request the carrier config loader to update the cofig for phoneId.
193     *
194     * Depending on simState, the config may be cleared or loaded from config app.
195     * This is only used by SubscriptionInfoUpdater.
196     *
197     * @hide
198     */
199    @SystemApi
200    public void updateConfigForPhoneId(int phoneId, String simState) {
201        try {
202            getICarrierConfigLoader().updateConfigForPhoneId(phoneId, simState);
203        } catch (RemoteException ex) {
204            Rlog.e(TAG, "Error updating config for phoneId=" + phoneId + ": " + ex.toString());
205        } catch (NullPointerException ex) {
206            Rlog.e(TAG, "Error updating config for phoneId=" + phoneId + ": " + ex.toString());
207        }
208    }
209
210    /**
211     * Returns a new bundle with the default value for every supported configuration variable.
212     *
213     * @hide
214     */
215    @SystemApi
216    public static Bundle getDefaultConfig() {
217        return new Bundle(sDefaults);
218    }
219
220    /** @hide */
221    private ICarrierConfigLoader getICarrierConfigLoader() {
222        return ICarrierConfigLoader.Stub
223                .asInterface(ServiceManager.getService(Context.CARRIER_CONFIG_SERVICE));
224    }
225}
226