Merge "Fix NPE crash in UwbPreferenceController and optimize the lifecycle observer adding condition in page" am: b2a466d92f
am: a9c6040eb8
am: d24f4a3f54
am: 41fc3efd4c
Original change: https://android-review.googlesource.com/c/platform/packages/apps/Settings/+/2206258 Change-Id: I8f3a0597e938b3d1fd1a3e87a89f95834716c16d Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -69,8 +69,12 @@ public class AdvancedConnectedDeviceDashboardFragment extends DashboardFragment
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
UwbPreferenceController uwbPreferenceController = use(UwbPreferenceController.class);
|
||||
if (uwbPreferenceController != null && getSettingsLifecycle() != null) {
|
||||
getSettingsLifecycle().addObserver(uwbPreferenceController);
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user