Ejemplo n.º 1
0
    @Override
    protected Void doInBackground(Intent... intents) {
      Intent intent = intents[0];
      Xlog.d(
          MmsApp.TXN_TAG,
          "do In Background, slotId=" + intent.getIntExtra(Phone.GEMINI_SIM_ID_KEY, 0));
      // Get raw PDU push-data from the message and parse it
      byte[] pushData = intent.getByteArrayExtra("data");
      PduParser parser = new PduParser(pushData);
      GenericPdu pdu = parser.parse();

      if (null == pdu) {
        Log.e(TAG, "Invalid PUSH data");
        return null;
      }

      PduPersister p = PduPersister.getPduPersister(mContext);
      ContentResolver cr = mContext.getContentResolver();
      int type = pdu.getMessageType();
      long threadId = -1;

      try {
        switch (type) {
          case MESSAGE_TYPE_DELIVERY_IND:
            Xlog.d(MmsApp.TXN_TAG, "type=MESSAGE_TYPE_DELIVERY_IND");
          case MESSAGE_TYPE_READ_ORIG_IND:
            {
              if (type == MESSAGE_TYPE_READ_ORIG_IND) {
                Xlog.d(MmsApp.TXN_TAG, "type=MESSAGE_TYPE_READ_ORIG_IND");
              }
              threadId = findThreadId(mContext, pdu, type);
              if (threadId == -1) {
                // The associated SendReq isn't found, therefore skip
                // processing this PDU.
                break;
              }

              Uri uri = p.persist(pdu, Inbox.CONTENT_URI);
              // Update thread ID for ReadOrigInd & DeliveryInd.
              ContentValues values = new ContentValues(1);
              values.put(Mms.THREAD_ID, threadId);
              SqliteWrapper.update(mContext, cr, uri, values, null, null);
              break;
            }
          case MESSAGE_TYPE_NOTIFICATION_IND:
            {
              Xlog.d(MmsApp.TXN_TAG, "type=MESSAGE_TYPE_NOTIFICATION_IND");
              NotificationInd nInd = (NotificationInd) pdu;

              if (MmsConfig.getTransIdEnabled()) {
                byte[] contentLocation = nInd.getContentLocation();
                if ('=' == contentLocation[contentLocation.length - 1]) {
                  byte[] transactionId = nInd.getTransactionId();
                  byte[] contentLocationWithId =
                      new byte[contentLocation.length + transactionId.length];
                  System.arraycopy(
                      contentLocation, 0, contentLocationWithId, 0, contentLocation.length);
                  System.arraycopy(
                      transactionId,
                      0,
                      contentLocationWithId,
                      contentLocation.length,
                      transactionId.length);
                  nInd.setContentLocation(contentLocationWithId);
                }
              }

              if (!isDuplicateNotification(mContext, nInd)) {
                Uri uri = p.persist(pdu, Inbox.CONTENT_URI);
                // add for gemini
                if (FeatureOption.MTK_GEMINI_SUPPORT) {
                  // update pdu
                  ContentValues values = new ContentValues(2);
                  SIMInfo si =
                      SIMInfo.getSIMInfoBySlot(
                          mContext, intent.getIntExtra(Phone.GEMINI_SIM_ID_KEY, -1));
                  if (null == si) {
                    Xlog.e(
                        MmsApp.TXN_TAG,
                        "PushReceiver:SIMInfo is null for slot "
                            + intent.getIntExtra(Phone.GEMINI_SIM_ID_KEY, -1));
                    break;
                  }
                  values.put(Mms.SIM_ID, si.mSimId);
                  values.put(WapPush.SERVICE_ADDR, intent.getStringExtra(WapPush.SERVICE_ADDR));
                  SqliteWrapper.update(mContext, cr, uri, values, null, null);
                  Xlog.d(
                      MmsApp.TXN_TAG,
                      "save notification slotId="
                          + intent.getIntExtra(Phone.GEMINI_SIM_ID_KEY, 0)
                          + "\tsimId="
                          + si.mSimId
                          + "\tsc="
                          + intent.getStringExtra(WapPush.SERVICE_ADDR)
                          + "\taddr="
                          + intent.getStringExtra(WapPush.ADDR));

                  // update pending messages
                  long msgId = 0;
                  Cursor cursor =
                      SqliteWrapper.query(
                          mContext,
                          mContext.getContentResolver(),
                          uri,
                          new String[] {Mms._ID},
                          null,
                          null,
                          null);
                  if (cursor != null && cursor.getCount() == 1 && cursor.moveToFirst()) {
                    try {
                      msgId = cursor.getLong(0);
                      Xlog.d(MmsApp.TXN_TAG, "msg id = " + msgId);
                    } finally {
                      cursor.close();
                    }
                  }

                  Uri.Builder uriBuilder = PendingMessages.CONTENT_URI.buildUpon();
                  uriBuilder.appendQueryParameter("protocol", "mms");
                  uriBuilder.appendQueryParameter("message", String.valueOf(msgId));
                  Cursor pendingCs =
                      SqliteWrapper.query(
                          mContext,
                          mContext.getContentResolver(),
                          uriBuilder.build(),
                          null,
                          null,
                          null,
                          null);
                  if (pendingCs != null) {
                    try {
                      if ((pendingCs.getCount() == 1) && pendingCs.moveToFirst()) {
                        ContentValues valuesforPending = new ContentValues();
                        valuesforPending.put(PendingMessages.SIM_ID, si.mSimId);
                        int columnIndex = pendingCs.getColumnIndexOrThrow(PendingMessages._ID);
                        long id = pendingCs.getLong(columnIndex);
                        SqliteWrapper.update(
                            mContext,
                            mContext.getContentResolver(),
                            PendingMessages.CONTENT_URI,
                            valuesforPending,
                            PendingMessages._ID + "=" + id,
                            null);
                      } else {
                        Xlog.w(
                            MmsApp.TXN_TAG,
                            "can not find message to set pending sim id, msgId=" + msgId);
                      }
                    } finally {
                      pendingCs.close();
                    }
                  }
                } else {
                  ContentValues value = new ContentValues(1);
                  value.put(WapPush.SERVICE_ADDR, intent.getStringExtra(WapPush.SERVICE_ADDR));
                  SqliteWrapper.update(mContext, cr, uri, value, null, null);
                  Xlog.d(
                      MmsApp.TXN_TAG,
                      "save notification,"
                          + "\tsc="
                          + intent.getStringExtra(WapPush.SERVICE_ADDR)
                          + "\taddr="
                          + intent.getStringExtra(WapPush.ADDR));
                }

                // Start service to finish the notification transaction.
                Intent svc = new Intent(mContext, TransactionService.class);
                svc.putExtra(TransactionBundle.URI, uri.toString());
                svc.putExtra(
                    TransactionBundle.TRANSACTION_TYPE, Transaction.NOTIFICATION_TRANSACTION);
                if (FeatureOption.MTK_GEMINI_SUPPORT) {
                  SIMInfo si =
                      SIMInfo.getSIMInfoBySlot(
                          mContext, intent.getIntExtra(Phone.GEMINI_SIM_ID_KEY, -1));
                  if (null == si) {
                    Xlog.e(
                        MmsApp.TXN_TAG,
                        "PushReceiver: SIMInfo is null for slot "
                            + intent.getIntExtra(Phone.GEMINI_SIM_ID_KEY, -1));
                    break;
                  }
                  int simId = (int) si.mSimId;
                  svc.putExtra(Phone.GEMINI_SIM_ID_KEY, simId);
                  // svc.putExtra(Phone.GEMINI_SIM_ID_KEY,
                  // intent.getIntExtra(Phone.GEMINI_SIM_ID_KEY, 0));
                }
                mContext.startService(svc);
              } else if (LOCAL_LOGV) {
                Log.v(
                    TAG,
                    "Skip downloading duplicate message: " + new String(nInd.getContentLocation()));
              }
              break;
            }
          default:
            Log.e(TAG, "Received unrecognized PDU.");
        }
      } catch (MmsException e) {
        Log.e(TAG, "Failed to save the data from PUSH: type=" + type, e);
      } catch (RuntimeException e) {
        Log.e(TAG, "Unexpected RuntimeException.", e);
      } finally {
        raisePriority(mContext, false);
        Xlog.d(MmsApp.TXN_TAG, "Normal priority");
      }

      if (LOCAL_LOGV) {
        Log.v(TAG, "PUSH Intent processed.");
      }

      return null;
    }