1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16 package com.android.phone.vvm.omtp.sms;
17 
18 import com.android.phone.vvm.omtp.OmtpConstants;
19 
20 /**
21  * Structured data representation of an OMTP SYNC message.
22  *
23  * Getters will return null if the field was not set in the message body or it could not be parsed.
24  */
25 public class SyncMessage {
26     // Sync event that triggered this message.
27     private final String mSyncTriggerEvent;
28     // Total number of new messages on the server.
29     private final Integer mNewMessageCount;
30     // UID of the new message.
31     private final String mMessageId;
32     // Length of the message.
33     private final Integer mMessageLength;
34     // Content type (voice, video, fax...) of the new message.
35     private final String mContentType;
36     // Sender of the new message.
37     private final String mSender;
38     // Timestamp (in millis) of the new message.
39     private final Long mMsgTimeMillis;
40 
41     @Override
toString()42     public String toString() {
43         return "SyncMessage [mSyncTriggerEvent=" + mSyncTriggerEvent
44                 + ", mNewMessageCount=" + mNewMessageCount
45                 + ", mMessageId=" + mMessageId
46                 + ", mMessageLength=" + mMessageLength
47                 + ", mContentType=" + mContentType
48                 + ", mSender=" + mSender
49                 + ", mMsgTimeMillis=" + mMsgTimeMillis + "]";
50     }
51 
SyncMessage(WrappedMessageData wrappedData)52     public SyncMessage(WrappedMessageData wrappedData) {
53         mSyncTriggerEvent = wrappedData.extractString(OmtpConstants.SYNC_TRIGGER_EVENT);
54         mMessageId = wrappedData.extractString(OmtpConstants.MESSAGE_UID);
55         mMessageLength = wrappedData.extractInteger(OmtpConstants.MESSAGE_LENGTH);
56         mContentType = wrappedData.extractString(OmtpConstants.CONTENT_TYPE);
57         mSender = wrappedData.extractString(OmtpConstants.SENDER);
58         mNewMessageCount = wrappedData.extractInteger(OmtpConstants.NUM_MESSAGE_COUNT);
59         mMsgTimeMillis = wrappedData.extractTime(OmtpConstants.TIME);
60     }
61 
62     /**
63      * @return the event that triggered the sync message. This is a mandatory field and must always
64      * be set.
65      */
getSyncTriggerEvent()66     public String getSyncTriggerEvent() {
67         return mSyncTriggerEvent;
68     }
69 
70     /**
71      * @return the number of new messages stored on the voicemail server.
72      */
getNewMessageCount()73     public int getNewMessageCount() {
74         return mNewMessageCount != null ? mNewMessageCount : 0;
75     }
76 
77     /**
78      * @return the message ID of the new message.
79      * <p>
80      * Expected to be set only for
81      * {@link com.android.phone.vvm.omtp.OmtpConstants#NEW_MESSAGE}
82      */
getId()83     public String getId() {
84         return mMessageId;
85     }
86 
87     /**
88      * @return the content type of the new message.
89      * <p>
90      * Expected to be set only for
91      * {@link com.android.phone.vvm.omtp.OmtpConstants#NEW_MESSAGE}
92      */
getContentType()93     public String getContentType() {
94         return mContentType;
95     }
96 
97     /**
98      * @return the message length of the new message.
99      * <p>
100      * Expected to be set only for
101      * {@link com.android.phone.vvm.omtp.OmtpConstants#NEW_MESSAGE}
102      */
getLength()103     public int getLength() {
104         return mMessageLength != null ? mMessageLength : 0;
105     }
106 
107     /**
108      * @return the sender's phone number of the new message specified as MSISDN.
109      * <p>
110      * Expected to be set only for
111      * {@link com.android.phone.vvm.omtp.OmtpConstants#NEW_MESSAGE}
112      */
getSender()113     public String getSender() {
114         return mSender;
115     }
116 
117     /**
118      * @return the timestamp as milliseconds for the new message.
119      * <p>
120      * Expected to be set only for
121      * {@link com.android.phone.vvm.omtp.OmtpConstants#NEW_MESSAGE}
122      */
getTimestampMillis()123     public long getTimestampMillis() {
124         return mMsgTimeMillis != null ? mMsgTimeMillis : 0;
125     }
126 }