summaryrefslogtreecommitdiffstats
path: root/src/java/com/android/internal/telephony/SyntheticSmsMessage.java
blob: 14bfca86f4e5419f176cbabae1b345a678c74ce0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package com.android.internal.telephony;

import org.json.JSONObject;

import com.android.internal.telephony.SmsConstants.MessageClass;

public class SyntheticSmsMessage extends SmsMessageBase {
    public static class SyntheticAddress extends SmsAddress {
    }

    public static boolean isSyntheticPdu(byte[] pdu) {
        try {
            JSONObject json = new JSONObject(new String(pdu));
            return json.optBoolean("synthetic", false);
        }
        catch (Exception e) {
        }
        return false;
    }

    public static SyntheticSmsMessage createFromPdu(byte[] pdu) {
        try {
            // TODO: use Parcelable or Bundle or something that serializes?
            JSONObject json = new JSONObject(new String(pdu));
            SyntheticSmsMessage message = new SyntheticSmsMessage(
                    json.getString("originatingAddress"),
                    json.optString("scAddress", null),
                    json.getString("messageBody"),
                    json.getLong("timestampMillis"));
            return message;
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public SyntheticSmsMessage(String originatingAddress, String scAddress, String messageBody, long timestampMillis) {
        this.originatingAddress = new SyntheticAddress();
        this.originatingAddress.address = originatingAddress;

        this.messageBody = messageBody;
        this.scTimeMillis = timestampMillis;
        this.scAddress = scAddress;

        try {
            JSONObject json = new JSONObject();
            json.put("originatingAddress", originatingAddress);
            json.put("scAddress", scAddress);
            json.put("messageBody", messageBody);
            json.put("timestampMillis", timestampMillis);
            json.put("synthetic", true);
            this.mPdu = json.toString().getBytes();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public MessageClass getMessageClass() {
        return SmsConstants.MessageClass.UNKNOWN;
    }

    @Override
    public int getProtocolIdentifier() {
        return 0;
    }

    @Override
    public boolean isReplace() {
        return false;
    }

    @Override
    public boolean isCphsMwiMessage() {
        return false;
    }

    @Override
    public boolean isMWIClearMessage() {
        return false;
    }

    @Override
    public boolean isMWISetMessage() {
        return false;
    }

    @Override
    public boolean isMwiDontStore() {
        return false;
    }

    @Override
    public int getStatus() {
        return 0;
    }

    @Override
    public boolean isStatusReportMessage() {
        return false;
    }

    @Override
    public boolean isReplyPathPresent() {
        return false;
    }
}