blob: 8c22d7a992935c44353b9a81eb890dd23e353d39 [file] [log] [blame]
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001/**
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
Jonathan Basseri6465afd2015-02-25 13:05:57 -080017package com.android.phone;
18
19import static android.Manifest.permission.READ_PHONE_STATE;
20import static com.android.internal.telephony.uicc.IccCardProxy.ACTION_INTERNAL_SIM_STATE_CHANGED;
21
Jonathan Basseri11f89572015-05-05 11:57:39 -070022import android.annotation.NonNull;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080023import android.app.ActivityManagerNative;
24import android.content.BroadcastReceiver;
25import android.content.ComponentName;
26import android.content.Context;
27import android.content.Intent;
28import android.content.IntentFilter;
29import android.content.ServiceConnection;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -070030import android.content.pm.PackageInfo;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070031import android.content.pm.PackageManager;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080032import android.database.sqlite.SQLiteDatabase;
33import android.database.sqlite.SQLiteOpenHelper;
34import android.os.AsyncResult;
Junda Liu43d723a2015-05-12 17:23:45 -070035import android.os.Binder;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080036import android.os.Handler;
37import android.os.IBinder;
38import android.os.Message;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070039import android.os.PersistableBundle;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080040import android.os.RemoteException;
41import android.os.ServiceManager;
42import android.os.UserHandle;
43import android.service.carrier.CarrierConfigService;
44import android.service.carrier.CarrierIdentifier;
45import android.service.carrier.ICarrierConfigService;
46import android.telephony.CarrierConfigManager;
47import android.telephony.SubscriptionManager;
48import android.telephony.TelephonyManager;
49import android.util.Log;
50
51import com.android.internal.telephony.ICarrierConfigLoader;
52import com.android.internal.telephony.IccCardConstants;
53import com.android.internal.telephony.Phone;
54import com.android.internal.telephony.PhoneConstants;
55import com.android.internal.telephony.PhoneFactory;
56import com.android.internal.telephony.TelephonyIntents;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -070057import com.android.internal.util.FastXmlSerializer;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080058
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -070059import org.xmlpull.v1.XmlPullParser;
60import org.xmlpull.v1.XmlPullParserException;
61import org.xmlpull.v1.XmlPullParserFactory;
62
63import java.io.File;
Junda Liu43d723a2015-05-12 17:23:45 -070064import java.io.FileDescriptor;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -070065import java.io.FileInputStream;
66import java.io.FileNotFoundException;
67import java.io.FileOutputStream;
68import java.io.IOException;
Junda Liu43d723a2015-05-12 17:23:45 -070069import java.io.PrintWriter;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080070import java.util.List;
71
72/**
73 * CarrierConfigLoader binds to privileged carrier apps to fetch carrier config overlays.
74 * TODO: implement persist cache
Jonathan Basseri6465afd2015-02-25 13:05:57 -080075 * TODO: handle package install/uninstall events
76 */
77
78public class CarrierConfigLoader extends ICarrierConfigLoader.Stub {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -070079 private static final String LOG_TAG = "CarrierConfigLoader";
Jonathan Basseri6465afd2015-02-25 13:05:57 -080080 // Package name for default carrier config app, bundled with system image.
81 private static final String DEFAULT_CARRIER_CONFIG_PACKAGE = "com.android.carrierconfig";
82
83 /** The singleton instance. */
84 private static CarrierConfigLoader sInstance;
85 // The context for phone app, passed from PhoneGlobals.
86 private Context mContext;
87 // Carrier configs from default app, indexed by phoneID.
Jonathan Basseric31f1f32015-05-12 10:13:03 -070088 private PersistableBundle[] mConfigFromDefaultApp;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080089 // Carrier configs from privileged carrier config app, indexed by phoneID.
Jonathan Basseric31f1f32015-05-12 10:13:03 -070090 private PersistableBundle[] mConfigFromCarrierApp;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080091 // Service connection for binding to config app.
92 private ConfigServiceConnection[] mServiceConnection;
93
94 // Broadcast receiver for SIM and pkg intents, register intent filter in constructor.
95 private final BroadcastReceiver mReceiver = new ConfigLoaderBroadcastReceiver();
96
97 // Message codes; see mHandler below.
98 // Request from SubscriptionInfoUpdater when SIM becomes absent or error.
99 private static final int EVENT_CLEAR_CONFIG = 0;
100 // Request from SubscriptionInfoUpdater to update config.
101 private static final int EVENT_UPDATE_CONFIG = 1;
102 // Request from carrier app to reload config.
103 private static final int EVENT_RELOAD_CONFIG = 2;
104 // Has connected to default app.
105 private static final int EVENT_CONNECTED_TO_DEFAULT = 3;
106 // Has connected to carrier app.
107 private static final int EVENT_CONNECTED_TO_CARRIER = 4;
108 // Config has been loaded from default app.
109 private static final int EVENT_LOADED_FROM_DEFAULT = 5;
110 // Config has been loaded from carrier app.
111 private static final int EVENT_LOADED_FROM_CARRIER = 6;
112
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700113 // Tags used for saving and restoring XML documents.
114 private static final String TAG_DOCUMENT = "carrier_config";
115 private static final String TAG_VERSION = "package_version";
116 private static final String TAG_BUNDLE = "bundle_data";
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800117
118 // Handler to process various events.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700119 //
120 // For each phoneId, state transition should be: default app bind->connected->loaded, carrier
121 // app (if exists) bind-> connected->loaded. At any time, at most one connection is active. If
122 // events are not in this order, previous connection will be unbind, so only latest event takes
123 // effect.
124 //
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800125 // We broadcast config change when:
126 // 1. loaded from carrier app
127 // 2. loaded from default app if no carrier app
128 // 3. config cleared, possibly due to sim removed
129 // 4. bind or IPC error
130 private Handler mHandler = new Handler() {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700131 @Override
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800132 public void handleMessage(Message msg) {
133 int phoneId = msg.arg1;
134 log("mHandler: " + msg.what + " phoneId: " + phoneId);
135 CarrierIdentifier carrierId;
136 ConfigServiceConnection conn;
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700137 PersistableBundle config;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800138 switch (msg.what) {
139 case EVENT_CLEAR_CONFIG:
140 mConfigFromDefaultApp[phoneId] = null;
141 mConfigFromCarrierApp[phoneId] = null;
142 mServiceConnection[phoneId] = null;
143 broadcastConfigChangedIntent(phoneId);
144 break;
145 case EVENT_UPDATE_CONFIG:
146 // Use persist cache to avoid loading from app.
147 // Fall through to next event if cache not hit.
148 case EVENT_RELOAD_CONFIG:
149 if (!bindToConfigPackage(DEFAULT_CARRIER_CONFIG_PACKAGE,
150 phoneId, EVENT_CONNECTED_TO_DEFAULT)) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700151 // Send bcast if bind fails
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800152 broadcastConfigChangedIntent(phoneId);
153 }
154 break;
155
156 case EVENT_CONNECTED_TO_DEFAULT:
157 carrierId = getCarrierIdForPhoneId(phoneId);
158 conn = (ConfigServiceConnection) msg.obj;
159 // If new service connection has been created, unbind.
160 if (mServiceConnection[phoneId] != conn || conn.service == null) {
161 mContext.unbindService(conn);
162 break;
163 }
164 try {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700165 ICarrierConfigService configService = ICarrierConfigService.Stub
166 .asInterface(conn.service);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800167 config = configService.getCarrierConfig(carrierId);
168 mConfigFromDefaultApp[phoneId] = config;
Junda Liu9f2d2712015-05-15 14:22:45 -0700169 sendMessage(obtainMessage(EVENT_LOADED_FROM_DEFAULT, phoneId, -1));
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800170 } catch (RemoteException ex) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700171 loge("Failed to get carrier config: " + ex.toString());
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800172 } finally {
173 mContext.unbindService(mServiceConnection[phoneId]);
174 }
175 break;
176
177 case EVENT_LOADED_FROM_DEFAULT:
178 if (mServiceConnection[phoneId] == null) {
179 break;
180 }
181 List<String> carrierPackageNames = TelephonyManager.from(mContext)
Junda Liu0bdd55b2015-05-04 14:32:58 -0700182 .getCarrierPackageNamesForIntentAndPhone(
183 new Intent(CarrierConfigService.SERVICE_INTERFACE), phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800184 log("Found carrier config app: " + carrierPackageNames);
185 if (carrierPackageNames != null && carrierPackageNames.size() > 0) {
186 if (!bindToConfigPackage(carrierPackageNames.get(0),
187 phoneId, EVENT_CONNECTED_TO_CARRIER)) {
188 broadcastConfigChangedIntent(phoneId);
189 }
190 } else {
191 broadcastConfigChangedIntent(phoneId);
192 }
193 break;
194
195 case EVENT_CONNECTED_TO_CARRIER:
196 carrierId = getCarrierIdForPhoneId(phoneId);
197 conn = (ConfigServiceConnection) msg.obj;
198 // If new service connection has been created, unbind.
199 if (mServiceConnection[phoneId] != conn ||
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700200 conn.service == null) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800201 mContext.unbindService(conn);
202 break;
203 }
204 try {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700205 ICarrierConfigService configService = ICarrierConfigService.Stub
206 .asInterface(conn.service);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800207 config = configService.getCarrierConfig(carrierId);
208 mConfigFromCarrierApp[phoneId] = config;
Junda Liu9f2d2712015-05-15 14:22:45 -0700209 sendMessage(obtainMessage(EVENT_LOADED_FROM_CARRIER, phoneId, -1));
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800210 } catch (RemoteException ex) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700211 loge("Failed to get carrier config: " + ex.toString());
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800212 } finally {
213 mContext.unbindService(mServiceConnection[phoneId]);
214 }
215 break;
216
217 case EVENT_LOADED_FROM_CARRIER:
218 if (mServiceConnection[phoneId] == null) {
219 break;
220 }
221 broadcastConfigChangedIntent(phoneId);
222 break;
223 }
224 }
225 };
226
227 /**
228 * Constructs a CarrierConfigLoader, registers it as a service, and registers a broadcast
229 * receiver for relevant events.
230 */
231 private CarrierConfigLoader(Context context) {
232 mContext = context;
233
234 // Register for package updates.
235 IntentFilter triggers = new IntentFilter();
236 triggers.addAction(Intent.ACTION_PACKAGE_ADDED);
237 triggers.addAction(Intent.ACTION_PACKAGE_CHANGED);
238 triggers.addAction(Intent.ACTION_PACKAGE_REMOVED);
239 mContext.registerReceiver(mReceiver, triggers);
240
241 int numPhones = TelephonyManager.from(context).getPhoneCount();
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700242 mConfigFromDefaultApp = new PersistableBundle[numPhones];
243 mConfigFromCarrierApp = new PersistableBundle[numPhones];
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800244 mServiceConnection = new ConfigServiceConnection[numPhones];
245 // Make this service available through ServiceManager.
246 ServiceManager.addService(Context.CARRIER_CONFIG_SERVICE, this);
247 log("CarrierConfigLoader has started");
248 }
249
250 /**
251 * Initialize the singleton CarrierConfigLoader instance.
252 *
253 * This is only done once, at startup, from {@link com.android.phone.PhoneApp#onCreate}.
254 */
255 /* package */
256 static CarrierConfigLoader init(Context context) {
257 synchronized (CarrierConfigLoader.class) {
258 if (sInstance == null) {
259 sInstance = new CarrierConfigLoader(context);
260 } else {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700261 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800262 }
263 return sInstance;
264 }
265 }
266
267 private void broadcastConfigChangedIntent(int phoneId) {
268 Intent intent = new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
269 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
270 SubscriptionManager.putPhoneIdAndSubIdExtra(intent, phoneId);
271 ActivityManagerNative.broadcastStickyIntent(intent, READ_PHONE_STATE,
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700272 UserHandle.USER_ALL);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800273 }
274
275 /** Binds to the default or carrier config app. */
276 private boolean bindToConfigPackage(String pkgName, int phoneId, int eventId) {
277 log("Binding to " + pkgName + " for phone " + phoneId);
278 Intent carrierConfigService = new Intent(CarrierConfigService.SERVICE_INTERFACE);
279 carrierConfigService.setPackage(pkgName);
280 mServiceConnection[phoneId] = new ConfigServiceConnection(phoneId, eventId);
281 try {
282 return mContext.bindService(carrierConfigService, mServiceConnection[phoneId],
283 Context.BIND_AUTO_CREATE);
284 } catch (SecurityException ex) {
285 return false;
286 }
287 }
288
289 private CarrierIdentifier getCarrierIdForPhoneId(int phoneId) {
290 String mcc = "";
291 String mnc = "";
292 String imsi = "";
293 String gid1 = "";
294 String gid2 = "";
295 String spn = TelephonyManager.from(mContext).getSimOperatorNameForPhone(phoneId);
296 String simOperator = TelephonyManager.from(mContext).getSimOperatorNumericForPhone(phoneId);
Jonathan Basseri1fa437c2015-04-20 11:08:18 -0700297 // A valid simOperator should be 5 or 6 digits, depending on the length of the MNC.
298 if (simOperator != null && simOperator.length() >= 3) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800299 mcc = simOperator.substring(0, 3);
300 mnc = simOperator.substring(3);
301 }
302 Phone phone = PhoneFactory.getPhone(phoneId);
303 if (phone != null) {
304 imsi = phone.getSubscriberId();
305 gid1 = phone.getGroupIdLevel1();
Junda Liu73183532015-05-14 13:55:40 -0700306 gid2 = phone.getGroupIdLevel2();
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800307 }
308
309 return new CarrierIdentifier(mcc, mnc, spn, imsi, gid1, gid2);
310 }
311
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700312 /**
313 * Writes a bundle to an XML file.
314 *
315 * The bundle will be written to a file named after the package name and ICCID, so that it can
316 * be restored later with {@link @restoreConfigFromXml}. The XML output will include the bundle
317 * and the current version of the specified package. In case of errors, no file will be written.
318 *
319 * @param packageName the name of the package from which we fetched this bundle.
320 * @param iccid the ICCID of the subscription for which this bundle was fetched.
321 * @param config the bundle to be written.
322 */
323 private void saveConfigToXml(String packageName, String iccid, PersistableBundle config) {
324 final String version = getPackageVersion(packageName);
325 if (version == null) {
326 loge("Failed to get package version for: " + packageName);
327 return;
328 }
329
330 FileOutputStream outFile = null;
331 try {
332 outFile = new FileOutputStream(
333 new File(mContext.getFilesDir(), getFilenameForConfig(packageName, iccid)));
334 FastXmlSerializer out = new FastXmlSerializer();
335 out.setOutput(outFile, "utf-8");
336 out.startDocument("utf-8", true);
337 out.startTag(null, TAG_DOCUMENT);
338 out.startTag(null, TAG_VERSION);
339 out.text(version);
340 out.endTag(null, TAG_VERSION);
341 out.startTag(null, TAG_BUNDLE);
342 config.saveToXml(out);
343 out.endTag(null, TAG_BUNDLE);
344 out.endTag(null, TAG_DOCUMENT);
345 out.endDocument();
346 out.flush();
347 outFile.close();
348 }
349 catch (IOException e) {
350 loge(e.toString());
351 }
352 catch (XmlPullParserException e) {
353 loge(e.toString());
354 }
355 }
356
357 /**
358 * Reads a bundle from an XML file.
359 *
360 * This restores a bundle that was written with {@link #saveConfigToXml}. This returns the saved
361 * config bundle for the given package and ICCID. If the saved config is for a different package
362 * version than the current version, then null will be returned.
363 *
364 * @param packageName the name of the package from which we fetched this bundle.
365 * @param iccid the ICCID of the subscription for which this bundle was fetched.
366 * @return the bundle from the XML file. Returns null if there is no saved config, the saved
367 * version does not match, or reading config fails.
368 */
369 private PersistableBundle restoreConfigFromXml(String packageName, String iccid) {
370 final String version = getPackageVersion(packageName);
371 if (version == null) {
372 loge("Failed to get package version for: " + packageName);
373 return null;
374 }
375
376 PersistableBundle restoredBundle = null;
377 FileInputStream inFile = null;
378 try {
379 inFile = new FileInputStream(
380 new File(mContext.getFilesDir(), getFilenameForConfig(packageName, iccid)));
381 XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
382 parser.setInput(inFile, "utf-8");
383
384 int event;
385 while (((event = parser.next()) != XmlPullParser.END_DOCUMENT)) {
386
387 if (event == XmlPullParser.START_TAG && TAG_VERSION.equals(parser.getName())) {
388 String savedVersion = parser.nextText();
389 if (!version.equals(savedVersion)) {
390 log("Saved version mismatch: " + version + " vs " + savedVersion);
391 break;
392 }
393 }
394
395 if (event == XmlPullParser.START_TAG && TAG_BUNDLE.equals(parser.getName())) {
396 restoredBundle = PersistableBundle.restoreFromXml(parser);
397 }
398 }
399 inFile.close();
400 }
401 catch (FileNotFoundException e) {
402 loge(e.toString());
403 }
404 catch (XmlPullParserException e) {
405 loge(e.toString());
406 }
407 catch (IOException e) {
408 loge(e.toString());
409 }
410
411 return restoredBundle;
412 }
413
414 /** Builds a canonical file name for a config file. */
415 private String getFilenameForConfig(String packageName, String iccid) {
416 return "carrierconfig-" + packageName + "-" + iccid + ".xml";
417 }
418
419 /** Return the current version of a package, or null if the name is not found. */
420 private String getPackageVersion(String packageName) {
421 try {
422 PackageInfo info = mContext.getPackageManager().getPackageInfo(packageName, 0);
423 return info.versionName;
424 } catch (PackageManager.NameNotFoundException e) {
425 return null;
426 }
427 }
428
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800429 @Override
Jonathan Basseri11f89572015-05-05 11:57:39 -0700430 public @NonNull PersistableBundle getConfigForSubId(int subId) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800431 int phoneId = SubscriptionManager.getPhoneId(subId);
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700432 PersistableBundle retConfig = CarrierConfigManager.getDefaultConfig();
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800433 if (SubscriptionManager.isValidPhoneId(phoneId)) {
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700434 PersistableBundle config = mConfigFromDefaultApp[phoneId];
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700435 if (config != null)
436 retConfig.putAll(config);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800437 config = mConfigFromCarrierApp[phoneId];
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700438 if (config != null)
439 retConfig.putAll(config);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800440 }
441 return retConfig;
442 }
443
444 @Override
445 public void reloadCarrierConfigForSubId(int subId) {
446 int phoneId = SubscriptionManager.getPhoneId(subId);
447 if (SubscriptionManager.isValidPhoneId(phoneId)) {
Junda Liu9f2d2712015-05-15 14:22:45 -0700448 mHandler.sendMessage(mHandler.obtainMessage(EVENT_RELOAD_CONFIG, phoneId, -1));
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800449 } else {
450 log("Ignore invalid phoneId: " + phoneId + " for subId: " + subId);
451 }
452 }
453
454 @Override
455 public void updateConfigForPhoneId(int phoneId, String simState) {
456 log("update config for phoneId: " + phoneId + " simState: " + simState);
457 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
458 return;
459 }
460 // requires Java 7 for switch on string.
461 switch (simState) {
462 case IccCardConstants.INTENT_VALUE_ICC_ABSENT:
463 case IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR:
464 case IccCardConstants.INTENT_VALUE_ICC_UNKNOWN:
Junda Liu9f2d2712015-05-15 14:22:45 -0700465 mHandler.sendMessage(mHandler.obtainMessage(EVENT_CLEAR_CONFIG, phoneId, -1));
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800466 break;
467 case IccCardConstants.INTENT_VALUE_ICC_LOADED:
468 case IccCardConstants.INTENT_VALUE_ICC_LOCKED:
Junda Liu9f2d2712015-05-15 14:22:45 -0700469 mHandler.sendMessage(mHandler.obtainMessage(EVENT_UPDATE_CONFIG, phoneId, -1));
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800470 break;
471 }
472 }
473
Junda Liu43d723a2015-05-12 17:23:45 -0700474 @Override
475 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
476 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
477 != PackageManager.PERMISSION_GRANTED) {
478 pw.println("Permission Denial: can't dump carrierconfig from from pid="
479 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
480 return;
481 }
482 pw.println("CarrierConfigLoader: " + this);
483 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
484 pw.println(" Phone Id=" + i);
485 pw.println(" mConfigFromDefaultApp=" + mConfigFromDefaultApp[i]);
486 pw.println(" mConfigFromCarrierApp=" + mConfigFromCarrierApp[i]);
487 }
488 }
489
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800490 private class ConfigServiceConnection implements ServiceConnection {
491 int phoneId;
492 int eventId;
493 IBinder service;
494
495 public ConfigServiceConnection(int phoneId, int eventId) {
496 this.phoneId = phoneId;
497 this.eventId = eventId;
498 }
499
500 @Override
501 public void onServiceConnected(ComponentName name, IBinder service) {
502 log("Connected to config app: " + name.flattenToString());
503 this.service = service;
504 mHandler.sendMessage(mHandler.obtainMessage(eventId, phoneId, -1, this));
505 }
506
507 @Override
508 public void onServiceDisconnected(ComponentName name) {
509 this.service = null;
510 }
511 }
512
513 private class ConfigLoaderBroadcastReceiver extends BroadcastReceiver {
514 @Override
515 public void onReceive(Context context, Intent intent) {
516 String action = intent.getAction();
517 log("Receive action: " + action);
518 }
519 }
520
521 private static void log(String msg) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700522 Log.d(LOG_TAG, msg);
523 }
524
525 private static void loge(String msg) {
526 Log.e(LOG_TAG, msg);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800527 }
528}