• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     }
43 
44     @Override
onReceive(Context context, Intent intent)45     public void onReceive(Context context, Intent intent) {
46         if (isInitialStickyBroadcast()) {
47             return;
48         }
49 
50         if (ACTION_CARRIER_CONFIG_CHANGED.equals(intent.getAction())) {
51             checkSubscriptionIndex(intent);
52         }
53     }
54 
checkSubscriptionIndex(Intent intent)55     private void checkSubscriptionIndex(Intent intent) {
56         if (intent.hasExtra(CarrierConfigManager.EXTRA_SUBSCRIPTION_INDEX)) {
57             int subId = intent.getIntExtra(CarrierConfigManager.EXTRA_SUBSCRIPTION_INDEX, -1);
58             Log.i(TAG, "subId from config changed: " + subId);
59             mLatch.countDown();
60         }
61     }
62 }
63