summaryrefslogtreecommitdiff
path: root/src/com
diff options
context:
space:
mode:
authorHui Wang <huiwang@google.com>2022-01-12 20:11:46 +0000
committerHui Wang <huiwang@google.com>2022-02-01 19:36:01 +0000
commit9beb2691d9507aff2e6eab2f1fcb9fafe12be070 (patch)
tree2b55a761a8085106f22cbe2dbd21a216a77cfee3 /src/com
parent612b3e1a1f5a6c59798dbfe9480de7144932608d (diff)
downloadCellBroadcastReceiver-9beb2691d9507aff2e6eab2f1fcb9fafe12be070.tar.gz
Cache the resources when the mnc of the configuration is not zero
Checking the sim loaded is not used properly for the resources caching. The resources per the mcc and mnc can also be ready before sim loaded. In this case, the mnc of the configuration from the resource is not 0. Bug: 214250834 Test: atest CellBroadcastReceiverUnitTests Change-Id: I15d6fe9d2e50c06d17fd8602b67bc9ddc5affb9c
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java20
1 files changed, 7 insertions, 13 deletions
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java b/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java
index dd6291f03..f4fe98d17 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java
@@ -33,7 +33,6 @@ import android.os.Bundle;
import android.os.UserManager;
import android.os.Vibrator;
import android.telephony.SubscriptionManager;
-import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.MenuItem;
import android.widget.Switch;
@@ -881,17 +880,8 @@ public class CellBroadcastSettings extends CollapsingToolbarBaseActivity {
*/
public static @NonNull Resources getResources(@NonNull Context context, int subId) {
- try {
- if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID
- || !SubscriptionManager.isValidSubscriptionId(subId)
- // per the latest design, subId can be valid earlier than mcc mnc is known to
- // telephony. check if sim is loaded to avoid caching the wrong resources.
- || context.getSystemService(TelephonyManager.class).getSimApplicationState(
- SubscriptionManager.getSlotIndex(subId)) != TelephonyManager.SIM_STATE_LOADED) {
- return context.getResources();
- }
- } catch (Exception e) {
- Log.d(TAG, "Fail to getSimApplicationState due to " + e);
+ if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID
+ || !SubscriptionManager.isValidSubscriptionId(subId)) {
return context.getResources();
}
@@ -902,7 +892,11 @@ public class CellBroadcastSettings extends CollapsingToolbarBaseActivity {
Resources res = SubscriptionManager.getResourcesForSubId(context, subId);
- sResourcesCache.put(subId, res);
+ if (res.getConfiguration().mnc != 0) {
+ Log.d(TAG, "Cache resource for sub: " + subId + ", mcc: "
+ + res.getConfiguration().mcc + ", mnc:" + res.getConfiguration().mnc);
+ sResourcesCache.put(subId, res);
+ }
return res;
}