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.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
@@ -40,6 +41,9 @@ import androidx.annotation.VisibleForTesting;
|
|||||||
* for creating dialogs.
|
* for creating dialogs.
|
||||||
*/
|
*/
|
||||||
public final class Utils {
|
public final class Utils {
|
||||||
|
|
||||||
|
private static final String TAG = "BluetoothUtils";
|
||||||
|
|
||||||
static final boolean V = BluetoothUtils.V; // verbose logging
|
static final boolean V = BluetoothUtils.V; // verbose logging
|
||||||
static final boolean D = BluetoothUtils.D; // regular logging
|
static final boolean D = BluetoothUtils.D; // regular logging
|
||||||
|
|
||||||
@@ -107,11 +111,15 @@ public final class Utils {
|
|||||||
String message = context.getString(messageResId, name);
|
String message = context.getString(messageResId, name);
|
||||||
Context activity = manager.getForegroundActivity();
|
Context activity = manager.getForegroundActivity();
|
||||||
if (manager.isForegroundActivity()) {
|
if (manager.isForegroundActivity()) {
|
||||||
new AlertDialog.Builder(activity)
|
try {
|
||||||
.setTitle(R.string.bluetooth_error_title)
|
new AlertDialog.Builder(activity)
|
||||||
.setMessage(message)
|
.setTitle(R.string.bluetooth_error_title)
|
||||||
.setPositiveButton(android.R.string.ok, null)
|
.setMessage(message)
|
||||||
.show();
|
.setPositiveButton(android.R.string.ok, null)
|
||||||
|
.show();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "Cannot show error dialog.", e);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user