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

Commit b2a466d9 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Fix NPE crash in UwbPreferenceController and optimize the lifecycle...

Merge "Fix NPE crash in UwbPreferenceController and optimize the lifecycle observer adding condition in page"
parents a512817a 0b9a6304
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -69,10 +69,14 @@ public class AdvancedConnectedDeviceDashboardFragment extends DashboardFragment
    public void onAttach(Context context) {
        super.onAttach(context);
        UwbPreferenceController uwbPreferenceController = use(UwbPreferenceController.class);
        if (uwbPreferenceController != null && getSettingsLifecycle() != null) {
        // We only need the observer listen to the broadcast in the background for refreshing
        // UI if the device supports UWB.
        if (uwbPreferenceController != null && uwbPreferenceController.isUwbSupportedOnDevice()) {
            if (getSettingsLifecycle() != null) {
                getSettingsLifecycle().addObserver(uwbPreferenceController);
            }
        }
    }

    @Override
    protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
+4 −2
Original line number Diff line number Diff line
@@ -75,8 +75,7 @@ public class UwbPreferenceController extends TogglePreferenceController implemen
        };
    }

    @VisibleForTesting
    boolean isUwbSupportedOnDevice() {
    public boolean isUwbSupportedOnDevice() {
        return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_UWB);
    }

@@ -99,6 +98,9 @@ public class UwbPreferenceController extends TogglePreferenceController implemen

    @Override
    public boolean isChecked() {
        if (!isUwbSupportedOnDevice()) {
            return false;
        }
        int state = mUwbManager.getAdapterState();
        return state == STATE_ENABLED_ACTIVE || state == STATE_ENABLED_INACTIVE;
    }