/** * Handle incoming transaction requests. The incoming requests are initiated by the MMSC Server * or by the MMS Client itself. */ @Override public void handleMessage(Message msg) { int serviceId = msg.arg1; Intent intent = (Intent) msg.obj; if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) { Log.v(TAG, "handleMessage serviceId: " + serviceId + " intent: " + intent); } if (intent != null) { String action = intent.getAction(); int error = intent.getIntExtra("errorCode", 0); if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) { Log.v(TAG, "handleMessage action: " + action + " error: " + error); } if (MESSAGE_SENT_ACTION.equals(intent.getAction())) { handleSmsSent(intent, error); } else if (SMS_RECEIVED_ACTION.equals(action)) { handleSmsReceived(intent, error); } else if (ACTION_BOOT_COMPLETED.equals(action)) { handleBootCompleted(); } else if (TelephonyIntents.ACTION_SERVICE_STATE_CHANGED.equals(action)) { handleServiceStateChanged(intent); } else if (ACTION_SEND_MESSAGE.endsWith(action)) { handleSendMessage(); } else if (ACTION_SEND_INACTIVE_MESSAGE.equals(action)) { handleSendInactiveMessage(); } } // NOTE: We MUST not call stopSelf() directly, since we need to // make sure the wake lock acquired by AlertReceiver is released. SmsReceiver.finishStartingService(SmsReceiverService.this, serviceId); }
private void unRegisterForServiceStateChanges() { if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE) || LogTag.DEBUG_SEND) { Log.v(TAG, "unRegisterForServiceStateChanges"); } try { Context context = getApplicationContext(); context.unregisterReceiver(SmsReceiver.getInstance()); } catch (IllegalArgumentException e) { // Allow un-matched register-unregister calls } }
private void registerForServiceStateChanges() { Context context = getApplicationContext(); unRegisterForServiceStateChanges(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED); if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE) || LogTag.DEBUG_SEND) { Log.v(TAG, "registerForServiceStateChanges"); } context.registerReceiver(SmsReceiver.getInstance(), intentFilter); }
/** * Mark all messages with a given {@link Uri} as read. * * @param context {@link Context} * @param uri {@link Uri} * @param read read status */ static void markRead(final Context context, final Uri uri, final int read) { Log.d(TAG, "markRead(" + uri + "," + read + ")"); if (uri == null) { return; } String[] sel = Message.SELECTION_UNREAD; if (read == 0) { sel = Message.SELECTION_READ; } final ContentResolver cr = context.getContentResolver(); final ContentValues cv = new ContentValues(); cv.put(Message.PROJECTION[Message.INDEX_READ], read); try { cr.update(uri, cv, Message.SELECTION_READ_UNREAD, sel); } catch (IllegalArgumentException e) { Log.e(TAG, "failed update", e); Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show(); } SmsReceiver.updateNewMessageNotification(context, null); }