[Settings] NullPointerException when disable eSIM/Fi

When disabling eSIM/Fi, CarrierConfig retrieved on that subscription
becomes null and need to perform null pointer checking when accessing
it.

Bug: 149484288
Test: manual
Change-Id: If8a206788407a65c2cb9e5bafe3bc89b93cf63fe
This commit is contained in:
Bonian Chen
2020-02-13 11:56:03 +08:00
parent 9229504fe2
commit 2de00e766d
3 changed files with 49 additions and 15 deletions

View File

@@ -48,8 +48,6 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
@VisibleForTesting @VisibleForTesting
Preference mPreference; Preference mPreference;
private CarrierConfigManager mCarrierConfigManager;
private PersistableBundle mCarrierConfig;
private PhoneCallStateListener mPhoneStateListener; private PhoneCallStateListener mPhoneStateListener;
@VisibleForTesting @VisibleForTesting
Integer mCallState; Integer mCallState;
@@ -63,21 +61,23 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
public Enhanced4gBasePreferenceController(Context context, String key) { public Enhanced4gBasePreferenceController(Context context, String key) {
super(context, key); super(context, key);
mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
m4gLteListeners = new ArrayList<>(); m4gLteListeners = new ArrayList<>();
mPhoneStateListener = new PhoneCallStateListener(); mPhoneStateListener = new PhoneCallStateListener();
} }
public Enhanced4gBasePreferenceController init(int subId) { public Enhanced4gBasePreferenceController init(int subId) {
if (SubscriptionManager.isValidSubscriptionId(mSubId) && mSubId == subId) { if (mSubId == subId) {
return this; return this;
} }
mSubId = subId; mSubId = subId;
mCarrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId); final PersistableBundle carrierConfig = getCarrierConfigForSubId(subId);
if (carrierConfig == null) {
return this;
}
final boolean show4GForLTE = mCarrierConfig.getBoolean( final boolean show4GForLTE = carrierConfig.getBoolean(
CarrierConfigManager.KEY_SHOW_4G_FOR_LTE_DATA_ICON_BOOL); CarrierConfigManager.KEY_SHOW_4G_FOR_LTE_DATA_ICON_BOOL);
m4gCurrentMode = mCarrierConfig.getInt( m4gCurrentMode = carrierConfig.getInt(
CarrierConfigManager.KEY_ENHANCED_4G_LTE_TITLE_VARIANT_INT); CarrierConfigManager.KEY_ENHANCED_4G_LTE_TITLE_VARIANT_INT);
if (m4gCurrentMode != MODE_ADVANCED_CALL) { if (m4gCurrentMode != MODE_ADVANCED_CALL) {
m4gCurrentMode = show4GForLTE ? MODE_4G_CALLING : MODE_VOLTE; m4gCurrentMode = show4GForLTE ? MODE_4G_CALLING : MODE_VOLTE;
@@ -91,10 +91,7 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
if (!isModeMatched()) { if (!isModeMatched()) {
return CONDITIONALLY_UNAVAILABLE; return CONDITIONALLY_UNAVAILABLE;
} }
if (!SubscriptionManager.isValidSubscriptionId(subId)) { final PersistableBundle carrierConfig = getCarrierConfigForSubId(subId);
return CONDITIONALLY_UNAVAILABLE;
}
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(subId);
if ((carrierConfig == null) if ((carrierConfig == null)
|| carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_ENHANCED_4G_LTE_BOOL)) { || carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_ENHANCED_4G_LTE_BOOL)) {
return CONDITIONALLY_UNAVAILABLE; return CONDITIONALLY_UNAVAILABLE;
@@ -103,7 +100,7 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
if (!queryState.isReadyToVoLte()) { if (!queryState.isReadyToVoLte()) {
return CONDITIONALLY_UNAVAILABLE; return CONDITIONALLY_UNAVAILABLE;
} }
return (isUserControlAllowed() && queryState.isAllowUserControl()) return (isUserControlAllowed(carrierConfig) && queryState.isAllowUserControl())
? AVAILABLE : AVAILABLE_UNSEARCHABLE; ? AVAILABLE : AVAILABLE_UNSEARCHABLE;
} }
@@ -129,7 +126,7 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
final SwitchPreference switchPreference = (SwitchPreference) preference; final SwitchPreference switchPreference = (SwitchPreference) preference;
final VolteQueryImsState queryState = queryImsState(mSubId); final VolteQueryImsState queryState = queryImsState(mSubId);
switchPreference.setEnabled(isUserControlAllowed() switchPreference.setEnabled(isUserControlAllowed(getCarrierConfigForSubId(mSubId))
&& queryState.isAllowUserControl()); && queryState.isAllowUserControl());
switchPreference.setChecked(queryState.isEnabledByUser() switchPreference.setChecked(queryState.isEnabledByUser()
&& queryState.isAllowUserControl()); && queryState.isAllowUserControl());
@@ -180,9 +177,10 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
return new VolteQueryImsState(mContext, subId); return new VolteQueryImsState(mContext, subId);
} }
private boolean isUserControlAllowed() { private boolean isUserControlAllowed(final PersistableBundle carrierConfig) {
return (mCallState != null) && (mCallState == TelephonyManager.CALL_STATE_IDLE) return (mCallState != null) && (mCallState == TelephonyManager.CALL_STATE_IDLE)
&& mCarrierConfig.getBoolean( && (carrierConfig != null)
&& carrierConfig.getBoolean(
CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL); CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL);
} }

View File

@@ -17,6 +17,8 @@
package com.android.settings.network.telephony; package com.android.settings.network.telephony;
import android.content.Context; import android.content.Context;
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager;
import com.android.settings.core.BasePreferenceController; import com.android.settings.core.BasePreferenceController;
@@ -37,4 +39,20 @@ public abstract class TelephonyBasePreferenceController extends BasePreferenceCo
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
return MobileNetworkUtils.getAvailability(mContext, mSubId, this::getAvailabilityStatus); return MobileNetworkUtils.getAvailability(mContext, mSubId, this::getAvailabilityStatus);
} }
/**
* Get carrier config based on specific subscription id.
*
* @param subId is the subscription id
* @return {@link PersistableBundle} of carrier config, or {@code null} when carrier config
* is not available.
*/
public PersistableBundle getCarrierConfigForSubId(int subId) {
if (!SubscriptionManager.isValidSubscriptionId(subId)) {
return null;
}
final CarrierConfigManager carrierConfigMgr =
mContext.getSystemService(CarrierConfigManager.class);
return carrierConfigMgr.getConfigForSubId(subId);
}
} }

View File

@@ -17,6 +17,8 @@
package com.android.settings.network.telephony; package com.android.settings.network.telephony;
import android.content.Context; import android.content.Context;
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager;
import com.android.settings.core.TogglePreferenceController; import com.android.settings.core.TogglePreferenceController;
@@ -37,4 +39,20 @@ public abstract class TelephonyTogglePreferenceController extends TogglePreferen
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
return MobileNetworkUtils.getAvailability(mContext, mSubId, this::getAvailabilityStatus); return MobileNetworkUtils.getAvailability(mContext, mSubId, this::getAvailabilityStatus);
} }
/**
* Get carrier config based on specific subscription id.
*
* @param subId is the subscription id
* @return {@link PersistableBundle} of carrier config, or {@code null} when carrier config
* is not available.
*/
public PersistableBundle getCarrierConfigForSubId(int subId) {
if (!SubscriptionManager.isValidSubscriptionId(subId)) {
return null;
}
final CarrierConfigManager carrierConfigMgr =
mContext.getSystemService(CarrierConfigManager.class);
return carrierConfigMgr.getConfigForSubId(subId);
}
} }