1 /* 2 * Copyright (C) 2024 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 17 package com.android.settings.network.telephony 18 19 import android.os.PersistableBundle 20 import android.telephony.CarrierConfigManager 21 import android.telephony.SubscriptionManager 22 import androidx.core.os.persistableBundleOf 23 24 /** 25 * Gets the configuration values of the specified config keys applied. 26 */ CarrierConfigManagernull27fun CarrierConfigManager.safeGetConfig( 28 keys: List<String>, 29 subId: Int = SubscriptionManager.getDefaultSubscriptionId(), 30 ): PersistableBundle = try { 31 getConfigForSubId(subId, *keys.toTypedArray()) 32 } catch (e: IllegalStateException) { 33 // The CarrierConfigLoader (the service implemented the CarrierConfigManager) hasn't been 34 // initialized yet. This may occurs during very early phase of phone booting up or when Phone 35 // process has been restarted. 36 // Settings should not assume Carrier config loader (and any other system services as well) are 37 // always available. If not available, use default value instead. 38 persistableBundleOf() 39 } catch (e: RuntimeException) { 40 // The reason is same with above. 41 persistableBundleOf() 42 } 43