[Settings] Avoid settings crash from NPE of TelephonyManager.

Bug: 233783567
Test: atest passed
Change-Id: Ie0ed8fa3b87b8e130396cf4d918295403ae43501
This commit is contained in:
tom hsu
2023-05-25 22:29:55 +08:00
committed by Tom Hsu
parent 59ec10b05a
commit 06c3ae5e82

View File

@@ -21,6 +21,7 @@ import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.Log;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
@@ -34,6 +35,7 @@ import com.android.settings.network.telephony.TelephonyConstants.TelephonyManage
*/
public class PreferredNetworkModePreferenceController extends TelephonyBasePreferenceController
implements ListPreference.OnPreferenceChangeListener {
private static final String TAG = "PrefNetworkModeCtrl";
private CarrierConfigCache mCarrierConfigCache;
private TelephonyManager mTelephonyManager;
@@ -99,6 +101,10 @@ public class PreferredNetworkModePreferenceController extends TelephonyBasePrefe
}
private int getPreferredNetworkMode() {
if (mTelephonyManager == null) {
Log.w(TAG, "TelephonyManager is null");
return TelephonyManagerConstants.NETWORK_MODE_UNKNOWN;
}
return MobileNetworkUtils.getNetworkTypeFromRaf(
(int) mTelephonyManager.getAllowedNetworkTypesForReason(
TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER));