CarrierConfigManager.java revision 3031bf961103ecc1caa32449a3cdb95575042278
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    /**
40     * This intent is broadcast by the system when carrier config changes.
41     */
42    public static final String
43            ACTION_CARRIER_CONFIG_CHANGED = "android.intent.action.carrier_config_changed";
44
45    /**
46     * Flag specifying whether VoLTE should be available for carrier, independent of carrier
47     * provisioning. If false: hard disabled. If true: then depends on carrier provisioning,
48     * availability, etc.
49     */
50    public static final String BOOL_CARRIER_VOLTE_AVAILABLE = "bool_carrier_volte_available";
51
52    /**
53     * Flag specifying whether VoLTE availability is based on provisioning.
54     */
55    public static final String BOOL_CARRIER_VOLTE_PROVISIONED = "bool_carrier_volte_provisioned";
56
57    /**
58     * Flag specifying whether VoLTE TTY is supported.
59     */
60    public static final String BOOL_CARRIER_VOLTE_TTY_SUPPORTED
61            = "bool_carrier_volte_tty_supported";
62
63    /**
64     * Show APN Settings for some CDMA carriers.
65     */
66    public static final String BOOL_SHOW_APN_SETTING_CDMA = "bool_show_apn_setting_cdma";
67
68    /**
69     * If Voice Radio Technology is RIL_RADIO_TECHNOLOGY_LTE:14 or RIL_RADIO_TECHNOLOGY_UNKNOWN:0
70     * this is the value that should be used instead. A configuration value of
71     * RIL_RADIO_TECHNOLOGY_UNKNOWN:0 means there is no replacement value and that the default
72     * assumption for phone type (GSM) should be used.
73     */
74    public static final String INT_VOLTE_REPLACEMENT_RAT = "int_volte_replacement_rat";
75
76    private final static String TAG = "CarrierConfigManager";
77
78    /** The default value for every variable. */
79    private final static Bundle sDefaults;
80
81    static {
82        sDefaults = new Bundle();
83        sDefaults.putBoolean(BOOL_CARRIER_VOLTE_AVAILABLE, false);
84        sDefaults.putBoolean(BOOL_CARRIER_VOLTE_PROVISIONED, false);
85        sDefaults.putBoolean(BOOL_CARRIER_VOLTE_TTY_SUPPORTED, true);
86        sDefaults.putBoolean(BOOL_SHOW_APN_SETTING_CDMA, false);
87
88        sDefaults.putInt(INT_VOLTE_REPLACEMENT_RAT, 0);
89    }
90
91    /**
92     * Gets the configuration values for a particular subscription, which is associated with a
93     * specific SIM card. If an invalid subId is used, the returned config will contain default
94     * values.
95     *
96     * @param subId the subscription ID, normally obtained from {@link SubscriptionManager}.
97     * @return A {@link Bundle} containing the config for the given subId, or default values for an
98     *         invalid subId.
99     */
100    public Bundle getConfigForSubId(int subId) {
101        try {
102            return getICarrierConfigLoader().getConfigForSubId(subId);
103        } catch (RemoteException ex) {
104            Rlog.e(TAG, "Error getting config for subId " + Integer.toString(subId) + ": "
105                    + ex.toString());
106        } catch (NullPointerException ex) {
107            Rlog.e(TAG, "Error getting config for subId " + Integer.toString(subId) + ": "
108                    + ex.toString());
109        }
110        return null;
111    }
112
113    /**
114     * Gets the configuration values for the default subscription.
115     *
116     * @see #getConfigForSubId
117     */
118    public Bundle getConfig() {
119        return getConfigForSubId(SubscriptionManager.getDefaultSubId());
120    }
121
122    /**
123     * Calling this method triggers telephony services to fetch the current carrier configuration.
124     * <p>
125     * Normally this does not need to be called because the platform reloads config on its own. Call
126     * this method if your app wants to update config at an arbitrary moment.
127     * </p>
128     * <p>
129     * This method returns before the reload has completed, and
130     * {@link android.service.carrier.CarrierConfigService#onLoadConfig} will be called from an
131     * arbitrary thread.
132     * </p>
133     */
134    public void reloadCarrierConfigForSubId(int subId) {
135        try {
136            getICarrierConfigLoader().reloadCarrierConfigForSubId(subId);
137        } catch (RemoteException ex) {
138            Rlog.e(TAG, "Error reloading config for subId=" + subId + ": " + ex.toString());
139        } catch (NullPointerException ex) {
140            Rlog.e(TAG, "Error reloading config for subId=" + subId + ": " + ex.toString());
141        }
142    }
143
144    /**
145     * Request the carrier config loader to update the cofig for phoneId.
146     *
147     * Depending on simState, the config may be cleared or loaded from config app.
148     * This is only used by SubscriptionInfoUpdater.
149     *
150     * @hide
151     */
152    @SystemApi
153    public void updateConfigForPhoneId(int phoneId, String simState) {
154        try {
155            getICarrierConfigLoader().updateConfigForPhoneId(phoneId, simState);
156        } catch (RemoteException ex) {
157            Rlog.e(TAG, "Error updating config for phoneId=" + phoneId + ": " + ex.toString());
158        } catch (NullPointerException ex) {
159            Rlog.e(TAG, "Error updating config for phoneId=" + phoneId + ": " + ex.toString());
160        }
161    }
162
163    /**
164     * Returns a bundle with the default value for every supported configuration variable.
165     *
166     * @hide
167     */
168    @SystemApi
169    public static Bundle getDefaultConfig() {
170        return sDefaults;
171    }
172
173    /** @hide */
174    private ICarrierConfigLoader getICarrierConfigLoader() {
175        return ICarrierConfigLoader.Stub
176                .asInterface(ServiceManager.getService(Context.CARRIER_CONFIG_SERVICE));
177    }
178}
179