Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1a311f71 authored by Marie Janssen's avatar Marie Janssen
Browse files

Check exception to prevent crash on invalid URIs

Previously if an invalid URI for a notification is received,
Bluetooth crashed.

Bug: 28940687
Change-Id: I54e17b7180e770bb8a5cf48c3d4b2a35657cb67f
parent e1f09cb4
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -285,9 +285,17 @@ public class BluetoothOppReceiver extends BroadcastReceiver {
    private void cancelNotification(Context context, Uri uri) {
        NotificationManager notMgr = (NotificationManager)context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        if (notMgr != null) {
            notMgr.cancel((int)ContentUris.parseId(uri));
            if (V) Log.v(TAG, "notMgr.cancel called");
        if (notMgr == null) return;

        int id = -1;
        try {
          id = (int) ContentUris.parseId(uri);
        } catch (NumberFormatException ex) {
          Log.v(TAG, "Can't parse notification ID from Uri!");
          return;
        }

        notMgr.cancel(id);
        if (V) Log.v(TAG, "notMgr.cancel called");
    }
}