[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:
@@ -48,8 +48,6 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
|
||||
|
||||
@VisibleForTesting
|
||||
Preference mPreference;
|
||||
private CarrierConfigManager mCarrierConfigManager;
|
||||
private PersistableBundle mCarrierConfig;
|
||||
private PhoneCallStateListener mPhoneStateListener;
|
||||
@VisibleForTesting
|
||||
Integer mCallState;
|
||||
@@ -63,21 +61,23 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
|
||||
|
||||
public Enhanced4gBasePreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
|
||||
m4gLteListeners = new ArrayList<>();
|
||||
mPhoneStateListener = new PhoneCallStateListener();
|
||||
}
|
||||
|
||||
public Enhanced4gBasePreferenceController init(int subId) {
|
||||
if (SubscriptionManager.isValidSubscriptionId(mSubId) && mSubId == subId) {
|
||||
if (mSubId == subId) {
|
||||
return this;
|
||||
}
|
||||
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);
|
||||
m4gCurrentMode = mCarrierConfig.getInt(
|
||||
m4gCurrentMode = carrierConfig.getInt(
|
||||
CarrierConfigManager.KEY_ENHANCED_4G_LTE_TITLE_VARIANT_INT);
|
||||
if (m4gCurrentMode != MODE_ADVANCED_CALL) {
|
||||
m4gCurrentMode = show4GForLTE ? MODE_4G_CALLING : MODE_VOLTE;
|
||||
@@ -91,10 +91,7 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
|
||||
if (!isModeMatched()) {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
if (!SubscriptionManager.isValidSubscriptionId(subId)) {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(subId);
|
||||
final PersistableBundle carrierConfig = getCarrierConfigForSubId(subId);
|
||||
if ((carrierConfig == null)
|
||||
|| carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_ENHANCED_4G_LTE_BOOL)) {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
@@ -103,7 +100,7 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
|
||||
if (!queryState.isReadyToVoLte()) {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
return (isUserControlAllowed() && queryState.isAllowUserControl())
|
||||
return (isUserControlAllowed(carrierConfig) && queryState.isAllowUserControl())
|
||||
? AVAILABLE : AVAILABLE_UNSEARCHABLE;
|
||||
}
|
||||
|
||||
@@ -129,7 +126,7 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
|
||||
final SwitchPreference switchPreference = (SwitchPreference) preference;
|
||||
|
||||
final VolteQueryImsState queryState = queryImsState(mSubId);
|
||||
switchPreference.setEnabled(isUserControlAllowed()
|
||||
switchPreference.setEnabled(isUserControlAllowed(getCarrierConfigForSubId(mSubId))
|
||||
&& queryState.isAllowUserControl());
|
||||
switchPreference.setChecked(queryState.isEnabledByUser()
|
||||
&& queryState.isAllowUserControl());
|
||||
@@ -180,9 +177,10 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
|
||||
return new VolteQueryImsState(mContext, subId);
|
||||
}
|
||||
|
||||
private boolean isUserControlAllowed() {
|
||||
private boolean isUserControlAllowed(final PersistableBundle carrierConfig) {
|
||||
return (mCallState != null) && (mCallState == TelephonyManager.CALL_STATE_IDLE)
|
||||
&& mCarrierConfig.getBoolean(
|
||||
&& (carrierConfig != null)
|
||||
&& carrierConfig.getBoolean(
|
||||
CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL);
|
||||
}
|
||||
|
||||
|
@@ -17,6 +17,8 @@
|
||||
package com.android.settings.network.telephony;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.PersistableBundle;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
import android.telephony.SubscriptionManager;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
@@ -37,4 +39,20 @@ public abstract class TelephonyBasePreferenceController extends BasePreferenceCo
|
||||
public int 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);
|
||||
}
|
||||
}
|
||||
|
@@ -17,6 +17,8 @@
|
||||
package com.android.settings.network.telephony;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.PersistableBundle;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
import android.telephony.SubscriptionManager;
|
||||
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
@@ -37,4 +39,20 @@ public abstract class TelephonyTogglePreferenceController extends TogglePreferen
|
||||
public int 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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user