CarrierConfigManager.java revision 9a1c9b67c4b2426884deb60c1ff84130ab47333c
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    private final static String TAG = "CarrierConfigManager";
82
83    /** The default value for every variable. */
84    private final static Bundle sDefaults;
85
86    static {
87        sDefaults = new Bundle();
88        sDefaults.putBoolean(BOOL_CARRIER_VOLTE_AVAILABLE, false);
89        sDefaults.putBoolean(BOOL_CARRIER_VOLTE_PROVISIONED, false);
90        sDefaults.putBoolean(BOOL_CARRIER_VOLTE_TTY_SUPPORTED, true);
91        sDefaults.putBoolean(BOOL_SHOW_APN_SETTING_CDMA, false);
92
93        sDefaults.putInt(INT_VOLTE_REPLACEMENT_RAT, 0);
94    }
95
96    /**
97     * Gets the configuration values for a particular subscription, which is associated with a
98     * specific SIM card. If an invalid subId is used, the returned config will contain default
99     * values.
100     *
101     * @param subId the subscription ID, normally obtained from {@link SubscriptionManager}.
102     * @return A {@link Bundle} containing the config for the given subId, or default values for an
103     *         invalid subId.
104     */
105    public Bundle getConfigForSubId(int subId) {
106        try {
107            return getICarrierConfigLoader().getConfigForSubId(subId);
108        } catch (RemoteException ex) {
109            Rlog.e(TAG, "Error getting config for subId " + Integer.toString(subId) + ": "
110                    + ex.toString());
111        } catch (NullPointerException ex) {
112            Rlog.e(TAG, "Error getting config for subId " + Integer.toString(subId) + ": "
113                    + ex.toString());
114        }
115        return null;
116    }
117
118    /**
119     * Gets the configuration values for the default subscription.
120     *
121     * @see #getConfigForSubId
122     */
123    public Bundle getConfig() {
124        return getConfigForSubId(SubscriptionManager.getDefaultSubId());
125    }
126
127    /**
128     * Calling this method triggers telephony services to fetch the current carrier configuration.
129     * <p>
130     * Normally this does not need to be called because the platform reloads config on its own. Call
131     * this method if your app wants to update config at an arbitrary moment.
132     * </p>
133     * <p>
134     * This method returns before the reload has completed, and
135     * {@link android.service.carrier.CarrierConfigService#onLoadConfig} will be called from an
136     * arbitrary thread.
137     * </p>
138     */
139    public void reloadCarrierConfigForSubId(int subId) {
140        try {
141            getICarrierConfigLoader().reloadCarrierConfigForSubId(subId);
142        } catch (RemoteException ex) {
143            Rlog.e(TAG, "Error reloading config for subId=" + subId + ": " + ex.toString());
144        } catch (NullPointerException ex) {
145            Rlog.e(TAG, "Error reloading config for subId=" + subId + ": " + ex.toString());
146        }
147    }
148
149    /**
150     * Request the carrier config loader to update the cofig for phoneId.
151     *
152     * Depending on simState, the config may be cleared or loaded from config app.
153     * This is only used by SubscriptionInfoUpdater.
154     *
155     * @hide
156     */
157    @SystemApi
158    public void updateConfigForPhoneId(int phoneId, String simState) {
159        try {
160            getICarrierConfigLoader().updateConfigForPhoneId(phoneId, simState);
161        } catch (RemoteException ex) {
162            Rlog.e(TAG, "Error updating config for phoneId=" + phoneId + ": " + ex.toString());
163        } catch (NullPointerException ex) {
164            Rlog.e(TAG, "Error updating config for phoneId=" + phoneId + ": " + ex.toString());
165        }
166    }
167
168    /**
169     * Returns a bundle with the default value for every supported configuration variable.
170     *
171     * @hide
172     */
173    @SystemApi
174    public static Bundle getDefaultConfig() {
175        return sDefaults;
176    }
177
178    /** @hide */
179    private ICarrierConfigLoader getICarrierConfigLoader() {
180        return ICarrierConfigLoader.Stub
181                .asInterface(ServiceManager.getService(Context.CARRIER_CONFIG_SERVICE));
182    }
183}
184