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

Commit b731e630 authored by Chaohui Wang's avatar Chaohui Wang
Browse files

Check isSimHardwareVisible earlier

In SimEidPreferenceController, to reduce flaky on no SIM devices.

Bug: 304560734
Test: manual - on "About phone / tablet" page
Test: unit test
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:8b7e6c28bcef0788b4fc637af16dcaef32a16c14)
Merged-In: I07ae9b785d0fbe24a866883080a466a2110ca68f
Change-Id: I07ae9b785d0fbe24a866883080a466a2110ca68f
parent d3cc9b20
Loading
Loading
Loading
Loading
+8 −11
Original line number Diff line number Diff line
@@ -59,11 +59,13 @@ class SimEidPreferenceController(context: Context, preferenceKey: String) :
    }

    /**
     * Returns available here, but UI availability is retrieved asynchronously later.
     * Returns available here, if SIM hardware is visible.
     *
     * Check [updateNonIndexableKeys] for search availability.
     * Also check [getIsAvailableAndUpdateEid] for other availability check which retrieved
     * asynchronously later.
     */
    override fun getAvailabilityStatus() = AVAILABLE
    override fun getAvailabilityStatus() =
        if (SubscriptionUtil.isSimHardwareVisible(mContext)) AVAILABLE else UNSUPPORTED_ON_DEVICE

    override fun displayPreference(screen: PreferenceScreen) {
        super.displayPreference(screen)
@@ -95,12 +97,7 @@ class SimEidPreferenceController(context: Context, preferenceKey: String) :
    }

    private fun getIsAvailableAndUpdateEid(): Boolean {
        if (!SubscriptionUtil.isSimHardwareVisible(mContext) ||
            !mContext.userManager.isAdminUser ||
            Utils.isWifiOnly(mContext)
        ) {
            return false
        }
        if (!mContext.userManager.isAdminUser || Utils.isWifiOnly(mContext)) return false
        eid = eidStatus?.eid ?: ""
        return eid.isNotEmpty()
    }
@@ -147,8 +144,8 @@ class SimEidPreferenceController(context: Context, preferenceKey: String) :
    }

    override fun updateNonIndexableKeys(keys: MutableList<String>) {
        if (!getIsAvailableAndUpdateEid()) {
            keys.add(preferenceKey)
        if (!isAvailable() || !getIsAvailableAndUpdateEid()) {
            keys += preferenceKey
        }
    }