CarrierConfigManager.java revision 2850d7a5996aaccc675a917cfec61f5ba55845d7
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     * If Voice Radio Technology is RIL_RADIO_TECHNOLOGY_LTE:14 or RIL_RADIO_TECHNOLOGY_UNKNOWN:0
75     * this is the value that should be used instead. A configuration value of
76     * RIL_RADIO_TECHNOLOGY_UNKNOWN:0 means there is no replacement value and that the default
77     * assumption for phone type (GSM) should be used.
78     */
79    public static final String INT_VOLTE_REPLACEMENT_RAT = "int_volte_replacement_rat";
80
81    /* The following 3 fields are related to carrier visual voicemail. */
82
83    /**
84     *  The carrier number MO sms messages are sent to.
85     *
86     *  @hide
87     */
88    public static final String STRING_VVM_DESTINATION_NUMBER = "string_vvm_destination_number";
89
90    /**
91     * The port through which the MO sms messages are sent through.
92     *
93     * @hide
94     */
95    public static final String INT_VVM_PORT_NUMBER = "int_vvm_port_number";
96
97    /**
98     * The type of visual voicemail protocol the carrier adheres to (see below).
99     *
100     * @hide
101     */
102    public static final String STRING_VVM_TYPE = "string_vvm_type";
103
104    /* Visual voicemail protocols */
105
106    /**
107     * The OMTP protocol.
108     *
109     * @hide
110     */
111    public static final String VVM_TYPE_OMTP = "vvm_type_omtp";
112
113    private final static String TAG = "CarrierConfigManager";
114
115    /** The default value for every variable. */
116    private final static Bundle sDefaults;
117
118    static {
119        sDefaults = new Bundle();
120        sDefaults.putBoolean(BOOL_CARRIER_VOLTE_AVAILABLE, false);
121        sDefaults.putBoolean(BOOL_CARRIER_VOLTE_PROVISIONED, false);
122        sDefaults.putBoolean(BOOL_CARRIER_VOLTE_TTY_SUPPORTED, true);
123        sDefaults.putBoolean(BOOL_SHOW_APN_SETTING_CDMA, false);
124
125        sDefaults.putInt(INT_VOLTE_REPLACEMENT_RAT, 0);
126
127        sDefaults.putString(STRING_VVM_DESTINATION_NUMBER, "");
128        sDefaults.putString(STRING_VVM_TYPE, "");
129        sDefaults.putInt(INT_VVM_PORT_NUMBER, 0);
130    }
131
132    /**
133     * Gets the configuration values for a particular subscription, which is associated with a
134     * specific SIM card. If an invalid subId is used, the returned config will contain default
135     * values.
136     *
137     * @param subId the subscription ID, normally obtained from {@link SubscriptionManager}.
138     * @return A {@link Bundle} containing the config for the given subId, or default values for an
139     *         invalid subId.
140     */
141    public Bundle getConfigForSubId(int subId) {
142        try {
143            return getICarrierConfigLoader().getConfigForSubId(subId);
144        } catch (RemoteException ex) {
145            Rlog.e(TAG, "Error getting config for subId " + Integer.toString(subId) + ": "
146                    + ex.toString());
147        } catch (NullPointerException ex) {
148            Rlog.e(TAG, "Error getting config for subId " + Integer.toString(subId) + ": "
149                    + ex.toString());
150        }
151        return null;
152    }
153
154    /**
155     * Gets the configuration values for the default subscription.
156     *
157     * @see #getConfigForSubId
158     */
159    public Bundle getConfig() {
160        return getConfigForSubId(SubscriptionManager.getDefaultSubId());
161    }
162
163    /**
164     * Calling this method triggers telephony services to fetch the current carrier configuration.
165     * <p>
166     * Normally this does not need to be called because the platform reloads config on its own. Call
167     * this method if your app wants to update config at an arbitrary moment.
168     * </p>
169     * <p>
170     * This method returns before the reload has completed, and
171     * {@link android.service.carrier.CarrierConfigService#onLoadConfig} will be called from an
172     * arbitrary thread.
173     * </p>
174     */
175    public void reloadCarrierConfigForSubId(int subId) {
176        try {
177            getICarrierConfigLoader().reloadCarrierConfigForSubId(subId);
178        } catch (RemoteException ex) {
179            Rlog.e(TAG, "Error reloading config for subId=" + subId + ": " + ex.toString());
180        } catch (NullPointerException ex) {
181            Rlog.e(TAG, "Error reloading config for subId=" + subId + ": " + ex.toString());
182        }
183    }
184
185    /**
186     * Request the carrier config loader to update the cofig for phoneId.
187     *
188     * Depending on simState, the config may be cleared or loaded from config app.
189     * This is only used by SubscriptionInfoUpdater.
190     *
191     * @hide
192     */
193    @SystemApi
194    public void updateConfigForPhoneId(int phoneId, String simState) {
195        try {
196            getICarrierConfigLoader().updateConfigForPhoneId(phoneId, simState);
197        } catch (RemoteException ex) {
198            Rlog.e(TAG, "Error updating config for phoneId=" + phoneId + ": " + ex.toString());
199        } catch (NullPointerException ex) {
200            Rlog.e(TAG, "Error updating config for phoneId=" + phoneId + ": " + ex.toString());
201        }
202    }
203
204    /**
205     * Returns a bundle with the default value for every supported configuration variable.
206     *
207     * @hide
208     */
209    @SystemApi
210    public static Bundle getDefaultConfig() {
211        return sDefaults;
212    }
213
214    /** @hide */
215    private ICarrierConfigLoader getICarrierConfigLoader() {
216        return ICarrierConfigLoader.Stub
217                .asInterface(ServiceManager.getService(Context.CARRIER_CONFIG_SERVICE));
218    }
219}
220