ForgetDeviceDialogFragment check whether device is null or not

Bug: 280687867
Test: build pass
Change-Id: I4134569854165f20f6287406d9ed627b2c15c05b
This commit is contained in:
SongFerngWang
2023-06-06 14:08:44 +08:00
committed by SongFerng Wang
parent 0741621536
commit 13cd052693

View File

@@ -23,6 +23,7 @@ import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AlertDialog;
@@ -63,6 +64,13 @@ public class ForgetDeviceDialogFragment extends InstrumentedDialogFragment {
@Override
public Dialog onCreateDialog(Bundle inState) {
Context context = getContext();
mDevice = getDevice(context);
if (mDevice == null) {
Log.e(TAG, "onCreateDialog: Device is null.");
return null;
}
DialogInterface.OnClickListener onConfirm = (dialog, which) -> {
mDevice.unpair();
Activity activity = getActivity();
@@ -70,9 +78,6 @@ public class ForgetDeviceDialogFragment extends InstrumentedDialogFragment {
activity.finish();
}
};
Context context = getContext();
mDevice = getDevice(context);
AlertDialog dialog = new AlertDialog.Builder(context)
.setPositiveButton(R.string.bluetooth_unpair_dialog_forget_confirm_button,
onConfirm)