SmsManager.java revision 29305a0d8e45e8b6731ab91e59fcba7a4d6ff766
1c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville/* 2c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Copyright (C) 2008 The Android Open Source Project 31260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. 4c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 5c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Licensed under the Apache License, Version 2.0 (the "License"); 6c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * you may not use this file except in compliance with the License. 7c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * You may obtain a copy of the License at 8c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 9c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * http://www.apache.org/licenses/LICENSE-2.0 10c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 11c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Unless required by applicable law or agreed to in writing, software 12c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * distributed under the License is distributed on an "AS IS" BASIS, 13c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * See the License for the specific language governing permissions and 15c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * limitations under the License. 16c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville */ 17c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 18c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savillepackage android.telephony; 19c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 207fce994eb223105829becb6c26e3af7a9739752cDianne Hackbornimport android.app.ActivityThread; 21c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savilleimport android.app.PendingIntent; 22c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savilleimport android.os.RemoteException; 23c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savilleimport android.os.ServiceManager; 24c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savilleimport android.text.TextUtils; 25c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 26c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savilleimport com.android.internal.telephony.ISms; 27c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savilleimport com.android.internal.telephony.SmsRawData; 28d720945f2be5ea5fe0faf67e67d9ea0e184eba67Alex Yakavenkaimport com.android.internal.telephony.uicc.IccConstants; 29c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 30c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savilleimport java.util.ArrayList; 31c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savilleimport java.util.Arrays; 32c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savilleimport java.util.List; 33c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 34c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville/* 35c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * TODO(code review): Curious question... Why are a lot of these 36c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * methods not declared as static, since they do not seem to require 37c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * any local object state? Presumably this cannot be changed without 38c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * interfering with the API... 39c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville */ 40c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 41c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville/** 42c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Manages SMS operations such as sending data, text, and pdu SMS messages. 4329305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * Get this object by calling the static method {@link #getDefault()}. 4429305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * 4529305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * <p>For information about how to behave as the default SMS app on Android 4.4 (API level 19) 4629305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * and higher, see {@link android.provider.Telephony}. 47c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville */ 48c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savillepublic final class SmsManager { 49c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** Singleton object constructed during class initialization. */ 50c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville private static final SmsManager sInstance = new SmsManager(); 51c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 52c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** 53c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Send a text based SMS. 54c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 5529305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * <p class="note"><strong>Note:</strong> Using this method requires that your app has the 5629305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * {@link android.Manifest.permission#SEND_SMS} permission.</p> 5729305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * 5829305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * <p class="note"><strong>Note:</strong> Beginning with Android 4.4 (API level 19), if 5929305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * <em>and only if</em> an app is not selected as the default SMS app, the system automatically 6029305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * writes messages sent using this method to the SMS Provider (the default SMS app is always 6129305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * responsible for writing its sent messages to the SMS Provider). For information about 6229305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * how to behave as the default SMS app, see {@link android.provider.Telephony}.</p> 6329305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * 6429305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * 65c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @param destinationAddress the address to send the message to 66c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @param scAddress is the service center address or null to use 67c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * the current default SMSC 68c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @param text the body of the message to send 69c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @param sentIntent if not NULL this <code>PendingIntent</code> is 70c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * broadcast when the message is successfully sent, or failed. 71c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * The result code will be <code>Activity.RESULT_OK</code> for success, 72c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * or one of these errors:<br> 73c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * <code>RESULT_ERROR_GENERIC_FAILURE</code><br> 74c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * <code>RESULT_ERROR_RADIO_OFF</code><br> 75c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * <code>RESULT_ERROR_NULL_PDU</code><br> 76c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * For <code>RESULT_ERROR_GENERIC_FAILURE</code> the sentIntent may include 77c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * the extra "errorCode" containing a radio technology specific value, 78c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * generally only useful for troubleshooting.<br> 79c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * The per-application based SMS control checks sentIntent. If sentIntent 80c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * is NULL the caller will be checked against all unknown applications, 81c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * which cause smaller number of SMS to be sent in checking period. 82c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @param deliveryIntent if not NULL this <code>PendingIntent</code> is 83c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * broadcast when the message is delivered to the recipient. The 84c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * raw pdu of the status report is in the extended data ("pdu"). 85c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 86c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @throws IllegalArgumentException if destinationAddress or text are empty 87c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville */ 88c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville public void sendTextMessage( 89c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville String destinationAddress, String scAddress, String text, 90c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville PendingIntent sentIntent, PendingIntent deliveryIntent) { 91c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville if (TextUtils.isEmpty(destinationAddress)) { 92c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville throw new IllegalArgumentException("Invalid destinationAddress"); 93c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 94c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 95c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville if (TextUtils.isEmpty(text)) { 96c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville throw new IllegalArgumentException("Invalid message body"); 97c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 98c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 99c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville try { 100c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms")); 101c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville if (iccISms != null) { 1027fce994eb223105829becb6c26e3af7a9739752cDianne Hackborn iccISms.sendText(ActivityThread.currentPackageName(), destinationAddress, 1037fce994eb223105829becb6c26e3af7a9739752cDianne Hackborn scAddress, text, sentIntent, deliveryIntent); 104c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 105c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } catch (RemoteException ex) { 106c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville // ignore it 107c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 108c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 109c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 110c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** 111c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Divide a message text into several fragments, none bigger than 112c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * the maximum SMS message size. 113c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 114c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @param text the original message. Must not be null. 115c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @return an <code>ArrayList</code> of strings that, in order, 116c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * comprise the original message 117910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks * 118910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks * @throws IllegalArgumentException if text is null 119c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville */ 120c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville public ArrayList<String> divideMessage(String text) { 121910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks if (null == text) { 122910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks throw new IllegalArgumentException("text is null"); 123910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks } 124c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville return SmsMessage.fragmentText(text); 125c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 126c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 127c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** 128c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Send a multi-part text based SMS. The callee should have already 129c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * divided the message into correctly sized parts by calling 130c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * <code>divideMessage</code>. 131c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 13229305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * <p class="note"><strong>Note:</strong> Using this method requires that your app has the 13329305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * {@link android.Manifest.permission#SEND_SMS} permission.</p> 13429305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * 13529305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * <p class="note"><strong>Note:</strong> Beginning with Android 4.4 (API level 19), if 13629305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * <em>and only if</em> an app is not selected as the default SMS app, the system automatically 13729305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * writes messages sent using this method to the SMS Provider (the default SMS app is always 13829305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * responsible for writing its sent messages to the SMS Provider). For information about 13929305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * how to behave as the default SMS app, see {@link android.provider.Telephony}.</p> 14029305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * 141c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @param destinationAddress the address to send the message to 142c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @param scAddress is the service center address or null to use 143c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * the current default SMSC 144c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @param parts an <code>ArrayList</code> of strings that, in order, 145c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * comprise the original message 146c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @param sentIntents if not null, an <code>ArrayList</code> of 147c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * <code>PendingIntent</code>s (one for each message part) that is 148c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * broadcast when the corresponding message part has been sent. 149c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * The result code will be <code>Activity.RESULT_OK</code> for success, 150c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * or one of these errors:<br> 151c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * <code>RESULT_ERROR_GENERIC_FAILURE</code><br> 152c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * <code>RESULT_ERROR_RADIO_OFF</code><br> 153c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * <code>RESULT_ERROR_NULL_PDU</code><br> 154c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * For <code>RESULT_ERROR_GENERIC_FAILURE</code> each sentIntent may include 155c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * the extra "errorCode" containing a radio technology specific value, 156c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * generally only useful for troubleshooting.<br> 157c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * The per-application based SMS control checks sentIntent. If sentIntent 158c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * is NULL the caller will be checked against all unknown applications, 159c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * which cause smaller number of SMS to be sent in checking period. 160c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @param deliveryIntents if not null, an <code>ArrayList</code> of 161c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * <code>PendingIntent</code>s (one for each message part) that is 162c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * broadcast when the corresponding message part has been delivered 163c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * to the recipient. The raw pdu of the status report is in the 164c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * extended data ("pdu"). 165c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 166c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @throws IllegalArgumentException if destinationAddress or data are empty 167c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville */ 168c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville public void sendMultipartTextMessage( 169c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville String destinationAddress, String scAddress, ArrayList<String> parts, 170c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents) { 171c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville if (TextUtils.isEmpty(destinationAddress)) { 172c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville throw new IllegalArgumentException("Invalid destinationAddress"); 173c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 174c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville if (parts == null || parts.size() < 1) { 175c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville throw new IllegalArgumentException("Invalid message body"); 176c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 177c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 178c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville if (parts.size() > 1) { 179c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville try { 180c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms")); 181c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville if (iccISms != null) { 1827fce994eb223105829becb6c26e3af7a9739752cDianne Hackborn iccISms.sendMultipartText(ActivityThread.currentPackageName(), 1837fce994eb223105829becb6c26e3af7a9739752cDianne Hackborn destinationAddress, scAddress, parts, 184c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville sentIntents, deliveryIntents); 185c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 186c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } catch (RemoteException ex) { 187c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville // ignore it 188c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 189c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } else { 190c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville PendingIntent sentIntent = null; 191c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville PendingIntent deliveryIntent = null; 192c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville if (sentIntents != null && sentIntents.size() > 0) { 193c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville sentIntent = sentIntents.get(0); 194c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 195c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville if (deliveryIntents != null && deliveryIntents.size() > 0) { 196c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville deliveryIntent = deliveryIntents.get(0); 197c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 198c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville sendTextMessage(destinationAddress, scAddress, parts.get(0), 199c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville sentIntent, deliveryIntent); 200c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 201c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 202c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 203c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** 204c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Send a data based SMS to a specific application port. 205c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 20629305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * <p class="note"><strong>Note:</strong> Using this method requires that your app has the 20729305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * {@link android.Manifest.permission#SEND_SMS} permission.</p> 20829305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * 209c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @param destinationAddress the address to send the message to 210c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @param scAddress is the service center address or null to use 211c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * the current default SMSC 212c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @param destinationPort the port to deliver the message to 213c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @param data the body of the message to send 214c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @param sentIntent if not NULL this <code>PendingIntent</code> is 215c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * broadcast when the message is successfully sent, or failed. 216c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * The result code will be <code>Activity.RESULT_OK</code> for success, 217c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * or one of these errors:<br> 218c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * <code>RESULT_ERROR_GENERIC_FAILURE</code><br> 219c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * <code>RESULT_ERROR_RADIO_OFF</code><br> 220c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * <code>RESULT_ERROR_NULL_PDU</code><br> 221c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * For <code>RESULT_ERROR_GENERIC_FAILURE</code> the sentIntent may include 222c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * the extra "errorCode" containing a radio technology specific value, 223c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * generally only useful for troubleshooting.<br> 224c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * The per-application based SMS control checks sentIntent. If sentIntent 225c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * is NULL the caller will be checked against all unknown applications, 226c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * which cause smaller number of SMS to be sent in checking period. 227c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @param deliveryIntent if not NULL this <code>PendingIntent</code> is 228c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * broadcast when the message is delivered to the recipient. The 229c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * raw pdu of the status report is in the extended data ("pdu"). 230c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 231c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @throws IllegalArgumentException if destinationAddress or data are empty 232c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville */ 233c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville public void sendDataMessage( 234c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville String destinationAddress, String scAddress, short destinationPort, 235c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent) { 236c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville if (TextUtils.isEmpty(destinationAddress)) { 237c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville throw new IllegalArgumentException("Invalid destinationAddress"); 238c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 239c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 240c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville if (data == null || data.length == 0) { 241c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville throw new IllegalArgumentException("Invalid message data"); 242c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 243c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 244c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville try { 245c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms")); 246c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville if (iccISms != null) { 2477fce994eb223105829becb6c26e3af7a9739752cDianne Hackborn iccISms.sendData(ActivityThread.currentPackageName(), 2487fce994eb223105829becb6c26e3af7a9739752cDianne Hackborn destinationAddress, scAddress, destinationPort & 0xFFFF, 249c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville data, sentIntent, deliveryIntent); 250c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 251c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } catch (RemoteException ex) { 252c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville // ignore it 253c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 254c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 255c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 256c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** 257c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Get the default instance of the SmsManager 258c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 259c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @return the default instance of the SmsManager 260c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville */ 261c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville public static SmsManager getDefault() { 262c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville return sInstance; 263c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 264c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 265c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville private SmsManager() { 266c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville //nothing 267c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 268c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 269c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** 270c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Copy a raw SMS PDU to the ICC. 271c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * ICC (Integrated Circuit Card) is the card of the device. 272c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * For example, this can be the SIM or USIM for GSM. 273c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 274c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @param smsc the SMSC for this message, or NULL for the default SMSC 275c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @param pdu the raw PDU to store 276c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @param status message status (STATUS_ON_ICC_READ, STATUS_ON_ICC_UNREAD, 277c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * STATUS_ON_ICC_SENT, STATUS_ON_ICC_UNSENT) 278c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @return true for success 279c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 280910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks * @throws IllegalArgumentException if pdu is NULL 281c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * {@hide} 282c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville */ 283c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville public boolean copyMessageToIcc(byte[] smsc, byte[] pdu, int status) { 284c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville boolean success = false; 285c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 286910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks if (null == pdu) { 287910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks throw new IllegalArgumentException("pdu is NULL"); 288910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks } 289c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville try { 290c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms")); 291c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville if (iccISms != null) { 2927fce994eb223105829becb6c26e3af7a9739752cDianne Hackborn success = iccISms.copyMessageToIccEf(ActivityThread.currentPackageName(), 2937fce994eb223105829becb6c26e3af7a9739752cDianne Hackborn status, pdu, smsc); 294c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 295c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } catch (RemoteException ex) { 296c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville // ignore it 297c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 298c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 299c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville return success; 300c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 301c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 302c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** 303c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Delete the specified message from the ICC. 304c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * ICC (Integrated Circuit Card) is the card of the device. 305c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * For example, this can be the SIM or USIM for GSM. 306c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 307c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @param messageIndex is the record index of the message on ICC 308c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @return true for success 309c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 310c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * {@hide} 311c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville */ 312c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville public boolean 313c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville deleteMessageFromIcc(int messageIndex) { 314c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville boolean success = false; 315c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville byte[] pdu = new byte[IccConstants.SMS_RECORD_LENGTH-1]; 316c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville Arrays.fill(pdu, (byte)0xff); 317c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 318c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville try { 319c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms")); 320c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville if (iccISms != null) { 3217fce994eb223105829becb6c26e3af7a9739752cDianne Hackborn success = iccISms.updateMessageOnIccEf(ActivityThread.currentPackageName(), 3227fce994eb223105829becb6c26e3af7a9739752cDianne Hackborn messageIndex, STATUS_ON_ICC_FREE, pdu); 323c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 324c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } catch (RemoteException ex) { 325c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville // ignore it 326c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 327c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 328c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville return success; 329c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 330c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 331c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** 332c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Update the specified message on the ICC. 333c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * ICC (Integrated Circuit Card) is the card of the device. 334c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * For example, this can be the SIM or USIM for GSM. 335c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 336c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @param messageIndex record index of message to update 337c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @param newStatus new message status (STATUS_ON_ICC_READ, 338c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * STATUS_ON_ICC_UNREAD, STATUS_ON_ICC_SENT, 339c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * STATUS_ON_ICC_UNSENT, STATUS_ON_ICC_FREE) 340c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @param pdu the raw PDU to store 341c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @return true for success 342c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 343c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * {@hide} 344c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville */ 345c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville public boolean updateMessageOnIcc(int messageIndex, int newStatus, byte[] pdu) { 346c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville boolean success = false; 347c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 348c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville try { 349c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms")); 350c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville if (iccISms != null) { 3517fce994eb223105829becb6c26e3af7a9739752cDianne Hackborn success = iccISms.updateMessageOnIccEf(ActivityThread.currentPackageName(), 3527fce994eb223105829becb6c26e3af7a9739752cDianne Hackborn messageIndex, newStatus, pdu); 353c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 354c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } catch (RemoteException ex) { 355c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville // ignore it 356c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 357c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 358c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville return success; 359c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 360c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 361c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** 362c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Retrieves all messages currently stored on ICC. 363c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * ICC (Integrated Circuit Card) is the card of the device. 364c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * For example, this can be the SIM or USIM for GSM. 365c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 366c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @return <code>ArrayList</code> of <code>SmsMessage</code> objects 367c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 368c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * {@hide} 369c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville */ 370c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville public static ArrayList<SmsMessage> getAllMessagesFromIcc() { 371c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville List<SmsRawData> records = null; 372c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 373c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville try { 374c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms")); 375c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville if (iccISms != null) { 3767fce994eb223105829becb6c26e3af7a9739752cDianne Hackborn records = iccISms.getAllMessagesFromIccEf(ActivityThread.currentPackageName()); 377c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 378c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } catch (RemoteException ex) { 379c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville // ignore it 380c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 381c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 382c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville return createMessageListFromRawRecords(records); 383c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 384c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 385c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** 386c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Enable reception of cell broadcast (SMS-CB) messages with the given 387c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * message identifier. Note that if two different clients enable the same 388c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * message identifier, they must both disable it for the device to stop 389c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * receiving those messages. All received messages will be broadcast in an 390c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * intent with the action "android.provider.Telephony.SMS_CB_RECEIVED". 391c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Note: This call is blocking, callers may want to avoid calling it from 392c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * the main thread of an application. 393c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 394a63f55cf17629426d976830429a7612387532195Rika Brooks * @param messageIdentifier Message identifier as specified in TS 23.041 (3GPP) 395a63f55cf17629426d976830429a7612387532195Rika Brooks * or C.R1001-G (3GPP2) 396c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @return true if successful, false otherwise 397c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @see #disableCellBroadcast(int) 398c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 399c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * {@hide} 400c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville */ 401c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville public boolean enableCellBroadcast(int messageIdentifier) { 402c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville boolean success = false; 403c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 404c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville try { 405c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms")); 406c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville if (iccISms != null) { 407c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville success = iccISms.enableCellBroadcast(messageIdentifier); 408c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 409c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } catch (RemoteException ex) { 410c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville // ignore it 411c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 412c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 413c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville return success; 414c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 415c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 416c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** 417c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Disable reception of cell broadcast (SMS-CB) messages with the given 418c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * message identifier. Note that if two different clients enable the same 419c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * message identifier, they must both disable it for the device to stop 420c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * receiving those messages. 421c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Note: This call is blocking, callers may want to avoid calling it from 422c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * the main thread of an application. 423c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 424a63f55cf17629426d976830429a7612387532195Rika Brooks * @param messageIdentifier Message identifier as specified in TS 23.041 (3GPP) 425a63f55cf17629426d976830429a7612387532195Rika Brooks * or C.R1001-G (3GPP2) 426c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @return true if successful, false otherwise 427c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 428c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @see #enableCellBroadcast(int) 429c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 430c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * {@hide} 431c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville */ 432c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville public boolean disableCellBroadcast(int messageIdentifier) { 433c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville boolean success = false; 434c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 435c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville try { 436c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms")); 437c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville if (iccISms != null) { 438c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville success = iccISms.disableCellBroadcast(messageIdentifier); 439c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 440c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } catch (RemoteException ex) { 441c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville // ignore it 442c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 443c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 444c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville return success; 445c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 446c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 447c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** 448c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Enable reception of cell broadcast (SMS-CB) messages with the given 449c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * message identifier range. Note that if two different clients enable the same 450c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * message identifier, they must both disable it for the device to stop 451c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * receiving those messages. All received messages will be broadcast in an 452c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * intent with the action "android.provider.Telephony.SMS_CB_RECEIVED". 453c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Note: This call is blocking, callers may want to avoid calling it from 454c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * the main thread of an application. 455c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 456a63f55cf17629426d976830429a7612387532195Rika Brooks * @param startMessageId first message identifier as specified in TS 23.041 (3GPP) 457a63f55cf17629426d976830429a7612387532195Rika Brooks * or C.R1001-G (3GPP2) 458a63f55cf17629426d976830429a7612387532195Rika Brooks * @param endMessageId last message identifier as specified in TS 23.041 (3GPP) 459a63f55cf17629426d976830429a7612387532195Rika Brooks * or C.R1001-G (3GPP2) 460c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @return true if successful, false otherwise 461c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @see #disableCellBroadcastRange(int, int) 462c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 463910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks * @throws IllegalArgumentException if endMessageId < startMessageId 464c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * {@hide} 465c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville */ 466c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville public boolean enableCellBroadcastRange(int startMessageId, int endMessageId) { 467c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville boolean success = false; 468c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 469910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks if (endMessageId < startMessageId) { 470910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks throw new IllegalArgumentException("endMessageId < startMessageId"); 471910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks } 472c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville try { 473c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms")); 474c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville if (iccISms != null) { 475c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville success = iccISms.enableCellBroadcastRange(startMessageId, endMessageId); 476c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 477c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } catch (RemoteException ex) { 478c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville // ignore it 479c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 480c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 481c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville return success; 482c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 483c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 484c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** 485c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Disable reception of cell broadcast (SMS-CB) messages with the given 486c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * message identifier range. Note that if two different clients enable the same 487c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * message identifier, they must both disable it for the device to stop 488c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * receiving those messages. 489c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Note: This call is blocking, callers may want to avoid calling it from 490c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * the main thread of an application. 491c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 492a63f55cf17629426d976830429a7612387532195Rika Brooks * @param startMessageId first message identifier as specified in TS 23.041 (3GPP) 493a63f55cf17629426d976830429a7612387532195Rika Brooks * or C.R1001-G (3GPP2) 494a63f55cf17629426d976830429a7612387532195Rika Brooks * @param endMessageId last message identifier as specified in TS 23.041 (3GPP) 495a63f55cf17629426d976830429a7612387532195Rika Brooks * or C.R1001-G (3GPP2) 496c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @return true if successful, false otherwise 497c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 498c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @see #enableCellBroadcastRange(int, int) 499c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 500910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks * @throws IllegalArgumentException if endMessageId < startMessageId 501c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * {@hide} 502c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville */ 503c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville public boolean disableCellBroadcastRange(int startMessageId, int endMessageId) { 504c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville boolean success = false; 505c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 506910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks if (endMessageId < startMessageId) { 507910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks throw new IllegalArgumentException("endMessageId < startMessageId"); 508910825a2ed10bd5cc454b91380b7db0dac2e616eRika Brooks } 509c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville try { 510c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms")); 511c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville if (iccISms != null) { 512c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville success = iccISms.disableCellBroadcastRange(startMessageId, endMessageId); 513c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 514c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } catch (RemoteException ex) { 515c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville // ignore it 516c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 517c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 518c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville return success; 519c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 520c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 521c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** 522c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Create a list of <code>SmsMessage</code>s from a list of RawSmsData 523c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * records returned by <code>getAllMessagesFromIcc()</code> 524c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * 525c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @param records SMS EF records, returned by 526c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * <code>getAllMessagesFromIcc</code> 527c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @return <code>ArrayList</code> of <code>SmsMessage</code> objects. 528c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville */ 529c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville private static ArrayList<SmsMessage> createMessageListFromRawRecords(List<SmsRawData> records) { 530c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville ArrayList<SmsMessage> messages = new ArrayList<SmsMessage>(); 531c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville if (records != null) { 532c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville int count = records.size(); 533c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville for (int i = 0; i < count; i++) { 534c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville SmsRawData data = records.get(i); 535c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville // List contains all records, including "free" records (null) 536c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville if (data != null) { 537c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville SmsMessage sms = SmsMessage.createFromEfRecord(i+1, data.getBytes()); 538c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville if (sms != null) { 539c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville messages.add(sms); 540c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 541c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 542c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 543c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 544c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville return messages; 545c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville } 546c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 5471260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa /** 5481260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * SMS over IMS is supported if IMS is registered and SMS is supported 5491260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * on IMS. 5501260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * 5511260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * @return true if SMS over IMS is supported, false otherwise 5521260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * 5531260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * @see #getImsSmsFormat() 5541260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * 5551260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * @hide 5561260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa */ 5571260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa boolean isImsSmsSupported() { 5581260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa boolean boSupported = false; 5591260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa try { 5601260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms")); 5611260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa if (iccISms != null) { 5621260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa boSupported = iccISms.isImsSmsSupported(); 5631260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa } 5641260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa } catch (RemoteException ex) { 5651260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa // ignore it 5661260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa } 5671260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa return boSupported; 5681260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa } 5691260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa 5701260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa /** 5711260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * Gets SMS format supported on IMS. SMS over IMS format is 5721260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * either 3GPP or 3GPP2. 5731260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * 5741260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * @return SmsMessage.FORMAT_3GPP, 5751260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * SmsMessage.FORMAT_3GPP2 5761260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * or SmsMessage.FORMAT_UNKNOWN 5771260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * 5781260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * @see #isImsSmsSupported() 5791260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * 5801260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * @hide 5811260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa */ 5821260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa String getImsSmsFormat() { 5831260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa String format = com.android.internal.telephony.SmsConstants.FORMAT_UNKNOWN; 5841260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa try { 5851260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms")); 5861260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa if (iccISms != null) { 5871260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa format = iccISms.getImsSmsFormat(); 5881260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa } 5891260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa } catch (RemoteException ex) { 5901260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa // ignore it 5911260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa } 5921260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa return format; 5931260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa } 5941260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa 595c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville // see SmsMessage.getStatusOnIcc 596c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 597c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** Free space (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). */ 598c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville static public final int STATUS_ON_ICC_FREE = 0; 599c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 600c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** Received and read (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). */ 601c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville static public final int STATUS_ON_ICC_READ = 1; 602c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 603c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** Received and unread (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). */ 604c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville static public final int STATUS_ON_ICC_UNREAD = 3; 605c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 606c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** Stored and sent (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). */ 607c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville static public final int STATUS_ON_ICC_SENT = 5; 608c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 609c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** Stored and unsent (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). */ 610c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville static public final int STATUS_ON_ICC_UNSENT = 7; 611c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 612c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville // SMS send failure result codes 613c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville 614c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** Generic failure cause */ 615c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville static public final int RESULT_ERROR_GENERIC_FAILURE = 1; 616c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** Failed because radio was explicitly turned off */ 617c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville static public final int RESULT_ERROR_RADIO_OFF = 2; 618c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** Failed because no pdu provided */ 619c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville static public final int RESULT_ERROR_NULL_PDU = 3; 620c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** Failed because service is currently unavailable */ 621c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville static public final int RESULT_ERROR_NO_SERVICE = 4; 622c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** Failed because we reached the sending queue limit. {@hide} */ 623c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville static public final int RESULT_ERROR_LIMIT_EXCEEDED = 5; 624c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville /** Failed because FDN is enabled. {@hide} */ 625c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville static public final int RESULT_ERROR_FDN_CHECK_FAILURE = 6; 626c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville} 627