1 /* 2 * Copyright (C) 2020 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; 18 19 import android.content.BroadcastReceiver; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.content.IntentFilter; 23 import android.telephony.CarrierConfigManager; 24 import android.util.Log; 25 26 import java.util.concurrent.CountDownLatch; 27 28 /** A receiver listens to the carrier config changes. */ 29 public class CarrierConfigChangedReceiver extends BroadcastReceiver { 30 private static final String TAG = "CarrierConfigChangedReceiver"; 31 private static final String ACTION_CARRIER_CONFIG_CHANGED = 32 CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED; 33 34 private final CountDownLatch mLatch; 35 CarrierConfigChangedReceiver(CountDownLatch latch)36 public CarrierConfigChangedReceiver(CountDownLatch latch) { 37 mLatch = latch; 38 } 39 registerOn(Context context)40 public void registerOn(Context context) { 41 context.registerReceiver(this, new IntentFilter(ACTION_CARRIER_CONFIG_CHANGED), 42 Context.RECEIVER_EXPORTED/*UNAUDITED*/); 43 } 44 45 @Override onReceive(Context context, Intent intent)46 public void onReceive(Context context, Intent intent) { 47 if (isInitialStickyBroadcast()) { 48 return; 49 } 50 51 if (ACTION_CARRIER_CONFIG_CHANGED.equals(intent.getAction())) { 52 checkSubscriptionIndex(intent); 53 } 54 } 55 checkSubscriptionIndex(Intent intent)56 private void checkSubscriptionIndex(Intent intent) { 57 if (intent.hasExtra(CarrierConfigManager.EXTRA_SUBSCRIPTION_INDEX)) { 58 int subId = intent.getIntExtra(CarrierConfigManager.EXTRA_SUBSCRIPTION_INDEX, -1); 59 Log.i(TAG, "subId from config changed: " + subId); 60 mLatch.countDown(); 61 } 62 } 63 } 64