class 0 短信和普通短信 随设置逻辑

短信分为四个类别:Class 0、1、2和3,分别定义了短信的重要性和存储位置。Class 0消息不保存在存储器中,Class 1和2存储在设备或SIM卡,Class 3用于转发到外部设备。数据流动过程包括电话接收和发送短信的路径,涉及SMS堆栈、观察者应用程序和消息存储。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >




测试情况,短信到来之时手机都处于灭屏状态或者在launcher界面: 

一、settings里面勾选“在来电话时发出振动” 
1、mms settings勾选振动 
class0短信和其他class短信都会振动 
2、mms settings关闭振动 ----- 这是唯一class0和class1不同的情况 
class0短信振动 
其他class短信不振动 

二、settings里面关闭“在来电话时发出振动” 
1、mms settings勾选振动 
class0短信和其他class短信都不振动 
2、mms settings关闭振动 
class0短信和其他class短信都不振动 

仔细查看代码,发现class0的通知和普通短信的通知确实不一样 
/packages/apps/Mms/src/com/android/mms/transaction/MessagingNotification.java
class0: 
public static boolean notifyClassZeroMessage(Context context, String address) 

普通短信: 
blockingUpdateNewMessageIndicator方法,最后调用 
updateNotification方法 





普通短信,短信设置,情景模式设置:
public static void blockingUpdateNewMessageIndicator(Context context, long newMsgThreadId,
            boolean isStatusMessage, Uri statusMessageUri) {
        /// M: add for notification settings
        NotificationProfile notiProf = getNotificationProfileByThreadId(context, newMsgThreadId);
        boolean isContinuousComming = false;
        long currentTime = System.currentTimeMillis();
        if (newMsgThreadId != THREAD_NONE) {
            isContinuousComming = currentTime <= sLastNotificationTime + RINGTONE_WAIT_TIME;
            Log.d(TAG, "isContinuousComming = " + isContinuousComming + " currentTime " + currentTime + "  " + sLastNotificationTime);
        }
        final boolean isDefaultSmsApp = MmsConfig.isSmsEnabled(context);
        if (!isDefaultSmsApp) {
            cancelNotification(context, NOTIFICATION_ID);
            if (DEBUG || Log.isLoggable(LogTag.APP, Log.VERBOSE))
                Log.d(TAG, "blockingUpdateNewMessageIndicator: not the default sms app - skipping "
                        + "notification");
            return;
        }

        synchronized (sCurrentlyDisplayedThreadLock) {
            Log.d(TAG, "newMsgThreadId = " + newMsgThreadId + "sCurrentlyDisplayedThreadId = " + sCurrentlyDisplayedThreadId);
            if (newMsgThreadId > 0 && newMsgThreadId == sCurrentlyDisplayedThreadId) {
                if (DEBUG) {
                    Log.d(TAG, "blockingUpdateNewMessageIndicator: newMsgThreadId == " +
                            "sCurrentlyDisplayedThreadId so NOT showing notification," +
                            " but playing soft sound. threadId: " + newMsgThreadId);
                }
                if (!isContinuousComming) {
                    playInConversationNotificationSound(context, notiProf);
                    sLastNotificationTime = currentTime;
                }
                return;
            }
        }

        SortedSet<NotificationInfo> notificationSet =
                new TreeSet<NotificationInfo>(INFO_COMPARATOR);

        Set<Long> threads = new HashSet<Long>(4);

        int count = 0;
        int mmsUnReadCount = addMmsNotificationInfos(context, threads, notificationSet);
        int smsUnReadCount = addSmsNotificationInfos(context, threads, notificationSet);

        if (!isContinuousComming) {
            cancelNotification(context, NOTIFICATION_ID);
        }
        if (!notificationSet.isEmpty()) {
            if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
                Log.d(TAG, "blockingUpdateNewMessageIndicator: count=" + count +
                        ", newMsgThreadId=" + newMsgThreadId);
            }
            updateNotification(context, newMsgThreadId != THREAD_NONE, threads.size(), notificationSet,
                    newMsgThreadId, notiProf, isContinuousComming, mmsUnReadCount, smsUnReadCount);
            sLastNotificationTime = currentTime;
        }

        // And deals with delivery reports (which use Toasts). It's safe to call in a worker
        // thread because the toast will eventually get posted to a handler.
        MmsSmsDeliveryInfo delivery = getSmsNewDeliveryInfo(context, statusMessageUri);
        if (delivery != null) {
            delivery.deliver(context, isStatusMessage);
        }

        notificationSet.clear();
        threads.clear();
    }





class 0 短信
/// M: the new methods
    /// M:Code analyze 004,add for class 0 of sms types,class 0 means the sms will not be save into
    /// phone or simCard,but only show on the phone @{
    public static boolean notifyClassZeroMessage(Context context, String address) {
        Log.d(TAG, "notifyClassZeroMessage");
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);

        boolean enabled = sp.getBoolean(NotificationPreferenceActivity.NOTIFICATION_ENABLED, true);
        Log.d(TAG, "notifyClassZeroMessage, enabled = " + enabled);
        if (!enabled) {
            return false;
        }

        NotificationManager nm = (NotificationManager)
                context.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new Notification();

        String ringtoneStr = sp.getString(NotificationPreferenceActivity.NOTIFICATION_RINGTONE, null);
        ringtoneStr = MessagingNotification.checkRingtone(context, ringtoneStr);
        Uri ringtone = TextUtils.isEmpty(ringtoneStr) ? null : Uri.parse(ringtoneStr);
        processNotificationSound(context, notification, ringtone);

        notification.tickerText = address;
        notification.flags |= Notification.FLAG_SHOW_LIGHTS;
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.ledARGB = 0xff00ff00;
        notification.ledOnMS = 500;
        notification.ledOffMS = 2000;
        nm.notify(CLASS_ZERO_NOTIFICATION_ID, notification);
        return true;
    }




Types of SMS Message

There are four classes of an SMS message. Classes identify the importance of an SMS message and also the location where it must be stored.

  • Class 0

    This type of SMS message is displayed on the mobile screen without being saved in the message store or on the SIM card; unless explicitly saved by the mobile user.

  • Class 1

    This message is to be stored in the device memory or the SIM card (depending on memory availability).

  • Class 2

    This message class carries SIM card data. The SIM card data must be successfully transferred prior to sending acknowledgment to the service center. An error message is sent to the service center if this transmission is not possible.

  • Class 3

    This message is forwarded from the receiving entity to an external device. The delivery acknowledgment is sent to the service center regardless of whether or not the message was forwarded to the external device.

Data flow

For an incoming message, the usual route is:

  1. The phone receives the SMS. The telephony server notifies the SMS stack.

  2. The SMS stack decodes the message and then notifies the SMS watcher that handles messages of the relevant service center. The watcher creates a new messaging entry in the message store's Inbox.

  3. Any messaging application that is set as an observer of the message store is notified of the arrival of the new message. The application can then determine whether it should handle the message, and if so, can then read the message and process it appropriately.

For an outgoing message, the route is:

  1. A messaging application uses the SMS client MTM APIs to create a message, to set its contents and fields, and to send it

  2. The message server passes the send command to the SMS server MTM. This calls the appropriate SMS stack to send the message.

  3. The stack calls the telephony server to send the message.

Related concepts




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值