If unregister fails we should log but not crash

Stephen Paul Weber created

Often this isn't even needed since most contact removals are not of a PSTN
gateway.  Worst case they end up with an extra phone account in system, but if
we can't remove probably it's not there or owned by us anyway.

Change summary

src/main/java/eu/siacs/conversations/entities/Contact.java | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

Detailed changes

src/main/java/eu/siacs/conversations/entities/Contact.java 🔗

@@ -13,6 +13,7 @@ import android.telecom.PhoneAccount;
 import android.telecom.PhoneAccountHandle;
 import android.telecom.TelecomManager;
 import android.text.TextUtils;
+import android.util.Log;
 
 import androidx.annotation.NonNull;
 
@@ -687,7 +688,12 @@ public class Contact implements ListItem, Blockable {
         }
 
         TelecomManager telecomManager = ctx.getSystemService(TelecomManager.class);
-        telecomManager.unregisterPhoneAccount(phoneAccountHandle());
+
+        try {
+            telecomManager.unregisterPhoneAccount(phoneAccountHandle());
+        } catch (final SecurityException e) {
+            Log.w(Config.LOGTAG, "Could not unregister " + getJid() + " as phone account: " + e);
+        }
     }
 
     public static int getOption(Class<? extends AbstractPhoneContact> clazz) {