• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.systemui.util;
18 
19 import android.content.BroadcastReceiver;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.content.IntentFilter;
23 import android.os.PersistableBundle;
24 import android.telephony.CarrierConfigManager;
25 import android.telephony.SubscriptionManager;
26 import android.util.SparseArray;
27 
28 import com.android.systemui.dagger.SysUISingleton;
29 
30 import javax.inject.Inject;
31 
32 /**
33  * Tracks the Carrier Config values.
34  */
35 @SysUISingleton
36 public class CarrierConfigTracker extends BroadcastReceiver {
37     private final SparseArray<Boolean> mCallStrengthConfigs = new SparseArray<>();
38     private final SparseArray<Boolean> mNoCallingConfigs = new SparseArray<>();
39     private final CarrierConfigManager mCarrierConfigManager;
40     private boolean mDefaultCallStrengthConfigLoaded;
41     private boolean mDefaultCallStrengthConfig;
42     private boolean mDefaultNoCallingConfigLoaded;
43     private boolean mDefaultNoCallingConfig;
44 
45     @Inject
CarrierConfigTracker(Context context)46     public CarrierConfigTracker(Context context) {
47         mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
48         context.registerReceiver(
49                 this, new IntentFilter(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED));
50     }
51 
52     @Override
onReceive(Context context, Intent intent)53     public void onReceive(Context context, Intent intent) {
54         if (intent.getAction() == CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED) {
55             int subId = intent.getIntExtra(
56                     CarrierConfigManager.EXTRA_SUBSCRIPTION_INDEX,
57                     SubscriptionManager.INVALID_SUBSCRIPTION_ID);
58             if (!SubscriptionManager.isValidSubscriptionId(subId)) {
59                 return;
60             }
61             PersistableBundle b = mCarrierConfigManager.getConfigForSubId(subId);
62             if (b != null) {
63                 boolean hideNoCallingConfig = b.getBoolean(
64                         CarrierConfigManager.KEY_USE_IP_FOR_CALLING_INDICATOR_BOOL);
65                 boolean displayCallStrengthIcon = b.getBoolean(
66                         CarrierConfigManager.KEY_DISPLAY_CALL_STRENGTH_INDICATOR_BOOL);
67                 mCallStrengthConfigs.put(subId, displayCallStrengthIcon);
68                 mNoCallingConfigs.put(subId, hideNoCallingConfig);
69             }
70         }
71     }
72 
73     /**
74      * Returns the KEY_DISPLAY_CALL_STRENGTH_INDICATOR_BOOL value for the given subId.
75      */
getCallStrengthConfig(int subId)76     public boolean getCallStrengthConfig(int subId) {
77         if (mCallStrengthConfigs.indexOfKey(subId) >= 0) {
78             return mCallStrengthConfigs.get(subId);
79         }
80         if (!mDefaultCallStrengthConfigLoaded) {
81             mDefaultCallStrengthConfig =
82                     CarrierConfigManager.getDefaultConfig().getBoolean(
83                             CarrierConfigManager.KEY_DISPLAY_CALL_STRENGTH_INDICATOR_BOOL);
84             mDefaultCallStrengthConfigLoaded = true;
85         }
86         return mDefaultCallStrengthConfig;
87     }
88 
89     /**
90      * Returns the KEY_USE_IP_FOR_CALLING_INDICATOR_BOOL value for the given subId.
91      */
getNoCallingConfig(int subId)92     public boolean getNoCallingConfig(int subId) {
93         if (mNoCallingConfigs.indexOfKey(subId) >= 0) {
94             return mNoCallingConfigs.get(subId);
95         }
96         if (!mDefaultNoCallingConfigLoaded) {
97             mDefaultNoCallingConfig =
98                     CarrierConfigManager.getDefaultConfig().getBoolean(
99                             CarrierConfigManager.KEY_USE_IP_FOR_CALLING_INDICATOR_BOOL);
100             mDefaultNoCallingConfigLoaded = true;
101         }
102         return mDefaultNoCallingConfig;
103     }
104 }
105