Data only device(without FEATURE_TELEPHON_CALLING) : Add try/catch to handle UnsupportedOperationException

If the device does not have Telephony feature calling, the some of interfaces in TelephonyManager throw UnsupportedOperationException.

Bug: 297989574
Test: oriole with ATT SIM, boot completed
      APM/data/wifi on/off, browse setting menu
Change-Id: Ifa9092cd8d9a00039e9d93d5fd9fc4dabed633c8
This commit is contained in:
joonhunshin
2023-12-01 08:25:58 +00:00
parent 0756dc37bb
commit 37d4fb736e
6 changed files with 83 additions and 11 deletions

View File

@@ -29,6 +29,7 @@ import android.util.Log;
import androidx.annotation.VisibleForTesting;
import com.android.internal.telephony.flags.Flags;
import com.android.settings.network.GlobalSettingsChangeListener;
import com.android.settings.network.ProxySubscriptionManager;
import com.android.settings.overlay.FeatureFactory;
@@ -146,8 +147,19 @@ public class AirplaneModeEnabler extends GlobalSettingsChangeListener {
* @return any subscription within device is under ECM mode
*/
public boolean isInEcmMode() {
if (mTelephonyManager.getEmergencyCallbackMode()) {
return true;
if (Flags.enforceTelephonyFeatureMappingForPublicApis()) {
try {
if (mTelephonyManager.getEmergencyCallbackMode()) {
return true;
}
} catch (UnsupportedOperationException e) {
// Device doesn't support FEATURE_TELEPHONY_CALLING
// Ignore exception, device is not in ECM mode.
}
} else {
if (mTelephonyManager.getEmergencyCallbackMode()) {
return true;
}
}
final List<SubscriptionInfo> subInfoList =
ProxySubscriptionManager.getInstance(mContext).getActiveSubscriptionsInfo();
@@ -158,8 +170,18 @@ public class AirplaneModeEnabler extends GlobalSettingsChangeListener {
final TelephonyManager telephonyManager =
mTelephonyManager.createForSubscriptionId(subInfo.getSubscriptionId());
if (telephonyManager != null) {
if (telephonyManager.getEmergencyCallbackMode()) {
return true;
if (!Flags.enforceTelephonyFeatureMappingForPublicApis()) {
if (telephonyManager.getEmergencyCallbackMode()) {
return true;
}
} else {
try {
if (telephonyManager.getEmergencyCallbackMode()) {
return true;
}
} catch (UnsupportedOperationException e) {
// Ignore exception, device is not in ECM mode.
}
}
}
}