Fix issue where device does not create any phone accounts.
A code change was recently made to TelecomAccountRegistry which made it
possible for the emergency-only phone account to NOT be added.
Hard-wiring setupAccounts in this manner is not correct as the method has
a check at the end to see if the dfeault account should be added.
I've corrected the method short-circuit potentials and also move the
creation of the default emergency-only phone account into a finally
block to ensure coding errors (or crashes for that matter) in the main
loop will not cause a situation where there is no emergency call acct.
Test: Removed sim, rebooted and noted that the default account is created.
Test: Removed and replaced sim numerous times and noted that the correct
default emergency and regular phone accounts are created.
Bug: 126214468
Merged-In: Iaef69a5331078a9f848cc00e7e98e46b3a8862a6
Change-Id: Iaef69a5331078a9f848cc00e7e98e46b3a8862a6
diff --git a/src/com/android/services/telephony/TelecomAccountRegistry.java b/src/com/android/services/telephony/TelecomAccountRegistry.java
index 3505fe7..6bbcdc4 100644
--- a/src/com/android/services/telephony/TelecomAccountRegistry.java
+++ b/src/com/android/services/telephony/TelecomAccountRegistry.java
@@ -790,6 +790,7 @@
@Override
public void onSubscriptionsChanged() {
// Any time the SubscriptionInfo changes...rerun the setup
+ Log.i(this, "onSubscriptionsChanged - update accounts");
tearDownAccounts();
setupAccounts();
}
@@ -1146,37 +1147,48 @@
// Go through SIM-based phones and register ourselves -- registering an existing account
// will cause the existing entry to be replaced.
Phone[] phones = PhoneFactory.getPhones();
- Log.d(this, "Found %d phones. Attempting to register.", phones.length);
+ Log.i(this, "setupAccounts: Found %d phones. Attempting to register.", phones.length);
final boolean phoneAccountsEnabled = mContext.getResources().getBoolean(
R.bool.config_pstn_phone_accounts_enabled);
synchronized (mAccountsLock) {
- if (phoneAccountsEnabled) {
- for (Phone phone : phones) {
- int subscriptionId = phone.getSubId();
- Log.d(this, "Phone with subscription id %d", subscriptionId);
- // setupAccounts can be called multiple times during service changes. Don't add an
- // account if the Icc has not been set yet.
- if (!SubscriptionManager.isValidSubscriptionId(subscriptionId)
- || phone.getFullIccSerialNumber() == null) return;
- // Don't add account if it's opportunistic subscription, which is considered
- // data only for now.
- SubscriptionInfo info = SubscriptionManager.from(mContext)
- .getActiveSubscriptionInfo(subscriptionId);
- if (info == null || info.isOpportunistic()) return;
+ try {
+ if (phoneAccountsEnabled) {
+ for (Phone phone : phones) {
+ int subscriptionId = phone.getSubId();
+ Log.i(this, "setupAccounts: Phone with subscription id %d", subscriptionId);
+ // setupAccounts can be called multiple times during service changes.
+ // Don't add an account if the Icc has not been set yet.
+ if (!SubscriptionManager.isValidSubscriptionId(subscriptionId)
+ || phone.getFullIccSerialNumber() == null) {
+ Log.d(this, "setupAccounts: skipping invalid subid %d", subscriptionId);
+ continue;
+ }
+ // Don't add account if it's opportunistic subscription, which is considered
+ // data only for now.
+ SubscriptionInfo info = SubscriptionManager.from(mContext)
+ .getActiveSubscriptionInfo(subscriptionId);
+ if (info == null || info.isOpportunistic()) {
+ Log.d(this, "setupAccounts: skipping unknown or opportunistic subid %d",
+ subscriptionId);
+ continue;
+ }
- mAccounts.add(new AccountEntry(phone, false /* emergency */,
- false /* isDummy */));
+ mAccounts.add(new AccountEntry(phone, false /* emergency */,
+ false /* isDummy */));
+ }
}
- }
-
- // If we did not list ANY accounts, we need to provide a "default" SIM account
- // for emergency numbers since no actual SIM is needed for dialing emergency
- // numbers but a phone account is.
- if (mAccounts.isEmpty()) {
- mAccounts.add(new AccountEntry(PhoneFactory.getDefaultPhone(), true /* emergency */,
- false /* isDummy */));
+ } finally {
+ // If we did not list ANY accounts, we need to provide a "default" SIM account
+ // for emergency numbers since no actual SIM is needed for dialing emergency
+ // numbers but a phone account is.
+ if (mAccounts.isEmpty()) {
+ Log.i(this, "setupAccounts: adding default");
+ mAccounts.add(
+ new AccountEntry(PhoneFactory.getDefaultPhone(), true /* emergency */,
+ false /* isDummy */));
+ }
}
// Add a fake account entry.