SmsManager.java revision a8f8c5a113a66de4854f4fb13a5825eb0705bd59
1c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville/*
2c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Copyright (C) 2008 The Android Open Source Project
3c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville *
4c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Licensed under the Apache License, Version 2.0 (the "License");
5c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * you may not use this file except in compliance with the License.
6c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * You may obtain a copy of the License at
7c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville *
8c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville *      http://www.apache.org/licenses/LICENSE-2.0
9c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville *
10c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Unless required by applicable law or agreed to in writing, software
11c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * distributed under the License is distributed on an "AS IS" BASIS,
12c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * See the License for the specific language governing permissions and
14c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * limitations under the License.
15c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville */
16c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
17c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savillepackage android.telephony;
18c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
197fce994eb223105829becb6c26e3af7a9739752cDianne Hackbornimport android.app.ActivityThread;
20c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savilleimport android.app.PendingIntent;
2131d02efb89a5b16679b67d8487a3c4c4c907dd7aPauloftheWestimport android.content.ActivityNotFoundException;
22b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wenimport android.content.ContentValues;
235855254b4e0c22aaaa688ebbfb5c38b222cbf9d6Cheuksan Wangimport android.content.Context;
245855254b4e0c22aaaa688ebbfb5c38b222cbf9d6Cheuksan Wangimport android.content.Intent;
25b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wenimport android.net.Uri;
26bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseriimport android.os.BaseBundle;
27038b5c11030741f103c15741db74068ce099cb53Shri Bordeimport android.os.Bundle;
28c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savilleimport android.os.RemoteException;
29c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savilleimport android.os.ServiceManager;
30c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savilleimport android.text.TextUtils;
31038b5c11030741f103c15741db74068ce099cb53Shri Bordeimport android.util.ArrayMap;
3231d02efb89a5b16679b67d8487a3c4c4c907dd7aPauloftheWestimport android.util.Log;
33c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
34c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savilleimport com.android.internal.telephony.ISms;
35c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savilleimport com.android.internal.telephony.SmsRawData;
367320aa58e7fcbe113ec85e6ae7d41858af2e3270Ye Wenimport com.android.internal.telephony.IMms;
37d720945f2be5ea5fe0faf67e67d9ea0e184eba67Alex Yakavenkaimport com.android.internal.telephony.uicc.IccConstants;
38c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
39c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savilleimport java.util.ArrayList;
40c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savilleimport java.util.Arrays;
41c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savilleimport java.util.List;
42038b5c11030741f103c15741db74068ce099cb53Shri Bordeimport java.util.Map;
43c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
44c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville/*
45c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * TODO(code review): Curious question... Why are a lot of these
46c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * methods not declared as static, since they do not seem to require
47c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * any local object state?  Presumably this cannot be changed without
48c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * interfering with the API...
49c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville */
50c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
51c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville/**
52c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Manages SMS operations such as sending data, text, and pdu SMS messages.
5329305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * Get this object by calling the static method {@link #getDefault()}.
5429305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main *
5529305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * <p>For information about how to behave as the default SMS app on Android 4.4 (API level 19)
5629305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * and higher, see {@link android.provider.Telephony}.
57c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville */
58c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savillepublic final class SmsManager {
5931d02efb89a5b16679b67d8487a3c4c4c907dd7aPauloftheWest    private static final String TAG = "SmsManager";
60038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
61038b5c11030741f103c15741db74068ce099cb53Shri Borde     * A psuedo-subId that represents the default subId at any given time. The actual subId it
62038b5c11030741f103c15741db74068ce099cb53Shri Borde     * represents changes as the default subId is changed.
63038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
649dbb6ad72f064bde732111fe40ded4543b34295eYe Wen    private static final int DEFAULT_SUBSCRIPTION_ID = -1002;
65038b5c11030741f103c15741db74068ce099cb53Shri Borde
66c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /** Singleton object constructed during class initialization. */
679dbb6ad72f064bde732111fe40ded4543b34295eYe Wen    private static final SmsManager sInstance = new SmsManager(DEFAULT_SUBSCRIPTION_ID);
68038b5c11030741f103c15741db74068ce099cb53Shri Borde    private static final Object sLockObject = new Object();
699dbb6ad72f064bde732111fe40ded4543b34295eYe Wen
70a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe    /** @hide */
71a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe    public static final int CELL_BROADCAST_RAN_TYPE_GSM = 0;
72a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe    /** @hide */
73a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe    public static final int CELL_BROADCAST_RAN_TYPE_CDMA = 1;
749dbb6ad72f064bde732111fe40ded4543b34295eYe Wen
759dbb6ad72f064bde732111fe40ded4543b34295eYe Wen    private static final Map<Integer, SmsManager> sSubInstances =
769dbb6ad72f064bde732111fe40ded4543b34295eYe Wen            new ArrayMap<Integer, SmsManager>();
779dbb6ad72f064bde732111fe40ded4543b34295eYe Wen
789dbb6ad72f064bde732111fe40ded4543b34295eYe Wen    /** A concrete subscription id, or the pseudo DEFAULT_SUBSCRIPTION_ID */
79b237a11044ed842d2865ff8c8716befb06b6ca25Wink Saville    private int mSubId;
80038b5c11030741f103c15741db74068ce099cb53Shri Borde
81038b5c11030741f103c15741db74068ce099cb53Shri Borde    /*
82038b5c11030741f103c15741db74068ce099cb53Shri Borde     * Key for the various carrier-dependent configuration values.
83038b5c11030741f103c15741db74068ce099cb53Shri Borde     * Some of the values are used by the system in processing SMS or MMS messages. Others
84038b5c11030741f103c15741db74068ce099cb53Shri Borde     * are provided for the convenience of SMS applications.
85038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
86038b5c11030741f103c15741db74068ce099cb53Shri Borde
87038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
88038b5c11030741f103c15741db74068ce099cb53Shri Borde     * Whether to append transaction id to MMS WAP Push M-Notification.ind's content location URI
89038b5c11030741f103c15741db74068ce099cb53Shri Borde     * when constructing the download URL of a new MMS (boolean type)
90038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
913b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri    public static final String MMS_CONFIG_APPEND_TRANSACTION_ID =
923b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            CarrierConfigManager.KEY_MMS_APPEND_TRANSACTION_ID_BOOL;
93038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
94038b5c11030741f103c15741db74068ce099cb53Shri Borde     * Whether MMS is enabled for the current carrier (boolean type)
95038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
963b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri    public static final String
973b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri        MMS_CONFIG_MMS_ENABLED = CarrierConfigManager.KEY_MMS_MMS_ENABLED_BOOL;
98038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
99a28fa38c44f45a1abccc73a508fecf8462978b96Ye Wen     * Whether group MMS is enabled for the current carrier (boolean type)
100a28fa38c44f45a1abccc73a508fecf8462978b96Ye Wen     */
101731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri    public static final String
1023b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            MMS_CONFIG_GROUP_MMS_ENABLED = CarrierConfigManager.KEY_MMS_GROUP_MMS_ENABLED_BOOL;
103a28fa38c44f45a1abccc73a508fecf8462978b96Ye Wen    /**
104731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri     * If this is enabled, M-NotifyResp.ind should be sent to the WAP Push content location instead
105731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri     * of the default MMSC (boolean type)
106038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
107731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri    public static final String MMS_CONFIG_NOTIFY_WAP_MMSC_ENABLED =
1083b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            CarrierConfigManager.KEY_MMS_NOTIFY_WAP_MMSC_ENABLED_BOOL;
109038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
110038b5c11030741f103c15741db74068ce099cb53Shri Borde     * Whether alias is enabled (boolean type)
111038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
112731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri    public static final String
1133b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            MMS_CONFIG_ALIAS_ENABLED = CarrierConfigManager.KEY_MMS_ALIAS_ENABLED_BOOL;
114038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
115038b5c11030741f103c15741db74068ce099cb53Shri Borde     * Whether audio is allowed to be attached for MMS messages (boolean type)
116038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
117731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri    public static final String
1183b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            MMS_CONFIG_ALLOW_ATTACH_AUDIO = CarrierConfigManager.KEY_MMS_ALLOW_ATTACH_AUDIO_BOOL;
119038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
120038b5c11030741f103c15741db74068ce099cb53Shri Borde     * Whether multipart SMS is enabled (boolean type)
121038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
1223b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri    public static final String MMS_CONFIG_MULTIPART_SMS_ENABLED =
1233b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            CarrierConfigManager.KEY_MMS_MULTIPART_SMS_ENABLED_BOOL;
124038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
125038b5c11030741f103c15741db74068ce099cb53Shri Borde     * Whether SMS delivery report is enabled (boolean type)
126038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
127731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri    public static final String MMS_CONFIG_SMS_DELIVERY_REPORT_ENABLED =
1283b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            CarrierConfigManager.KEY_MMS_SMS_DELIVERY_REPORT_ENABLED_BOOL;
129038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
130038b5c11030741f103c15741db74068ce099cb53Shri Borde     * Whether content-disposition field should be expected in an MMS PDU (boolean type)
131038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
132038b5c11030741f103c15741db74068ce099cb53Shri Borde    public static final String MMS_CONFIG_SUPPORT_MMS_CONTENT_DISPOSITION =
1333b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            CarrierConfigManager.KEY_MMS_SUPPORT_MMS_CONTENT_DISPOSITION_BOOL;
134038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
135038b5c11030741f103c15741db74068ce099cb53Shri Borde     * Whether multipart SMS should be sent as separate messages
136038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
137038b5c11030741f103c15741db74068ce099cb53Shri Borde    public static final String MMS_CONFIG_SEND_MULTIPART_SMS_AS_SEPARATE_MESSAGES =
1383b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            CarrierConfigManager.KEY_MMS_SEND_MULTIPART_SMS_AS_SEPARATE_MESSAGES_BOOL;
139038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
140038b5c11030741f103c15741db74068ce099cb53Shri Borde     * Whether MMS read report is enabled (boolean type)
141038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
142731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri    public static final String MMS_CONFIG_MMS_READ_REPORT_ENABLED =
1433b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            CarrierConfigManager.KEY_MMS_MMS_READ_REPORT_ENABLED_BOOL;
144038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
145038b5c11030741f103c15741db74068ce099cb53Shri Borde     * Whether MMS delivery report is enabled (boolean type)
146038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
147731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri    public static final String MMS_CONFIG_MMS_DELIVERY_REPORT_ENABLED =
1483b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            CarrierConfigManager.KEY_MMS_MMS_DELIVERY_REPORT_ENABLED_BOOL;
149038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
150038b5c11030741f103c15741db74068ce099cb53Shri Borde     * Max MMS message size in bytes (int type)
151038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
152731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri    public static final String
1533b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            MMS_CONFIG_MAX_MESSAGE_SIZE = CarrierConfigManager.KEY_MMS_MAX_MESSAGE_SIZE_INT;
154038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
155038b5c11030741f103c15741db74068ce099cb53Shri Borde     * Max MMS image width (int type)
156038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
157731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri    public static final String
1583b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            MMS_CONFIG_MAX_IMAGE_WIDTH = CarrierConfigManager.KEY_MMS_MAX_IMAGE_WIDTH_INT;
159038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
160038b5c11030741f103c15741db74068ce099cb53Shri Borde     * Max MMS image height (int type)
161038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
162731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri    public static final String
1633b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            MMS_CONFIG_MAX_IMAGE_HEIGHT = CarrierConfigManager.KEY_MMS_MAX_IMAGE_HEIGHT_INT;
164038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
165038b5c11030741f103c15741db74068ce099cb53Shri Borde     * Limit of recipients of MMS messages (int type)
166038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
167731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri    public static final String
1683b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            MMS_CONFIG_RECIPIENT_LIMIT = CarrierConfigManager.KEY_MMS_RECIPIENT_LIMIT_INT;
169038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
170038b5c11030741f103c15741db74068ce099cb53Shri Borde     * Min alias character count (int type)
171038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
172731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri    public static final String
1733b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            MMS_CONFIG_ALIAS_MIN_CHARS = CarrierConfigManager.KEY_MMS_ALIAS_MIN_CHARS_INT;
174038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
175038b5c11030741f103c15741db74068ce099cb53Shri Borde     * Max alias character count (int type)
176038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
177731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri    public static final String
1783b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            MMS_CONFIG_ALIAS_MAX_CHARS = CarrierConfigManager.KEY_MMS_ALIAS_MAX_CHARS_INT;
179038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
180731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri     * When the number of parts of a multipart SMS reaches this threshold, it should be converted
181731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri     * into an MMS (int type)
182038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
183731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri    public static final String MMS_CONFIG_SMS_TO_MMS_TEXT_THRESHOLD =
1843b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            CarrierConfigManager.KEY_MMS_SMS_TO_MMS_TEXT_THRESHOLD_INT;
185038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
186038b5c11030741f103c15741db74068ce099cb53Shri Borde     * Some carriers require SMS to be converted into MMS when text length reaches this threshold
187038b5c11030741f103c15741db74068ce099cb53Shri Borde     * (int type)
188038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
189038b5c11030741f103c15741db74068ce099cb53Shri Borde    public static final String MMS_CONFIG_SMS_TO_MMS_TEXT_LENGTH_THRESHOLD =
1903b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            CarrierConfigManager.KEY_MMS_SMS_TO_MMS_TEXT_LENGTH_THRESHOLD_INT;
191038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
192038b5c11030741f103c15741db74068ce099cb53Shri Borde     * Max message text size (int type)
193038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
1943b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri    public static final String MMS_CONFIG_MESSAGE_TEXT_MAX_SIZE =
1953b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            CarrierConfigManager.KEY_MMS_MESSAGE_TEXT_MAX_SIZE_INT;
196038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
197038b5c11030741f103c15741db74068ce099cb53Shri Borde     * Max message subject length (int type)
198038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
199731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri    public static final String
2003b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            MMS_CONFIG_SUBJECT_MAX_LENGTH = CarrierConfigManager.KEY_MMS_SUBJECT_MAX_LENGTH_INT;
201038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
202038b5c11030741f103c15741db74068ce099cb53Shri Borde     * MMS HTTP socket timeout in milliseconds (int type)
203038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
204731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri    public static final String
2053b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            MMS_CONFIG_HTTP_SOCKET_TIMEOUT = CarrierConfigManager.KEY_MMS_HTTP_SOCKET_TIMEOUT_INT;
206038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
207038b5c11030741f103c15741db74068ce099cb53Shri Borde     * The name of the UA Prof URL HTTP header for MMS HTTP request (String type)
208038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
209731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri    public static final String
2103b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            MMS_CONFIG_UA_PROF_TAG_NAME = CarrierConfigManager.KEY_MMS_UA_PROF_TAG_NAME_STRING;
211038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
212038b5c11030741f103c15741db74068ce099cb53Shri Borde     * The User-Agent header value for MMS HTTP request (String type)
213038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
2143b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri    public static final String
2153b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            MMS_CONFIG_USER_AGENT = CarrierConfigManager.KEY_MMS_USER_AGENT_STRING;
216038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
217038b5c11030741f103c15741db74068ce099cb53Shri Borde     * The UA Profile URL header value for MMS HTTP request (String type)
218038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
2193b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri    public static final String
2203b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            MMS_CONFIG_UA_PROF_URL = CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING;
221038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
222038b5c11030741f103c15741db74068ce099cb53Shri Borde     * A list of HTTP headers to add to MMS HTTP request, separated by "|" (String type)
223038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
2243b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri    public static final String
2253b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            MMS_CONFIG_HTTP_PARAMS = CarrierConfigManager.KEY_MMS_HTTP_PARAMS_STRING;
226038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
227038b5c11030741f103c15741db74068ce099cb53Shri Borde     * Email gateway number (String type)
228038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
2293b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri    public static final String MMS_CONFIG_EMAIL_GATEWAY_NUMBER =
2303b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            CarrierConfigManager.KEY_MMS_EMAIL_GATEWAY_NUMBER_STRING;
231038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
232038b5c11030741f103c15741db74068ce099cb53Shri Borde     * The suffix to append to the NAI header value for MMS HTTP request (String type)
233038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
2343b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri    public static final String
2353b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            MMS_CONFIG_NAI_SUFFIX = CarrierConfigManager.KEY_MMS_NAI_SUFFIX_STRING;
2365a2f604ccf1e55db3d617a06375bddcf56d96b4cTom Taylor    /**
237731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri     * If true, show the cell broadcast (amber alert) in the SMS settings. Some carriers don't want
238731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri     * this shown. (Boolean type)
2395a2f604ccf1e55db3d617a06375bddcf56d96b4cTom Taylor     */
2409dbb6ad72f064bde732111fe40ded4543b34295eYe Wen    public static final String MMS_CONFIG_SHOW_CELL_BROADCAST_APP_LINKS =
2413b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            CarrierConfigManager.KEY_MMS_SHOW_CELL_BROADCAST_APP_LINKS_BOOL;
242731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri    /**
243731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri     * Whether the carrier MMSC supports charset field in Content-Type header. If this is false,
244731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri     * then we don't add "charset" to "Content-Type"
245731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri     */
246731a59fc17aa2865871a813a36f7d07aac85a626Jonathan Basseri    public static final String MMS_CONFIG_SUPPORT_HTTP_CHARSET_HEADER =
2473b413ed5184da3253ab7feb1081c221e0fbced28Jonathan Basseri            CarrierConfigManager.KEY_MMS_SUPPORT_HTTP_CHARSET_HEADER_BOOL;
24831d02efb89a5b16679b67d8487a3c4c4c907dd7aPauloftheWest    /*
24931d02efb89a5b16679b67d8487a3c4c4c907dd7aPauloftheWest     * Forwarded constants from SimDialogActivity.
25031d02efb89a5b16679b67d8487a3c4c4c907dd7aPauloftheWest     */
25131d02efb89a5b16679b67d8487a3c4c4c907dd7aPauloftheWest    private static String DIALOG_TYPE_KEY = "dialog_type";
25231d02efb89a5b16679b67d8487a3c4c4c907dd7aPauloftheWest    private static final int SMS_PICK = 2;
253c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
254c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
255c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Send a text based SMS.
256c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
25729305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main     * <p class="note"><strong>Note:</strong> Using this method requires that your app has the
25829305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main     * {@link android.Manifest.permission#SEND_SMS} permission.</p>
25929305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main     *
26029305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main     * <p class="note"><strong>Note:</strong> Beginning with Android 4.4 (API level 19), if
26129305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main     * <em>and only if</em> an app is not selected as the default SMS app, the system automatically
26229305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main     * writes messages sent using this method to the SMS Provider (the default SMS app is always
26329305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main     * responsible for writing its sent messages to the SMS Provider). For information about
26429305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main     * how to behave as the default SMS app, see {@link android.provider.Telephony}.</p>
26529305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main     *
26629305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main     *
267c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param destinationAddress the address to send the message to
268c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param scAddress is the service center address or null to use
269c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  the current default SMSC
270c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param text the body of the message to send
271c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param sentIntent if not NULL this <code>PendingIntent</code> is
272c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  broadcast when the message is successfully sent, or failed.
273c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  The result code will be <code>Activity.RESULT_OK</code> for success,
274c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  or one of these errors:<br>
275c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  <code>RESULT_ERROR_GENERIC_FAILURE</code><br>
276c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  <code>RESULT_ERROR_RADIO_OFF</code><br>
277c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  <code>RESULT_ERROR_NULL_PDU</code><br>
278c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  For <code>RESULT_ERROR_GENERIC_FAILURE</code> the sentIntent may include
279c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  the extra "errorCode" containing a radio technology specific value,
280c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  generally only useful for troubleshooting.<br>
281c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  The per-application based SMS control checks sentIntent. If sentIntent
282c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  is NULL the caller will be checked against all unknown applications,
283c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  which cause smaller number of SMS to be sent in checking period.
284c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param deliveryIntent if not NULL this <code>PendingIntent</code> is
285c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  broadcast when the message is delivered to the recipient.  The
286c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  raw pdu of the status report is in the extended data ("pdu").
287c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
288c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @throws IllegalArgumentException if destinationAddress or text are empty
289c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
290c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public void sendTextMessage(
291c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            String destinationAddress, String scAddress, String text,
292c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            PendingIntent sentIntent, PendingIntent deliveryIntent) {
293a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang        sendTextMessageInternal(destinationAddress, scAddress, text,
294a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang            sentIntent, deliveryIntent, true /* persistMessageForCarrierApp*/);
295a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang    }
296a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang
297a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang    private void sendTextMessageInternal(String destinationAddress, String scAddress,
298a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang            String text, PendingIntent sentIntent, PendingIntent deliveryIntent,
299a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang            boolean persistMessageForCarrierApp) {
300c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        if (TextUtils.isEmpty(destinationAddress)) {
301c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            throw new IllegalArgumentException("Invalid destinationAddress");
302c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
303c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
304c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        if (TextUtils.isEmpty(text)) {
305c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            throw new IllegalArgumentException("Invalid message body");
306c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
307c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
308c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        try {
3097961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski            ISms iccISms = getISmsServiceOrThrow();
3109dbb6ad72f064bde732111fe40ded4543b34295eYe Wen            iccISms.sendTextForSubscriber(getSubscriptionId(), ActivityThread.currentPackageName(),
311f5c3780bb4e11d6f88ca9b9fee19e7b279285bdeTom Taylor                    destinationAddress,
312a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang                    scAddress, text, sentIntent, deliveryIntent,
313a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang                    persistMessageForCarrierApp);
314c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        } catch (RemoteException ex) {
315c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            // ignore it
316c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
317c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
318c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
319c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
320a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang     * Send a text based SMS without writing it into the SMS Provider.
321a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang     *
322a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang     * <p>Only the carrier app can call this method.</p>
323a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang     *
324a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang     * @see #sendTextMessage(String, String, String, PendingIntent, PendingIntent)
325a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang     * @hide
326a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang     */
327a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang    public void sendTextMessageWithoutPersisting(
328a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang            String destinationAddress, String scAddress, String text,
329a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang            PendingIntent sentIntent, PendingIntent deliveryIntent) {
330a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang        sendTextMessageInternal(destinationAddress, scAddress, text,
331a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang            sentIntent, deliveryIntent, false /* persistMessageForCarrierApp*/);
332a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang    }
333a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang
334a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang    /**
335c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen     * A variant of {@link SmsManager#sendTextMessage} that allows self to be the caller. This is
336c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen     * for internal use only.
337c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen     *
338c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen     * @hide
339c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen     */
340c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen    public void sendTextMessageWithSelfPermissions(
341c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen            String destinationAddress, String scAddress, String text,
342c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen            PendingIntent sentIntent, PendingIntent deliveryIntent) {
343c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen        if (TextUtils.isEmpty(destinationAddress)) {
344c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen            throw new IllegalArgumentException("Invalid destinationAddress");
345c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen        }
346c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen
347c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen        if (TextUtils.isEmpty(text)) {
348c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen            throw new IllegalArgumentException("Invalid message body");
349c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen        }
350c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen
351c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen        try {
352c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen            ISms iccISms = getISmsServiceOrThrow();
353c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen            iccISms.sendTextForSubscriberWithSelfPermissions(getSubscriptionId(),
354c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen                    ActivityThread.currentPackageName(),
355c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen                    destinationAddress,
356c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen                    scAddress, text, sentIntent, deliveryIntent);
357c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen        } catch (RemoteException ex) {
358c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen            // ignore it
359c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen        }
360c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen    }
361c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen
362c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen    /**
36363418bbd2a9d7cc88ae24cc5ae776c01d688fc3aAnil Muthineni     * Inject an SMS PDU into the android application framework.
36463418bbd2a9d7cc88ae24cc5ae776c01d688fc3aAnil Muthineni     *
3655889fd6e26caa9b8164666cd8c29df973fd7c265Shishir Agrawal     * The caller should have carrier privileges.
36622604f3bafc0f9348e175e8e71d6eb2d3b45a62dJunda Liu     * @see android.telephony.TelephonyManager#hasCarrierPrivileges
3675889fd6e26caa9b8164666cd8c29df973fd7c265Shishir Agrawal     *
36863418bbd2a9d7cc88ae24cc5ae776c01d688fc3aAnil Muthineni     * @param pdu is the byte array of pdu to be injected into android application framework
36963418bbd2a9d7cc88ae24cc5ae776c01d688fc3aAnil Muthineni     * @param format is the format of SMS pdu (3gpp or 3gpp2)
37063418bbd2a9d7cc88ae24cc5ae776c01d688fc3aAnil Muthineni     * @param receivedIntent if not NULL this <code>PendingIntent</code> is
37163418bbd2a9d7cc88ae24cc5ae776c01d688fc3aAnil Muthineni     *  broadcast when the message is successfully received by the
3728215559cd1141ac90c478fd3df75e43c9d755c6cCheuksan Wang     *  android application framework, or failed. This intent is broadcasted at
37363418bbd2a9d7cc88ae24cc5ae776c01d688fc3aAnil Muthineni     *  the same time an SMS received from radio is acknowledged back.
3748215559cd1141ac90c478fd3df75e43c9d755c6cCheuksan Wang     *  The result code will be <code>RESULT_SMS_HANDLED</code> for success, or
3758215559cd1141ac90c478fd3df75e43c9d755c6cCheuksan Wang     *  <code>RESULT_SMS_GENERIC_ERROR</code> for error.
37663418bbd2a9d7cc88ae24cc5ae776c01d688fc3aAnil Muthineni     *
3778215559cd1141ac90c478fd3df75e43c9d755c6cCheuksan Wang     * @throws IllegalArgumentException if format is not one of 3gpp and 3gpp2.
37863418bbd2a9d7cc88ae24cc5ae776c01d688fc3aAnil Muthineni     */
37963418bbd2a9d7cc88ae24cc5ae776c01d688fc3aAnil Muthineni    public void injectSmsPdu(byte[] pdu, String format, PendingIntent receivedIntent) {
38063418bbd2a9d7cc88ae24cc5ae776c01d688fc3aAnil Muthineni        if (!format.equals(SmsMessage.FORMAT_3GPP) && !format.equals(SmsMessage.FORMAT_3GPP2)) {
38163418bbd2a9d7cc88ae24cc5ae776c01d688fc3aAnil Muthineni            // Format must be either 3gpp or 3gpp2.
38263418bbd2a9d7cc88ae24cc5ae776c01d688fc3aAnil Muthineni            throw new IllegalArgumentException(
38363418bbd2a9d7cc88ae24cc5ae776c01d688fc3aAnil Muthineni                    "Invalid pdu format. format must be either 3gpp or 3gpp2");
38463418bbd2a9d7cc88ae24cc5ae776c01d688fc3aAnil Muthineni        }
38563418bbd2a9d7cc88ae24cc5ae776c01d688fc3aAnil Muthineni        try {
38663418bbd2a9d7cc88ae24cc5ae776c01d688fc3aAnil Muthineni            ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
38763418bbd2a9d7cc88ae24cc5ae776c01d688fc3aAnil Muthineni            if (iccISms != null) {
38894de93efcd4d4b879c14c443f7dfaabb5a9ce4a9Cheuksan Wang                iccISms.injectSmsPduForSubscriber(
38994de93efcd4d4b879c14c443f7dfaabb5a9ce4a9Cheuksan Wang                        getSubscriptionId(), pdu, format, receivedIntent);
39063418bbd2a9d7cc88ae24cc5ae776c01d688fc3aAnil Muthineni            }
39163418bbd2a9d7cc88ae24cc5ae776c01d688fc3aAnil Muthineni        } catch (RemoteException ex) {
39263418bbd2a9d7cc88ae24cc5ae776c01d688fc3aAnil Muthineni          // ignore it
39363418bbd2a9d7cc88ae24cc5ae776c01d688fc3aAnil Muthineni        }
39463418bbd2a9d7cc88ae24cc5ae776c01d688fc3aAnil Muthineni    }
39563418bbd2a9d7cc88ae24cc5ae776c01d688fc3aAnil Muthineni
39663418bbd2a9d7cc88ae24cc5ae776c01d688fc3aAnil Muthineni    /**
397c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Divide a message text into several fragments, none bigger than
398c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * the maximum SMS message size.
399c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
400c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param text the original message.  Must not be null.
401c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return an <code>ArrayList</code> of strings that, in order,
402c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *   comprise the original message
403910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks     *
404910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks     * @throws IllegalArgumentException if text is null
405c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
406c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public ArrayList<String> divideMessage(String text) {
407910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks        if (null == text) {
408910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks            throw new IllegalArgumentException("text is null");
409910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks        }
410c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return SmsMessage.fragmentText(text);
411c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
412c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
413c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
414c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Send a multi-part text based SMS.  The callee should have already
415c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * divided the message into correctly sized parts by calling
416c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * <code>divideMessage</code>.
417c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
41829305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main     * <p class="note"><strong>Note:</strong> Using this method requires that your app has the
41929305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main     * {@link android.Manifest.permission#SEND_SMS} permission.</p>
42029305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main     *
42129305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main     * <p class="note"><strong>Note:</strong> Beginning with Android 4.4 (API level 19), if
42229305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main     * <em>and only if</em> an app is not selected as the default SMS app, the system automatically
42329305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main     * writes messages sent using this method to the SMS Provider (the default SMS app is always
42429305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main     * responsible for writing its sent messages to the SMS Provider). For information about
42529305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main     * how to behave as the default SMS app, see {@link android.provider.Telephony}.</p>
42629305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main     *
427c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param destinationAddress the address to send the message to
428c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param scAddress is the service center address or null to use
429c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *   the current default SMSC
430c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param parts an <code>ArrayList</code> of strings that, in order,
431c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *   comprise the original message
432c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param sentIntents if not null, an <code>ArrayList</code> of
433c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *   <code>PendingIntent</code>s (one for each message part) that is
434c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *   broadcast when the corresponding message part has been sent.
435c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *   The result code will be <code>Activity.RESULT_OK</code> for success,
436c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *   or one of these errors:<br>
437c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *   <code>RESULT_ERROR_GENERIC_FAILURE</code><br>
438c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *   <code>RESULT_ERROR_RADIO_OFF</code><br>
439c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *   <code>RESULT_ERROR_NULL_PDU</code><br>
440c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *   For <code>RESULT_ERROR_GENERIC_FAILURE</code> each sentIntent may include
441c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *   the extra "errorCode" containing a radio technology specific value,
442c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *   generally only useful for troubleshooting.<br>
443c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *   The per-application based SMS control checks sentIntent. If sentIntent
444c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *   is NULL the caller will be checked against all unknown applications,
445c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *   which cause smaller number of SMS to be sent in checking period.
446c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param deliveryIntents if not null, an <code>ArrayList</code> of
447c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *   <code>PendingIntent</code>s (one for each message part) that is
448c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *   broadcast when the corresponding message part has been delivered
449c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *   to the recipient.  The raw pdu of the status report is in the
450c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *   extended data ("pdu").
451c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
452c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @throws IllegalArgumentException if destinationAddress or data are empty
453c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
454c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public void sendMultipartTextMessage(
455c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            String destinationAddress, String scAddress, ArrayList<String> parts,
456c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents) {
457a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang        sendMultipartTextMessageInternal(destinationAddress, scAddress, parts,
458a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang              sentIntents, deliveryIntents, true /* persistMessageForCarrierApp*/);
459a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang    }
460a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang
461a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang    private void sendMultipartTextMessageInternal(
462a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang            String destinationAddress, String scAddress, ArrayList<String> parts,
463a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang            ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents,
464a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang            boolean persistMessageForCarrierApp) {
465c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        if (TextUtils.isEmpty(destinationAddress)) {
466c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            throw new IllegalArgumentException("Invalid destinationAddress");
467c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
468c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        if (parts == null || parts.size() < 1) {
469c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            throw new IllegalArgumentException("Invalid message body");
470c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
471c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
472c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        if (parts.size() > 1) {
473c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            try {
4747961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski                ISms iccISms = getISmsServiceOrThrow();
4759dbb6ad72f064bde732111fe40ded4543b34295eYe Wen                iccISms.sendMultipartTextForSubscriber(getSubscriptionId(),
476f5c3780bb4e11d6f88ca9b9fee19e7b279285bdeTom Taylor                        ActivityThread.currentPackageName(),
4777961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski                        destinationAddress, scAddress, parts,
478a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang                        sentIntents, deliveryIntents, persistMessageForCarrierApp);
479c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            } catch (RemoteException ex) {
480c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                // ignore it
481c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            }
482c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        } else {
483c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            PendingIntent sentIntent = null;
484c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            PendingIntent deliveryIntent = null;
485c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            if (sentIntents != null && sentIntents.size() > 0) {
486c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                sentIntent = sentIntents.get(0);
487c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            }
488c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            if (deliveryIntents != null && deliveryIntents.size() > 0) {
489c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                deliveryIntent = deliveryIntents.get(0);
490c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            }
491c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            sendTextMessage(destinationAddress, scAddress, parts.get(0),
492c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    sentIntent, deliveryIntent);
493c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
494c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
495c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
496c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
497a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang     * Send a multi-part text based SMS without writing it into the SMS Provider.
498a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang     *
499a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang     * <p>Only the carrier app can call this method.</p>
500a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang     *
501a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang     * @see #sendMultipartTextMessage(String, String, ArrayList, ArrayList, ArrayList)
502a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang     * @hide
503a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang     **/
504a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang    public void sendMultipartTextMessageWithoutPersisting(
505a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang            String destinationAddress, String scAddress, ArrayList<String> parts,
506a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang            ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents) {
507a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang        sendMultipartTextMessageInternal(destinationAddress, scAddress, parts,
508a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang            sentIntents, deliveryIntents, false /* persistMessageForCarrierApp*/);
509a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang    }
510a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang
511a8f8c5a113a66de4854f4fb13a5825eb0705bd59Ji Yang    /**
512c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Send a data based SMS to a specific application port.
513c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
51429305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main     * <p class="note"><strong>Note:</strong> Using this method requires that your app has the
51529305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main     * {@link android.Manifest.permission#SEND_SMS} permission.</p>
51629305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main     *
517c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param destinationAddress the address to send the message to
518c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param scAddress is the service center address or null to use
519c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  the current default SMSC
520c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param destinationPort the port to deliver the message to
521c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param data the body of the message to send
522c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param sentIntent if not NULL this <code>PendingIntent</code> is
523c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  broadcast when the message is successfully sent, or failed.
524c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  The result code will be <code>Activity.RESULT_OK</code> for success,
525c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  or one of these errors:<br>
526c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  <code>RESULT_ERROR_GENERIC_FAILURE</code><br>
527c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  <code>RESULT_ERROR_RADIO_OFF</code><br>
528c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  <code>RESULT_ERROR_NULL_PDU</code><br>
529c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  For <code>RESULT_ERROR_GENERIC_FAILURE</code> the sentIntent may include
530c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  the extra "errorCode" containing a radio technology specific value,
531c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  generally only useful for troubleshooting.<br>
532c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  The per-application based SMS control checks sentIntent. If sentIntent
533c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  is NULL the caller will be checked against all unknown applications,
534c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  which cause smaller number of SMS to be sent in checking period.
535c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param deliveryIntent if not NULL this <code>PendingIntent</code> is
536c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  broadcast when the message is delivered to the recipient.  The
537c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *  raw pdu of the status report is in the extended data ("pdu").
538c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
539c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @throws IllegalArgumentException if destinationAddress or data are empty
540c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
541c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public void sendDataMessage(
542c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            String destinationAddress, String scAddress, short destinationPort,
543c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent) {
544c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        if (TextUtils.isEmpty(destinationAddress)) {
545c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            throw new IllegalArgumentException("Invalid destinationAddress");
546c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
547c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
548c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        if (data == null || data.length == 0) {
549c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            throw new IllegalArgumentException("Invalid message data");
550c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
551c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
552c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        try {
5537961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski            ISms iccISms = getISmsServiceOrThrow();
5549dbb6ad72f064bde732111fe40ded4543b34295eYe Wen            iccISms.sendDataForSubscriber(getSubscriptionId(), ActivityThread.currentPackageName(),
5557961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski                    destinationAddress, scAddress, destinationPort & 0xFFFF,
5567961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski                    data, sentIntent, deliveryIntent);
557c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        } catch (RemoteException ex) {
558c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            // ignore it
559c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
560c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
561c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
562c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
563c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen     * A variant of {@link SmsManager#sendDataMessage} that allows self to be the caller. This is
564c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen     * for internal use only.
565c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen     *
566c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen     * @hide
567c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen     */
568c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen    public void sendDataMessageWithSelfPermissions(
569c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen            String destinationAddress, String scAddress, short destinationPort,
570c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen            byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent) {
571c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen        if (TextUtils.isEmpty(destinationAddress)) {
572c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen            throw new IllegalArgumentException("Invalid destinationAddress");
573c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen        }
574c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen
575c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen        if (data == null || data.length == 0) {
576c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen            throw new IllegalArgumentException("Invalid message data");
577c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen        }
578c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen
579c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen        try {
580c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen            ISms iccISms = getISmsServiceOrThrow();
581c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen            iccISms.sendDataForSubscriberWithSelfPermissions(getSubscriptionId(),
582c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen                    ActivityThread.currentPackageName(), destinationAddress, scAddress,
583c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen                    destinationPort & 0xFFFF, data, sentIntent, deliveryIntent);
584c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen        } catch (RemoteException ex) {
585c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen            // ignore it
586c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen        }
587c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen    }
588c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen
589c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen
590c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen
591c55f67e3fa488c5f8aa90fda1ae43ef9d32cef52Nancy Chen    /**
5929dbb6ad72f064bde732111fe40ded4543b34295eYe Wen     * Get the SmsManager associated with the default subscription id. The instance will always be
5939dbb6ad72f064bde732111fe40ded4543b34295eYe Wen     * associated with the default subscription id, even if the default subscription id is changed.
594622829e128850899e64b049931de2883f17cf4ddTom Taylor     *
5959dbb6ad72f064bde732111fe40ded4543b34295eYe Wen     * @return the SmsManager associated with the default subscription id
596622829e128850899e64b049931de2883f17cf4ddTom Taylor     */
597c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public static SmsManager getDefault() {
598c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return sInstance;
599c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
600c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
601038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
6029dbb6ad72f064bde732111fe40ded4543b34295eYe Wen     * Get the the instance of the SmsManager associated with a particular subscription id
603038b5c11030741f103c15741db74068ce099cb53Shri Borde     *
6049dbb6ad72f064bde732111fe40ded4543b34295eYe Wen     * @param subId an SMS subscription id, typically accessed using
605541eac28e7e7eda38376e59e5a658cb3f8948f5fShri Borde     *   {@link android.telephony.SubscriptionManager}
606038b5c11030741f103c15741db74068ce099cb53Shri Borde     * @return the instance of the SmsManager associated with subId
607038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
6089dbb6ad72f064bde732111fe40ded4543b34295eYe Wen    public static SmsManager getSmsManagerForSubscriptionId(int subId) {
6090508a41ae6be773cb1632006b5d3669ee5a1aa13Shri Borde        // TODO(shri): Add javadoc link once SubscriptionManager is made public api
610038b5c11030741f103c15741db74068ce099cb53Shri Borde        synchronized(sLockObject) {
611038b5c11030741f103c15741db74068ce099cb53Shri Borde            SmsManager smsManager = sSubInstances.get(subId);
612038b5c11030741f103c15741db74068ce099cb53Shri Borde            if (smsManager == null) {
613038b5c11030741f103c15741db74068ce099cb53Shri Borde                smsManager = new SmsManager(subId);
614038b5c11030741f103c15741db74068ce099cb53Shri Borde                sSubInstances.put(subId, smsManager);
615038b5c11030741f103c15741db74068ce099cb53Shri Borde            }
616038b5c11030741f103c15741db74068ce099cb53Shri Borde            return smsManager;
617038b5c11030741f103c15741db74068ce099cb53Shri Borde        }
618038b5c11030741f103c15741db74068ce099cb53Shri Borde    }
619038b5c11030741f103c15741db74068ce099cb53Shri Borde
620b237a11044ed842d2865ff8c8716befb06b6ca25Wink Saville    private SmsManager(int subId) {
621038b5c11030741f103c15741db74068ce099cb53Shri Borde        mSubId = subId;
622038b5c11030741f103c15741db74068ce099cb53Shri Borde    }
623038b5c11030741f103c15741db74068ce099cb53Shri Borde
624038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
6259dbb6ad72f064bde732111fe40ded4543b34295eYe Wen     * Get the associated subscription id. If the instance was returned by {@link #getDefault()},
6269dbb6ad72f064bde732111fe40ded4543b34295eYe Wen     * then this method may return different values at different points in time (if the user
627dfdf9c40ebaaed15b5020ad6bce898fadd32dd58Wink Saville     * changes the default subscription id). It will return < 0 if the default subscription id
628dfdf9c40ebaaed15b5020ad6bce898fadd32dd58Wink Saville     * cannot be determined.
629038b5c11030741f103c15741db74068ce099cb53Shri Borde     *
63031d02efb89a5b16679b67d8487a3c4c4c907dd7aPauloftheWest     * Additionally, to support legacy applications that are not multi-SIM aware,
63131d02efb89a5b16679b67d8487a3c4c4c907dd7aPauloftheWest     * if the following are true:
63231d02efb89a5b16679b67d8487a3c4c4c907dd7aPauloftheWest     *     - We are using a multi-SIM device
63331d02efb89a5b16679b67d8487a3c4c4c907dd7aPauloftheWest     *     - A default SMS SIM has not been selected
63431d02efb89a5b16679b67d8487a3c4c4c907dd7aPauloftheWest     *     - At least one SIM subscription is available
63531d02efb89a5b16679b67d8487a3c4c4c907dd7aPauloftheWest     * then ask the user to set the default SMS SIM.
63631d02efb89a5b16679b67d8487a3c4c4c907dd7aPauloftheWest     *
6379dbb6ad72f064bde732111fe40ded4543b34295eYe Wen     * @return associated subscription id
638038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
6399dbb6ad72f064bde732111fe40ded4543b34295eYe Wen    public int getSubscriptionId() {
64031d02efb89a5b16679b67d8487a3c4c4c907dd7aPauloftheWest        final int subId = (mSubId == DEFAULT_SUBSCRIPTION_ID)
64131d02efb89a5b16679b67d8487a3c4c4c907dd7aPauloftheWest                ? getDefaultSmsSubscriptionId() : mSubId;
642f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan        boolean isSmsSimPickActivityNeeded = false;
64331d02efb89a5b16679b67d8487a3c4c4c907dd7aPauloftheWest        final Context context = ActivityThread.currentApplication().getApplicationContext();
644f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan        try {
645f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan            ISms iccISms = getISmsService();
646f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan            if (iccISms != null) {
647f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan                isSmsSimPickActivityNeeded = iccISms.isSmsSimPickActivityNeeded(subId);
64831d02efb89a5b16679b67d8487a3c4c4c907dd7aPauloftheWest            }
649f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan        } catch (RemoteException ex) {
650f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan            Log.e(TAG, "Exception in getSubscriptionId");
651f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan        }
65231d02efb89a5b16679b67d8487a3c4c4c907dd7aPauloftheWest
653f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan        if (isSmsSimPickActivityNeeded) {
654f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan            Log.d(TAG, "getSubscriptionId isSmsSimPickActivityNeeded is true");
655f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan            // ask the user for a default SMS SIM.
656f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan            Intent intent = new Intent();
657f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan            intent.setClassName("com.android.settings",
658f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan                    "com.android.settings.sim.SimDialogActivity");
659f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
660f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan            intent.putExtra(DIALOG_TYPE_KEY, SMS_PICK);
661f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan            try {
662f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan                context.startActivity(intent);
663f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan            } catch (ActivityNotFoundException anfe) {
664f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan                // If Settings is not installed, only log the error as we do not want to break
665f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan                // legacy applications.
666f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan                Log.e(TAG, "Unable to launch Settings application.");
66731d02efb89a5b16679b67d8487a3c4c4c907dd7aPauloftheWest            }
668038b5c11030741f103c15741db74068ce099cb53Shri Borde        }
66931d02efb89a5b16679b67d8487a3c4c4c907dd7aPauloftheWest
67031d02efb89a5b16679b67d8487a3c4c4c907dd7aPauloftheWest        return subId;
671c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
672c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
673c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
6747961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski     * Returns the ISms service, or throws an UnsupportedOperationException if
6757961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski     * the service does not exist.
6767961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski     */
6777961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski    private static ISms getISmsServiceOrThrow() {
6787961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski        ISms iccISms = getISmsService();
6797961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski        if (iccISms == null) {
6807961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski            throw new UnsupportedOperationException("Sms is not supported");
6817961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski        }
6827961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski        return iccISms;
6837961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski    }
6847961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski
6857961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski    private static ISms getISmsService() {
6867961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski        return ISms.Stub.asInterface(ServiceManager.getService("isms"));
6877961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski    }
6887961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski
6897961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski    /**
690c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Copy a raw SMS PDU to the ICC.
691c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * ICC (Integrated Circuit Card) is the card of the device.
692c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * For example, this can be the SIM or USIM for GSM.
693c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
694c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param smsc the SMSC for this message, or NULL for the default SMSC
695c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param pdu the raw PDU to store
696c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param status message status (STATUS_ON_ICC_READ, STATUS_ON_ICC_UNREAD,
697c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *               STATUS_ON_ICC_SENT, STATUS_ON_ICC_UNSENT)
698c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return true for success
699c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
700910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks     * @throws IllegalArgumentException if pdu is NULL
701c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * {@hide}
702c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
703a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    public boolean copyMessageToIcc(byte[] smsc, byte[] pdu,int status) {
704c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        boolean success = false;
705c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
706910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks        if (null == pdu) {
707910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks            throw new IllegalArgumentException("pdu is NULL");
708910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks        }
709c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        try {
7107961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski            ISms iccISms = getISmsService();
711c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            if (iccISms != null) {
7129dbb6ad72f064bde732111fe40ded4543b34295eYe Wen                success = iccISms.copyMessageToIccEfForSubscriber(getSubscriptionId(),
713f5c3780bb4e11d6f88ca9b9fee19e7b279285bdeTom Taylor                        ActivityThread.currentPackageName(),
7147fce994eb223105829becb6c26e3af7a9739752cDianne Hackborn                        status, pdu, smsc);
715c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            }
716c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        } catch (RemoteException ex) {
717c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            // ignore it
718c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
719c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
720c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return success;
721c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
722c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
723c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
724c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Delete the specified message from the ICC.
725c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * ICC (Integrated Circuit Card) is the card of the device.
726c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * For example, this can be the SIM or USIM for GSM.
727c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
728c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param messageIndex is the record index of the message on ICC
729c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return true for success
730c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
731c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * {@hide}
732c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
733c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public boolean
734c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    deleteMessageFromIcc(int messageIndex) {
735c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        boolean success = false;
736c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        byte[] pdu = new byte[IccConstants.SMS_RECORD_LENGTH-1];
737c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        Arrays.fill(pdu, (byte)0xff);
738c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
739c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        try {
7407961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski            ISms iccISms = getISmsService();
741c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            if (iccISms != null) {
7429dbb6ad72f064bde732111fe40ded4543b34295eYe Wen                success = iccISms.updateMessageOnIccEfForSubscriber(getSubscriptionId(),
743f5c3780bb4e11d6f88ca9b9fee19e7b279285bdeTom Taylor                        ActivityThread.currentPackageName(),
7447fce994eb223105829becb6c26e3af7a9739752cDianne Hackborn                        messageIndex, STATUS_ON_ICC_FREE, pdu);
745c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            }
746c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        } catch (RemoteException ex) {
747c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            // ignore it
748c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
749c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
750c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return success;
751c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
752c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
753c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
754c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Update the specified message on the ICC.
755c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * ICC (Integrated Circuit Card) is the card of the device.
756c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * For example, this can be the SIM or USIM for GSM.
757c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
758c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param messageIndex record index of message to update
759c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param newStatus new message status (STATUS_ON_ICC_READ,
760c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *                  STATUS_ON_ICC_UNREAD, STATUS_ON_ICC_SENT,
761c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *                  STATUS_ON_ICC_UNSENT, STATUS_ON_ICC_FREE)
762c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param pdu the raw PDU to store
763c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return true for success
764c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
765c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * {@hide}
766c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
767c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public boolean updateMessageOnIcc(int messageIndex, int newStatus, byte[] pdu) {
768c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        boolean success = false;
769c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
770c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        try {
7717961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski            ISms iccISms = getISmsService();
772c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            if (iccISms != null) {
7739dbb6ad72f064bde732111fe40ded4543b34295eYe Wen                success = iccISms.updateMessageOnIccEfForSubscriber(getSubscriptionId(),
774f5c3780bb4e11d6f88ca9b9fee19e7b279285bdeTom Taylor                        ActivityThread.currentPackageName(),
7757fce994eb223105829becb6c26e3af7a9739752cDianne Hackborn                        messageIndex, newStatus, pdu);
776c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            }
777c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        } catch (RemoteException ex) {
778c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            // ignore it
779c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
780c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
781c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return success;
782c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
783c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
784c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
785c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Retrieves all messages currently stored on ICC.
786c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * ICC (Integrated Circuit Card) is the card of the device.
787c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * For example, this can be the SIM or USIM for GSM.
788c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
789c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return <code>ArrayList</code> of <code>SmsMessage</code> objects
790c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
791c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * {@hide}
792c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
7939dbb6ad72f064bde732111fe40ded4543b34295eYe Wen    public ArrayList<SmsMessage> getAllMessagesFromIcc() {
794c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        List<SmsRawData> records = null;
795c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
796c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        try {
7977961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski            ISms iccISms = getISmsService();
798c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            if (iccISms != null) {
7999dbb6ad72f064bde732111fe40ded4543b34295eYe Wen                records = iccISms.getAllMessagesFromIccEfForSubscriber(
8009dbb6ad72f064bde732111fe40ded4543b34295eYe Wen                        getSubscriptionId(),
801f5c3780bb4e11d6f88ca9b9fee19e7b279285bdeTom Taylor                        ActivityThread.currentPackageName());
802c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            }
803c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        } catch (RemoteException ex) {
804c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            // ignore it
805c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
806c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
807c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return createMessageListFromRawRecords(records);
808c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
809c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
810c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
811c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Enable reception of cell broadcast (SMS-CB) messages with the given
812a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     * message identifier and RAN type. The RAN type specify this message ID
813a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     * belong to 3GPP (GSM) or 3GPP2(CDMA).Note that if two different clients
814a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     * enable the same message identifier, they must both disable it for the device to stop
815c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * receiving those messages. All received messages will be broadcast in an
816c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * intent with the action "android.provider.Telephony.SMS_CB_RECEIVED".
817c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Note: This call is blocking, callers may want to avoid calling it from
818c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * the main thread of an application.
819c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
820a63f55cf17629426d976830429a7612387532195Rika Brooks     * @param messageIdentifier Message identifier as specified in TS 23.041 (3GPP)
821a63f55cf17629426d976830429a7612387532195Rika Brooks     * or C.R1001-G (3GPP2)
822a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     * @param ranType as defined in class SmsManager, the value can be one of these:
823a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     *    android.telephony.SmsMessage.CELL_BROADCAST_RAN_TYPE_GSM
824a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     *    android.telephony.SmsMessage.CELL_BROADCAST_RAN_TYPE_CDMA
825c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return true if successful, false otherwise
826a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     * @see #disableCellBroadcast(int, int)
827c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
828c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * {@hide}
829c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
830a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe    public boolean enableCellBroadcast(int messageIdentifier, int ranType) {
831c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        boolean success = false;
832c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
833c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        try {
8347961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski            ISms iccISms = getISmsService();
835c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            if (iccISms != null) {
8369dbb6ad72f064bde732111fe40ded4543b34295eYe Wen                success = iccISms.enableCellBroadcastForSubscriber(
8379dbb6ad72f064bde732111fe40ded4543b34295eYe Wen                        getSubscriptionId(), messageIdentifier, ranType);
838c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            }
839c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        } catch (RemoteException ex) {
840c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            // ignore it
841c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
842c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
843c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return success;
844c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
845c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
846c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
847c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Disable reception of cell broadcast (SMS-CB) messages with the given
848a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     * message identifier and RAN type. The RAN type specify this message ID
849a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     * belong to 3GPP (GSM) or 3GPP2(CDMA). Note that if two different clients
850a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     * enable the same message identifier, they must both disable it for the
851a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     * device to stop receiving those messages.
852c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Note: This call is blocking, callers may want to avoid calling it from
853c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * the main thread of an application.
854c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
855a63f55cf17629426d976830429a7612387532195Rika Brooks     * @param messageIdentifier Message identifier as specified in TS 23.041 (3GPP)
856a63f55cf17629426d976830429a7612387532195Rika Brooks     * or C.R1001-G (3GPP2)
857a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     * @param ranType as defined in class SmsManager, the value can be one of these:
858a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     *    android.telephony.SmsMessage.CELL_BROADCAST_RAN_TYPE_GSM
859a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     *    android.telephony.SmsMessage.CELL_BROADCAST_RAN_TYPE_CDMA
860c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return true if successful, false otherwise
861c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
862a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     * @see #enableCellBroadcast(int, int)
863c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
864c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * {@hide}
865c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
866a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe    public boolean disableCellBroadcast(int messageIdentifier, int ranType) {
867c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        boolean success = false;
868c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
869c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        try {
8707961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski            ISms iccISms = getISmsService();
871c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            if (iccISms != null) {
8729dbb6ad72f064bde732111fe40ded4543b34295eYe Wen                success = iccISms.disableCellBroadcastForSubscriber(
8739dbb6ad72f064bde732111fe40ded4543b34295eYe Wen                        getSubscriptionId(), messageIdentifier, ranType);
874c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            }
875c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        } catch (RemoteException ex) {
876c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            // ignore it
877c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
878c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
879c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return success;
880c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
881c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
882c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
883c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Enable reception of cell broadcast (SMS-CB) messages with the given
884a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     * message identifier range and RAN type. The RAN type specify this message ID
885a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     * belong to 3GPP (GSM) or 3GPP2(CDMA). Note that if two different clients enable
886a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     * the same message identifier, they must both disable it for the device to stop
887c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * receiving those messages. All received messages will be broadcast in an
888c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * intent with the action "android.provider.Telephony.SMS_CB_RECEIVED".
889c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Note: This call is blocking, callers may want to avoid calling it from
890c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * the main thread of an application.
891c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
892a63f55cf17629426d976830429a7612387532195Rika Brooks     * @param startMessageId first message identifier as specified in TS 23.041 (3GPP)
893a63f55cf17629426d976830429a7612387532195Rika Brooks     * or C.R1001-G (3GPP2)
894a63f55cf17629426d976830429a7612387532195Rika Brooks     * @param endMessageId last message identifier as specified in TS 23.041 (3GPP)
895a63f55cf17629426d976830429a7612387532195Rika Brooks     * or C.R1001-G (3GPP2)
896a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     * @param ranType as defined in class SmsManager, the value can be one of these:
897a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     *    android.telephony.SmsMessage.CELL_BROADCAST_RAN_TYPE_GSM
898a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     *    android.telephony.SmsMessage.CELL_BROADCAST_RAN_TYPE_CDMA
899c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return true if successful, false otherwise
900a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     * @see #disableCellBroadcastRange(int, int, int)
901c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
902910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks     * @throws IllegalArgumentException if endMessageId < startMessageId
903c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * {@hide}
904c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
905a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe    public boolean enableCellBroadcastRange(int startMessageId, int endMessageId, int ranType) {
906c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        boolean success = false;
907c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
908910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks        if (endMessageId < startMessageId) {
909910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks            throw new IllegalArgumentException("endMessageId < startMessageId");
910910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks        }
911c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        try {
9127961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski            ISms iccISms = getISmsService();
913c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            if (iccISms != null) {
9149dbb6ad72f064bde732111fe40ded4543b34295eYe Wen                success = iccISms.enableCellBroadcastRangeForSubscriber(getSubscriptionId(),
915a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe                        startMessageId, endMessageId, ranType);
916c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            }
917c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        } catch (RemoteException ex) {
918c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            // ignore it
919c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
920c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
921c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return success;
922c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
923c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
924c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
925c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Disable reception of cell broadcast (SMS-CB) messages with the given
926a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     * message identifier range and RAN type. The RAN type specify this message
927a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     * ID range belong to 3GPP (GSM) or 3GPP2(CDMA). Note that if two different
928a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     * clients enable the same message identifier, they must both disable it for
929a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     * the device to stop receiving those messages.
930c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Note: This call is blocking, callers may want to avoid calling it from
931c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * the main thread of an application.
932c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
933a63f55cf17629426d976830429a7612387532195Rika Brooks     * @param startMessageId first message identifier as specified in TS 23.041 (3GPP)
934a63f55cf17629426d976830429a7612387532195Rika Brooks     * or C.R1001-G (3GPP2)
935a63f55cf17629426d976830429a7612387532195Rika Brooks     * @param endMessageId last message identifier as specified in TS 23.041 (3GPP)
936a63f55cf17629426d976830429a7612387532195Rika Brooks     * or C.R1001-G (3GPP2)
937a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     * @param ranType as defined in class SmsManager, the value can be one of these:
938a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     *    android.telephony.SmsMessage.CELL_BROADCAST_RAN_TYPE_GSM
939a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     *    android.telephony.SmsMessage.CELL_BROADCAST_RAN_TYPE_CDMA
940c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return true if successful, false otherwise
941c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
942a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe     * @see #enableCellBroadcastRange(int, int, int)
943c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
944910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks     * @throws IllegalArgumentException if endMessageId < startMessageId
945c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * {@hide}
946c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
947a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe    public boolean disableCellBroadcastRange(int startMessageId, int endMessageId, int ranType) {
948c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        boolean success = false;
949c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
950910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks        if (endMessageId < startMessageId) {
951910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks            throw new IllegalArgumentException("endMessageId < startMessageId");
952910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks        }
953c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        try {
9547961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski            ISms iccISms = getISmsService();
955c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            if (iccISms != null) {
9569dbb6ad72f064bde732111fe40ded4543b34295eYe Wen                success = iccISms.disableCellBroadcastRangeForSubscriber(getSubscriptionId(),
957a8064ed9c00ab7bdd584e722efebce429bcaa51bxinhe                        startMessageId, endMessageId, ranType);
958c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            }
959c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        } catch (RemoteException ex) {
960c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            // ignore it
961c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
962c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
963c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return success;
964c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
965c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
966c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
967c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Create a list of <code>SmsMessage</code>s from a list of RawSmsData
968c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * records returned by <code>getAllMessagesFromIcc()</code>
969c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
970c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param records SMS EF records, returned by
971c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *   <code>getAllMessagesFromIcc</code>
972c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return <code>ArrayList</code> of <code>SmsMessage</code> objects.
973c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
974c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    private static ArrayList<SmsMessage> createMessageListFromRawRecords(List<SmsRawData> records) {
975c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        ArrayList<SmsMessage> messages = new ArrayList<SmsMessage>();
976c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        if (records != null) {
977c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            int count = records.size();
978c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            for (int i = 0; i < count; i++) {
979c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                SmsRawData data = records.get(i);
980c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                // List contains all records, including "free" records (null)
981c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                if (data != null) {
982c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    SmsMessage sms = SmsMessage.createFromEfRecord(i+1, data.getBytes());
983c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    if (sms != null) {
984c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                        messages.add(sms);
985c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    }
986c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                }
987c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            }
988c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
989c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return messages;
990c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
991c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
9921260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa    /**
9931260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa     * SMS over IMS is supported if IMS is registered and SMS is supported
9941260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa     * on IMS.
9951260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa     *
9961260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa     * @return true if SMS over IMS is supported, false otherwise
9971260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa     *
9981260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa     * @see #getImsSmsFormat()
9991260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa     *
10001260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa     * @hide
10011260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa     */
10028b53bb26569395511e3dbd5f94bda74ea6b9e37cXia Ying    public boolean isImsSmsSupported() {
10031260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa        boolean boSupported = false;
10041260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa        try {
10057961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski            ISms iccISms = getISmsService();
10061260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa            if (iccISms != null) {
10079dbb6ad72f064bde732111fe40ded4543b34295eYe Wen                boSupported = iccISms.isImsSmsSupportedForSubscriber(getSubscriptionId());
10081260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa            }
10091260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa        } catch (RemoteException ex) {
10101260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa            // ignore it
10111260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa        }
10121260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa        return boSupported;
10131260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa    }
10141260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa
10151260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa    /**
10161260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa     * Gets SMS format supported on IMS.  SMS over IMS format is
10171260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa     * either 3GPP or 3GPP2.
10181260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa     *
10191260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa     * @return SmsMessage.FORMAT_3GPP,
10201260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa     *         SmsMessage.FORMAT_3GPP2
10211260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa     *      or SmsMessage.FORMAT_UNKNOWN
10221260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa     *
10231260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa     * @see #isImsSmsSupported()
10241260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa     *
10251260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa     * @hide
10261260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa     */
10278b53bb26569395511e3dbd5f94bda74ea6b9e37cXia Ying    public String getImsSmsFormat() {
10281260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa        String format = com.android.internal.telephony.SmsConstants.FORMAT_UNKNOWN;
10291260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa        try {
10307961ac2c8d2e50d879bc6d5b272b7d972a335c0eAdam Lesinski            ISms iccISms = getISmsService();
10311260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa            if (iccISms != null) {
10329dbb6ad72f064bde732111fe40ded4543b34295eYe Wen                format = iccISms.getImsSmsFormatForSubscriber(getSubscriptionId());
10331260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa            }
10341260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa        } catch (RemoteException ex) {
10351260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa            // ignore it
10361260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa        }
10371260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa        return format;
10381260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa    }
10391260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa
1040a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    /**
10419dbb6ad72f064bde732111fe40ded4543b34295eYe Wen     * Get default sms subscription id
1042a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville     *
10439dbb6ad72f064bde732111fe40ded4543b34295eYe Wen     * @return the default SMS subscription id
1044a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville     */
1045299dad50409e907993fa96c7401d4f10c58018b1Wink Saville    public static int getDefaultSmsSubscriptionId() {
1046299dad50409e907993fa96c7401d4f10c58018b1Wink Saville        ISms iccISms = null;
1047299dad50409e907993fa96c7401d4f10c58018b1Wink Saville        try {
1048299dad50409e907993fa96c7401d4f10c58018b1Wink Saville            iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
1049299dad50409e907993fa96c7401d4f10c58018b1Wink Saville            return iccISms.getPreferredSmsSubscription();
1050299dad50409e907993fa96c7401d4f10c58018b1Wink Saville        } catch (RemoteException ex) {
1051dfdf9c40ebaaed15b5020ad6bce898fadd32dd58Wink Saville            return -1;
1052299dad50409e907993fa96c7401d4f10c58018b1Wink Saville        } catch (NullPointerException ex) {
1053dfdf9c40ebaaed15b5020ad6bce898fadd32dd58Wink Saville            return -1;
1054299dad50409e907993fa96c7401d4f10c58018b1Wink Saville        }
1055a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    }
1056a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
1057a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    /**
1058a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville     * Get SMS prompt property,  enabled or not
1059a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville     *
1060a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville     * @return true if enabled, false otherwise
1061a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville     * @hide
1062a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville     */
1063a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    public boolean isSMSPromptEnabled() {
1064a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville        ISms iccISms = null;
1065a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville        try {
1066a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville            iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
1067a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville            return iccISms.isSMSPromptEnabled();
1068a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville        } catch (RemoteException ex) {
1069a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville            return false;
1070a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville        } catch (NullPointerException ex) {
1071a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville            return false;
1072a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville        }
1073a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    }
1074a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
1075c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    // see SmsMessage.getStatusOnIcc
1076c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
1077c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /** Free space (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). */
1078c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    static public final int STATUS_ON_ICC_FREE      = 0;
1079c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
1080c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /** Received and read (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). */
1081c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    static public final int STATUS_ON_ICC_READ      = 1;
1082c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
1083c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /** Received and unread (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). */
1084c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    static public final int STATUS_ON_ICC_UNREAD    = 3;
1085c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
1086c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /** Stored and sent (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). */
1087c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    static public final int STATUS_ON_ICC_SENT      = 5;
1088c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
1089c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /** Stored and unsent (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). */
1090c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    static public final int STATUS_ON_ICC_UNSENT    = 7;
1091c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
1092c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    // SMS send failure result codes
1093c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
1094c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /** Generic failure cause */
1095c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    static public final int RESULT_ERROR_GENERIC_FAILURE    = 1;
1096c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /** Failed because radio was explicitly turned off */
1097c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    static public final int RESULT_ERROR_RADIO_OFF          = 2;
1098c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /** Failed because no pdu provided */
1099c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    static public final int RESULT_ERROR_NULL_PDU           = 3;
1100c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /** Failed because service is currently unavailable */
1101c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    static public final int RESULT_ERROR_NO_SERVICE         = 4;
1102c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /** Failed because we reached the sending queue limit.  {@hide} */
1103c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    static public final int RESULT_ERROR_LIMIT_EXCEEDED     = 5;
1104c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /** Failed because FDN is enabled. {@hide} */
1105c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    static public final int RESULT_ERROR_FDN_CHECK_FAILURE  = 6;
1106afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen
11075855254b4e0c22aaaa688ebbfb5c38b222cbf9d6Cheuksan Wang    static private final String PHONE_PACKAGE_NAME = "com.android.phone";
11085855254b4e0c22aaaa688ebbfb5c38b222cbf9d6Cheuksan Wang
1109afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen    /**
1110afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen     * Send an MMS message
1111afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen     *
11125855254b4e0c22aaaa688ebbfb5c38b222cbf9d6Cheuksan Wang     * @param context application context
1113be48040525446d99675eeb4760fae35465a2271dJulian Odell     * @param contentUri the content Uri from which the message pdu will be read
1114afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen     * @param locationUrl the optional location url where message should be sent to
1115529d6396030c30829a6dcc59f47ca48644854003Ye Wen     * @param configOverrides the carrier-specific messaging configuration values to override for
1116038b5c11030741f103c15741db74068ce099cb53Shri Borde     *  sending the message.
1117afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen     * @param sentIntent if not NULL this <code>PendingIntent</code> is
1118afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen     *  broadcast when the message is successfully sent, or failed
1119be48040525446d99675eeb4760fae35465a2271dJulian Odell     * @throws IllegalArgumentException if contentUri is empty
1120afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen     */
11215855254b4e0c22aaaa688ebbfb5c38b222cbf9d6Cheuksan Wang    public void sendMultimediaMessage(Context context, Uri contentUri, String locationUrl,
11224ee38f3f051d1738a9df852bc1b054cc7290a16fYe Wen            Bundle configOverrides, PendingIntent sentIntent) {
1123be48040525446d99675eeb4760fae35465a2271dJulian Odell        if (contentUri == null) {
1124be48040525446d99675eeb4760fae35465a2271dJulian Odell            throw new IllegalArgumentException("Uri contentUri null");
1125afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen        }
1126afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen        try {
1127afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen            final IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
1128afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen            if (iMms == null) {
1129afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen                return;
1130afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen            }
11315855254b4e0c22aaaa688ebbfb5c38b222cbf9d6Cheuksan Wang
11329dbb6ad72f064bde732111fe40ded4543b34295eYe Wen            iMms.sendMessage(getSubscriptionId(), ActivityThread.currentPackageName(), contentUri,
1133be48040525446d99675eeb4760fae35465a2271dJulian Odell                    locationUrl, configOverrides, sentIntent);
1134afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen        } catch (RemoteException e) {
1135afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen            // Ignore it
1136afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen        }
1137afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen    }
1138afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen
1139afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen    /**
1140afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen     * Download an MMS message from carrier by a given location URL
1141afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen     *
11425855254b4e0c22aaaa688ebbfb5c38b222cbf9d6Cheuksan Wang     * @param context application context
1143afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen     * @param locationUrl the location URL of the MMS message to be downloaded, usually obtained
1144afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen     *  from the MMS WAP push notification
1145be48040525446d99675eeb4760fae35465a2271dJulian Odell     * @param contentUri the content uri to which the downloaded pdu will be written
1146529d6396030c30829a6dcc59f47ca48644854003Ye Wen     * @param configOverrides the carrier-specific messaging configuration values to override for
1147038b5c11030741f103c15741db74068ce099cb53Shri Borde     *  downloading the message.
1148afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen     * @param downloadedIntent if not NULL this <code>PendingIntent</code> is
1149afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen     *  broadcast when the message is downloaded, or the download is failed
1150be48040525446d99675eeb4760fae35465a2271dJulian Odell     * @throws IllegalArgumentException if locationUrl or contentUri is empty
1151c5f9236283882b8e08390ac52e5b1fab2d3bc2fbYe Wen     */
11525855254b4e0c22aaaa688ebbfb5c38b222cbf9d6Cheuksan Wang    public void downloadMultimediaMessage(Context context, String locationUrl, Uri contentUri,
11534ee38f3f051d1738a9df852bc1b054cc7290a16fYe Wen            Bundle configOverrides, PendingIntent downloadedIntent) {
1154afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen        if (TextUtils.isEmpty(locationUrl)) {
1155afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen            throw new IllegalArgumentException("Empty MMS location URL");
1156afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen        }
1157be48040525446d99675eeb4760fae35465a2271dJulian Odell        if (contentUri == null) {
1158be48040525446d99675eeb4760fae35465a2271dJulian Odell            throw new IllegalArgumentException("Uri contentUri null");
1159be48040525446d99675eeb4760fae35465a2271dJulian Odell        }
1160afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen        try {
1161afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen            final IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
1162afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen            if (iMms == null) {
1163afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen                return;
1164afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen            }
11659dbb6ad72f064bde732111fe40ded4543b34295eYe Wen            iMms.downloadMessage(
11669dbb6ad72f064bde732111fe40ded4543b34295eYe Wen                    getSubscriptionId(), ActivityThread.currentPackageName(), locationUrl,
1167be48040525446d99675eeb4760fae35465a2271dJulian Odell                    contentUri, configOverrides, downloadedIntent);
1168afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen        } catch (RemoteException e) {
1169afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen            // Ignore it
1170afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen        }
1171afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen    }
1172afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen
1173afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen    // MMS send/download failure result codes
1174afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen    public static final int MMS_ERROR_UNSPECIFIED = 1;
1175afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen    public static final int MMS_ERROR_INVALID_APN = 2;
1176afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen    public static final int MMS_ERROR_UNABLE_CONNECT_MMS = 3;
1177afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen    public static final int MMS_ERROR_HTTP_FAILURE = 4;
1178be48040525446d99675eeb4760fae35465a2271dJulian Odell    public static final int MMS_ERROR_IO_ERROR = 5;
11795855254b4e0c22aaaa688ebbfb5c38b222cbf9d6Cheuksan Wang    public static final int MMS_ERROR_RETRY = 6;
11801f14e73b498c7b0690c138a0cdcbd4c4319c65edYe Wen    public static final int MMS_ERROR_CONFIGURATION_ERROR = 7;
118142618e2abde6133f3615e1f94e4b3d8d53b6d31dYe Wen    public static final int MMS_ERROR_NO_DATA_NETWORK = 8;
1182afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen
11839dbb6ad72f064bde732111fe40ded4543b34295eYe Wen    /** Intent extra name for MMS sending result data in byte array type */
11844ee38f3f051d1738a9df852bc1b054cc7290a16fYe Wen    public static final String EXTRA_MMS_DATA = "android.telephony.extra.MMS_DATA";
11859dbb6ad72f064bde732111fe40ded4543b34295eYe Wen    /** Intent extra name for HTTP status code for MMS HTTP failure in integer type */
1186b53e8e1598e9d21d8af9004b1d4c5ba127358aceYe Wen    public static final String EXTRA_MMS_HTTP_STATUS = "android.telephony.extra.MMS_HTTP_STATUS";
1187afa929f85b8f0c4f0c53b57956d1fd2ec7314904Ye Wen
1188982c5004a49b57a1f9ca7b054df5a7c0bb3bda20Ye Wen    /**
1189b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * Import a text message into system's SMS store
1190b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *
1191f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     * Only default SMS apps can import SMS
1192f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     *
1193b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param address the destination(source) address of the sent(received) message
1194b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param type the type of the message
1195b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param text the message text
1196b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param timestampMillis the message timestamp in milliseconds
1197b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param seen if the message is seen
1198b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param read if the message is read
1199b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @return the message URI, null if failed
12004ee38f3f051d1738a9df852bc1b054cc7290a16fYe Wen     * @hide
1201b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     */
1202b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    public Uri importTextMessage(String address, int type, String text, long timestampMillis,
1203b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            boolean seen, boolean read) {
1204b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        try {
1205b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
1206b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            if (iMms != null) {
1207b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen                return iMms.importTextMessage(ActivityThread.currentPackageName(),
1208b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen                        address, type, text, timestampMillis, seen, read);
1209b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            }
1210b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        } catch (RemoteException ex) {
1211b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            // ignore it
1212b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        }
1213b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        return null;
1214b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    }
1215b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen
12164ee38f3f051d1738a9df852bc1b054cc7290a16fYe Wen    /** Represents the received SMS message for importing {@hide} */
1217b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    public static final int SMS_TYPE_INCOMING = 0;
12184ee38f3f051d1738a9df852bc1b054cc7290a16fYe Wen    /** Represents the sent SMS message for importing {@hide} */
1219b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    public static final int SMS_TYPE_OUTGOING = 1;
1220b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen
1221b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    /**
1222b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * Import a multimedia message into system's MMS store. Only the following PDU type is
1223b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * supported: Retrieve.conf, Send.req, Notification.ind, Delivery.ind, Read-Orig.ind
1224b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *
1225f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     * Only default SMS apps can import MMS
1226f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     *
1227be48040525446d99675eeb4760fae35465a2271dJulian Odell     * @param contentUri the content uri from which to read the PDU of the message to import
1228b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param messageId the optional message id. Use null if not specifying
1229b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param timestampSecs the optional message timestamp. Use -1 if not specifying
1230b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param seen if the message is seen
1231b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param read if the message is read
1232b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @return the message URI, null if failed
1233b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @throws IllegalArgumentException if pdu is empty
12344ee38f3f051d1738a9df852bc1b054cc7290a16fYe Wen     * {@hide}
1235b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     */
1236be48040525446d99675eeb4760fae35465a2271dJulian Odell    public Uri importMultimediaMessage(Uri contentUri, String messageId, long timestampSecs,
1237b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            boolean seen, boolean read) {
1238be48040525446d99675eeb4760fae35465a2271dJulian Odell        if (contentUri == null) {
1239be48040525446d99675eeb4760fae35465a2271dJulian Odell            throw new IllegalArgumentException("Uri contentUri null");
1240b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        }
1241b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        try {
1242b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
1243b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            if (iMms != null) {
1244b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen                return iMms.importMultimediaMessage(ActivityThread.currentPackageName(),
1245be48040525446d99675eeb4760fae35465a2271dJulian Odell                        contentUri, messageId, timestampSecs, seen, read);
1246b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            }
1247b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        } catch (RemoteException ex) {
1248b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            // ignore it
1249b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        }
1250b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        return null;
1251b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    }
1252b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen
1253b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    /**
1254b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * Delete a system stored SMS or MMS message
1255b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *
1256f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     * Only default SMS apps can delete system stored SMS and MMS messages
1257f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     *
1258b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param messageUri the URI of the stored message
1259b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @return true if deletion is successful, false otherwise
1260b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @throws IllegalArgumentException if messageUri is empty
12614ee38f3f051d1738a9df852bc1b054cc7290a16fYe Wen     * {@hide}
1262b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     */
1263b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    public boolean deleteStoredMessage(Uri messageUri) {
1264b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        if (messageUri == null) {
1265b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            throw new IllegalArgumentException("Empty message URI");
1266b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        }
1267b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        try {
1268b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
1269b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            if (iMms != null) {
1270b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen                return iMms.deleteStoredMessage(ActivityThread.currentPackageName(), messageUri);
1271b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            }
1272b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        } catch (RemoteException ex) {
1273b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            // ignore it
1274b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        }
1275b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        return false;
1276b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    }
1277b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen
1278b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    /**
1279b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * Delete a system stored SMS or MMS thread
1280b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *
1281f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     * Only default SMS apps can delete system stored SMS and MMS conversations
1282f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     *
1283b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param conversationId the ID of the message conversation
1284b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @return true if deletion is successful, false otherwise
12854ee38f3f051d1738a9df852bc1b054cc7290a16fYe Wen     * {@hide}
1286b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     */
1287b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    public boolean deleteStoredConversation(long conversationId) {
1288b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        try {
1289b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
1290b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            if (iMms != null) {
1291b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen                return iMms.deleteStoredConversation(
1292b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen                        ActivityThread.currentPackageName(), conversationId);
1293b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            }
1294b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        } catch (RemoteException ex) {
1295b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            // ignore it
1296b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        }
1297b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        return false;
1298b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    }
1299b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen
1300b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    /**
1301b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * Update the status properties of a system stored SMS or MMS message, e.g.
1302b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * the read status of a message, etc.
1303b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *
1304b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param messageUri the URI of the stored message
1305b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param statusValues a list of status properties in key-value pairs to update
1306e58ff3bd4399dfe68517b100169e01e6b93dc7b6Ye Wen     * @return true if update is successful, false otherwise
1307b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @throws IllegalArgumentException if messageUri is empty
13084ee38f3f051d1738a9df852bc1b054cc7290a16fYe Wen     * {@hide}
1309b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     */
1310b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    public boolean updateStoredMessageStatus(Uri messageUri, ContentValues statusValues) {
1311b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        if (messageUri == null) {
1312b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            throw new IllegalArgumentException("Empty message URI");
1313b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        }
1314b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        try {
1315b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
1316b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            if (iMms != null) {
1317b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen                return iMms.updateStoredMessageStatus(ActivityThread.currentPackageName(),
1318b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen                        messageUri, statusValues);
1319b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            }
1320b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        } catch (RemoteException ex) {
1321b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            // ignore it
1322b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        }
1323b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        return false;
1324b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    }
1325b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen
13264ee38f3f051d1738a9df852bc1b054cc7290a16fYe Wen    /** Message status property: whether the message has been seen. 1 means seen, 0 not {@hide} */
1327b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    public static final String MESSAGE_STATUS_SEEN = "seen";
13284ee38f3f051d1738a9df852bc1b054cc7290a16fYe Wen    /** Message status property: whether the message has been read. 1 means read, 0 not {@hide} */
1329b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    public static final String MESSAGE_STATUS_READ = "read";
1330e58ff3bd4399dfe68517b100169e01e6b93dc7b6Ye Wen
1331e58ff3bd4399dfe68517b100169e01e6b93dc7b6Ye Wen    /**
1332e58ff3bd4399dfe68517b100169e01e6b93dc7b6Ye Wen     * Archive or unarchive a stored conversation
1333e58ff3bd4399dfe68517b100169e01e6b93dc7b6Ye Wen     *
1334e58ff3bd4399dfe68517b100169e01e6b93dc7b6Ye Wen     * @param conversationId the ID of the message conversation
1335e58ff3bd4399dfe68517b100169e01e6b93dc7b6Ye Wen     * @param archived true to archive the conversation, false to unarchive
1336e58ff3bd4399dfe68517b100169e01e6b93dc7b6Ye Wen     * @return true if update is successful, false otherwise
13374ee38f3f051d1738a9df852bc1b054cc7290a16fYe Wen     * {@hide}
1338e58ff3bd4399dfe68517b100169e01e6b93dc7b6Ye Wen     */
1339e58ff3bd4399dfe68517b100169e01e6b93dc7b6Ye Wen    public boolean archiveStoredConversation(long conversationId, boolean archived) {
1340e58ff3bd4399dfe68517b100169e01e6b93dc7b6Ye Wen        try {
1341e58ff3bd4399dfe68517b100169e01e6b93dc7b6Ye Wen            IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
1342e58ff3bd4399dfe68517b100169e01e6b93dc7b6Ye Wen            if (iMms != null) {
1343e58ff3bd4399dfe68517b100169e01e6b93dc7b6Ye Wen                return iMms.archiveStoredConversation(ActivityThread.currentPackageName(),
1344e58ff3bd4399dfe68517b100169e01e6b93dc7b6Ye Wen                        conversationId, archived);
1345e58ff3bd4399dfe68517b100169e01e6b93dc7b6Ye Wen            }
1346e58ff3bd4399dfe68517b100169e01e6b93dc7b6Ye Wen        } catch (RemoteException ex) {
1347e58ff3bd4399dfe68517b100169e01e6b93dc7b6Ye Wen            // ignore it
1348e58ff3bd4399dfe68517b100169e01e6b93dc7b6Ye Wen        }
1349e58ff3bd4399dfe68517b100169e01e6b93dc7b6Ye Wen        return false;
1350e58ff3bd4399dfe68517b100169e01e6b93dc7b6Ye Wen    }
1351b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen
1352b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    /**
1353b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * Add a text message draft to system SMS store
1354b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *
1355f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     * Only default SMS apps can add SMS draft
1356f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     *
1357b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param address the destination address of message
1358b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param text the body of the message to send
1359b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @return the URI of the stored draft message
13604ee38f3f051d1738a9df852bc1b054cc7290a16fYe Wen     * {@hide}
1361b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     */
1362b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    public Uri addTextMessageDraft(String address, String text) {
1363b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        try {
1364b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
1365b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            if (iMms != null) {
1366b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen                return iMms.addTextMessageDraft(ActivityThread.currentPackageName(), address, text);
1367b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            }
1368b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        } catch (RemoteException ex) {
1369b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            // ignore it
1370b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        }
1371b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        return null;
1372b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    }
1373b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen
1374b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    /**
1375b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * Add a multimedia message draft to system MMS store
1376b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *
1377f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     * Only default SMS apps can add MMS draft
1378f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     *
1379be48040525446d99675eeb4760fae35465a2271dJulian Odell     * @param contentUri the content uri from which to read the PDU data of the draft MMS
1380b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @return the URI of the stored draft message
1381b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @throws IllegalArgumentException if pdu is empty
13824ee38f3f051d1738a9df852bc1b054cc7290a16fYe Wen     * {@hide}
1383b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     */
1384be48040525446d99675eeb4760fae35465a2271dJulian Odell    public Uri addMultimediaMessageDraft(Uri contentUri) {
1385be48040525446d99675eeb4760fae35465a2271dJulian Odell        if (contentUri == null) {
1386be48040525446d99675eeb4760fae35465a2271dJulian Odell            throw new IllegalArgumentException("Uri contentUri null");
1387b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        }
1388b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        try {
1389b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
1390b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            if (iMms != null) {
1391be48040525446d99675eeb4760fae35465a2271dJulian Odell                return iMms.addMultimediaMessageDraft(ActivityThread.currentPackageName(),
1392be48040525446d99675eeb4760fae35465a2271dJulian Odell                        contentUri);
1393b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            }
1394b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        } catch (RemoteException ex) {
1395b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            // ignore it
1396b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        }
1397b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        return null;
1398b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    }
1399b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen
1400b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    /**
1401b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * Send a system stored text message.
1402b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *
1403b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * You can only send a failed text message or a draft text message.
1404b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *
1405b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param messageUri the URI of the stored message
1406b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param scAddress is the service center address or null to use the current default SMSC
1407b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param sentIntent if not NULL this <code>PendingIntent</code> is
1408b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *  broadcast when the message is successfully sent, or failed.
1409b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *  The result code will be <code>Activity.RESULT_OK</code> for success,
1410b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *  or one of these errors:<br>
1411b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *  <code>RESULT_ERROR_GENERIC_FAILURE</code><br>
1412b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *  <code>RESULT_ERROR_RADIO_OFF</code><br>
1413b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *  <code>RESULT_ERROR_NULL_PDU</code><br>
1414b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *  For <code>RESULT_ERROR_GENERIC_FAILURE</code> the sentIntent may include
1415b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *  the extra "errorCode" containing a radio technology specific value,
1416b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *  generally only useful for troubleshooting.<br>
1417b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *  The per-application based SMS control checks sentIntent. If sentIntent
1418b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *  is NULL the caller will be checked against all unknown applications,
1419b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *  which cause smaller number of SMS to be sent in checking period.
1420b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param deliveryIntent if not NULL this <code>PendingIntent</code> is
1421b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *  broadcast when the message is delivered to the recipient.  The
1422b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *  raw pdu of the status report is in the extended data ("pdu").
1423b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *
1424b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @throws IllegalArgumentException if messageUri is empty
14254ee38f3f051d1738a9df852bc1b054cc7290a16fYe Wen     * {@hide}
1426b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     */
1427b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    public void sendStoredTextMessage(Uri messageUri, String scAddress, PendingIntent sentIntent,
1428b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            PendingIntent deliveryIntent) {
1429b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        if (messageUri == null) {
1430b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            throw new IllegalArgumentException("Empty message URI");
1431b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        }
1432b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        try {
1433b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            ISms iccISms = getISmsServiceOrThrow();
14349dbb6ad72f064bde732111fe40ded4543b34295eYe Wen            iccISms.sendStoredText(
14359dbb6ad72f064bde732111fe40ded4543b34295eYe Wen                    getSubscriptionId(), ActivityThread.currentPackageName(), messageUri,
1436b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen                    scAddress, sentIntent, deliveryIntent);
1437b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        } catch (RemoteException ex) {
1438b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            // ignore it
1439b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        }
1440b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    }
1441b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen
1442b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    /**
1443b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * Send a system stored multi-part text message.
1444b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *
1445b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * You can only send a failed text message or a draft text message.
1446b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * The provided <code>PendingIntent</code> lists should match the part number of the
1447b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * divided text of the stored message by using <code>divideMessage</code>
1448b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *
1449b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param messageUri the URI of the stored message
1450b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param scAddress is the service center address or null to use
1451b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *   the current default SMSC
1452b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param sentIntents if not null, an <code>ArrayList</code> of
1453b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *   <code>PendingIntent</code>s (one for each message part) that is
1454b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *   broadcast when the corresponding message part has been sent.
1455b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *   The result code will be <code>Activity.RESULT_OK</code> for success,
1456b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *   or one of these errors:<br>
1457b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *   <code>RESULT_ERROR_GENERIC_FAILURE</code><br>
1458b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *   <code>RESULT_ERROR_RADIO_OFF</code><br>
1459b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *   <code>RESULT_ERROR_NULL_PDU</code><br>
1460b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *   For <code>RESULT_ERROR_GENERIC_FAILURE</code> each sentIntent may include
1461b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *   the extra "errorCode" containing a radio technology specific value,
1462b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *   generally only useful for troubleshooting.<br>
1463b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *   The per-application based SMS control checks sentIntent. If sentIntent
1464b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *   is NULL the caller will be checked against all unknown applications,
1465b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *   which cause smaller number of SMS to be sent in checking period.
1466b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param deliveryIntents if not null, an <code>ArrayList</code> of
1467b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *   <code>PendingIntent</code>s (one for each message part) that is
1468b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *   broadcast when the corresponding message part has been delivered
1469b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *   to the recipient.  The raw pdu of the status report is in the
1470b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *   extended data ("pdu").
1471b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *
1472b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @throws IllegalArgumentException if messageUri is empty
14734ee38f3f051d1738a9df852bc1b054cc7290a16fYe Wen     * {@hide}
1474b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     */
1475b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    public void sendStoredMultipartTextMessage(Uri messageUri, String scAddress,
1476b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents) {
1477b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        if (messageUri == null) {
1478b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            throw new IllegalArgumentException("Empty message URI");
1479b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        }
1480b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        try {
1481b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            ISms iccISms = getISmsServiceOrThrow();
14829dbb6ad72f064bde732111fe40ded4543b34295eYe Wen            iccISms.sendStoredMultipartText(
14839dbb6ad72f064bde732111fe40ded4543b34295eYe Wen                    getSubscriptionId(), ActivityThread.currentPackageName(), messageUri,
1484b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen                    scAddress, sentIntents, deliveryIntents);
1485b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        } catch (RemoteException ex) {
1486b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            // ignore it
1487b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        }
1488b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    }
1489b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen
1490b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    /**
1491b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * Send a system stored MMS message
1492b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *
1493b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * This is used for sending a previously sent, but failed-to-send, message or
1494b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * for sending a text message that has been stored as a draft.
1495b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *
1496b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param messageUri the URI of the stored message
1497529d6396030c30829a6dcc59f47ca48644854003Ye Wen     * @param configOverrides the carrier-specific messaging configuration values to override for
1498038b5c11030741f103c15741db74068ce099cb53Shri Borde     *  sending the message.
1499b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @param sentIntent if not NULL this <code>PendingIntent</code> is
1500b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     *  broadcast when the message is successfully sent, or failed
1501b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     * @throws IllegalArgumentException if messageUri is empty
15024ee38f3f051d1738a9df852bc1b054cc7290a16fYe Wen     * {@hide}
1503b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen     */
15044ee38f3f051d1738a9df852bc1b054cc7290a16fYe Wen    public void sendStoredMultimediaMessage(Uri messageUri, Bundle configOverrides,
1505529d6396030c30829a6dcc59f47ca48644854003Ye Wen            PendingIntent sentIntent) {
1506b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        if (messageUri == null) {
1507b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            throw new IllegalArgumentException("Empty message URI");
1508b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        }
1509b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        try {
1510b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
1511b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            if (iMms != null) {
15129dbb6ad72f064bde732111fe40ded4543b34295eYe Wen                iMms.sendStoredMessage(
15139dbb6ad72f064bde732111fe40ded4543b34295eYe Wen                        getSubscriptionId(), ActivityThread.currentPackageName(), messageUri,
1514529d6396030c30829a6dcc59f47ca48644854003Ye Wen                        configOverrides, sentIntent);
1515b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            }
1516b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        } catch (RemoteException ex) {
1517b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen            // ignore it
1518b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen        }
1519b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen    }
1520f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen
1521f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen    /**
1522f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     * Turns on/off the flag to automatically write sent/received SMS/MMS messages into system
1523f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     *
1524f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     * When this flag is on, all SMS/MMS sent/received are stored by system automatically
1525f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     * When this flag is off, only SMS/MMS sent by non-default SMS apps are stored by system
1526f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     * automatically
1527f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     *
1528f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     * This flag can only be changed by default SMS apps
1529f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     *
1530f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     * @param enabled Whether to enable message auto persisting
15314ee38f3f051d1738a9df852bc1b054cc7290a16fYe Wen     * {@hide}
1532f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     */
1533f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen    public void setAutoPersisting(boolean enabled) {
1534f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen        try {
1535f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen            IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
1536f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen            if (iMms != null) {
1537f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen                iMms.setAutoPersisting(ActivityThread.currentPackageName(), enabled);
1538f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen            }
1539f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen        } catch (RemoteException ex) {
1540f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen            // ignore it
1541f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen        }
1542f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen    }
1543f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen
1544f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen    /**
1545f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     * Get the value of the flag to automatically write sent/received SMS/MMS messages into system
1546f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     *
1547f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     * When this flag is on, all SMS/MMS sent/received are stored by system automatically
1548f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     * When this flag is off, only SMS/MMS sent by non-default SMS apps are stored by system
1549f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     * automatically
1550f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     *
1551f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     * @return the current value of the auto persist flag
15524ee38f3f051d1738a9df852bc1b054cc7290a16fYe Wen     * {@hide}
1553f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen     */
1554f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen    public boolean getAutoPersisting() {
1555f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen        try {
1556f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen            IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
1557f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen            if (iMms != null) {
1558f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen                return iMms.getAutoPersisting();
1559f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen            }
1560f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen        } catch (RemoteException ex) {
1561f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen            // ignore it
1562f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen        }
1563f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen        return false;
1564f1aeeb51f2c62420012122e0ccc75b3940c570e4Ye Wen    }
1565038b5c11030741f103c15741db74068ce099cb53Shri Borde
1566038b5c11030741f103c15741db74068ce099cb53Shri Borde    /**
1567038b5c11030741f103c15741db74068ce099cb53Shri Borde     * Get carrier-dependent configuration values.
1568038b5c11030741f103c15741db74068ce099cb53Shri Borde     *
1569038b5c11030741f103c15741db74068ce099cb53Shri Borde     * @return bundle key/values pairs of configuration values
1570038b5c11030741f103c15741db74068ce099cb53Shri Borde     */
1571038b5c11030741f103c15741db74068ce099cb53Shri Borde    public Bundle getCarrierConfigValues() {
1572038b5c11030741f103c15741db74068ce099cb53Shri Borde        try {
1573038b5c11030741f103c15741db74068ce099cb53Shri Borde            IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
1574038b5c11030741f103c15741db74068ce099cb53Shri Borde            if (iMms != null) {
15759dbb6ad72f064bde732111fe40ded4543b34295eYe Wen                return iMms.getCarrierConfigValues(getSubscriptionId());
1576038b5c11030741f103c15741db74068ce099cb53Shri Borde            }
1577038b5c11030741f103c15741db74068ce099cb53Shri Borde        } catch (RemoteException ex) {
1578038b5c11030741f103c15741db74068ce099cb53Shri Borde            // ignore it
1579038b5c11030741f103c15741db74068ce099cb53Shri Borde        }
1580038b5c11030741f103c15741db74068ce099cb53Shri Borde        return null;
1581038b5c11030741f103c15741db74068ce099cb53Shri Borde    }
1582038b5c11030741f103c15741db74068ce099cb53Shri Borde
1583bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri    /**
1584bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri     * Filters a bundle to only contain MMS config variables.
1585bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri     *
1586bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri     * This is for use with bundles returned by {@link CarrierConfigManager} which contain MMS
1587bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri     * config and unrelated config. It is assumed that all MMS_CONFIG_* keys are present in the
1588bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri     * supplied bundle.
1589bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri     *
1590bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri     * @param config a Bundle that contains MMS config variables and possibly more.
1591bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri     * @return a new Bundle that only contains the MMS_CONFIG_* keys defined above.
1592bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri     * @hide
1593bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri     */
1594bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri    public static Bundle getMmsConfig(BaseBundle config) {
1595bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        Bundle filtered = new Bundle();
1596bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putBoolean(MMS_CONFIG_APPEND_TRANSACTION_ID,
1597bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri                config.getBoolean(MMS_CONFIG_APPEND_TRANSACTION_ID));
1598bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putBoolean(MMS_CONFIG_MMS_ENABLED, config.getBoolean(MMS_CONFIG_MMS_ENABLED));
1599bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putBoolean(MMS_CONFIG_GROUP_MMS_ENABLED,
1600bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri                config.getBoolean(MMS_CONFIG_GROUP_MMS_ENABLED));
1601bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putBoolean(MMS_CONFIG_NOTIFY_WAP_MMSC_ENABLED,
1602bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri                config.getBoolean(MMS_CONFIG_NOTIFY_WAP_MMSC_ENABLED));
1603bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putBoolean(MMS_CONFIG_ALIAS_ENABLED, config.getBoolean(MMS_CONFIG_ALIAS_ENABLED));
1604bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putBoolean(MMS_CONFIG_ALLOW_ATTACH_AUDIO,
1605bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri                config.getBoolean(MMS_CONFIG_ALLOW_ATTACH_AUDIO));
1606bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putBoolean(MMS_CONFIG_MULTIPART_SMS_ENABLED,
1607bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri                config.getBoolean(MMS_CONFIG_MULTIPART_SMS_ENABLED));
1608bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putBoolean(MMS_CONFIG_SMS_DELIVERY_REPORT_ENABLED,
1609bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri                config.getBoolean(MMS_CONFIG_SMS_DELIVERY_REPORT_ENABLED));
1610bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putBoolean(MMS_CONFIG_SUPPORT_MMS_CONTENT_DISPOSITION,
1611bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri                config.getBoolean(MMS_CONFIG_SUPPORT_MMS_CONTENT_DISPOSITION));
1612bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putBoolean(MMS_CONFIG_SEND_MULTIPART_SMS_AS_SEPARATE_MESSAGES,
1613bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri                config.getBoolean(MMS_CONFIG_SEND_MULTIPART_SMS_AS_SEPARATE_MESSAGES));
1614bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putBoolean(MMS_CONFIG_MMS_READ_REPORT_ENABLED,
1615bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri                config.getBoolean(MMS_CONFIG_MMS_READ_REPORT_ENABLED));
1616bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putBoolean(MMS_CONFIG_MMS_DELIVERY_REPORT_ENABLED,
1617bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri                config.getBoolean(MMS_CONFIG_MMS_DELIVERY_REPORT_ENABLED));
1618bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putInt(MMS_CONFIG_MAX_MESSAGE_SIZE, config.getInt(MMS_CONFIG_MAX_MESSAGE_SIZE));
1619bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putInt(MMS_CONFIG_MAX_IMAGE_WIDTH, config.getInt(MMS_CONFIG_MAX_IMAGE_WIDTH));
1620bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putInt(MMS_CONFIG_MAX_IMAGE_HEIGHT, config.getInt(MMS_CONFIG_MAX_IMAGE_HEIGHT));
1621bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putInt(MMS_CONFIG_RECIPIENT_LIMIT, config.getInt(MMS_CONFIG_RECIPIENT_LIMIT));
1622bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putInt(MMS_CONFIG_ALIAS_MIN_CHARS, config.getInt(MMS_CONFIG_ALIAS_MIN_CHARS));
1623bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putInt(MMS_CONFIG_ALIAS_MAX_CHARS, config.getInt(MMS_CONFIG_ALIAS_MAX_CHARS));
1624bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putInt(MMS_CONFIG_SMS_TO_MMS_TEXT_THRESHOLD,
1625bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri                config.getInt(MMS_CONFIG_SMS_TO_MMS_TEXT_THRESHOLD));
1626bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putInt(MMS_CONFIG_SMS_TO_MMS_TEXT_LENGTH_THRESHOLD,
1627bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri                config.getInt(MMS_CONFIG_SMS_TO_MMS_TEXT_LENGTH_THRESHOLD));
1628bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putInt(MMS_CONFIG_MESSAGE_TEXT_MAX_SIZE,
1629bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri                config.getInt(MMS_CONFIG_MESSAGE_TEXT_MAX_SIZE));
1630bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putInt(MMS_CONFIG_SUBJECT_MAX_LENGTH,
1631bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri                config.getInt(MMS_CONFIG_SUBJECT_MAX_LENGTH));
1632bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putInt(MMS_CONFIG_HTTP_SOCKET_TIMEOUT,
1633bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri                config.getInt(MMS_CONFIG_HTTP_SOCKET_TIMEOUT));
1634bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putString(MMS_CONFIG_UA_PROF_TAG_NAME,
1635bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri                config.getString(MMS_CONFIG_UA_PROF_TAG_NAME));
1636bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putString(MMS_CONFIG_USER_AGENT, config.getString(MMS_CONFIG_USER_AGENT));
1637bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putString(MMS_CONFIG_UA_PROF_URL, config.getString(MMS_CONFIG_UA_PROF_URL));
1638bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putString(MMS_CONFIG_HTTP_PARAMS, config.getString(MMS_CONFIG_HTTP_PARAMS));
1639bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putString(MMS_CONFIG_EMAIL_GATEWAY_NUMBER,
1640bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri                config.getString(MMS_CONFIG_EMAIL_GATEWAY_NUMBER));
1641bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putString(MMS_CONFIG_NAI_SUFFIX, config.getString(MMS_CONFIG_NAI_SUFFIX));
1642bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putBoolean(MMS_CONFIG_SHOW_CELL_BROADCAST_APP_LINKS,
1643bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri                config.getBoolean(MMS_CONFIG_SHOW_CELL_BROADCAST_APP_LINKS));
1644bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        filtered.putBoolean(MMS_CONFIG_SUPPORT_HTTP_CHARSET_HEADER,
1645bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri                config.getBoolean(MMS_CONFIG_SUPPORT_HTTP_CHARSET_HEADER));
1646bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri        return filtered;
1647bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri    }
1648bdc2ca1e1ad6a10c84b132607c108cbc29bc9520Jonathan Basseri
1649c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville}
1650