Loading src/java/com/android/internal/telephony/InboundSmsHandler.java +0 −59 Original line number Diff line number Diff line Loading @@ -41,7 +41,6 @@ import android.database.Cursor; import android.database.SQLException; import android.net.Uri; import android.os.AsyncResult; import android.os.Binder; import android.os.Bundle; import android.os.IDeviceIdleController; import android.os.Message; Loading @@ -57,7 +56,6 @@ import android.service.carrier.CarrierMessagingService; import android.telephony.SmsMessage; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.LocalLog; import android.util.Pair; Loading Loading @@ -1620,63 +1618,6 @@ public abstract class InboundSmsHandler extends StateMachine { Rlog.e(getName(), s, e); } /** * Store a received SMS into Telephony provider * * @param intent The intent containing the received SMS * @return The URI of written message */ @UnsupportedAppUsage private Uri writeInboxMessage(Intent intent) { final SmsMessage[] messages = Telephony.Sms.Intents.getMessagesFromIntent(intent); if (messages == null || messages.length < 1) { loge("Failed to parse SMS pdu"); return null; } // Sometimes, SmsMessage is null if it can’t be parsed correctly. for (final SmsMessage sms : messages) { if (sms == null) { loge("Can’t write null SmsMessage"); return null; } } final ContentValues values = parseSmsMessage(messages); final long identity = Binder.clearCallingIdentity(); try { return mContext.getContentResolver().insert(Telephony.Sms.Inbox.CONTENT_URI, values); } catch (Exception e) { loge("Failed to persist inbox message", e); } finally { Binder.restoreCallingIdentity(identity); } return null; } /** * Convert SmsMessage[] into SMS database schema columns * * @param msgs The SmsMessage array of the received SMS * @return ContentValues representing the columns of parsed SMS */ private static ContentValues parseSmsMessage(SmsMessage[] msgs) { final SmsMessage sms = msgs[0]; final ContentValues values = new ContentValues(); values.put(Telephony.Sms.Inbox.ADDRESS, sms.getDisplayOriginatingAddress()); values.put(Telephony.Sms.Inbox.BODY, buildMessageBodyFromPdus(msgs)); values.put(Telephony.Sms.Inbox.DATE_SENT, sms.getTimestampMillis()); values.put(Telephony.Sms.Inbox.DATE, System.currentTimeMillis()); values.put(Telephony.Sms.Inbox.PROTOCOL, sms.getProtocolIdentifier()); values.put(Telephony.Sms.Inbox.SEEN, 0); values.put(Telephony.Sms.Inbox.READ, 0); final String subject = sms.getPseudoSubject(); if (!TextUtils.isEmpty(subject)) { values.put(Telephony.Sms.Inbox.SUBJECT, subject); } values.put(Telephony.Sms.Inbox.REPLY_PATH_PRESENT, sms.isReplyPathPresent() ? 1 : 0); values.put(Telephony.Sms.Inbox.SERVICE_CENTER, sms.getServiceCenterAddress()); return values; } /** * Build up the SMS message body from the SmsMessage array of received SMS * Loading src/java/com/android/internal/telephony/WapPushOverSms.java +0 −173 Original line number Diff line number Diff line Loading @@ -16,9 +16,7 @@ package com.android.internal.telephony; import static com.google.android.mms.pdu.PduHeaders.MESSAGE_TYPE_DELIVERY_IND; import static com.google.android.mms.pdu.PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND; import static com.google.android.mms.pdu.PduHeaders.MESSAGE_TYPE_READ_ORIG_IND; import android.annotation.NonNull; import android.annotation.Nullable; Loading @@ -28,41 +26,29 @@ import android.app.BroadcastOptions; import android.compat.annotation.UnsupportedAppUsage; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.ServiceConnection; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.database.Cursor; import android.database.DatabaseUtils; import android.database.sqlite.SQLiteException; import android.net.Uri; import android.os.Bundle; import android.os.IBinder; import android.os.IDeviceIdleController; import android.os.RemoteException; import android.os.UserHandle; import android.os.UserManager; import android.provider.Telephony; import android.provider.Telephony.Sms.Intents; import android.telephony.SmsManager; import android.telephony.SubscriptionManager; import android.text.TextUtils; import android.util.Log; import com.android.internal.telephony.uicc.IccUtils; import com.android.telephony.Rlog; import com.google.android.mms.MmsException; import com.google.android.mms.pdu.DeliveryInd; import com.google.android.mms.pdu.GenericPdu; import com.google.android.mms.pdu.NotificationInd; import com.google.android.mms.pdu.PduHeaders; import com.google.android.mms.pdu.PduParser; import com.google.android.mms.pdu.PduPersister; import com.google.android.mms.pdu.ReadOrigInd; import java.util.HashMap; import java.util.List; Loading Loading @@ -473,165 +459,6 @@ public class WapPushOverSms implements ServiceConnection { .getBoolean(SmsManager.MMS_CONFIG_SUPPORT_MMS_CONTENT_DISPOSITION, true); } private void writeInboxMessage(int subId, GenericPdu pdu) { if (pdu == null) { Rlog.e(TAG, "Invalid PUSH PDU"); } final PduPersister persister = PduPersister.getPduPersister(mContext); final int type = pdu.getMessageType(); try { switch (type) { case MESSAGE_TYPE_DELIVERY_IND: case MESSAGE_TYPE_READ_ORIG_IND: { final long threadId = getDeliveryOrReadReportThreadId(mContext, pdu); if (threadId == -1) { // The associated SendReq isn't found, therefore skip // processing this PDU. Rlog.e(TAG, "Failed to find delivery or read report's thread id"); break; } final Uri uri = persister.persist( pdu, Telephony.Mms.Inbox.CONTENT_URI, true/*createThreadId*/, true/*groupMmsEnabled*/, null/*preOpenedFiles*/); if (uri == null) { Rlog.e(TAG, "Failed to persist delivery or read report"); break; } // Update thread ID for ReadOrigInd & DeliveryInd. final ContentValues values = new ContentValues(1); values.put(Telephony.Mms.THREAD_ID, threadId); if (mContext.getContentResolver().update( uri, values, null/*where*/, null/*selectionArgs*/) != 1) { Rlog.e(TAG, "Failed to update delivery or read report thread id"); } break; } case MESSAGE_TYPE_NOTIFICATION_IND: { final NotificationInd nInd = (NotificationInd) pdu; Bundle configs = SmsManager.getSmsManagerForSubscriptionId(subId) .getCarrierConfigValues(); if (configs != null && configs.getBoolean( SmsManager.MMS_CONFIG_APPEND_TRANSACTION_ID, false)) { final 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)) { final Uri uri = persister.persist( pdu, Telephony.Mms.Inbox.CONTENT_URI, true/*createThreadId*/, true/*groupMmsEnabled*/, null/*preOpenedFiles*/); if (uri == null) { Rlog.e(TAG, "Failed to save MMS WAP push notification ind"); } } else { Rlog.d(TAG, "Skip storing duplicate MMS WAP push notification ind: " + new String(nInd.getContentLocation())); } break; } default: Log.e(TAG, "Received unrecognized WAP Push PDU."); } } catch (MmsException e) { Log.e(TAG, "Failed to save MMS WAP push data: type=" + type, e); } catch (RuntimeException e) { Log.e(TAG, "Unexpected RuntimeException in persisting MMS WAP push data", e); } } private static final String THREAD_ID_SELECTION = Telephony.Mms.MESSAGE_ID + "=? AND " + Telephony.Mms.MESSAGE_TYPE + "=?"; @UnsupportedAppUsage private static long getDeliveryOrReadReportThreadId(Context context, GenericPdu pdu) { String messageId; if (pdu instanceof DeliveryInd) { messageId = new String(((DeliveryInd) pdu).getMessageId()); } else if (pdu instanceof ReadOrigInd) { messageId = new String(((ReadOrigInd) pdu).getMessageId()); } else { Rlog.e(TAG, "WAP Push data is neither delivery or read report type: " + pdu.getClass().getCanonicalName()); return -1L; } Cursor cursor = null; try { cursor = context.getContentResolver().query( Telephony.Mms.CONTENT_URI, new String[]{ Telephony.Mms.THREAD_ID }, THREAD_ID_SELECTION, new String[]{ DatabaseUtils.sqlEscapeString(messageId), Integer.toString(PduHeaders.MESSAGE_TYPE_SEND_REQ) }, null/*sortOrder*/); if (cursor != null && cursor.moveToFirst()) { return cursor.getLong(0); } } catch (SQLiteException e) { Rlog.e(TAG, "Failed to query delivery or read report thread id", e); } finally { if (cursor != null) { cursor.close(); } } return -1L; } private static final String LOCATION_SELECTION = Telephony.Mms.MESSAGE_TYPE + "=? AND " + Telephony.Mms.CONTENT_LOCATION + " =?"; @UnsupportedAppUsage private static boolean isDuplicateNotification(Context context, NotificationInd nInd) { final byte[] rawLocation = nInd.getContentLocation(); if (rawLocation != null) { String location = new String(rawLocation); String[] selectionArgs = new String[] { location }; Cursor cursor = null; try { cursor = context.getContentResolver().query( Telephony.Mms.CONTENT_URI, new String[]{ Telephony.Mms._ID }, LOCATION_SELECTION, new String[]{ Integer.toString(PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND), new String(rawLocation) }, null/*sortOrder*/); if (cursor != null && cursor.getCount() > 0) { // We already received the same notification before. return true; } } catch (SQLiteException e) { Rlog.e(TAG, "failed to query existing notification ind", e); } finally { if (cursor != null) { cursor.close(); } } } return false; } public static String getPermissionForType(String mimeType) { String permission; if (WspTypeDecoder.CONTENT_TYPE_B_MMS.equals(mimeType)) { Loading Loading
src/java/com/android/internal/telephony/InboundSmsHandler.java +0 −59 Original line number Diff line number Diff line Loading @@ -41,7 +41,6 @@ import android.database.Cursor; import android.database.SQLException; import android.net.Uri; import android.os.AsyncResult; import android.os.Binder; import android.os.Bundle; import android.os.IDeviceIdleController; import android.os.Message; Loading @@ -57,7 +56,6 @@ import android.service.carrier.CarrierMessagingService; import android.telephony.SmsMessage; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.LocalLog; import android.util.Pair; Loading Loading @@ -1620,63 +1618,6 @@ public abstract class InboundSmsHandler extends StateMachine { Rlog.e(getName(), s, e); } /** * Store a received SMS into Telephony provider * * @param intent The intent containing the received SMS * @return The URI of written message */ @UnsupportedAppUsage private Uri writeInboxMessage(Intent intent) { final SmsMessage[] messages = Telephony.Sms.Intents.getMessagesFromIntent(intent); if (messages == null || messages.length < 1) { loge("Failed to parse SMS pdu"); return null; } // Sometimes, SmsMessage is null if it can’t be parsed correctly. for (final SmsMessage sms : messages) { if (sms == null) { loge("Can’t write null SmsMessage"); return null; } } final ContentValues values = parseSmsMessage(messages); final long identity = Binder.clearCallingIdentity(); try { return mContext.getContentResolver().insert(Telephony.Sms.Inbox.CONTENT_URI, values); } catch (Exception e) { loge("Failed to persist inbox message", e); } finally { Binder.restoreCallingIdentity(identity); } return null; } /** * Convert SmsMessage[] into SMS database schema columns * * @param msgs The SmsMessage array of the received SMS * @return ContentValues representing the columns of parsed SMS */ private static ContentValues parseSmsMessage(SmsMessage[] msgs) { final SmsMessage sms = msgs[0]; final ContentValues values = new ContentValues(); values.put(Telephony.Sms.Inbox.ADDRESS, sms.getDisplayOriginatingAddress()); values.put(Telephony.Sms.Inbox.BODY, buildMessageBodyFromPdus(msgs)); values.put(Telephony.Sms.Inbox.DATE_SENT, sms.getTimestampMillis()); values.put(Telephony.Sms.Inbox.DATE, System.currentTimeMillis()); values.put(Telephony.Sms.Inbox.PROTOCOL, sms.getProtocolIdentifier()); values.put(Telephony.Sms.Inbox.SEEN, 0); values.put(Telephony.Sms.Inbox.READ, 0); final String subject = sms.getPseudoSubject(); if (!TextUtils.isEmpty(subject)) { values.put(Telephony.Sms.Inbox.SUBJECT, subject); } values.put(Telephony.Sms.Inbox.REPLY_PATH_PRESENT, sms.isReplyPathPresent() ? 1 : 0); values.put(Telephony.Sms.Inbox.SERVICE_CENTER, sms.getServiceCenterAddress()); return values; } /** * Build up the SMS message body from the SmsMessage array of received SMS * Loading
src/java/com/android/internal/telephony/WapPushOverSms.java +0 −173 Original line number Diff line number Diff line Loading @@ -16,9 +16,7 @@ package com.android.internal.telephony; import static com.google.android.mms.pdu.PduHeaders.MESSAGE_TYPE_DELIVERY_IND; import static com.google.android.mms.pdu.PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND; import static com.google.android.mms.pdu.PduHeaders.MESSAGE_TYPE_READ_ORIG_IND; import android.annotation.NonNull; import android.annotation.Nullable; Loading @@ -28,41 +26,29 @@ import android.app.BroadcastOptions; import android.compat.annotation.UnsupportedAppUsage; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.ServiceConnection; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.database.Cursor; import android.database.DatabaseUtils; import android.database.sqlite.SQLiteException; import android.net.Uri; import android.os.Bundle; import android.os.IBinder; import android.os.IDeviceIdleController; import android.os.RemoteException; import android.os.UserHandle; import android.os.UserManager; import android.provider.Telephony; import android.provider.Telephony.Sms.Intents; import android.telephony.SmsManager; import android.telephony.SubscriptionManager; import android.text.TextUtils; import android.util.Log; import com.android.internal.telephony.uicc.IccUtils; import com.android.telephony.Rlog; import com.google.android.mms.MmsException; import com.google.android.mms.pdu.DeliveryInd; import com.google.android.mms.pdu.GenericPdu; import com.google.android.mms.pdu.NotificationInd; import com.google.android.mms.pdu.PduHeaders; import com.google.android.mms.pdu.PduParser; import com.google.android.mms.pdu.PduPersister; import com.google.android.mms.pdu.ReadOrigInd; import java.util.HashMap; import java.util.List; Loading Loading @@ -473,165 +459,6 @@ public class WapPushOverSms implements ServiceConnection { .getBoolean(SmsManager.MMS_CONFIG_SUPPORT_MMS_CONTENT_DISPOSITION, true); } private void writeInboxMessage(int subId, GenericPdu pdu) { if (pdu == null) { Rlog.e(TAG, "Invalid PUSH PDU"); } final PduPersister persister = PduPersister.getPduPersister(mContext); final int type = pdu.getMessageType(); try { switch (type) { case MESSAGE_TYPE_DELIVERY_IND: case MESSAGE_TYPE_READ_ORIG_IND: { final long threadId = getDeliveryOrReadReportThreadId(mContext, pdu); if (threadId == -1) { // The associated SendReq isn't found, therefore skip // processing this PDU. Rlog.e(TAG, "Failed to find delivery or read report's thread id"); break; } final Uri uri = persister.persist( pdu, Telephony.Mms.Inbox.CONTENT_URI, true/*createThreadId*/, true/*groupMmsEnabled*/, null/*preOpenedFiles*/); if (uri == null) { Rlog.e(TAG, "Failed to persist delivery or read report"); break; } // Update thread ID for ReadOrigInd & DeliveryInd. final ContentValues values = new ContentValues(1); values.put(Telephony.Mms.THREAD_ID, threadId); if (mContext.getContentResolver().update( uri, values, null/*where*/, null/*selectionArgs*/) != 1) { Rlog.e(TAG, "Failed to update delivery or read report thread id"); } break; } case MESSAGE_TYPE_NOTIFICATION_IND: { final NotificationInd nInd = (NotificationInd) pdu; Bundle configs = SmsManager.getSmsManagerForSubscriptionId(subId) .getCarrierConfigValues(); if (configs != null && configs.getBoolean( SmsManager.MMS_CONFIG_APPEND_TRANSACTION_ID, false)) { final 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)) { final Uri uri = persister.persist( pdu, Telephony.Mms.Inbox.CONTENT_URI, true/*createThreadId*/, true/*groupMmsEnabled*/, null/*preOpenedFiles*/); if (uri == null) { Rlog.e(TAG, "Failed to save MMS WAP push notification ind"); } } else { Rlog.d(TAG, "Skip storing duplicate MMS WAP push notification ind: " + new String(nInd.getContentLocation())); } break; } default: Log.e(TAG, "Received unrecognized WAP Push PDU."); } } catch (MmsException e) { Log.e(TAG, "Failed to save MMS WAP push data: type=" + type, e); } catch (RuntimeException e) { Log.e(TAG, "Unexpected RuntimeException in persisting MMS WAP push data", e); } } private static final String THREAD_ID_SELECTION = Telephony.Mms.MESSAGE_ID + "=? AND " + Telephony.Mms.MESSAGE_TYPE + "=?"; @UnsupportedAppUsage private static long getDeliveryOrReadReportThreadId(Context context, GenericPdu pdu) { String messageId; if (pdu instanceof DeliveryInd) { messageId = new String(((DeliveryInd) pdu).getMessageId()); } else if (pdu instanceof ReadOrigInd) { messageId = new String(((ReadOrigInd) pdu).getMessageId()); } else { Rlog.e(TAG, "WAP Push data is neither delivery or read report type: " + pdu.getClass().getCanonicalName()); return -1L; } Cursor cursor = null; try { cursor = context.getContentResolver().query( Telephony.Mms.CONTENT_URI, new String[]{ Telephony.Mms.THREAD_ID }, THREAD_ID_SELECTION, new String[]{ DatabaseUtils.sqlEscapeString(messageId), Integer.toString(PduHeaders.MESSAGE_TYPE_SEND_REQ) }, null/*sortOrder*/); if (cursor != null && cursor.moveToFirst()) { return cursor.getLong(0); } } catch (SQLiteException e) { Rlog.e(TAG, "Failed to query delivery or read report thread id", e); } finally { if (cursor != null) { cursor.close(); } } return -1L; } private static final String LOCATION_SELECTION = Telephony.Mms.MESSAGE_TYPE + "=? AND " + Telephony.Mms.CONTENT_LOCATION + " =?"; @UnsupportedAppUsage private static boolean isDuplicateNotification(Context context, NotificationInd nInd) { final byte[] rawLocation = nInd.getContentLocation(); if (rawLocation != null) { String location = new String(rawLocation); String[] selectionArgs = new String[] { location }; Cursor cursor = null; try { cursor = context.getContentResolver().query( Telephony.Mms.CONTENT_URI, new String[]{ Telephony.Mms._ID }, LOCATION_SELECTION, new String[]{ Integer.toString(PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND), new String(rawLocation) }, null/*sortOrder*/); if (cursor != null && cursor.getCount() > 0) { // We already received the same notification before. return true; } } catch (SQLiteException e) { Rlog.e(TAG, "failed to query existing notification ind", e); } finally { if (cursor != null) { cursor.close(); } } } return false; } public static String getPermissionForType(String mimeType) { String permission; if (WspTypeDecoder.CONTENT_TYPE_B_MMS.equals(mimeType)) { Loading