Fix crash when showing the device not found dialog.

If users click to pair a not foundable device and then close the Settings page,
Settings will crash becasue dialog holder is closed.
This CL is part of the fix. It set the context to null when the activity
stops.

Bug: 306548036
Test: atest
Change-Id: If68e3e9cd62216ad83b2e5058f504fce35e36a06
This commit is contained in:
Yiyi Shen
2023-10-23 15:51:54 +08:00
parent 8e38bd0b3a
commit a7d0d00f4a
3 changed files with 15 additions and 25 deletions

View File

@@ -91,6 +91,7 @@ public class FastPairDevicePreferenceController extends BasePreferenceController
@Override
public void onStart(@NonNull LifecycleOwner owner) {
if (mFastPairDeviceUpdater != null) {
mFastPairDeviceUpdater.setPreferenceContext(mContext);
mFastPairDeviceUpdater.registerCallback();
} else {
if (DEBUG) {
@@ -103,6 +104,7 @@ public class FastPairDevicePreferenceController extends BasePreferenceController
@Override
public void onStop(@NonNull LifecycleOwner owner) {
if (mFastPairDeviceUpdater != null) {
mFastPairDeviceUpdater.setPreferenceContext(null);
mFastPairDeviceUpdater.unregisterCallback();
} else {
if (DEBUG) {
@@ -118,7 +120,6 @@ public class FastPairDevicePreferenceController extends BasePreferenceController
mPreferenceGroup = screen.findPreference(getPreferenceKey());
mSeeAllPreference = mPreferenceGroup.findPreference(KEY_SEE_ALL);
updatePreferenceVisibility();
if (isAvailable()) {
final Context context = screen.getContext();
mFastPairDeviceUpdater.setPreferenceContext(context);