Fix Settings Crash

TelephonyManager modify getAllowedCarriers api, cause Setting crash.
Add try catch to avoid the issue.

Bug: 335751239
Change-Id: I5777c92f8eaf44413f60002e746e9969b3bd9f0d
Test: manual test
This commit is contained in:
Edgar Wang
2024-04-22 08:35:43 +00:00
parent 2ecc77ef08
commit 59cb0e1b30

View File

@@ -21,6 +21,7 @@ import static com.android.settings.development.DevelopmentOptionsActivityRequest
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.os.SystemProperties;
import android.os.UserHandle;
@@ -176,6 +177,13 @@ public class OemUnlockPreferenceController extends DeveloperOptionsPreferenceCon
/** Returns {@code true} if the device is SIM-locked. Otherwise, returns {@code false}. */
private boolean isSimLockedDevice() {
if (!mContext.getPackageManager().hasSystemFeature(
PackageManager.FEATURE_TELEPHONY_CARRIERLOCK)) {
Log.w(TAG,
"getAllowedCarriers is unsupported without "
+ "PackageManager#FEATURE_TELEPHONY_CARRIERLOCK");
return false;
}
int phoneCount = mTelephonyManager.getPhoneCount();
for (int i = 0; i < phoneCount; i++) {
if (mTelephonyManager.getAllowedCarriers(i).size() > 0) {