Add NPE check when showing error dialog.
Add NPE check when showing error dialog Bug: 110263996 Test: make -j42 RunSettingsRoboTests ROBOTEST_FILTER=UtilsTest Change-Id: I93d6c662ea7031a631ac8c2c33cacc974677c3d7
This commit is contained in:
@@ -22,6 +22,7 @@ import android.bluetooth.BluetoothProfile;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
@@ -40,6 +41,9 @@ import androidx.annotation.VisibleForTesting;
|
||||
* for creating dialogs.
|
||||
*/
|
||||
public final class Utils {
|
||||
|
||||
private static final String TAG = "BluetoothUtils";
|
||||
|
||||
static final boolean V = BluetoothUtils.V; // verbose logging
|
||||
static final boolean D = BluetoothUtils.D; // regular logging
|
||||
|
||||
@@ -107,11 +111,15 @@ public final class Utils {
|
||||
String message = context.getString(messageResId, name);
|
||||
Context activity = manager.getForegroundActivity();
|
||||
if (manager.isForegroundActivity()) {
|
||||
new AlertDialog.Builder(activity)
|
||||
.setTitle(R.string.bluetooth_error_title)
|
||||
.setMessage(message)
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.show();
|
||||
try {
|
||||
new AlertDialog.Builder(activity)
|
||||
.setTitle(R.string.bluetooth_error_title)
|
||||
.setMessage(message)
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.show();
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Cannot show error dialog.", e);
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
Reference in New Issue
Block a user