private void handleSendMessage(MasterSecret masterSecret, Intent intent) { long messageId = intent.getLongExtra("message_id", -1); UniversalTransport transport = new UniversalTransport(context, masterSecret); EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context); EncryptingSmsDatabase.Reader reader = null; SmsMessageRecord record; Log.w("SmsSender", "Sending message: " + messageId); try { if (messageId != -1) reader = database.getMessage(masterSecret, messageId); else reader = database.getOutgoingMessages(masterSecret); while (reader != null && (record = reader.getNext()) != null) { try { database.markAsSending(record.getId()); transport.deliver(record); } catch (UntrustedIdentityException e) { Log.w("SmsSender", e); IncomingIdentityUpdateMessage identityUpdateMessage = IncomingIdentityUpdateMessage.createFor(e.getE164Number(), e.getIdentityKey()); DatabaseFactory.getEncryptingSmsDatabase(context) .insertMessageInbox(masterSecret, identityUpdateMessage); DatabaseFactory.getSmsDatabase(context).markAsSentFailed(messageId); } catch (UndeliverableMessageException ude) { Log.w("SmsSender", ude); DatabaseFactory.getSmsDatabase(context).markAsSentFailed(messageId); } catch (RetryLaterException rle) { Log.w("SmsSender", rle); if (systemStateListener.isConnected()) scheduleQuickRetryAlarm(); else systemStateListener.registerForConnectivityChange(); } } } finally { if (reader != null) reader.close(); } }
private void unregisterForRadioChanges() { systemStateListener.unregisterForConnectivityChange(); }
private void registerForRadioChanges() { if (systemStateListener.isConnected()) systemStateListener.registerForRadioChange(); else systemStateListener.registerForConnectivityChange(); }