Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5a3ba387 authored by Tomasz Wasilczyk's avatar Tomasz Wasilczyk
Browse files

Fix UiccController crash due to inconsistent phone count

Using TelephonyManager.getDefault() causes mContext to be null, which
makes getPhoneCount quietly fall back to default values. This makes it
return sometimes 0, sometimes 1, depending on whether the calling code
used TelephonyManager.getDefault() or TelephonyManager.from(Context).

Bug: 404627136
Flag: EXEMPT bugfix
Test: boot gcar_x86_64-trunk_staging-userdebug and observe NPEs in logcat
Change-Id: Ibf87e7cac9595d87ac593d581928b3863953a274
parent ac903221
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1665,7 +1665,7 @@ public class UiccController extends Handler {
    }

    private boolean isValidPhoneIndex(int index) {
        return (index >= 0 && index < TelephonyManager.getDefault().getPhoneCount());
        return (index >= 0 && index < mTelephonyManager.getActiveModemCount());
    }

    private boolean isValidSlotIndex(int index) {
@@ -1673,7 +1673,7 @@ public class UiccController extends Handler {
    }

    private boolean isShuttingDown() {
        for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
        for (int i = 0; i < mTelephonyManager.getActiveModemCount(); i++) {
            if (PhoneFactory.getPhone(i) != null &&
                    PhoneFactory.getPhone(i).isShuttingDown()) {
                return true;