UiccSmsController.java revision a8467dd0c524787104b1ccdddc5e8af10ba729ed
1/* 2 * Copyright (C) 2008 The Android Open Source Project 3 * Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. 4 * Not a Contribution. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19package com.android.internal.telephony; 20 21import android.app.PendingIntent; 22import android.os.ServiceManager; 23import android.telephony.Rlog; 24 25import com.android.internal.telephony.ISms; 26import com.android.internal.telephony.Phone; 27import com.android.internal.telephony.SmsRawData; 28 29import java.util.ArrayList; 30import java.util.List; 31 32/** 33 * UiccSmsController to provide an inter-process communication to 34 * access Sms in Icc. 35 */ 36public class UiccSmsController extends ISms.Stub { 37 static final String LOG_TAG = "RIL_UiccSmsController"; 38 39 protected Phone[] mPhone; 40 41 protected UiccSmsController(Phone[] phone){ 42 mPhone = phone; 43 44 if (ServiceManager.getService("isms") == null) { 45 ServiceManager.addService("isms", this); 46 } 47 } 48 49 public boolean 50 updateMessageOnIccEf(String callingPackage, int index, int status, byte[] pdu) 51 throws android.os.RemoteException { 52 return updateMessageOnIccEfUsingSubId(getPreferredSmsSubscription(), callingPackage, 53 index, status, pdu); 54 } 55 56 public boolean 57 updateMessageOnIccEfUsingSubId(long subId, String callingPackage, int index, int status, 58 byte[] pdu) throws android.os.RemoteException { 59 IccSmsInterfaceManager iccSmsIntMgr = getIccSmsInterfaceManager(subId); 60 if (iccSmsIntMgr != null) { 61 return iccSmsIntMgr.updateMessageOnIccEf(callingPackage, index, status, pdu); 62 } else { 63 Rlog.e(LOG_TAG,"updateMessageOnIccEf iccSmsIntMgr is null" + 64 " for Subscription: " + subId); 65 return false; 66 } 67 } 68 69 public boolean copyMessageToIccEf(String callingPackage, int status, byte[] pdu, byte[] smsc) 70 throws android.os.RemoteException { 71 return copyMessageToIccEfUsingSubId(getPreferredSmsSubscription(), callingPackage, status, 72 pdu, smsc); 73 } 74 75 public boolean copyMessageToIccEfUsingSubId(long subId, String callingPackage, int status, 76 byte[] pdu, byte[] smsc) throws android.os.RemoteException { 77 IccSmsInterfaceManager iccSmsIntMgr = getIccSmsInterfaceManager(subId); 78 if (iccSmsIntMgr != null) { 79 return iccSmsIntMgr.copyMessageToIccEf(callingPackage, status, pdu, smsc); 80 } else { 81 Rlog.e(LOG_TAG,"copyMessageToIccEf iccSmsIntMgr is null" + 82 " for Subscription: " + subId); 83 return false; 84 } 85 } 86 87 public List<SmsRawData> getAllMessagesFromIccEf(String callingPackage) 88 throws android.os.RemoteException { 89 return getAllMessagesFromIccEfUsingSubId(getPreferredSmsSubscription(), callingPackage); 90 } 91 92 public List<SmsRawData> getAllMessagesFromIccEfUsingSubId(long subId, String callingPackage) 93 throws android.os.RemoteException { 94 IccSmsInterfaceManager iccSmsIntMgr = getIccSmsInterfaceManager(subId); 95 if (iccSmsIntMgr != null) { 96 return iccSmsIntMgr.getAllMessagesFromIccEf(callingPackage); 97 } else { 98 Rlog.e(LOG_TAG,"getAllMessagesFromIccEf iccSmsIntMgr is" + 99 " null for Subscription: " + subId); 100 return null; 101 } 102 } 103 104 public void sendData(String callingPackage, String destAddr, String scAddr, int destPort, 105 byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent) { 106 sendDataUsingSubId(getPreferredSmsSubscription(), callingPackage, destAddr, scAddr, 107 destPort, data, sentIntent, deliveryIntent); 108 } 109 110 public void sendDataUsingSubId(long subId, String callingPackage, String destAddr, 111 String scAddr, int destPort, byte[] data, PendingIntent sentIntent, 112 PendingIntent deliveryIntent) { 113 IccSmsInterfaceManager iccSmsIntMgr = getIccSmsInterfaceManager(subId); 114 if (iccSmsIntMgr != null) { 115 iccSmsIntMgr.sendData(callingPackage, destAddr, scAddr, destPort, data, 116 sentIntent, deliveryIntent); 117 } else { 118 Rlog.e(LOG_TAG,"sendText iccSmsIntMgr is null for" + 119 " Subscription: " + subId); 120 } 121 } 122 123 public void sendText(String callingPackage, String destAddr, String scAddr, 124 String text, PendingIntent sentIntent, PendingIntent deliveryIntent) { 125 sendTextUsingSubId(getPreferredSmsSubscription(), callingPackage, destAddr, scAddr, 126 text, sentIntent, deliveryIntent); 127 } 128 129 public void sendTextUsingSubId(long subId, String callingPackage, String destAddr, 130 String scAddr, String text, PendingIntent sentIntent, PendingIntent deliveryIntent) { 131 IccSmsInterfaceManager iccSmsIntMgr = getIccSmsInterfaceManager(subId); 132 if (iccSmsIntMgr != null) { 133 iccSmsIntMgr.sendText(callingPackage, destAddr, scAddr, text, sentIntent, 134 deliveryIntent); 135 } else { 136 Rlog.e(LOG_TAG,"sendText iccSmsIntMgr is null for" + 137 " Subscription: " + subId); 138 } 139 } 140 141 public void sendMultipartText(String callingPackage, String destAddr, String scAddr, 142 List<String> parts, List<PendingIntent> sentIntents, 143 List<PendingIntent> deliveryIntents) throws android.os.RemoteException { 144 sendMultipartTextUsingSubId(getPreferredSmsSubscription(), callingPackage, destAddr, 145 scAddr, parts, sentIntents, deliveryIntents); 146 } 147 148 public void sendMultipartTextUsingSubId(long subId, String callingPackage, String destAddr, 149 String scAddr, List<String> parts, List<PendingIntent> sentIntents, 150 List<PendingIntent> deliveryIntents) 151 throws android.os.RemoteException { 152 IccSmsInterfaceManager iccSmsIntMgr = getIccSmsInterfaceManager(subId); 153 if (iccSmsIntMgr != null ) { 154 iccSmsIntMgr.sendMultipartText(callingPackage, destAddr, scAddr, parts, sentIntents, 155 deliveryIntents); 156 } else { 157 Rlog.e(LOG_TAG,"sendMultipartText iccSmsIntMgr is null for" + 158 " Subscription: " + subId); 159 } 160 } 161 162 public boolean enableCellBroadcast(int messageIdentifier) throws android.os.RemoteException { 163 return enableCellBroadcastUsingSubId(getPreferredSmsSubscription(), messageIdentifier); 164 } 165 166 public boolean enableCellBroadcastUsingSubId(long subId, int messageIdentifier) 167 throws android.os.RemoteException { 168 return enableCellBroadcastRangeUsingSubId(subId, messageIdentifier, messageIdentifier); 169 } 170 171 public boolean enableCellBroadcastRange(int startMessageId, int endMessageId) 172 throws android.os.RemoteException { 173 return enableCellBroadcastRangeUsingSubId(getPreferredSmsSubscription(), startMessageId, 174 endMessageId); 175 } 176 177 public boolean enableCellBroadcastRangeUsingSubId(long subId, int startMessageId, 178 int endMessageId) throws android.os.RemoteException { 179 IccSmsInterfaceManager iccSmsIntMgr = getIccSmsInterfaceManager(subId); 180 if (iccSmsIntMgr != null ) { 181 return iccSmsIntMgr.enableCellBroadcastRange(startMessageId, endMessageId); 182 } else { 183 Rlog.e(LOG_TAG,"enableCellBroadcast iccSmsIntMgr is null for" + 184 " Subscription: " + subId); 185 } 186 return false; 187 } 188 189 public boolean disableCellBroadcast(int messageIdentifier) throws android.os.RemoteException { 190 return disableCellBroadcastUsingSubId(getPreferredSmsSubscription(), messageIdentifier); 191 } 192 193 public boolean disableCellBroadcastUsingSubId(long subId, int messageIdentifier) 194 throws android.os.RemoteException { 195 return disableCellBroadcastRangeUsingSubId(subId, messageIdentifier, messageIdentifier); 196 } 197 198 public boolean disableCellBroadcastRange(int startMessageId, int endMessageId) 199 throws android.os.RemoteException { 200 return disableCellBroadcastRangeUsingSubId(getPreferredSmsSubscription(), startMessageId, 201 endMessageId); 202 } 203 204 public boolean disableCellBroadcastRangeUsingSubId(long subId, int startMessageId, 205 int endMessageId) throws android.os.RemoteException { 206 IccSmsInterfaceManager iccSmsIntMgr = getIccSmsInterfaceManager(subId); 207 if (iccSmsIntMgr != null ) { 208 return iccSmsIntMgr.disableCellBroadcastRange(startMessageId, endMessageId); 209 } else { 210 Rlog.e(LOG_TAG,"disableCellBroadcast iccSmsIntMgr is null for" + 211 " Subscription:"+subId); 212 } 213 return false; 214 } 215 216 public int getPremiumSmsPermission(String packageName) { 217 return getPremiumSmsPermissionUsingSubId(getPreferredSmsSubscription(), packageName); 218 } 219 220 @Override 221 public int getPremiumSmsPermissionUsingSubId(long subId, String packageName) { 222 IccSmsInterfaceManager iccSmsIntMgr = getIccSmsInterfaceManager(subId); 223 if (iccSmsIntMgr != null ) { 224 return iccSmsIntMgr.getPremiumSmsPermission(packageName); 225 } else { 226 Rlog.e(LOG_TAG, "getPremiumSmsPermission iccSmsIntMgr is null"); 227 } 228 //TODO Rakesh 229 return 0; 230 } 231 232 public void setPremiumSmsPermission(String packageName, int permission) { 233 setPremiumSmsPermissionUsingSubId(getPreferredSmsSubscription(), packageName, permission); 234 } 235 236 @Override 237 public void setPremiumSmsPermissionUsingSubId(long subId, String packageName, int permission) { 238 IccSmsInterfaceManager iccSmsIntMgr = getIccSmsInterfaceManager(subId); 239 if (iccSmsIntMgr != null ) { 240 iccSmsIntMgr.setPremiumSmsPermission(packageName, permission); 241 } else { 242 Rlog.e(LOG_TAG, "setPremiumSmsPermission iccSmsIntMgr is null"); 243 } 244 } 245 246 public boolean isImsSmsSupported() { 247 return isImsSmsSupportedUsingSubId(getPreferredSmsSubscription()); 248 } 249 250 @Override 251 public boolean isImsSmsSupportedUsingSubId(long subId) { 252 IccSmsInterfaceManager iccSmsIntMgr = getIccSmsInterfaceManager(subId); 253 if (iccSmsIntMgr != null ) { 254 return iccSmsIntMgr.isImsSmsSupported(); 255 } else { 256 Rlog.e(LOG_TAG, "isImsSmsSupported iccSmsIntMgr is null"); 257 } 258 return false; 259 } 260 261 public String getImsSmsFormat() { 262 return getImsSmsFormatUsingSubId(getPreferredSmsSubscription()); 263 } 264 265 @Override 266 public String getImsSmsFormatUsingSubId(long subId) { 267 IccSmsInterfaceManager iccSmsIntMgr = getIccSmsInterfaceManager(subId); 268 if (iccSmsIntMgr != null ) { 269 return iccSmsIntMgr.getImsSmsFormat(); 270 } else { 271 Rlog.e(LOG_TAG, "getImsSmsFormat iccSmsIntMgr is null"); 272 } 273 return null; 274 } 275 276 /** 277 * get sms interface manager object based on subscription. 278 **/ 279 private IccSmsInterfaceManager getIccSmsInterfaceManager(long subId) { 280 long phoneId = SubscriptionController.getInstance().getPhoneId(subId); 281 try { 282 return (IccSmsInterfaceManager) 283 ((PhoneProxy)mPhone[(int)phoneId]).getIccSmsInterfaceManager(); 284 } catch (NullPointerException e) { 285 Rlog.e(LOG_TAG, "Exception is :"+e.toString()+" For subscription :"+subId ); 286 e.printStackTrace(); //This will print stact trace 287 return null; 288 } catch (ArrayIndexOutOfBoundsException e) { 289 Rlog.e(LOG_TAG, "Exception is :"+e.toString()+" For subscription :"+subId ); 290 e.printStackTrace(); //This will print stack trace 291 return null; 292 } 293 } 294 295 /** 296 Gets User preferred SMS subscription */ 297 public long getPreferredSmsSubscription() { 298 return PhoneFactory.getDefaultSubscription(); 299 } 300 301 /** 302 * Get SMS prompt property, enabled or not 303 **/ 304 public boolean isSMSPromptEnabled() { 305 return PhoneFactory.isSMSPromptEnabled(); 306 } 307 308} 309